Ejemplo n.º 1
0
 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);
     }
 }
Ejemplo n.º 2
0
        public void GetConnectionCheck()
        {
            var now = DateTime.Now;
            var mv  = new MeasuredValue()
            {
                Name        = "",
                Description = "meine beschreibung",
                TimeStamp   = now,
                Value       = "test",
                Quality     = OPCQuality.NoValue
            };

            int affectedRows = ValueTableWriter.SaveValueWhenConditionsAreMet(mv, CompressionCondition.GetDefaultCondition());

            Assert.AreEqual(0, affectedRows);
            //ValueTableWriter valueTable = new ValueTableWriter();
            //MeasuredValue mv = valueTable.ReadLastMeasuredValueFromLocalDB("test", TypeCode.Double);
            //Assert.AreEqual(OPCQuality.NoValue, mv.Quality);
        }
Ejemplo n.º 3
0
        public void InsertIntoIntTable()
        {
            DateTime now      = DateTime.Now;
            string   tagName  = "MyMeasuredValue";
            int      tagValue = 12345678;
            string   remark   = "Bla Bla";
            int      count    = ValueTableWriter.SaveValueWhenConditionsAreMet(
                new MeasuredValue()
            {
                Name        = tagName,
                TimeStamp   = now,
                Quality     = OPCQuality.Good,
                Value       = tagValue,
                Description = remark
            }, CompressionCondition.GetNoCompressionCondition());

            Assert.AreEqual(1, count);

            count = ValueTableWriter.SaveValueWhenConditionsAreMet(
                new MeasuredValue()
            {
                Name        = tagName,
                TimeStamp   = now + new TimeSpan(0, 0, 0, 1, 1),
                Quality     = OPCQuality.Good,
                Value       = tagValue,
                Description = remark
            }, CompressionCondition.GetDefaultCondition());
            Assert.AreEqual(0, count);

            MeasuredValue mv = ValueTableWriter.ReadLastMeasuredValueFromLocalDB("MyMeasuredValue", TypeCode.Int32);

            Assert.AreEqual(tagName, mv.Name);
            TimeSpan sp = now - mv.TimeStamp;

            // Datenbankgenauigkeit ist bei Datum nicht hoch genug
            Assert.Greater(0.1, sp.TotalSeconds);
            Assert.AreEqual(tagValue, mv.Value);
            Assert.AreEqual(OPCQuality.Good, mv.Quality);
            Assert.AreEqual(remark, mv.Description);
        }