Пример #1
0
            public Services.P2PCommunicationsScheme.Data.P2PData RetrieveData(Services.P2PCommunicationsScheme.Data.P2PDataRequest request, int P2PPortNumber)
            {
                if (request.RequestedDataName == CNDServiceDefinitions.CND_TABLE_DATA_NAME)
                {
                    P2PData cndTable = new P2PData(CNDServiceDefinitions.CND_TABLE_DATA_NAME, this.CNDTable.DataTable);
                    return(cndTable);

                    //*****************************************************************
                    // !!!!! IMPORTANT EVALUATION
                    //this indicates to the connected client that the port belongs to
                    //the CND service,
                    //*****************************************************************
                }
                else if (request.RequestedDataName == CNDServiceDefinitions.CND_SERVICE_PORT_CONNECTION_CHECK_DATA)
                {
                    return(new P2PData(CNDServiceDefinitions.CND_SERVICE_PORT_CONNECTION_CHECK_DATA, true));
                    //*****************************************************************
                    //*****************************************************************
                }
                else if (request.RequestedDataName == CNDServiceDefinitions.CND_GET_COMPONENT_CND_REGISTRY_CMD)
                {
                    return(this.Handle_GetComponentAddressingRegistry_Request(request));
                }
                else
                {
                    throw (new Exception("The CND Service can handle the data named \'" + request.RequestedDataName + "\'"));
                }
            }
 public void btnRequestData_Click(System.Object sender, System.EventArgs e)
 {
     try
     {
         this.Cursor = Cursors.WaitCursor;
         if (this.txtDataNameToRequest.Text.Length <= 0)
         {
             throw (new Exception("No data name to request"));
         }
         P2PData        data    = default(P2PData);
         P2PDataRequest request = new P2PDataRequest(this.txtDataNameToRequest.Text);
         data = this._p2pPortclient.RetrieveData(request);
         this.CfDataDisplayCtrl1.ShowData(data.Value);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         this.Cursor = Cursors.Default;
         this.dgrdGeneralStatistics.DataSource = this._p2pPortclient.Statistics.GeneralStatisticsTable;
         this.dgrdRequestStats.DataSource      = this._p2pPortclient.Statistics.DataRequestsStatisticsTable;
     }
 }
 public void tmrAutoSend_Tick(System.Object sender, System.EventArgs e)
 {
     try
     {
         IEnumerator enumm  = this.lstAutoSend.Items.GetEnumerator();
         Data        dat    = default(Data);
         P2PData     p2pdat = default(P2PData);
         while (enumm.MoveNext())
         {
             dat    = (CommunicationsUISupportLibrary.Data)enumm.Current;
             p2pdat = GetP2PDataToSend(dat);
             AssingDataAttributesToP2PData(p2pdat);
             try
             {
                 this._p2pPortclient.SendData(P2PDataSendMode.SyncrhonicalSend, p2pdat);
             }
             catch (Exception ex)
             {
                 this.lstErrorsOnAutoSEnd.Items.Add(ex.Message);
             }
         }
         this.dgrdGeneralStatistics.DataSource = this._p2pPortclient.Statistics.GeneralStatisticsTable;
         this.dgrdSendStats.DataSource         = this._p2pPortclient.Statistics.DataSendingStatisticsTable;
     }
     catch (Exception ex)
     {
         this.lstErrorsOnAutoSEnd.Items.Add(ex.Message);
     }
 }
 private P2PData GetP2PDataToSend()
 {
     if (this.CfDataManagerContainer1.DataCount > 0)
     {
         Data    dat    = this.CfDataManagerContainer1.SelectedData;
         P2PData p2pDat = default(P2PData);
         if (!(dat == null))
         {
             p2pDat = P2PData.GetP2PDataObject(dat.DataName, dat.data);
             if (!(p2pDat == null))
             {
                 this.AssingDataAttributesToP2PData(p2pDat);
                 return(p2pDat);
             }
             else
             {
                 throw new Exception("No valid p2p data to return");
             }
         }
         else
         {
             throw (new Exception("No selected data to send"));
         }
     }
     else
     {
         throw (new Exception("No data available to send"));
     }
 }
            internal void PostPublicationOnServer(DPE_ClientPublicationDefinition PublicationDefinition)
            {
                //crates the publication definition into a P2PData to send to the server
                CustomHashTable varsToPublish = new CustomHashTable();
                string          variableName  = "";

                DPE_ServerDefs.PublicationVariableDataType variableDataType = default(DPE_ServerDefs.PublicationVariableDataType);
                string variableDataTypeAsString = "";

                IEnumerator enumm = PublicationDefinition.VariablesToPublishTable.GetEnumerator();

                while (enumm.MoveNext())
                {
                    variableName             = System.Convert.ToString(((DictionaryEntry)enumm.Current).Key);
                    variableDataType         = (DPE_ServerDefs.PublicationVariableDataType)(((DictionaryEntry)enumm.Current).Value);
                    variableDataTypeAsString = DPE_ServerDefs.Get_String_FromPublicationVariableDataType(variableDataType);
                    varsToPublish.Add(variableName, variableDataTypeAsString);
                }

                P2PData data = new P2PData(DPE_ServerDefs.DPE_CMD_CREATE_PUBLICATION, varsToPublish);

                data.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATIONS_GROUP, PublicationDefinition.PublicationsGroup);
                data.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_CLIENT_ID, this._STXDataSocketClient.ClientID);
                data.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_NAME, PublicationDefinition.PublicationName);

                Services.P2PCommunicationsScheme.P2PPortClient p2pclient = default(Services.P2PCommunicationsScheme.P2PPortClient);
                try
                {
                    p2pclient = new Services.P2PCommunicationsScheme.P2PPortClient(this._STXDataSocketClient.DSSServerHostName, this._STXDataSocketClient.PublicationsPost_PortNumber);
                    p2pclient.Connect();

                    //sends the information to the server in order to create it
                    p2pclient.SendData(P2PDataSendMode.SyncrhonicalSend, data);

                    p2pclient.Dispose();

                    //it the publication was created in the server then ists definition is saved in the publications posted manager
                    //in order to allow it to re create ii if needed
                    this.AddPublicationDefinitionAfterCreation(PublicationDefinition);

                    string msg = "Publication \'" + PublicationDefinition.PublicationName + "\'    ->    POSTED succesfully.";
                    CustomEventLog.WriteEntry(EventLogEntryType.SuccessAudit, msg);
                }
                catch (Exception ex)
                {
                    try
                    {
                        this.RemovePublicationDefinition(PublicationDefinition);
                    }
                    catch (Exception)
                    {
                    }
                    string errMSg = "";
                    errMSg = "Error creating the publication \'" + PublicationDefinition.PublicationName + "\' : " + ex.Message;
                    throw (new Exception(errMSg));
                }
            }
Пример #6
0
 public CommunicationsData(string addresseComponentName, string senderComponentName, string dataName, DataSet data)
 {
     dataName = dataName.ToUpper();
     this._senderComponentName   = senderComponentName;
     this._addresseComponentName = addresseComponentName;
     this._p2pData = new P2PData(dataName, data);
     this._p2pData.DataAttributesTable.AddAttribute("SENDER_COMPONENT", senderComponentName);
     this._p2pData.DataAttributesTable.AddAttribute("ADDRESSE_COMPONENT", addresseComponentName);
 }
Пример #7
0
 internal void LogDataReceptionEvent(P2PData data)
 {
     try
     {
         this._LogDataReceptionEventQueue.Enqueue(data);
     }
     catch (Exception)
     {
     }
 }
 internal void LogDataSendEvent(P2PData data)
 {
     try
     {
         this.LogDataSendEventsOnTable(data);
     }
     catch (Exception)
     {
     }
 }
Пример #9
0
            internal CommunicationsData RetrieveData(CNDCommunicationsEnvironment.Data.CommunicationsDataRequest datarequest)
            {
                P2PData dataResult = default(P2PData);

                dataResult = this._p2pPortClient.RetrieveData(datarequest.P2PDataRequest);
                CommunicationsData dataRetrieved = default(CommunicationsData);

                dataRetrieved = CommunicationsData.GetCommunicationsDataObject(datarequest.RemoteAddresseComponentName, datarequest.SenderComponentName, dataResult.DataName, dataResult.Value);
                return(dataRetrieved);
            }
        public CommunicationsLibrary.Services.P2PCommunicationsScheme.Data.P2PData RetrieveData(CommunicationsLibrary.Services.P2PCommunicationsScheme.Data.P2PDataRequest request, int HandlerP2PPortNumber)
        {
            string dataName = request.RequestedDataName;

            if (this.chkSimulateHaltExecution.Checked)
            {
                while (true)
                {
                    System.Threading.Thread.Sleep(10);
                    if (!this.chkSimulateHaltExecution.Checked)
                    {
                        break;
                    }
                }
            }

            if (this.chkSimulateFailure.Checked)
            {
                if (rbtnSimulateNull.Checked)
                {
                    return(null);
                }
                else
                {
                    throw (new Exception(this.txtExceptionText.Text));
                }
            }


            if (this.chkRequestLog.Checked)
            {
                string msgStr = "Data Requested : " + dataName;
                this.SetListBoxItem(this.lstRequestReceived, msgStr);
            }


            this.SetDataGridDataSource(this.dgrGeneralStatistics, this._P2PPort.Statistics.GeneralStatisticsTable);
            this.SetDataGridDataSource(this.dgrRequestStatistics, this._P2PPort.Statistics.DataRequestsStatisticsTable);

            if (this.CfDataManagerContainer1.ContainsData(dataName))
            {
                Data    dat  = this.CfDataManagerContainer1.DataItem(dataName);
                P2PData data = default(P2PData);
                data = P2PData.GetP2PDataObject(dataName, dat.data);
                return(data);
            }
            else
            {
                return(null);
            }
        }
            private void SendDataInAsynchronicalMode(P2PData data)
            {
                //this method send data to the P2PPort without waiting a callback or a result from the remote port
                bool   throwError = false;
                string errMsg     = "";

                if (!(this._tcpClient == null))
                {
                    lock (this._socketPortBlockingFlag)
                    {
                        this._dataDEliveryResultISAvailable = false;
                        byte[] dataByteBuffer = data.Serialize();

                        if (dataByteBuffer.Length > P2PNetworkingDefinitions.DATABUFFER_SIZE)
                        {
                            throwError = true;
                            errMsg     = "The size of the data exceeds the maximun limit of " + System.Convert.ToString(P2PNetworkingDefinitions.DATABUFFER_SIZE) + " for the P2P port";
                        }
                        else
                        {
                            if (!(this._socketStream == null))
                            {
                                try
                                {
                                    this._socketStream.Write(dataByteBuffer, 0, dataByteBuffer.Length);

                                    this.Statistics.LogDataSendEvent(data);
                                }
                                catch (Exception ex)
                                {
                                    throwError = true;
                                    errMsg     = ex.Message;
                                }
                            }
                            else
                            {
                                throwError = true;
                                errMsg     = "The socket stream is not available";
                            }
                        }
                    }
                    if (throwError)
                    {
                        throw (new Exception(errMsg));
                    }
                }
                else
                {
                    throw (new Exception("The client is not connected to the remote port specified as [" + this._remoteHostName + " : " + System.Convert.ToString(this._remotePortNumber) + "]"));
                }
            }
Пример #12
0
            private void Handle_ComponentRegistrationRemoval_Data(P2PData data)
            {
                if (!data.DataAttributesTable.ContainsAttribute(CNDServiceDefinitions.COMPONENT_NAME))
                {
                    throw (new Exception("can\'t remove a component registry becuase the parameter \'" + CNDServiceDefinitions.COMPONENT_NAME + " \' is missing"));
                }
                P2PDataAttributesTable.P2PDataAttribute attr = new P2PDataAttributesTable.P2PDataAttribute();

                attr = data.DataAttributesTable.GetAttribute(CNDServiceDefinitions.COMPONENT_NAME);
                string compName = "";

                compName = attr.AttrValue;

                this.UnsubsribeComponent(compName);
            }
Пример #13
0
            public static P2PData GetP2PDataObject(string dataName, object data)
            {
                string  type     = data.GetType().ToString();
                P2PData _p2pData = default(P2PData);

                switch (type)
                {
                case "System.String":
                    _p2pData = new P2PData(dataName, System.Convert.ToString(data));
                    break;

                case "System.Int32":
                    _p2pData = new P2PData(dataName, System.Convert.ToInt32(data));
                    break;

                case "System.Decimal":
                    _p2pData = new P2PData(dataName, System.Convert.ToDecimal(data));
                    break;

                case "System.Boolean":
                    _p2pData = new P2PData(dataName, System.Convert.ToBoolean(data));
                    break;

                case "System.Data.DataTable":
                    _p2pData = new P2PData(dataName, (DataTable)data);
                    break;

                case "System.Data.DataSet":
                    _p2pData = new P2PData(dataName, (DataSet)data);
                    break;

                case "UtilitiesLibrary.Data.CustomHashTable":
                    _p2pData = new P2PData(dataName, (CustomHashTable)data);
                    break;

                case "UtilitiesLibrary.Data.CustomList":
                    _p2pData = new P2PData(dataName, (CustomList)data);
                    break;

                case "UtilitiesLibrary.Data.CustomSortedList":
                    _p2pData = new P2PData(dataName, (CustomSortedList)data);
                    break;

                default:
                    throw (new Exception("Unsupported data type \'" + type + "\' for \'P2PData\' data type "));
                }
                return(_p2pData);
            }
Пример #14
0
            private void Handle_ComponentRegistration_Data(P2PData data)
            {
                UtilitiesLibrary.Data.CustomHashTable table = default(UtilitiesLibrary.Data.CustomHashTable);
                table = (CustomHashTable)data.Value;

                if (!table.Contains(CNDServiceDefinitions.CND_TABLE_COMPONENT_NAME))
                {
                    throw (new Exception("Can\'t register a component in CNDService becuase the parameter \'[Component Name]\' is missing."));
                }

                if (!table.Contains(CNDServiceDefinitions.CND_TABLE_HOST_NAME))
                {
                    throw (new Exception("Can\'t register a component in CNDService becuase the parameter \'[Hostname]\' is missing."));
                }

                if (!table.Contains(CNDServiceDefinitions.CND_TABLE_P2P_PORT_NUMBER))
                {
                    throw (new Exception("Can\'t register a component in CNDService becuase the parameter \'[P2PPortNumber]\' is missing."));
                }

                if (!table.Contains(CNDServiceDefinitions.CND_TABLE_IP_ADDRESS))
                {
                    throw (new Exception("Can\'t register a component in CNDService becuase the parameter \'[IPAddress]\' is missing."));
                }

                if (!table.Contains(CNDServiceDefinitions.CND_TABLE_APPLICATION_NAME))
                {
                    throw (new Exception("Can\'t register a component in CNDService becuase the parameter \'[Application Name]\' is missing."));
                }

                if (!table.Contains(CNDServiceDefinitions.CND_TABLE_APPLICATION_PROCESS_ID))
                {
                    throw (new Exception("Can\'t register a component in CNDService becuase the parameter \'[Application Process ID]\' is missing."));
                }

                string compName = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_COMPONENT_NAME));

                compName = compName.ToUpper();
                string hostName             = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_HOST_NAME));
                string P2PPortNumber        = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_P2P_PORT_NUMBER));
                string IPAddress            = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_IP_ADDRESS));
                string ApplicationName      = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_NAME));
                string ApplicationProcessID = System.Convert.ToString(table.Item(CNDServiceDefinitions.CND_TABLE_APPLICATION_PROCESS_ID));

                int portNumber = Convert.ToInt32(P2PPortNumber);

                this.SubscribeComponent(compName, hostName, IPAddress, portNumber, ApplicationName, ApplicationProcessID);
            }
        private void LoadDataAttributes(P2PData data)
        {
            this.lstDataAttributes.Items.Clear();
            IEnumerator enumm = default(IEnumerator);

            enumm = data.DataAttributesTable.GetEnumerator();
            CommunicationsLibrary.Services.P2PCommunicationsScheme.Data.P2PDataAttributesTable.P2PDataAttribute attr = default(CommunicationsLibrary.Services.P2PCommunicationsScheme.Data.P2PDataAttributesTable.P2PDataAttribute);
            string str = "";

            while (enumm.MoveNext())
            {
                attr = (CommunicationsLibrary.Services.P2PCommunicationsScheme.Data.P2PDataAttributesTable.P2PDataAttribute)enumm.Current;
                str  = attr.AttrName + " , " + attr.AttrValue;
                this.lstDataAttributes.Items.Add(str);
            }
        }
 private void AssingDataAttributesToP2PData(P2PData data)
 {
     if (this._dataAttributesTable.ContainsKey(data.DataName))
     {
         //the data has attributes
         Hashtable   attrTable = (Hashtable)(this._dataAttributesTable[data.DataName]);
         IEnumerator enumm     = attrTable.GetEnumerator();
         string      attrName  = "";
         string      attrValue = "";
         while (enumm.MoveNext())
         {
             attrName  = System.Convert.ToString(((DictionaryEntry)enumm.Current).Key);
             attrValue = System.Convert.ToString(((DictionaryEntry)enumm.Current).Value);
             data.DataAttributesTable.AddAttribute(attrName, attrValue);
         }
     }
 }
 public void btnSendData_Click(System.Object sender, System.EventArgs e)
 {
     try
     {
         P2PData dat = this.GetP2PDataToSend();
         this._p2pPortclient.SendData(P2PDataSendMode.SyncrhonicalSend, dat);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
     finally
     {
         this.dgrdGeneralStatistics.DataSource = this._p2pPortclient.Statistics.GeneralStatisticsTable;
         this.dgrdSendStats.DataSource         = this._p2pPortclient.Statistics.DataSendingStatisticsTable;
     }
 }
Пример #18
0
            private P2PData Handle_GetComponentAddressingRegistry_Request(P2PDataRequest request)
            {
                string componentName = "";

                componentName = request.GetRequestParameter(CNDServiceDefinitions.COMPONENT_NAME);
                if (componentName == null)
                {
                    throw (new Exception("Can\'t resolve the Addressing because the paramter \'COMPONENT_NAME\' was missing in the data request."));
                }
                if (!this.CNDTable.ContainsComponentRegistry(componentName))
                {
                    throw (new Exception("Can\'t resolve the Addressig for component \'" + componentName + "\' because is not registered on the Service"));
                }
                CustomHashTable cnsREgister = this.CNDTable.GetComponentRegistry(componentName);
                P2PData         register    = new P2PData("CND_ADDRESSING_REGISTER", cnsREgister);

                return(register);
            }
        public void lstDataReceived_SelectedIndexChanged(System.Object sender, System.EventArgs e)
        {
            this.txtXMLDataString.Text = "";
            this.lstDataAttributes.Items.Clear();

            if (this.lstDataReceived.SelectedIndex >= 0)
            {
                P2PData dat = default(P2PData);
                dat = (CommunicationsLibrary.Services.P2PCommunicationsScheme.Data.P2PData) this.lstDataReceived.SelectedItem;

                this.CfDataDisplayCtrl1.ShowData(dat.Value);
                this.txtXMLDataString.Text = dat.XMLDataString;
                if (dat.DataAttributesTable.count > 0)
                {
                    this.LoadDataAttributes(dat);
                }
            }
        }
Пример #20
0
        private void _net_DisplayPeerMessage(P2PData message, string from)
        {
            // Показать полученное сообщение (вызывается из службы WCF)
            _board.SetMap(message.Map);
            var method = new MethodInvoker(() =>
            {
                Invalidate();
                _game.Direction  = message.Player == Player.Black;
                _game.BlackScore = message.BlackScore;
                _game.WhiteScore = message.WhiteScore;
                UpdateStatusText(message.Step);
                UpdateStatus();
                if (message.Player == Player.Black)
                {
                    var item = new LogItem()
                    {
                        Number = _game.Log.Count + 1, White = message.Step
                    };
                    item.AddToMap(_board.GetMap().DeepClone());
                    _game.Log.Add(item);
                    lvLog.VirtualListSize = _game.Log.Count;
                    var lvi           = lvLog.Items[lvLog.Items.Count - 1];
                    lvLog.FocusedItem = lvi;
                    lvi.EnsureVisible();
                    lvLog.Invalidate();
                }
                else
                {
                    var item   = _game.Log[_game.Log.Count - 1];
                    item.Black = message.Step;
                    item.AddToMap(_board.GetMap().DeepClone());
                    lvLog.Invalidate();
                }
            });

            if (InvokeRequired)
            {
                BeginInvoke(method);
            }
            else
            {
                method();
            }
        }
 public void tmrAutoRequest_Tick(System.Object sender, System.EventArgs e)
 {
     try
     {
         P2PData        data    = default(P2PData);
         P2PDataRequest request = new P2PDataRequest(this.txtDataNameToRequest.Text);
         data = this._p2pPortclient.RetrieveData(request);
         this.CfDataDisplayCtrl1.ShowData(data.Value);
     }
     catch (Exception ex)
     {
         this.lstErrorsOnAutoRequest.Items.Add(ex.Message);
     }
     finally
     {
         this.dgrdGeneralStatistics.DataSource = this._p2pPortclient.Statistics.GeneralStatisticsTable;
         this.dgrdRequestStats.DataSource      = this._p2pPortclient.Statistics.DataRequestsStatisticsTable;
     }
 }
            public void SendData(P2PDataSendMode mode, P2PData data)
            {
                switch (mode)
                {
                case P2PDataSendMode.SyncrhonicalSend:
                    //sends data to the remote port and waits intil the remote port returns a operation
                    //result
                    try
                    {
                        this.SendDataInSynchronicalMode(data);
                    }
                    catch (Exception ex)
                    {
                        throw (ex);
                    }
                    try
                    {
                        if (SuccesfullyDataSentEvent != null)
                        {
                            SuccesfullyDataSentEvent(data);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    break;

                case P2PDataSendMode.AsynchronycalSend:
                    //this method send data to the P2PPort without waiting a callback or a result from the remote port
                    this.SendDataInAsynchronicalMode(data);
                    try
                    {
                        if (SuccesfullyDataSentEvent != null)
                        {
                            SuccesfullyDataSentEvent(data);
                        }
                    }
                    catch (Exception)
                    {
                    }
                    break;
                }
            }
        private P2PData GetP2PDataToSend(Data dat)
        {
            P2PData p2pDat   = default(P2PData);
            string  dataType = dat.data.GetType().ToString();

            switch (dataType)
            {
            case "System.String":
                p2pDat = new P2PData(dat.DataName, System.Convert.ToString(dat.data));
                break;

            case "System.Int32":
                p2pDat = new P2PData(dat.DataName, System.Convert.ToInt32(dat.data));
                break;

            case "System.Boolean":
                p2pDat = new P2PData(dat.DataName, System.Convert.ToBoolean(dat.data));
                break;

            case "System.Decimal":
                p2pDat = new P2PData(dat.DataName, System.Convert.ToDecimal(dat.data));
                break;

            case "System.Data.DataTable":
                p2pDat = new P2PData(dat.DataName, (DataTable)dat.data);
                break;

            case "UtilitiesLibrary.Data.CustomHashTable":
                p2pDat = new P2PData(dat.DataName, (CustomHashTable)dat.data);
                break;

            case "UtilitiesLibrary.Data.CustomList":
                p2pDat = new P2PData(dat.DataName, (CustomList)dat.data);
                break;

            case "UtilitiesLibrary.Data.CustomSortedList":
                p2pDat = new P2PData(dat.DataName, (CustomSortedList)dat.data);
                break;
            }
            return(p2pDat);
        }
Пример #24
0
            public Services.P2PCommunicationsScheme.Data.P2PData RetrieveData(Services.P2PCommunicationsScheme.Data.P2PDataRequest request, int P2PPortNumber)
            {
                string adresseComponentName = System.Convert.ToString(request.GetRequestParameter("ADDRESSE_COMPONENT"));

                if (adresseComponentName == null)
                {
                    throw (new Exception("Can\'t retrieve data because the parameter \'ADDRESSE_COMPONENT\' was missing in the request structure"));
                }

                string senderComponentName = System.Convert.ToString(request.GetRequestParameter("SENDER_COMPONENT"));

                if (senderComponentName == null)
                {
                    throw (new Exception("Can\'t retrieve data because the parameter \'SENDER_COMPONENT\' was missing in the request structure"));
                }

                CNDCommunicationsEnvironment.Data.CommunicationsDataRequest commdDataRequest = new CNDCommunicationsEnvironment.Data.CommunicationsDataRequest(adresseComponentName, senderComponentName, System.Convert.ToString(request.RequestedDataName));

                CommunicationsData dataResult = ((CNDCommunicationsEnvironment.Interfaces.IUseCNDCommunicationsScheme) this._componentOwner).RetrieveDataToRemoteComponent(commdDataRequest);

                P2PData resultData = P2PData.GetP2PDataObject(dataResult.P2PData.DataName, dataResult.P2PData.Value);

                return(resultData);
            }
Пример #25
0
 internal static void PrepareDataToSend(SocketAsyncEventArgs e, P2PData data)
 {
     Byte[] SerializedData = data.Serialize();
     DataPreparationHandler.PrepareAndBufferData(e, SerializedData);
 }
            internal void ConnectoToPublication(DPE_PublicationConnectionHandler_Type connectionHandlerType, string publicationName, DPE_ServerDefs.DPE_PublicationConnectionMode connectionMode)
            {
                //*****************************************************************************
                //request to the server the connection parameters of the publication
                P2PDataRequest dataREquest = new P2PDataRequest(DPE_ServerDefs.DPE_CMD_PUBLICATION_SUBSCRIPTION_DATA);

                dataREquest.AddRequestParameter(DPE_PublicationsDefinitions.DPE_PUBLICATION_NAME, publicationName);

                P2PData publicationPArams = null;
                string  msg = "";

                Services.P2PCommunicationsScheme.P2PPortClient publicationsInformationRetrieveP2PPortClient = null;
                int trialsCount = 0;


                publicationsInformationRetrieveP2PPortClient = new Services.P2PCommunicationsScheme.P2PPortClient(this._STXDataSocketClient.DSSServerHostName, this._STXDataSocketClient.PublicationsInformationRetrieve_PortNumber);
                publicationsInformationRetrieveP2PPortClient.Connect();


                //performs a  while cycle until the client gets the connection parameters
                while (true)
                {
                    try
                    {
                        publicationPArams = publicationsInformationRetrieveP2PPortClient.RetrieveData(dataREquest);
                        break;
                    }
                    catch (Exception ex)
                    {
                        trialsCount++;

                        if (trialsCount >= MAX_DATA_CONNECTION_PARAMETERS_INQUIRY_TRIALS)
                        {
                            msg = "Error trying to connect to publication \'" + publicationName + "\': " + ex.Message;
                            throw (new Exception(msg));
                        }
                    }

                    System.Threading.Thread.Sleep(10);
                }

                try
                {
                    publicationsInformationRetrieveP2PPortClient.Dispose();
                }
                catch (Exception)
                {
                }

                CustomHashTable paramsList          = (CustomHashTable)publicationPArams.Value;
                string          publicationHostNAme = System.Convert.ToString(paramsList.Item(DPE_PublicationsDefinitions.DPE_PUBLICATION_HOSTNAME));
                int             publicationPort     = System.Convert.ToInt32(paramsList.Item(DPE_PublicationsDefinitions.DPE_PUBLICATION_PORT));

                //*****************************************************************************
                //CREATION OF THE PUBLICATION HANDLER and CONNECTION WITH publication
                DPE_PublicationConnectionHandler publicationConnectionHandler = default(DPE_PublicationConnectionHandler);

                publicationConnectionHandler = this.CreatePublicationConnectionHandler(connectionHandlerType, this._STXDataSocketClient, publicationName, publicationHostNAme, publicationPort, connectionMode);


                //*****************************************************************************
                //Ciclic process in order to allow the server to register the client socket connection . -> to synchronize the client registration
                //by ser client with the server event to log the publication event

                msg = "Error trying to perform the client connection registration to the publication \'" + publicationName + "\' : ";

                //*****************************************************************************
                //registration of the client connection to a publication in the server
                //the client sends to the server a information telling to which publication has already connected
                //and also for the TCP client mode to tell the publication to which port send the data

                int  connectionRegistrationTrialCounter = 0;
                bool connectionRegistration             = false;

                //preparation of the connection information into a p2p data
                P2PData clientPubCnnData = new P2PData(DPE_ServerDefs.DPE_CMD_CLIENT_PUBLICATION_CONNECTION_REGISTRATION, DPE_ServerDefs.DPE_CMD_CLIENT_PUBLICATION_CONNECTION_REGISTRATION);

                clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_CLIENT_ID, this._STXDataSocketClient.ClientID);
                clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_NAME, publicationName);
                clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_CONNECTION_HANDLER_ID, publicationConnectionHandler.HandlerID);
                //---------------------HANDLING FOR THE CONNECTION MODE ------------------------------
                string connectionModeAsString = "";

                connectionModeAsString = DPE_ServerDefs.Get_STXDSS_PublicationConnectionMode_ToAString(connectionMode);
                clientPubCnnData.DataAttributesTable.AddAttribute(DPE_PublicationsDefinitions.DPE_PUBLICATION_CLIENT_CONNECTION_MODE, connectionModeAsString);


                msg = "Error trying to perform the client connection registration to the publication \'" + publicationName + "\' : ";


                //sends to server the information to the server several times until the information reaches the server
                Services.P2PCommunicationsScheme.P2PPortClient publicationsClientRegistrationP2PPortClient = default(Services.P2PCommunicationsScheme.P2PPortClient);

                publicationsClientRegistrationP2PPortClient = new Services.P2PCommunicationsScheme.P2PPortClient(this._STXDataSocketClient.DSSServerHostName, this._STXDataSocketClient.PublicationsClientRegistration_PortNumber);
                publicationsClientRegistrationP2PPortClient.Connect();

                while (connectionRegistration == false)
                {
                    try
                    {
                        publicationsClientRegistrationP2PPortClient.SendData(P2PDataSendMode.SyncrhonicalSend, clientPubCnnData);

                        connectionRegistration = true;

                        publicationsClientRegistrationP2PPortClient.Dispose();

                        CustomEventLog.WriteEntry(EventLogEntryType.SuccessAudit, "Connection to publication \'" + publicationName + "\' succesfull");

                        break;
                    }
                    catch (Exception ex)
                    {
                        System.Threading.Thread.Sleep(10);

                        connectionRegistrationTrialCounter++;

                        if (connectionRegistrationTrialCounter >= MAX_CONNECTION_REGISTRATION_TRIALS)
                        {
                            msg = msg + ex.Message;

                            try
                            {
                                publicationsClientRegistrationP2PPortClient.Dispose();
                            }
                            catch (Exception)
                            {
                            }

                            try
                            {
                                this.DisposeConnectionHandler(publicationName);
                            }
                            catch (Exception)
                            {
                            }

                            throw (new Exception(msg));
                        }
                    }
                }
            }
Пример #27
0
 // function that mainly process the received data in the server port
 private void ProcessReceivedData(P2PPortClientHandler client)
 {
     try
     {
         if (!(client == null))
         {
             try
             {
                 //*****************************************
                 //tries to deserialize to a P2PDATA
                 //*****************************************
                 P2PData data = P2PData.Deserialize(client.ReceiveDataBuffer);
                 this.Statistics.LogDataReceptionEvent(data);
                 try
                 {
                     //catches if an exception ocurrs to avoid the programm exist from the reading thread
                     //because of a failure in the object that implements the interface.
                     ((IUseP2PCommunicationsScheme)this._portOwnerComponent).ReceiveData(data, this.ListeningPortNumber);
                     Services.P2PCommunicationsScheme.Data.P2PDataDeliveryResult successfulDataDelivery = Services.P2PCommunicationsScheme.Data.P2PDataDeliveryResult.GetSucceedDeliveryResult(data);
                     client.handlerSocket.Send(successfulDataDelivery.Serialize());
                     //***************************************************************************************
                 }
                 catch (Exception ex)
                 {
                     Services.P2PCommunicationsScheme.Data.P2PDataDeliveryResult failureDataDelivery = Services.P2PCommunicationsScheme.Data.P2PDataDeliveryResult.GetFailureDeliveryResult(data, ex.Message);
                     client.handlerSocket.Send(failureDataDelivery.Serialize());
                     //***************************************************************************************
                 }
             }
             catch (Exception ex)
             {
                 //*****************************************
                 //tries to deserialize to a P2P_DATA_DELIVERY_RESULT
                 //*****************************************
                 P2PDataRequest dataRequest   = default(P2PDataRequest);
                 P2PData        dataRequested = default(P2PData);
                 try
                 {
                     dataRequest = P2PDataRequest.Deserialize(client.ReceiveDataBuffer);
                     try
                     {
                         dataRequested = ((IUseP2PCommunicationsScheme)this._portOwnerComponent).RetrieveData(dataRequest, this.ListeningPortNumber);
                         if (!(dataRequested == null))
                         {
                             this.Statistics.LogSuccesfulDataRequestEvent(dataRequest);
                             client.handlerSocket.Send(dataRequested.Serialize());
                             //***************************************************************************************
                         }
                         else
                         {
                             this.Statistics.LogFailedDataRequestEvent(dataRequest);
                             string portOwnerName = ((IUseP2PCommunicationsScheme)this._portOwnerComponent).P2PPortOwnerName;
                             if (portOwnerName == null)
                             {
                                 portOwnerName = "UNKNOWN";
                             }
                             string errorMessage = "The remote object \'" + portOwnerName + "\' can\'t handle the requested data named \'" + dataRequest.RequestedDataName + "\'";
                             P2PDataRequestFailure reqFAilure = P2PDataRequestFailure.GetP2PDataRequestFailure(dataRequest, errorMessage);
                             client.handlerSocket.Send(reqFAilure.Serialize());
                             //***************************************************************************************
                         }
                     }
                     catch (Exception ex2)
                     {
                         this.Statistics.LogFailedDataRequestEvent(dataRequest);
                         string portOwnerName = ((IUseP2PCommunicationsScheme)this._portOwnerComponent).P2PPortOwnerName;
                         if (portOwnerName == null)
                         {
                             portOwnerName = "UNKNOWN";
                         }
                         string errorMessage = ex2.Message;
                         P2PDataRequestFailure reqFAilure = P2PDataRequestFailure.GetP2PDataRequestFailure(dataRequest, errorMessage);
                         client.handlerSocket.Send(reqFAilure.Serialize());
                         //***************************************************************************************
                     }
                 }
                 catch (Exception)
                 {
                     string msg = "";
                     msg = "Error processing incomming data from P2PPort client : " + ex.ToString();
                     CustomEventLog.WriteEntry(EventLogEntryType.Error, msg);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         string msg = "";
         msg = "Error processing incomming data from P2PPort client : " + ex.ToString();
         CustomEventLog.WriteEntry(EventLogEntryType.Error, msg);
     }
 }
            internal static P2PDataDeliveryResult GetSucceedDeliveryResult(P2PData data)
            {
                P2PDataDeliveryResult result = new P2PDataDeliveryResult(data);

                return(result);
            }
            private void LogDataSendEventsOnTable(P2PData Data)
            {
                if (!(Data == null))
                {
                    string    selectionCriteria = "";
                    DataRow[] resultRows        = null;


                    //*****************************************************************************
                    //updates the general statistics table
                    //*****************************************************************************
                    try
                    {
                        lock (this._generalStatisticsTable)
                        {
                            selectionCriteria = "[Client Port Event] = \'Successful Data Send\'";
                            resultRows        = this._generalStatisticsTable.Select(selectionCriteria);
                            if (resultRows.Length <= 0)
                            {
                                DataRow row = this._generalStatisticsTable.NewRow();
                                row["Client Port Event"] = "Successful Data Send";
                                row["Count"]             = 1;
                                this._generalStatisticsTable.Rows.Add(row);
                            }
                            else
                            {
                                long count = (long)(resultRows[0]["Count"]);
                                count++;
                                resultRows[0]["Count"] = count;
                                resultRows[0].AcceptChanges();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string msg = "Error updating P2PPortClient General Statistics Table : " + ex.ToString();
                        CustomEventLog.WriteEntry(EventLogEntryType.Error, msg);
                    }

                    //*****************************************************************************
                    //updates the data send statistics table
                    //*****************************************************************************
                    try
                    {
                        lock (this._dataSendingStatisticsTable)
                        {
                            selectionCriteria = "DataName = \'" + Data.DataName + "\' AND DataType = \'" + Data.Value.GetType().ToString() + "\'";
                            resultRows        = this._dataSendingStatisticsTable.Select(selectionCriteria);
                            if (resultRows.Length <= 0)
                            {
                                //the dataname with the datatype is not registered
                                DataRow row = this._dataSendingStatisticsTable.NewRow();
                                row["DataName"]          = Data.DataName;
                                row["DataType"]          = Data.Value.GetType().ToString();
                                row["Count"]             = 1;
                                row["FirstSendDateTime"] = DateTime.Now;
                                row["LastSendDateTime"]  = DateTime.Now;
                                this._dataSendingStatisticsTable.Rows.Add(row);
                            }
                            else
                            {
                                //the dataname with the datatype is registered
                                long count = (long)(resultRows[0]["Count"]);
                                count++;
                                resultRows[0]["Count"]            = count;
                                resultRows[0]["LastSendDateTime"] = DateTime.Now;
                                resultRows[0].AcceptChanges();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        string msg = "Error updating P2PPortClient Data Send Statistics Table : " + ex.ToString();
                        CustomEventLog.WriteEntry(EventLogEntryType.Error, msg);
                    }
                }
            }
Пример #30
0
            internal static P2PData ParseAndGet_P2PData_FromXMLDataString(string XMLString)
            {
                System.IO.StringReader   sr     = null;
                System.Xml.XmlTextReader m_xmlr = null;

                try
                {
                    sr     = new System.IO.StringReader(XMLString);
                    m_xmlr = new System.Xml.XmlTextReader(sr);
                    m_xmlr.WhitespaceHandling = System.Xml.WhitespaceHandling.None;
                }
                catch (System.Xml.XmlException)
                {
                    string msg;
                    msg = "Error trying to get XML format from  P2P Data string [" + XMLString + "]";
                }
                catch (Exception ex)
                {
                    string msg = "";
                    msg = "Error trying to parse P2P socket XML string : " + ex.Message;
                    throw (new Exception(msg));
                }
                m_xmlr.Read();
                string HeaderIdentifier = m_xmlr.Name;

                if (HeaderIdentifier != "P2P_DATA")
                {
                    throw (new System.Xml.XmlException("Invalid P2P data header " + HeaderIdentifier + ". Must be \'P2P_DATA\'"));
                }
                else
                {
                    //**********************************************************
                    //retrieves the data operation type
                    //**********************************************************

                    string operationID = "";
                    operationID = m_xmlr.GetAttribute("P2PDataOperationID");
                    if (operationID == null)
                    {
                        operationID = Guid.NewGuid().ToString();
                    }

                    //**********************************************************
                    //retrieves the data itself
                    //**********************************************************
                    m_xmlr.Read();
                    string       dataSectionName = m_xmlr.Name;
                    DataVariable variable        = default(DataVariable);
                    if (dataSectionName == "DATA")
                    {
                        string variableXMLstring = m_xmlr.ReadOuterXml();
                        variable = XMLDataFormatting.RetrieveDataVariableFromXMLString(variableXMLstring);
                    }
                    else
                    {
                        throw (new Exception("Invalid data XML section name \'" + dataSectionName + "\'. Is expected to be \'DATA\'"));
                    }

                    //**********************************************************
                    //retrieves the attributes table and its XML attributes
                    //**********************************************************
                    string dataAttributesSectionName = m_xmlr.Name;
                    P2PDataAttributesTable attrTAble = null;
                    int AttrCount = 0;

                    if (dataAttributesSectionName == "DATA_ATTRIBUTES")
                    {
                        string attributesCount = m_xmlr.GetAttribute("DataAttrCount");
                        if (!(attributesCount == null))
                        {
                            AttrCount = System.Convert.ToInt32(attributesCount);
                            if (AttrCount > 0)
                            {
                                string       attrTableXMLString = m_xmlr.ReadInnerXml();
                                DataVariable tableVar           = default(DataVariable);
                                tableVar  = XMLDataFormatting.RetrieveDataVariableFromXMLString(attrTableXMLString);
                                attrTAble = new P2PDataAttributesTable((CustomHashTable)tableVar.Data);
                            }
                        }
                        else
                        {
                            throw (new Exception("The parameter \'AttrCount\' is missing on the XML string in te section \'DATA_ATTRIBUTES\'"));
                        }
                    }
                    else
                    {
                        throw (new Exception("Invalid data attributes XML section name \'" + dataSectionName + "\'. Is expected to be \'DATA_ATTRIBUTES\'"));
                    }

                    P2PData data = default(P2PData);
                    data = new P2PData(operationID, System.Convert.ToString(variable.Name), variable.Data);
                    if (AttrCount > 0)
                    {
                        data.AttachAttributesTable(attrTAble);
                    }
                    return(data);
                }
            }