Пример #1
0
        /// <summary>
        /// Write the DataValue 'dv' to the CSV file.
        /// </summary>
        protected virtual void WriteDataValueToCsvFile(DataValue dv)
        {
            TMValue tmvalue =
                new TMValue(
                    OpcNodeId.ToString(),
                    dv.ServerTimestamp,
                    dv.WrappedValue.ToString(),
                    dv.StatusCode.ToString()
                    );

            tmvalue.WriteToCsvFile();
        }
            public Repository(SQLiteConnection connection, OpcNodeId nodeId)
                : base()
            {
                this.connection = connection;
                this.syncRoot   = new object();

                var nodeIdValue = nodeId.ToString();

                //this.Create(value)
                {
                    this.createCommand = this.connection.CreateCommand();

                    var commandText
                        = "insert into HistoryData ("
                          + "            NodeId, "
                          + "            Timestamp, "
                          + "            TimestampValue, "
                          + "            Value, ";

                    if (!IsModifiedHistory)
                    {
                        commandText
                            += "        StatusCode)";
                    }
                    else
                    {
                        commandText
                            += "        StatusCode, "
                               + "         ModificationTime, "
                               + "         ModificationTimeValue, "
                               + "         ModificationType, "
                               + "         ModificationUserName)";
                    }

                    commandText
                        += "      values ("
                           + "            @nodeId, "
                           + "            @timestamp, "
                           + "            @timestampValue, "
                           + "            @value, ";

                    if (!IsModifiedHistory)
                    {
                        commandText
                            += "        @statusCode)";
                    }
                    else
                    {
                        commandText
                            += "        @statusCode, "
                               + "         @modificationTime, "
                               + "         @modificationTimeValue, "
                               + "         @modificationType, "
                               + "         @modificationUserName)";
                    }

                    this.createCommand.CommandText = commandText;

                    var parameters = this.createCommand.Parameters;
                    parameters.AddWithValue("@nodeId", nodeIdValue);

                    this.createTimestamp      = parameters.Add("@timestamp", DbType.DateTime);
                    this.createTimestampValue = parameters.Add("@timestampValue", DbType.Int64);
                    this.createValue          = parameters.Add("@value", DbType.Object);
                    this.createStatusCode     = parameters.Add("@statusCode", DbType.Int64);

                    if (IsModifiedHistory)
                    {
                        this.createModificationTime      = parameters.Add("@modificationTime", DbType.DateTime);
                        this.createModificationTimeValue = parameters.Add("@modificationTimeValue", DbType.Int64);
                        this.createModificationType      = parameters.Add("@modificationType", DbType.Byte);
                        this.createModificationUserName  = parameters.Add("@modificationUserName", DbType.String);
                    }
                }

                //this.Delete(timestamp)
                {
                    this.deleteCommand = this.connection.CreateCommand();

                    this.deleteCommand.CommandText
                        = "delete from HistoryData "
                          + "      where NodeId = @nodeId "
                          + "        and TimestampValue = @timestampValue";

                    var parameters = this.deleteCommand.Parameters;
                    parameters.AddWithValue("@nodeId", nodeIdValue);

                    this.deleteTimestampValue = parameters.Add("@timestampValue", DbType.Int64);
                }

                //this.Delete(startTime, endTime)
                {
                    this.deleteRangeCommand = this.connection.CreateCommand();

                    this.deleteRangeCommand.CommandText
                        = "delete from HistoryData "
                          + " where NodeId = @nodeId "
                          + "   and TimestampValue >= @startTimeValue "
                          + "   and TimeStampValue <= @endTimeValue";

                    var parameters = this.deleteRangeCommand.Parameters;
                    parameters.AddWithValue("@nodeId", nodeIdValue);

                    this.deleteRangeStartTimeValue = parameters.Add("@startTimeValue", DbType.Int64);
                    this.deleteRangeEndTimeValue   = parameters.Add("@endTimeValue", DbType.Int64);
                }

                //this.Exists(timestamp)
                {
                    this.existsCommand = this.connection.CreateCommand();

                    this.existsCommand.CommandText
                        = "select count(1) "
                          + "  from HistoryData hd "
                          + " where hd.NodeId = @nodeId "
                          + "   and hd.TimestampValue = @timestampValue";

                    var parameters = this.existsCommand.Parameters;
                    parameters.AddWithValue("@nodeId", nodeIdValue);

                    this.existsTimestampValue = parameters.Add("@timestampValue", DbType.Int64);
                }

                //this.Read(timestamp)
                {
                    this.readCommand = this.connection.CreateCommand();

                    var commandText
                        = "select hd.TimestampValue, "
                          + "       hd.Value, ";

                    if (!IsModifiedHistory)
                    {
                        commandText
                            += "      hd.StatusCode ";
                    }
                    else
                    {
                        commandText
                            += "      hd.StatusCode, "
                               + "       hd.ModificationTimeValue, "
                               + "       hd.ModificationType, "
                               + "       hd.ModificationUserName ";
                    }

                    commandText
                        += " from HistoryData hd "
                           + " where hd.NodeId = @nodeId "
                           + "   and hd.TimestampValue = @timestampValue";

                    this.readCommand.CommandText = commandText;

                    var parameters = this.readCommand.Parameters;
                    parameters.AddWithValue("@nodeId", nodeIdValue);

                    this.readTimestampValue = parameters.Add("@timestampValue", DbType.Int64);
                }

                //this.Read(startTime, endTime)
                {
                    this.readRangeCommand = this.connection.CreateCommand();

                    var commandText
                        = "select hd.TimestampValue, "
                          + "       hd.Value, ";

                    if (!IsModifiedHistory)
                    {
                        commandText
                            += "      hd.StatusCode ";
                    }
                    else
                    {
                        commandText
                            += "      hd.StatusCode, "
                               + "       hd.ModificationTimeValue, "
                               + "       hd.ModificationType, "
                               + "       hd.ModificationUserName ";
                    }

                    commandText
                        += " from HistoryData hd "
                           + " where hd.NodeId = @nodeId "
                           + "   and hd.TimestampValue >= @startTimeValue "
                           + "   and hd.TimestampValue <= @endTimeValue";

                    this.readRangeCommand.CommandText = commandText;

                    var parameters = this.readRangeCommand.Parameters;
                    parameters.AddWithValue("@nodeId", nodeIdValue);

                    this.readRangeStartTimeValue = parameters.Add("@startTimeValue", DbType.Int64);
                    this.readRangeEndTimeValue   = parameters.Add("@endTimeValue", DbType.Int64);
                }

                //this.Update(value)
                {
                    this.updateCommand = this.connection.CreateCommand();

                    var commandText
                        = "update HistoryData "
                          + "   set Value = @value, ";

                    if (!IsModifiedHistory)
                    {
                        commandText
                            += "   StatusCode = @statusCode ";
                    }
                    else
                    {
                        commandText
                            += "   StatusCode = @statusCode, "
                               + "    ModificationTime = @modificationTime, "
                               + "    ModificationTimeValue = @modificationTimeValue, "
                               + "    ModificationType = @modificationType, "
                               + "    ModificationUserName = @modificationUserName ";
                    }

                    commandText
                        += "where NodeId = @nodeId "
                           + "   and TimestampValue = @timestampValue";

                    this.updateCommand.CommandText = commandText;

                    var parameters = this.updateCommand.Parameters;
                    parameters.AddWithValue("@nodeId", nodeIdValue);

                    this.updateTimestampValue = parameters.Add("@timestampValue", DbType.Int64);
                    this.updateValue          = parameters.Add("@value", DbType.Object);
                    this.updateStatusCode     = parameters.Add("@statusCode", DbType.Int64);

                    if (IsModifiedHistory)
                    {
                        this.updateModificationTime      = parameters.Add("@modificationTime", DbType.DateTime);
                        this.updateModificationTimeValue = parameters.Add("@modificationTimeValue", DbType.Int64);
                        this.updateModificationType      = parameters.Add("@modificationType", DbType.Byte);
                        this.updateModificationUserName  = parameters.Add("@modificationUserName", DbType.String);
                    }
                }
            }
Пример #3
0
        private int ReadTagChange(OpcNodeId nodeId)
        {
            try
            {
                ServiceConfig.Reader readerConfig = null;
                foreach (var serviceConfig in RfidService.ServiceConfigs)
                {
                    readerConfig =
                        serviceConfig.Readers.FirstOrDefault(reader =>
                                                             reader.Tags.ReaderTag.ReadTag == nodeId.ToString());
                    if (readerConfig != null)
                    {
                        break;
                    }
                }

                if (readerConfig == null)
                {
                    _eventLog.WriteEntry("Unable to find matching config. Check system settings.", EventLogEntryType.Error, (int)EventIds.Ids.NullReaderError);
                    _client.WriteNode(nodeId, false);
                    return(1);
                }

                using (var reader = new RfidReader(readerConfig, ref _eventLog))
                {
                    if (!reader.GetStatus())
                    {
                        _client.WriteNode(readerConfig.Tags.ErrorTag.ErrorBool, true);
                        _client.WriteNode(readerConfig.Tags.ErrorTag.ErrorString, "Reader not online!");
                        _client.WriteNode(nodeId, false);
                        return(1);
                    }

                    var nodeVal = reader.Read_Epc();
                    if (string.IsNullOrEmpty(nodeVal))
                    {
                        _client.WriteNode(readerConfig.Tags.ErrorTag.ErrorBool, true);
                        _client.WriteNode(readerConfig.Tags.ErrorTag.ErrorString, "No Tags Detected!");
                        _client.WriteNode(readerConfig.Tags.UuidTag.UuidTag, string.Empty);
                    }
                    else
                    {
                        _client.WriteNode(readerConfig.Tags.UuidTag.UuidTag, nodeVal);
                    }
                    _client.WriteNode(nodeId, false);
                }
                return(0);
            }
            catch (Exception e)
            {
                _eventLog.WriteEntry($"Unknown Error\n{e.Message}\n{e.StackTrace}\n\n{e.InnerException}", EventLogEntryType.Error, (int)EventIds.Ids.UnknownError);
                return(1);
            }
        }