예제 #1
0
        private void HandleMetaSignalCommand(ClientConnection connection, byte[] buffer, int startIndex, int length)
        {
            MakeConfigurationChanges(() =>
            {
                try
                {
                    if (startIndex + sizeof(int) > Math.Min(length, buffer.Length))
                    {
                        throw new InvalidOperationException("No message payload.");
                    }

                    int index             = startIndex;
                    int payloadByteLength = BigEndian.ToInt32(buffer, index);
                    index += sizeof(int);

                    if (payloadByteLength < 0 || index + payloadByteLength > Math.Min(length, buffer.Length))
                    {
                        throw new InvalidOperationException($"Payload byte length out of bounds ({payloadByteLength}).");
                    }

                    string parameterString = connection.Encoding.GetString(buffer, index, payloadByteLength);
                    MetaSignal metaSignal  = new MetaSignal();
                    new ConnectionStringParser <SettingAttribute>().ParseConnectionString(parameterString, metaSignal);

                    string deviceAcronym = Regex.Replace($"{metaSignal.AnalyticProjectName}!{metaSignal.AnalyticInstanceName}".ToUpper(), @"[^A-Z0-9\-!_\.@#\$]", "");
                    string deviceName    = $"{metaSignal.AnalyticProjectName} {metaSignal.AnalyticInstanceName}";
                    using (AdoDataConnection dbConnection = new AdoDataConnection("systemSettings"))
                    {
                        if (dbConnection.ExecuteScalar <int>("SELECT COUNT(*) FROM Device WHERE UniqueID = {0}", metaSignal.DeviceID) > 0)
                        {
                            dbConnection.ExecuteNonQuery("UPDATE Device SET Acronym = {0} WHERE UniqueID = {1}", deviceAcronym, metaSignal.DeviceID);
                        }
                        else
                        {
                            dbConnection.ExecuteNonQuery("INSERT INTO Device(Acronym, Name, UniqueID, ProtocolID) VALUES({0}, {1}, {2}, (SELECT ID FROM Protocol WHERE Acronym = 'VirtualInput'))", deviceAcronym, deviceName, metaSignal.DeviceID);
                        }

                        int deviceID     = dbConnection.ExecuteScalar <int>("SELECT ID FROM Device WHERE UniqueID = {0}", metaSignal.DeviceID);
                        int signalTypeID = dbConnection.ExecuteScalar <int>("SELECT ID FROM SignalType WHERE Acronym = {0}", metaSignal.SignalType);

                        if (dbConnection.ExecuteScalar <int>("SELECT COUNT(*) FROM Measurement WHERE SignalID = {0}", metaSignal.SignalID) > 0)
                        {
                            dbConnection.ExecuteNonQuery("UPDATE Measurement SET DeviceID = {0}, PointTag = {1}, SignalTypeID = {2}, Description = {3}", metaSignal.DeviceID, metaSignal.PointTag, signalTypeID, metaSignal.Description);
                        }
                        else
                        {
                            dbConnection.ExecuteNonQuery("INSERT INTO Measurement(DeviceID, SignalID, PointTag, SignalTypeID, Description) VALUES({0}, {1}, {2}, {3}, {4})", deviceID, metaSignal.SignalID, metaSignal.PointTag, signalTypeID, metaSignal.Description);
                        }
                    }
                }
                catch (Exception ex)
                {
                    string errorMessage = $"Meta-signal command failed due to exception: {ex.Message}";
                    OnProcessException(new Exception(errorMessage, ex));
                    SendClientResponse(connection.ClientID, ServerResponse.Failed, (ServerCommand)ECAServerCommand.StatusMessage, errorMessage);
                }
            });
        }
예제 #2
0
        public void CreateMeasurement(OutputMeasurement measurement)
        {
            MetaSignal metaSignal = new MetaSignal()
            {
                AnalyticProjectName  = measurement.DevicePrefix,
                AnalyticInstanceName = measurement.DeviceSuffix,
                SignalType           = measurement.SignalType,
                PointTag             = measurement.PointTag,
                Description          = measurement.Description
            };

            string message = new ConnectionStringParser <SettingAttribute>().ComposeConnectionString(metaSignal);

            Subscriber.SendServerCommand((ServerCommand)ECAServerCommand.MetaSignal, message);
        }
예제 #3
0
 public void MetaSignalCommand(MetaSignal signal)
 {
     HubClient.MetaSignalCommand(signal);
 }
예제 #4
0
        public void MetaSignalCommand(MetaSignal signal)
        {
            string connString = new ConnectionStringParser <SettingAttribute>().ComposeConnectionString(signal);

            DataSubscription.SendServerCommand((ServerCommand)ECAServerCommand.MetaSignal, connString);
        }
예제 #5
0
        public void SendMetadata(MetaSignal metaSignal)
        {
            string message = new ConnectionStringParser <SettingAttribute>().ComposeConnectionString(metaSignal);

            m_dataSubscriber.SendServerCommand((ServerCommand)ECAServerCommand.MetaSignal, message);
        }
예제 #6
0
파일: DataHub.cs 프로젝트: lulzzz/openECA
 public void MetaSignalCommand(MetaSignal signal)
 {
     m_dataSubscriptionOperations.MetaSignalCommand(signal);
 }