Beispiel #1
0
        private void DoCopyTask(object state)
        {
            CopyTask copyTask = state as CopyTask;

            foreach (string f in copyTask.files)
            {
                string   targetPath = copyTask.targetDir + "\\" + Path.GetFileName(f);
                FileInfo sourceInfo = new FileInfo(f);
                FileInfo targetInfo = null;

                if (File.Exists(targetPath))
                {
                    targetInfo = new FileInfo(targetPath);
                }

                try
                {
                    if (targetInfo == null || targetInfo.LastWriteTime < sourceInfo.LastWriteTime)
                    {
                        File.Copy(f, targetPath, true);
                        Log(string.Format("{0} Copyed.", f));
                    }
                    else
                    {
                        // Skip..
                    }
                }
                catch (Exception ex)
                {
                    LogFile("Copy from {0} to {1} fail : {2}\r\n {3}", f, targetPath, ex.Message, ex.StackTrace);
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Executes the task.
        /// </summary>
        protected override void ExecuteTask()
        {
            String baseFolder = this.CreateBaseDir();
            DocSet docSet     = this.CreateDocSet();
            IEnumerable <Framework> frameworks = this.CreateFrameworks(docSet);

            foreach (var f in frameworks)
            {
                if (f.source != DocumentOrigin.Doxygen)
                {
                    continue;
                }

                this.Log(Level.Info, "Copying header files for '{0}'...", f.name);

                FileSet fileSet = new FileSet();
                fileSet.BaseDirectory = new DirectoryInfo(f.path);
                fileSet.Includes.Add("**/*.h");

                CopyTask copyTask = new CopyTask();
                copyTask.Project     = this.Project;
                copyTask.FailOnError = true;
                if (docSet != null)
                {
                    copyTask.ToDirectory = new DirectoryInfo(Path.Combine(baseFolder, docSet.Name, f.name, DocumentType.Source.ToString()));
                }
                else
                {
                    copyTask.ToDirectory = new DirectoryInfo(Path.Combine(baseFolder, f.name, DocumentType.Source.ToString()));
                }
                copyTask.CopyFileSet = fileSet;
                copyTask.Filters     = this.Filters;
                copyTask.Execute();
            }
        }
        private void CopyFileSet(FileSet fileSet, String toDir)
        {
            CopyTask task = new CopyTask();

            task.Project = this.Project;
            task.InitializeTaskConfiguration();
            task.ToDirectory = new DirectoryInfo(toDir);
            task.CopyFileSet = fileSet;
            task.Execute();
        }
        private void CopyFile(FileInfo fileInfo, String toDir)
        {
            CopyTask task = new CopyTask();

            task.Project = this.Project;
            task.InitializeTaskConfiguration();
            task.ToDirectory = new DirectoryInfo(toDir);
            task.SourceFile  = fileInfo;
            task.Execute();
        }
Beispiel #5
0
        public void Copy()
        {
            var t = new CopyTask(_source, _dest);

            t.Execute();

            string s = File.ReadAllText(Path.Combine(_dest, "test.txt"));

            Assert.AreEqual("the test\r\n", s);
        }
        public void CopyTask_Perform()
        {
            CopyTask target = new CopyTask();

            target.Source      = @"D:\Videos\DARDASIM_2.iso";
            target.Destination = @"c:\temp\DARDASIM_2.iso";
            var res = target.Perform();

            Assert.AreEqual(ResultStatus.Completed, res.Status);
        }
Beispiel #7
0
        /// <summary>
        /// Copies the specified file if the destination file does not exist, or
        /// the source file has been modified since it was previously copied.
        /// </summary>
        /// <param name="srcFile">The file to copy.</param>
        /// <param name="destFile">The destination file.</param>
        /// <param name="parent">The <see cref="Task" /> in which context the operation will be performed.</param>
        protected void CopyFile(FileInfo srcFile, FileInfo destFile, Task parent)
        {
            // create instance of Copy task
            CopyTask ct = new CopyTask();

            // parent is solution task
            ct.Parent = parent;

            // inherit project from parent task
            ct.Project   = parent.Project;
            ct.CallStack = parent.CallStack;

            // inherit namespace manager from parent task
            ct.NamespaceManager = parent.NamespaceManager;

            // inherit verbose setting from parent task
            ct.Verbose = parent.Verbose;

            // only output warning messages or higher, unless
            // we're running in verbose mode
            if (!ct.Verbose)
            {
                ct.Threshold = Level.Warning;
            }

            // make sure framework specific information is set
            ct.InitializeTaskConfiguration();

            // set parent of child elements
            ct.CopyFileSet.Parent = ct;

            // inherit project for child elements from containing task
            ct.CopyFileSet.Project   = ct.Project;
            ct.CopyFileSet.CallStack = ct.CallStack;

            // inherit namespace manager from containing task
            ct.CopyFileSet.NamespaceManager = ct.NamespaceManager;

            // set file to copy
            ct.SourceFile = srcFile;

            // set file
            ct.ToFile = destFile;

            // increment indentation level
            ct.Project.Indent();

            try {
                // execute task
                ct.Execute();
            } finally {
                // restore indentation level
                ct.Project.Unindent();
            }
        }
        public void CopyTask_CheckCancel()
        {
            CopyTask target = new CopyTask();

            target.Source      = @"D:\Videos\DARDASIM_2.iso";
            target.Destination = @"c:\temp\DARDASIM_2.iso";
            Task.Factory.StartNew(() => {
                Thread.Sleep(2000);
                target.Cancel();
            });
            var res = target.Perform();

            Assert.AreEqual(ResultStatus.Failed, res.Status);
        }
        GivenSourcePathDestPathRecursiveAndFilePattern__WhenCallingBuild__ShouldReturnCopyTaskWithMatchingConfig()
        {
            CopyTaskBuilder sut = new CopyTaskBuilder(new CopyPolicyDummy(), new MockFileSystem());

            ConfigureTask(sut);

            CopyTask task = (CopyTask)sut.Build();

            Assert.AreEqual(TaskId, task.Id);
            Assert.AreEqual(TaskName, task.Name);
            Assert.AreEqual(TheSourcePath, task.Source);
            Assert.AreEqual(TheDestPath, task.Destination);
            Assert.AreEqual(FilePattern, task.FilePattern);
            Assert.AreEqual(AlwaysOverwrite, task.AlwaysOverwrite);
            Assert.IsTrue(task.Recursive);
        }
        public void GivenTaskBuiltWithValidConfiguration__WhenRunningTask__ShouldCopyPolicyShouldBeCalled()
        {
            MockFileSystem fileSystem = new MockFileSystem(new Dictionary <string, MockFileData>
            {
                { TheSourcePath, string.Empty }
            });
            CopyPolicySpy copyPolicySpy = new CopyPolicySpy();

            CopyTaskBuilder sut = new CopyTaskBuilder(copyPolicySpy, fileSystem);

            ConfigureTask(sut);
            CopyTask task = (CopyTask)sut.Build();

            task.Run();

            Assert.IsTrue(copyPolicySpy.CopyCalled);
        }
Beispiel #11
0
        public void GivenPathToFileAndDestination__WhenCallingRun__ShouldCopyUsingCopyPolicy()
        {
            MockFileSystemWithFileInfoCopySpy fileSystem = new MockFileSystemWithFileInfoCopySpy();
            CopyPolicySpy copyPolicySpy = new CopyPolicySpy();

            fileSystem.FileSystem.AddFile("Data/MyFile.txt", string.Empty);

            const string destination = "Copy/MyFile.txt";

            _sut = new CopyTask(copyPolicySpy, fileSystem)
            {
                Source      = "Data/MyFile.txt",
                Destination = destination
            };

            _sut.Run();

            Assert.IsTrue(copyPolicySpy.CopyCalled);
            Assert.IsFalse(((FileInfoCopySpy)fileSystem.FileInfo.FromFileName("Data/MyFile.txt")).FileWasCopied);
        }
Beispiel #12
0
        private void CopyFiles(string filter, string fromdir, string todir)
        {
            string[] files = Directory.GetFiles(fromdir, filter);
            CopyTask task  = new CopyTask();

            task.files     = files;
            task.targetDir = todir;

            // µÈ´ýÓпÕÓàÏß³Ì
            while (GetAvilableThreadNum() == 0)
            {
                Thread.Sleep(10);
            }

            ThreadPool.QueueUserWorkItem(new WaitCallback(DoCopyTask), task);

            foreach (string dir in Directory.GetDirectories(fromdir))
            {
                CopyFiles(filter, dir, todir);
            }
        }
Beispiel #13
0
 /// <summary>
 /// 添加一条数据
 /// </summary>
 /// <param name="data">数据</param>
 /// <returns></returns>
 public ReturnPost CopyInsert(CopyTask data)
 {
     try
     {
         if (_col.FindOne(p => p.ComponentId == data.ComponentId && p.BridgeName == data.BridgeName) == null)
         {
             var copyData = _col.FindOne(p => p.Id == data.Id);
             if (copyData != null)
             {
                 copyData.Id         = Guid.NewGuid().ToString();
                 copyData.BridgeName = data.BridgeName;
                 _col.Insert(copyData);
                 var holeGroups = _holeGroup.Find(h => h.ParentId == data.Id);
                 foreach (var item in holeGroups)
                 {
                     item.Id       = Guid.NewGuid().ToString();
                     item.ParentId = copyData.Id;
                     _holeGroup.Insert(item);
                 }
                 return(new ReturnPost()
                 {
                     Data = copyData, Message = true
                 });
             }
         }
         return(new ReturnPost()
         {
             Message = false
         });
     }
     catch (Exception)
     {
         return(new ReturnPost()
         {
             Message = false
         });
     }
 }
Beispiel #14
0
 public IActionResult CopyTask(CopyTask data)
 {
     return(Json(_col.CopyInsert(data)));
 }
Beispiel #15
0
        /// <summary>
        /// Updates the <see cref="ProcessStartInfo" /> of the specified
        /// <see cref="Process"/>.
        /// </summary>
        /// <param name="process">The <see cref="Process" /> of which the <see cref="ProcessStartInfo" /> should be updated.</param>
        protected override void PrepareProcess(Process process)
        {
            if (!SupportsAssemblyReferences)
            {
                // create instance of Copy task
                CopyTask ct = new CopyTask();

                // inherit project from current task
                ct.Project = Project;

                // inherit namespace manager from current task
                ct.NamespaceManager = NamespaceManager;

                // parent is current task
                ct.Parent = this;

                // inherit verbose setting from license task
                ct.Verbose = Verbose;

                // only output warning messages or higher, unless we're running
                // in verbose mode
                if (!ct.Verbose)
                {
                    ct.Threshold = Level.Warning;
                }

                // make sure framework specific information is set
                ct.InitializeTaskConfiguration();

                // set parent of child elements
                ct.CopyFileSet.Parent = ct;

                // inherit project from solution task for child elements
                ct.CopyFileSet.Project = ct.Project;

                // inherit namespace manager from solution task
                ct.CopyFileSet.NamespaceManager = ct.NamespaceManager;

                // set base directory of fileset
                ct.CopyFileSet.BaseDirectory = Assemblies.BaseDirectory;

                // copy all files to base directory itself
                ct.Flatten = true;

                // copy referenced assemblies
                foreach (string file in Assemblies.FileNames)
                {
                    ct.CopyFileSet.Includes.Add(file);
                }

                // copy command line tool to working directory
                ct.CopyFileSet.Includes.Add(base.ProgramFileName);

                // set destination directory
                ct.ToDirectory = BaseDirectory;

                // increment indentation level
                ct.Project.Indent();
                try {
                    // execute task
                    ct.Execute();
                } finally {
                    // restore indentation level
                    ct.Project.Unindent();
                }

                // change program to execute the tool in working directory as
                // that will allow this tool to resolve assembly references
                // using assemblies stored in the same directory
                _programFileName = Path.Combine(BaseDirectory.FullName,
                                                Path.GetFileName(base.ProgramFileName));

                // determine target directory
                string targetDir = Path.GetDirectoryName(Path.Combine(
                                                             BaseDirectory.FullName, Target));
                // ensure target directory exists
                if (!String.IsNullOrEmpty(targetDir) && !Directory.Exists(targetDir))
                {
                    Directory.CreateDirectory(targetDir);
                }
            }
            else
            {
                foreach (string assembly in Assemblies.FileNames)
                {
                    Arguments.Add(new Argument(string.Format(CultureInfo.InvariantCulture,
                                                             "/i:\"{0}\"", assembly)));
                }
            }

            // further delegate preparation to base class
            base.PrepareProcess(process);
        }
Beispiel #16
0
        /// <summary>
        /// Updates the <see cref="ProcessStartInfo" /> of the specified
        /// <see cref="Process"/>.
        /// </summary>
        /// <param name="process">The <see cref="Process" /> of which the <see cref="ProcessStartInfo" /> should be updated.</param>
        protected override void PrepareProcess(Process process)
        {
            if (!SupportsAssemblyReferences)
            {
                // use a newly created temporary directory as working directory
                BaseDirectory = FileUtils.GetTempDirectory().FullName;

                // avoid copying the assembly references (and resgen) to a
                // temporary directory if not necessary
                if (Assemblies.FileNames.Count == 0 || !RequiresAssemblyReferences)
                {
                    // further delegate preparation to base class
                    base.PrepareProcess(process);

                    // no further processing required
                    return;
                }

                // create instance of Copy task
                CopyTask ct = new CopyTask();

                // inherit project from current task
                ct.Project = Project;

                // inherit namespace manager from current task
                ct.NamespaceManager = NamespaceManager;

                // parent is current task
                ct.Parent = this;

                // inherit verbose setting from resgen task
                ct.Verbose = Verbose;

                // only output warning messages or higher, unless we're running
                // in verbose mode
                if (!ct.Verbose)
                {
                    ct.Threshold = Level.Warning;
                }

                // make sure framework specific information is set
                ct.InitializeTaskConfiguration();

                // set parent of child elements
                ct.CopyFileSet.Parent = ct;

                // inherit project from solution task for child elements
                ct.CopyFileSet.Project = ct.Project;

                // inherit namespace manager from solution task
                ct.CopyFileSet.NamespaceManager = ct.NamespaceManager;

                // set base directory of fileset
                ct.CopyFileSet.BaseDirectory = Assemblies.BaseDirectory;

                // copy all files to base directory itself
                ct.Flatten = true;

                // copy referenced assemblies
                foreach (string file in Assemblies.FileNames)
                {
                    ct.CopyFileSet.Includes.Add(file);
                }

                // copy command line tool to working directory
                ct.CopyFileSet.Includes.Add(base.ProgramFileName);

                // set destination directory
                ct.ToDirectory = new DirectoryInfo(BaseDirectory);

                // increment indentation level
                ct.Project.Indent();
                try {
                    // execute task
                    ct.Execute();
                } finally {
                    // restore indentation level
                    ct.Project.Unindent();
                }

                // change program to execute the tool in working directory as
                // that will allow this tool to resolve assembly references
                // using assemblies stored in the same directory
                _programFileName = Path.Combine(BaseDirectory,
                                                Path.GetFileName(base.ProgramFileName));
            }
            else
            {
                foreach (string assembly in Assemblies.FileNames)
                {
                    AppendArgument(string.Format(CultureInfo.InvariantCulture,
                                                 " /r:\"{0}\"", assembly));
                }
            }

            // further delegate preparation to base class
            base.PrepareProcess(process);
        }
 public CopyTaskBuilder(ICopyPolicy copyPolicy, IFileSystem fileSystem = null)
 {
     _copyTask = new CopyTask(copyPolicy, fileSystem ?? new FileSystem());
 }
Beispiel #18
0
        private static IEnumerable <ITask> ParseChildren(XmlNode parent)
        {
            if (parent == null || parent.ChildNodes.Count == 0)
            {
                return(null);
            }

            var tasks = new List <ITask>();

            foreach (XmlNode child in parent.ChildNodes)
            {
                if (child.NodeType != XmlNodeType.Element)
                {
                    continue;
                }
                var children = ParseChildren(child);

                ITask task = null;
                var   transliteratePath = child.Attributes["transliteratePath"] != null && bool.Parse(child.Attributes["transliteratePath"].Value);
                switch (child.Name)
                {
                case "copy":

                    var copy         = new CopyTask(null, children, child.Attributes["target"].Value, transliteratePath);
                    var overrideMode = OverwriteMode.Rename;
                    if (child.Attributes["overwriteMode"] != null)
                    {
                        overrideMode = (OverwriteMode)Enum.Parse(typeof(OverwriteMode), child.Attributes["overwriteMode"].Value, true);
                    }
                    copy.OverrideMode = overrideMode;
                    task = copy;
                    break;

                case "xslt":
                    task = new XsltTask(child.Attributes["filePathKey"].Value, null, children);
                    break;

                case "crop":
                    task = new CropTask(child.Attributes["xKey"].Value, child.Attributes["yKey"].Value,
                                        child.Attributes["widthKey"].Value, child.Attributes["heightKey"].Value, null, children);
                    break;

                case "watermark":
                    task = new WatermarkTask(child.Attributes["textKey"].Value, child.Attributes["textPositionKey"].Value, null, children);
                    break;

                case "temp":
                    task = new TempTask(null, children);
                    break;

                case "delete":
                    task = new DeleteTask(null, children, bool.Parse(child.Attributes["deleteEmptyFolders"].Value));
                    break;

                case "dpof":
                    var targetDirectory      = child.Attributes["targetDirectory"].Value;
                    var channelDirectoryName = child.Attributes["channelDirectoryName"].Value;
                    var copyCountKey         = child.Attributes["copyCountKey"].Value;
                    var paperSizeKey         = child.Attributes["paperSizeKey"].Value;
                    var channelKey           = child.Attributes["printChannelKey"].Value;
                    task = new DpofTask(null, children, copyCountKey, paperSizeKey, channelDirectoryName, channelKey, targetDirectory, transliteratePath);
                    break;

                case "convert":
                    ConvertTask.ConvertFormat format;
                    Enum.TryParse(child.Attributes["to"].Value, true, out format);
                    task = new ConvertTask(format, null, children);
                    break;
                }
                if (task != null)
                {
                    if (children != null)
                    {
                        foreach (var ch in children)
                        {
                            ch.ParentTask = task;
                        }
                    }
                    tasks.Add(task);
                }
            }
            return(tasks);
        }
Beispiel #19
0
 public void SetUp()
 {
     _fileSystem = new MockFileSystem();
     _assertions = new FileSystemAssertions(_fileSystem);
     _sut        = new CopyTask(new CopyPolicyFake(), _fileSystem);
 }
 public void CopyFile(string fromPath, string toPath)
 {
     CopyTask t = new CopyTask(fromPath, toPath);
     t.Run();
     this.history.Push(t);
 }