public object Deserialize(JsonValue value, JsonMapper mapper)
        {
            DeltaPage deltaPage = new DeltaPage();

            deltaPage.Cursor  = value.GetValue <string>("cursor");
            deltaPage.HasMore = value.GetValue <bool>("has_more");
            deltaPage.Reset   = value.GetValue <bool>("reset");
            deltaPage.Entries = new List <DeltaEntry>();
            JsonValue entriesValue = value.GetValue("entries");

            if (entriesValue != null)
            {
                foreach (JsonValue entryValue in entriesValue.GetValues())
                {
                    DeltaEntry deltaEntry = new DeltaEntry();
                    deltaEntry.Path = entryValue.GetValue <string>(0);
                    JsonValue metadataValue = entryValue.GetValue(1) as JsonObject;
                    if (metadataValue != null)
                    {
                        deltaEntry.Metadata = mapper.Deserialize <Entry>(metadataValue);
                    }
                    deltaPage.Entries.Add(deltaEntry);
                }
            }
            return(deltaPage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Builds a DeltaEntry object from a list of JRaw responses
        /// </summary>
        /// <param name="stringList"></param>
        /// <returns></returns>
        private DeltaEntry JRawListToDeltaEntry(List <JRaw> stringList)
        {
            var deltaEntry = new DeltaEntry
            {
                Path = JToken.Parse(stringList[0].ToString()).Value <string>()
            };

            if (!String.IsNullOrEmpty(stringList[1].ToString()))
            {
                deltaEntry.MetaData = JsonConvert.DeserializeObject <Metadata>(stringList[1].ToString());
            }
            return(deltaEntry);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Builds a DeltaEntry object from a list of string responses
        /// </summary>
        /// <param name="stringList"></param>
        /// <returns></returns>
        private DeltaEntry StringListToDeltaEntry(List <string> stringList)
        {
            var deltaEntry = new DeltaEntry
            {
                Path = stringList[0]
            };

            if (!String.IsNullOrEmpty(stringList[1]))
            {
                deltaEntry.MetaData = JsonConvert.DeserializeObject <Metadata>(stringList[1]);
            }
            return(deltaEntry);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Helper function to convert a stringlist to a DeltaEntry object
        /// </summary>
        /// <param name="stringList"></param>
        /// <returns></returns>
        private DeltaEntry StringListToDeltaEntry(List <string> stringList)
        {
            var deltaEntry = new DeltaEntry
            {
                Path = stringList[0]
            };

            if (!String.IsNullOrEmpty(stringList[1]))
            {
                var jsonDeserializer = new JsonDeserializer();
                var fakeresponse     = new RestResponse
                {
                    Content = stringList[1]
                };
                deltaEntry.MetaData = jsonDeserializer.Deserialize <MetaData>(fakeresponse);
            }
            return(deltaEntry);
        }
Ejemplo n.º 5
0
        internal static DataPointValue GetDataPointValue(DeltaEntry keyEntry, DataSetType dataSetType)
        {
            ProcessDataPointValue dpv = ProcessValueFactory.CreateValue(keyEntry.DataType);

            if (dpv == null)
            {
                Logger.Error($"Unable to create DataPoint for entry: {keyEntry}");
                return(null);
            }
            dpv.Orcat     = keyEntry.Orcat;
            dpv.Quality   = keyEntry.Quality;
            dpv.Timestamp = keyEntry.TimeStamp;
            dpv.Value     = keyEntry.Value;
            if (keyEntry is KeyEntry key)
            {
                dpv.Prefix  = key.Prefix;
                dpv.Unit    = key.Unit;
                dpv.FieldID = key.FieldID;
            }
            if (dpv is CounterValue)
            {
                dpv.SetAttributeValue(CounterValue.QuantityAttributeName, keyEntry.Value2);
            }
            if (dpv is StepPosValue || dpv is StepPosEvent)
            {
                dpv.SetAttributeValue(StepPosValue.TransientAttributeName, keyEntry.Value2);
            }
            if (dpv is ComplexMeasuredValue)
            {
                dpv.SetAttributeValue(ComplexMeasuredValue.AngleAttributeName, keyEntry.Value2);
            }
            if (dpv.Timestamp == 0)
            {
                dpv.Timestamp = DateTime.Now.ToFileTimeUtc();
            }
            return(dpv);
        }
 public object Deserialize(JsonValue value, JsonMapper mapper)
 {
     DeltaPage deltaPage = new DeltaPage();
     deltaPage.Cursor = value.GetValue<string>("cursor");
     deltaPage.HasMore = value.GetValue<bool>("has_more");
     deltaPage.Reset = value.GetValue<bool>("reset");
     deltaPage.Entries = new List<DeltaEntry>();
     JsonValue entriesValue = value.GetValue("entries");
     if (entriesValue != null)
     {
         foreach (JsonValue entryValue in entriesValue.GetValues())
         {
             DeltaEntry deltaEntry = new DeltaEntry();
             deltaEntry.Path = entryValue.GetValue<string>(0);
             JsonValue metadataValue = entryValue.GetValue(1) as JsonObject;
             if (metadataValue != null)
             {
                 deltaEntry.Metadata = mapper.Deserialize<Entry>(metadataValue);
             }
             deltaPage.Entries.Add(deltaEntry);
         }
     }
     return deltaPage;
 }
Ejemplo n.º 7
0
        public List <DeltaEntry> Read(string Name, bool isGrouped = false)
        {
            List <DeltaEntry> deltaEntries = new List <DeltaEntry>();

            if (CommonConfig == null || Workbook == null)
            {
                return(deltaEntries);
            }
            IXLWorksheet keySheet = Workbook.Worksheets.Worksheet(Name);
            IXLRows      rows     = keySheet.RowsUsed();
            bool         firstRow = true;

            foreach (IXLRow row in rows)
            {
                if (firstRow)
                {
                    firstRow = false;
                    continue;
                }
                DeltaEntry entry = new DeltaEntry();

                // Index
                IXLCell indexCell = row.Cell("A");
                if (string.IsNullOrWhiteSpace(indexCell.GetString()))
                {
                    Logger.Error($"Empty index cell in row {row.RowNumber()}");
                    continue;
                }
                ushort index = ushort.MinValue;
                try
                {
                    index = indexCell.GetValue <ushort>();
                }
                catch (FormatException e)
                {
                    Logger.Error($"Unable to parse index '{indexCell.GetString()}' as ushort in row {row.RowNumber()}", e);
                    continue;
                }
                entry.Index = index;

                //Grouped Delta Entry
                if (isGrouped)
                {
                    entry.DataType = KeyEntries.First()
                                     .DataType;
                }
                else
                {
                    // Map DataType from KeyList
                    if (KeyEntries == null || KeyEntries.Count == 0)
                    {
                        Logger.Error("Cannot parse value of DeltaEntry, because KeyEntries are not available.");
                        continue;
                    }
                    if (KeyEntries.Count < entry.Index)
                    {
                        Logger.Error($"Cannot parse value of DeltaEntry, because index [{entry.Index}] of Delta Entry is not available in KeyEntries List (count is {KeyEntries.Count})."
                                     );
                        continue;
                    }
                    KeyEntry keyEntry = KeyEntries[entry.Index];
                    entry.DataType = keyEntry.DataType;
                }

                // Orcat
                IXLCell orcatCell = row.Cell("B");
                if (ParseOrcat(row, orcatCell, out byte?orcatValue) && orcatValue.HasValue)
                {
                    entry.Orcat = orcatValue.Value;
                }

                // Quality
                IXLCell qualityCell = row.Cell("C");
                if (ParseQuality(row, qualityCell, out ushort?qualityValue) && qualityValue.HasValue)
                {
                    entry.Quality = qualityValue.Value;
                }

                // Timestamp
                IXLCell timeStampCell = row.Cell("D");
                if (ParseTimeStamp(row, timeStampCell, out long?timeStampValue) && timeStampValue.HasValue)
                {
                    entry.TimeStamp = timeStampValue.Value;
                }

                // Value
                IXLCell valueCell  = row.Cell("E");
                IXLCell value2Cell = row.Cell("F");
                IEntry  baseEntry  = entry;
                if (!TryParse(valueCell, value2Cell, ref baseEntry))
                {
                    continue;
                }

                //Name
                if (isGrouped)
                {
                    IXLCell cellName = row.Cell("F");
                    if (!string.IsNullOrWhiteSpace(cellName.GetString()))
                    {
                        try
                        {
                            entry.Name = cellName.GetValue <string>();
                        }
                        catch (FormatException exception)
                        {
                            Logger.Error($"Unable to parse '{qualityCell.GetString()}' in row {row.RowNumber()} as UInt16", exception);
                        }
                    }
                }
                deltaEntries.Add(entry);
            }
            return(deltaEntries);
        }