本文整理汇总了C#中System.IO.TextWriter.Close方法的典型用法代码示例。如果您正苦于以下问题:C# TextWriter.Close方法的具体用法?C# TextWriter.Close怎么用?C# TextWriter.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.TextWriter
的用法示例。
在下文中一共展示了TextWriter.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Compile
public void Compile(string fileName)
{
var parent = Directory.GetParent(fileName);
var dir = Directory.CreateDirectory($"output_{parent.Name}");
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
var tacFilePath = $"{dir.FullName}/{fileNameWithoutExtension}.tac";
var asmFilePath = $"{dir.FullName}/{fileNameWithoutExtension}.asm";
try
{
FileIn = File.CreateText(tacFilePath);
var streamReader = new StreamReader(fileName);
var lexAnalyzer = new LexicalAnalyzerService(streamReader);
var symbolTable = new SymbolTable
{
Printer = (val) =>
{
Console.WriteLine(val);
}
};
var syntaxParser = new SyntaxParserService(lexAnalyzer, symbolTable);
PrintSourceCode(File.ReadAllText(fileName));
syntaxParser.Parse();
FileIn.Close();
Intelx86GeneratorService.Generate(
File.ReadAllLines(tacFilePath),
syntaxParser.GlobalStrings,
syntaxParser.MethodLocalSize,
syntaxParser.MethodParamSize,
(str) => {
if (File.Exists(asmFilePath))
{
File.Delete(asmFilePath);
}
File.AppendAllText(asmFilePath, str);
Console.WriteLine(str);
});
}
catch (Exception ex)
{
// Delete out file
if (File.Exists(tacFilePath))
{
FileIn.Close();
File.Delete(tacFilePath);
}
Print("Oops, there seems to be something wrong.\n\n", ErrorColor);
Print(ex.Message, ErrorColor);
}
}
示例2: ValidateFile
public void ValidateFile(Stream stream, TextWriter outstream, Action<int> progress, Action<string> status)
{
try {
MZTabErrorList errorList = new MZTabErrorList(Level.Info);
try {
validate(stream, outstream, errorList, progress, status);
//refine();
} catch (MZTabException e) {
outstream.Write(MZTabProperties.MZTabExceptionMessage);
errorList.Add(e.Error);
} catch (MZTabErrorOverflowException) {
outstream.Write(MZTabProperties.MZTabErrorOverflowExceptionMessage);
}
errorList.print(outstream);
if (errorList.IsNullOrEmpty()) {
outstream.Write("No errors in this section!" + MZTabConstants.NEW_LINE);
}
outstream.Close();
//stream.Close();
} catch (Exception e) {
MessageBox.Show(e.Message, e.StackTrace);
}
}
示例3: RunPostCompile
protected override void RunPostCompile()
{
if (string.IsNullOrEmpty(MapFile))
return;
using (writer = new StreamWriter(MapFile))
{
// Emit map file header
writer.WriteLine(CompilerOptions.OutputFile);
writer.WriteLine();
writer.WriteLine("Timestamp is {0}", DateTime.Now);
writer.WriteLine();
writer.WriteLine("Preferred load address is {0:x16}", (object)Linker.BaseAddress);
writer.WriteLine();
// Emit the sections
EmitSections(Linker);
writer.WriteLine();
// Emit all symbols
EmitSymbols(Linker);
writer.Close();
}
}
示例4: Save
/// <summary>
/// Saves a Graph to CSV format
/// </summary>
/// <param name="g">Graph</param>
/// <param name="output">Writer to save to</param>
public void Save(IGraph g, TextWriter output)
{
try
{
foreach (Triple t in g.Triples)
{
this.GenerateNodeOutput(output, t.Subject, TripleSegment.Subject);
output.Write(',');
this.GenerateNodeOutput(output, t.Predicate, TripleSegment.Predicate);
output.Write(',');
this.GenerateNodeOutput(output, t.Object, TripleSegment.Object);
output.Write("\r\n");
}
output.Close();
}
catch
{
try
{
output.Close();
}
catch
{
//No error handling, just trying to clean up
}
throw;
}
}
示例5: Output
public void Output(TextWriter writer)
{
var outputList = new List<AuditResultsOutput>();
foreach (var result in _results)
{
if (_auditEventTypes.HasFlag(AuditEventTypes.ResolvedAssemblyReferences))
outputList.AddRange(result.ResolvedAssemblyReferences.Select(u => new AuditResultsOutput {PackageName = result.Package.Id, Category = "Resolved Assembly", Item = u.Name}));
if (_auditEventTypes.HasFlag(AuditEventTypes.UnloadablePackageFiles))
outputList.AddRange(result.UnloadablePackageFiles.Select(u => new AuditResultsOutput { PackageName = result.Package.Id, Category = "Unloadable Package File", Item = u }));
if (_auditEventTypes.HasFlag(AuditEventTypes.UnresolvedAssemblyReferences))
outputList.AddRange(result.UnresolvedAssemblyReferences.Select(u => new AuditResultsOutput { PackageName = result.Package.Id, Category = "Unresolved Assembly", Item = u.Name }));
if (_auditEventTypes.HasFlag(AuditEventTypes.UnresolvedDependencies))
outputList.AddRange(result.UnresolvedDependencies.Select(u => new AuditResultsOutput { PackageName = result.Package.Id, Category = "Unresolved Package Dependency", Item = u.Id }));
if (_auditEventTypes.HasFlag(AuditEventTypes.UnusedPackageDependencies))
outputList.AddRange(result.UnusedPackageDependencies.Select(u => new AuditResultsOutput { PackageName = result.Package.Id, Category = "Unused Package Dependency", Item = u.Id }));
if (_auditEventTypes.HasFlag(AuditEventTypes.UsedPackageDependencies))
outputList.AddRange(result.UsedPackageDependencies.Select(u => new AuditResultsOutput { PackageName = result.Package.Id, Category = "Used Package Dependency", Item = u.Id }));
if (_auditEventTypes.HasFlag(AuditEventTypes.FeedResolvableReferences))
outputList.AddRange(result.FeedResolvableReferences.Select(u => new AuditResultsOutput { PackageName = result.Package.Id, Category = "Feed Resolvable Assembly", Item = u.Name }));
if (_auditEventTypes.HasFlag(AuditEventTypes.GacResolvableReferences))
outputList.AddRange(result.GacResolvableReferences.Select(u => new AuditResultsOutput { PackageName = result.Package.Id, Category = "GAC Resolvable Assembly", Item = u.Name }));
if (_auditEventTypes.HasFlag(AuditEventTypes.UnresolvableAssemblyReferences))
outputList.AddRange(result.UnresolvableReferences.Select(u => new AuditResultsOutput { PackageName = result.Package.Id, Category = "Unresolvable Assembly Reference (not on feed or in GAC)", Item = u.Name }));
}
foreach (var output in outputList)
writer.WriteLine(output.ToString());
writer.Close();
}
示例6: GenerateResult
public static void GenerateResult (TextReader sr, TextWriter sw, Uri baseUri)
{
while (sr.Peek () > 0) {
string uriString = sr.ReadLine ();
if (uriString.Length == 0 || uriString [0] == '#')
continue;
Uri uri = (baseUri == null) ?
new Uri (uriString) : new Uri (baseUri, uriString);
sw.WriteLine ("-------------------------");
sw.WriteLine (uriString);
sw.WriteLine (uri.ToString ());
sw.WriteLine (uri.AbsoluteUri);
sw.WriteLine (uri.Scheme);
sw.WriteLine (uri.Host);
sw.WriteLine (uri.LocalPath);
sw.WriteLine (uri.Query);
sw.WriteLine (uri.Port);
sw.WriteLine (uri.IsFile);
sw.WriteLine (uri.IsUnc);
sw.WriteLine (uri.IsLoopback);
sw.WriteLine (uri.UserEscaped);
sw.WriteLine (uri.HostNameType);
sw.WriteLine (uri.AbsolutePath);
sw.WriteLine (uri.PathAndQuery);
sw.WriteLine (uri.Authority);
sw.WriteLine (uri.Fragment);
sw.WriteLine (uri.UserInfo);
sw.Flush ();
}
sr.Close ();
sw.Close ();
}
示例7: OnStart
protected override void OnStart(string[] args)
{
if (!EventLog.SourceExists("SSISIncomingDirectoryWatcher", "."))
{
EventLog.CreateEventSource("SSISIncomingDirectoryWatcher", "Application");
}
Lg = new EventLog("Application", ".", "SSISIncomingDirectoryWatcher");
Lg.WriteEntry("Service started at " + DateTime.Now, EventLogEntryType.Information);
try
{
tw = File.CreateText(logFilePath);
tw.WriteLine("Service started at {0}", DateTime.Now);
readInConfigValues();
Watcher = new FileSystemWatcher();
Watcher.Path = dirToWatch;
Watcher.IncludeSubdirectories = false;
Watcher.Created += new FileSystemEventHandler(watcherChange);
Watcher.EnableRaisingEvents = true;
}
catch (Exception ex)
{
Lg.WriteEntry(ex.Message, EventLogEntryType.Error);
}
finally
{
tw.Close();
}
}
示例8: log
public void log(String value)
{
writer = new StreamWriter(fileName,true);
writer.WriteLine(" ");
writer.WriteLine("[ "+System.DateTime.UtcNow+" ] "+value);
writer.Close();
}
示例9: AdicionarNoXML
private static void AdicionarNoXML(string filename)
{
if (data.Columns.Count == 0)
data.Columns.Add("CaminhoArquivo");
if (data.Rows.Count > 10)
{
int iterador = data.Rows.Count - 1;
while (iterador > 10)
{
data.Rows.Remove(data.Rows[iterador]);
iterador--;
}
}
int posicao = VerificaLista(filename);
if (posicao != -1)
{
data.Rows[posicao].Delete();
}
data.Rows.Add(filename);
writer = File.CreateText(xml);
data.WriteXml(writer);
writer.Close();
}
示例10: LogTextWriter
public LogTextWriter(string filePath, string prefix = null, string suffix = null, string newline = "\n")
{
_outputQueue = new ConcurrentQueue<string>();
_outputRun = 1;
_outputThread = new Thread(() =>
{
string o;
using (FileStream _fs = File.Open(filePath, FileMode.Create, FileAccess.ReadWrite, FileShare.Read))
{
_innerWriter = new StreamWriter(_fs);
_innerWriter.NewLine = newline;
while (Thread.VolatileRead(ref _outputRun) == 1 || _outputQueue.Count > 0)
{
if (_outputQueue.Count > 0)
{
while (_outputQueue.TryDequeue(out o))
_innerWriter.Write(o);
_innerWriter.Flush();
}
else
Thread.Sleep(_outputThreadDelay);
}
// _fs.Close();
_innerWriter.Close();
}
});
_outputThread.Priority = ThreadPriority.BelowNormal;
_outputThread.Start();
_prefix = prefix;
_suffix = suffix;
}
示例11: Main
static void Main(string[] args)
{
output = Console.Out;
output = new StreamWriter(@"Assignment2.smt");
start("P Int Int Int", "QF_UFLIA");
int[] chip = new int[2] {29,22};
int[] powerComponent = new int[2] {4,2};
int[,] components = new int[8, 2] {{9,7},{12,6},{10,7},{18,5},{20,4},{10,6},{8,6},{10,8}};
int powerDist = 17;
//All components must occur
for (int i = 2; i < components.Length + 2; i++) {
output.WriteLine("(or");
for (int x = 0; x < chip [0]; x++) {
for (int y = 0; y < chip [1]; y++) {
output.WriteLine("(= (P {0} {1}) {2})", x, y, i);
}
}
output.WriteLine(")");
}
end();
output.Close();
//Console.ReadKey();
}
示例12: WriteToStream
public static void WriteToStream(TextWriter stream, DataTable table, bool header, bool quoteall)
{
if (header)
{
for (int i = 0; i < table.Columns.Count; i++)
{
WriteItem(stream, table.Columns[i].Caption, quoteall);
if (i < table.Columns.Count - 1)
stream.Write(',');
else
stream.Write("\r\n");
}
}
foreach (DataRow row in table.Rows)
{
for (int i = 0; i < table.Columns.Count; i++)
{
WriteItem(stream, row[i], quoteall);
if (i < table.Columns.Count - 1)
stream.Write(',');
else
stream.Write("\r\n");
}
}
stream.Flush();
stream.Close();
}
示例13: Main
static int Main(string[] args)
{
try
{
if (!File.Exists(templateName))
{
Console.WriteLine(templateName + " not found."); return 1;
}
try
{
fStream = new FileStream(@"FreeImage.cs", FileMode.Create);
}
catch
{
Console.WriteLine("Unable to create output file."); return 2;
}
textOut = new StreamWriter(fStream);
string[] content = File.ReadAllLines(templateName);
for (int lineNumber = 0; lineNumber < content.Length; lineNumber++)
{
string line = content[lineNumber].Trim();
Match match = searchPattern.Match(line);
if (match.Success && match.Groups.Count == 2 && match.Groups[1].Value != null)
{
if (!File.Exists(baseFolder + match.Groups[1].Value))
{
throw new FileNotFoundException(baseFolder + match.Groups[1].Value + " does not exist.");
}
ParseFile(baseFolder + match.Groups[1].Value);
}
else
{
textOut.WriteLine(content[lineNumber]);
}
}
return 0;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
//Console.WriteLine("Error while parsing.");
return 3;
}
finally
{
if (textOut != null)
{
textOut.Flush();
textOut.Close();
}
}
}
示例14: Write
public static void Write(TextWriter writer, bool ownsStream, Action<JsonWriter.Item> resolver, JsonWriterOptions options = null)
{
JsonWriter w = new JsonWriter(writer, options);
if (options == null) options = defaultOptions;
resolver(w.itemWriter);
if (ownsStream)
writer.Close();
}
示例15: Profiler
/// <summary>
/// Creates a profiler object
/// </summary>
/// <param name="filename">Name of file to save profiling log to</param>
/// <param name="append">True if the file should not be overwritten</param>
public Profiler(string filename, bool append)
{
// done to make sure file path is writeable – each time logging used new streamwriter opened & closed to prevent file locking for entire AWB session
log = new StreamWriter(filename, append, Encoding.Unicode);
log.Close();
FileName = filename;
Append = append;
}