Ejemplo n.º 1
0
 /// <summary>
 /// Creates a new NGRIDController object.
 /// </summary>
 /// <param name="name">Name of the controller</param>
 public NGRIDController(string name)
     : base(name, CommunicationLayer.CreateApplicationId())
 {
     _settings = NGRIDSettings.Instance;
     //_designSettings = NGRIDDesignSettings.Instance;
     MessageReceived += NGRIDController_MessageReceived;
 }
Ejemplo n.º 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">NGRIDControllerMessage object that includes controlMessage</param>
        private void ProcessUpdateServerGraphMessage(ICommunicator communicator, UpdateServerGraphMessage controlMessage, NGRIDControllerMessage controllerMessage)
        {
            try
            {
                var newSettings = new NGRIDSettings(Path.Combine(GeneralHelper.GetCurrentDirectory(), "NGRIDSettings.xml"));
                //var newDesignSettings = new NGRIDDesignSettings(Path.Combine(GeneralHelper.GetCurrentDirectory(), "NGRIDSettings.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
                );
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public NGRIDServer()
 {
     _settings                       = NGRIDSettings.Instance;
     _serverGraph                    = new NGRIDServerGraph();
     _clientApplicationList          = new NGRIDClientApplicationList();
     _ngridManager                   = new NGRIDController("NGRIDController");
     _storageManager                 = StorageManagerFactory.CreateStorageManager();
     _routingTable                   = new RoutingTable();
     _communicationLayer             = new CommunicationLayer();
     _organizationLayer              = new OrganizationLayer(_communicationLayer, _storageManager, _routingTable, _serverGraph, _clientApplicationList, _ngridManager);
     _ngridManager.OrganizationLayer = _organizationLayer;
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Constructor.
 /// </summary>
 /// <param name="communicationLayer">Reference to the Communication Layer</param>
 /// <param name="storageManager">Reference to the Storage Manager</param>
 /// <param name="routingTable">Reference to the routing table</param>
 /// <param name="serverGraph">Reference to server graph</param>
 /// <param name="clientApplicationList">Reference to application list</param>
 /// <param name="ngridManager">Reference to NGRID Manager object</param>
 public OrganizationLayer(CommunicationLayer communicationLayer, IStorageManager storageManager, RoutingTable routingTable, NGRIDServerGraph serverGraph, NGRIDClientApplicationList clientApplicationList, NGRIDController ngridManager)
 {
     _settings              = NGRIDSettings.Instance;
     _communicationLayer    = communicationLayer;
     _storageManager        = storageManager;
     _routingTable          = routingTable;
     _serverGraph           = serverGraph;
     _clientApplicationList = clientApplicationList;
     _ngridManager          = ngridManager;
     _waitingMessages       = new SortedList <string, WaitingMessage>();
     PrepareCommunicationLayer();
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public CommunicationLayer()
        {
            _settings              = NGRIDSettings.Instance;
            _remoteApplications    = new SortedList <int, NGRIDRemoteApplication>();
            _communicators         = new SortedList <long, ICommunicator>();
            _communicationManagers =
                new List <ICommunicationManager>
            {
                new TCPCommunicationManager(Convert.ToInt32(_settings["__ThisServerTCPPort"].Trim()))
            };

            foreach (var manager in _communicationManagers)
            {
                manager.CommunicatorConnected += Manager_CommunicatorConnected;
            }
        }
 /// <summary>
 /// Contructor. Gets applications from given settings file.
 /// </summary>
 public NGRIDClientApplicationList()
 {
     _settings    = NGRIDSettings.Instance;
     Applications = new SortedList <string, NGRIDClientApplication>();
     try
     {
         CreateApplicationList();
     }
     catch (NGRIDException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new NGRIDException("Can not read settings file.", ex);
     }
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Contructor.
 /// </summary>
 public NGRIDServerGraph()
 {
     _settings       = NGRIDSettings.Instance;
     ServerNodes     = new SortedList <string, NGRIDServerNode>();
     AdjacentServers = new SortedList <string, NGRIDAdjacentServer>();
     _pingTimer      = new Timer(PingTimer_Elapsed, null, Timeout.Infinite, Timeout.Infinite);
     try
     {
         CreateGraph();
     }
     catch (NGRIDException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new NGRIDException("Can not read settings file. Detail: " + ex.Message, ex);
     }
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Creates a new RoutingTable object.
 /// </summary>
 public RoutingTable()
 {
     _settings = NGRIDSettings.Instance;
     Rules     = new List <RoutingRule>();
     CreateRuleList();
 }