当前位置: 首页>>代码示例>>C#>>正文


C# Config.Create方法代码示例

本文整理汇总了C#中Config.Create方法的典型用法代码示例。如果您正苦于以下问题:C# Config.Create方法的具体用法?C# Config.Create怎么用?C# Config.Create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Config的用法示例。


在下文中一共展示了Config.Create方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: WriteConfig

        /// <summary>
        /// Writes the current object out to a file.
        /// </summary>
        public void WriteConfig() {
            IConfig config = new Config();
            config.Create<PotatoController>();
            this.WriteConfig(config, this.Shared.Variables.Get<String>(CommonVariableNames.PotatoConfigPassword));

            config.Save(new FileInfo(Path.Combine(Defines.ConfigsDirectory.FullName, this.GetType().Namespace + ".json")));
        }
开发者ID:EBassie,项目名称:Potato,代码行数:10,代码来源:PotatoController.cs

示例2: WriteConfig

        /// <summary>
        /// Preps the config, then passes it to the executable object's WriteConfig(Config)
        /// </summary>
        /// <remarks>You can see a similar implementation of this in Instance, which is treated
        /// as the base class (therefore it's not passing a config to a child class) but instead
        /// needs to make the initial config object before writing to it.</remarks>
        public virtual void WriteConfig() {
            if (this.ConfigDirectoryInfo != null) {
                Config config = new Config();
                config.Create(this.GetType());
                this.WriteConfig(config);

                config.Save(new FileInfo(Path.Combine(this.ConfigDirectoryInfo.FullName, this.GetType().Namespace + ".json")));
            }
        }
开发者ID:EBassie,项目名称:Potato,代码行数:15,代码来源:PluginController.cs

示例3: TestSecurityWriteConfig

        public void TestSecurityWriteConfig() {
            var security = new SecurityController();
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAddGroup,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName"
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupSetPermission,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    "CustomPermission",
                    22
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupSetPermission,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    CommandType.VariablesSet,
                    77
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupSetPermission,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    CommandType.VariablesSetA,
                    88
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupAddAccount,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    "Phogue"
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAccountSetPassword,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Phogue",
                    "password"
                })
            });

            security.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken("Phogue", Guid.Parse("f380eb1e-1438-48c0-8c3d-ad55f2d40538"), "Token Hash", DateTime.Parse("2024-04-14 20:51:00 PM")).SetOrigin(CommandOrigin.Local));

            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAccountSetPreferredLanguageCode,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Phogue",
                    "de-DE"
                })
            });
            security.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAccountAddPlayer,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Phogue",
                    CommonProtocolType.DiceBattlefield3,
                    "ABCDEF"
                })
            });

            // Save a config of the language controller
            var saveConfig = new Config();
            saveConfig.Create(typeof(SecurityController));
            security.WriteConfig(saveConfig);
            saveConfig.Save(ConfigFileInfo);

            // Load the config in a new config.
            var loadConfig = new Config();
            loadConfig.Load(ConfigFileInfo);

            var commands = loadConfig.RootOf<SecurityController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList();

            Assert.AreEqual("SecurityAddGroup", commands[0].Command.Name);
            Assert.AreEqual("Guest", commands[0].Command.Parameters[0].First<String>());

            Assert.AreEqual("SecurityAddGroup", commands[1].Command.Name);
            Assert.AreEqual("GroupName", commands[1].Command.Parameters[0].First<String>());

            Assert.AreEqual("SecurityGroupSetPermission", commands[2].Command.Name);
            Assert.AreEqual("GroupName", commands[2].Command.Parameters[0].First<String>());
            Assert.AreEqual(CommandType.VariablesSet.ToString(), commands[2].Command.Parameters[1].First<String>());
            Assert.AreEqual("77", commands[2].Command.Parameters[2].First<String>());

            Assert.AreEqual("SecurityGroupSetPermission", commands[3].Command.Name);
            Assert.AreEqual("GroupName", commands[3].Command.Parameters[0].First<String>());
            Assert.AreEqual(CommandType.VariablesSetA.ToString(), commands[3].Command.Parameters[1].First<String>());
            Assert.AreEqual("88", commands[3].Command.Parameters[2].First<String>());
//.........这里部分代码省略.........
开发者ID:EBassie,项目名称:Potato,代码行数:101,代码来源:TestSecurity.cs

示例4: TestSecurityLoadConfig

        public void TestSecurityLoadConfig() {
            var saveSecurity = new SecurityController();
            saveSecurity.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAddGroup,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName"
                })
            });
            saveSecurity.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupSetPermission,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    "CustomPermission",
                    22
                })
            });
            saveSecurity.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupSetPermission,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    CommandType.VariablesSet,
                    77
                })
            });
            saveSecurity.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupSetPermission,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    CommandType.VariablesSetA,
                    88
                })
            });
            saveSecurity.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityGroupAddAccount,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "GroupName",
                    "Phogue"
                })
            });
            saveSecurity.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAccountSetPassword,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Phogue",
                    "password"
                })
            });

            saveSecurity.Tunnel(CommandBuilder.SecurityAccountAppendAccessToken("Phogue", Guid.Parse("f380eb1e-1438-48c0-8c3d-ad55f2d40538"), "Token Hash", DateTime.Parse("2024-04-14 20:51:00 PM")).SetOrigin(CommandOrigin.Local));

            saveSecurity.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAccountSetPreferredLanguageCode,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Phogue",
                    "de-DE"
                })
            });
            saveSecurity.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.SecurityAccountAddPlayer,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "Phogue",
                    CommonProtocolType.DiceBattlefield3,
                    "ABCDEF"
                })
            });

            // Save a config of the security controller
            var saveConfig = new Config();
            saveConfig.Create(typeof(SecurityController));
            saveSecurity.WriteConfig(saveConfig);
            saveConfig.Save(ConfigFileInfo);

            // Load the config in a new config.
            var loadSecurity = (SecurityController)new SecurityController().Execute();
            var loadConfig = new Config();
            loadConfig.Load(ConfigFileInfo);
            loadSecurity.Execute(loadConfig);

            var lastGroup = loadSecurity.Groups.LastOrDefault(group => @group.Name == "GroupName") ?? new GroupModel();

            Assert.AreEqual("Guest", loadSecurity.Groups.First().Name);
            Assert.AreEqual("GroupName", loadSecurity.Groups.Last().Name);
            Assert.AreEqual(22, lastGroup.Permissions.First(permission => permission.Name == "CustomPermission").Authority);
            Assert.AreEqual(77, lastGroup.Permissions.First(permission => permission.Name == CommandType.VariablesSet.ToString()).Authority);
            Assert.AreEqual(88, lastGroup.Permissions.First(permission => permission.Name == CommandType.VariablesSetA.ToString()).Authority);
            Assert.AreEqual("Phogue", loadSecurity.Groups.SelectMany(group => group.Accounts).First().Username);
            Assert.AreEqual(Guid.Parse("f380eb1e-1438-48c0-8c3d-ad55f2d40538"), loadSecurity.Groups.SelectMany(group => group.Accounts).First().AccessTokens.First().Value.Id);
            Assert.AreEqual("Token Hash", loadSecurity.Groups.SelectMany(group => group.Accounts).First().AccessTokens.First().Value.TokenHash);
            Assert.AreEqual(DateTime.Parse("2024-04-14 20:51:00 PM"), loadSecurity.Groups.SelectMany(group => group.Accounts).First().AccessTokens.First().Value.LastTouched);
            Assert.AreEqual("de-DE", loadSecurity.Groups.Last().Accounts.First().PreferredLanguageCode);
            Assert.AreEqual(CommonProtocolType.DiceBattlefield3, loadSecurity.Groups.SelectMany(group => group.Accounts).SelectMany(account => account.Players).First().ProtocolType);
            Assert.AreEqual("ABCDEF", loadSecurity.Groups.SelectMany(group => group.Accounts).SelectMany(account => account.Players).First().Uid);

//.........这里部分代码省略.........
开发者ID:EBassie,项目名称:Potato,代码行数:101,代码来源:TestSecurity.cs

示例5: TestWriteConfig

        public void TestWriteConfig() {
            var variables = (VariableController)new VariableController().Execute();
            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "NameToWriteString",
                    "this is a string"
                })
            });

            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "NameToWriteInteger",
                    1
                })
            });

            // Empty strings should not be written. No point saving nothing.
            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "NameToignore",
                    ""
                })
            });

            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "NameToNotWrite",
                    "This shouldn't appear in the saved file."
                })
            });

            variables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    CommonVariableNames.MaximumProtocolConnections,
                    10
                })
            });

            // Save a config of the variables controller
            var saveConfig = new Config();
            saveConfig.Create(typeof (VariableController));
            variables.WriteConfig(saveConfig);
            saveConfig.Save(ConfigFileInfo);

            // Load the config in a new config.
            var loadConfig = new Config();
            loadConfig.Load(ConfigFileInfo);

            var commands = loadConfig.RootOf<VariableController>().Children<JObject>().Select(item => item.ToObject<IConfigCommand>(JsonSerialization.Minimal)).ToList();

            // Order is not maintained so we can only check that the values in some disorder are output.
            // Nope, not perfect.
            foreach (var command in commands) {
                Assert.AreEqual("VariablesSetA", command.Command.Name);
                Assert.IsTrue(new List<String>() { "NameToWriteString", "NameToWriteInteger", "MaximumProtocolConnections" }.Contains(command.Command.Parameters[0].First<String>()));
                Assert.IsTrue(new List<String>() { "this is a string", "1", "10" }.Contains(command.Command.Parameters[1].First<String>()));
            }
        }
开发者ID:EBassie,项目名称:Potato,代码行数:68,代码来源:TestVariableController.cs

示例6: TestLoadConfig

        public void TestLoadConfig() {
            var saveVariables = (VariableController)new VariableController().Execute();
            saveVariables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "KeyToWriteString",
                    "this is a string"
                })
            });

            saveVariables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "KeyToWriteInteger",
                    1
                })
            });

            saveVariables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSet,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    "KeyToNotWrite",
                    "This shouldn't appear in the saved file."
                })
            });

            saveVariables.Tunnel(new Command() {
                Origin = CommandOrigin.Local,
                CommandType = CommandType.VariablesSetA,
                Parameters = TestHelpers.ObjectListToContentList(new List<Object>() {
                    CommonVariableNames.MaximumProtocolConnections,
                    10
                })
            });

            // Save a config of the variables controller
            var saveConfig = new Config();
            saveConfig.Create(typeof (VariableController));
            saveVariables.WriteConfig(saveConfig);
            saveConfig.Save(ConfigFileInfo);

            // Load the config in a new config.
            var loadVariables = (VariableController)new VariableController().Execute();
            var loadConfig = new Config();
            loadConfig.Load(ConfigFileInfo);
            loadVariables.Execute(loadConfig);

            Assert.AreEqual("this is a string", loadVariables.ArchiveVariables.Values.First(v => v.Name == "KeyToWriteString").ToType<String>());
            Assert.AreEqual(1, loadVariables.ArchiveVariables.Values.First(v => v.Name == "KeyToWriteInteger").ToType<int>());
            Assert.AreEqual(10, loadVariables.ArchiveVariables.Values.First(v => v.Name == "MaximumProtocolConnections").ToType<int>());
        }
开发者ID:EBassie,项目名称:Potato,代码行数:54,代码来源:TestVariableController.cs


注:本文中的Config.Create方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。