예제 #1
0
 internal void RemoveExistingHandler(RemoteComponentComunicationsHandler handler)
 {
     if (this._handlersTable.ContainsKey(handler.RemoteComponentName))
     {
         this._handlersTable.Remove(handler.RemoteComponentName);
         handler.ConnectionWithRemoteComponentLost -= ConnectionWithRemoteComponentLost;
     }
 }
예제 #2
0
 internal void AddNewHandler(RemoteComponentComunicationsHandler handler)
 {
     if (!this._handlersTable.ContainsKey(handler.RemoteComponentName))
     {
         this._handlersTable.Add(handler.RemoteComponentName, handler);
         handler.ConnectionWithRemoteComponentLost += ConnectionWithRemoteComponentLost;
     }
 }
예제 #3
0
 private void ConnectionWithRemoteComponentLost(string RemoteComponentName)
 {
     if (this.ContainsHandlerForRemoteComponent(RemoteComponentName))
     {
         RemoteComponentComunicationsHandler handler = default(RemoteComponentComunicationsHandler);
         handler = this.GetHandler(RemoteComponentName);
         this.RemoveExistingHandler(handler);
     }
 }
예제 #4
0
 public CommunicationsData RequestDataFromRemoteComponent(CNDCommunicationsEnvironment.Data.CommunicationsDataRequest dataRequest)
 {
     if (this._remoteHandlersContainer.ContainsHandlerForRemoteComponent(dataRequest.RemoteAddresseComponentName))
     {
         RemoteComponentComunicationsHandler handler = this._remoteHandlersContainer.GetHandler(dataRequest.RemoteAddresseComponentName);
         return(handler.RetrieveData(dataRequest));
     }
     else
     {
         RemoteComponentComunicationsHandler newhandler = this.GetRemoteHandlerForComponent(dataRequest.RemoteAddresseComponentName);
         this._remoteHandlersContainer.AddNewHandler(newhandler);
         return(newhandler.RetrieveData(dataRequest));
     }
 }
예제 #5
0
 public void SendData(CommunicationsData data)
 {
     if (this._remoteHandlersContainer.ContainsHandlerForRemoteComponent(data.AddresseComponentName))
     {
         RemoteComponentComunicationsHandler handler = this._remoteHandlersContainer.GetHandler(data.AddresseComponentName);
         handler.SendData(data);
     }
     else
     {
         RemoteComponentComunicationsHandler newhandler = this.GetRemoteHandlerForComponent(data.AddresseComponentName);
         this._remoteHandlersContainer.AddNewHandler(newhandler);
         newhandler.SendData(data);
     }
 }
예제 #6
0
            public void SubscribeToCommunicationsService(object component)
            {
                //the object that subscribes to the communications manager must implements the interface
                //IUseCNDCommunicationsScheme
                if (!(component is CNDCommunicationsEnvironment.Interfaces.IUseCNDCommunicationsScheme))
                {
                    throw (new Exception("The component passed as parameter can\'t be subscribed to communications environment because it must implements the \'IUseCNDCommunicationsScheme\' interface"));
                }

                string componentName = ((CNDCommunicationsEnvironment.Interfaces.IUseCNDCommunicationsScheme)component).ComponentName;

                componentName = componentName.ToUpper();
                if (componentName.Length <= 0)
                {
                    throw (new Exception("Can\'t subscribe to communications service because the component name can\'t be zero length"));
                }


                if (this._LocalHandlersContainer.ContainsHandlerForComponent(componentName))
                {
                    //the component with the name specified is already registered
                    throw (new Exception("The component \'" + componentName + "\' is already subscribed in the communications environment"));
                }

                CNDCommunicationsEnvironment.LocalCommunicationsHandling.LocalComponentCommunicationsHandler componentHandler = new CNDCommunicationsEnvironment.LocalCommunicationsHandling.LocalComponentCommunicationsHandler(component);
                this._LocalHandlersContainer.AddNewHandler(componentHandler);
                CNDSErviceRegistrationData CNDRegistrationData = componentHandler.GetRegistrationInformation();

                try
                {
                    this._CNDClient.SubscribeComponent(CNDRegistrationData);
                    this.LogComponent(CNDRegistrationData);
                }
                catch (Exception)
                {
                    //subscription failed so the manager will try to subscribe later
                    this.LogComponentForPendingSubscriptionToCNDService(CNDRegistrationData);
                    StartPendingSubscriptionTimer();
                }

                try
                {
                    //creates locally a handler to communicate with this component
                    RemoteComponentComunicationsHandler newhandler = this.GetRemoteHandlerForComponent(componentName);
                    this._remoteHandlersContainer.AddNewHandler(newhandler);
                }
                catch (Exception)
                {
                }
            }
예제 #7
0
 private RemoteComponentComunicationsHandler GetRemoteHandlerForComponent(string RemoteComponentName)
 {
     try
     {
         CNDAddressingReg reg = default(CNDAddressingReg);
         reg = this._CNDClient.ResolveAddress(RemoteComponentName);
         RemoteComponentComunicationsHandler handler = new RemoteComponentComunicationsHandler(RemoteComponentName, reg.HostName, reg.IPAddress, reg.P2PPortNumber);
         return(handler);
     }
     catch (Exception ex)
     {
         throw (new Exception("Unable to send data to component name \'" + RemoteComponentName + "\' becuase it is not posible to resolve its network location. Error: " + ex.Message));
     }
 }
예제 #8
0
 private void NewComponentRegistrationDetected(CNDAddressingReg ComponentCNDRegister)
 {
     try
     {
         //when a remote component is registred in the CNDService then is detected and is creted locally
         // a handler to communicate with it
         RemoteComponentComunicationsHandler newhandler = this.GetRemoteHandlerForComponent(ComponentCNDRegister.ComponentName);
         this._remoteHandlersContainer.AddNewHandler(newhandler);
         if (CNDTableChangedEvent != null)
         {
             CNDTableChangedEvent(this.CNDTable);
         }
     }
     catch (Exception ex)
     {
         CustomEventLog.WriteEntry(ex);
     }
 }
예제 #9
0
            public void UnsubscribeFromCommunicationsService(object component)
            {
                //the object that subscribes to the communications manager must implements the interface
                //IUseCNDCommunicationsScheme
                if (!(component is CNDCommunicationsEnvironment.Interfaces.IUseCNDCommunicationsScheme))
                {
                    throw (new Exception("The component passed as parameter can\'t be subscribed to communications environment because it must implements the \'IUseCNDCommunicationsScheme\' interface"));
                }

                string componentName = ((CNDCommunicationsEnvironment.Interfaces.IUseCNDCommunicationsScheme)component).ComponentName;

                componentName = componentName.ToUpper();

                CNDCommunicationsEnvironment.LocalCommunicationsHandling.LocalComponentCommunicationsHandler handler = default(CNDCommunicationsEnvironment.LocalCommunicationsHandling.LocalComponentCommunicationsHandler);
                if (this._LocalHandlersContainer.ContainsHandlerForComponent(componentName))
                {
                    handler = this._LocalHandlersContainer.GetHandler(componentName);
                    if (!(handler == null))
                    {
                        this._LocalHandlersContainer.RemoveExistingHandler(handler);
                    }
                }

                this._CNDClient.UnSubcribeComponent(componentName);

                //destroy the communications handler to communicate with the component locally
                if (this._remoteHandlersContainer.ContainsHandlerForRemoteComponent(componentName))
                {
                    RemoteComponentComunicationsHandler remoteComsHandler = default(RemoteComponentComunicationsHandler);
                    remoteComsHandler = this._remoteHandlersContainer.GetHandler(componentName);
                    this._remoteHandlersContainer.RemoveExistingHandler(remoteComsHandler);
                    remoteComsHandler.Dispose();
                }

                try
                {
                    this.UnlogComponent(componentName);
                }
                catch (Exception)
                {
                }
            }
예제 #10
0
 private void ComponentUnregistrationDetected(CNDAddressingReg ComponentCNDRegister)
 {
     try
     {
         if (this._remoteHandlersContainer.ContainsHandlerForRemoteComponent(ComponentCNDRegister.ComponentName))
         {
             RemoteComponentComunicationsHandler handler = default(RemoteComponentComunicationsHandler);
             handler = this._remoteHandlersContainer.GetHandler(ComponentCNDRegister.ComponentName);
             this._remoteHandlersContainer.RemoveExistingHandler(handler);
             if (CNDTableChangedEvent != null)
             {
                 CNDTableChangedEvent(this.CNDTable);
             }
         }
     }
     catch (Exception ex)
     {
         CustomEventLog.WriteEntry(ex);
     }
 }
예제 #11
0
 internal void DisposeAllHandlers()
 {
     try
     {
         IEnumerator enumm = this._handlersTable.GetEnumerator();
         RemoteComponentComunicationsHandler handler = default(RemoteComponentComunicationsHandler);
         while (enumm.MoveNext())
         {
             handler = (RemoteComponentComunicationsHandler)(((DictionaryEntry)enumm.Current).Value);
             try
             {
                 handler.Dispose();
             }
             catch (Exception)
             {
             }
             handler.ConnectionWithRemoteComponentLost -= ConnectionWithRemoteComponentLost;
         }
         this._handlersTable.Clear();
     }
     catch (Exception)
     {
     }
 }