当前位置: 首页>>代码示例>>C#>>正文


C# IFileSystem.Copy方法代码示例

本文整理汇总了C#中IFileSystem.Copy方法的典型用法代码示例。如果您正苦于以下问题:C# IFileSystem.Copy方法的具体用法?C# IFileSystem.Copy怎么用?C# IFileSystem.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IFileSystem的用法示例。


在下文中一共展示了IFileSystem.Copy方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AssemblyInfoFileUpdate

        public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
        {
            if (!args.UpdateAssemblyInfo) return;

            if (args.Output != OutputType.Json)
                Console.WriteLine("Updating assembly info files");

            var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem);

            foreach (var assemblyInfoFile in assemblyInfoFiles)
            {
                var backupAssemblyInfo = assemblyInfoFile + ".bak";
                var localAssemblyInfo = assemblyInfoFile;
                fileSystem.Copy(assemblyInfoFile, backupAssemblyInfo, true);
                restoreBackupTasks.Add(() =>
                {
                    if (fileSystem.Exists(localAssemblyInfo))
                        fileSystem.Delete(localAssemblyInfo);
                    fileSystem.Move(backupAssemblyInfo, localAssemblyInfo);
                });
                cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));

                var assemblyVersion = variables.AssemblySemVer;
                var assemblyInfoVersion = variables.InformationalVersion;
                var assemblyFileVersion = variables.MajorMinorPatch + ".0";
                var fileContents = fileSystem.ReadAllText(assemblyInfoFile)
                    .RegexReplace(@"AssemblyVersion\(""\d+.\d+.\d+(.(\d+|\*))?""\)", string.Format("AssemblyVersion(\"{0}\")", assemblyVersion))
                    .RegexReplace(@"AssemblyInformationalVersion\(""\d+.\d+.\d+(.(\d+|\*))?""\)", string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion))
                    .RegexReplace(@"AssemblyFileVersion\(""\d+.\d+.\d+(.(\d+|\*))?""\)", string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion));

                fileSystem.WriteAllText(assemblyInfoFile, fileContents);
            }
        }
开发者ID:Wikell,项目名称:GitVersion,代码行数:33,代码来源:AssemblyInfoFileUpdate.cs

示例2: AssemblyInfoFileUpdate

        public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
        {
            if (!args.UpdateAssemblyInfo) return;

            if (args.Output != OutputType.Json)
                Logger.WriteInfo("Updating assembly info files");

            var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem).ToList();
            Logger.WriteInfo(string.Format("Found {0} files", assemblyInfoFiles.Count));

            var assemblyVersion = variables.AssemblySemVer;
            var assemblyVersionRegex = new Regex(@"AssemblyVersion\s*\(\s*""[^""]*""\s*\)");
            var assemblyVersionString = !string.IsNullOrWhiteSpace(assemblyVersion) ? string.Format("AssemblyVersion(\"{0}\")", assemblyVersion) : null;
            var assemblyInfoVersion = variables.InformationalVersion;
            var assemblyInfoVersionRegex = new Regex(@"AssemblyInformationalVersion\s*\(\s*""[^""]*""\s*\)");
            var assemblyInfoVersionString = string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion);
            var assemblyFileVersion = variables.MajorMinorPatch + ".0";
            var assemblyFileVersionRegex = new Regex(@"AssemblyFileVersion\s*\(\s*""[^""]*""\s*\)");
            var assemblyFileVersionString = string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion);

            foreach (var assemblyInfoFile in assemblyInfoFiles)
            {
                var backupAssemblyInfo = assemblyInfoFile.FullName + ".bak";
                var localAssemblyInfo = assemblyInfoFile.FullName;
                fileSystem.Copy(assemblyInfoFile.FullName, backupAssemblyInfo, true);
                restoreBackupTasks.Add(() =>
                {
                    if (fileSystem.Exists(localAssemblyInfo))
                        fileSystem.Delete(localAssemblyInfo);
                    fileSystem.Move(backupAssemblyInfo, localAssemblyInfo);
                });
                cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));

                var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName);
                var appendedAttributes = false;
                if (!string.IsNullOrWhiteSpace(assemblyVersion))
                {
                    fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
                }
                fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString, assemblyInfoFile.Extension, ref appendedAttributes);
                fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString, assemblyInfoFile.Extension, ref appendedAttributes);

                if (appendedAttributes)
                {
                    // If we appended any attributes, put a new line after them
                    fileContents += Environment.NewLine;
                }
                fileSystem.WriteAllText(assemblyInfoFile.FullName, fileContents);
            }
        }
开发者ID:qetza,项目名称:GitVersion,代码行数:50,代码来源:AssemblyInfoFileUpdate.cs

示例3: Copy

 public void Copy(IFileSystem source, FileSystemPath sourcePath, IFileSystem destination, FileSystemPath destinationPath)
 {
     var pSource = (PhysicalFileSystem)source;
     var pDestination = (PhysicalFileSystem)destination;
     var pSourcePath = pSource.GetPhysicalPath(sourcePath);
     var pDestinationPath = pDestination.GetPhysicalPath(destinationPath);
     if (sourcePath.IsFile)
         System.IO.File.Copy(pSourcePath, pDestinationPath);
     else
     {
         destination.CreateDirectory(destinationPath);
         foreach(var e in source.GetEntities(sourcePath))
             source.Copy(e, destination, e.IsFile ? destinationPath.AppendFile(e.EntityName) : destinationPath.AppendDirectory(e.EntityName));
     }
 }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:15,代码来源:PhysicalEntityMover.cs

示例4: AssemblyInfoFileUpdate

        public AssemblyInfoFileUpdate(Arguments args, string workingDirectory, VersionVariables variables, IFileSystem fileSystem)
        {
            if (!args.UpdateAssemblyInfo) return;

            if (args.Output != OutputType.Json)
                Logger.WriteInfo("Updating assembly info files");

            var assemblyInfoFiles = GetAssemblyInfoFiles(workingDirectory, args, fileSystem);
            Logger.WriteInfo(string.Format("Found {0} files", assemblyInfoFiles.Count()));

            var assemblyVersion = variables.AssemblySemVer;
            var assemblyVersionRegex = new Regex(@"AssemblyVersion\(""[^""]*""\)");
            var assemblyVersionString = string.Format("AssemblyVersion(\"{0}\")", assemblyVersion);
            var assemblyInfoVersion = variables.InformationalVersion;
            var assemblyInfoVersionRegex = new Regex(@"AssemblyInformationalVersion\(""[^""]*""\)");
            var assemblyInfoVersionString = string.Format("AssemblyInformationalVersion(\"{0}\")", assemblyInfoVersion);
            var assemblyFileVersion = variables.MajorMinorPatch + ".0";
            var assemblyFileVersionRegex = new Regex(@"AssemblyFileVersion\(""[^""]*""\)");
            var assemblyFileVersionString = string.Format("AssemblyFileVersion(\"{0}\")", assemblyFileVersion);

            foreach (var assemblyInfoFile in assemblyInfoFiles.Select(f => new FileInfo(f)))
            {
                var backupAssemblyInfo = assemblyInfoFile.FullName + ".bak";
                var localAssemblyInfo = assemblyInfoFile.FullName;
                fileSystem.Copy(assemblyInfoFile.FullName, backupAssemblyInfo, true);
                restoreBackupTasks.Add(() =>
                {
                    if (fileSystem.Exists(localAssemblyInfo))
                        fileSystem.Delete(localAssemblyInfo);
                    fileSystem.Move(backupAssemblyInfo, localAssemblyInfo);
                });
                cleanupBackupTasks.Add(() => fileSystem.Delete(backupAssemblyInfo));

                var fileContents = fileSystem.ReadAllText(assemblyInfoFile.FullName);
                fileContents = ReplaceOrAppend(assemblyVersionRegex, fileContents, assemblyVersionString);
                fileContents = ReplaceOrAppend(assemblyInfoVersionRegex, fileContents, assemblyInfoVersionString);
                fileContents = ReplaceOrAppend(assemblyFileVersionRegex, fileContents, assemblyFileVersionString);

                fileSystem.WriteAllText(assemblyInfoFile.FullName, fileContents);
            }
        }
开发者ID:Tungsten78,项目名称:GitVersion,代码行数:41,代码来源:AssemblyInfoFileUpdate.cs

示例5: ExpectFileCheckAndCopy

 private static void ExpectFileCheckAndCopy(IFileSystem fileSystem, string fileName)
 {
     var sourceFile = Path.Combine(defaultWorkingDir, fileName);
     var destFile = Path.Combine(
         Path.Combine("artefactDir", "1"),
         Path.Combine("AntsPerformance", fileName));
     Expect.Call(fileSystem.FileExists(sourceFile)).Return(true);
     Expect.Call(() => fileSystem.Copy(sourceFile, destFile));
 }
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:9,代码来源:AntsPerformanceProfilerTaskTests.cs

示例6: PreparePackages

        // prepare NuGet dependencies, download them if required
        private static IEnumerable<string> PreparePackages(
														string scriptPath,
														IFileSystem fileSystem, IPackageAssemblyResolver packageAssemblyResolver,
														IPackageInstaller packageInstaller)
        {
            var workingDirectory = Path.GetDirectoryName(scriptPath);
            var binDirectory = Path.Combine(workingDirectory, @"bin\debug"); //TODO : ScriptCs.Constants.BinFolder

            var packages = packageAssemblyResolver.GetPackages(workingDirectory);

            packageInstaller.InstallPackages(
                                                    packages,
                                                    allowPreRelease: true);

            // current implementeation of RoslynCTP required dependencies to be in 'bin' folder
            if (!fileSystem.DirectoryExists(binDirectory))
            {
                fileSystem.CreateDirectory(binDirectory);
            }

            // copy dependencies one by one from 'packages' to 'bin'
            foreach (var assemblyName
                                    in packageAssemblyResolver.GetAssemblyNames(workingDirectory))
            {
                var assemblyFileName = Path.GetFileName(assemblyName);
                var destFile = Path.Combine(binDirectory, assemblyFileName);

                var sourceFileLastWriteTime = fileSystem.GetLastWriteTime(assemblyName);
                var destFileLastWriteTime = fileSystem.GetLastWriteTime(destFile);

                if (sourceFileLastWriteTime == destFileLastWriteTime)
                {
                    //outputCallback(string.Format("Skipped: '{0}' because it is already exists", assemblyName));
                }
                else
                {
                    fileSystem.Copy(assemblyName, destFile, overwrite: true);

                    //if (outputCallback != null)
                    //{
                    //	outputCallback(string.Format("Copy: '{0}' to '{1}'", assemblyName, destFile));
                    //}
                }

                yield return destFile;
            }
        }
开发者ID:RobGibbens,项目名称:tekcron,代码行数:48,代码来源:ExecuteScriptCs.cs

示例7: CopyFromIndex

        private void CopyFromIndex(
            string indexFile, 
            string targetFolder, 
            IFileSystem fileSystem, 
            ILogger logger, 
            IIntegrationResult result)
        {
            var basePath = Path.GetDirectoryName(indexFile);
            using (var reader = fileSystem.Load(indexFile))
            {
                XDocument document = null;
                try
                {
                    document = XDocument.Load(reader);
                }
                catch (Exception error)
                {
                    throw new CruiseControlException(
                        "Unable to load index file - " + error.Message ?? string.Empty,
                        error);
                }

                var rootEl = document.Element("ReportResources");
                if (rootEl == null)
                {
                    throw new CruiseControlException("Unable to load contents manifest - unable to find root node");
                }

                var files = new List<string>();
                foreach (var fileEl in rootEl.Elements("File"))
                {
                    var fullPath = fileEl.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fileEl.Value);
                    }

                    files.Add(fullPath);
                }

                foreach (var folder in rootEl.Elements("Directory"))
                {
                    var fullPath = folder.Value;
                    if (!Path.IsPathRooted(fullPath))
                    {
                        fullPath = Path.Combine(basePath, fullPath);
                    }

                    files.AddRange(fileSystem.GetFilesInDirectory(fullPath, true));
                }

                var baseLength = basePath.Length;
                foreach (var file in files)
                {
                    logger.Info("Copying file '{0}' to '{1}'", file, targetFolder);
                    var targetFile = file.StartsWith(basePath) ?
                        file.Substring(baseLength) :
                        Path.GetFileName(file);
                    result.BuildProgressInformation.AddTaskInformation(
                        string.Format(CultureInfo.CurrentCulture, "Copying file '{0}' to '{1}'", targetFile, targetFolder));
                    fileSystem.Copy(file, Path.Combine(targetFolder, targetFile));
                }
            }

        }
开发者ID:kascomp,项目名称:CruiseControl.NET,代码行数:65,代码来源:MergeFilesTask.cs


注:本文中的IFileSystem.Copy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。