当前位置: 首页>>代码示例>>C#>>正文


C# IFolder.DeleteTree方法代码示例

本文整理汇总了C#中IFolder.DeleteTree方法的典型用法代码示例。如果您正苦于以下问题:C# IFolder.DeleteTree方法的具体用法?C# IFolder.DeleteTree怎么用?C# IFolder.DeleteTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFolder的用法示例。


在下文中一共展示了IFolder.DeleteTree方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CrawlRemoteFolder

            /// <summary>
            /// Crawl remote subfolder, syncing down if needed.
            /// Meanwhile, cache all contained remote folders, they are output parameters that are used in CrawlLocalFiles/CrawlLocalFolders
            /// </summary>
            private void CrawlRemoteFolder(IFolder remoteSubFolder, string localFolder, IList<string> remoteFolders)
            {
                SleepWhileSuspended();

                try
                {
                    if (Utils.WorthSyncing(localFolder, remoteSubFolder.Name, repoinfo))
                    {
                        // Logger.Debug("CrawlRemote localFolder:\"" + localFolder + "\" remoteSubFolder.Path:\"" + remoteSubFolder.Path + "\" remoteSubFolder.Name:\"" + remoteSubFolder.Name + "\"");
                        remoteFolders.Add(remoteSubFolder.Name);
                        var subFolderItem = database.GetFolderSyncItemFromRemotePath(remoteSubFolder.Path);
                        if (null == subFolderItem)
                        {
                            subFolderItem = SyncItemFactory.CreateFromRemotePath(remoteSubFolder.Path, repoinfo);
                        }

                        // Check whether local folder exists.
                        if (Directory.Exists(subFolderItem.LocalPath))
                        {
                            // Recurse into folder.
                            CrawlSync(remoteSubFolder, subFolderItem.LocalPath);
                        }
                        else
                        {
                            // If there was previously a file with this name, delete it.
                            // TODO warn if local changes in the file.
                            if (File.Exists(subFolderItem.LocalPath))
                            {
                                activityListener.ActivityStarted();
                                File.Delete(subFolderItem.LocalPath);
                                activityListener.ActivityStopped();
                            }

                            if (database.ContainsFolder(subFolderItem))
                            {
                                // If there was previously a folder with this name, it means that
                                // the user has deleted it voluntarily, so delete it from server too.

                                activityListener.ActivityStarted();

                                // Delete the folder from the remote server.
                                try
                                {
                                    Logger.Debug("Removing remote folder tree: " + remoteSubFolder.Path);
                                    IList<string> failedIDs = remoteSubFolder.DeleteTree(true, null, true);
                                    if (failedIDs == null || failedIDs.Count != 0)
                                    {
                                        Logger.Error("Failed to completely delete remote folder " + remoteSubFolder.Path);
                                        // TODO Should we retry? Maybe at least once, as a manual recursion instead of a DeleteTree.
                                    }
                                }
                                catch (CmisPermissionDeniedException e)
                                {
                                    // We don't have the permission to delete this folder. Warn and recreate it.
                                    Utils.NotifyUser("You don't have the necessary permissions to delete folder " + remoteSubFolder.Path
                                        + "\nIf you feel you should be able to delete it, please contact your server administrator");
                                    DownloadFolder(remoteSubFolder, localFolder);
                                }

                                // Delete the folder from database.
                                database.RemoveFolder(subFolderItem);

                                activityListener.ActivityStopped();
                            }
                            else
                            {
                                if (Utils.IsInvalidFileName(remoteSubFolder.Name))
                                {
                                    Logger.Warn("Skipping remote folder with name invalid on local filesystem: " + remoteSubFolder.Name);
                                }
                                else
                                {
                                    // The folder has been recently created on server, so download it.
                                    activityListener.ActivityStarted();
                                    Directory.CreateDirectory(subFolderItem.LocalPath);

                                    // Create database entry for this folder.
                                    // TODO - Yannick - Add metadata
                                    database.AddFolder(subFolderItem, remoteSubFolder.Id, remoteSubFolder.LastModificationDate);
                                    Logger.Info("Added folder to database: " + subFolderItem.LocalPath);

                                    // Recursive copy of the whole folder.
                                    RecursiveFolderCopy(remoteSubFolder, subFolderItem.LocalPath);

                                    activityListener.ActivityStopped();
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    activityListener.ActivityStopped();
                    ProcessRecoverableException("Could not crawl sync remote folder: " + remoteSubFolder.Path, e);
                }
            }
开发者ID:jelacote,项目名称:CmisSync,代码行数:100,代码来源:CrawlStrategy.cs

示例2: SyncDownloadFolder

            /// <summary>
            /// Download a single folder from the CMIS server for sync.
            /// </summary>
            /// <returns>true if successful</returns>
            private bool SyncDownloadFolder(IFolder remoteSubFolder, string localFolder)
            {
                var syncItem = SyncItemFactory.CreateFromRemotePath(remoteSubFolder.Path, repoinfo);
                string localName = PathRepresentationConverter.RemoteToLocal(remoteSubFolder.Name);

                // If the target folder has been removed/renamed, then relaunch sync.
                if (!Directory.Exists(localFolder))
                {
                    Logger.Warn("The target folder has been removed/renamed: " + localFolder);
                    return false;
                }

                if (Directory.Exists(syncItem.LocalPath))
                {
                    return true;
                }

                if (database.ContainsFolder(syncItem))
                {
                    // If there was previously a folder with this name, it means that
                    // the user has deleted it voluntarily, so delete it from server too.

                    // Delete the folder from the remote server.
                    Logger.Debug(String.Format("CMIS::DeleteTree({0})", remoteSubFolder.Path));
                    try
                    {
                        remoteSubFolder.DeleteTree(true, null, true);
                        // Delete the folder from database.
                        database.RemoveFolder(syncItem);
                    }
                    catch (Exception)
                    {
                        Logger.Info("Remote Folder could not be deleted: " + remoteSubFolder.Path);
                        // Just go on and try it the next time
                    }
                }
                else
                {
                    // The folder has been recently created on server, so download it.

                    // If there was previously a file with this name, delete it.
                    // TODO warn if local changes in the file.
                    if (File.Exists(syncItem.LocalPath))
                    {
                        string conflictFilename = Utils.CreateConflictFilename(syncItem.LocalPath, repoinfo.User);
                        Logger.Warn("Local file \"" + syncItem.LocalPath + "\" has been renamed to \"" + conflictFilename + "\"");
                        File.Move(syncItem.LocalPath, conflictFilename);
                    }

                    // Skip if invalid folder name. See https://github.com/aegif/CmisSync/issues/196
                    if (Utils.IsInvalidFolderName(localName))
                    {
                        Logger.Info("Skipping download of folder with illegal name: " + localName);
                    }
                    else if (repoinfo.isPathIgnored(syncItem.RemoteRelativePath))
                    {
                        Logger.Info("Skipping dowload of ignored folder: " + syncItem.RemoteRelativePath);
                    }
                    else
                    {
                        // Create local folder.remoteDocument.Name
                        Logger.Info("Creating local directory: " + syncItem.LocalPath);
                        Directory.CreateDirectory(syncItem.LocalPath);

                        // Should the local folder be made read-only?
                        // Check ther permissions of the current user to the remote folder.
                        bool readOnly = ! remoteSubFolder.AllowableActions.Actions.Contains(PermissionMappingKeys.CanAddToFolderObject);
                        if (readOnly)
                        {
                            new DirectoryInfo(syncItem.LocalPath).Attributes =  FileAttributes.ReadOnly;
                        }

                        // Create database entry for this folder.
                        // TODO - Yannick - Add metadata
                        database.AddFolder(syncItem, remoteSubFolder.Id, remoteSubFolder.LastModificationDate);
                    }
                }

                return true;
            }
开发者ID:jelacote,项目名称:CmisSync,代码行数:84,代码来源:SynchronizedFolder.cs

示例3: CrawlRemoteFolder

            /// <summary>
            /// Crawl remote subfolder, syncing down if needed.
            /// Meanwhile, cache and remoteFolders, they are output parameters that are used in CrawlLocalFiles/CrawlLocalFolders
            /// </summary>
            private void CrawlRemoteFolder(IFolder remoteSubFolder, string localFolder, IList remoteFolders)
            {
                sleepWhileSuspended();

                try
                {
                    if (Utils.WorthSyncing(localFolder, remoteSubFolder.Name, repoinfo))
                    {
                        //Logger.Debug("CrawlRemote dir: " + localFolder + Path.DirectorySeparatorChar.ToString() + remoteSubFolder.Name);
                        remoteFolders.Add(remoteSubFolder.Name);
                        string localSubFolder = Path.Combine(localFolder, remoteSubFolder.Name);

                        // Check whether local folder exists.
                        if (Directory.Exists(localSubFolder))
                        {
                            // Recurse into folder.
                            CrawlSync(remoteSubFolder, localSubFolder);
                        }
                        else
                        {
                            // If there was previously a file with this name, delete it.
                            // TODO warn if local changes in the file.
                            if (File.Exists(localSubFolder))
                            {
                                File.Delete(localSubFolder);
                            }

                            if (database.ContainsFolder(localSubFolder))
                            {
                                // If there was previously a folder with this name, it means that
                                // the user has deleted it voluntarily, so delete it from server too.

                                // Delete the folder from the remote server.
                                remoteSubFolder.DeleteTree(true, null, true);

                                // Delete the folder from database.
                                database.RemoveFolder(localSubFolder);
                            }
                            else
                            {
                                // The folder has been recently created on server, so download it.
                                Directory.CreateDirectory(localSubFolder);

                                // Create database entry for this folder.
                                // TODO - Yannick - Add metadata
                                database.AddFolder(localSubFolder, remoteSubFolder.LastModificationDate);
                                Logger.Info("Added folder to database: " + localSubFolder);

                                // Recursive copy of the whole folder.
                                RecursiveFolderCopy(remoteSubFolder, localSubFolder);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    ProcessRecoverableException("Could not crawl sync remote folder: " + remoteSubFolder.Path, e);
                }
            }
开发者ID:keithwharrison,项目名称:Oris4Sync,代码行数:63,代码来源:CrawlStrategy.cs

示例4: DeleteRemoteFolder

            /// <summary>
            /// Delete the folder from the remote server.
            /// </summary>
            public void DeleteRemoteFolder(IFolder folder, SyncItem syncItem, string upperFolderPath)
            {
                try
                {
                    Logger.Debug("Removing remote folder tree: " + folder.Path);
                    IList<string> failedIDs = folder.DeleteTree(true, null, true);
                    if (failedIDs == null || failedIDs.Count != 0)
                    {
                        Logger.Error("Failed to completely delete remote folder " + folder.Path);
                        // TODO Should we retry? Maybe at least once, as a manual recursion instead of a DeleteTree.
                    }

                    // Delete the folder from database.
                    database.RemoveFolder(syncItem);
                }
                catch (CmisPermissionDeniedException e)
                {

                    // TODO: Add resource
                    string message = String.Format("フォルダ {0} に対して削除やリネームする権限がないため、サーバからこのフォルダを復元します(フォルダに含まれるファイル数が多い場合、復元に時間がかかります)。", syncItem.LocalPath);
                    Utils.NotifyUser(message);


                    // We don't have the permission to delete this folder. Warn and recreate it.
                    /*
                    Utils.NotifyUser("You don't have the necessary permissions to delete folder " + folder.Path
                        + "\nIf you feel you should be able to delete it, please contact your server administrator");
                    */
                    database.RemoveFolder(syncItem);
                    DownloadDirectory(folder, syncItem.RemotePath, syncItem.LocalPath);
                }
            }
开发者ID:aegif,项目名称:ASaasDriveClient,代码行数:35,代码来源:SynchronizedFolder.cs

示例5: SyncDownloadFolder

            /// <summary>
            /// Download a single folder from the CMIS server for sync.
            /// </summary>
            private bool SyncDownloadFolder(IFolder remoteSubFolder, string localFolder)
            {
                string name = remoteSubFolder.Name;
                string remotePathname = remoteSubFolder.Path;
                string localSubFolder = Path.Combine(localFolder, name);
                if (!Directory.Exists(localFolder))
                {
                    // The target folder has been removed/renamed => relaunch sync
                    Logger.Warn("The target folder has been removed/renamed: " + localFolder);
                    return false;
                }

                if (Directory.Exists(localSubFolder))
                {
                    return true;
                }

                if (database.ContainsFolder(localSubFolder))
                {
                    // If there was previously a folder with this name, it means that
                    // the user has deleted it voluntarily, so delete it from server too.

                    // Delete the folder from the remote server.
                    Logger.Debug(String.Format("CMIS::DeleteTree({0})", remoteSubFolder.Path));
                    try
                    {
                        remoteSubFolder.DeleteTree(true, null, true);
                        // Delete the folder from database.
                        database.RemoveFolder(localSubFolder);
                    }
                    catch (Exception)
                    {
                        Logger.Info("Remote Folder could not be deleted: " + remoteSubFolder.Path);
                        // Just go on and try it the next time
                    }
                }
                else
                {
                    // The folder has been recently created on server, so download it.

                    // If there was previously a file with this name, delete it.
                    // TODO warn if local changes in the file.
                    if (File.Exists(localSubFolder))
                    {
                        Logger.Warn("Local file \"" + localSubFolder + "\" has been renamed to \"" + localSubFolder + ".conflict\"");
                        File.Move(localSubFolder, localSubFolder + ".conflict");
                    }

                    // Skip if invalid folder name. See https://github.com/nicolas-raoul/CmisSync/issues/196
                    if (Utils.IsInvalidFolderName(name))
                    {
                        Logger.Info("Skipping download of folder with illegal name: " + name);
                    }
                    else if (repoinfo.isPathIgnored(remotePathname))
                    {
                        Logger.Info("Skipping dowload of ignored folder: " + remotePathname);
                    }
                    else
                    {
                        // Create local folder.remoteDocument.Name
                        Logger.Info("Creating local directory: " + localSubFolder);
                        Directory.CreateDirectory(localSubFolder);

                        // Create database entry for this folder.
                        // TODO - Yannick - Add metadata
                        database.AddFolder(localSubFolder, remoteSubFolder.Id, remoteSubFolder.LastModificationDate);
                    }
                }

                return true;
            }
开发者ID:pcreignou,项目名称:CmisSync,代码行数:74,代码来源:SynchronizedFolder.cs

示例6: CrawlRemoteFolder

        /// <summary>
        /// Crawl remote subfolder, syncing down if needed.
        /// Meanwhile, cache all contained remote folders, they are output parameters that are used in CrawlLocalFiles/CrawlLocalFolders
        /// </summary>
        private void CrawlRemoteFolder(IFolder remoteSubFolder, string localFolder, IList<string> remoteFolders)
        {
            CheckPendingCancelation();

            try
            {
                if (SyncUtils.IsWorthSyncing(localFolder, remoteSubFolder.Name, SyncFolderInfo))
                {
                    // Logger.Debug("CrawlRemote localFolder:\"" + localFolder + "\" remoteSubFolder.Path:\"" + remoteSubFolder.Path + "\" remoteSubFolder.Name:\"" + remoteSubFolder.Name + "\"");
                    remoteFolders.Add(remoteSubFolder.Name);

                    SyncItem subFolderItem = getSyncItemFromRemotePath(remoteSubFolder.Path);

                    // Check whether local folder exists.
                    if (Directory.Exists(subFolderItem.LocalPath))
                    {
                        // Recurse into folder.
                        CrawlSync(remoteSubFolder, subFolderItem.LocalPath);
                    }
                    else
                    {
                        // If there was previously a file with this name, delete it.
                        // TODO warn if local changes in the file.
                        if (File.Exists(subFolderItem.LocalPath))
                        {

                            File.Delete(subFolderItem.LocalPath);

                        }

                        if (database.ContainsFolder(subFolderItem))
                        {
                            // If there was previously a folder with this name, it means that
                            // the user has deleted it voluntarily, so delete it from server too.

                            // Delete the folder from the remote server.
                            try
                            {
                                Logger.Debug("Removing remote folder tree: " + remoteSubFolder.Path);
                                IList<string> failedIDs = remoteSubFolder.DeleteTree(true, null, true);
                                if (failedIDs == null || failedIDs.Count != 0)
                                {
                                    Logger.Error("Failed to completely delete remote folder " + remoteSubFolder.Path);
                                    // TODO Should we retry? Maybe at least once, as a manual recursion instead of a DeleteTree.
                                }
                            }
                            catch (CmisPermissionDeniedException e)
                            {
                                HandleException(new DeleteRemoteFolderException(remoteSubFolder.Path, e));
                                //restore the folder
                                //TODO: check permissions before deleting the folder
                                DownloadFolder(remoteSubFolder, localFolder);
                                return;
                            }

                            // Delete the folder from database.
                            database.RemoveFolder(subFolderItem);

                        }
                        else
                        {
                            if (SyncUtils.IsInvalidFileName(remoteSubFolder.Name))
                            {
                                Logger.Warn("Skipping remote folder with name invalid on local filesystem: " + remoteSubFolder.Name);
                            }
                            else
                            {
                                // The folder has been recently created on server, so download it.

                                Directory.CreateDirectory(subFolderItem.LocalPath);

                                // Create database entry for this folder.
                                // TODO - Yannick - Add metadata
                                database.AddFolder(subFolderItem, remoteSubFolder.Id, remoteSubFolder.LastModificationDate);
                                Logger.Info("Added folder to database: " + subFolderItem.LocalPath);

                                // Recursive copy of the whole folder.
                                RecursiveFolderCopy(remoteSubFolder, subFolderItem.LocalPath);

                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {

                HandleException(new DownloadFolderException(remoteSubFolder.Path, e));
            }
        }
开发者ID:lelmarir,项目名称:CmisSync,代码行数:94,代码来源:SyncFolderSyncronizer_CrawlStrategy.cs


注:本文中的IFolder.DeleteTree方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。