Beispiel #1
0
        public static IReadOnlyCollection <string> BackupFolder(string pSourceRoot, string pDestinationRoot, Action <double, string> pCallbackStatus, StreamWriter pLogger, int pIORetries)
        {
            pDestinationRoot = StringControls.NormalizeFolderPath(pDestinationRoot);
            string rel = DateTime.Now.ToString("yyyyMMdd HH.mm.ss tt");

            return(CopyFolder(pSourceRoot, pDestinationRoot + rel, pCallbackStatus, pLogger, pIORetries));
        }
Beispiel #2
0
        private void btnRestoreBackup_Click(object sender, EventArgs e)
        {
            string pathBackup;
            {
                var fbd = new FolderBrowserDialog();
                fbd.SelectedPath = this._PC_RootBackups.Value;

                var dr = fbd.ShowDialog();

                if (dr != DialogResult.OK && dr != DialogResult.Yes)
                {
                    return;
                }

                pathBackup = StringControls.NormalizeFolderPath(fbd.SelectedPath);
            }

            string msg = string.Format("Restoring Backup ({0}) to Production-Live", Path.GetDirectoryName(pathBackup));

            List <Tuple <Func <IReadOnlyCollection <string> >, string> > commands = new List <Tuple <Func <IReadOnlyCollection <string> >, string> >();

            commands.Add(new Tuple <Func <IReadOnlyCollection <string> >, string>(() => FileOperations.CopyFolder(pathBackup, this._PC_RootProductionLive.Value, this.UpdateTaskStatus, this._Log, IORetries), msg));
            commands.Add(new Tuple <Func <IReadOnlyCollection <string> >, string>(() => FileOperations.CopyWebConfig(this._PC_ConfigProductionLive.Value, this._PC_RootProductionLive.Value, this.UpdateTaskStatus, this._Log, IORetries), "Copying web.config to Production-Live"));

            this.RunCommands(msg, commands);
        }
Beispiel #3
0
        public static IReadOnlyCollection <string> ClearExtraFiles(string pSourceRoot, string pDestinationRoot, Action <double, string> pCallbackStatus, StreamWriter pLogger, int pIORetries)
        {
            pSourceRoot      = StringControls.NormalizeFolderPath(pSourceRoot);
            pDestinationRoot = StringControls.NormalizeFolderPath(pDestinationRoot);
            pCallbackStatus(0, "Calculating...");

            var filesSrc   = Directory.GetFiles(pSourceRoot, "*", SearchOption.AllDirectories);
            var foldersSrc = Directory.GetDirectories(pSourceRoot, "*", SearchOption.AllDirectories);

            var filesDst   = Directory.GetFiles(pDestinationRoot, "*", SearchOption.AllDirectories);
            var foldersDst = Directory.GetDirectories(pDestinationRoot, "*", SearchOption.AllDirectories);

            int           itemCount = filesDst.Length + foldersDst.Length;
            List <string> errors    = new List <string>();
            int           iItem     = 0;

            foreach (var file in filesDst)
            {
                pCallbackStatus(
                    ++iItem / (double)itemCount,
                    string.Format("Checking for leftovers - {0} : {1}",
                                  Path.GetDirectoryName(file),
                                  Path.GetFileName(file)));

                var relFile = file.Substring(pDestinationRoot.Length);
                var dstFile = pDestinationRoot + relFile;
                var srcFile = pSourceRoot + relFile;
                if (!File.Exists(srcFile))
                {
                    AttemptAction(pIORetries, () => File.Delete(dstFile), "deleting leftover file: " + relFile, errors, pLogger);
                }
            }

            foreach (var folder in foldersDst)
            {
                pCallbackStatus(++iItem / (double)itemCount, "Checking for leftovers: " + folder);

                var relFolder = folder.Substring(pDestinationRoot.Length);
                var dstFolder = pDestinationRoot + relFolder;
                var srcFolder = pSourceRoot + relFolder;
                if (!Directory.Exists(srcFolder))
                {
                    AttemptAction(pIORetries, () => Directory.Delete(dstFolder, true), "deleting leftover folder: " + relFolder, errors, pLogger);
                }
            }

            return(errors);
        }
Beispiel #4
0
        public static IReadOnlyCollection <string> CopyFolder(string pSourceRoot, string pDestinationRoot, Action <double, string> pCallbackStatus, StreamWriter pLogger, int pIORetries)
        {
            pSourceRoot      = StringControls.NormalizeFolderPath(pSourceRoot);
            pDestinationRoot = StringControls.NormalizeFolderPath(pDestinationRoot);
            pCallbackStatus(0, "Calculating...");

            var           files     = Directory.GetFiles(pSourceRoot, "*", SearchOption.AllDirectories);
            var           folders   = Directory.GetDirectories(pSourceRoot, "*", SearchOption.AllDirectories);
            int           itemCount = files.Length + folders.Length;
            List <string> errors    = new List <string>();
            int           iItem     = 0;

            foreach (var folder in folders)
            {
                pCallbackStatus(++iItem / (double)itemCount, "Creating " + folder);

                var relFolder = folder.Substring(pSourceRoot.Length);
                var dstFolder = pDestinationRoot + relFolder;
                AttemptAction(pIORetries, () => Directory.CreateDirectory(dstFolder), "creating folder: " + relFolder, errors, pLogger);
            }

            foreach (var file in files)
            {
                pCallbackStatus(
                    ++iItem / (double)itemCount,
                    string.Format("Copying {0} : {1}",
                                  Path.GetDirectoryName(file),
                                  Path.GetFileName(file)));

                var relFile = file.Substring(pSourceRoot.Length);
                var dstFile = pDestinationRoot + relFile;
                AttemptAction(pIORetries, () => File.Copy(file, dstFile, true), "copying file: " + relFile, errors, pLogger);
            }

            return(errors);
        }
Beispiel #5
0
        public static IReadOnlyCollection <string> ClearFolder(string pFolder, Action <double, string> pCallbackStatus, StreamWriter pLogger, int pIORetries)
        {
            pFolder = StringControls.NormalizeFolderPath(pFolder);
            pCallbackStatus(0, "Calculating...");

            var files   = Directory.GetFiles(pFolder, "*", SearchOption.AllDirectories);
            var folders = Directory.GetDirectories(pFolder, "*", SearchOption.AllDirectories);

            int itemCount = files.Length + folders.Length;

            List <string> errors = new List <string>();
            int           iItem  = 0;

            foreach (var file in files)
            {
                pCallbackStatus(
                    ++iItem / (double)itemCount,
                    string.Format("Deleting {0} : {1}",
                                  Path.GetDirectoryName(file),
                                  Path.GetFileName(file)));

                AttemptAction(pIORetries, () => File.Delete(file), "deleting file: " + file, errors, pLogger);
            }

            foreach (var folder in folders)
            {
                pCallbackStatus(++iItem / (double)itemCount, "Deleting " + folder);

                if (Directory.Exists(folder))
                {
                    AttemptAction(pIORetries, () => Directory.Delete(folder, true), "deleting folder: " + folder, errors, pLogger);
                }
            }

            return(errors);
        }