コード例 #1
0
        /// <summary>
        /// Removes a folder recursively from the offline DB
        /// </summary>
        /// <param name="folderPath">Path of the folder</param>
        /// <returns>TRUE if all went weel or FALSE in other case.</returns>
        public static bool RemoveFolderFromOfflineDB(string folderPath)
        {
            if (string.IsNullOrWhiteSpace(folderPath))
            {
                return(false);
            }

            bool result = true;

            if (FolderService.FolderExists(folderPath))
            {
                try
                {
                    IEnumerable <string> childFolders = Directory.GetDirectories(folderPath);
                    if (childFolders != null)
                    {
                        foreach (var folder in childFolders)
                        {
                            if (folder != null)
                            {
                                result &= RemoveFolderFromOfflineDB(folder);
                                result &= SavedForOfflineDB.DeleteNodeByLocalPath(folder);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_ERROR,
                                   string.Format("Error removing from the offline DB the subfolders of '{0}'", folderPath), e);
                    result = false;
                }

                try
                {
                    IEnumerable <string> childFiles = Directory.GetFiles(folderPath);
                    if (childFiles != null)
                    {
                        foreach (var file in childFiles)
                        {
                            if (file != null)
                            {
                                result &= SavedForOfflineDB.DeleteNodeByLocalPath(file);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_ERROR,
                                   string.Format("Error removing from the offline DB the files of '{0}'", folderPath), e);
                    result = false;
                }
            }

            result &= SavedForOfflineDB.DeleteNodeByLocalPath(folderPath);

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Checks if the previous folders of an offline folder node path are empty
        /// and removes them from the offline folder and the DB on this case.
        /// </summary>
        /// <param name="folderNodePath">Path of the folder node</param>
        /// <returns>TRUE if the process finished successfully or FALSE in other case.</returns>
        public static bool CleanOfflineFolderNodePath(string folderNodePath)
        {
            if (string.IsNullOrWhiteSpace(folderNodePath))
            {
                return(false);
            }

            var result = true;

            while (string.CompareOrdinal(folderNodePath, AppService.GetOfflineDirectoryPath()) != 0)
            {
                try
                {
                    if (!FolderService.FolderExists(folderNodePath))
                    {
                        return(false);
                    }

                    var folderPathToRemove = folderNodePath;
                    if (!FolderService.IsEmptyFolder(folderPathToRemove))
                    {
                        return(true);
                    }

                    var directoryInfo = new DirectoryInfo(folderNodePath).Parent;
                    if (directoryInfo == null)
                    {
                        return(true);
                    }
                    folderNodePath = directoryInfo.FullName;

                    result &= FolderService.DeleteFolder(folderPathToRemove);
                    result &= SavedForOfflineDB.DeleteNodeByLocalPath(folderPathToRemove);
                }
                catch (Exception e)
                {
                    LogService.Log(MLogLevel.LOG_LEVEL_ERROR,
                                   string.Format("Error cleaning offline node path '{0}'", folderNodePath), e);
                    return(false);
                }
            }

            return(result);
        }
コード例 #3
0
        private static List <string> GetDownloadDirectoryFiles(string path)
        {
            var files = new List <string>();

            if (FolderService.FolderExists(path))
            {
                try
                {
                    files.AddRange(Directory.GetFiles(path));

                    var folders = new List <string>();
                    folders.AddRange(Directory.GetDirectories(path));

                    foreach (var folder in folders)
                    {
                        files.AddRange(GetDownloadDirectoryFiles(folder));
                    }
                }
                catch (Exception e) { throw e.GetBaseException(); }
            }

            return(files);
        }