Ejemplo n.º 1
0
        /// <summary>
        /// Gets all settings from XML file.
        /// </summary>
        private void LoadFromXml()
        {
            //Create XmlDocument object to read XML settings file
            var settingsXmlDoc = new XmlDocument();
            settingsXmlDoc.Load(FilePath);

            //Get Settings section
            var resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Settings/Setting");
            if (resultNodes == null)
            {
                return;
            }

            foreach (XmlNode node in resultNodes)
            {
                _settings[node.Attributes["Key"].Value] = node.Attributes["Value"].Value;
            }

            if (string.IsNullOrEmpty(_settings["ThisServerName"]))
            {
                throw new NGRIDException("ThisServerName is not defined.");
            }

            _thisServerName = _settings["ThisServerName"];

            //Get Servers section
            resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Servers/Server");
            if (resultNodes == null)
            {
                throw new NGRIDException("No server defined.");
            }

            foreach (XmlNode node in resultNodes)
            {
                Servers.Add(new ServerInfoItem
                                {
                                    Name = node.Attributes["Name"].Value.Trim(),
                                    IpAddress = node.Attributes["IpAddress"].Value,
                                    Port = Convert.ToInt32(node.Attributes["Port"].Value),
                                    Adjacents = node.Attributes["Adjacents"].Value
                                });
            }

            //Get Applications section
            resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Applications/Application");
            if (resultNodes != null)
            {
                //Read all application entries from xml file
                foreach (XmlNode node in resultNodes)
                {
                    var application = new ApplicationInfoItem
                    {
                        Name = node.Attributes["Name"].Value
                    };

                    //Add predefined communication channels
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        switch (childNode.Name)
                        {
                            case "Communication":
                                switch (childNode.Attributes["Type"].Value)
                                {
                                    case "WebService":
                                        var webServiceComm = new ApplicationInfoItem.CommunicationChannelInfoItem
                                        {
                                            CommunicationType = "WebService"
                                        };
                                        webServiceComm.CommunicationSettings.Add("Url", childNode.Attributes["Url"].Value);
                                        application.CommunicationChannels.Add(webServiceComm);
                                        break;
                                }

                                break;
                        }
                    }

                    Applications.Add(application);
                }
            }

            //Get Routes section
            resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Routes/Route");
            if (resultNodes != null)
            {
                //Read all route entries from xml file
                foreach (XmlNode node in resultNodes)
                {
                    var route = new RouteInfoItem
                                {
                                    Name = node.Attributes["Name"].Value,
                                    DistributionType = GetAttribute(node, "DistributionType")
                                };

                    //Read all filter entries of route from xml file
                    var filterNodes = node.SelectNodes("/NGRIDConfiguration/Routes/Route/Filters/Filter");
                    if (filterNodes != null)
                    {
                        foreach (XmlNode filterNode in filterNodes)
                        {
                            var filter = new RouteInfoItem.FilterInfoItem
                                             {
                                                 SourceServer = GetAttribute(filterNode, "SourceServer"),
                                                 SourceApplication = GetAttribute(filterNode, "SourceApplication"),
                                                 DestinationServer = GetAttribute(filterNode, "DestinationServer"),
                                                 DestinationApplication =
                                                     GetAttribute(filterNode, "DestinationApplication"),
                                                 TransmitRule = GetAttribute(filterNode, "TransmitRule")
                                             };
                            route.Filters.Add(filter);
                        }
                    }

                    //Read all destination entries of route from xml file
                    var destinationNodes = node.SelectNodes("/NGRIDConfiguration/Routes/Route/Destinations/Destination");
                    if (destinationNodes != null)
                    {
                        foreach (XmlNode destinationNode in destinationNodes)
                        {
                            var destination = new RouteInfoItem.DestinationInfoItem
                                           {
                                               Application = GetAttribute(destinationNode, "Application"),
                                               Server = GetAttribute(destinationNode, "Server"),
                                               RouteFactor = Convert.ToInt32(GetAttribute(destinationNode, "RouteFactor") ?? "1")
                                           };
                            if (destination.RouteFactor <= 0)
                            {
                                destination.RouteFactor = 1;
                            }

                            route.Destinations.Add(destination);
                        }
                    }

                    Routes.Add(route);
                }
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets all settings from XML file.
        /// </summary>
        private void LoadFromXml()
        {
            //Create XmlDocument object to read XML settings file
            var settingsXmlDoc = new XmlDocument();

            settingsXmlDoc.Load(FilePath);

            //Get Settings section
            var resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Settings/Setting");

            if (resultNodes == null)
            {
                return;
            }

            foreach (XmlNode node in resultNodes)
            {
                _settings[node.Attributes["Key"].Value] = node.Attributes["Value"].Value;
            }

            if (string.IsNullOrEmpty(_settings["ThisServerName"]))
            {
                throw new NGRIDException("ThisServerName is not defined.");
            }

            _thisServerName = _settings["ThisServerName"];

            //Get Servers section
            resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Servers/Server");
            if (resultNodes == null)
            {
                throw new NGRIDException("No server defined.");
            }

            foreach (XmlNode node in resultNodes)
            {
                Servers.Add(new ServerInfoItem
                {
                    Name      = node.Attributes["Name"].Value.Trim(),
                    IpAddress = node.Attributes["IpAddress"].Value,
                    Port      = Convert.ToInt32(node.Attributes["Port"].Value),
                    Adjacents = node.Attributes["Adjacents"].Value
                });
            }

            //Get Applications section
            resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Applications/Application");
            if (resultNodes != null)
            {
                //Read all application entries from xml file
                foreach (XmlNode node in resultNodes)
                {
                    var application = new ApplicationInfoItem
                    {
                        Name = node.Attributes["Name"].Value
                    };

                    //Add predefined communication channels
                    foreach (XmlNode childNode in node.ChildNodes)
                    {
                        switch (childNode.Name)
                        {
                        case "Communication":
                            switch (childNode.Attributes["Type"].Value)
                            {
                            case "WebService":
                                var webServiceComm = new ApplicationInfoItem.CommunicationChannelInfoItem
                                {
                                    CommunicationType = "WebService"
                                };
                                webServiceComm.CommunicationSettings.Add("Url", childNode.Attributes["Url"].Value);
                                application.CommunicationChannels.Add(webServiceComm);
                                break;
                            }

                            break;
                        }
                    }

                    Applications.Add(application);
                }
            }

            //Get Routes section
            resultNodes = settingsXmlDoc.SelectNodes("/NGRIDConfiguration/Routes/Route");
            if (resultNodes != null)
            {
                //Read all route entries from xml file
                foreach (XmlNode node in resultNodes)
                {
                    var route = new RouteInfoItem
                    {
                        Name             = node.Attributes["Name"].Value,
                        DistributionType = GetAttribute(node, "DistributionType")
                    };

                    //Read all filter entries of route from xml file
                    var filterNodes = node.SelectNodes("/NGRIDConfiguration/Routes/Route/Filters/Filter");
                    if (filterNodes != null)
                    {
                        foreach (XmlNode filterNode in filterNodes)
                        {
                            var filter = new RouteInfoItem.FilterInfoItem
                            {
                                SourceServer           = GetAttribute(filterNode, "SourceServer"),
                                SourceApplication      = GetAttribute(filterNode, "SourceApplication"),
                                DestinationServer      = GetAttribute(filterNode, "DestinationServer"),
                                DestinationApplication =
                                    GetAttribute(filterNode, "DestinationApplication"),
                                TransmitRule = GetAttribute(filterNode, "TransmitRule")
                            };
                            route.Filters.Add(filter);
                        }
                    }

                    //Read all destination entries of route from xml file
                    var destinationNodes = node.SelectNodes("/NGRIDConfiguration/Routes/Route/Destinations/Destination");
                    if (destinationNodes != null)
                    {
                        foreach (XmlNode destinationNode in destinationNodes)
                        {
                            var destination = new RouteInfoItem.DestinationInfoItem
                            {
                                Application = GetAttribute(destinationNode, "Application"),
                                Server      = GetAttribute(destinationNode, "Server"),
                                RouteFactor = Convert.ToInt32(GetAttribute(destinationNode, "RouteFactor") ?? "1")
                            };
                            if (destination.RouteFactor <= 0)
                            {
                                destination.RouteFactor = 1;
                            }

                            route.Destinations.Add(destination);
                        }
                    }

                    Routes.Add(route);
                }
            }
        }