Ejemplo n.º 1
0
 public void TestDataReadWrite(DatasetConfig testDataset)
 {
     DatabaseInterfaces[testDataset].Write(ReadData.ReadDataFromDataSources(testDataset, testDataset.DatasetConfigRows, ConnectionList, false));
 }
Ejemplo n.º 2
0
        private void OpenStoragesAndCreateTriggers(bool CreateTriggers, bool StartedAsService)
        {
            foreach (DatasetConfig datasetConfig in akConfig.Datasets)
            {
                try
                {
                    IDBInterface akDBInterface = null;

                    akDBInterface = StorageHelper.GetStorage(datasetConfig, RemotingServer.ClientComms.CallNotifyEvent);
                    akDBInterface.ThreadExceptionOccured += new ThreadExceptionEventHandler(tmpTrigger_ThreadExceptionOccured);

                    DatabaseInterfaces.Add(datasetConfig, akDBInterface);

                    Logging.LogText("DB Interface: " + datasetConfig.Name + " is starting...", Logging.LogLevel.Information);

                    akDBInterface.Initiate(datasetConfig);

                    if (CreateTriggers)
                    {
                        if (datasetConfig.Trigger == DatasetTriggerType.Tags_Handshake_Trigger)
                        {
                            PLCTagTriggerThread tmpTrigger = new PLCTagTriggerThread(akDBInterface, datasetConfig, ConnectionList, StartedAsService);
                            tmpTrigger.StartTrigger();
                            tmpTrigger.ThreadExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            myDisposables.Add(tmpTrigger);
                        }
                        else if (datasetConfig.Trigger == DatasetTriggerType.Time_Trigger)
                        {
                            TimeTriggerThread tmpTrigger = new TimeTriggerThread(akDBInterface, datasetConfig, ConnectionList, StartedAsService);
                            tmpTrigger.StartTrigger();
                            tmpTrigger.ThreadExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            myDisposables.Add(tmpTrigger);
                        }
                        else if (datasetConfig.Trigger == DatasetTriggerType.Time_Trigger_With_Value_Comparison)
                        {
                            TimeTriggerWithCheckForChangesThread tmpTrigger = new TimeTriggerWithCheckForChangesThread(akDBInterface, datasetConfig, ConnectionList, StartedAsService);
                            tmpTrigger.StartTrigger();
                            tmpTrigger.ThreadExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            myDisposables.Add(tmpTrigger);
                        }
                        else if (datasetConfig.Trigger == DatasetTriggerType.Quartz_Trigger)
                        {
                            QuartzTriggerThread tmpTrigger = new QuartzTriggerThread(akDBInterface, datasetConfig, ConnectionList, StartedAsService);
                            tmpTrigger.StartTrigger();
                            tmpTrigger.ThreadExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            myDisposables.Add(tmpTrigger);
                        }
                        else if (datasetConfig.Trigger == DatasetTriggerType.Triggered_By_Incoming_Data_On_A_TCPIP_Connection)
                        {
                            TCPIPConfig tcpipConnConf = datasetConfig.TriggerConnection as TCPIPConfig;

                            tcpipConnConf.MultiTelegramme = tcpipConnConf.MultiTelegramme <= 0 ? 1 : tcpipConnConf.MultiTelegramme;

                            if (tcpipConnConf.MultiTelegramme == 0)
                            {
                                tcpipConnConf.MultiTelegramme = 1;
                            }
                            TCPFunctionsAsync tmpConn = new TCPFunctionsAsync(null, tcpipConnConf.IPasIPAddress, tcpipConnConf.Port, !tcpipConnConf.PassiveConnection, tcpipConnConf.DontUseFixedTCPLength ? -1 : ReadData.GetCountOfBytesToRead(datasetConfig.DatasetConfigRows) * tcpipConnConf.MultiTelegramme);
                            tmpConn.AllowMultipleClients          = tcpipConnConf.AcceptMultipleConnections;
                            tmpConn.UseKeepAlive                  = tcpipConnConf.UseTcpKeepAlive;
                            tmpConn.AsynchronousExceptionOccured += tmpTrigger_ThreadExceptionOccured;
                            tmpConn.AutoReConnect                 = true;
                            var conf = datasetConfig;
                            tmpConn.DataRecieved += (bytes, tcpClient) =>
                            {
                                if (tcpipConnConf.MultiTelegramme == 0)
                                {
                                    tcpipConnConf.MultiTelegramme = 1;
                                }
                                for (int j = 1; j <= tcpipConnConf.MultiTelegramme; j++)
                                {
                                    var    ln     = bytes.Length / tcpipConnConf.MultiTelegramme;
                                    byte[] tmpArr = new byte[ln];
                                    Array.Copy(bytes, ((j - 1) * ln), tmpArr, 0, ln);

                                    IEnumerable <object> values = ReadData.ReadDataFromByteBuffer(conf, conf.DatasetConfigRows, tmpArr, StartedAsService);
                                    if (values != null)
                                    {
                                        akDBInterface.Write(values);
                                    }
                                }
                            };
                            tmpConn.ConnectionEstablished += (TcpClient tcp) =>
                            {
                                Logging.LogText("Connection established: " + tcpipConnConf.IPasIPAddress + ", " + tcpipConnConf.Port, Logging.LogLevel.Information);
                            };
                            tmpConn.ConnectionClosed += (TcpClient tcp) =>
                            {
                                Logging.LogText("Connection closed: " + tcpipConnConf.IPasIPAddress + ", " + tcpipConnConf.Port, Logging.LogLevel.Information);
                            };
                            Logging.LogText("Connection prepared: " + tcpipConnConf.IPasIPAddress + ", " + tcpipConnConf.Port, Logging.LogLevel.Information);
                            tmpConn.Start();
                            ConnectionList.Add(tcpipConnConf, tmpConn);
                            myDisposables.Add(tmpConn);
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logging.LogText("Error in OpenStorragesAndCreateTriggers occured!", ex, Logging.LogLevel.Error);
                }
            }
        }
Ejemplo n.º 3
0
 public void TestDataRead(DatasetConfig testDataset)
 {
     ReadData.ReadDataFromDataSources(testDataset, testDataset.DatasetConfigRows, ConnectionList, false);
 }