Example #1
0
        private void InitDetailsFromMeta(MetaFrame metaMessage)
        {
            if (m_VisualizerForm.InvokeRequired)
            {
                m_VisualizerForm.Invoke(new Action <MetaFrame>(InitDetailsFromMeta), metaMessage);
            }
            else
            {
                try
                {
                    string publisherID = metaMessage.NetworkMessageHeader.PublisherID.Value;
                    ushort writerID    = metaMessage.DataSetWriterID;
                    ConcurrentDictionary <ushort, BindingSource> writerDictionary =
                        m_Bindings.GetOrAdd(publisherID, pubID => new ConcurrentDictionary <ushort, BindingSource>());
                    BindingSource bs = writerDictionary.GetOrAdd(writerID, s => new BindingSource());
                    bs.Clear();
                    m_VisualizerForm.ResetGroupedTypeIndex(publisherID, writerID);

                    if (metaMessage.FieldMetaDataList != null)
                    {
                        for (int i = 0; i < metaMessage.FieldMetaDataList.Count; i++)
                        {
                            FieldMetaData fieldMetaData     = metaMessage.FieldMetaDataList[i];
                            bool          isOldEnum         = false,
                                          isGroupedDataType = false;
                            if (metaMessage.StructureDataTypes.TryGetValue(fieldMetaData.DataType, out StructureDescription structDesc))
                            {
                                if (metaMessage.EnumDataTypes != null &&
                                    structDesc.Name.Name.ToString()
                                    .Contains("EnumValue"))
                                {
                                    isOldEnum = true;
                                }
                            }
                            if (!isOldEnum)
                            {
                                isGroupedDataType = ProcessValueFactory.GetNodeIDType(fieldMetaData.DataType) == NodeIDType.GroupDataTypeTimeSeries;
                            }
                            DataPointBase dp = null;
                            if (fieldMetaData.DataType == File.PreDefinedNodeID)
                            {
                                dp = new FileDataPoint();
                            }
                            else
                            {
                                dp = new ProcessDataPoint();
                            }
                            dp.Index = fieldMetaData.Index;
                            dp.Name  = dp.GetType()
                                       .Name
                                       == "FileDataPoint"
                                              ? Path.GetFileName(fieldMetaData.Name.Value)
                                              : fieldMetaData.Name.Value;
                            bs.Add(dp);
                            if (isGroupedDataType)
                            {
                                m_VisualizerForm.AddGroupDataTypeIndex(publisherID, writerID, bs.Count - 1);
                                List <StructureField> fields = metaMessage.StructureDataTypes[fieldMetaData.DataType]
                                                               .Fields;
                                int count = fields.Count;
                                for (int k = 0; k < count; k++)
                                {
                                    string name = fields[k]
                                                  .Name.Value;
                                    if (name != "_time" && name.Contains("_qc") == false)
                                    {
                                        ProcessDataPoint dp1 = new ProcessDataPoint();
                                        dp1.Index = fieldMetaData.Index;
                                        dp1.Name  = fields[k]
                                                    .Name.Value;
                                        bs.Add(dp1);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    if (Debugger.IsAttached)
                    {
                        Debugger.Break();
                    }
                    else
                    {
                        throw;
                    }
                }
            }
        }
Example #2
0
        internal bool TryParse(IXLCell cell, IXLCell cell2, ref IEntry entry)
        {
            string stringValue  = cell.GetString();
            string stringValue2 = cell2.GetString();

            if (string.IsNullOrWhiteSpace(stringValue))
            {
                return(false);
            }
            if (entry.DataType == SPSValue.PreDefinedNodeID || entry.DataType == SPSEvent.PreDefinedNodeID)
            {
                bool value;
                try
                {
                    value = cell.GetValue <bool>();
                }
                catch (FormatException exception)
                {
                    Logger.Error($"Unable to parse '{stringValue}' in row {cell.WorksheetRow().RowNumber()} as bool.", exception);
                    return(false);
                }
                entry.Value = value;
                return(true);
            }
            if (entry.DataType == DPSValue.PreDefinedNodeID || entry.DataType == DPSEvent.PreDefinedNodeID)
            {
                byte value;
                try
                {
                    value = cell.GetValue <byte>();
                }
                catch (FormatException exception)
                {
                    Logger.Error($"Unable to parse '{stringValue}' in row {cell.WorksheetRow().RowNumber()} as byte.", exception);
                    return(false);
                }
                entry.Value = value;
                return(true);
            }
            if (entry.DataType == MeasuredValue.PreDefinedNodeID || entry.DataType == MeasuredValueEvent.PreDefinedNodeID)
            {
                float value;
                try
                {
                    value = cell.GetValue <float>();
                }
                catch (FormatException exception)
                {
                    Logger.Error($"Unable to parse '{stringValue}' in row {cell.WorksheetRow().RowNumber()} as float.", exception);
                    return(false);
                }
                entry.Value = value;
                return(true);
            }
            if (entry.DataType == StepPosValue.PreDefinedNodeID || entry.DataType == StepPosEvent.PreDefinedNodeID)
            {
                int  value;
                bool value2;
                try
                {
                    value  = cell.GetValue <int>();
                    value2 = cell2.GetValue <bool>();
                }
                catch (FormatException exception)
                {
                    Logger.Error($"Unable to parse '{stringValue}' and '{stringValue2}' in row {cell.WorksheetRow().RowNumber()} as float and bool.", exception);
                    return(false);
                }
                entry.Value  = value;
                entry.Value2 = value2;
                return(true);
            }
            if (entry.DataType == CounterValue.PreDefinedNodeID)
            {
                long  value;
                float value2;
                try
                {
                    value  = cell.GetValue <int>();
                    value2 = cell2.GetValue <float>();
                }
                catch (FormatException exception)
                {
                    Logger.Error($"Unable to parse '{stringValue}' and '{stringValue2}' in row {cell.WorksheetRow().RowNumber()} as int and float.", exception);
                    return(false);
                }
                entry.Value  = value;
                entry.Value2 = value2;
                return(true);
            }
            if (entry.DataType == ComplexMeasuredValue.PreDefinedNodeID)
            {
                float value;
                float value2;
                try
                {
                    value  = cell.GetValue <float>();
                    value2 = cell2.GetValue <float>();
                }
                catch (FormatException exception)
                {
                    Logger.Error($"Unable to parse '{stringValue}' and '{stringValue2}' in row {cell.WorksheetRow().RowNumber()} as float and float.", exception);
                    return(false);
                }
                entry.Value  = value;
                entry.Value2 = value2;
                return(true);
            }
            if (entry.DataType == StringEvent.PreDefinedNodeID)
            {
                string value;
                try
                {
                    value = cell.GetValue <string>();
                }
                catch (FormatException exception)
                {
                    Logger.Error($"Unable to parse '{stringValue}' in row {cell.WorksheetRow().RowNumber()} as string.", exception);
                    return(false);
                }
                entry.Value = value;
                return(true);
            }
            if (ProcessValueFactory.GetNodeIDType(entry.DataType) == NodeIDType.GroupDataTypeTimeSeries)
            {
                float value;
                try
                {
                    value = cell.GetValue <float>();
                }
                catch (FormatException exception)
                {
                    Logger.Error($"Unable to parse '{stringValue}' in row {cell.WorksheetRow().RowNumber()} as string.", exception);
                    return(false);
                }
                entry.Value = value;
                return(true);
            }

            // For everything else we assume it's an Integer or an Enum
            int enumValue;

            try
            {
                enumValue = cell.GetValue <int>();
            }
            catch (FormatException exception)
            {
                Logger.Error($"Unable to parse '{stringValue}' in row {cell.WorksheetRow().RowNumber()} as int.", exception);
                return(false);
            }
            entry.Value = enumValue;
            return(true);
        }