Ejemplo n.º 1
0
        public static int ConverBackupProfileFolderToNewPath(this BackupProfileData profile, string path)
        {
            int iCount = -1;

            var subdirectoryList = GetDirectoriesNames(profile, path);

            if (subdirectoryList == null || subdirectoryList.Count() == 0)
            {
                return(0);
            }
            else
            {
                iCount = 0;
                foreach (string subDirectory in subdirectoryList)
                {
                    string sourcePath = profile.GetStorageInterface().Combine(path, subDirectory);
                    if (profile.GetStorageInterface().IsFolder(sourcePath) && (subDirectory.Length >= 36))
                    {
                        try
                        {
                            Guid newGuid = Guid.Parse(subDirectory.Substring(0, 36));
                            if (profile.GUID != newGuid)
                            {
                                var sub1 = subDirectory.Substring(36, subDirectory.Length - 36);
                                var sub2 = subDirectory.Remove(36);

                                var    destDirectory = profile.GUID.ToString("D") + subDirectory.Substring(36, subDirectory.Length - 36);
                                string targetPath    = profile.GetStorageInterface().Combine(path, destDirectory);
                                if (profile.GetStorageInterface().MoveDirectory(sourcePath, targetPath))
                                {
                                    iCount++;
                                }
                            }
                        }
                        catch (ArgumentNullException)
                        {
                            Console.WriteLine("The string to be parsed is null.");
                        }
                        catch (FormatException)
                        {
                            //                                    Console.WriteLine("Bad format: {0}", subDirectory);
                        }
                    }
                }
            }

            return(iCount);
        }
Ejemplo n.º 2
0
        public static List <string> GetDirectoriesNames(this BackupProfileData profile, string path)
        {
            //Process directories
            string[] sourceSubdirectoryEntries     = profile.GetStorageInterface().GetDirectories(path);
            var      sourceSubdirectoryEntriesList = new List <string>();

            if (sourceSubdirectoryEntries != null)
            {
                if (sourceSubdirectoryEntriesList != null)
                {
                    foreach (var entry in sourceSubdirectoryEntries)
                    {
                        sourceSubdirectoryEntriesList.Add(profile.GetStorageInterface().GetFileName(entry));
                    }
                }
            }

            return(sourceSubdirectoryEntriesList);
        }
Ejemplo n.º 3
0
        public static ProfileTargetFolderStatusEnum GetProfileTargetFolderStatus(this BackupProfileData profile, string path)
        {
            ProfileTargetFolderStatusEnum profileStatus;

            if (!profile.GetStorageInterface().DirectoryExists(path))
            {
                profileStatus = ProfileTargetFolderStatusEnum.InvalidTargetPath;
            }
            else
            {
                var subdirectoryList = GetDirectoriesNames(profile, path);

                if (subdirectoryList == null || subdirectoryList.Count() == 0)
                {
                    profileStatus = ProfileTargetFolderStatusEnum.EmptyFolderNoProfile;
                }
                else
                {
                    int iMatchCount      = 0;
                    int iOtherMatchCount = 0;
                    foreach (string subDirectory in subdirectoryList)
                    {
                        string newPath = profile.GetStorageInterface().Combine(path, subDirectory);
                        if (profile.GetStorageInterface().IsFolder(newPath))
                        {
                            if (subDirectory.StartsWith(profile.GUID.ToString("D")))
                            {
                                iMatchCount++;
                            }
                            else
                            {
                                try
                                {
                                    if (subDirectory.Length > 36)
                                    {
                                        Guid newGuid = Guid.Parse(subDirectory.Substring(0, 32 + 4));
                                        iOtherMatchCount++;
                                    }
                                }
                                catch (ArgumentNullException)
                                {
                                    Console.WriteLine("The string to be parsed is null.");
                                }
                                catch (FormatException)
                                {
                                    //                                    Console.WriteLine("Bad format: {0}", subDirectory);
                                }
                            }
                        }
                    }

                    if (iMatchCount == subdirectoryList.Count)
                    {
                        profileStatus = ProfileTargetFolderStatusEnum.AssosiatedWithThisProfile;
                    }
                    else if (iMatchCount == 0 && iOtherMatchCount == 0)
                    {
                        profileStatus = ProfileTargetFolderStatusEnum.NonEmptyFolderNoProfile;
                    }
                    else if (iOtherMatchCount > 0)
                    {
                        profileStatus = ProfileTargetFolderStatusEnum.AssosiatedWithADifferentProfile;
                    }
                    else
                    {
                        profileStatus = ProfileTargetFolderStatusEnum.CoccuptedOrNotRecognizedProfile;
                    }
                }
            }

            return(profileStatus);
        }