// when encountering the same file name, create a file name with a index count addendum public bool CreateForWriting() { try { int i = 1; while (File.Exists(filename)) { ConstructFullPathName("_" + i.ToString("X2")); //a simple counter i++; } if (log != null) { log.TraceEvent(LogLevels.Info, 111, "Creating new output file: " + filename); } string path = Path.GetDirectoryName(filename); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } stream = File.Create(filename); writer = new StreamWriter(stream);// , System.Text.Encoding.Unicode); return(true); } catch (Exception e) { if (log != null) { log.TraceException(e); } return(false); } }
public AnalyzerHandler(double theTicSizeInSeconds, LMLoggers.LognLM logger) { ticSizeInSeconds = theTicSizeInSeconds; log = logger; verboseTrace = log.ShouldTrace(LogLevels.Verbose); numNeutronEventsReceived = 0; numNeutronEventsReceivedWhetherProcessedOrNot = 0; numNeutronEventsCompleted = 0; numCircuits = 0; timeOfLastNeutronEvent = 0; if (ticSizeInSeconds == 1e-7) { timeBaseConversion = 1ul; // no external to internal conversion } else if (ticSizeInSeconds == 1e-8) { timeBaseConversion = 10ul; // shift gate units from tics (1e-7) to shakes (1e-8) } #if USE_SPINTIME ResetSpinTime(); #endif //create stack of RawAnalysisProperties.circularListBlockIncrement neutron events, as a starting point InitializeEventList(); permissionToUseEndOfEvents = new SemaphoreSlim(1, 1); // LMKV-52 fix: create here with counter set at 1 and only 1 thread //set up the AH BackgroundWorker AHWorkerStopNow = false; AHWorkerHasCompleted = false; AHWorkerStopAtEndOfEvents = false; AHWorker = new BackgroundWorker(); AHWorker.WorkerSupportsCancellation = false; //parent will stop the worker with the boolean flags AHWorker.DoWork += new DoWorkEventHandler(AHWorkerDoWork); AHWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(AHWorkerRunWorkerCompleted); AHWorker.RunWorkerAsync(); // permissionToUseEndOfEventsRelease(); // LMKV-52 fix: allow 1 thread at a time now that bkg worker started //pause until the AHWorker is working... while (AHWorker.IsBusy == false) { //spin } log.TraceEvent(LogLevels.Verbose, (int)AnalyzerEventCode.AnalyzerHandlerEvent, "AnalyzerHandler constructor started its thread."); }
// assumes file is created and open, header and footer text is set and rows constructed. public virtual void CreateReport(UInt16 logResults) { lines = new List <string>(2 + rows.Length + 1); if (hf != null) { lines.Add(hf.header); lines.Add(hf.GetColumnHeader()); } string s; for (int i = 0; i < rows.Length; i++) { Row r = rows[i]; if (r != null) { s = rows[i].ToLine(separator); } else { s = sepAsString; } lines.Add(s); } if (hf != null) { lines.Add(hf.footer); } foreach (string ls in lines) { f.WriteLine(ls); } bool sendToLogFile = false, logToConsole = false; switch (logResults) { case 1: sendToLogFile = true; break; case 2: logToConsole = true; break; case 3: sendToLogFile = logToConsole = true; break; } if (sendToLogFile || logToConsole) { LMLoggers.LognLM log = loggers.Logger(LMLoggers.AppSection.App); TraceEventCache tec = new TraceEventCache(); foreach (string ls in lines) { if (sendToLogFile && logToConsole) { log.TraceEvent(LogLevels.Verbose, 717, ls); } else if (logToConsole) { log.TraceEventConsole(LogLevels.Verbose, 717, ls, tec); } else { log.TraceEventFileOnly(LogLevels.Verbose, 717, ls, tec); } } } }
public AnalyzerHandler(double theTicSizeInSeconds, LMLoggers.LognLM logger) { TickSizeInSeconds = theTicSizeInSeconds; log = logger; verboseTrace = log.ShouldTrace(LogLevels.Verbose); InitCounters(); #if USE_SPINTIME ResetSpinTime(); #endif //create stack of RawAnalysisProperties.circularListBlockIncrement neutron events, as a starting point //InitializeEventList(RawAnalysisProperties.circularListBlockIncrement); permissionToUseEndOfEvents = new SemaphoreSlim(1, 1); // LMKV-52 fix: create here with counter set at 1 and only 1 thread //set up the AH BackgroundWorker AHWorkerStopNow = false; AHWorkerHasCompleted = false; AHWorkerStopAtEndOfEvents = false; AHWorker = new BackgroundWorker(); AHWorker.WorkerSupportsCancellation = false; //parent will stop the worker with the boolean flags AHWorker.DoWork += new DoWorkEventHandler(AHWorkerDoWork); AHWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(AHWorkerRunWorkerCompleted); AHWorker.RunWorkerAsync(); // permissionToUseEndOfEventsRelease(); // LMKV-52 fix: allow 1 thread at a time now that bkg worker started //pause until the AHWorker is working... while (AHWorker.IsBusy == false) { //spin } log.TraceEvent(LogLevels.Verbose, (int)AnalyzerEventCode.AnalyzerHandlerEvent, "AnalyzerHandler constructor started its thread."); }