public void SaveScaleLine() { try { if (Status != EStatus.Working) { return; } if (LastLine.Line == string.Empty) { return; } Pesajes pesajes = Pesajes.NewList(); Pesaje item = pesajes.NewItem(); CopyFromLine(item, LastLine); pesajes.OpenNewSession(); pesajes.BeginTransaction(); pesajes.Save(); pesajes.CloseSession(); MyLogger.LogText("Line saved: " + LastLine.Line, "ScalesMng::SaveScaleLine"); Status = EStatus.Closed; } catch (Exception ex) { MyLogger.LogException(ex, "ScalesMng::SaveScaleLine"); Status = EStatus.Error; } }
public void LogException_ShouldLog_InnerException() { using (ShimsContext.Create()) { // Arrange var componentUnderTest = new MyLogger("loggingLevels"); var expected = new DateTime(2000, 1, 2, 1, 2, 3); System.Fakes.ShimDateTime.NowGet = () => expected; var exception = new Exception("Test"); var aggregateException = new AggregateException(exception); // Act componentUnderTest.LogException("cat1", aggregateException); // Assert componentUnderTest.Messages.ShouldHaveSameValueAs(new[] { new LoggedMessage { Category = "cat1", Level = LoggingLevel.Error, Message = $"When:{expected} Level:Error Category:cat1 Message:" + exception } }); } }
public void StopRead() { try { Status = PortMngStatus.Stop; if (PortReaderThread == null) { return; } while (PortReaderThread.IsAlive) { continue; } if (SerialPort != null) { SerialPort.Close(); } Status = PortMngStatus.Stop; } catch (Exception ex) { MyLogger.LogException(ex, "SerialPortMng::StopRead"); } finally { MyLogger.LogText("Port " + SerialPort.PortName + " CLOSED", "SerialPortMng::StopRead"); PortReaderThread = null; SerialPort = null; } }
protected void StartStatusMonitor() { try { if (Monitor) { MyLogger.LogText("MONITOR ENABLED", "ServiceBase::StartStatusMonitor"); MonitorMng.Instance.ComponentApiKey = ApiKey; MonitorMng.Instance.ComponentSecretKey = SecretKey; MonitorMng.Instance.ComponentSerial = SerialNumber; MonitorMng.Instance.ComponentName = ComponentName; MonitorMng.Instance.ComponentType = EComponentType.WinService; MonitorMng.Instance.ComponentStatus = EComponentStatus.OK; MonitorMng.Instance.ComponentInterval = MonitorPollInterval; MonitorMng.Instance.StartPoll(MonitorPollInterval); } else { MyLogger.LogText("MONITOR DISABLED", "ServiceBase::StartStatusMonitor"); } } catch (Exception ex) { MyLogger.LogException(ex, "ServiceBase::StartStatusMonitor"); } }
public void LogException_ShouldNotLog() { // Arrange var componentUnderTest = new MyLogger("loggingEmpty"); var exception = new Exception("Test"); // Act componentUnderTest.LogException("", exception); // Assert componentUnderTest.Messages.ShouldHaveSameValueAs(new List <LoggedMessage>()); }
public void BackupErrorHandler(object sender, iQExceptionHandler.ErrorEventArgs e) { Status = EStatus.Error; switch (e.Exception.Code) { case iQExceptionCode.INFO: MyLogger.LogText("BAQUP::INFO: " + e.Exception.Message); break; default: MyLogger.LogException(e.Exception, "BaQup::BackupErrorHandler"); break; } }
public void ScaleListeningStop() { try { SaveScaleLine(); SerialPortMng.Instance.Close(); _main = null; } catch (Exception ex) { MyLogger.LogException(ex, "ScalesMng::ScaleListeningStop"); } }
protected void PortLineReader() { try { if (SerialPort == null) { return; } Status = PortMngStatus.Reading; MyLogger.LogText("Opening port " + SerialPort.PortName + " ...", "SerialPortMng::PortLineReader"); SerialPort.Open(); MyLogger.LogText("Port " + SerialPort.PortName + " OPEN", "SerialPortMng::PortLineReader"); if (Status == PortMngStatus.Reading) { MyLogger.LogText("Listening Port " + SerialPort.PortName, "SerialPortMng::PortLineReader"); } string value = string.Empty; //Port Reading Loop while (Status == PortMngStatus.Reading) { try { value = SerialPort.ReadLine(); } catch (TimeoutException) { value = string.Empty; MyLogger.LogText("Port read Timeout", "SerialPortMng::PortLineReader"); } if (!string.IsNullOrEmpty(value)) { LineHandlerDelegate(value); } } MyLogger.LogText("Stop listening Port " + SerialPort.PortName, "SerialPortMng::PortLineReader"); } catch (Exception ex) { MyLogger.LogException(ex, "SerialPortMng::PortLineReader"); } }
public void Run() { if (Status == EStatus.Working) { return; } Status = EStatus.Working; try { MyLogger.LogText("BAQUP START", "BaQup::Run"); try { AppController.Instance.InitFromService(BackupErrorHandler); Principal.Login(Library.SettingsMng.GetServicesUser(), Library.SettingsMng.GetServicesPassword()); Library.SettingsMng.Instance.SetBackupsPath(Properties.Settings.Default.BACKUPS_PATH); CompanyList companies = CompanyList.GetList(AppContext.User.GetInfo(), false); AppController.AutoBackup(companies.ToList <ISchemaInfo>(), true); MyLogger.LogText("BAQUP FINISH", "BaQup::Run"); } catch (Exception ex) { Status = EStatus.Error; MyLogger.LogException(ex, "BaQup::Run"); } Status = EStatus.Closed; } catch (Exception ex) { Status = EStatus.Error; MyLogger.LogException(ex, "BaQup::Run"); } finally { AppController.Instance.Close(); } }
public void SaveScaleLine(string line) { try { if (IsNegativeLine(line)) { return; } if (ZeroLine(line)) { if (LastLine.Line != string.Empty) { Status = EStatus.Working; SaveScaleLine(); } LastLine.Line = string.Empty; return; } if (!IsStableLine(line)) { return; } if (!IsValidWeigth(line)) { return; } if (!IsDistinctLine(line)) { return; } LastLine.Line = line; LastLine.Date = DateTime.Now; } catch (Exception ex) { MyLogger.LogException(ex, "ScalesMng::SaveScaleLine"); } }
public MainForm() { InitializeComponent(); Globals.Instance.MainForm = this; Globals.Instance.Cursor = this.Cursor; Globals.Instance.StatusBar = this.Principal_StatusBar; Globals.Instance.StatusLabel = this.Status_Label; Globals.Instance.AnimLabel = this.Anim_Label; Globals.Instance.ProgressBar = this.Progress_Bar; Globals.Instance.ProgressInfoMng = ProgressInfoMng.Instance; SaveFile_DLG.InitialDirectory = System.Windows.Forms.Application.StartupPath + Library.Resources.Paths.BACKUPS; //Indicamos el FormMng quien es el formulario principal FormMng.Instance.MainForm = this; FormatControls(); try { AppController.Instance.Init(System.Windows.Forms.Application.ProductVersion); SettingsMng.Instance.SetApplicationName(System.Windows.Forms.Application.ProductName + " " + System.Windows.Forms.Application.ProductVersion); ApplyOptions(); } catch (Exception ex) { MyLogger.LogException(ex, "MainForm::MainForm()"); MessageBox.Show(ex.Message); } #if TRACE Controler.Instance.Timer = ProgressInfoMng.Instance.Timer; #endif //Fichero de ayuda //HelpProvider.HelpNamespace = System.Windows.Forms.Application.StartupPath + Controler.HELP_PATH; }