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


C# IFile.OpenWrite方法代码示例

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


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

示例1: Copy

        private bool Copy(IFile source, IFile destination)
        {
            if (!source.Exists)
            {
                _log.Error("Could not find file {0}.", source.Path.FullPath);
                return false;
            }
            if (destination.Exists)
            {
                _log.Error("The file {0} already exist.", destination.Path.FullPath);
                return false;
            }

            using (var input = source.OpenRead())
            using (var output = destination.OpenWrite())
            {
                using (var reader = new StreamReader(input))
                using (var writer = new StreamWriter(output))
                {
                    while (true)
                    {
                        var line = reader.ReadLine();
                        if (line == null)
                        {
                            break;
                        }
                        writer.WriteLine(line);
                    }
                }
            }

            return true;
        }
开发者ID:gep13,项目名称:bootstrapper,代码行数:33,代码来源:FileCopier.cs

示例2: ReplaceLegacyControlTags

        private static void ReplaceLegacyControlTags(IFile file)
        {
            var contents = file.Contents;

            var regex = new Regex
                (@"(<%@\s*?Register\s+?TagPrefix="")(.+?)(""\s+?Namespace="".+?""\s+?Assembly="")(Subtext.Web.Controls)(""\s*?%>)"
                , RegexOptions.IgnoreCase | RegexOptions.Multiline
                );

            var newContent = regex.Replace(contents, delegate(Match m)
            {
                if (m.Groups[2].Value.Equals("st", StringComparison.CurrentCultureIgnoreCase))
                {
                    return string.Empty;
                }
                var sb = new StringBuilder();

                sb.Append(m.Groups[1].Value);
                sb.Append(m.Groups[2].Value);
                sb.Append(m.Groups[3].Value);
                sb.Append("Subtext.Web");
                sb.Append(m.Groups[5].Value);

                return sb.ToString();
            });

            if (contents != newContent)
            {
                var stream = new StreamWriter(file.OpenWrite());
                stream.Write(newContent);
                stream.Close();
            }
        }
开发者ID:ChrisPelatari,项目名称:SubText,代码行数:33,代码来源:SkinUpgrader.cs

示例3: MoveTo

        public void MoveTo(IFile destination)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            // Use the file system APIs if destination is also in the file system
            if (destination is LocalFile)
            {
                LocalFileProvider.Retry(() => _file.MoveTo(destination.Path.FullPath));
            }
            else
            {
                // Otherwise use streams to perform the move
                using (Stream sourceStream = OpenRead())
                {
                    using (Stream destinationStream = destination.OpenWrite())
                    {
                        sourceStream.CopyTo(destinationStream);
                    }
                }
                Delete();
            }
        }
开发者ID:ibebbs,项目名称:Wyam,代码行数:25,代码来源:LocalFile.cs

示例4: CopyTo

        public void CopyTo(IFile destination, bool overwrite = true, bool createDirectory = true)
        {
            if (destination == null)
            {
                throw new ArgumentNullException(nameof(destination));
            }

            // Create the directory
            if (createDirectory)
            {
                destination.Directory.Create();
            }
            
            // Use the file system APIs if destination is also in the file system
            if (destination is LocalFile)
            {
                LocalFileProvider.Retry(() => _file.CopyTo(destination.Path.FullPath, overwrite));
            }
            else
            {
                // Otherwise use streams to perform the copy
                using (Stream sourceStream = OpenRead())
                {
                    using (Stream destinationStream = destination.OpenWrite())
                    {
                        sourceStream.CopyTo(destinationStream);
                    }
                }
            }
        }
开发者ID:ibebbs,项目名称:Wyam,代码行数:30,代码来源:LocalFile.cs

示例5: UpgradeConfig

        private static void UpgradeConfig(IFile newConfig, IFile existingConfig)
        {
            var newXml = newConfig.ToXml();
            var existingXml = existingConfig.ToXml();

            ApplyCustomizations(existingXml, newXml);

            using(var stream = newConfig.OpenWrite())
            {
                newXml.Save(stream);
            }
            newConfig.Overwrite(existingConfig);
        }
开发者ID:rsaladrigas,项目名称:Subtext,代码行数:13,代码来源:WebConfigUpgrader.cs

示例6: CreateMSBuildProcess

        IProcess CreateMSBuildProcess(IFile responseFile, IFile project, string platform, string profile, string msbuildTargets)
        {
            using (var stream = responseFile.OpenWrite())
            using (var writer = new StreamWriter(stream, Encoding.UTF8))
            {
                var existingResponseFile = Environment.GetCommandLineArgs()
                        .Select(x => x.Trim())
                        .Where(x => x.StartsWith("@"))
                        .Select(x => _fileSystem.GetFile(x.Substring(1)))
                        .FirstOrDefault(x => x.Exists);
                if (existingResponseFile != null && existingResponseFile.Exists)
                {
                    foreach (var line in existingResponseFile.ReadLines().Where(NotTarget))
                        writer.WriteLine(line);
                }
                if (platform != null) writer.WriteLine("/p:OpenWrap-TargetPlatform=" + platform);
                if (profile != null)
                {
                    var msbuildVersioning = TargetFramework.ParseOpenWrapIdentifier(profile);
                    writer.WriteLine("/p:OpenWrap-TargetProfile=" + profile);
                    writer.WriteLine("/p:TargetFrameworkVersion=" + msbuildVersioning.Version);
                    writer.WriteLine("/p:TargetFrameworkIdentifier=" + msbuildVersioning.Identifier);
                    writer.WriteLine("/p:TargetFrameworkProfile=" + msbuildVersioning.Profile);
                }
                if (Configuration.Any())
                {
                    writer.WriteLine("/p:Configuration=" + Configuration.Last());
                }
                if (Debugger.IsAttached)
                    writer.WriteLine("/p:OpenWrap-StartDebug=true");
                writer.WriteLine("/p:OpenWrap-EmitOutputInstructions=true");
                writer.WriteLine("/p:OpenWrap-CurrentProjectFile=\"" + project.Path.FullPath + "\"");

                foreach (var kv in Properties.Where(_=>ReservedProperties.Contains(_.Key) == false))
                {
                    var value = kv.LastOrDefault();
                    if (value != null)
                        writer.WriteLine("/p:{0}={1}", kv.Key, value);
                }
                if (msbuildTargets != null)
                    writer.WriteLine("/t:" + msbuildTargets);

                var args = string.Format(@"@""{1}"" ""{0}""", project.Path.FullPath, responseFile.Path.FullPath);
                var msBuildProcess = CreateProcess(args);
                CopyEnvVars(Process.GetCurrentProcess(), msBuildProcess);
                writer.Flush();
                return msBuildProcess;
            }
        }
开发者ID:guesshoo,项目名称:openwrap,代码行数:49,代码来源:MSBuildPackageBuilder.cs

示例7: WriteDescriptor

 void WriteDescriptor(IFile descriptor, PackageDescriptor packageDescriptor)
 {
     using (Stream descriptorStream = descriptor.OpenWrite())
     {
         new PackageDescriptorReaderWriter().Write(packageDescriptor, descriptorStream);
     }
 }
开发者ID:guesshoo,项目名称:openwrap,代码行数:7,代码来源:InitWrapCommand.cs

示例8: SaveXmlToFile

 static void SaveXmlToFile(XElement xDoc, IFile file)
 {
     using (var stream = file.OpenWrite())
     using (var writer = XmlWriter.Create(stream))
     {
         xDoc.WriteTo(writer);
     }
 }
开发者ID:guesshoo,项目名称:openwrap,代码行数:8,代码来源:InitWrapCommand.cs

示例9: CreateMSBuildProcess

        Process CreateMSBuildProcess(IFile responseFile, IFile project, string platform, string profile, string msbuildTargets)
        {
            using (var stream = responseFile.OpenWrite())
            using (var writer = new StreamWriter(stream, Encoding.UTF8))
            {
                var existingResponseFile = Environment.GetCommandLineArgs()
                        .Select(x => x.Trim())
                        .Where(x => x.StartsWith("@"))
                        .Select(x => _fileSystem.GetFile(x.Substring(1)))
                        .FirstOrDefault(x=>x.Exists);
                if (existingResponseFile != null && existingResponseFile.Exists)
                {
                    foreach (var line in existingResponseFile.ReadLines().Where(NotTarget))
                        writer.WriteLine(line);
                }
                if (platform != null) writer.WriteLine("/p:OpenWrap-TargetPlatform=" + platform);
                if (profile != null)
                {
                    var msbuildVersioning = FrameworkVersioning.OpenWrapToMSBuild(profile);
                    writer.WriteLine("/p:OpenWrap-TargetProfile=" + profile);
                    writer.WriteLine("/p:TargetFrameworkVersion=" + msbuildVersioning.Version);
                    writer.WriteLine("/p:TargetFrameworkIdentifier=" + msbuildVersioning.Identifier);
                    writer.WriteLine("/p:TargetFrameworkProfile=" + msbuildVersioning.Profile);
                }
                writer.WriteLine("/p:OpenWrap-EmitOutputInstructions=true");
                writer.WriteLine("/p:OpenWrap-CurrentProjectFile=" + project.Path.FullPath);
                if (msbuildTargets != null)
                    writer.WriteLine("/t:" + msbuildTargets);

                var args = string.Format(@"@""{1}"" ""{0}""", project.Path.FullPath, responseFile.Path.FullPath);
                var msBuildProcess = CreateProcess(args);
                CopyEnvVars(Process.GetCurrentProcess(), msBuildProcess);
                writer.Flush();
                return msBuildProcess;
            }
        }
开发者ID:andrewdavey,项目名称:openwrap,代码行数:36,代码来源:MSBuildPackageBuilder.cs

示例10: NewFromFiles

 public static void NewFromFiles(IFile destinationPackage, IEnumerable<PackageContent> content)
 {
     using (var wrapStream = destinationPackage.OpenWrite())
         NewFromFiles(wrapStream, content);
 }
开发者ID:seantfox,项目名称:openwrap,代码行数:5,代码来源:PackageBuilder.cs

示例11: New

            public static IFile New(IFile wrapFile, string name, string version, params string[] descriptorLines)
            {
                //var wrapFile = new InMemoryFile(name + "-" + version + ".wrap");
                using (var wrapStream = wrapFile.OpenWrite())
                using (var zipFile = new ZipOutputStream(wrapStream))
                {
                    var nameTransform = new ZipNameTransform();

                    zipFile.PutNextEntry(new ZipEntry(name + ".wrapdesc"));

                    var descriptorContent = descriptorLines.Any()
                                                    ? string.Join("\r\n", descriptorLines)
                                                    : " ";

                    zipFile.Write(Encoding.UTF8.GetBytes(descriptorContent));

                    var versionEntry = new ZipEntry("version");
                    zipFile.PutNextEntry(versionEntry);

                    var versionData = Encoding.UTF8.GetBytes(version);
                    zipFile.Write(versionData);
                    zipFile.Finish();
                }
                return wrapFile;
            }
开发者ID:bobthemighty,项目名称:openwrap,代码行数:25,代码来源:resolving_dependencies_tree.cs


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