Exemple #1
0
 internal PublicationUpdateOperationHandler(string publicationName, string variableName)
 {
     this._operationType   = DPE_GlobalDefinitions.publicationUpdateOperationType.dataReset;
     this._data            = null;
     this._variableName    = variableName;
     this._publicationName = publicationName;
 }
            private void EventHandling_DATA_UPDATE_PCQ_NewItemDetected(object item)
            {
                try
                {
                    lock (this._locker)
                    {
                        DPE_PublicationData data = (DPE_PublicationData)item;
                        try
                        {
                            this._UPDATE_StatisticsHandler.LogEvent(data.VariableName);
                        }
                        catch (Exception)
                        {
                        }

                        try
                        {
                            if (dataUpdateFromPublicationEvent != null)
                            {
                                dataUpdateFromPublicationEvent(data);
                            }
                        }
                        catch (Exception)
                        {
                        }
                    }
                }
                catch (Exception ex)
                {
                    CustomEventLog.WriteEntry(ex);
                }
            }
Exemple #3
0
                private bool disposedValue = false;                 // To detect redundant calls


                internal PublicationUpdateOperationHandler(DPE_PublicationData data)
                {
                    this._operationType   = DPE_GlobalDefinitions.publicationUpdateOperationType.dataUpdate;
                    this._data            = data;
                    this._variableName    = data.VariableName;
                    this._publicationName = data.PublicationName;
                }
Exemple #4
0
 private void ValidateDataPublication(DPE_PublicationData data)
 {
     DPE_ServerDefs.PublicationVariableDataType type = default(DPE_ServerDefs.PublicationVariableDataType);
     type = this._variablesPublishedRegistry.GetDataVariablePublicationDataType(data.VariableName);
     if (type != data.DataType)
     {
         throw (new Exception("The data published as \'" + data.VariableName + "\' was declared to be of type \'" + type.ToString() + "\' and was received as \'" + data.DataType.ToString() + "\'"));
     }
 }
Exemple #5
0
 public void UpdatePublicationVariable(DPE_PublicationData data)
 {
     try
     {
         this._DATA_UPDATE_PCQ.Enqueue(data);
     }
     catch (Exception ex)
     {
         CustomEventLog.WriteEntry(ex);
     }
 }
Exemple #6
0
            private SocketData ConvertPublicationDataToSocketDataType(DPE_PublicationData data)
            {
                string     dataType         = data.Value.GetType().ToString();
                SocketData dataAsSocketData = default(SocketData);

                switch (dataType)
                {
                case "System.Int32":
                    dataAsSocketData = new SocketData(data.VariableName, System.Convert.ToInt32(data.Value));
                    break;

                case "System.Decimal":
                    dataAsSocketData = new SocketData(data.VariableName, System.Convert.ToDecimal(data.Value));
                    break;

                case "System.Boolean":
                    dataAsSocketData = new SocketData(data.VariableName, System.Convert.ToBoolean(data.Value));
                    break;

                case "System.String":
                    dataAsSocketData = new SocketData(data.VariableName, System.Convert.ToString(data.Value));
                    break;

                case "System.Data.DataSet":
                    dataAsSocketData = new SocketData(data.VariableName, (DataSet)data.Value);
                    break;

                case "System.Data.DataTable":
                    dataAsSocketData = new SocketData(data.VariableName, (DataTable)data.Value);
                    break;

                case "UtilitiesLibrary.Data.CustomHashTable":
                    dataAsSocketData = new SocketData(data.VariableName, (CustomHashTable)data.Value);
                    break;

                case "UtilitiesLibrary.Data.CustomList":
                    dataAsSocketData = new SocketData(data.VariableName, (CustomList)data.Value);
                    break;

                case "UtilitiesLibrary.Data.CustomSortedList":
                    dataAsSocketData = new SocketData(data.VariableName, (CustomSortedList)data.Value);
                    break;

                default:
                    string msg = "Unsupported data type \'" + dataType + "\' for publication \'" + this.PublicationName + "\'";
                    throw (new Exception(msg));
                }
                //*********************************************************************
                //IMPORTANT !!!!!!!
                //this flag indicates the data is for update a publication variable
                dataAsSocketData.AttributesTable.AddAttribute(DPE_ServerDefs.DPE_PUBLICATION_UPDATE_FLAG, DPE_ServerDefs.DPE_PUBLICATION_DATA_UPDATE);
                dataAsSocketData.AttributesTable.AddAttribute(DPE_ServerDefs.DPE_PUBLICATION_NAME, this._publicationName);
                return(dataAsSocketData);
            }
Exemple #7
0
 private void EventHandling_DATA_UPDATE_PCQ_NewItemDetected(object item)
 {
     try
     {
         DPE_PublicationData data = (DPE_PublicationData)item;
         this.WriteDataUPDATE(data);
     }
     catch (Exception ex)
     {
         CustomEventLog.WriteEntry(ex);
     }
 }
 private void STXDSSPublicationConnectionHandler_PublicationDataReceived(DPE_PublicationData data)
 {
     try
     {
         //to avoid the publsiher client receive updates from its own publications
         if (PublicationDataReceivedEvent != null)
         {
             PublicationDataReceivedEvent(data);
         }
     }
     catch (Exception)
     {
     }
 }
Exemple #9
0
 private void UpdatePublication()
 {
     if (this._variableDefinition.DataType == DPE_ServerDefs.PublicationVariableDataType.DPE_DT_Boolean)
     {
         DPE_PublicationData data = new DPE_PublicationData(this._publicationName, this._variableDefinition.VariableName, System.Convert.ToString(GetBooleanData()));
         this._client.UpdatePublicationData(data);
     }
     else if (this._variableDefinition.DataType == DPE_ServerDefs.PublicationVariableDataType.DPE_DT_CFHashTable)
     {
         DPE_PublicationData data = new DPE_PublicationData(this._publicationName, this._variableDefinition.VariableName, GetCFHashTable());
         this._client.UpdatePublicationData(data);
     }
     else if (this._variableDefinition.DataType == DPE_ServerDefs.PublicationVariableDataType.DPE_DT_CFList)
     {
         DPE_PublicationData data = new DPE_PublicationData(this._publicationName, this._variableDefinition.VariableName, GetCFList());
         this._client.UpdatePublicationData(data);
     }
     else if (this._variableDefinition.DataType == DPE_ServerDefs.PublicationVariableDataType.DPE_DT_CFSortedList)
     {
         DPE_PublicationData data = new DPE_PublicationData(this._publicationName, this._variableDefinition.VariableName, GetCFSortedList());
         this._client.UpdatePublicationData(data);
     }
     else if (this._variableDefinition.DataType == DPE_ServerDefs.PublicationVariableDataType.DPE_DT_DataSet)
     {
         DPE_PublicationData data = new DPE_PublicationData(this._publicationName, this._variableDefinition.VariableName, GetDataSet());
         this._client.UpdatePublicationData(data);
     }
     else if (this._variableDefinition.DataType == DPE_ServerDefs.PublicationVariableDataType.DPE_DT_DataTable)
     {
         DPE_PublicationData data = new DPE_PublicationData(this._publicationName, this._variableDefinition.VariableName, GetDataTable());
         this._client.UpdatePublicationData(data);
     }
     else if (this._variableDefinition.DataType == DPE_ServerDefs.PublicationVariableDataType.DPE_DT_Decimal)
     {
         DPE_PublicationData data = new DPE_PublicationData(this._publicationName, this._variableDefinition.VariableName, GetDecimal());
         this._client.UpdatePublicationData(data);
     }
     else if (this._variableDefinition.DataType == DPE_ServerDefs.PublicationVariableDataType.DPE_DT_String)
     {
         DPE_PublicationData data = new DPE_PublicationData(this._publicationName, this._variableDefinition.VariableName, GetString());
         this._client.UpdatePublicationData(data);
     }
     else if (this._variableDefinition.DataType == DPE_ServerDefs.PublicationVariableDataType.DPE_DT_Integer)
     {
         DPE_PublicationData data = new DPE_PublicationData(this._publicationName, this._variableDefinition.VariableName, GetInteger());
         this._client.UpdatePublicationData(data);
     }
 }
Exemple #10
0
            private void WriteDataUPDATE(DPE_PublicationData data)
            {
                try
                {
                    lock (_locker)
                    {
                        using (var cnn = new System.Data.SqlClient.SqlConnection(this._dataBaseConnectionString))
                        {
                            cnn.Open();

                            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
                            {
                                cmd.Connection = cnn;


                                this._dataType  = DPE_GlobalDefinitions.GetPublicationValueDataTypeAsString(data.Value);
                                this._dataValue = DPE_GlobalDefinitions.GetPublicationValueAsString(data.VariableName, System.Convert.ToInt32(data.Value));

                                string attributesAsString = "";
                                if (data.DataAttributesTable.Count > 0)
                                {
                                    CustomHashTable table = data.DataAttributesTable.ToSTXHashTable();
                                    attributesAsString = UtilitiesLibrary.Data.XMLDataFormatting.GetValueAsString(data.VariableName, table);
                                }

                                cmd.CommandText = "INSERT into " + this._publicationName + "(dataname,dataType, value, attributesTable , isDataReset)" +
                                                  "VALUES(\'" + data.VariableName + "\',\'" + this._dataType + "\',\'" + this._dataValue + "\',\'" + attributesAsString + "\',0)";
                                try
                                {
                                    cmd.ExecuteNonQuery();
                                    this._UPDATE_StatisticsHandler.LogEvent(data.VariableName);
                                }
                                catch (Exception ex)
                                {
                                    string    msg   = "Error performing UPDATE on \'" + data.VariableName + "\' from publication \'" + this._publicationName + "\': " + ex.Message;
                                    Exception newEX = new Exception(msg);
                                    throw (newEX);
                                }
                            }                     //--------- cmd
                        }                         //using del sql connection
                    }
                }
                catch (Exception ex)
                {
                    CustomEventLog.WriteEntry(ex);
                }
            }
 internal void RecordLastValue(DPE_PublicationData data)
 {
     try
     {
         lock (this._variablesLastDataRecorded)
         {
             if (this._variablesLastDataRecorded.ContainsKey(data.VariableName))
             {
                 this._variablesLastDataRecorded.Remove(data.VariableName);
             }
             this._variablesLastDataRecorded.Add(data.VariableName, data);
         }
     }
     catch (Exception)
     {
     }
 }
Exemple #12
0
 internal void SendPublicationDataUpdate(DPE_PublicationData data)
 {
     this._DSSPublicationsSQLWriter.UpdatePublicationVariable(data);
 }
Exemple #13
0
            private void ProcessPublicationUpdateDataReceivedOnConnection(SocketData data)
            {
                //the publication name comes as the sender socket client name
                DPE_PublicationData pubData = default(DPE_PublicationData);
                string publicationName      = "";

                publicationName = data.AttributesTable.GetAttribute(DPE_ServerDefs.DPE_PUBLICATION_NAME).Value;
                if (publicationName == null)
                {
                    throw (new Exception("Can\'t process publication data because the publication name attribute \'DPE_PUBLICATION_NAME\' is missing in the Socket data"));
                }

                string updateFlagString = "";

                updateFlagString = data.AttributesTable.GetAttribute(DPE_ServerDefs.DPE_PUBLICATION_UPDATE_FLAG).Value;
                if (updateFlagString == null)
                {
                    string msg = "Can\'t process the publication update because the incomming data dont contain the control flag \'" + DPE_ServerDefs.DPE_PUBLICATION_UPDATE_FLAG + "\'";
                    throw (new Exception(msg));
                }
                else
                {
                    switch (updateFlagString)
                    {
                    case DPE_ServerDefs.DPE_PUBLICATION_DATA_UPDATE:
                        pubData = DPE_PublicationData.GetSTXDSS_PublicationData(publicationName, data.DataName, data.Value);
                        if (data.AttributesTable.Count > 0)
                        {
                            pubData.DataAttributesTable.SetAttributesFromSource(data.AttributesTable);
                        }
                        try
                        {
                            if (PublicationDataReceivedEvent != null)
                            {
                                PublicationDataReceivedEvent(pubData);
                            }
                        }
                        catch (Exception)
                        {
                        }
                        break;

                    case DPE_ServerDefs.DPE_PUBLICATION_DATA_RESET:
                        try
                        {
                            if (PublicationDataResetReceivedEvent != null)
                            {
                                PublicationDataResetReceivedEvent(publicationName, data.DataName);
                            }
                        }
                        catch (Exception)
                        {
                        }
                        break;

                    default:
                        string msg = "";
                        msg = "Can\'t Update Publication data. Invalid parameter value for flag \'" + DPE_ServerDefs.DPE_PUBLICATION_UPDATE_FLAG + "\' : " + updateFlagString;
                        CustomEventLog.WriteEntry(EventLogEntryType.Error, msg);
                        break;
                    }
                }
            }
Exemple #14
0
 private void EventHandling_DSSPublicationsSQLReader_dataUpdateFromPublication(DPE_PublicationData newData)
 {
     try
     {
         if (PublicationDataReceivedEvent != null)
         {
             PublicationDataReceivedEvent(newData);
         }
     }
     catch (Exception)
     {
     }
 }
Exemple #15
0
            private void THREAD_FCN_UpdatePublicatonOnSubscriptorConnection()
            {
                try
                {
                    SocketsServerClientConnectionHandler ClientHandler = default(SocketsServerClientConnectionHandler);

                    if (this._updatePublicationOnClientConnectionQueue.Count > 0)
                    {
                        ClientHandler = null;
                        try
                        {
                            ClientHandler = (SocketsServerClientConnectionHandler)this._updatePublicationOnClientConnectionQueue.Dequeue();
                        }
                        catch (Exception)
                        {
                            ClientHandler = null;
                        }

                        if (!(ClientHandler == null))
                        {
                            lock (this._variablesPublishedRegistry)
                            {
                                IEnumerator         enumm         = default(IEnumerator);
                                string              variableName  = "";
                                DPE_PublicationData lastDataValue = default(DPE_PublicationData);
                                enumm = this._variablesPublishedRegistry.PublishedVariablesNamesList.GetEnumerator();

                                while (enumm.MoveNext())
                                {
                                    try
                                    {
                                        variableName  = System.Convert.ToString(enumm.Current);
                                        lastDataValue = this._variablesPublishedRegistry.GetLastRecordedDataValue(variableName);

                                        if (!(lastDataValue == null))
                                        {
                                            SocketData ds = default(SocketData);
                                            ds = this.ConvertPublicationDataToSocketDataType(lastDataValue);
                                            try
                                            {
                                                //Uses the sockets server to send data exclusively to a client
                                                this._publicationSocketsServer.SendDataToClient(ClientHandler, ds);
                                            }
                                            catch (Exception ex)
                                            {
                                                CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString());
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString());
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    CustomEventLog.WriteEntry(EventLogEntryType.Error, ex.ToString());
                }
            }
            private void EventHandling_readTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
            {
                //*****************************************************************************
                // STOPS THE TIMER
                //*****************************************************************************
                this._readTimer.Stop();

                try
                {
                    if (this._isFirstTimeRead)
                    {
                        //retrieves the server datetime to retrieve the data using datetime
                        this._lastReadDatetime    = this.GetPublicationsServerDAtetime();
                        this.dateAsstring         = NowToStandardODBCStringFormat(this._lastReadDatetime);
                        this._dataReadCommandTest = "Select * from " + this._tablename + " where datetime >= \'" + dateAsstring + "\' order by [datetime] asc";
                        this._isFirstTimeRead     = false;
                    }
                    else
                    {
                        if (this._lastRowIDReaded > 0)
                        {
                            //uses the row id as to retrieve new data
                            this._dataReadCommandTest = "Select * from " + this._tablename + " where rowID > " + System.Convert.ToString(this._lastRowIDReaded) + " order by [rowID] asc";
                        }
                        else
                        {
                            //uses the datetime as to retrieve new data
                            this.dateAsstring         = NowToStandardODBCStringFormat(this._lastReadDatetime);
                            this._dataReadCommandTest = "Select * from " + this._tablename + " where datetime >= \'" + dateAsstring + "\' order by [datetime] asc";
                        }
                    }

                    using (System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection(this._dataBaseSonnectionString))
                    {
                        try
                        {
                            cnn.Open();


                            using (System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand())
                            {
                                cmd.Connection = cnn;

                                //************************************************************
                                //PREPARES THE QUERY TO THE PUBLICATION
                                //************************************************************

                                cmd.CommandText = this._dataReadCommandTest;

                                using (System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter())
                                {
                                    da.SelectCommand = cmd;


                                    using (DataTable dt = new DataTable())
                                    {
                                        //******************************************
                                        // RETRIEVS THE DATA FROM DATA SOURCE
                                        da.Fill(dt);
                                        //******************************************


                                        //************************************************************
                                        //DATA TREATMENT
                                        if (dt.Rows.Count > 0)
                                        {
                                            DataRow     row   = default(DataRow);
                                            IEnumerator enumm = dt.Rows.GetEnumerator();
                                            while (enumm.MoveNext())
                                            {
                                                row = (DataRow )enumm.Current;

                                                //*****************************************************
                                                // transfors the row into a data update or data reset
                                                //*****************************************************
                                                try
                                                {
                                                    long     _rowID;
                                                    string   _dataType        = "";
                                                    string   _value           = "";
                                                    string   _dataName        = "";
                                                    DateTime _dataDatetime    = System.Convert.ToDateTime(null);
                                                    bool     _isDataReset     = false;
                                                    string   _attributesTAble = "";


                                                    _rowID           = (long)(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_ROWID]);
                                                    _dataType        = System.Convert.ToString(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_DATA_TYPE]);
                                                    _value           = System.Convert.ToString(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_VALUE]);
                                                    _dataName        = System.Convert.ToString(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_DATA_NAME]);
                                                    _attributesTAble = System.Convert.ToString(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_ATTRIBUTES_TABLE]);

                                                    try
                                                    {
                                                        _dataDatetime = System.Convert.ToDateTime(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_DATA_DATETIME]);
                                                    }
                                                    catch (Exception)
                                                    {
                                                        _dataDatetime = DateTime.Now;
                                                    }
                                                    _isDataReset = System.Convert.ToBoolean(row[DPE_GlobalDefinitions.DPE_PUBLICATION_TABLE_DEFINITION_IS_DATA_RESET]);


                                                    //------------------------------------------------

                                                    if (!_isDataReset)
                                                    {
                                                        DPE_PublicationData data = default(DPE_PublicationData);
                                                        data = DPE_GlobalDefinitions.GetPublicationValueFromString(this._publicationName, _dataName, _dataType, _value);


                                                        AttributesTable attrTAble = default(AttributesTable);
                                                        //------------------------------------------------
                                                        //verifies if there are a parameters table
                                                        if (_attributesTAble.Length > 0)
                                                        {
                                                            DataVariable    dataVar = XMLDataFormatting.RetrieveDataVariableFromXMLString(_attributesTAble);
                                                            CustomHashTable table   = (CustomHashTable)dataVar.Data;
                                                            attrTAble = new AttributesTable(table);
                                                            data.AttachAttibutesTable(attrTAble);
                                                        }

                                                        this._DATA_UPDATE_PCQ.Enqueue(data);
                                                    }
                                                    else
                                                    {
                                                        this._DATA_RESET_PCQ.Enqueue(_dataName);
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    CustomEventLog.WriteEntry(ex);
                                                }
                                            }
                                        }
                                        //************************************************************


                                        //************************************************************
                                        //GETS THE LAST TABLE REFERENCE DATE TIME and ROWid FROM THE DATA IF IS AVAILABLE
                                        try
                                        {
                                            if (dt.Rows.Count > 0)
                                            {
                                                this.SetLastReadDateTiemeAndRowID(dt);
                                            }
                                        }
                                        catch (Exception)
                                        {
                                        }
                                        //************************************************************
                                    }                     //----------- data table
                                }                         //-------- SqlDataAdapter
                            }                             //-------- SqlCommand
                        }
                        catch (System.Data.SqlClient.SqlException sqlex)
                        {
                            //overrides the error qhen
                            if (sqlex.ErrorCode != -2146232060)
                            {
                                CustomEventLog.WriteEntry(sqlex);
                            }
                        }
                        catch (Exception ex)
                        {
                            CustomEventLog.DisplayEvent(EventLogEntryType.Error, ex.ToString());
                        }
                        finally
                        {
                            if (this._keepReading)
                            {
                                this._readTimer.Start();
                            }

                            try
                            {
                                cnn.Close();
                                cnn.Dispose();
                            }
                            catch (Exception)
                            {
                            }
                        }
                    }                     //-------  sqlConnection
                }
                catch (Exception ex)
                {
                    CustomEventLog.DisplayEvent(EventLogEntryType.Error, ex.ToString());
                }
            }