예제 #1
0
        public IFolder CreateFolder(CmisPath path, bool recursive,
                                    IDictionary <string, object> properties)
        {
            path = path.WithoutTrailingSlash();

            if (recursive)
            {
                // check if it already exists and proceed to create otherwise
                try
                {
                    return(GetFolder(path));
                }
                catch (CmisObjectNotFoundException)
                {
                }
            }

            var     components = path.GetComponents();
            var     dirname    = components[0];
            var     basename   = components[1];
            IFolder parent     = recursive ? CreateFolder(dirname, true, null) : GetFolder(dirname);

            var allProps = new Dictionary <string, object>()
            {
                { PropertyIds.ObjectTypeId, "cmis:folder" },
                { PropertyIds.Name, basename }
            };

            Utilities.UpdateDictionary(allProps, properties);
            return(parent.CreateFolder(allProps));
        }
/*
 TODO: enable support for propertie
        [Parameter(Position = 3, Mandatory = false)]
        public Hashtable Properties { get; set; }
*/

        protected override void EndProcessing()
        {
            var path = new CmisPath(Path);
            if (LocalFile != null && path.HasTrailingSlash())
            {
                path = path.Combine(System.IO.Path.GetFileName(LocalFile));
            }
            var nav = new CmisNavigation(CmisSession, WorkingFolder);
//            var props = Utilities.HashtableToDict(Properties);
            var stream = GetContentStream();
            try
            {
//                WriteObject(nav.CreateDocument(path, stream, props));
                WriteObject(nav.CreateDocument(path, stream, null));
            }
            catch (CmisBaseException e)
            {
                ThrowTerminatingError(new ErrorRecord(e, "CreateDocumentFailed",
                                                      ErrorCategory.WriteError, path));
            }
            finally
            {
                if (stream != null)
                {
                    stream.Stream.Close();
                }
            }
        }
예제 #3
0
        public IFolder CreateFolder(CmisPath path, bool recursive,
                                    IDictionary<string, object> properties)
        {
            path = path.WithoutTrailingSlash();

            if (recursive)
            {
                // check if it already exists and proceed to create otherwise
                try
                {
                    return GetFolder(path);
                }
                catch (CmisObjectNotFoundException)
                {
                }
            }

            var components = path.GetComponents();
            var dirname = components[0];
            var basename = components[1];
            IFolder parent = recursive ? CreateFolder(dirname, true, null) : GetFolder(dirname);

            var allProps = new Dictionary<string, object>()
            {
                { PropertyIds.ObjectTypeId, "cmis:folder" },
                { PropertyIds.Name, basename }
            };
            Utilities.UpdateDictionary(allProps, properties);
            return parent.CreateFolder(allProps);
        }
예제 #4
0
 public CmisPath Combine(CmisPath other)
 {
     if (other.IsAbsolutePath())
     {
         return other.Clone();
     }
     return new CmisPath(_path + CorrectSlash + other.ToString());
 }
예제 #5
0
 public CmisPath Combine(CmisPath other)
 {
     if (other.IsAbsolutePath())
     {
         return(other.Clone());
     }
     return(new CmisPath(_path + CorrectSlash + other.ToString()));
 }
예제 #6
0
        public IList <string> Delete(CmisPath cmisPath, bool recursive)
        {
            ICmisObject obj;

            if (!TryGet(cmisPath, out obj))
            {
                // fail otherwise
                return(new string[] { _curDir.Combine(cmisPath).ToString() });
            }
            return(Delete(obj, recursive));
        }
예제 #7
0
        public IDocument GetDocument(CmisPath cmisPath)
        {
            IDocument d = Get(cmisPath) as IDocument;

            if (d == null)
            {
                var path = _curDir.Combine(cmisPath).ToString();
                var msg  = String.Format("The object identified by '{0}' is not a document.", path);
                throw new CmisObjectNotFoundException(msg);
            }
            return(d);
        }
예제 #8
0
        public IFolder GetFolder(CmisPath cmisPath)
        {
            IFolder f = Get(cmisPath) as IFolder;

            // we need to check if that object is a folder
            if (f == null)
            {
                var path = _curDir.Combine(cmisPath).ToString();
                var msg  = String.Format("The object identified by '{0}' is not a folder.", path);
                throw new CmisObjectNotFoundException(msg);
            }
            return(f);
        }
예제 #9
0
        public ICmisObject Get(CmisPath cmisPath)
        {
            ICmisObject obj;

            if (!TryGet(cmisPath, out obj))
            {
                // DotCMIS is not very generous when it comes to generating error messages
                // so we create a better one
                var msg = String.Format("The path '{0}' doesn't identify a CMIS object.",
                                        cmisPath.ToString());
                throw new CmisObjectNotFoundException(msg);
            }
            return(obj);
        }
예제 #10
0
        public bool TryGet(CmisPath cmisPath, out ICmisObject obj)
        {
            var path = _curDir.Combine(cmisPath).ToString();

            obj = null;
            try
            {
                obj = _session.GetObjectByPath(path);
            }
            catch (CmisObjectNotFoundException)
            {
                return(false);
            }
            return(true);
        }
        protected override void ProcessRecord()
        {
            var cmisPath = new CmisPath(Path);
            var navigation = new CmisNavigation(CmisSession, WorkingFolder);
            ICmisObject obj = null;
            try
            {
                obj = navigation.Get(cmisPath);
            }
            catch (CmisBaseException e)
            {
                ThrowTerminatingError(new ErrorRecord(e, "GetObjectFailed",
                                                      ErrorCategory.ResourceUnavailable, Path));
                return;
            }

            var nameIsEmpty = String.IsNullOrEmpty(Name);

            if (!(obj is IFolder) ||
                (!cmisPath.HasTrailingSlash() && nameIsEmpty && RecursionDepth < 1))
            {
                WriteObject(obj);
                return;
            }

            WildcardPattern wildcard = new WildcardPattern("*");
            if (!nameIsEmpty)
            {
                wildcard = Exact.IsPresent ? new WildcardPattern(Name)
                                      : new WildcardPattern(Name + "*", WildcardOptions.IgnoreCase);
            }
            int depth = RecursionDepth == 0 ? 1 : RecursionDepth;

            //otherwise we want the descendants of the folder
            var folder = obj as IFolder;
            IList<ITree<IFileableCmisObject>> descendants;
            try
            {
                descendants = folder.GetDescendants(depth);
            }
            catch (CmisBaseException e)
            {
                ThrowTerminatingError(new ErrorRecord(e, "GetDescendatnsFailed",
                                                      ErrorCategory.ResourceUnavailable, Path));
                return;
            }
            WriteTreeList(descendants, wildcard);
        }
예제 #12
0
        public IDocument CreateDocument(CmisPath path, ContentStream stream,
                                        IDictionary<string, object> properties)
        {
            var components = path.GetComponents();
            var name = components[1];
            if (name.Length == 0)
            {
                throw new CmisNameConstraintViolationException("The document name is empty.");
            }
            var folder = GetFolder(components[0]);

            var allProps = new Dictionary<string, object>()
            {
                { PropertyIds.ObjectTypeId, "cmis:document" },
                { PropertyIds.Name, name }
            };
            Utilities.UpdateDictionary(allProps, properties);
            return folder.CreateDocument(allProps, stream, VersioningState.Major);
        }
예제 #13
0
        public IDocument CreateDocument(CmisPath path, ContentStream stream,
                                        IDictionary <string, object> properties)
        {
            var components = path.GetComponents();
            var name       = components[1];

            if (name.Length == 0)
            {
                throw new CmisNameConstraintViolationException("The document name is empty.");
            }
            var folder = GetFolder(components[0]);

            var allProps = new Dictionary <string, object>()
            {
                { PropertyIds.ObjectTypeId, "cmis:document" },
                { PropertyIds.Name, name }
            };

            Utilities.UpdateDictionary(allProps, properties);
            return(folder.CreateDocument(allProps, stream, VersioningState.Major));
        }
예제 #14
0
 public ICmisObject Get(CmisPath cmisPath)
 {
     ICmisObject obj;
     if (!TryGet(cmisPath, out obj))
     {
         // DotCMIS is not very generous when it comes to generating error messages
         // so we create a better one
         var msg = String.Format("The path '{0}' doesn't identify a CMIS object.",
                                 cmisPath.ToString());
         throw new CmisObjectNotFoundException(msg);
     }
     return obj;
 }
예제 #15
0
 public IFolder CreateFolder(CmisPath path, bool recursive)
 {
     return(CreateFolder(path, recursive, null));
 }
예제 #16
0
 public IFolder CreateTempFolder(CmisPath path, bool recursive)
 {
     return CreateTempFolder(path, recursive, null);
 }
예제 #17
0
 public IDocument CreateTempDocument(CmisPath path, ContentStream stream,
                                     IDictionary<string, object> properties) 
 {
     var doc = _cmisNav.CreateDocument(path, stream, properties);
     _createdObjects.Add(doc);
     return doc;
 }
예제 #18
0
 public IDocument CreateTempDocument(CmisPath path, ContentStream stream)
 {
     return CreateTempDocument(path, stream, null);
 }
예제 #19
0
 protected void SetWorkingFolder(CmisPath path)
 {
     _workingFolder = path;
     SessionState.PSVariable.Set(DIRECTORY_VAR_NAME, path.ToString());
 }
예제 #20
0
 public IFolder GetFolder(CmisPath cmisPath)
 {
     IFolder f = Get(cmisPath) as IFolder;
     // we need to check if that object is a folder
     if (f == null)
     {
         var path = _curDir.Combine(cmisPath).ToString();
         var msg = String.Format("The object identified by '{0}' is not a folder.", path);
         throw new CmisObjectNotFoundException(msg);
     }
     return f;
 }
예제 #21
0
 public bool TryGet(CmisPath cmisPath, out ICmisObject obj)
 {
     var path = _curDir.Combine(cmisPath).ToString();
     obj = null;
     try
     {
         obj = _session.GetObjectByPath(path);
     }
     catch (CmisObjectNotFoundException)
     {
         return false;
     }
     return true;
 }
예제 #22
0
 public IList<string> Delete(CmisPath cmisPath, bool recursive)
 {
     ICmisObject obj;
     if (!TryGet(cmisPath, out obj))
     {
         // fail otherwise
         return new string[] { _curDir.Combine(cmisPath).ToString() };
     }
     return Delete(obj, recursive);
 }
예제 #23
0
        public ICmisObject Get(CmisPath path)
        {
			return _cmisNav.Get(path);
        }
예제 #24
0
 public IDocument CreateTempDocument(CmisPath path)
 {
     return CreateTempDocument(path, null);
 }
예제 #25
0
 public IDocument GetDocument(CmisPath cmisPath)
 {
     IDocument d = Get(cmisPath) as IDocument;
     if (d == null)
     {
         var path = _curDir.Combine(cmisPath).ToString();
         var msg = String.Format("The object identified by '{0}' is not a document.", path);
         throw new CmisObjectNotFoundException(msg);
     }
     return d;
 }
예제 #26
0
 public IDocument CreateTempDocument(CmisPath path, string content, string mimeType) 
 {
     var bytes = Encoding.UTF8.GetBytes(content);
     var contentStream = new ContentStream();
     contentStream.MimeType = mimeType;
     contentStream.Length = bytes.Length;
     using (var memoryStream = new MemoryStream(bytes))
     {
         contentStream.Stream = memoryStream;
         return CreateTempDocument(path, contentStream, null);
     }
 }
예제 #27
0
 public CmisNavigation(ISession session, CmisPath path)
 {
     _session = session;
     _curDir  = path;
 }
예제 #28
0
 public IFolder CreateTempFolder(CmisPath path)
 {
     return CreateTempFolder(path, false);
 }
예제 #29
0
 public IDocument CreateDocument(CmisPath path, ContentStream stream)
 {
     return(CreateDocument(path, stream, null));
 }
예제 #30
0
 public IFolder CreateTempFolder(CmisPath path, bool recursive,
                             IDictionary<string, object> properties) 
 {
     path = path.WithoutTrailingSlash();
     if (recursive)
     {
         try
         {
             return _cmisNav.GetFolder(path);
         }
         catch (CmisBaseException) {}
     }
     var comps = path.GetComponents();
     if (recursive)
     {
         CreateTempFolder(comps[0], true, null);
     }
     var folder = _cmisNav.CreateFolder(path, false, properties);
     _createdObjects.Add(folder);
     return folder;
 }
예제 #31
0
 public CmisNavigation(ISession session, CmisPath path)
 {
     _session = session;
     _curDir = path;
 }