示例#1
0
 /// <summary>
 /// Creates a new MDSController object.
 /// </summary>
 /// <param name="name">Name of the controller</param>
 public MDSController(string name)
     : base(name, CommunicationLayer.CreateApplicationId())
 {
     _settings = MDSSettings.Instance;
     _designSettings = MDSDesignSettings.Instance;
     MessageReceived += MDSController_MessageReceived;
 }
示例#2
0
        /// <summary>
        /// Processes UpdateServerGraphMessage.
        /// </summary>
        /// <param name="communicator">Communicator that sent message</param>
        /// <param name="controlMessage">The message to be processed</param>
        /// <param name="controllerMessage">MDSControllerMessage object that includes controlMessage</param>
        private void ProcessUpdateServerGraphMessage(ICommunicator communicator, UpdateServerGraphMessage controlMessage, MDSControllerMessage controllerMessage)
        {
            try
            {
                var newSettings = new MDSSettings(Path.Combine(GeneralHelper.GetCurrentDirectory(), "MDSSettings.xml"));
                var newDesignSettings = new MDSDesignSettings(Path.Combine(GeneralHelper.GetCurrentDirectory(), "MDSSettings.design.xml"));

                //Clear existing server lists
                newSettings.Servers.Clear();
                newDesignSettings.Servers.Clear();

                //Add servers from UpdateServerGraphMessage
                newSettings.ThisServerName = controlMessage.ServerGraph.ThisServerName;
                foreach (var server in controlMessage.ServerGraph.Servers)
                {
                    //Settings
                    newSettings.Servers.Add(
                        new ServerInfoItem
                        {
                            Name = server.Name,
                            IpAddress = server.IpAddress,
                            Port = server.Port,
                            Adjacents = server.Adjacents
                        });
                    //Design settings
                    newDesignSettings.Servers.Add(
                        new ServerDesignItem
                        {
                            Name = server.Name,
                            Location = server.Location
                        });
                }

                //Save settings
                newSettings.SaveToXml();
                newDesignSettings.SaveToXml();
            }
            catch (Exception ex)
            {
                //Send fail message
                ReplyMessageToCommunicator(
                    communicator,
                    new OperationResultMessage {Success = false, ResultMessage = ex.Message},
                    controllerMessage
                    );
                return;
            }

            //Send success message
            ReplyMessageToCommunicator(
                communicator,
                new OperationResultMessage {Success = true, ResultMessage = "Success"},
                controllerMessage
                );
        }