Beispiel #1
0
            /// <summary>
            /// Process a detected deletion.
            /// </summary>
            /// <param name="remoteFolder">Remote folder.</param>
            /// <param name="localFolder">Local folder.</param>
            /// <param name="pathname">Pathname.</param>
            /// <returns>Whether the delete has now been synchronized, so that no further action is needed</returns>
            private bool WatcherSyncDelete(string remoteFolder, string localFolder, string pathname, Grace grace)
            {
                SleepWhileSuspended();

                // In many programs (like Microsoft Word), deletion is often just a save:
                // 1. Save data to temporary file ~wrdxxxx.tmp
                // 2. Delete Example.doc
                // 3. Rename ~wrdxxxx.tmp to Example.doc
                // See https://support.microsoft.com/en-us/kb/211632
                // So, upon deletion, wait a bit for any save operation to hopefully finalize, then sync.
                // This is not 100% foolproof, as saving can last for more than the grace time, but probably
                // the best we can do without mind-reading third-party programs.
                grace.WaitGraceTime();
                try
                {
                    if (Utils.IsMetadataFile(pathname))
                    {
                        // Nothing to do
                        return(true);
                    }

                    SyncItem item = database.GetSyncItemFromLocalPath(pathname);
                    if (item == null)
                    {
                        // The item must be in the database
                        return(false);
                    }

                    ICmisObject cmisObject = session.GetObjectByPath(item.RemotePath);
                    if (cmisObject == null)
                    {
                        // the object does not exist on the server so nothing to do
                        return(true);
                    }

                    cmisObject.Delete(true);

                    // Folder or File
                    database.RemoveFolder(item);
                    database.RemoveFile(item);

                    // Remove metadata if exists
                    if (File.Exists(pathname + ".metadata"))
                    {
                        File.Delete(pathname + ".metadata");
                        database.RemoveMetadataFile(item);
                    }

                    return(true);
                }
                catch (Exception e)
                {
                    ProcessRecoverableException("Could Not process Watch Sync Delete : ", e);
                    return(false);
                }
            }
 public IList <string> Delete(ICmisObject obj, bool recursive)
 {
     if (recursive && obj is IFolder)
     {
         return(((IFolder)obj).DeleteTree(false, UnfileObject.Delete, true));
     }
     try
     {
         obj.Delete(false);
     }
     catch (CmisBaseException)
     {
         return(new string[] { GetCmisObjectPath(obj) });
     }
     return(null);
 }
Beispiel #3
0
        public void Cleanup(string fileName, DokanFileInfo info)
        {
#if TRACE
            if (info.Context != null)
            {
                Console.WriteLine(string.Format(CultureInfo.CurrentCulture, "{0}('{1}', {2} - entering",
                                                "Cleanup", fileName, ToTrace(info)));
            }
#endif

            if (info.Context != null && info.Context is FileStream)
            {
                (info.Context as FileStream).Dispose();
            }
            info.Context = null;

            if (info.DeleteOnClose)
            {
                var  cmisPath   = fileName.Replace("\\", "/");
                bool pathExists = true;

                ICmisObject cmisObject = null;

                try
                {
                    cmisObject = cmisSession.GetObjectByPath(cmisPath);
                }

                /*catch (IOException) // TODO remove
                 * {
                 *  pathExists = false;
                 * }*/
                catch (DotCMIS.Exceptions.CmisObjectNotFoundException)
                {
                    pathExists = false;
                }

                if (pathExists)
                {
                    cmisObject.Delete(true);
                }
            }
            Trace("Cleanup", fileName, info, DokanResult.Success);
        }
 public void CleanUp()
 {
     // delete in reverse order makes sure to delete hierarchies correctly
     for (int i = _createdObjects.Count - 1; i >= 0; i--)
     {
         var         tmpObj = _createdObjects[i];
         ICmisObject obj    = tmpObj as ICmisObject;
         if (obj == null)
         {
             if (!_cmisNav.TryGet(tmpObj.ToString(), out obj))
             {
                 continue;
             }
         }
         try
         {
             obj.Delete(true);
         }
         catch (CmisObjectNotFoundException) {}
     }
     _createdObjects.Clear();
 }
        public void TestCreate()
        {
            string testFolderName = "porttest";

            if (Session.ExistsPath("/", testFolderName))
            {
                ICmisObject obj = Session.GetObjectByPath("/", testFolderName, OperationContextUtils.CreateMinimumOperationContext());
                if (obj is IFolder)
                {
                    ((IFolder)obj).DeleteTree(true, UnfileObject.Delete, true);
                }
                else
                {
                    obj.Delete();
                }
            }

            // create folder
            IFolder root      = Session.GetRootFolder();
            IFolder newFolder = CreateFolder(root, testFolderName);

            Assert.IsNotNull(newFolder);

            // create document
            string    contentString = "Hello World";
            IDocument newDoc        = CreateTextDocument(newFolder, "test.txt", contentString);

            Assert.IsNotNull(newDoc);

            // get content
            IContentStream newContent = newDoc.GetContentStream();

            Assert.IsNotNull(newContent);
            Assert.IsNotNull(newContent.Stream);

            Assert.AreEqual(contentString, ConvertStreamToString(newContent.Stream));

            // fetch it again to get the updated content stream length property
            IOperationContext ctxt   = OperationContextUtils.CreateMaximumOperationContext();
            ICmisObject       newObj = Session.GetObject(newDoc, ctxt);

            Assert.IsTrue(newObj is IDocument);
            IDocument newDoc2 = (IDocument)newObj;

            Assert.AreEqual(newDoc.Name, newDoc2.Name);
            Assert.AreEqual(Encoding.UTF8.GetBytes(contentString).Length, newDoc2.ContentStreamLength);

            // fetch it again
            newObj = Session.GetLatestDocumentVersion(newDoc, ctxt);
            Assert.IsTrue(newObj is IDocument);
            IDocument newDoc3 = (IDocument)newObj;

            Assert.AreEqual(newDoc.Id, newDoc3.Id);
            Assert.AreEqual(newDoc.Name, newDoc3.Name);

            // delete document
            newDoc.Delete();

            try
            {
                Session.GetObject(newDoc);
                Assert.Fail("Document still exists.");
            }
            catch (CmisObjectNotFoundException)
            {
                // expected
            }

            Assert.IsFalse(Session.Exists(newDoc.Id));


            // try an item
            IList <IObjectType> types = Session.GetTypeChildren(null, false).ToList();

            Assert.IsNotNull(types);
            Assert.IsTrue(types.Count >= 2);
            if (types.Any(type => type.Id == "cmis:item"))
            {
                IItem newItem = CreateItem(newFolder, "testItem");

                newItem.Delete();

                Assert.IsFalse(Session.Exists(newItem.Id));
            }


            // delete folder

            Assert.IsTrue(Session.ExistsPath(newFolder.Path));

            newFolder.Delete();

            Assert.IsFalse(Session.Exists(newFolder));
        }
 public IList<string> Delete(ICmisObject obj, bool recursive)
 {
     if (recursive && obj is IFolder)
     {
         return ((IFolder)obj).DeleteTree(false, UnfileObject.Delete, true);
     }
     try
     {
         obj.Delete(false);
     }
     catch (CmisBaseException)
     {
         return new string[] { GetCmisObjectPath(obj) };
     }
     return null;
 }