public void Process(BaseEvent _event) { if (_Methods.ContainsKey(_event.GetType().Name)) { _Methods[_event.GetType().Name].Invoke(this, new object[] { _event }); } else { //throw new NotImplementedException(string.Format("Метод обработки события {0} не найден.", _event.GetType().Name)); Console.WriteLine(string.Format("Метод обработки события {0} не найден.", _event.GetType().Name)); } }
public void PackEventClass(BaseEvent classEvent) { var eventType = classEvent.GetType(); m_eventClassName = eventType.Name; DataContractJsonSerializer JSONSerializer = new DataContractJsonSerializer(classEvent.GetType()); MemoryStream stream = new MemoryStream(); JSONSerializer.WriteObject(stream, classEvent); stream.Position = 0; m_eventClassJSONData = new StreamReader(stream).ReadToEnd(); //Console.WriteLine(m_eventClassJSONData); }
public void OnEvent(BaseEvent newEvent) { Console.WriteLine("Event come {0}", newEvent.GetType().Name); lock (Queue) { Queue.Enqueue(newEvent); } }
public void OnEvent(BaseEvent newEvent) { //Logger.log(newEvent.ToString(), "Received", InstantLogger.TypeMessage.error); DataContractJsonSerializer jsonSerializer = new DataContractJsonSerializer(newEvent.GetType()); MemoryStream stream = new MemoryStream(); jsonSerializer.WriteObject(stream, newEvent); stream.Position = 0; string str = new StreamReader(stream).ReadToEnd(); InstantLogger.log(str, "Received and Serialize", InstantLogger.TypeMessage.normal); }
public bool Insert(BaseEvent _event, int unitNumber) { try { string sql = string.Format("INSERT INTO {0}{1} (Time", _event.GetType().Name, unitNumber); List<OracleParameter> parametres = new List<OracleParameter>(); parametres.Add(new OracleParameter() { ParameterName = "Time", OracleDbType = OracleDbType.Date, Value = _event.Time, Direction = System.Data.ParameterDirection.Input }); string dataSql = ""; foreach (PropertyInfo property in GetDBPointProperties(_event.GetType())) { sql += string.Format(",{0}", property.Name); parametres.Add(new OracleParameter() { ParameterName = property.Name, OracleDbType = GetDBPointPropertiesType(property), Value = property.PropertyType.Name != "Boolean" ? _event.GetType().GetProperty(property.Name).GetValue(_event, null) : (bool) _event.GetType().GetProperty(property.Name).GetValue(_event, null) ? 1 : 0, Direction = System.Data.ParameterDirection.Input }); dataSql += string.Format(", :{0}", property.Name); } sql += string.Format(") VALUES (:Time{0})", dataSql); ExecuteNonQuery(sql, parametres.ToArray()); return true; } catch (OracleException exception) { if (exception.Message.IndexOf("3114") > 0) { try { Connection.Close(); Connection.Open(); } catch { } ; return false; } if (exception.Message.IndexOf("unique constraint") > 0 || exception.Message.IndexOf("-00001") > 0) return true; return false; } catch { return false; } }
public void OnEvent(BaseEvent newEvent) { using (var log = new Logger("DBWriterTT")) { try { var evtFlex = newEvent as FlexEvent; if (evtFlex != null) { try { if (DbLayerTrends.Instance.Insert(evtFlex, _unitNumber)) { log.msg(string.Format("{0}: inserted trends for {1} from {2}", newEvent.Time, newEvent.GetType().Name, _unitNumber)); } } catch (OracleException exception) { log.msg(string.Format("{0}: Can't inserted trends for {1} from {2}", newEvent.Time, newEvent.GetType().Name, _unitNumber)); log.err(exception.ToString()); } } else { var evt = (ConverterBaseEvent) newEvent; evt.iCnvNr = _unitNumber; if ((evt is LanceEvent) || (evt is OffGasAnalysisEvent) || (evt is OffGasEvent) || (evt is BoilerWaterCoolingEvent) || (evt is SlagOutburstEvent) || (evt is IgnitionEvent) || (evt is ModeLanceEvent) || (evt is ModeVerticalPathEvent) || (evt is CalculatedCarboneEvent) || (evt is ConverterAngleEvent)) { try { if (DbLayerTrends.Instance.Insert(evt)) { log.msg(string.Format("{0}: inserted trends for {1} from {2}", evt.Time, evt.GetType().Name, evt.iCnvNr)); } } catch (OracleException exception) { log.msg(string.Format("{0}: Can't inserted trends for {1} from {2}", evt.Time, evt.GetType().Name, evt.iCnvNr)); log.err(exception.ToString()); } } if ((evt is AdditionsEvent) || (evt is BlowingEvent) || (evt is ReBlowingEvent) || (evt is DeslaggingEvent) || (evt is HeatChangeEvent) || (evt is HeatingScrapEvent) || (evt is HotMetalLadleEvent) || (evt is HotMetalPouringEvent) || (evt is IgnitionEvent) || (evt is ResetO2TotalVolEvent) || (evt is ScrapChargingEvent) || (evt is ScrapEvent) || (evt is SlagBlowingEvent) || (evt is SublanceStartEvent) || (evt is SublanceCEvent) || (evt is SublanceOxidationEvent) || (evt is SublanceTemperatureEvent) || (evt is TappingEvent)) { try { if (DbLayerTelegrams.Instance.Insert(evt)) { log.msg(string.Format("{0}: inserted telergams for {1} from {2}", evt.Time, evt.GetType().Name, evt.iCnvNr)); } } catch (OracleException exception) { log.msg(string.Format("{0}: Can't inserted telergams trends for {1} from {2}", evt.Time, evt.GetType().Name, evt.iCnvNr)); log.err(exception.ToString()); } } } } catch(Exception ex) { log.err(ex.ToString()); } } }
private string PropertyValueToSqlString(BaseEvent _event, string propertyName) { var propertyType = _event.GetType().GetProperty(propertyName).PropertyType; var propertyValue = _event.GetType().GetProperty(propertyName).GetValue(_event,null); return (propertyType.Name.ToLower() == "datetime" || propertyType.Name.ToLower() == "string") ? string.Format("'{0}'", propertyValue) : string.Format("{0}", propertyValue); }
public bool Insert(BaseEvent _event, int unitNumber) { try { var sql = string.Format("INSERT INTO {0}{1} (Time", _event.GetType().Name, unitNumber); var dataSql = ""; foreach (var property in GetDBPointProperties(_event.GetType())) { sql += string.Format(",{0}", property.Name); dataSql += string.Format(",{0}", PropertyValueToSqlString(_event, property.Name)); } sql += string.Format(") VALUES ({0}{1})", OracleDate(_event.Time), dataSql); ExecuteNonQuery(sql); return true; } catch { return false; } }
private bool ProcessEvents(BaseEvent _event) { if (m_Methods.ContainsKey(_event.GetType().Name)) { return (bool)m_Methods[_event.GetType().Name].Invoke(this, new object[] { _event }); } return true; }
public void OnEvent(BaseEvent newEvent) { using (Logger l = new Logger("OnEvent")) { if (cTime.Day != DateTime.Now.Day) { cTime = DateTime.Now; InstantLogger.log("", "To be continued...", InstantLogger.TypeMessage.important); InstantLogger.LogFileInit(); InstantLogger.log("", "...Continuing", InstantLogger.TypeMessage.important); } l.msg(newEvent.GetType().FullName); if (newEvent is OPCDirectReadEvent) { OpcConnector.ProcessEvent(newEvent as OPCDirectReadEvent); return; } var plcg = new PLCGroup(); bool found = false; foreach (object x in newEvent.GetType().GetCustomAttributes(false)) { if (x.GetType().Name == "PLCGroup") { plcg = (PLCGroup) x; if (plcg.Destination == opcDestination_) { l.msg(" " + plcg.Location + " -- " + plcg.Destination); found = true; break; } } } if (!found) return; List<int> arrSrvH = new List<int>(); List<object> arrItmV = new List<object>(); var plcp = new PLCPoint(); foreach (var prop in newEvent.GetType().GetProperties()) { foreach (object x in prop.GetCustomAttributes(false)) { if (x.GetType().Name == "PLCPoint") { // InstantLogger.log(prop.GetCustomAttributesData()[1].ToString()); if (((PLCPoint) x).IsWritable) { plcp = (PLCPoint) x; var s = string.Format(opcAddressFmt_, plcg.Location, OPCFledged.OpcConnector.cnv(plcp.Location)); var sb = new StringBuilder(); sb.AppendFormat(" " + prop.Name + " = " + prop.GetValue(newEvent, null).ToString()); sb.AppendFormat("\n IsWritable = " + plcp.IsWritable.ToString()); sb.AppendFormat("\n " + plcp.Location + " % " + s); sb.AppendFormat("\n " + newEvent.GetType()); l.msg(sb.ToString()); int index = 0; bool eureka = false; while (index < OpcConnector.m_Item_defs.Count) { OPCItemDef v = OpcConnector.m_Item_defs[index]; //InstantLogger.msg("comparing <{0}> == <{1}>", v.ItemID, s); if (v.ItemID == s) { if (!v.Active) l.err("Item <{0}> is excluded from monitoring", v.ItemID); else { arrSrvH.Add(OpcConnector.m_Handles_srv[index]); l.msg("+++++ {0}", prop.PropertyType.ToString()); if (prop.PropertyType == (typeof (System.String))) { string w = prop.GetValue(newEvent, null).ToString(); List<byte> wb = new List<byte>(); for (int i = 0; i < w.Length; i++) { UInt16 b = (UInt16) w.ElementAt(i); if (b > 900) b -= 848; wb.Add((byte) b); } arrItmV.Add(wb.ToArray()); } else if (prop.PropertyType == (typeof (System.Boolean))) { if (!OpcConnector.FlagStore.ContainsKey(v.ItemID)) { l.err("First reference to <{0}> found on writing!!!", v.ItemID); OpcConnector.FlagStore.Add(v.ItemID, 0); } arrItmV.Add(BoolExpressions.SetBit(OpcConnector.FlagStore[v.ItemID], plcp.BitNumber, Convert.ToBoolean( prop.GetValue(newEvent, null)))); } else arrItmV.Add(prop.GetValue(newEvent, null)); } eureka = true; break; } index++; } if (!eureka) l.err("Item <{0}> is unknown to OPC Fledged", s); } } } } int count = arrItmV.Count; if (count > 0) { int[] aE; if (OpcConnector.m_The_grp.Write(arrSrvH.ToArray(), arrItmV.ToArray(), out aE)) l.msg("Done processing event -- true"); else { for (int i = 0; i < aE.Length; i++) { if (HRESULTS.Failed(aE[i])) { l.err("Item srvH={0} failed with HRESULT=0x{1:x} -- value {2}", arrSrvH[i], aE[i], arrItmV[i] ); } else l.msg("Item srvH={0} succseeded -- value {1}", arrSrvH[i], arrItmV[i]); } } } l.msg("Done processing event"); } }