public void OnNext(DiagnosticCommand value) { if (StackExchange.Profiling.MiniProfiler.Current == null) { return; } if (value is ReadDiagnosticCommand readCommand) { if (readCommand.CommandState == CommandState.Start) { Commands[value.CommandId] = StackExchange.Profiling.MiniProfiler.Current.CustomTiming("mongoframework", readCommand.Queryable.ToQuery(), readCommand.Source); } else if (Commands.TryRemove(value.CommandId, out var current)) { if (readCommand.CommandState == CommandState.FirstResult) { Commands[value.CommandId] = current; current.FirstFetchCompleted(); } else { current.Errored = readCommand.CommandState == CommandState.Error; current.Stop(); } } } else if (value is WriteDiagnosticCommandBase writeCommandBase) { OnNextWriteCommand(writeCommandBase); } else if (value is IndexDiagnosticCommandBase indexCommandBase) { OnNextIndexCommand(indexCommandBase); } }
protected override void InternalProcessRecord() { base.InternalProcessRecord(); base.CheckExclusiveParameters(new object[] { "Organizations", "CurrentOrganization" }); if (!CacheApplicationManager.IsApplicationDefined(this.Application)) { base.WriteError(new ArgumentException(Strings.ErrorApplicationNotDefined(this.Application)), (ErrorCategory)1000, null); } ICollection <Guid> collection = this.ResolveOrganizations(); DiagnosticType diagnosticType = this.GetDiagnosticType(); DiagnosticType command = diagnosticType; ICollection <Guid> orgIds = collection; ICollection <Guid> entries; if (this.CacheKeys != null) { ICollection <Guid> cacheKeys = this.CacheKeys; entries = cacheKeys; } else { entries = new List <Guid>(); } DiagnosticCommand diagnosticCommand = new DiagnosticCommand(command, orgIds, entries); using (NamedPipeClientStream namedPipeClientStream = this.PrepareClientStream()) { byte[] array = diagnosticCommand.ToSendMessage(); byte[] array2 = new byte[5000]; try { namedPipeClientStream.Write(array, 0, array.Length); namedPipeClientStream.Flush(); int num; do { Array.Clear(array2, 0, array2.Length); num = namedPipeClientStream.Read(array2, 0, array2.Length); if (num > 0) { this.ProcessReceivedData(array2, num); } }while (num > 0 && namedPipeClientStream.IsConnected); } catch (IOException exception) { base.WriteError(exception, (ErrorCategory)1001, null); } catch (ObjectDisposedException exception2) { base.WriteError(exception2, (ErrorCategory)1001, null); } catch (NotSupportedException exception3) { base.WriteError(exception3, (ErrorCategory)1001, null); } catch (InvalidOperationException exception4) { base.WriteError(exception4, (ErrorCategory)1001, null); } } }
/// <summary> /// /// </summary> /// <param name="args"></param> static void Main(string[] args) { //Initialise log output LogDefinition log = new LogDefinition(LOG_ID, Environment.CurrentDirectory + @"\Logs\SparkConsole.log"); LogDefinitionList.Instance.Add(LOG_ID, log); //Log arguments StringBuilder argText = new StringBuilder(); for (int i = 0; i < args.Count(); i++) { argText.Append(string.Format("[{0}]={1} ", i, args[i])); } log.WriteLine("Intiated"); log.WriteLine("ARGUMENTS: " + argText.ToString()); //Execute command try { //Get command identifier if (args.Count() == 0) { throw new ArgumentException("Command not specified"); } string commandId = args[0].ToLower(); IConsoleCommand command = null; switch (commandId) { case "exportmarket": command = new ExportMarketCommand(log); break; case "exportsecurity": command = new ExportSecurityCommand(log); break; case "diagnostic": command = new DiagnosticCommand(log); break; case "test": log.WriteLine("Test log entry"); break; default: throw new ArgumentException("Command '" + commandId + "' not recognised"); } //Execute command if (command != null) { command.Execute(args); } } catch (ArgumentException ex) { log.WriteLine("ERROR: " + ex.Message); } catch (Exception ex) { log.WriteLine("ERROR: " + ex.Message + "\r\n" + ex.StackTrace); } //Flush log buffer log.WriteLine("Completed\r\n"); LogDefinitionList.Instance.Flush(); }