Example #1
0
        public void FixtureSetUp()
        {
            htmlEngine = new HtmlEngine();
            xmlEngine  = new XmlEngine();

            configuration = new DefaultConfiguration();
        }
Example #2
0
        private async Task <bool> CheckForUpdates()
        {
            bool   success = true;
            string xmlUrl  = "";

            string[] encodedXML = Assembly.GetExecutingAssembly().ManifestModule.Name.Split('_');
            if (Program.Arguments.Length == 1)
            {
                Logger.Log("XML passed via CLI.");
                xmlUrl = Program.Arguments[0];
            }
            else if (encodedXML.Length == 2)
            {
                Logger.Log("XML passed via module name.");
                xmlUrl = Encoding.UTF8.GetString(Convert.FromBase64String(encodedXML[1].Replace(".exe", "")));
            }
            else
            {
                Logger.Log("XML path has not been passed to Super Update!", LogLevels.Exception);
                return(false);
            }
            success = await XmlEngine.ReadXML(xmlUrl);

            if (!success)
            {
                return(success);
            }
            success = await UpdateEngine.DetectUpdates();

            if (!success)
            {
                return(success);
            }
            if (UpdateEngine.CurrentVersion != UpdateEngine.LatestVersion)
            {
                if (UpdateEngine.LatestVersion.Attributes["UpdateMessage"] != null)
                {
                    Logger.Log(UpdateEngine.LatestVersion.Attributes["UpdateMessage"].Value, LogLevels.Information);
                }
                else
                {
                    Logger.Log("Found new version, press \"Install\" to begin.", LogLevels.Information);
                }
            }
            else
            {
                XmlNode noUpdateMessage = XmlEngine.UpdateXML.SelectSingleNode("/SuperUpdate/Settings/MessageNoUpdate");
                if (noUpdateMessage != null)
                {
                    Logger.Log(noUpdateMessage.Attributes["Text"].Value, LogLevels.Information);
                }
                else
                {
                    Logger.Log("No updates are available.", LogLevels.Information);
                }
            }
            return(success);
        }
Example #3
0
        public void TestExcelSampleInput()
        {
            XmlEngine e = new XmlEngine();
            var network = e.XmlFileToNetwork(
                XDocument.Load("../../TestNetworks/NewSampleInputs_orig.xml")
            );

            #region Check link information
            // Rely on order to match links.
            Link[] expectedLinks = new Link[]
            {
                new Link() { Distance = 681, MaxTrains = 10, FuelAdjustment = 1 },
                new Link() { Distance = 842, MaxTrains = 2, FuelAdjustment = 1.4 },

                new Link() { Distance = 681, MaxTrains = 10, FuelAdjustment = 1 },
                new Link() { Distance = 735, MaxTrains = 8, FuelAdjustment = 1.4 },
                new Link() { Distance = 367, MaxTrains = 10, FuelAdjustment = 1 },

                new Link() { Distance = 367, MaxTrains = 10, FuelAdjustment = 1 },
                new Link() { Distance = 689, MaxTrains = 12, FuelAdjustment = 1.4 },
                new Link() { Distance = 500, MaxTrains = 16, FuelAdjustment = 1 },

                new Link() { Distance = 500, MaxTrains = 16, FuelAdjustment = 1 },
                new Link() { Distance = 773, MaxTrains = 10, FuelAdjustment = 1.2 },

                new Link() { Distance = 842, MaxTrains = 2, FuelAdjustment = 1.4 },
                new Link() { Distance = 735, MaxTrains = 8, FuelAdjustment = 1.4 },
                new Link() { Distance = 689, MaxTrains = 12, FuelAdjustment = 1.4 },
                new Link() { Distance = 773, MaxTrains = 10, FuelAdjustment = 1.2 },
            };
            int linkI = 0;
            foreach(var l in network.Links)
            {
                double actualDist = l.Distance;
                double expectedDist = expectedLinks[linkI].Distance;

                Assert.IsTrue(ApproxEqual(actualDist, expectedDist, DistanceAllowableError));

                Assert.AreEqual(l.MaxTrains, expectedLinks[linkI].MaxTrains);
                Assert.AreEqual(l.FuelAdjustment, expectedLinks[linkI].FuelAdjustment);

                linkI++;
            }
            #endregion
        }
Example #4
0
        internal static T GetObjectProperties <T>(PrtgResponse response, XmlEngine xmlEngine, ObjectProperty mandatoryProperty)
        {
            var xml  = HtmlParser.Default.GetXml(response);
            var xDoc = new XDocument(xml);

            //If the response does not contain the mandatory property, we are executing as a read only user, and
            //should return null

            var name = HtmlParser.DefaultPropertyPrefix + ObjectPropertyParser.GetObjectPropertyName(mandatoryProperty).TrimEnd('_');

            if (xDoc.Descendants(name).ToList().Count > 0)
            {
                var items = xmlEngine.DeserializeObject <T>(xDoc.CreateReader());

                return(items);
            }

            return(default(T));
        }
Example #5
0
        protected XmlStorage(string path)
        {
            SettingsPath = path;
            _engine      = new XmlEngine();

            // First set defaults. This way our settings are "resistant" to new settings - so new settings that doesn't exist in the settings file
            // gets a default value, while the old ones are overwritten.
            SetDefaults();

            // Blah blah, load the xml file and let the engine parse it out to the class structure.
            if (File.Exists(path))
            {
                _engine.Load(this, XElement.Load(path, LoadOptions.SetLineInfo));
            }
            else
            {
                // Force a save with default values. Ensure we have the file on disk for the next time we load.
                Save();
            }
        }
Example #6
0
        /// <summary>
        /// This method will check for updates in the main form and display them to the user.
        /// </summary>
        /// <returns>bool: True on success.</returns>
        private async Task <bool> CheckForUpdates()
        {
            bool         success;
            string       xmlUrl = "";
            FileStream   fs     = File.OpenRead(Process.GetCurrentProcess().MainModule.FileName);
            StreamReader sr     = new StreamReader(fs);

            fs.Seek(-2048, SeekOrigin.End);
            List <string> srLines = new List <string>();

            while (!sr.EndOfStream)
            {
                srLines.Add(await sr.ReadLineAsync());
            }
            if (
                srLines.Count >= 2 &&
                srLines[srLines.Count - 2] == "" &&
                srLines[srLines.Count - 1] != "" &&
                Uri.TryCreate(srLines[srLines.Count - 1], UriKind.RelativeOrAbsolute, out Uri uri)
                )
            {
                xmlUrl = uri.ToString();
            }
            if (Program.Arguments.Length == 1)
            {
                Logger.Log("XML passed via CLI.");
                xmlUrl = Program.Arguments[0];
            }
            else if (xmlUrl != "")
            {
                Logger.Log("XML passed via binary.");
            }
            else
            {
                Logger.Log("XML path has not been passed to Super Update!", LogLevels.Exception);
                return(false);
            }
            success = await XmlEngine.ReadXML(xmlUrl);

            if (!success)
            {
                return(success);
            }
            success = await UpdateEngine.DetectUpdates();

            if (!success)
            {
                return(success);
            }
            if (UpdateEngine.CurrentVersion != UpdateEngine.LatestVersion)
            {
                if (UpdateEngine.LatestVersion.Attributes["UpdateMessage"] != null)
                {
                    Logger.Log(UpdateEngine.LatestVersion.Attributes["UpdateMessage"].Value, LogLevels.Information);
                }
                else
                {
                    Logger.Log("Found new version, press \"Install\" to begin.", LogLevels.Information);
                }
            }
            else
            {
                XmlNode noUpdateMessage = XmlEngine.UpdateXML.SelectSingleNode("/SU:SuperUpdate/SU:Settings/SU:MessageNoUpdate", XmlEngine.XNS);
                if (noUpdateMessage != null)
                {
                    Logger.Log(noUpdateMessage.Attributes["Text"].Value, LogLevels.Information);
                }
                else
                {
                    Logger.Log("No updates are available.", LogLevels.Information);
                }
            }
            return(success);
        }
        public void TestNewExample4()
        {
            XmlEngine e = new XmlEngine();
            var network = e.XmlFileToNetwork(
                XDocument.Load("../../TestNetworks/new_example4.xml")
            );

            // Assign 1-based IDs to check against the excel documents.
            for(int i = 0; i < network.Nodes.Count; i++)
                network.Nodes.ElementAt(i).ID = i + 1;
            for(int i = 0; i < network.Links.Count; i++)
                network.Links.ElementAt(i).ID = i + 1;
            for(int i = 0; i < network.Orders.Count; i++)
                network.Orders.ElementAt(i).ID = i + 1;

            network.Optimize();

            #region Expected values
            var expectedNodeDec = TranslateToNodes(new Dictionary<string, Dictionary<string, int>>()
                {
                    {"LAX",
                        new Dictionary<string, int>(){
                            {"LAX>DEN", 560 },
                            {"LAX>PHX", 440 },
                            {"DEN>LAX", 0 },
                            {"DEN>PHX", 0 },
                            {"PHX>LAX", 0 },
                            {"PHX>DEN", 35 },
                        }
                    },
                    {"DEN",
                        new Dictionary<string, int>(){
                            {"LAX>DEN", 0 },
                            {"LAX>PHX", 0 },
                            {"DEN>LAX", 240 },
                            {"DEN>PHX", 560 },
                            {"PHX>LAX", 60 },
                            {"PHX>DEN", 0 },
                        }
                    },
                    {"PHX",
                        new Dictionary<string, int>(){
                            {"LAX>DEN", 0 },
                            {"LAX>PHX", 0 },
                            {"DEN>LAX", 0 },
                            {"DEN>PHX", 0 },
                            {"PHX>LAX", 100 },
                            {"PHX>DEN", 100 },
                        }
                    }
                }, network);
            var expectedLinkDec = TranslateToLinks(new Dictionary<string, int>()
                {
                    {"LAX>DEN", 7 },
                    {"LAX>PHX", 6 },
                    {"DEN>LAX", 3 },
                    {"DEN>PHX", 7 },
                    {"PHX>LAX", 2 },
                    {"PHX>DEN", 2 },
                }, network);
            #endregion

            OptimizationEngine oe = OptimizationEngine.getInstance();
            var optimization = oe.Optimize(network,
                new OptimizationEngine.OptimizationOptions());

            var op = optimization.ToOptimization();

            Assert.IsTrue(NodeDictionariesEqual(expectedNodeDec, optimization.flowDecisions));

            Assert.IsTrue(
                LinkDictionariesEqual(expectedLinkDec, optimization.locomotiveDecisions));

            Assert.AreEqual(9917500, optimization.totalCost);
        }
        public void TestNewNetwork()
        {
            XmlEngine e = new XmlEngine();
            var network = e.XmlFileToNetwork(
                XDocument.Load("../../TestNetworks/NewSampleInputs.xml")
            );

            // Assign 1-based IDs to maintain validity.
            for(int i = 0; i < network.Nodes.Count; i++)
                network.Nodes.ElementAt(i).ID = i + 1;
            for(int i = 0; i < network.Links.Count; i++)
                network.Links.ElementAt(i).ID = i + 1;
            for(int i = 0; i < network.Orders.Count; i++)
                network.Orders.ElementAt(i).ID = i + 1;

            OptimizationEngine oe = OptimizationEngine.getInstance();
            var optimization = oe.Optimize(network,
                new OptimizationEngine.OptimizationOptions());

            var op = optimization.ToOptimization();

            // Can't get the excel spreadsheet to agree even if I give it the optimizer's shipping
            // decisions and train numbers.
            Assert.AreEqual(3343246, optimization.totalCost);

            Assert.Inconclusive();
        }
Example #9
0
 public ObjectEngine(PrtgClient client, RequestEngine engine, IXmlSerializer xmlSerializer)
 {
     prtgClient    = client;
     requestEngine = engine;
     XmlEngine     = new XmlEngine(xmlSerializer);
 }
 public RaceImportWorker(JsonEngine jsonEngine, XmlEngine xmlEngine, IOutputService outputService)
 {
     _jsonEngine    = jsonEngine;
     _xmlEngine     = xmlEngine;
     _outputService = outputService;
 }