private void SaveEnergyValues(SmlMessageFinder smlCutter, SmlMessageParser parser) { var box = new MeasureValueBox(); box.MeasuredUtcTime = DateTime.UtcNow; box.MeasuredValues.Add("EHZ.MeasureTime", DateTime.Now); box.MeasuredValues.Add("EHZ.ConsumedEnergy1", parser.ConsumedEnergy1_Wh); box.MeasuredValues.Add("EHZ.ConsumedEnergy2", parser.ConsumedEnergy2_Wh); box.MeasuredValues.Add("EHZ.ProducedEnergy1", parser.ProducedEnergy1_Wh); box.MeasuredValues.Add("EHZ.ProducedEnergy2", parser.ProducedEnergy2_Wh); box.MeasuredValues.Add("EHZ.Device", parser.Device); box.MeasuredValues.Add("EHZ.CompanyName", parser.CompanyName); _Queue.Send(box); }
private void TransferQueueToDatebase(string messageQueuePath) { try { var simpleMessageQueueWrapper = new SimpleMessageQueueWrapper <IDictionary <string, object> >(); simpleMessageQueueWrapper.Initialize(messageQueuePath); var dictionary = simpleMessageQueueWrapper.Peek(); int num = 500; while (dictionary != null && num-- >= 0) { IEnumerable <string> source = from key in dictionary.Keys where key.Contains("MeasureTime") select key; string timeKeyName = source.FirstOrDefault <string>(); if (timeKeyName != null) { DateTime dateTime = (DateTime)dictionary[timeKeyName]; IEnumerable <string> enumerable = from key in dictionary.Keys where key != timeKeyName select key; foreach (string current in enumerable) { MeasuredValue measuredValue = new MeasuredValue(); measuredValue.Name = current; measuredValue.Quality = OPCQuality.Good; measuredValue.TimeStamp = (DateTime)dictionary[timeKeyName]; measuredValue.Description = ""; measuredValue.Value = dictionary[current]; if (measuredValue.Value is long) { measuredValue.Value = Convert.ToInt32(measuredValue.Value.ToString()); } _Logger.DebugFormat("save to local DB: {0}", measuredValue); ValueTableWriter.SaveValueWhenConditionsAreMet(measuredValue, _CompressionConditionManager.GetConfigFor(current)); } dictionary = simpleMessageQueueWrapper.Receive(); } else { _Logger.Error("cannot find a 'MeasureTime' in the message directory. Send message to ErrorQueue"); _ErrorQueue.Send(dictionary); dictionary = simpleMessageQueueWrapper.Receive(); } dictionary = simpleMessageQueueWrapper.Peek(); } ValueTableWriter.TransferDataToDestDB(); } catch (Exception ex) { _Logger.Error(ex.Message, ex); } }
protected void SendToQueue(MeasureValueBox measureValueBox) { _Queue.Send(measureValueBox); }