コード例 #1
0
        // POST api/SystemDefaultsValues
        public HttpResponseMessage PostValue(DefaultValues[] values)
        {
            HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);

            base.SetParamsAndSettings();
            ConfigurationModel model           = new ConfigurationModel(settings);
            string             result          = string.Empty;
            List <RequestData> requestDataList = GetRequestDataList(values);

            model.Initialise(requestDataList);
            bool isValid = model.Validate();

            if (isValid)
            {
                model.Save();
                model.Initialise();
            }
            else
            {
                model.SetTabWithErrorActive();
            }
            if (model.RedirectURL == string.Empty)
            {
                result = ViewRenderer.RenderView("~/Views/SystemDefaults/Configuration.cshtml", model, null);
            }
            else
            {
                result = "returnURL=" + model.RedirectURL;
            }
            response.Content = new StringContent(result);
            response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/html");
            return(response);
        }
コード例 #2
0
        public void SingleFeatureNoOptionsAddsFeature()
        {
            var simpleScript =
                @"// Fills in details for download packages automatically.
				// This instance created AUTOMATICALLY during a previous run.
				function AutomatePackages()
				{
					SetElement(""FlavorName1"", ""NAME"");
					SetElement(""FlavorUrl1"", ""URL"");
					NextStage();
					NextStage();
				}"                ;
            var configuration = new ConfigurationModel();
            var scriptFile    = Path.Combine(TestFolder, "test.js");
            var installerFile = Path.Combine(TestFolder, "installer.xml");

            File.WriteAllText(scriptFile, simpleScript);
            configuration.FileLocation = installerFile;
            configuration.Save();
            JavaScriptConverter.ConvertJsToXml(scriptFile, installerFile);
            var serializer = new XmlSerializer(typeof(ConfigurationModel));

            using (var textReader = new StreamReader(installerFile))
            {
                var model = (ConfigurationModel)serializer.Deserialize(textReader);
                Assert.That(model.Flavors, Is.Not.Null);
                Assert.That(model.Flavors.Count, Is.EqualTo(1));
                Assert.That(model.Flavors.First().FlavorName, Is.EqualTo("NAME"));
                Assert.That(model.Flavors.First().DownloadURL, Is.EqualTo("URL"));
            }
        }
コード例 #3
0
 public void ExistingFeatureInModelIsNotDuplicated()
 {
     var simpleScript =
         @"// Fills in details for download packages automatically.
         // This instance created AUTOMATICALLY during a previous run.
         function AutomatePackages()
         {
             SetElement(""FlavorName1"", ""NAME"");
             SetElement(""FlavorUrl1"", ""URL"");
             NextStage();
             NextStage();
         }";
     var configuration = new ConfigurationModel();
     configuration.Flavors = new List<ConfigurationModel.FlavorOptions> { new ConfigurationModel.FlavorOptions { FlavorName = "NAME"}};
     var scriptFile = Path.Combine(TestFolder, "test.js");
     var installerFile = Path.Combine(TestFolder, "installer.xml");
     File.WriteAllText(scriptFile, simpleScript);
     configuration.FileLocation = installerFile;
     configuration.Save();
     JavaScriptConverter.ConvertJsToXml(scriptFile, installerFile);
     var serializer = new XmlSerializer(typeof(ConfigurationModel));
     using (var textReader = new StreamReader(installerFile))
     {
         var model = (ConfigurationModel)serializer.Deserialize(textReader);
         Assert.That(model.Flavors, Is.Not.Null);
         Assert.That(model.Flavors.Count, Is.EqualTo(1));
         Assert.That(model.Flavors.First().FlavorName, Is.EqualTo("NAME"));
         Assert.That(model.Flavors.First().DownloadURL, Is.EqualTo("URL"));
     }
 }
コード例 #4
0
 public void Close()
 {
     model.Workload          = view.Workload;
     model.Tolerance         = view.Tolerance;
     model.Subtract          = view.Subtract;
     model.SubtractCondition = view.SubtractCondition;
     model.SubtractQuantity  = view.SubtractQuantity;
     model.Warn          = view.Warn;
     model.WarnCondition = view.WarnCondition;
     model.Startup       = view.Startup;
     model.Save();
 }
コード例 #5
0
        public void Save()
        {
            try
            {
                model.Save();

                //signal about changes to all who might be interested
                eventAggregator.PublishOnBackgroundThread(new AppEvent
                {
                    Type = Constants.ConfigurationChangedMessage
                });
            }
            catch (Exception e)
            {
                MessageBox.Show($"Failed to save configuration. Reason : {e}", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            MessageBox.Show("Saved configuration.", "Message", MessageBoxButton.OK, MessageBoxImage.Information);
        }
コード例 #6
0
        public void TestTasksConversion()
        {
            var flavorName1 = "flavorA";
            var url1 = "http://a.com";
            var outputPath = "D:/Test";
            var sfxStyle = "Hmm";
            var complexScript =
                @"// Fills in details for download packages automatically.
                // This instance created AUTOMATICALLY during a previous run.
                function AutomatePackages()
                {
                " +
                string.Format(@"SetElement(""FlavorName1"", ""{0}"");
                    SetElement(""FlavorUrl1"", ""{1}"");
                    NextStage();
                    SelectElement(""IncludedF1P1"", true);
                    NextStage();

                    SetElement(""OutputPath"", ""{2}"");
                    SelectElement(""WriteXml"", true);
                    SelectElement(""WriteDownloadsXml"", true);
                    SelectElement(""Compile"", true);
                    SelectElement(""GatherFiles"", true);
                    SelectElement(""BuildSfx"", true);
                    SetElement(""SfxStyle"", ""{3}"");
                    SetElement(""SaveSettings"", true);", flavorName1, url1, outputPath, sfxStyle) +
                @"
                }";

            var configuration = new ConfigurationModel();
            configuration.Products = new List<ConfigurationModel.Product>();
            var mainProduct = "Main Product";
            configuration.Products.Add(new ConfigurationModel.Product {Title = mainProduct});
            var scriptFile = Path.Combine(TestFolder, "test.js");
            var installerFile = Path.Combine(TestFolder, "installer.xml");
            File.WriteAllText(scriptFile, complexScript);
            configuration.Tasks = new ConfigurationModel.TasksToExecuteSettings();
            configuration.FileLocation = installerFile;
            configuration.Save();
            // Prove that values started as false
            Assert.That(configuration.Tasks.BuildSelfExtractingDownloadPackage, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.Compile, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.GatherFiles, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.WriteDownloadsXml, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.WriteInstallerXml, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.RememberSettings, Is.False, "Setup did not initiate values to false, test invalid");
            // SUT
            JavaScriptConverter.ConvertJsToXml(scriptFile, installerFile);
            var serializer = new XmlSerializer(typeof (ConfigurationModel));
            using (var textReader = new StreamReader(installerFile))
            {
                var model = (ConfigurationModel) serializer.Deserialize(textReader);
                Assert.That(model.Tasks.OutputFolder, Is.EqualTo(outputPath));
                Assert.That(model.Tasks.BuildSelfExtractingDownloadPackage, Is.True);
                Assert.That(model.Tasks.Compile, Is.True);
                Assert.That(model.Tasks.GatherFiles, Is.True);
                Assert.That(model.Tasks.WriteDownloadsXml, Is.True);
                Assert.That(model.Tasks.WriteInstallerXml, Is.True);
                Assert.That(model.Tasks.RememberSettings, Is.True);
            }
        }
コード例 #7
0
        public void TestFeatureProductSelection()
        {
            var flavorName1 = "flavorA";
            var flavorName2 = "flavorB";
            var url1 = "http://a.com";
            var url2 = "http://b.com";
            var complexScript =
                @"// Fills in details for download packages automatically.
                // This instance created AUTOMATICALLY during a previous run.
                function AutomatePackages()
                {
                " +
                string.Format(@"SetElement(""FlavorName1"", ""{0}"");
                    SetElement(""FlavorUrl1"", ""{1}"");
                    AddFlavor();
                    SetElement(""FlavorName2"", ""{2}"");
                    SetElement(""FlavorUrl2"", ""{3}"");

                    NextStage();

                    SelectElement(""IncludedF1P1"", true);
                    SelectElement(""IncludedF1P2"", false);

                    SelectElement(""IncludedF2P1"", false);
                    SelectElement(""IncludedF2P2"", true);

                    NextStage();", flavorName1, url1, flavorName2, url2) +
                    @"
                }";

            var configuration = new ConfigurationModel();
            // The configuration needs to have 2 Products for the given JavaScript
            configuration.Products = new List<ConfigurationModel.Product>();
            var mainProduct = "Main Product";
            configuration.Products.Add(new ConfigurationModel.Product { Title = mainProduct });
            var dependency = "Dependency";
            configuration.Products.Add(new ConfigurationModel.Product { Title = dependency });
            var scriptFile = Path.Combine(TestFolder, "test.js");
            var installerFile = Path.Combine(TestFolder, "installer.xml");
            File.WriteAllText(scriptFile, complexScript);
            configuration.FileLocation = installerFile;
            configuration.Save();
            JavaScriptConverter.ConvertJsToXml(scriptFile, installerFile);
            var serializer = new XmlSerializer(typeof(ConfigurationModel));
            using (var textReader = new StreamReader(installerFile))
            {
                var model = (ConfigurationModel)serializer.Deserialize(textReader);
                Assert.That(model.Flavors, Is.Not.Null);
                Assert.That(model.Flavors.Count, Is.EqualTo(2));
                var firstFlavor = model.Flavors[0];
                var secondFlavor = model.Flavors[1];
                Assert.That(firstFlavor.FlavorName, Is.EqualTo(flavorName1));
                Assert.That(firstFlavor.DownloadURL, Is.EqualTo(url1));
                Assert.That(firstFlavor.IncludedProductTitles[0], Is.EqualTo(mainProduct));
                Assert.That(secondFlavor.FlavorName, Is.EqualTo(flavorName2));
                Assert.That(secondFlavor.DownloadURL, Is.EqualTo(url2));
                Assert.That(secondFlavor.IncludedProductTitles[0], Is.EqualTo(dependency));
            }
        }
コード例 #8
0
 private void SaveConfigurationSetting(Action<CalculatorSettings> settingsMutator)
 {
     settingsMutator?.Invoke(CalculatorSettings);
     Task.Run(() => configurationModel.Save());
 }
コード例 #9
0
        public void TestSkipConversionOnNewModel()
        {
            var flavorName1   = "flavorA";
            var url1          = "http://a.com";
            var outputPath    = "D:/Test";
            var sfxStyle      = "Hmm";
            var complexScript =
                @"// Fills in details for download packages automatically.
				// This instance created AUTOMATICALLY during a previous run.
				function AutomatePackages()
				{
				"                 +
                string.Format(@"SetElement(""FlavorName1"", ""{0}"");
					SetElement(""FlavorUrl1"", ""{1}"");
					NextStage();
					SelectElement(""IncludedF1P1"", true);
					NextStage();

					SetElement(""OutputPath"", ""{2}"");
					SelectElement(""WriteXml"", true);
					SelectElement(""WriteDownloadsXml"", true);
					SelectElement(""Compile"", true);
					SelectElement(""GatherFiles"", true);
					SelectElement(""BuildSfx"", true);
					SetElement(""SfxStyle"", ""{3}"");
					SetElement(""SaveSettings"", true);"                    , flavorName1, url1, outputPath, sfxStyle) +
                @"
				}"                ;

            var configuration = new ConfigurationModel {
                Version = "1.0"
            };

            configuration.Products = new List <ConfigurationModel.Product>();
            var mainProduct = "Main Product";

            configuration.Products.Add(new ConfigurationModel.Product {
                Title = mainProduct
            });
            var scriptFile    = Path.Combine(TestFolder, "test.js");
            var installerFile = Path.Combine(TestFolder, "installer.xml");

            File.WriteAllText(scriptFile, complexScript);
            configuration.Tasks        = new ConfigurationModel.TasksToExecuteSettings();
            configuration.FileLocation = installerFile;
            configuration.Save();
            // Prove that values started as false
            Assert.That(configuration.Tasks.BuildSelfExtractingDownloadPackage, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.Compile, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.GatherFiles, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.WriteDownloadsXml, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.WriteInstallerXml, Is.False, "Setup did not initiate values to false, test invalid");
            Assert.That(configuration.Tasks.RememberSettings, Is.False, "Setup did not initiate values to false, test invalid");
            // SUT
            JavaScriptConverter.ConvertJsToXml(scriptFile, installerFile);
            var serializer = new XmlSerializer(typeof(ConfigurationModel));

            using (var textReader = new StreamReader(installerFile))
            {
                var model = (ConfigurationModel)serializer.Deserialize(textReader);
                Assert.That(model.Tasks.BuildSelfExtractingDownloadPackage, Is.False);
                Assert.That(model.Tasks.Compile, Is.False);
                Assert.That(model.Tasks.GatherFiles, Is.False);
                Assert.That(model.Tasks.WriteDownloadsXml, Is.False);
                Assert.That(model.Tasks.WriteInstallerXml, Is.False);
                Assert.That(model.Tasks.RememberSettings, Is.False);
                Assert.That(model.Tasks.OutputFolder, Is.Null);
            }
        }
コード例 #10
0
        public void TestFeatureProductSelection()
        {
            var flavorName1   = "flavorA";
            var flavorName2   = "flavorB";
            var url1          = "http://a.com";
            var url2          = "http://b.com";
            var complexScript =
                @"// Fills in details for download packages automatically.
				// This instance created AUTOMATICALLY during a previous run.
				function AutomatePackages()
				{
				"                 +
                string.Format(@"SetElement(""FlavorName1"", ""{0}"");
					SetElement(""FlavorUrl1"", ""{1}"");
					AddFlavor();
					SetElement(""FlavorName2"", ""{2}"");
					SetElement(""FlavorUrl2"", ""{3}"");

					NextStage();

					SelectElement(""IncludedF1P1"", true);
					SelectElement(""IncludedF1P2"", false);

					SelectElement(""IncludedF2P1"", false);
					SelectElement(""IncludedF2P2"", true);

					NextStage();"                    , flavorName1, url1, flavorName2, url2) +
                @"
				}"                ;

            var configuration = new ConfigurationModel();

            // The configuration needs to have 2 Products for the given JavaScript
            configuration.Products = new List <ConfigurationModel.Product>();
            var mainProduct = "Main Product";

            configuration.Products.Add(new ConfigurationModel.Product {
                Title = mainProduct
            });
            var dependency = "Dependency";

            configuration.Products.Add(new ConfigurationModel.Product {
                Title = dependency
            });
            var scriptFile    = Path.Combine(TestFolder, "test.js");
            var installerFile = Path.Combine(TestFolder, "installer.xml");

            File.WriteAllText(scriptFile, complexScript);
            configuration.FileLocation = installerFile;
            configuration.Save();
            JavaScriptConverter.ConvertJsToXml(scriptFile, installerFile);
            var serializer = new XmlSerializer(typeof(ConfigurationModel));

            using (var textReader = new StreamReader(installerFile))
            {
                var model = (ConfigurationModel)serializer.Deserialize(textReader);
                Assert.That(model.Flavors, Is.Not.Null);
                Assert.That(model.Flavors.Count, Is.EqualTo(2));
                var firstFlavor  = model.Flavors[0];
                var secondFlavor = model.Flavors[1];
                Assert.That(firstFlavor.FlavorName, Is.EqualTo(flavorName1));
                Assert.That(firstFlavor.DownloadURL, Is.EqualTo(url1));
                Assert.That(firstFlavor.IncludedProductTitles[0], Is.EqualTo(mainProduct));
                Assert.That(secondFlavor.FlavorName, Is.EqualTo(flavorName2));
                Assert.That(secondFlavor.DownloadURL, Is.EqualTo(url2));
                Assert.That(secondFlavor.IncludedProductTitles[0], Is.EqualTo(dependency));
            }
        }