コード例 #1
0
/*
 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();
                }
            }
        }
コード例 #2
0
/*
 TODO: enable support for properties
        [Parameter(Position = 4, Mandatory = false)]
        public Hashtable Properties { get; set; }
*/

        protected override void EndProcessing()
        {
            var navigation = new CmisNavigation(CmisSession, WorkingFolder);
            ICmisObject obj = (Object != null) ? Object : navigation.Get(Path);

/*
            if (Properties != null || !String.IsNullOrEmpty(Name))
            {
                var props = Utilities.HashtableToDict(Properties);
                if (!String.IsNullOrEmpty(Name))
                {
                    props[PropertyIds.Name] = Name;
                }
                obj = obj.UpdateProperties(props);
            }
 */
            if (!String.IsNullOrEmpty(Name))
            {
                var props = new Dictionary<string, object>() { { PropertyIds.Name, Name } };
                obj = obj.UpdateProperties(props);
            }

            // check if we should update content
            if (LocalFile == null && !HasContent())
            {
                WriteObject(obj);
                return; 
            }

            // otherwise the object must be a document
            var doc = obj as IDocument;
            if (doc == null)
            {
                var ex = new CmisObjectNotFoundException("The provided object is not a Document");
                ThrowTerminatingError(new ErrorRecord(ex, "UpdateObjNotDocument",
                                                      ErrorCategory.InvalidArgument, Object));
            }

            var stream = GetContentStream();
            stream.FileName = obj.Name; // important, as may not set
            try
            {
                var result = doc.SetContentStream(stream, true);
                WriteObject(result == null ? doc : result);
            }
            finally
            {
                stream.Stream.Close();
            }
        }
コード例 #3
0
        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);
        }
コード例 #4
0
/*
 TODO: enable yupport for properties
        [Parameter(Position = 1, Mandatory = false)]
        public Hashtable Properties { get; set; }
*/
        protected override void ProcessRecord()
        {
            var navigation = new CmisNavigation(CmisSession, WorkingFolder);
            foreach (string p in Path)
            {
                try
                {
//                    var props = Utilities.HashtableToDict(Properties);
//                    WriteObject(navigation.CreateFolder(p, Recursive.IsPresent, props));
                    WriteObject(navigation.CreateFolder(p, Recursive.IsPresent, null));
                }
                catch (CmisBaseException e)
                {
                    ThrowTerminatingError(new ErrorRecord(e, "FolderCreationFailed",
                                                          ErrorCategory.WriteError, p));
                }
            }
        }
コード例 #5
0
 protected override void ProcessRecord()
 {
     var navigation = new CmisNavigation(CmisSession, WorkingFolder);
     if (Path != null)
     {
         foreach (var path in Path)
         {
             WriteFailErrors(navigation.Delete(path, Recursive.IsPresent));
         }
     }
     else
     {
         foreach (var obj in Object)
         {
             WriteFailErrors(navigation.Delete(obj, Recursive.IsPresent));
         }
     }
 }
コード例 #6
0
 public CmisTestHelper(ISession session)
 {
     _session = session;
     _createdObjects = new List<object>();
     _cmisNav = new CmisNavigation(session);
 }
コード例 #7
0
        protected override void ProcessRecord()
        {
            var doc = Document;
            if (doc == null)
            {
                doc = new CmisNavigation(CmisSession, WorkingFolder).GetDocument(Path);
            }
            var writeToPipeline = String.IsNullOrEmpty(Destination);
            var size = (long) doc.ContentStreamLength;

            // Do some security checks firsat if we should write the output to pipeline
            var msg = String.Format("The content is not plain text, but of type {0}. Do you want to"
                                    + "write it to pipeline anyway?", doc.ContentStreamMimeType);
            if (writeToPipeline && !IsPlaintextType(doc.ContentStreamMimeType) && !Force &&
                !ShouldContinue(msg, "Document Content Warning"))
            {
                return;
            }

            msg = String.Format("The document is pretty big (greater than {0:0.##} MB). " +
                "Are you sure that you want to write it to the pipeline anyway?",
                ((double)_pipelineMaxSize) / (1024 * 1024));
            if (writeToPipeline && size > _pipelineMaxSize && !Force &&
                !ShouldContinue(msg, "Big Document Warning"))
            {
                return;
            }

            msg = "The destination already exists. Do you want to overwrite that file?";
            if (!writeToPipeline && File.Exists(Destination) && !Force &&
                !ShouldContinue(msg, "Destination File Exists"))
            {
                return;
            }

            // TODO: better download mechanism anywhere
            byte[] stringBuffer = null;
            Stream outputStream;
            if (writeToPipeline)
            {
                stringBuffer = new byte[size];
                outputStream = new MemoryStream(stringBuffer);
            }
            else
            {
                outputStream = new FileStream(Destination, FileMode.Create);
            }

            IContentStream stream = null;
            try
            {
                var buffer = new byte[8 * 1024];
                int offset = 0;
                int bytesRead = 0;
                stream = doc.GetContentStream();

                while ((bytesRead = stream.Stream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    outputStream.Write(buffer, 0, bytesRead);
                    offset += bytesRead;
                }
                outputStream.Flush();
            }
            finally
            {
                if (stream != null)
                {
                    stream.Stream.Close();
                }
                outputStream.Close();
            }

            if (writeToPipeline)
            {
                // TODO: support encodings
                WriteObject(Encoding.UTF8.GetString(stringBuffer));
            }
        }
コード例 #8
0
 public override void SetUp()
 {
     _cmisNav = new CmisNavigation(CmisSession);
 }