public bool InsertPumpTimeSlots(int siteId, string dataJson) { ServiceLog sl = new ServiceLog(); try { SiteId = siteId; mq = new MeterQueries(siteId); List <PUMPTIMESLOTSEntity> data = JsonConvert.DeserializeObject <List <PUMPTIMESLOTSEntity> >(dataJson); if (data == null) { return(false); } foreach (var slot in data) { mq.AddPumpTimeSlot(slot.PATIENTID, slot); } return(true); } catch (Exception ex) { //log... sl.Log(Guid.Empty, "InsertPumpTimeSlots", "FirebirdDatabaseService", ex.StackTrace, $"SiteId: {SiteId} - Exception: {ex.Message}", dataJson, ServiceLog.TraceEventType.Error); return(false); } }
public List <ServiceLog> RetrieveLog(long serviceId, long limitDate) { List <ServiceLog> logs = new List <ServiceLog>(); SQLiteConnection connection = (SQLiteConnection)DatabaseContext.GetConnection(); connection.Open(); SQLiteCommand command = connection.CreateCommand(); command.CommandType = CommandType.Text; command.CommandText = "SELECT * FROM servicelog WHERE serviceid=@0 AND date > @1 ORDER BY date"; command.Parameters.Add(new SQLiteParameter("@0", serviceId)); command.Parameters.Add(new SQLiteParameter("@1", limitDate)); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) { ServiceLog log = new ServiceLog(); log.id = Convert.ToInt64(reader["id"]); log.serviceId = Convert.ToInt64(reader["serviceid"]); log.text = Convert.ToString(reader["text"]); log.date = Convert.ToInt64(reader["date"]); logs.Add(log); } reader.Close(); connection.Close(); return(logs); }
//Обработчики команд private void ExecuteAddServiceLog(object parameter) { ServiceLog sl = new ServiceLog() { Date = Date.ToShortDateString(), Device = SelectedDevice, Repairer = SelectedUser }; sl.ParametersValues = new List <ParameterValue>(); foreach (var item in ParametersValues) { sl.ParametersValues.Add(item); } foreach (var item in SelectedServices) { sl.ServicesDone.Add(new ServiceDone { RowidServiceForModel = item.Rowid }); } foreach (var item in SelectedSpares) { sl.SparesUsed.Add(new SpareUsed { RowidSpareForModel = item.Rowid }); } if (_dbContext is SQLiteContext) { SQLiteContext context = _dbContext as SQLiteContext; context.ServiceLog.Add(sl); context.SaveChanges(); context.Configuration.LazyLoadingEnabled = true; context.Database.Initialize(true); } }
private void buttonConvert_Click(object sender, EventArgs e) { using (AD2DBInitialParams initParams = AD2DBInitialParams.GetParams()) { textBoxLog.Text = string.Empty; ServiceLog log = new ServiceLog("ADToAccredit"); log.AddTextBoxTraceListener(textBoxLog); initParams.Log = log; this._ProcessedObjectsCount = 0; OutputStatus(); initParams.BeforeProcessADObject += new BeforeProcessADObjectDelegate(initParams_BeforeProcessADObject); AD2DBConvertion converter = new AD2DBConvertion(initParams); converter.DoConvert(); OutputStatus(); OguMechanismFactory.GetMechanism().RemoveAllCache(); PermissionMechanismFactory.GetMechanism().RemoveAllCache(); } }
public async Task PrePublish <T>(PublishContext <T> context) where T : class { Guid operationId; Exception exception = null; Guid.TryParse(context.Headers.Get(LogConstansts.Common.OperationId, ""), out operationId); var publisher = context.Headers.Get(LogConstansts.QueueMessageHeaderNames.Publisher, ""); if (operationId == Guid.Empty) { exception = new Exception("Operation Id was not set in header of" + typeof(T).Name + " message"); } if (string.IsNullOrEmpty(publisher)) { exception = new Exception("Publisher was not set in header of" + typeof(T).Name + " message"); } var log = new ServiceLog(operationId, LogConstansts.Protocols.Ampq, publisher, DateTime.UtcNow, TimeSpan.Zero, exception, 0, 0, context.DestinationAddress.AbsoluteUri, context.SourceAddress.AbsoluteUri, "From JWT in headers", "From JwT in headers", LogConstansts.Levels.Debug, false, false, true, false, context, ""); await loggingBusControl.Log(log); }
public bool InsertMeterReadings(int siteId, string dataJson) { ServiceLog sl = new ServiceLog(); try { SiteId = siteId; mq = new MeterQueries(siteId); List <METERREADINGEntity> data = JsonConvert.DeserializeObject <List <METERREADINGEntity> >(dataJson); if (data == null) { return(false); } mq.BulkInsertMeterReading(data); return(true); } catch (Exception ex) { //log... sl.Log(Guid.Empty, "InsertMeterReadings", "FirebirdDatabaseService", ex.StackTrace, $"SiteId: {SiteId} - Exception: {ex.Message}", dataJson, ServiceLog.TraceEventType.Error); return(false); } }
public bool InsertPatientPumpProgram(int siteId, string dataJson) { ServiceLog sl = new ServiceLog(); try { SiteId = siteId; mq = new MeterQueries(siteId); PATIENTPUMPPROGRAMEntity data = JsonConvert.DeserializeObject <PATIENTPUMPPROGRAMEntity>(dataJson); if (data == null) { return(false); } mq.AddPatientPumpProgram(data); return(true); } catch (Exception ex) { //log... sl.Log(Guid.Empty, "InsertPatientPumpProgram", "FirebirdDatabaseService", ex.StackTrace, $"SiteId: {SiteId} - Exception: {ex.Message}", dataJson, ServiceLog.TraceEventType.Error); return(false); } }
public void logMessage(string message, bool online = true) { ServiceConfiguration config = ServiceConfiguration.Instance; var newLog = new ServiceLog( config.serviceId, ServiceType.SensorReader, message, LogLevel.Message); string serializedLog = JsonSerializer.Serialize(newLog); lock (this.msgLock) { if (!File.Exists(this.messageLogPath)) { File.Create(this.messageLogPath).Close(); } File.AppendAllText(this.messageLogPath, "\n" + serializedLog); } if (config.consoleLogLevel.Contains(config.logMessageLevel)) { Console.WriteLine(serializedLog); } }
public bool UpdateInsuletPumpSettings(int siteId, string dataJson) { ServiceLog sl = new ServiceLog(); try { SiteId = siteId; mq = new MeterQueries(siteId); INSULETPUMPSETTINGSEntity data = JsonConvert.DeserializeObject <INSULETPUMPSETTINGSEntity>(dataJson); if (data == null) { return(false); } mq.UpdateInsuletPumpSettings(data.PATIENTID, data); return(true); } catch (Exception ex) { //log... sl.Log(Guid.Empty, "UpdateInsuletPumpSettings", "FirebirdDatabaseService", ex.StackTrace, $"SiteId: {SiteId} - Exception: {ex.Message}", dataJson, ServiceLog.TraceEventType.Error); return(false); } }
public void logError(string error, bool online = true) { ServiceConfiguration config = ServiceConfiguration.Instance; ServiceLog newLog = new ServiceLog( config.serviceId, ServiceType.SensorReader, error, LogLevel.Error); string serializedLog = JsonSerializer.Serialize(newLog); lock (this.errorLock) { if (!File.Exists(this.errorLogPath)) { File.Create(this.errorLogPath).Close(); } File.AppendAllText(this.errorLogPath, "\n" + serializedLog, Encoding.UTF8); } if (config.consoleLogLevel.Contains(config.logErrorLevel)) { Console.WriteLine(serializedLog); } }
public void Run() { serverSocket = null; clientSocket = null; try { ServiceLog.Info(string.Format("正在启动 Modbus RTU 数据采集服务[{0} {1}:{2}]", ServerID, server_ip, server_port)); IPEndPoint endPoint = new IPEndPoint(server_ip, server_port); serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); serverSocket.Bind(endPoint); serverSocket.Listen(10); ServiceLog.Info(string.Format("启动 Modbus RTU 数据采集服务[{0} {1}:{2}]成功,正在接收连接...", ServerID, server_ip, server_port)); } catch (Exception ex) { ServiceLog.Error(string.Format("启动 Modbus RTU 数据采集服务[{0} {1}:{2}]发生错误:{3}", ServerID, server_ip, server_port, ex.Message)); return; } while (true) { Thread.Sleep(100); clientSocket = AcceptConnection(); } }
public bool UpdateDmdata(int siteId, string dataJson) { ServiceLog sl = new ServiceLog(); try { SiteId = siteId; mq = new MeterQueries(siteId); DMDATAEntity data = JsonConvert.DeserializeObject <DMDATAEntity>(dataJson); if (data == null) { return(false); } mq.UpdateDmDataValues(data.PATIENTID, data.LOWBGLEVEL, data.HIGHBGLEVEL, data.LASTMODIFIEDDATE); return(true); } catch (Exception ex) { //log... sl.Log(Guid.Empty, "UpdateDmdata", "FirebirdDatabaseService", ex.StackTrace, $"SiteId: {SiteId} - Exception: {ex.Message}", dataJson, ServiceLog.TraceEventType.Error); return(false); } }
object IClientMessageInspector.BeforeSendRequest(ref System.ServiceModel.Channels.Message request, IClientChannel channel) { try { this.ServiceLogEntity = new ServiceLog { Module = this.ModuleName, ActionName = request.Headers.Action.Split('/').Last(), OutgoingXml = request.ToString(), RequestDate = DateTime.Now }; if (this.ServiceLogEntity.ActionName == "Divide") { this.ServiceLogEntity.HintKey = "Divide process started."; } } catch (Exception ex) { this.ServiceLogEntity = new ServiceLog { Module = this.ModuleName, ActionName = request.Headers.Action.Split('/').Last(), OutgoingXml = "Hata" + ex.Message, RequestDate = DateTime.Now }; } _logRepository.InsertOrUpdateServiceLog(this.ServiceLogEntity); return(this.ServiceLogEntity.Id); }
// 只读 public string ReadCard() { int sector = 3; st = Program.rf_card(icdev, 1, snr); //寻卡 if (st != 0) { // list_m.Items.Add("寻卡失败"); Thread.Sleep(1000); // Program.rf_beep(icdev, 10); // 蜂鸣时间,单位是50毫秒 return(ReadCard()); } else { byte[] snr1 = new byte[8]; // list_m.Items.Add("寻卡成功!"); Program.hex_a(snr, snr1, 4); // 读取软件版本号 // list_m.Items.Add(System.Text.Encoding.Default.GetString(snr1)); Program.rf_beep(icdev, 50); // 蜂鸣时间,单位是50毫秒 ServiceLog.WriteServiceLog(ServiceLog.CARD_SERVICE, "读卡数据:" + snr1, "", DateTime.Now); return(System.Text.Encoding.Default.GetString(snr1)); } // Program.rf_halt(icdev); // 执行该命令后如果是ALL寻卡模式则必须重新寻卡才能够对该卡操作,如果是IDLE模式则必须把卡移开感应区再进来才能寻得这张卡。 // Program.rf_beep(icdev, 50); // 蜂鸣时间,单位是50毫秒 }
public async Task ConsumeFault <T>(ConsumeContext <T> context, TimeSpan duration, string consumerType, Exception exception) where T : class { Guid operationId; Guid.TryParse(context.Headers.Get(LogConstansts.Common.OperationId, ""), out operationId); var publisher = context.Headers.Get(LogConstansts.QueueMessageHeaderNames.Publisher, ""); var additionalInfo = ""; if (operationId == Guid.Empty) { additionalInfo = "Operation Id was not set in header of" + typeof(T).Name + " message"; } if (string.IsNullOrEmpty(publisher)) { additionalInfo = "Publisher was not set in header of" + typeof(T).Name + " message"; } var log = new ServiceLog(operationId, LogConstansts.Protocols.Ampq, $"Publisher: {publisher} \r\n Consumer:{consumerType}", DateTime.UtcNow, duration, exception, 0, 0, context.DestinationAddress.AbsoluteUri, context.SourceAddress.AbsoluteUri, "From JWT in headers", "From JwT in headers", LogConstansts.Levels.Debug, false, false, false, true, context, "", additionalInfo); await loggingBusControl.Log(log); }
private void SearchForStackTrace() { var parameters = new Hashtable { { "project", TeamProject } }; var crc = (int)Crc32.GetStreamCrc32(exception.StackTrace); parameters.Add("checksum", crc); string query = "SELECT [System.ID],[StackTrace], [System.Title] from WorkItems where [System.TeamProject] = @project AND " + "[System.WorkItemType]='Exception' and [StackChecksum] = " + crc; var wiql = new Wiql { Query = query }; using (var workItemTrackingHttpClient = new WorkItemTrackingHttpClient(new Uri(this.ApplicationInfo.AccountUri), Credentials)) { var items = workItemTrackingHttpClient.QueryByWiqlAsync(wiql).Result; if (items == null || !items.WorkItems.Any()) { ServiceLog.Error("WorkItemStore unexpectedly returned null for query: " + query); return; } workItems = items.WorkItems.Cast <WorkItem>(); } }
public SView(ServiceLog serviceLog, int index) { ServiceLog = serviceLog; ServiceCategories = CalculateCategory(serviceLog); Categories = String.Empty; Index = index; }
private void PortableAdded(object sender, EventArrivedEventArgs e) { try { var pd = e.NewEvent.Properties["TargetInstance"]; { var mbo = pd.Value as ManagementBaseObject; if (mbo != null) { var driveinfo = mbo.Properties["Caption"].Value.ToString(); if (driveinfo.Contains("USB Composite Device")) { var thread = new Thread(DisplayFormThreadForPortable); thread.SetApartmentState(ApartmentState.STA); thread.Start("vincapture"); } } } } catch (Exception ex) { ServiceLog.ErrorImportLog(ex.Message); ServiceLog.ErrorImportLog(ex.StackTrace); } }
public void publishLog(ServiceLog log) { ServiceConfiguration config = ServiceConfiguration.Instance; this.PublishEvent(log, config.serviceLogTopic, config.registryLogFilter); }
protected override void OnMessage(MessageEventArgs e) { var msg = e.Data; var message = ReadCard(); Send(message); ServiceLog.WriteServiceLog(ServiceLog.HT_SERVICE, "发送数据:", message, DateTime.Now); }
public string LogMessage(string message) { var log = new ServiceLog( ServiceConfiguration.Instance.serviceId, ServiceType.SensorRegistry, message, LogLevel.Message); broker.publishLog(log); return(JsonConvert.SerializeObject(log, Formatting.Indented)); }
public EditServiceLogVM(long rowid) { ParametersValues = new ObservableCollection <ParameterValue>(); Services = new ObservableCollection <ServiceForModel>(); Spares = new ObservableCollection <SpareForModel>(); Users = new ObservableCollection <Repairer>(); OldServices = new ObservableCollection <ServiceForModel>(); OldSpares = new ObservableCollection <SpareForModel>(); NewSpare = false; NewService = false; _selectedServices = new ObservableCollection <ServiceForModel>(); _selectedSpares = new ObservableCollection <SpareForModel>(); _dbContext = SingletonDBContext.GetInstance(new SQLiteContext()).DBContext; if (_dbContext is SQLiteContext) { SQLiteContext context = _dbContext as SQLiteContext; _serviceLog = context.ServiceLog.Where(s => s.Rowid == rowid).SingleOrDefault(); //var parameters = context.ParameterForModel.Where(pfm => pfm.RowidModel == _serviceLog.Device.RowidModel).ToList(); //foreach (var item in parameters) //{ // var pv = context.ServiceLog.Where(s => s.Device.Rowid == _serviceLog.Device.Rowid).ToList().LastOrDefault()?.ParametersValues.ToList().LastOrDefault(); // if (pv == null) // { // ParametersValues.Add(new ParameterValue() { RowidParameterForModel = item.Rowid, ParameterForModel = item, Value = item.Parameter.Default }); // } // else // { // ParametersValues.Add(new ParameterValue() { RowidParameterForModel = item.Rowid, ParameterForModel = item, Value = pv.Value }); // } //} context.ParameterValue.Where(pv => pv.ServiceLog.Rowid == _serviceLog.Rowid).ToList().ForEach(item => ParametersValues.Add(item)); List <ParameterForModel> tempPFM = ParametersValues.Select(pv => pv.ParameterForModel).ToList(); var temp = context.ParameterForModel.Where(pfm => pfm.RowidModel == _serviceLog.Device.RowidModel).ToList(); temp = temp.Where(item => !tempPFM.Contains(item)).ToList(); if (temp != null) { temp.ForEach(item => ParametersValues.Add(new ParameterValue() { ParameterForModel = item })); } context.ServiceForModel.Where(s => s.RowidModel == _serviceLog.Device.RowidModel).ToList().ForEach(item => Services.Add(item)); context.SpareForModel.Where(s => s.RowidModel == _serviceLog.Device.RowidModel).ToList().ForEach(item => Spares.Add(item)); context.Repairer.ToList().ForEach(item => Users.Add(item)); SelectedUser = _serviceLog.Repairer; _serviceLog.SparesUsed.Select(su => su.SpareForModel).ToList().ForEach(item => OldSpares.Add(item)); _serviceLog.ServicesDone.Select(sd => sd.ServiceForModel).ToList().ForEach(item => OldServices.Add(item)); } Date = _serviceLog.DateTime; Title = String.Format("Изменить {0} I/N - \"{1}\" | S/N - \"{2}\"", _serviceLog.Device.Model.TypeModel.ShortName, _serviceLog.Device.InventoryNumber, _serviceLog.Device.SerialNumber); }
/// <summary> /// Called when [message processing]. /// </summary> /// <returns></returns> protected virtual bool OnMessageProcessing() { try { var messageProcessing = MessageProcessing; if (messageProcessing != null) { messageProcessing(this, null); } } catch (Exception ex) { ServiceLog.ErrorFormat("Failed raising 'finished message processing' event.", ex); return(false); } return(true); }
/// <summary> /// 关闭串口 /// </summary> public void CloseCom() { try //关闭串口 { sp.Close(); isOpen = false; ServiceLog.WriteServiceLog(ServiceLog.VC_SERVICE, "关闭串口", "", DateTime.Now); } catch (Exception) { ServiceLog.WriteServiceLog(ServiceLog.VC_SERVICE, "关闭串口时发生错误", "", DateTime.Now); } }
/// <summary> /// Called when [message received]. /// </summary> /// <param name="m">The m.</param> /// <returns></returns> protected virtual bool OnMessageReceived(TransportMessage m) { try { var messageReceived = MessageReceived; if (messageReceived != null) { messageReceived(this, new MessageReceivedEventArgs(m)); } } catch (Exception ex) { ServiceLog.WarningFormat("Failed raising 'transport message received' event for message with ID=" + m.Id, ex); return(false); } return(true); }
/// <summary> /// Called when [message processing failed]. /// </summary> /// <returns></returns> protected virtual bool OnMessageProcessingFailed() { try { var messageProcessingFailed = MessageProcessingFailed; if (messageProcessingFailed != null) { messageProcessingFailed(this, null); } } catch (Exception ex) { ServiceLog.WarningFormat("Failed raising 'failed message processing' event.", ex); return(false); } return(true); }
private async void LogRequest(ServiceLog requestLog, string clientId, ResponseCodeType responseCode, Stopwatch requestWatch, bool logRolling) { try { requestLog.ResponseCode = responseCode; requestWatch.Stop(); requestLog.TimeTakenMs = requestWatch.ElapsedMilliseconds; await mongoRepository.Add(requestLog, clientId, requestLog.GetType().Name, logRolling); } catch (Exception exception) { logger.LogError("Error logging service request: " + exception.Message); } }
private void ReconnectToServer() { try { ServiceLog.Info(string.Format("正在重新建立 Modbus TCP 数据采集连接[{0} {1}:{2}]", ServerID, server_ip, server_port)); clientSocket = AcceptConnection(); ServiceLog.Info(string.Format("重新建立 Modbus TCP 数据采集连接[{0} {1}:{2}]成功...", ServerID, server_ip, server_port)); } catch (Exception ex) { ServiceLog.Error(string.Format("重新建立 Modbus TCP 数据采集连接[{0} {1}:{2}]发生错误:{3}", ServerID, server_ip, server_port, ex.Message)); return; } }
protected override void OnMessage(MessageEventArgs e) { if (isOpen == false) { OpenCom(); } var msg = e.Data; var message = ReadCard(); Send(message); Console.WriteLine(message); ServiceLog.WriteServiceLog(ServiceLog.HT_SERVICE, "发送数据:", message, DateTime.Now); }
private IList <ServiceCategory> CalculateCategory(ServiceLog serviceLog) { List <ServiceCategory> serviceCategories = new List <ServiceCategory>(); long complexity = 0; serviceLog.ServicesDone.ToList().ForEach(i => complexity += i.ServiceForModel.Service.Price); DbContext dbContext = SingletonDBContext.GetInstance(new SQLiteContext()).DBContext; if (dbContext is SQLiteContext) { var context = dbContext as SQLiteContext; serviceCategories = context.ServiceCategory.ToList().FindAll(s => complexity >= s.MinValue && complexity <= s.MaxValue).ToList(); } return(serviceCategories); }