public void AddRow(CtpObject[] values)
 {
     CtpObject[] item = new CtpObject[values.Length];
     for (int x = 0; x < values.Length; x++)
     {
         item[x] = values[x];
     }
     Rows.Add(item);
 }
Пример #2
0
        private SttpDataPointMetadata Lookup(CtpObject dataPointID)
        {
            if (m_metadataLookup.TryGetValue(dataPointID, out var value))
            {
                return(value);
            }
            var dp = new SttpDataPointMetadata(null);

            dp.DataPointID = dataPointID;
            return(dp);
        }
        public void ProcessCommand(CommandGetMetadata command, CtpNetStream encoder)
        {
            var repository = m_repository;

            if (repository.ContainsTable(command.Table))
            {
                var table         = repository[command.Table];
                var columns       = new List <MetadataColumn>();
                var columnIndexes = new List <int>();
                if (command.Columns == null || command.Columns.Count == 0)
                {
                    columns.AddRange(table.Columns);
                    for (int x = 0; x < columns.Count; x++)
                    {
                        columnIndexes.Add(x);
                    }
                }
                else
                {
                    foreach (var column in command.Columns)
                    {
                        var c = table.Columns.FindIndex(x => x.Name == column);
                        if (c < 0)
                        {
                            encoder.Send(new CommandMetadataRequestFailed("Syntax Error", "Could not find the specified column " + column));
                            return;
                        }
                        columnIndexes.Add(c);
                        columns.Add(table.Columns[c]);
                    }
                }

                byte channelID = 1;
                int  rowCount  = 0;

                var         rowEncoder = new MetadataRowEncoder(columns);
                CtpObject[] values     = new CtpObject[columns.Count];
                encoder.Send(new CommandBeginMetadataResponse(channelID, Guid.Empty, repository.RuntimeID, repository.VersionNumber, command.Table, columns));
                foreach (var row in table.Rows)
                {
                    for (int x = 0; x < values.Length; x++)
                    {
                        values[x] = row.Fields[columnIndexes[x]];
                    }
                    rowEncoder.AddRow(values);
                    if (rowEncoder.Size > 30000)
                    {
                        throw new NotImplementedException();
                        //encoder.SendRaw(rowEncoder.ToArray(), channelID);
                        rowEncoder.Clear();
                    }

                    rowCount++;
                }
                if (rowEncoder.Size > 0)
                {
                    throw new NotImplementedException();
                    //encoder.SendRaw(rowEncoder.ToArray(), channelID);
                    rowEncoder.Clear();
                }
                encoder.Send(new CommandEndMetadataResponse(channelID, rowCount));
            }
            else
            {
                encoder.Send(new CommandMetadataRequestFailed("Syntax Error", "Could not find the specified table " + command.Table));
            }
        }
 public SttpDataPointID(CtpObject id)
 {
     ID         = id;
     m_hashCode = ID.GetHashCode();
 }
Пример #5
0
 public AttributeValues(string name, CtpObject value)
 {
     Name  = name;
     Value = value;
 }
Пример #6
0
        public override bool Read(SttpDataPoint dataPoint)
        {
TryAgain:
            if (m_stream.IsEmpty)
            {
                return(false);
            }

            m_lastChannelID++;
            CtpObject value = m_stream.Read();

            if (value.ValueTypeCode == CtpTypeCode.Integer)
            {
                long code = value.IsInteger;
                if (0 <= code && code <= 15)
                {
                    bool channelIDChanged = (code & 1) != 0;
                    bool hasMetadata      = (code & 2) != 0;
                    bool qualityChanged   = (code & 4) != 0;
                    bool timeChanged      = (code & 8) != 0;

                    if (channelIDChanged)
                    {
                        m_lastChannelID = m_stream.Read().AsInt32;
                    }

                    if (hasMetadata)
                    {
                        Assign(new SttpDataPointID(m_stream.Read()), m_lastChannelID);
                    }

                    if (qualityChanged)
                    {
                        m_lastQuality = m_stream.Read().AsInt64;
                    }

                    if (timeChanged)
                    {
                        m_lastTimestamp = m_stream.Read().AsCtpTime;
                    }

                    value = m_stream.Read();
                }
                else
                {
                    value = code - 16;
                }
            }

            dataPoint.DataPoint = GetMetadata(m_lastChannelID);
            dataPoint.Quality   = m_lastQuality;
            dataPoint.Time      = m_lastTimestamp;
            dataPoint.Value     = value;

            if (dataPoint.DataPoint == null)
            {
                goto TryAgain;
            }

            return(true);
        }
Пример #7
0
        /// <summary>
        /// This method will extract all literals and assign them a new variable name.
        /// </summary>
        private string ExtractLiterals(string expression)
        {
            int param = 1;

            StringBuilder sb        = new StringBuilder();
            StringBuilder sbLiteral = new StringBuilder();

            bool isLiteral = false;

            for (var x = 0; x < expression.Length; x++)
            {
                char c    = expression[x];
                char peek = ' ';
                if (x + 1 < expression.Length)
                {
                    peek = expression[x + 1];
                }

                if (c == '#')
                {
                    isLiteral = !isLiteral;
                    if (!isLiteral)
                    {
                        //Only on closing, if the next char is a # is this an escape character.
                        if (peek == '#')
                        {
                            sbLiteral.Append('#');
                        }
                        else
                        {
                            CtpObject value = ParseLiteral(ToTrimString(sbLiteral));
                            while (Literals.ContainsKey($"{{{param}}}"))
                            {
                                param++;
                            }
                            Literals.Add($"{{{param}}}", value);
                            sbLiteral.Clear();
                            sb.Append($"{{{param}}}");
                        }
                    }
                }
                else if (isLiteral)
                {
                    sbLiteral.Append(c);
                }
                else
                {
                    switch (c)
                    {
                    default:
                        sb.Append(c);
                        break;
                    }
                }
            }
            if (isLiteral)
            {
                throw new Exception("Literal Mismatch");
            }
            if (sb.Length == 0)
            {
                return(string.Empty);
            }
            return(sb.ToString());
        }