Beispiel #1
0
        /// <summary>
        /// Generates all actions where the source type is directory, and the whole directory is copied
        /// </summary>
        /// <param name="pinfo">PublisherInfo representing the source</param>
        /// <param name="dest">PublisherDestination represeting the target</param>
        public void GenerateActionsForDirectoryFull(PublisherInfo pinfo, PublisherDestination dest)
        {
            if (Directory.Exists(pinfo.SourcePath) && Directory.Exists(Directory.GetParent(pinfo.SourcePath).FullName) &&
                _CurrentUserSecurity.HasAccess(new DirectoryInfo(pinfo.SourcePath), FileSystemRights.Read))
            {
                foreach (string folder in Directory.EnumerateDirectories(pinfo.SourcePath, "*",
                                                                         SearchOption.AllDirectories).Select(s => s.Replace(pinfo.SourcePath, String.Empty)))
                {
                    Actions.Add(new PublisherAction
                    {
                        Type       = PublisherTypes.ActionType.CreateDirectory,
                        TargetPath = PublisherIO.AppendDirectorySeparatorToDirectoryPath(Path.Combine(dest.TargetPath, Path.GetFileName(Path.GetDirectoryName(pinfo.SourcePath)), folder))
                    });
                }
                foreach (string file in Directory.EnumerateFiles(pinfo.SourcePath, "*", SearchOption.AllDirectories))
                {
                    string targetfile = Path.Combine(
                        dest.TargetPath,
                        Path.GetFileName(
                            Path.GetDirectoryName(pinfo.SourcePath)),
                        file.Replace(pinfo.SourcePath, String.Empty).Replace(Path.GetFileName(file), String.Empty),
                        Path.GetFileName(file));

                    Actions.Add(new PublisherAction
                    {
                        Type = (dest.Modes.Contains(PublisherTypes.PublisherMode.Overwrite) || pinfo.Modes.Contains(PublisherTypes.PublisherMode.Overwrite)) ?
                               PublisherTypes.ActionType.CopyFileToFileOverwrite : PublisherTypes.ActionType.CopyFileToFile,
                        SourcePath = file,
                        TargetPath = targetfile
                    });
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Runs all actions
        /// </summary>
        public void RunAllActions()
        {
            for (int i = 0; i < Actions.Count; i++)
            {
                switch (Actions[i].Type)
                {
                case PublisherTypes.ActionType.CreateDirectory:
                    Actions[i].Result = PublisherIO.CreateDirectory(Actions[i].TargetPath, _CurrentUserSecurity);
                    ActionDone?.Invoke(i + 1, Actions.Count, Actions[i]);
                    break;

                case PublisherTypes.ActionType.ArchiveDirectory:
                    Actions[i].Result = PublisherIO.ArchiveDirectory(Actions[i].SourcePath, _CurrentUserSecurity, Actions[i].TargetPath);
                    ActionDone?.Invoke(i + 1, Actions.Count, Actions[i]);
                    break;

                case PublisherTypes.ActionType.ArchiveDirectoryOverwrite:
                    Actions[i].Result = PublisherIO.ArchiveDirectory(Actions[i].SourcePath, _CurrentUserSecurity, Actions[i].TargetPath, overwritearchive: true);
                    ActionDone?.Invoke(i + 1, Actions.Count, Actions[i]);
                    break;

                case PublisherTypes.ActionType.ArchiveFile:
                    Actions[i].Result = PublisherIO.ArchiveFile(Actions[i].SourcePath, _CurrentUserSecurity, Actions[i].TargetPath);
                    ActionDone?.Invoke(i + 1, Actions.Count, Actions[i]);
                    break;

                case PublisherTypes.ActionType.ArchiveFileOverwrite:
                    Actions[i].Result = PublisherIO.ArchiveFile(Actions[i].SourcePath, _CurrentUserSecurity, Actions[i].TargetPath, overwritearchvie: true);
                    ActionDone?.Invoke(i + 1, Actions.Count, Actions[i]);
                    break;

                case PublisherTypes.ActionType.CopyFileToDirectory:
                    Actions[i].Result = PublisherIO.CopyFileToDirectory(Actions[i].SourcePath, Actions[i].TargetPath, _CurrentUserSecurity, false);
                    ActionDone?.Invoke(i + 1, Actions.Count, Actions[i]);
                    break;

                case PublisherTypes.ActionType.CopyFileToDirectoryOverwrite:
                    Actions[i].Result = PublisherIO.CopyFileToDirectory(Actions[i].SourcePath, Actions[i].TargetPath, _CurrentUserSecurity, true);
                    ActionDone?.Invoke(i + 1, Actions.Count, Actions[i]);
                    break;

                case PublisherTypes.ActionType.CopyFileToFile:
                    Actions[i].Result = PublisherIO.CopyFileToFile(Actions[i].SourcePath, Actions[i].TargetPath, _CurrentUserSecurity, false);
                    ActionDone?.Invoke(i + 1, Actions.Count, Actions[i]);
                    break;

                case PublisherTypes.ActionType.CopyFileToFileOverwrite:
                    Actions[i].Result = PublisherIO.CopyFileToFile(Actions[i].SourcePath, Actions[i].TargetPath, _CurrentUserSecurity, true);
                    ActionDone?.Invoke(i + 1, Actions.Count, Actions[i]);
                    break;

                default:
                    break;
                }
            }
        }