/// <summary>
 /// Writes the configuration of this handler in the given environment to the given XmlWriter.
 /// </summary>
 /// <param name="xmlWriter">The XmlWriter to writes the configuration to.</param>
 public void SaveConfiguration(XmlWriter xmlWriter)
 {
     if (ConfigurationWriter != null)
     {
         ConfigurationWriter.SaveConfiguration(xmlWriter, Environment);
     }
 }
        public void WriteConfigurationFile()
        {
            var configuration = new ConfigurationWriter(this);

            configuration.Validate();
            configuration.Save();
        }
        public void EnableMaintenanceMode()
        {
            var configWriter = new ConfigurationWriter(this);

            configWriter.EnableMaintenanceMode();
            InMaintenanceMode = true;
        }
예제 #4
0
        public void Can_Write_Recursive_Class_To_File()
        {
            var dict = new Dictionary <string, string>
            {
                { "Item", "TEST_VAL_ITEM" },
                { "SubItem_Item", "TEST_VAL_SUBITEM_ITEM" },
                { "SubItem_SubSubItem_Item", "TEST_VAL_SUBITEM_SUBSUBITEM_ITEM" },
                { "SubItem_SubSubItem_Bool", "true" },
                { "SubItem_SubSubItem_Int", "10" },
                { "SubItem_SubSubItem_Long", "10000000" },
                { "SubItem_SubSubItem_Double", "2.2" },
                { "SubItem_SubSubItem_Float", "2.22" }
            };

            // Set the environment variables we're going to use.
            EnvironmentVariableSource.SetEnvironment(dict);

            var parsed = ConfigurationParser.ParseConfiguration <TestClass>();

            ConfigurationWriter.WriteToFile(parsed, "cwrctf.txt", true);

            // Read in that file.
            var instance = ConfigurationParser.Parse <TestClass>("cwrctf.txt");

            Assert.Equal("TEST_VAL_ITEM", instance.Item);
            Assert.Equal("TEST_VAL_SUBITEM_ITEM", instance?.SubItem?.Item);
            Assert.Equal("TEST_VAL_SUBITEM_SUBSUBITEM_ITEM", instance?.SubItem?.SubSubItem?.Item);
            Assert.True(instance?.SubItem?.SubSubItem?.Bool);
            Assert.Equal(10, instance?.SubItem?.SubSubItem?.Int);
            Assert.Equal(10000000, instance?.SubItem?.SubSubItem?.Long);
            Assert.Equal(2.2D, instance?.SubItem?.SubSubItem?.Double);
            Assert.Equal(2.22F, instance?.SubItem?.SubSubItem?.Float);
        }
예제 #5
0
        public void CanRoundtrip()
        {
            var original = new RequestedConfiguration
            {
                BlockRules =
                {
                    new BlockRule {
                        BlockName = "Ore", Include = false
                    },
                },
                Displays =
                {
                    new RequestedDisplayConfiguration
                    {
                        DisplayName       = "Components",
                        IncludeCategories ={ "Components"                         },
                    },
                    new RequestedDisplayConfiguration
                    {
                        DisplayName       = "Hydrogen",
                        IncludeCategories ={ "Hydrogen"                           },
                    },
                },
            };

            var serialised   = new ConfigurationWriter().Serialise(original);
            var roundtripped = new ConfigurationReader().Deserialise(serialised);

            Assert.Multiple(() =>
            {
                Assert.That(roundtripped.BlockRules, Is.EquivalentTo(original.BlockRules));
                Assert.That(roundtripped.Displays, Is.EquivalentTo(original.Displays).Using(new RequestedDisplayConfigurationEqualityComparer()));
            });
        }
        public void DisableMaintenanceMode()
        {
            var configWriter = new ConfigurationWriter(this);

            configWriter.DisableMaintenanceMode();
            InMaintenanceMode = false;
        }
예제 #7
0
        public void SetDefaultProject(int projectid)
        {
            ConfigurationWriter configurationWriter = new ConfigurationWriter();

            configurationWriter.AddOrUpdateAppSetting <int>(Constants.DEFAULT_PROJECTID, projectid);

            Console.WriteLine("Default Project was successfuly set.", ConsoleColor.Green);
        }
예제 #8
0
        public void Can_Default_All_Types()
        {
            var parsed = ConfigurationParser.ParseConfiguration <AllDefaultTestsClass>();

            ConfigurationWriter.WriteToFile(parsed, "cdat.txt", true);

            Assert.Equal(4, parsed.IntDefault);
        }
예제 #9
0
 /// <summary>
 /// Persists the changes to the given configuration file.
 /// </summary>
 /// <param name="configurationFile">The configuration file to which changes should be persisted.</param>
 /// <param name="profileService">The profile service.</param>
 private static void PersistChanges(string configurationFile, ProfileService profileService)
 {
     using (Stream fileStream = File.Open(configurationFile, FileMode.Truncate, FileAccess.Write))
     {
         var configurationWriter = new ConfigurationWriter(profileService);
         configurationWriter.WriteConfiguration(fileStream);
     }
 }
예제 #10
0
        /// <summary>
        /// Saves the configuration to a binary file, using a specific <see cref="BinaryWriter"/>.
        /// </summary>
        public void SaveToBinaryStream(Stream stream, BinaryWriter writer)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            ConfigurationWriter.WriteToStreamBinary(this, stream, writer);
        }
예제 #11
0
        /// <summary>
        /// Saves the configuration to a stream.
        /// </summary>
        public void SaveToStream(Stream stream, Encoding encoding)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }

            ConfigurationWriter.WriteToStreamTextual(this, stream, encoding);
        }
예제 #12
0
 public Settings(SerialPort Port, ConfigurationReader ConfigurationReader, ConfigurationWriter ConfigurationWriter, ModuleConfiguration ModuleConfiguration, LocalServerConfiguration ServerConfiguration)
 {
     InitializeComponent();
     _SerialPort          = Port;
     _ModuleConfiguration = ModuleConfiguration;
     _ConfigurationReader = ConfigurationReader;
     _ConfigurationWriter = ConfigurationWriter;
     _ServerConfiguration = ServerConfiguration;
 }
예제 #13
0
 public List <ConfigurationSetting> ServerSettings(string settingName, object value, ref object message)
 {
     message = Resources.RestartedSettings;
     if (settingName != null)
     {
         ConfigurationWriter.WriteApplicationSetting(settingName, value);
         return(ConfigurationSetting.FindAllSettings());
     }
     return(ConfigurationSetting.FindAllSettings(true));
 }
예제 #14
0
        public IActionResult ChangeKey(ApiKeyItem item)
        {
            var hashedKey = KeyHash.GetStringSha256Hash(item.ApiKey);
            var result    = ConfigurationWriter.AddOrUpdateAppSetting("ApiKey", hashedKey);

            if (!result.Success)
            {
                return(NotFound(new StatusMessageResponse <ApiKeyItem>(item, "Failed to write to configuration file")));
            }

            return(Ok(new StatusMessageResponse <ApiKeyItem>(item, "Successfully changed Api Key. Please restart the Webserver for the changes to take affect.")));
        }
        public ConfigurationService()
        {
            var configDir = "";
            if (File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "configuration.xml")))
                configDir = Path.Combine(Directory.GetCurrentDirectory());
            else
                configDir = Path.Combine(Directory.GetCurrentDirectory(), "..", "..", "Config");

            _configurationReader = new ConfigurationReader(configDir);
            _configurationWriter = new ConfigurationWriter(configDir);

        }
예제 #16
0
        public void Can_Set_Default_Value()
        {
            var parsed = ConfigurationParser.ParseConfiguration <DefaultValueClass>();

            ConfigurationWriter.WriteToFile(parsed, "csdv.txt", true);

            // Read in that file.
            var instance = ConfigurationParser.Parse <DefaultValueClass>("csdv.txt");

            Assert.True(instance.HasDefault);
            Assert.False(instance.DoesNotHaveDefault);
        }
예제 #17
0
        public void Can_Convert_Weird_Value_Types()
        {
            var parsed = ConfigurationParser.ParseConfiguration <DefaultValueWeirdTypesClass>();

            ConfigurationWriter.WriteToFile(parsed, "ccwvt.txt", true);

            // Read in that file.
            var instance = ConfigurationParser.Parse <DefaultValueWeirdTypesClass>("ccwvt.txt");

            Assert.True(instance.HasDefault);
            Assert.True(instance.DoesNotHaveDefault);
        }
예제 #18
0
        public void Can_Read_And_Write_And_Parse_Enums()
        {
            var config = new EnumClass
            {
                Enum = TestEnum.Item2,
            };

            ConfigurationWriter.WriteToFile(config, "crawape.txt", true);

            var configParsed = ConfigurationParser.Parse <EnumClass>("crawape.txt");

            Assert.Equal(TestEnum.Item2, configParsed.Enum);
        }
예제 #19
0
    public void Save(XmlWriter xmlWriter, string sectionName)
    {
        Assert.IsNotNull(xmlWriter);
        Assert.IsNotNull(sectionName);

        xmlWriter.WriteStartElement(sectionName);
        ConfigurationWriter.Write(xmlWriter, RootNode.Attributes);

        foreach (var childNode in RootNode.ChildNodes)
        {
            ConfigurationWriter.WriteNode(xmlWriter, childNode);
        }

        xmlWriter.WriteEndElement();
    }
예제 #20
0
        public void ConfigWriterTest()
        {
            //Arrange
            var builder                = new Mock <IConfigurationBuilder>();
            var protocolInfo           = new Mock <IProtocolInfo>();
            var confReader             = new Mock <IConfigurationReader>();
            ConfigurationWriter writer = new ConfigurationWriter("hosts.json", builder.Object, protocolInfo.Object, confReader.Object);

            //Act
            var saveResult   = writer.RemoveFromConfig(-1);
            var removeResult = writer.SaveInConfig(new [] { "" });

            //Assert
            Assert.IsFalse(saveResult);
            Assert.IsFalse(removeResult);
        }
예제 #21
0
        private void Copy_Click(object sender, EventArgs e)
        {
            var stringWriter  = new StringWriter();
            var xmlTextWriter = new XmlTextWriter(stringWriter)
            {
                Formatting = Formatting.Indented
            };

            foreach (var node in SelectedConfigurationNodes)
            {
                ConfigurationWriter.WriteNode(xmlTextWriter, node);
            }

            var s = stringWriter.ToString();

            Clipboard.SetText(s);
        }
        public void RestoreAppConfig(string sourcePath)
        {
            if (sourcePath == null)
            {
                return;
            }
            var configFile = $"{Service.ExePath}.config";

            File.Copy(sourcePath, configFile, true);

            // Ensure Transport type is correct and populate the config with common settings even if they are defaults
            // Will not clobber other settings in the config
            var configWriter = new ConfigurationWriter(this);

            configWriter.Validate();
            configWriter.Save();
        }
예제 #23
0
        private void Copy_Click(object sender, EventArgs e)
        {
            var stringWriter  = new StringWriter();
            var xmlTextWriter = new XmlTextWriter(stringWriter);

            xmlTextWriter.Formatting = Formatting.Indented;

            foreach (var node in SelectedConfigurationNodes)
            {
                var connectionProperties = new ConnectionProperties();
                connectionProperties.Load(node);
                ConfigurationWriter.WriteNode(xmlTextWriter, node);
            }

            var s = stringWriter.ToString();

            Clipboard.SetText(s);
        }
예제 #24
0
        public void Can_Encrypt_And_Decrypt_Text()
        {
            var item = new EncryptedClass
            {
                Item1 = "Test string",
                Item2 = 65535,
                Item3 = true
            };

            var writer         = new ConfigurationWriter();
            var encryptHandler = new Func <string, string, string>((name, value) =>
            {
                return(name switch
                {
                    "Item1" => "xxxxx",
                    "Item2" => "11111",
                    "Item3" => "tralse",
                    _ => throw new ArgumentOutOfRangeException(nameof(name), name, null)
                });
            });
예제 #25
0
        public MainWindow()
        {
            InitializeComponent();

            _SerialPort          = new SerialPort();
            _ModuleConfiguration = new ModuleConfiguration();
            _CommandProcessor    = new CommandProcessingService(_SerialPort);
            _ConfigurationReader = new ConfigurationReader(_CommandProcessor, _ModuleConfiguration);
            _ConfigurationWriter = new ConfigurationWriter(_CommandProcessor, _ModuleConfiguration);
            _ServerConfiguration = new LocalServerConfiguration();

            SettingsPage       = new Settings(_SerialPort, _ConfigurationReader, _ConfigurationWriter, _ModuleConfiguration, _ServerConfiguration);
            BasicSetupPage     = new BasicSetup(_CommandProcessor, _ModuleConfiguration);
            WiFiSetupPage      = new WiFiSetup(_CommandProcessor, _ModuleConfiguration);
            TCPIPSetupPage     = new TCPUDPSettings(_CommandProcessor, _ModuleConfiguration);
            DataLoggerPage     = new DataLogging(_ServerConfiguration);
            RemoteTerminalPage = new RemoteTerminal(_ServerConfiguration);

            SettingsListViewItem.IsSelected = true;
        }
예제 #26
0
        public void Can_Write_To_File()
        {
            var dict = new Dictionary <string, string>
            {
                { "Test", "20" },
                { "TestBool", "true" }
            };

            EnvironmentVariableSource.SetEnvironment(dict);
            EnvironmentVariableRepository.SetConfigurationType(ConfigurationTypeEnum.PreferEnvironment);
            var output = ConfigurationParser.Parse <NullableClass>(EnvironmentVariableRepository);

            ConfigurationWriter.WriteToFile(output, "cwtf.txt", true);

            // Read in that file.
            var parsedConfig = ConfigurationParser.Parse <NullableClass>("cwtf.txt");

            Assert.Equal(20, parsedConfig.Test);
            Assert.True(parsedConfig.TestBool);
        }
예제 #27
0
        public void CanRoundtrip()
        {
            var original = new RequestedConfiguration
            {
                Ingots =
                {
                    [new ItemType("Ingot/Iron")] = new RequestedIngotConfiguration     {
                        Enable = true, StockpileTarget = 500, StockpileLimit = 1000
                    },
                    [new ItemType("Ingot/Platinum")] = new RequestedIngotConfiguration {
                        Enable = false, StockpileLimit = 200
                    },
                    [new ItemType("Ore/Test")] = new RequestedIngotConfiguration       {
                        Enable = true, StockpileTarget = 700
                    },
                },
                InventoryBlockNames =
                {
                    "Storage",
                    "Buffer",
                },
                OreStatusDisplayName   = "Status: \"Ore\"",
                IngotStatusDisplayName = "IngotStatus",
                RefinerySpeedFactor    = 5,
                AssemblerSpeedFactor   = 4,
            };

            var serialised   = new ConfigurationWriter().Serialise(original);
            var roundtripped = new ConfigurationReader().Deserialise(serialised);

            Assert.Multiple(() =>
            {
                Assert.That(roundtripped.Ingots, Is.EquivalentTo(original.Ingots).Using(new RequestedIngotConfigurationEqualityComparer()));
                Assert.That(roundtripped.InventoryBlockNames, Is.EquivalentTo(original.InventoryBlockNames));
                Assert.That(roundtripped.OreStatusDisplayName, Is.EqualTo(original.OreStatusDisplayName));
                Assert.That(roundtripped.IngotStatusDisplayName, Is.EqualTo(original.IngotStatusDisplayName));
                Assert.That(roundtripped.RefinerySpeedFactor, Is.EqualTo(original.RefinerySpeedFactor));
                Assert.That(roundtripped.AssemblerSpeedFactor, Is.EqualTo(original.AssemblerSpeedFactor));
            });
        }
        private List <string> GenerateConfigurationFiles()
        {
            List <string> files = new List <string>();

            var ds = dataGridView.DataSource as List <GseControlSelection>;

            var selections = ds.Where(x => x.Selected == true).ToList();

            // any selection?
            if (selections.Count == 0)
            {
                MessageBox.Show("Please select at least one GOOSE Control Block.", Program.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(files);
            }
            else
            {
                // selected profile?
                foreach (var gse in selections)
                {
                    if (string.IsNullOrWhiteSpace(gse.Direction))
                    {
                        MessageBox.Show($"Please select either Publish or Subscribe. [{gse.Name}]", Program.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return(files);
                    }

                    if (string.IsNullOrWhiteSpace(gse.Profile))
                    {
                        MessageBox.Show($"Please select OpenFMB profile to map. [{gse.Name}]", Program.AppName, MessageBoxButtons.OK, MessageBoxIcon.Information);
                        return(files);
                    }
                }

                // Everything is ok
                ConfigurationWriter writer = new ConfigurationWriter();
                files.AddRange(writer.WriteGooseConfigurationFiles(selections, "adapter"));
            }

            return(files);
        }
예제 #29
0
 public void SaveSetting(string configFile, string settingName, object value, bool isConnection)
 {
     ConfigurationWriter.WriteApplicationSetting(configFile, settingName, value, isConnection);
 }
예제 #30
0
 private void SetUpMock()
 {
     configurationWriter = mock.StrictMock<ConfigurationWriter>();
 }
 private void writeProfileDotConfigFile()
 {
     new FileSystem().CleanDirectory(_deployedFolderProfilePath);
     var writer = new ConfigurationWriter();
     writer.Write(Path.Combine(_deployedFolderProfilePath, "Profile.config"), _theProfile);
 }
 private void SetUpMock()
 {
     configurationWriter = mock.StrictMock <ConfigurationWriter>();
 }