Пример #1
0
 private void TriggerCallback()
 {
     try
     {
         IEnumerable <object> values = ReadData.ReadDataFromDataSources(datasetConfig, datasetConfig.DatasetConfigRows, activConnections, StartedAsService);
         if (values != null)
         {
             dbInterface.Write(values);
         }
     }
     catch (ThreadAbortException ex)
     {
         //ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
     }
     catch (Exception ex)
     {
         if (StartedAsService)
         {
             ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
         }
         else
         {
             throw;
         }
     }
 }
Пример #2
0
        private void WaitForTrigger()
        {
            try
            {
                while (true)
                {
                    IEnumerable <object> values = ReadData.ReadDataFromDataSources(datasetConfig, datasetConfig.DatasetConfigRows, activConnections, StartedAsService);
                    if (values != null)
                    {
                        dbInterface.Write(values);
                    }

                    Thread.Sleep(TriggerTimeSpan);
                }
            }
            catch (ThreadAbortException ex)
            {
            }
            catch (Exception ex)
            {
                if (StartedAsService)
                {
                    ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
                }
                else
                {
                    throw;
                }
            }
        }
Пример #3
0
        private void ThreadProc()
        {
            try
            {
                while (true)
                {
                    if (_initiated)
                    {
                        bool ok = false;
                        if (_intValueList.Count > 0)
                        {
                            lock (_intValueList) _maxAdd = _intValueList.Count;

                            try
                            {
                                ok = _internal_Write();
                            }
                            catch (ThreadAbortException)
                            {
                                throw;
                            }
                            catch (Exception ex)
                            {
                                if (ThreadExceptionOccured != null)
                                {
                                    ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
                                }
                                else
                                {
                                    Logging.LogText("Exception: ", ex, Logging.LogLevel.Error);
                                }
                            }

                            if (ok)
                            {
                                lock (_intValueList)
                                {
                                    _intValueList.RemoveRange(0, _maxAdd);
                                    _intDateTimesList.RemoveRange(0, _maxAdd);
                                }
                            }
                        }
                        else
                        {
                            Thread.Sleep(20);
                        }
                    }
                    else
                    {
                        this.Initiate();
                    }
                }
            }
            catch (ThreadAbortException)
            {
                return;
            }
        }
Пример #4
0
 void tmpTrigger_ThreadExceptionOccured(object sender, ThreadExceptionEventArgs e)
 {
     if (ThreadExceptionOccured != null)
     {
         context.Send(delegate
         {
             ThreadExceptionOccured.Invoke(sender, e);
         }, null);
         Dispose();
     }
     else
     {
         Logging.LogText("Exception occured! ", e.Exception, Logging.LogLevel.Error);
         //Dispose(); //Möglicherweise ein Restart hier rein??
     }
 }
Пример #5
0
        private void WaitForTrigger()
        {
            try
            {
                bool alreadyWritten = false;
                while (true)
                {
                    if (triggerConn.Connected)
                    {
                        try
                        {
                            //Read the Trigger Bit
                            triggerConn.ReadValue(readBit);
                        }
                        catch (Exception ex)
                        {
                            if (StartedAsService)
                            {
                                Logging.LogText("Error: Exception during ReadData, maybe Connection interupted?", ex, Logging.LogLevel.Error);
                                try
                                {
                                    triggerConn.Disconnect();
                                    triggerConn.Connect();
                                }
                                catch (Exception exex)
                                {
                                    Logging.LogText("Error: Exception during Connect...", exex, Logging.LogLevel.Error);
                                }
                            }
                            else
                            {
                                throw;
                            }
                        }
                        //If the cycle counter is 0, switch to the slower interval (it means that no new data was there for a long time! ;-)
                        if (cycle_counter > 0)
                        {
                            //Logging.LogTextToLog4Net("WaitForTrigger() => \"" + datasetConfig.TriggerConnection.Name + "\" - NoDataInterval active");
                            cycle_counter--;

                            if (cycle_counter == 0)
                            {
                                ak_interval = NoDataInterval;
                            }

                            if ((!((bool)readBit.Value) && !alreadyWritten) && datasetConfig.TriggerConnection is LibNoDaveConfig && !((LibNoDaveConfig)datasetConfig.TriggerConnection).StayConnected)
                            {
                                ak_interval = NoDataInterval;
                                Logging.LogTextToLog4Net("WaitForTrigger() => \"" + datasetConfig.TriggerConnection.Name + "\" Discconnect because !StayConnected");
                                triggerConn.Disconnect();
                            }
                        }

                        if (((bool)readBit.Value & !alreadyWritten) || ((bool)readBit.Value) && onlyUseOneTag)
                        {
                            //Logging.LogTextToLog4Net("WaitForTrigger() => \"" + datasetConfig.TriggerConnection.Name + "\" - NewDataInterval active");
                            alreadyWritten = true;
                            cycle_counter  = NoDataCycles;
                            ak_interval    = NewDataInterval;

                            IEnumerable <object> values = ReadData.ReadDataFromDataSources(datasetConfig, datasetConfig.DatasetConfigRows, activConnections, StartedAsService);
                            if (values != null)
                            {
                                dbInterface.Write(values);

                                if (!onlyUseOneTag)
                                {
                                    quittBit.Value = true;
                                    try
                                    {
                                        triggerConn.WriteValue(quittBit);
                                    }
                                    catch (Exception ex)
                                    {
                                        if (StartedAsService)
                                        {
                                            Logging.LogText(
                                                "Error: Exception during WriteValue, maybe Connection interupted?", ex,
                                                Logging.LogLevel.Error);
                                            try
                                            {
                                                triggerConn.Disconnect();
                                                triggerConn.Connect();
                                            }
                                            catch (Exception exex)
                                            {
                                                Logging.LogText("Error: Exception during Connect...", exex, Logging.LogLevel.Error);
                                            }
                                        }
                                        else
                                        {
                                            throw;
                                        }
                                    }
                                }
                                else
                                {
                                    readBit.Value = false;
                                    triggerConn.WriteValue(readBit);
                                }
                            }
                        }
                        else if (!(bool)readBit.Value && !onlyUseOneTag)
                        {
                            if (alreadyWritten)
                            {
                                alreadyWritten = false;
                                quittBit.Value = false;
                                try
                                {
                                    triggerConn.WriteValue(quittBit);
                                }
                                catch (Exception ex)
                                {
                                    if (StartedAsService)
                                    {
                                        Logging.LogText("Error: Exception during WriteValue, maybe Connection interupted?", ex, Logging.LogLevel.Error);
                                    }
                                    else
                                    {
                                        throw;
                                    }
                                }
                            }
                        }

                        //Logging.LogTextToLog4Net("Sleep() => \"" + datasetConfig.TriggerConnection.Name + "\" Interval:" + ak_interval);
                        Thread.Sleep(ak_interval);
                    }
                    else
                    {
                        Logging.LogTextToLog4Net("WaitForTrigger() => \"" + datasetConfig.TriggerConnection.Name + "\" => Connect...");
                        cycle_counter = NoDataCycles;
                        triggerConn.Connect();
                    }
                }
            }
            catch (ThreadAbortException ex)
            {
                //ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
            }
            catch (Exception ex)
            {
                ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
            }
        }
        private void WaitForTrigger()
        {
            try
            {
                bool alreadyWritten = false;
                while (true)
                {
                    if (triggerConn.Connected)
                    {
                        try
                        {
                            //Read the Trigger Bit
                            triggerConn.ReadValue(readBit);
                        }
                        catch (Exception ex)
                        {
                            if (StartedAsService)
                            {
                                Logging.LogText("Error: Exception during ReadData, maybe Connection interupted?", ex, Logging.LogLevel.Error);
                            }
                            else
                            {
                                throw;
                            }
                        }
                        //If the cycle counter is 0, switch to the slower interval (it means that no new data was there for a long time! ;-)
                        if (cycle_counter > 0)
                        {
                            cycle_counter--;
                            ak_interval = NoDataInterval;
                        }

                        if ((bool)readBit.Value & !alreadyWritten)
                        {
                            alreadyWritten = true;
                            cycle_counter  = NoDataCycles;
                            ak_interval    = NewDataInterval;

                            IEnumerable <object> values = ReadData.ReadDataFromDataSources(datasetConfig, datasetConfig.DatasetConfigRows, activConnections, StartedAsService);
                            if (values != null)
                            {
                                dbInterface.Write(values);

                                quittBit.Value = true;
                                try
                                {
                                    triggerConn.WriteValue(quittBit);
                                }
                                catch (Exception ex)
                                {
                                    if (StartedAsService)
                                    {
                                        Logging.LogText("Error: Exception during WriteValue, maybe Connection interupted?", ex, Logging.LogLevel.Error);
                                    }
                                    else
                                    {
                                        throw;
                                    }
                                }
                            }
                        }
                        else if (!(bool)readBit.Value)
                        {
                            if (alreadyWritten)
                            {
                                alreadyWritten = false;
                                quittBit.Value = false;
                                try
                                {
                                    triggerConn.WriteValue(quittBit);
                                }
                                catch (Exception ex)
                                {
                                    if (StartedAsService)
                                    {
                                        Logging.LogText("Error: Exception during WriteValue, maybe Connection interupted?", ex, Logging.LogLevel.Error);
                                    }
                                    else
                                    {
                                        throw;
                                    }
                                }
                            }
                        }
                    }

                    Thread.Sleep(ak_interval);
                }
            }
            catch (ThreadAbortException ex)
            {
                //ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
            }
            catch (Exception ex)
            {
                ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
            }
        }
        private void WaitForTrigger()
        {
            try
            {
                while (true)
                {
                    IEnumerable <object> values = ReadData.ReadDataFromDataSources(datasetConfig, datasetConfig.DatasetConfigRows, activConnections, StartedAsService);


                    if (values != null)
                    {
                        bool write = false;
                        if (oldValues != null && oldValues.Count > 0)
                        {
                            int i = 0;
                            foreach (object val in values)
                            {
                                if (val is IStructuralEquatable)
                                {
                                    if (!((IStructuralEquatable)val).Equals(oldValues[i], StructuralComparisons.StructuralEqualityComparer))
                                    {
                                        write = true;
                                    }
                                }
                                else if (!val.Equals(oldValues[i]))
                                {
                                    write = true;
                                }
                                i++;
                            }
                        }
                        else
                        {
                            write = true;
                        }

                        if (write)
                        {
                            dbInterface.Write(values);
                        }

                        oldValues.Clear();
                        oldValues.AddRange(values);
                    }

                    Thread.Sleep(TriggerTimeSpan);
                }
            }
            catch (ThreadAbortException ex)
            {
            }
            catch (Exception ex)
            {
                if (StartedAsService)
                {
                    ThreadExceptionOccured.Invoke(this, new ThreadExceptionEventArgs(ex));
                }
                else
                {
                    throw;
                }
            }
        }