/// <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 MDSClientApplication(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); } }
/// <summary> /// This method is used to add a new client application to MDS while MDS is running. /// Used by MDSController to allow user to add a new application from MDSManager 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 MDSClientApplication AddApplication(string name) { if (_settings.Applications.Exists(a => a.Name == name)) { throw new ArgumentException(String.Format("Application '{0}' already exists ", 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 MDSClientApplication(name); newApplication.Settings = _settings; newApplication.StorageManager = _storageManager; newApplication.MessageReceived += RemoteApplication_MessageReceived; _clientApplicationList.Applications.Add(name, newApplication); _communicationLayer.AddRemoteApplication(newApplication); newApplication.Start(); return(newApplication); } }
/// <summary> /// This method is used to add a new client application to MDS while MDS is running. /// Used by MDSController to allow user to add a new application from MDSManager 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 MDSClientApplication 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 MDSClientApplication(name); newApplication.Settings = _settings; newApplication.StorageManager = _storageManager; newApplication.MessageReceived += RemoteApplication_MessageReceived; _clientApplicationList.Applications.Add(name, newApplication); _communicationLayer.AddRemoteApplication(newApplication); newApplication.Start(); return(newApplication); } }
/// <summary> /// This method is used to delete a client application from MDS while MDS is running. /// Used by MDSController to allow user to remove an application from MDSManager 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 MDSClientApplication RemoveApplication(string name) { //Remove from application list and communicaton layer MDSClientApplication clientApplication = null; lock (_clientApplicationList.Applications) { if (_clientApplicationList.Applications.ContainsKey(name)) { clientApplication = _clientApplicationList.Applications[name]; if (clientApplication.ConnectedCommunicatorCount > 0) { throw new MDSException("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 MDSException("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); }
/// <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(MDSRemoteApplication senderApplication, ICommunicator senderCommunicator, MDSDataTransferMessage message) { MDSClientApplication 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> /// This method is used to add a new client application to MDS while MDS is running. /// Used by MDSController to allow user to add a new application from MDSManager 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 MDSClientApplication 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 MDSClientApplication(name); newApplication.Settings = _settings; newApplication.StorageManager = _storageManager; newApplication.MessageReceived += RemoteApplication_MessageReceived; _clientApplicationList.Applications.Add(name, newApplication); _communicationLayer.AddRemoteApplication(newApplication); newApplication.Start(); return newApplication; } }
/// <summary> /// This method is used to add a new client application to MDS while MDS is running. /// Used by MDSController to allow user to add a new application from MDSManager 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 MDSClientApplication AddApplication(string name) { if (_settings.Applications.Exists(a => a.Name == name)) throw new ArgumentException(String.Format("Application '{0}' already exists ", 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 MDSClientApplication(name); newApplication.Settings = _settings; newApplication.StorageManager = _storageManager; newApplication.MessageReceived += RemoteApplication_MessageReceived; _clientApplicationList.Applications.Add(name, newApplication); _communicationLayer.AddRemoteApplication(newApplication); newApplication.Start(); return newApplication; } }