public FormDeployProcess2(DeployLib.DeployProject project, DeployCmd cmd)
 {
     InitializeComponent();
     this.project = project;
     this.deployCmd = cmd;
 }
示例#2
0
        private void CopySingleFile(string sourceRoot, string sourceFullname, string destRoot,
            int deployed, ref int deployedIndex, int count,
            ref DeployEntryReport report, Func<int, object, bool> actReportProgress,
            DeployCmd cmd)
        {
            try
            {
                if (cmd == null) { cmd = new DeployCmd(false); }
                if (!cmd.CancelDeploy)
                {
                    var sourceSubFullname = sourceFullname.Substring(sourceRoot.Length);
                    var destFullname = destRoot + sourceSubFullname;

                    var destDir = Path.GetDirectoryName(destFullname);
                    var destFileExists = File.Exists(destFullname);
                    var sourceFile = new FileInfo(sourceFullname);
                    var deploy = true;
                    if (!Directory.Exists(destDir))
                    { Directory.CreateDirectory(destDir); }
                    else if (destFileExists)
                    {
                        if (!(cmd.ForceDeploy))
                        {
                            var destFile = new FileInfo(destFullname);
                            if (sourceFile.LastWriteTime <= destFile.LastWriteTime)
                            { deploy = false; }
                        }
                    }

                    if (deploy)
                    {
                        DoCopySingleFile(sourceFullname, deployed, deployedIndex, count, actReportProgress, cmd, destFullname, destFileExists, sourceFile);
                    }
                    else
                    {
                        if (actReportProgress != null)
                        {
                            actReportProgress(
                                100 * (deployed + deployedIndex + 1) / count,
                                new UserState(false, sourceFullname, destFullname, sourceFile.Length, DateTime.Now, this));
                        }
                    }
                }
            }
            catch (Exception e)
            {
                var singleFileReport = new SingleFileReport() { Error = e, };
                report.Add(singleFileReport);
            }

            deployedIndex++;
        }
示例#3
0
        private void DoCopySingleFile(string sourceFullname, int deployed, int deployedIndex, int count, Func<int, object, bool> actReportProgress, DeployCmd cmd, string destFullname, bool destFileExists, FileInfo sourceFile)
        {
            if (destFileExists)
            { File.SetAttributes(destFullname, System.IO.FileAttributes.Normal); }

            if (!string.IsNullOrEmpty(this.Source.Ip))
            {
                var sourcePath = Path.GetDirectoryName(this.Source.Goods);
                WmiShareFunction.CreateShareNetConnect(
                    this.Source.Ip, sourcePath, //"C$",
                    this.Source.Username,
                    this.Source.Password);
            }
            if (!string.IsNullOrEmpty(this.DestinationDir.Ip))
            {
                WmiShareFunction.CreateShareNetConnect(
                    this.DestinationDir.Ip, this.DestinationDir.Goods, //"C$",
                    this.DestinationDir.Username,
                    this.DestinationDir.Password);
            }

            if (actReportProgress != null)
            {
                actReportProgress(
                    100 * (deployed + deployedIndex + 1) / count,
                    new UserState(true, sourceFullname, destFullname, sourceFile.Length, DateTime.Now, this));
            }
            if (!cmd.CancelDeploy)
            { File.Copy(sourceFullname, destFullname, true); }
        }
示例#4
0
        public Tuple<int, DeployEntryReport> Deploy(DeployCmd cmd,
            Func<int, object, bool> actReportProgress = null,
            int deployed = 0, int count = 0, bool forceDeploy = false)
        {
            var sourceFilenames = Path.GetFileName(this.Source.Goods);
            var sourceRoot = string.Empty;
            if (!string.IsNullOrEmpty(this.Source.Ip))
            {
                //WmiShareFunction.CreateShareNetConnect(
                //    this.Source.Ip, this.Source.Goods,
                //    this.Source.Username, this.Source.Password);
                sourceRoot = string.Format(@"\\{0}\{1}",
                    this.Source.Ip, Path.GetDirectoryName(this.Source.Goods));
            }
            else
            { sourceRoot = Path.GetDirectoryName(this.Source.Goods); }
            var sourceFullnames = Directory.GetFiles(sourceRoot, sourceFilenames, SearchOption.AllDirectories);

            var destRoot = string.Empty;
            if (!string.IsNullOrEmpty(this.DestinationDir.Ip))
            {
                //WmiShareFunction.CreateShareNetConnect(
                //    this.DestinationDir.Ip, this.DestinationDir.Goods,
                //    this.DestinationDir.Username, this.DestinationDir.Password);
                destRoot = string.Format(@"\\{0}\{1}",
                    this.DestinationDir.Ip, this.DestinationDir.Goods);
            }
            else
            { destRoot = new DirectoryInfo(this.DestinationDir.Goods).FullName; }

            int deployedIndex = 0;
            var report = new DeployEntryReport(this);
            foreach (var sourceFullname in sourceFullnames)
            {
                CopySingleFile(sourceRoot, sourceFullname, destRoot,
                    deployed, ref deployedIndex, count, ref report, actReportProgress,
                    cmd);
            }

            return new Tuple<int, DeployEntryReport>(deployedIndex, report);
        }