本文整理汇总了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;
}
示例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();
}
}
示例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();
}
}
示例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);
}
}
}
}
示例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);
}
示例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;
}
}
示例7: WriteDescriptor
void WriteDescriptor(IFile descriptor, PackageDescriptor packageDescriptor)
{
using (Stream descriptorStream = descriptor.OpenWrite())
{
new PackageDescriptorReaderWriter().Write(packageDescriptor, descriptorStream);
}
}
示例8: SaveXmlToFile
static void SaveXmlToFile(XElement xDoc, IFile file)
{
using (var stream = file.OpenWrite())
using (var writer = XmlWriter.Create(stream))
{
xDoc.WriteTo(writer);
}
}
示例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;
}
}
示例10: NewFromFiles
public static void NewFromFiles(IFile destinationPackage, IEnumerable<PackageContent> content)
{
using (var wrapStream = destinationPackage.OpenWrite())
NewFromFiles(wrapStream, content);
}
示例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;
}