Write() public method

public Write ( Stream stream ) : bool
stream Stream
return bool
        public void WriteMultipleTest()
        {
            Delete();
            var configFile = new ConfigFile <Configuration>(FilePath);
            var one        = new TestConfigSection()
            {
                Value = 1
            };
            var two = new AnotherConfigSection()
            {
                Number = 2
            };

            configFile.Write(one, two);

            Assert.AreEqual(1, configFile.Read <TestConfigSection>().Value);
            Assert.AreEqual(2, configFile.Read <AnotherConfigSection>().Number);

            Delete();
            var three = new AThirdSection()
            {
                Int = 3
            };

            configFile.Write(one, two, three);

            Assert.AreEqual(1, configFile.Read <TestConfigSection>().Value);
            Assert.AreEqual(2, configFile.Read <AnotherConfigSection>().Number);
            Assert.AreEqual(3, configFile.Read <AThirdSection>().Int);
        }
Example #2
0
        /// <summary>
        /// Execute the task.
        /// </summary>
        /// <param name="Job">Information about the current job</param>
        /// <param name="BuildProducts">Set of build products produced by this node.</param>
        /// <param name="TagNameToFileSet">Mapping from tag names to the set of files they include</param>
        public override void Execute(JobContext Job, HashSet <FileReference> BuildProducts, Dictionary <string, HashSet <FileReference> > TagNameToFileSet)
        {
            FileReference ConfigFileLocation = ResolveFile(Parameters.File);

            ConfigFile ConfigFile;

            if (FileReference.Exists(ConfigFileLocation))
            {
                ConfigFile = new ConfigFile(ConfigFileLocation);
            }
            else
            {
                ConfigFile = new ConfigFile();
            }

            ConfigFileSection Section = ConfigFile.FindOrAddSection(Parameters.Section);

            Section.Lines.RemoveAll(x => String.Compare(x.Key, Parameters.Key, StringComparison.OrdinalIgnoreCase) == 0);
            Section.Lines.Add(new ConfigLine(ConfigLineAction.Set, Parameters.Key, Parameters.Value));

            FileReference.MakeWriteable(ConfigFileLocation);
            ConfigFile.Write(ConfigFileLocation);

            // Apply the optional tag to the produced archive
            foreach (string TagName in FindTagNamesFromList(Parameters.Tag))
            {
                FindOrAddTagSet(TagNameToFileSet, TagName).Add(ConfigFileLocation);
            }

            // Add the archive to the set of build products
            BuildProducts.Add(ConfigFileLocation);
        }
        public void MultipleReaderOrSingleWriter()
        {
            File.Delete(FilePath);
            var configFile = new ConfigFile <Configuration>(FilePath);

            configFile.Write(new TestConfigSection {
                Value = 6
            });

            // Verify multiple readers allowed.
            const int count = 4;

            bool[] done = new bool[count];
            Parallel.For(0, count, i =>
            {
                for (int j = 0; j < 10; j++)
                {
                    var section = configFile.Read <TestConfigSection>();
                    Assert.AreEqual(6, section.Value);
                }
                done[i] = true;
            });

            Array.ForEach(done, Assert.IsTrue);


            // Verify only single writer allowed.
            bool exceptionThrown = false;

            Parallel.For(0, 2, i =>
            {
                for (int j = 0; j < 5; j++)
                {
                    try
                    {
                        configFile.Write(new TestConfigSection {
                            Value = j
                        });
                    }
                    catch (IOException)
                    {
                        exceptionThrown = true;
                    }
                }
            });
            Assert.IsTrue(exceptionThrown);
        }
        private void GenerateConfigForConsumers(ConfigFile consumerConfig)
        {
            var consumerBindMappingFileName = Path.Combine(OutputPath, $"{ConsumerBindMappingConfigId}.BindMapping.xml");

            using (var consumerBindMapping = File.Create(consumerBindMappingFileName))
            {
                consumerConfig.Write(consumerBindMapping);
            }
        }
        public void WriteSectionTest()
        {
            Delete();

            var configFile = new ConfigFile <Configuration>(FilePath);

            var input = new TestConfigSection();

            configFile.Write(input);
        }
Example #6
0
        public void Confirm(object obj)
        {
            if (obj == null)
            {
                return;
            }

            CommandArgs args   = (CommandArgs)obj;
            var         player = args.Player ?? TSPlayer.Server;

            //Get the TShock group manager and setup the new vanilla group
            GroupManager gm    = TShock.Groups;
            Group        group = CreateVanillaGroupObject();

            if (!gm.GroupExists(GroupName))
            {
                gm.AddGroup(name: GroupName, parentname: null, permissions: group.Permissions, chatcolor: Group.defaultChatColor);
            }
            else
            {
                gm.UpdateGroup(name: GroupName, parentname: null, permissions: group.Permissions, chatcolor: Group.defaultChatColor, suffix: null, prefix: null);
            }
            //Retrieve the group again just so that the object state is synced with db state
            group = gm.GetGroupByName(GroupName);

            //Get the TShock user manager, select all non-superadmin groups, and change their group to the new vanilla group
            UserAccountManager um = TShock.UserAccounts;

            um.GetUserAccounts().Where(u => u.Group != "superadmin").ForEach(u => um.SetUserGroup(u, GroupName));

            //Update all active player's groups, as long as they're not a superadmin
            foreach (var ply in TShock.Players)
            {
                if (ply?.Group == null || ply.Group is SuperAdminGroup)
                {
                    continue;
                }

                ply.Group = group;
            }

            //Set the default group for any new guests joining
            Group.DefaultGroup = group;

            //Update the TShock config file so all new guest users will be assigned to the vanilla group
            ConfigFile tsConfig = TShock.Config;

            tsConfig.DefaultGuestGroupName        = GroupName;
            tsConfig.DefaultRegistrationGroupName = GroupName;
            //Write the config file so that this change persists
            tsConfig.Write(TShockConfigPath);

            player.SendSuccessMessage("Server has successfully been configured for vanilla gameplay.");
        }
Example #7
0
        public void SetValues(string path, List <EnvironmentItem> values)
        {
            FoamDictionary d = Dict.GetByUrl(path);

            d.Clear();
            foreach (EnvironmentItem p in values)
            {
                d.SetChild(p.Name, p.Value);
            }
            ConfigFile.Write();
        }
Example #8
0
        private void GenerateConfigForConsumers(ConfigFile consumerConfig)
        {
            if (ConsumerBindMappingConfig == null)
            {
                return;
            }

            using var consumerBindMapping = File.Create(ConsumerBindMappingConfig.ItemSpec);

            consumerConfig.Write(consumerBindMapping);
        }
Example #9
0
        protected override bool Execute(ConfigFile config)
        {
            var cppHeaderGenerator = new CppHeaderGenerator(
                SharpGenLogger,
                ForceParsing,
                OutputPath);

            var configsWithHeaders = new HashSet <ConfigFile>();

            foreach (var cfg in config.ConfigFilesLoaded)
            {
                if (HeaderFiles.Any(item => item.GetMetadata("ConfigId") == cfg.Id))
                {
                    configsWithHeaders.Add(cfg);
                }
            }

            var configsWithExtensions = new HashSet <string>();

            foreach (var file in ExtensionHeaders)
            {
                configsWithExtensions.Add(file.GetMetadata("ConfigId"));
            }

            var(updatedConfigs, prolog) = cppHeaderGenerator.GenerateCppHeaders(config, configsWithHeaders, configsWithExtensions);

            var consumerConfig = new ConfigFile
            {
                Id            = "CppConsumerConfig",
                IncludeProlog =
                {
                    prolog
                }
            };

            consumerConfig.Write(CppConsumerConfigCache.ItemSpec);

            var updatedConfigFiles = new List <ITaskItem>();

            foreach (var cfg in configsWithHeaders)
            {
                if (updatedConfigs.Contains(cfg) && cfg.AbsoluteFilePath != null)
                {
                    var item = new TaskItem(cfg.AbsoluteFilePath);
                    item.SetMetadata("Id", cfg.Id);
                    updatedConfigFiles.Add(item);
                }
            }

            UpdatedConfigs = updatedConfigFiles.ToArray();

            return(!SharpGenLogger.HasErrors);
        }
Example #10
0
File: Kits.cs Project: Olink/Kits
        public Kits(Main game)
            : base(game)
        {
            Order = 4;

            config = ConfigFile.Read(savepath);
            config.Write(savepath);

            Console.WriteLine( "End of pre initialize");

            if (Initialized != null)
                Initialized();
        }
Example #11
0
        private void button1_Click(object sender, EventArgs e)
        {
            var data = new ConfigData
            {
                UserName    = textBoxUser.Text,
                Password    = textBoxPassword.Text,
                ProxyServer = textBoxProxy.Text,
                ProxyPort   = textBoxPort.Text
            };

            ConfigFile.Write(data);
            Close();
        }
        public void TestWaitingForFileAccess()
        {
            Delete();
            File.WriteAllText(FilePath, string.Empty);
            var file       = File.Open(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            var configFile = new ConfigFile <Configuration>(FilePath);
            var task       = Task.Factory.StartNew(() => configFile.Write(new TestConfigSection {
                Value = 43
            }));

            Thread.Sleep(500);
            file.Close();
            task.Wait();
            Assert.AreEqual(43, configFile.Read <TestConfigSection>().Value);
        }
        public void WriteReadSectionTest()
        {
            Delete();

            var configFile = new ConfigFile <Configuration>(FilePath);

            var input = new TestConfigSection {
                Value = 12
            };

            configFile.Write(input);

            var output = configFile.Read <TestConfigSection>();

            Assert.AreEqual(input.Value, output.Value);
        }
        public void DeleteSectionTest()
        {
            Delete();
            var configFile = new ConfigFile <Configuration>(FilePath);
            var another    = new AnotherConfigSection();
            var test       = new TestConfigSection()
            {
                Value = 155
            };

            configFile.Write(another, test);

            Assert.AreEqual(155, configFile.Read <TestConfigSection>().Value);

            configFile.DeleteSection <TestConfigSection>();
            Assert.AreEqual(15, configFile.Read <AnotherConfigSection>().Number);
            Assert.AreEqual(9, configFile.Read <TestConfigSection>().Value);
        }
Example #15
0
        private ConfigFile SaveConfigFile(bool saveNew = false)
        {
            if (this.CurrentProfile.ECUFile != null)
            {
                Measurements ms = new Measurements();
                foreach (Measurement m in this.CurrentProfile.ECUFile.Measurements.Values.Where(m => m.Selected))
                {
                    ms.AddMeasurement(m);
                }

                if (ms.Values.Count() > 0)
                {
                    if (saveNew || string.IsNullOrEmpty(this.txtConfigFile.Text))
                    {
                        SaveFileDialog d = new SaveFileDialog();
                        d.Title            = "Save Config File As...";
                        d.InitialDirectory =
                            string.IsNullOrWhiteSpace(this.txtConfigFile.Text) ?
                            System.IO.Path.Combine(Program.ME7LoggerDirectory, "logs") :
                            System.IO.Path.GetDirectoryName(this.txtConfigFile.Text);
                        d.FileName = System.IO.Path.GetFileName(this.txtConfigFile.Text);
                        if (d.ShowDialog() != System.Windows.Forms.DialogResult.OK)
                        {
                            return(null);
                        }
                        this.txtConfigFile.Text = d.FileName;
                    }

                    ConfigFile configFile = new ConfigFile(txtConfigFile.Text, this.CurrentProfile.ECUFile.FileName, ms);
                    configFile.Write();
                    return(configFile);
                }
                else
                {
                    MessageBox.Show("No Measurements Selected");
                }
            }
            return(null);
        }
Example #16
0
        public override void ExecuteBuild()
        {
            int           WorkingCL       = -1;
            FileReference PluginFile      = null;
            string        ProjectFileName = ParseParamValue("Project");

            if (ProjectFileName == null)
            {
                ProjectFileName = CombinePaths(CmdEnv.LocalRoot, "SimpleGame", "SimpleGame.uproject");
            }
            LogInformation(ProjectFileName);

            ProjectParams Params = GetParams(this, ProjectFileName, out PluginFile);

            // Check whether folder already exists so we know if we can delete it later
            string PlatformStageDir     = Path.Combine(Params.StageDirectoryParam, "WindowsNoEditor");
            bool   bPreExistingStageDir = Directory.Exists(PlatformStageDir);

            PluginDescriptor Plugin = PluginDescriptor.FromFile(PluginFile);

            FileReference ProjectFile = new FileReference(ProjectFileName);

            // Add Plugin to folders excluded for nativization in config file
            FileReference UserEditorIni             = new FileReference(Path.Combine(Path.GetDirectoryName(ProjectFileName), "Config", "UserEditor.ini"));
            bool          bPreExistingUserEditorIni = FileReference.Exists(UserEditorIni);

            if (!bPreExistingUserEditorIni)
            {
                // Expect this most of the time so we will create and clean up afterwards
                DirectoryReference.CreateDirectory(UserEditorIni.Directory);
                CommandUtils.WriteAllText(UserEditorIni.FullName, "");
            }

            const string ConfigSection = "BlueprintNativizationSettings";
            const string ConfigKey     = "ExcludedFolderPaths";
            string       ConfigValue   = "/" + PluginFile.GetFileNameWithoutAnyExtensions() + "/";

            ConfigFile        UserEditorConfig = new ConfigFile(UserEditorIni);
            ConfigFileSection BPNSection       = UserEditorConfig.FindOrAddSection(ConfigSection);
            bool bUpdateConfigFile             = !BPNSection.Lines.Exists(x => String.Equals(x.Key, ConfigKey, StringComparison.OrdinalIgnoreCase) && String.Equals(x.Value, ConfigValue, StringComparison.OrdinalIgnoreCase));

            if (bUpdateConfigFile)
            {
                BPNSection.Lines.Add(new ConfigLine(ConfigLineAction.Add, ConfigKey, ConfigValue));
                UserEditorConfig.Write(UserEditorIni);
            }

            Project.Cook(Params);
            if (!bPreExistingUserEditorIni)
            {
                FileReference.Delete(UserEditorIni);
            }

            Project.CopyBuildToStagingDirectory(Params);
            Project.Package(Params, WorkingCL);
            Project.Archive(Params);
            Project.Deploy(Params);

            // Get path to where the plugin was staged
            string StagedPluginDir = Path.Combine(PlatformStageDir, Path.GetFileNameWithoutExtension(ProjectFileName), PluginFile.Directory.MakeRelativeTo(ProjectFile.Directory));
            string ZipFile         = Path.Combine(Params.StageDirectoryParam, PluginFile.GetFileNameWithoutAnyExtensions());

            CommandUtils.DeleteFile(ZipFile);
            System.IO.Compression.ZipFile.CreateFromDirectory(StagedPluginDir, ZipFile + ".zip");

            if (!bPreExistingStageDir)
            {
                CommandUtils.DeleteDirectory(PlatformStageDir);
            }
        }
Example #17
0
 public void SetValue(string path, string name, string value)
 {
     Dict.GetByUrl(path).SetChild(name, value);
     ConfigFile.Write();
 }