private void WriteBuffer() { lock (_nextChunkReadyLock) { for (;;) { if (_internalBuffer == null) { Monitor.Wait(_nextChunkReadyLock); } lock (_bufferFreedLock) { Out.Write(_internalBuffer, 0, _internalBufferIndex); _internalBuffer = null; _internalBufferIndex = 0; if (_isDisposed) { Out.Dispose(); return; } Monitor.Pulse(_bufferFreedLock); } GC.Collect(); } } }
protected virtual void Dispose(bool disposing) { if (disposing) { Out.Dispose(); Out = null; } }
public void Dispose() { Console.SetOut(savedStdOut); Console.SetError(savedStdErr); Out?.Dispose(); Out = null; Error?.Dispose(); Error = null; }
public void Dispose() { // On disposal, send a disconnect message Send(new DisconnectMessage(DisconnectType.Expected)); Stream.Dispose(); In.Dispose(); Out.Dispose(); Connection.Close(); }
public void Dispose() { Out?.Dispose(); Out = null; In?.Dispose(); In = null; Process?.Dispose(); Process = null; }
protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { Out.Dispose(); } disposedValue = true; } }
public void Dispose() { try { // On Dispose, send an unexpected disconnect signal. // If we've already disconnected cleanly, this will just fail Send(new DisconnectMessage(DisconnectType.Unexpected)); } catch { } Stream.Dispose(); Out.Dispose(); }
private void CleanUp() { if (Out != null) { Out.Dispose(); Out = null; } if (Source != null) { Source.Dispose(); Source = null; } }
void ReleaseDesignerOutlets() { if (Out != null) { Out.Dispose(); Out = null; } if (Start != null) { Start.Dispose(); Start = null; } }
/// <summary> /// Releases any resources used by this instance. /// </summary> public void Dispose() { //Check if (isDisposed) { return; } //Dispose ms.Dispose(); Out.Dispose(); In.Dispose(); isDisposed = true; //Null ms = null; buffer = null; }
private static int Main(string[] args) { WriteLine($"Roslynator Command Line Tool version {typeof(Program).GetTypeInfo().Assembly.GetName().Version}", Verbosity.Quiet); WriteLine("Copyright (c) Josef Pihrt. All rights reserved.", Verbosity.Quiet); WriteLine(Verbosity.Quiet); try { ParserResult <object> parserResult = Parser.Default.ParseArguments < #if DEBUG AnalyzeAssemblyCommandLineOptions, FindSymbolsCommandLineOptions, SlnListCommandLineOptions, ListVisualStudioCommandLineOptions, GenerateSourceReferencesCommandLineOptions, #endif FixCommandLineOptions, AnalyzeCommandLineOptions, ListSymbolsCommandLineOptions, FormatCommandLineOptions, PhysicalLinesOfCodeCommandLineOptions, LogicalLinesOfCodeCommandLineOptions, GenerateDocCommandLineOptions, GenerateDocRootCommandLineOptions>(args); bool verbosityParsed = false; parserResult.WithParsed <AbstractCommandLineOptions>(options => { var defaultVerbosity = Verbosity.Normal; if (options.Verbosity == null || TryParseVerbosity(options.Verbosity, out defaultVerbosity)) { ConsoleOut.Verbosity = defaultVerbosity; Verbosity fileLogVerbosity = defaultVerbosity; if (options.FileLogVerbosity == null || TryParseVerbosity(options.FileLogVerbosity, out fileLogVerbosity)) { if (options.FileLog != null) { var fs = new FileStream(options.FileLog, FileMode.Create, FileAccess.Write, FileShare.Read); var sw = new StreamWriter(fs, Encoding.UTF8, bufferSize: 4096, leaveOpen: false); Out = new TextWriterWithVerbosity(sw) { Verbosity = fileLogVerbosity }; } verbosityParsed = true; } } }); if (!verbosityParsed) { return(1); } return(parserResult.MapResult( #if DEBUG (AnalyzeAssemblyCommandLineOptions options) => AnalyzeAssembly(options), (FindSymbolsCommandLineOptions options) => FindSymbolsAsync(options).Result, (SlnListCommandLineOptions options) => SlnListAsync(options).Result, (ListVisualStudioCommandLineOptions options) => ListVisualStudio(options), (GenerateSourceReferencesCommandLineOptions options) => GenerateSourceReferencesAsync(options).Result, #endif (FixCommandLineOptions options) => FixAsync(options).Result, (AnalyzeCommandLineOptions options) => AnalyzeAsync(options).Result, (ListSymbolsCommandLineOptions options) => ListSymbolsAsync(options).Result, (FormatCommandLineOptions options) => FormatAsync(options).Result, (PhysicalLinesOfCodeCommandLineOptions options) => PhysicalLinesOfCodeAsync(options).Result, (LogicalLinesOfCodeCommandLineOptions options) => LogicalLinesOrCodeAsync(options).Result, (GenerateDocCommandLineOptions options) => GenerateDocAsync(options).Result, (GenerateDocRootCommandLineOptions options) => GenerateDocRootAsync(options).Result, _ => 1)); } catch (Exception ex) { if (ex is AggregateException aggregateException) { foreach (Exception innerException in aggregateException.InnerExceptions) { WriteError(innerException); } } else if (ex is FileNotFoundException || ex is InvalidOperationException) { WriteError(ex); } else { throw; } } finally { Out?.Dispose(); Out = null; #if DEBUG if (Debugger.IsAttached) { Console.ReadKey(); } #endif } return(1); }
private static int Main(string[] args) { #if DEBUG if (args.LastOrDefault() == "--debug") { WriteArgs(args.Take(args.Length - 1).ToArray(), Verbosity.Quiet); return(ExitCodes.NotSuccess); } #endif Parser parser = null; try { parser = CreateParser(ignoreUnknownArguments: true); if (args == null || args.Length == 0) { HelpCommand.WriteCommandsHelp(); return(ExitCodes.Success); } bool?success = null; ParserResult <BaseCommandLineOptions> defaultResult = parser .ParseArguments <BaseCommandLineOptions>(args) .WithParsed(options => { if (!options.Help) { return; } string commandName = args?.FirstOrDefault(); Command command = (commandName != null) ? CommandLoader.LoadCommand(typeof(Program).Assembly, commandName) : null; if (!ParseVerbosityAndOutput(options)) { success = false; return; } WriteArgs(args, Verbosity.Diagnostic); if (command != null) { HelpCommand.WriteCommandHelp(command); } else { HelpCommand.WriteCommandsHelp(); } success = true; }); if (success == false) { return(ExitCodes.Error); } if (success == true) { return(ExitCodes.Success); } parser = CreateParser(); ParserResult <object> parserResult = parser.ParseArguments( args, new Type[] { typeof(AnalyzeCommandLineOptions), typeof(FixCommandLineOptions), typeof(FormatCommandLineOptions), typeof(GenerateDocCommandLineOptions), typeof(GenerateDocRootCommandLineOptions), typeof(HelpCommandLineOptions), typeof(ListSymbolsCommandLineOptions), typeof(LogicalLinesOfCodeCommandLineOptions), typeof(MigrateCommandLineOptions), typeof(PhysicalLinesOfCodeCommandLineOptions), typeof(RenameSymbolCommandLineOptions), typeof(SpellcheckCommandLineOptions), #if DEBUG typeof(AnalyzeAssemblyCommandLineOptions), typeof(FindSymbolsCommandLineOptions), typeof(GenerateSourceReferencesCommandLineOptions), typeof(ListVisualStudioCommandLineOptions), typeof(ListReferencesCommandLineOptions), typeof(SlnListCommandLineOptions), #endif }); parserResult.WithNotParsed(e => { if (e.Any(f => f.Tag == ErrorType.VersionRequestedError)) { Console.WriteLine(typeof(Program).GetTypeInfo().Assembly.GetName().Version); success = false; return; } var helpText = new HelpText(SentenceBuilder.Create(), HelpCommand.GetHeadingText()); helpText = HelpText.DefaultParsingErrorsHandler(parserResult, helpText); VerbAttribute verbAttribute = parserResult.TypeInfo.Current.GetCustomAttribute <VerbAttribute>(); if (verbAttribute != null) { helpText.AddPreOptionsText(Environment.NewLine + HelpCommand.GetFooterText(verbAttribute.Name)); } Console.Error.WriteLine(helpText); success = false; }); if (success == true) { return(ExitCodes.Success); } if (success == false) { return(ExitCodes.Error); } parserResult.WithParsed <AbstractCommandLineOptions>( options => { if (ParseVerbosityAndOutput(options)) { WriteArgs(args, Verbosity.Diagnostic); } else { success = false; } }); if (success == false) { return(ExitCodes.Error); } return(parserResult.MapResult( (MSBuildCommandLineOptions options) => { switch (options) { case AnalyzeCommandLineOptions analyzeCommandLineOptions: return AnalyzeAsync(analyzeCommandLineOptions).Result; case FixCommandLineOptions fixCommandLineOptions: return FixAsync(fixCommandLineOptions).Result; case FormatCommandLineOptions formatCommandLineOptions: return FormatAsync(formatCommandLineOptions).Result; case GenerateDocCommandLineOptions generateDocCommandLineOptions: return GenerateDocAsync(generateDocCommandLineOptions).Result; case GenerateDocRootCommandLineOptions generateDocRootCommandLineOptions: return GenerateDocRootAsync(generateDocRootCommandLineOptions).Result; case ListSymbolsCommandLineOptions listSymbolsCommandLineOptions: return ListSymbolsAsync(listSymbolsCommandLineOptions).Result; case LogicalLinesOfCodeCommandLineOptions logicalLinesOfCodeCommandLineOptions: return LogicalLinesOrCodeAsync(logicalLinesOfCodeCommandLineOptions).Result; case PhysicalLinesOfCodeCommandLineOptions physicalLinesOfCodeCommandLineOptions: return PhysicalLinesOfCodeAsync(physicalLinesOfCodeCommandLineOptions).Result; case RenameSymbolCommandLineOptions renameSymbolCommandLineOptions: return RenameSymbolAsync(renameSymbolCommandLineOptions).Result; case SpellcheckCommandLineOptions spellcheckCommandLineOptions: return SpellcheckAsync(spellcheckCommandLineOptions).Result; #if DEBUG case FindSymbolsCommandLineOptions findSymbolsCommandLineOptions: return FindSymbolsAsync(findSymbolsCommandLineOptions).Result; case GenerateSourceReferencesCommandLineOptions generateSourceReferencesCommandLineOptions: return GenerateSourceReferencesAsync(generateSourceReferencesCommandLineOptions).Result; case ListReferencesCommandLineOptions listReferencesCommandLineOptions: return ListReferencesAsync(listReferencesCommandLineOptions).Result; case SlnListCommandLineOptions slnListCommandLineOptions: return SlnListAsync(slnListCommandLineOptions).Result; #endif default: throw new InvalidOperationException(); } }, (AbstractCommandLineOptions options) => { switch (options) { case HelpCommandLineOptions helpCommandLineOptions: return Help(helpCommandLineOptions); case MigrateCommandLineOptions migrateCommandLineOptions: return Migrate(migrateCommandLineOptions); #if DEBUG case AnalyzeAssemblyCommandLineOptions analyzeAssemblyCommandLineOptions: return AnalyzeAssembly(analyzeAssemblyCommandLineOptions); case ListVisualStudioCommandLineOptions listVisualStudioCommandLineOptions: return ListVisualStudio(listVisualStudioCommandLineOptions); #endif default: throw new InvalidOperationException(); } }, _ => ExitCodes.Error)); } catch (Exception ex) when(ex is AggregateException || ex is FileNotFoundException || ex is InvalidOperationException) { WriteError(ex); } finally { parser?.Dispose(); Out?.Dispose(); Out = null; } return(ExitCodes.Error); }
private static int Main(string[] args) { //WriteLine($"Orang Command Line Tool version {typeof(Program).GetTypeInfo().Assembly.GetName().Version}"); //WriteLine("Copyright (c) Josef Pihrt. All rights reserved."); //WriteLine(); try { Parser parser = CreateParser(ignoreUnknownArguments: true); bool help = false; ParserResult <BaseCommandLineOptions> defaultResult = parser .ParseArguments <BaseCommandLineOptions>(args) .WithParsed(options => { if (!options.Help) { return; } string?commandName = args?.FirstOrDefault(); Command?command = (commandName != null) ? CommandLoader.LoadCommand(typeof(Program).Assembly, commandName) : null; ParseVerbosityAndOutput(options); WriteArgs(args); if (command != null) { HelpCommand.WriteCommandHelp(command); } else { HelpCommand.WriteCommandsHelp(); } help = true; }) #if DEBUG .WithNotParsed(_ => { }); #else ; #endif if (help) { return(0); } bool success = true; parser = CreateParser(); ParserResult <object> parserResult = parser.ParseArguments < CopyCommandLineOptions, DeleteCommandLineOptions, EscapeCommandLineOptions, FindCommandLineOptions, HelpCommandLineOptions, ListPatternsCommandLineOptions, MatchCommandLineOptions, MoveCommandLineOptions, RenameCommandLineOptions, ReplaceCommandLineOptions, SplitCommandLineOptions >(args); parserResult.WithNotParsed(_ => { var helpText = new HelpText(SentenceBuilder.Create(), HelpCommand.GetHeadingText()); helpText = HelpText.DefaultParsingErrorsHandler(parserResult, helpText); VerbAttribute?verbAttribute = parserResult.TypeInfo.Current.GetCustomAttribute <VerbAttribute>(); if (verbAttribute != null) { helpText.AddPreOptionsText(Environment.NewLine + HelpCommand.GetFooterText(verbAttribute.Name)); } Console.Error.WriteLine(helpText); success = false; }); if (!success) { return(2); } parserResult.WithParsed <AbstractCommandLineOptions>(options => { success = ParseVerbosityAndOutput(options); WriteArgs(args); }); if (!success) { return(2); } return(parserResult.MapResult( (CopyCommandLineOptions options) => Copy(options), (MoveCommandLineOptions options) => Move(options), (DeleteCommandLineOptions options) => Delete(options), (EscapeCommandLineOptions options) => Escape(options), (FindCommandLineOptions options) => Find(options), (HelpCommandLineOptions options) => Help(options), (ListPatternsCommandLineOptions options) => ListPatterns(options), (MatchCommandLineOptions options) => Match(options), (RenameCommandLineOptions options) => Rename(options), (ReplaceCommandLineOptions options) => Replace(options), (SplitCommandLineOptions options) => Split(options), _ => 2)); } catch (Exception ex) { WriteError(ex); } finally { Out?.Dispose(); Out = null; } return(2); }
private static int Main(string[] args) { #if DEBUG // short command syntax if (args?.Length > 0) { switch (args[0]) { case "f": { ReplaceArgs("find"); break; } case "r": { ReplaceArgs("replace"); break; } } void ReplaceArgs(string commandName) { Array.Resize(ref args, args.Length + 1); for (int i = args.Length - 1; i >= 2; i--) { args[i] = args[i - 1]; } args[0] = commandName; args[1] = "-c"; } } #endif try { Parser parser = CreateParser(ignoreUnknownArguments: true); if (args == null || args.Length == 0) { HelpCommand.WriteCommandsHelp(); return(ExitCodes.Match); } var success = true; var help = false; ParserResult <BaseCommandLineOptions> defaultResult = parser .ParseArguments <BaseCommandLineOptions>(args) .WithParsed(options => { if (!options.Help) { return; } string?commandName = args?.FirstOrDefault(); Command?command = (commandName != null) ? CommandLoader.LoadCommand(typeof(Program).Assembly, commandName) : null; success = ParseVerbosityAndOutput(options); if (!success) { return; } WriteArgs(args); if (command != null) { HelpCommand.WriteCommandHelp(command); } else { HelpCommand.WriteCommandsHelp(); } help = true; }) #if DEBUG .WithNotParsed(_ => { }); #else ; #endif if (!success) { return(ExitCodes.Error); } if (help) { return(ExitCodes.Match); } parser = CreateParser(); ParserResult <object> parserResult = parser.ParseArguments < CopyCommandLineOptions, DeleteCommandLineOptions, EscapeCommandLineOptions, FindCommandLineOptions, HelpCommandLineOptions, ListPatternsCommandLineOptions, MatchCommandLineOptions, MoveCommandLineOptions, SpellcheckCommandLineOptions, RenameCommandLineOptions, ReplaceCommandLineOptions, SplitCommandLineOptions, SyncCommandLineOptions >(args); parserResult.WithNotParsed(_ => { var helpText = new HelpText(SentenceBuilder.Create(), HelpCommand.GetHeadingText()); helpText = HelpText.DefaultParsingErrorsHandler(parserResult, helpText); VerbAttribute?verbAttribute = parserResult.TypeInfo.Current.GetCustomAttribute <VerbAttribute>(); if (verbAttribute != null) { helpText.AddPreOptionsText(Environment.NewLine + HelpCommand.GetFooterText(verbAttribute.Name)); } Console.Error.WriteLine(helpText); success = false; }); if (!success) { return(ExitCodes.Error); } parserResult.WithParsed <AbstractCommandLineOptions>(options => { success = ParseVerbosityAndOutput(options); if (success) { WriteArgs(args); } }); if (!success) { return(ExitCodes.Error); } return(parserResult.MapResult( (CopyCommandLineOptions options) => Copy(options), (MoveCommandLineOptions options) => Move(options), (SyncCommandLineOptions options) => Sync(options), (DeleteCommandLineOptions options) => Delete(options), (EscapeCommandLineOptions options) => Escape(options), (FindCommandLineOptions options) => Find(options), (HelpCommandLineOptions options) => Help(options), (ListPatternsCommandLineOptions options) => ListPatterns(options), (MatchCommandLineOptions options) => Match(options), (SpellcheckCommandLineOptions options) => Spellcheck(options), (RenameCommandLineOptions options) => Rename(options), (ReplaceCommandLineOptions options) => Replace(options), (SplitCommandLineOptions options) => Split(options), _ => ExitCodes.Error)); } catch (Exception ex) { WriteError(ex); } finally { Out?.Dispose(); Out = null; } return(ExitCodes.Error); }
private static int Main(string[] args) { try { ParserResult <object> parserResult = Parser.Default.ParseArguments < MigrateCommandLineOptions, #if DEBUG AnalyzeAssemblyCommandLineOptions, FindSymbolsCommandLineOptions, SlnListCommandLineOptions, ListVisualStudioCommandLineOptions, GenerateSourceReferencesCommandLineOptions, ListReferencesCommandLineOptions, #endif FixCommandLineOptions, AnalyzeCommandLineOptions, ListSymbolsCommandLineOptions, FormatCommandLineOptions, SpellcheckCommandLineOptions, PhysicalLinesOfCodeCommandLineOptions, LogicalLinesOfCodeCommandLineOptions, GenerateDocCommandLineOptions, GenerateDocRootCommandLineOptions >(args); var verbosityParsed = false; parserResult.WithParsed <AbstractCommandLineOptions>(options => { var defaultVerbosity = Verbosity.Normal; if (options.Verbosity == null || TryParseVerbosity(options.Verbosity, out defaultVerbosity)) { ConsoleOut.Verbosity = defaultVerbosity; Verbosity fileLogVerbosity = defaultVerbosity; if (options.FileLogVerbosity == null || TryParseVerbosity(options.FileLogVerbosity, out fileLogVerbosity)) { if (options.FileLog != null) { var fs = new FileStream(options.FileLog, FileMode.Create, FileAccess.Write, FileShare.Read); var sw = new StreamWriter(fs, Encoding.UTF8, bufferSize: 4096, leaveOpen: false); Out = new TextWriterWithVerbosity(sw) { Verbosity = fileLogVerbosity }; } verbosityParsed = true; } } }); if (!verbosityParsed) { return(ExitCodes.Error); } WriteLine( $"Roslynator Command Line Tool version {typeof(Program).GetTypeInfo().Assembly.GetName().Version} " + $"(Roslyn version {typeof(Accessibility).GetTypeInfo().Assembly.GetName().Version})", Verbosity.Normal); return(parserResult.MapResult( #if DEBUG (AnalyzeAssemblyCommandLineOptions options) => AnalyzeAssembly(options), (FindSymbolsCommandLineOptions options) => FindSymbolsAsync(options).Result, (SlnListCommandLineOptions options) => SlnListAsync(options).Result, (ListVisualStudioCommandLineOptions options) => ListVisualStudio(options), (GenerateSourceReferencesCommandLineOptions options) => GenerateSourceReferencesAsync(options).Result, (ListReferencesCommandLineOptions options) => ListReferencesAsync(options).Result, #endif (FixCommandLineOptions options) => FixAsync(options).Result, (AnalyzeCommandLineOptions options) => AnalyzeAsync(options).Result, (ListSymbolsCommandLineOptions options) => ListSymbolsAsync(options).Result, (FormatCommandLineOptions options) => FormatAsync(options).Result, (SpellcheckCommandLineOptions options) => SpellcheckAsync(options).Result, (PhysicalLinesOfCodeCommandLineOptions options) => PhysicalLinesOfCodeAsync(options).Result, (LogicalLinesOfCodeCommandLineOptions options) => LogicalLinesOrCodeAsync(options).Result, (GenerateDocCommandLineOptions options) => GenerateDocAsync(options).Result, (GenerateDocRootCommandLineOptions options) => GenerateDocRootAsync(options).Result, (MigrateCommandLineOptions options) => Migrate(options), _ => ExitCodes.Error)); } catch (Exception ex) when(ex is AggregateException || ex is FileNotFoundException || ex is InvalidOperationException) { WriteError(ex); } finally { Out?.Dispose(); Out = null; } return(ExitCodes.Error); }
public void Dispose() { Out.Dispose(); Out = null; }