コード例 #1
0
        public static void OutputVS2008(string vs2008Prj, List <VirtualDirection> target)
        {
            XmlDocument dst_doc = new XmlDocument();

            dst_doc.Load(vs2008Prj);
            XmlElement dst_root = dst_doc.DocumentElement;
            Dictionary <string, List <XmlElement> > fileConfigs = new Dictionary <string, List <XmlElement> >();
            XmlNodeList fileList = dst_root.GetElementsByTagName("File");

            foreach (XmlNode node in fileList)
            {
                XmlAttribute attr = node.Attributes["RelativePath"];
                string       n    = attr.ToString();
                foreach (XmlNode cn in node.ChildNodes)
                {
                    if (cn.Name == "FileConfiguration")
                    {
                        if (!fileConfigs.ContainsKey(n))
                        {
                            fileConfigs[n] = new List <XmlElement>();
                        }
                        fileConfigs[n].Add(cn as XmlElement);
                    }
                }
            }
            XmlNodeList filesRootList = dst_root.GetElementsByTagName("Files");
            XmlNode     root          = filesRootList[0];

            //////////////////////////////////////////////////////////////////////////
            //修改2008 的工程
            XmlNodeList virtualNodeList = dst_root.GetElementsByTagName("Filter");

            while (virtualNodeList.Count > 0)
            {
                XmlNode node = virtualNodeList.Item(0);
                node.ParentNode.RemoveChild(node);
            }
            foreach (VirtualDirection sub in target)
            {
                CreateVS2008XmlNode(sub, root, dst_doc, fileConfigs);
            }

            dst_doc.Save(vs2008Prj);
        }
コード例 #2
0
ファイル: core.cs プロジェクト: Haagimus/PerformanceApp
        public static void UpdateConfigs()
        {
            if (StationID != "Server") // if station ID is not server do this
            {
                XmlDocument xml = new XmlDocument();

                // Store configuration file locations to variables
                string IPAConfig  = IPA.Inst_Dir + @"\Support\configuration.xml";
                string DVRConfig  = DVR.Inst_Dir + @"\Support\configuration.xml";
                string XBCAConfig = XBCA.Inst_Dir + @"\Support\xbox_controller_app_config.xml";

                // Update IPA Configuration xml
                xml.Load(IPAConfig);
                XmlNode sensor = xml.SelectSingleNode("//Sensor[@id=\"M1\"]/IsLegacy");
                sensor.InnerText = "false";
                XmlNode identity = xml.SelectSingleNode("//Identity[@Id=\"IdentityConfig\"]/StationId");
                identity.InnerText = StationID;
                XmlNode server = xml.SelectSingleNode("//SA2S_Client[@Id=\"SA2SClientConfig\"]/LocalIp");
                server.InnerText = StationIP.ToString();
                XmlNode mapPath = xml.SelectSingleNode("//MapPath[@Id=\"MapPathConfig\"]/MapPath");
                mapPath.InnerText = @"E:\1.NAVPLAN^E:\1.World_DTED_Lv1^E:\2.NORTHCOM^E:\2_CENTCOM_OIF^E:\2_NORTHCOM_Partial^E:\3_CentCom_OEF^E:\4_JSOTFFVW^E:\4_JSOTFP^E:\6.World_TLM^E:\ForceX_AreaMaps^E:\Nashville Maps";
                // Setup IPA video config for the corresponding workstation
                if (StationID != "OP1")
                {
                    // Disable video streams one, two and three on the laptop stations
                    XmlNode vidOne = xml.SelectSingleNode("//VideoSettingsCollection/Videos[@Id=\"MTS-A VIC SD DC\"]/IsActive");
                    vidOne.InnerText = "false";
                    XmlNode vidTwo = xml.SelectSingleNode("//VideoSettingsCollection/Videos[@Id=\"MX20 VIC SD DC\"]/IsActive");
                    vidTwo.InnerText = "false";
                    XmlNode vidThree = xml.SelectSingleNode("//VideoSettingsCollection/Videos[@Id=\"MX20 VIC HD DC\"]/IsActive");
                    vidThree.InnerText = "false";
                }
                xml.Save(IPAConfig); // Save xml changes to original source file

                // Update DVR Configuration xml
                xml.Load(DVRConfig);
                server           = xml.SelectSingleNode("//SA2S_Client[@Id=\"SA2SClientConfig\"]/LocalIp");
                server.InnerText = StationIP.ToString();
                xml.Save(DVRConfig); // Save xml changes to original source file

                // Update XBCA Configuration xml
                xml.Load(XBCAConfig);
                XmlNode element = xml.SelectSingleNode("//sensor_type");
                element.InnerText = "MTS-A (Common)";
                xml.Save(XBCAConfig); // Save xml changes to original source file
            }
            else // If station ID is the server do this
            {
                XmlDocument xml = new XmlDocument();

                // Store configuration file location to variable
                string IPASConfig = IPAS.Inst_Dir + @"\Master Configs\IPAS.PRI.config.xml";
                xml.Load(IPASConfig);
                XmlNode node = xml.SelectSingleNode(@"\base_configuration\config_section\base_config_section");
                // node = xml.base_configuration.config_sections.base_config_section;
                // Create new filter node for 200NM filter
                foreach (XmlElement section in node)
                {
                    XmlAttribute attr = section.GetAttributeNode("ID");
                    if (attr.ToString() == "Filters")
                    {
                        // Add a new item to the filters base_config_section
                        XmlElement filterItem = xml.CreateElement("item");
                        filterItem.SetAttribute("type", "ForceX.Framework.sob.filters.FilterSob, ForceX.Framework, Version=2.6.0.0, Culture=neutral, PublicKeyToken=null");
                        section.AppendChild(filterItem);

                        // Add a filter node to the section_items node
                        XmlElement filter = xml.CreateElement("filter");
                        filter.SetAttribute("id", "SCG.VQ1234-200nm");
                        filterItem.AppendChild(filter);

                        // Add the following nodes to the new filter node
                        XmlElement itemId     = xml.CreateElement("ItemId");
                        XmlNode    itemIdText = xml.CreateTextNode("SCG.VQ1234");
                        itemId.AppendChild(itemIdText);
                        filter.AppendChild(itemId);

                        XmlElement customId     = xml.CreateElement("CustomId");
                        XmlNode    customIdText = xml.CreateTextNode("false");
                        customId.AppendChild(customIdText);
                        filter.AppendChild(customId);

                        XmlElement Caption = xml.CreateElement("Caption");
                        filter.AppendChild(Caption);

                        XmlElement radiusValue     = xml.CreateElement("radiusValue");
                        XmlNode    radiusValueText = xml.CreateTextNode("200");
                        radiusValue.AppendChild(radiusValueText);
                        filter.AppendChild(radiusValue);

                        XmlElement distanceUnits     = xml.CreateElement("distanceUnits");
                        XmlNode    distanceUnitsText = xml.CreateTextNode("NauticalMiles");
                        distanceUnits.AppendChild(distanceUnitsText);
                        filter.AppendChild(distanceUnits);

                        XmlElement altitudeCeiling     = xml.CreateElement("altitudeCeiling");
                        XmlNode    altitudeCeilingText = xml.CreateTextNode("50000");
                        altitudeCeiling.AppendChild(altitudeCeilingText);
                        filter.AppendChild(altitudeCeiling);

                        XmlElement altitudeFloor     = xml.CreateElement("altitudeFloor");
                        XmlNode    altitudeFloorText = xml.CreateTextNode("1000");
                        altitudeFloor.AppendChild(altitudeFloorText);
                        filter.AppendChild(altitudeFloor);

                        XmlElement sources = xml.CreateElement("sources");
                        filter.AppendChild(sources);

                        XmlElement Active     = xml.CreateElement("Active");
                        XmlNode    ActiveText = xml.CreateTextNode("false");
                        Active.AppendChild(ActiveText);
                        filter.AppendChild(Active);

                        XmlElement usedOn = xml.CreateElement("usedOn");
                        filter.AppendChild(usedOn);

                        filterItem.AppendChild(filter);

                        xml.Save(IPASConfig); // Save xml changes to original source file
                    }
                }
            }
        }
コード例 #3
0
ファイル: SetRoute.cs プロジェクト: coaxke/VPN-Route-Helper
        private string GetVPNDefaultGateway(string LocalConfigFile)
        {
            // Setup a <List> of IP addresses as we dont know how many PPP interfaces the users will have active.
            List <string> VpnIPAddresses = new List <string>();
            int           IPaddressCount = 0;

            //Loop through network interfaces present on the system (both Physical and virtual)
            foreach (NetworkInterface NetInterface in NetworkInterface.GetAllNetworkInterfaces())
            {
                //Test if Interface is a PPP adaptor (VPN Adaptor)
                if (NetInterface.NetworkInterfaceType == NetworkInterfaceType.Ppp)
                {
                    foreach (UnicastIPAddressInformation ip in NetInterface.GetIPProperties().UnicastAddresses)
                    {
                        //Test if we have an IPv4 address returned to us
                        if (ip.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                        {
                            //Add Interface to <List> and increment the count.
                            Console.WriteLine("Found potential IP an address for VPN Tunnel : {0}", ip.Address.ToString());
                            VpnIPAddresses.Add(ip.Address.ToString());
                            IPaddressCount++;
                        }
                    }
                }
            }

            Console.WriteLine("Found {0} PPP Interface IP Address(es)...", IPaddressCount.ToString());

            if (IPaddressCount < 1)
            {
                //No VPN Sessiosn found, we cannot continue.
                Console.WriteLine("VPN has not been dialed - Please Dial VPN before attempting to set static routes.");
                return(null);
            }

            XmlDocument VpnconfigDoc = new XmlDocument();

            VpnconfigDoc.Load(LocalConfigFile);
            XmlNodeList DefaultGateways = VpnconfigDoc.SelectNodes("/VPN/DefaultGateways/DefaultGateway");

            foreach (string VPNIPaddress in VpnIPAddresses)
            {
                foreach (XmlNode DefaultGateway in DefaultGateways)
                {
                    XmlAttribute VpnSubnetLower    = DefaultGateway.Attributes["VPNSubnetLower"];
                    XmlAttribute VpnSubnetUpper    = DefaultGateway.Attributes["VPNSubnetUpper"];
                    XmlAttribute DG                = DefaultGateway.Attributes["DefaultGateway"];
                    XmlAttribute SubnetDescription = DefaultGateway.Attributes["SubnetDescription"];

                    Console.WriteLine("Checking to see if assigned VPN falls inside the range {0} - {1}", VpnSubnetLower.Value.ToString(), VpnSubnetUpper.Value.ToString());

                    //Check that the address we have assigned from VPN DHCP server falls in one of the defined subnet ranges - First one wins.

                    IPAddress AssignedVPNAddress = IPAddress.Parse(VPNIPaddress);
                    IPAddress LowerVPNSubnet     = IPAddress.Parse(VpnSubnetLower.Value.ToString());
                    IPAddress UpperVPNSubnet     = IPAddress.Parse(VpnSubnetUpper.Value.ToString());

                    //Cast Lower and upper ends of subnet into Byte-arrays so we can enumerate each Octet-group
                    byte[] lowerAddressBytes = LowerVPNSubnet.GetAddressBytes();
                    byte[] upperAddressBytes = UpperVPNSubnet.GetAddressBytes();

                    //Check that we're working with two of the same IP Types (IPv4/IPv6) - If not; there's no point in continuing
                    if (AssignedVPNAddress.AddressFamily != LowerVPNSubnet.AddressFamily)
                    {
                        Console.WriteLine("Assigned VPN address does not fall in same Address Family (IPv4/IPv6).");
                        return(null);
                    }
                    else
                    {
                        if (TestIPInRange(AssignedVPNAddress, LowerVPNSubnet, UpperVPNSubnet))
                        {
                            Console.WriteLine("Assigned VPN IP Address falls inside Pre-defined range ({0}) - Setting Default Gateway to {1}", SubnetDescription.ToString(), DG.Value.ToString());
                            return(DG.Value.ToString());
                        }
                    }
                }
            }
            //Default Return
            return(null);
        }