/// <summary>
        /// Reads the xml file and creates client applications using _settings.
        /// </summary>
        private void CreateApplicationList()
        {
            foreach (var application in _settings.Applications)
            {
                //Create application object
                var clientApplication = new NGRIDClientApplication(application.Name);

                foreach (var channel in application.CommunicationChannels)
                {
                    switch (channel.CommunicationType)
                    {
                    case "WebService":
                        clientApplication.AddCommunicator(
                            new WebServiceCommunicator(
                                channel.CommunicationSettings["Url"],
                                Communication.CommunicationLayer.CreateCommunicatorId()
                                ));
                        break;
                    }
                }

                //Add new application to list
                Applications.Add(clientApplication.Name, clientApplication);
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method is used to add a new client application to NGRID while NGRID is running.
        /// Used by NGRIDController to allow user to add a new application from NGRIDManager GUI.
        /// It does all necessary tasks to add new application (Updates XML file, adds application to needed
        /// collections of system...).
        /// </summary>
        /// <param name="name">Name of the new application</param>
        public NGRIDClientApplication AddApplication(string name)
        {
            //Add to settings
            lock (_settings.Applications)
            {
                _settings.Applications.Add(
                    new ApplicationInfoItem
                {
                    Name = name
                });
                _settings.SaveToXml();
            }

            //Add to applications list
            lock (_clientApplicationList.Applications)
            {
                var newApplication = new NGRIDClientApplication(name);
                newApplication.Settings         = _settings;
                newApplication.StorageManager   = _storageManager;
                newApplication.MessageReceived += RemoteApplication_MessageReceived;

                _clientApplicationList.Applications.Add(name, newApplication);
                _communicationLayer.AddRemoteApplication(newApplication);

                newApplication.Start();

                return(newApplication);
            }
        }
Beispiel #3
0
        /// <summary>
        /// This method is used to delete a client application from NGRID while NGRID is running.
        /// Used by NGRIDController to allow user to remove an application from NGRIDManager GUI.
        /// It does all necessary tasks to remove application (Updates XML file, removes application from needed
        /// collections of system...).
        /// </summary>
        /// <param name="name">Name of the application to remove</param>
        /// <returns>Removed client application</returns>
        public NGRIDClientApplication RemoveApplication(string name)
        {
            //Remove from application list and communicaton layer
            NGRIDClientApplication clientApplication = null;

            lock (_clientApplicationList.Applications)
            {
                if (_clientApplicationList.Applications.ContainsKey(name))
                {
                    clientApplication = _clientApplicationList.Applications[name];
                    if (clientApplication.ConnectedCommunicatorCount > 0)
                    {
                        throw new NGRIDException("Client application can not be removed. It has " +
                                                 clientApplication.ConnectedCommunicatorCount +
                                                 " communicators connected. Please stop theese communicators first.");
                    }

                    clientApplication.MessageReceived -= RemoteApplication_MessageReceived;

                    _communicationLayer.RemoveRemoteApplication(clientApplication);
                    _clientApplicationList.Applications.Remove(name);
                }
            }

            if (clientApplication == null)
            {
                throw new NGRIDException("There is no client application with name " + name);
            }

            clientApplication.Stop(true);

            //Remove from settings
            lock (_settings.Applications)
            {
                for (var i = 0; i < _settings.Applications.Count; i++)
                {
                    if (_settings.Applications[i].Name.Equals(name, StringComparison.OrdinalIgnoreCase))
                    {
                        _settings.Applications.RemoveAt(i);
                        _settings.SaveToXml();
                        break;
                    }
                }
            }

            return(clientApplication);
        }
Beispiel #4
0
        /// <summary>
        /// This method is called by ProcessDataTransferMessage when a message must be sent to a aclient application
        /// that is running on this server.
        /// </summary>
        /// <param name="senderApplication">Sender application/server</param>
        /// <param name="senderCommunicator">Sender communicator</param>
        /// <param name="message">Message</param>
        private void SentToClientApplication(NGRIDRemoteApplication senderApplication, ICommunicator senderCommunicator, NGRIDDataTransferMessage message)
        {
            NGRIDClientApplication destinationApplication = null;

            //If application exists on this server, get it
            lock (_clientApplicationList.Applications)
            {
                if (_clientApplicationList.Applications.ContainsKey(message.DestinationApplicationName))
                {
                    destinationApplication = _clientApplicationList.Applications[message.DestinationApplicationName];
                }
            }

            //If application doesn't exist on this server...
            if (destinationApplication == null)
            {
                SendOperationResultMessage(senderApplication, senderCommunicator, message, false, "Application does not exists on this server (" + _settings.ThisServerName + ").");
                return;
            }

            //Send message according TransmitRule
            switch (message.TransmitRule)
            {
            case MessageTransmitRules.DirectlySend:
                SendMessageDirectly(
                    senderApplication,
                    senderCommunicator,
                    destinationApplication,
                    message
                    );
                break;

            default:
                // case MessageTransmitRules.StoreAndForward:
                // case MessageTransmitRules.NonPersistent:
                EnqueueMessage(
                    senderApplication,
                    senderCommunicator,
                    destinationApplication,
                    message
                    );
                break;
            }
        }
        /// <summary>
        /// Reads the xml file and creates client applications using _settings.
        /// </summary>
        private void CreateApplicationList()
        {
            foreach (var application in _settings.Applications)
            {
                //Create application object
                var clientApplication = new NGRIDClientApplication(application.Name);

                foreach (var channel in application.CommunicationChannels)
                {
                    switch (channel.CommunicationType)
                    {
                        case "WebService":
                            clientApplication.AddCommunicator(
                                new WebServiceCommunicator(
                                    channel.CommunicationSettings["Url"],
                                    Communication.CommunicationLayer.CreateCommunicatorId()
                                    ));
                            break;
                    }
                }

                //Add new application to list
                Applications.Add(clientApplication.Name, clientApplication);
            }
        }
Beispiel #6
0
        /// <summary>
        /// This method is used to add a new client application to NGRID while NGRID is running.
        /// Used by NGRIDController to allow user to add a new application from NGRIDManager GUI.
        /// It does all necessary tasks to add new application (Updates XML file, adds application to needed
        /// collections of system...).
        /// </summary>
        /// <param name="name">Name of the new application</param>
        public NGRIDClientApplication AddApplication(string name)
        {
            //Add to settings
            lock (_settings.Applications)
            {
                _settings.Applications.Add(
                    new ApplicationInfoItem
                        {
                            Name = name
                        });
                _settings.SaveToXml();
            }

            //Add to applications list
            lock (_clientApplicationList.Applications)
            {
                var newApplication = new NGRIDClientApplication(name);
                newApplication.Settings = _settings;
                newApplication.StorageManager = _storageManager;
                newApplication.MessageReceived += RemoteApplication_MessageReceived;

                _clientApplicationList.Applications.Add(name, newApplication);
                _communicationLayer.AddRemoteApplication(newApplication);

                newApplication.Start();

                return newApplication;
            }
        }