public static void Register(HttpConfiguration config) { // Web API configuration and services // Web API routes config.MapHttpAttributeRoutes(); config.EnableCors(); config.Filters.Add(new ExceptionFilter()); bool showTestData; if (Boolean.TryParse(ConfigTools.GetAppStr("ShowTestData"), out showTestData) == false) { showTestData = false; } if (showTestData) { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }, namespaces: new string[] { "BT.Web.ApiControllers" } ); } else { config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional }, namespaces: new string[] { "BT.Web.ApiControllers.Test" } ); } }
/// <summary> /// インスタンスに値を代入します. /// </summary> public void Substitute(GlobalConfig conf) { ConfigTools.Substitute(conf.SystemConfig, SystemConfig); ConfigTools.Substitute(conf.BaloonConfig, BaloonConfig); ConfigTools.Substitute(conf.ShellConfig, ShellConfig); ConfigTools.Substitute(conf.UserInputConfig, UserInputConfig); }
/// <summary> /// Config.ConfigurableObjectAttribute 属性のついたデータ型をプロパティに持つオブジェクトの型から,各プロパティに対応するTabItemを取得します. /// TabControlにメソッドの戻り値を追加し,TabControlのDataContextに<paramref name="type" />型オブジェクトのインスタンスを設定すると,値を編集できるようになります. /// </summary> /// <param name="defaultMargin">コンポーネントの既定のマージン</param> /// <returns>属性にしたがって<code>Header</code>と<code>Content</code>が設定されたTabItem</returns> private static IEnumerable <TabItem> GenerateTabItems(Thickness defaultMargin) { // コントロールのインスタンス化 foreach (PropertyInfo propertyInfo in typeof(GlobalConfig).GetProperties()) { object[] configurables = propertyInfo.PropertyType.GetCustomAttributes(typeof(ConfigurableObjectAttribute), true); if (configurables.Length > 0) { // Configurableとしてマークされている var item = new TabItem { Header = ((ConfigurableObjectAttribute)configurables[0]).Title }; UserControl content = ConfigTools.GenerateUserControl(propertyInfo.PropertyType, defaultMargin); content.Margin = defaultMargin; item.Content = content; // Binding の作成 var binding = new Binding(propertyInfo.Name) { UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged }; content.SetBinding(DataContextProperty, binding); yield return(item); } } }
/// <summary> /// インスタンスのディープ コピーとして新しいインスタンスを作成します. /// </summary> public GlobalConfig(GlobalConfig src) { SystemConfig = ConfigTools.CreateCopyOf(src.SystemConfig); BaloonConfig = ConfigTools.CreateCopyOf(src.BaloonConfig); ShellConfig = ConfigTools.CreateCopyOf(src.ShellConfig); UserInputConfig = ConfigTools.CreateCopyOf(src.UserInputConfig); }
public void TestDefaultLanguage() { ConfigTools.InitConf("Config.xml"); CultureInfo ci = ConfigTools.GetCurrentLanguage(); Assert.AreEqual(ci, CultureInfo.CurrentCulture); }
public void VerifLnAddAndReset() { ConfigTools.InitLightNovels("LightNovels.xml"); Assert.AreEqual(Globale.LN_TO_RETRIEVE.Count, 2); ConfigTools.InitLightNovels("LightNovels.xml", true); Assert.AreEqual(Globale.LN_TO_RETRIEVE.Count, 1); }
public void TestDefaultLanguageChange() { CultureInfo ci = CultureInfo.CurrentCulture.TwoLetterISOLanguageName.ToUpper() == "FR" ? CultureInfo.GetCultureInfo("en") : CultureInfo.GetCultureInfo("de"); ConfigTools.InitConf("Config.xml", ci); Assert.AreEqual(ci, ConfigTools.GetCurrentLanguage()); }
private void LocateToolStripMenuItemClick(object sender, EventArgs e) { var tDirDialog = new FolderBrowserDialog(); tDirDialog.Description = @"Current folder location of the CslaGen templates is:" + Environment.NewLine + _controller.TemplatesDirectory + Environment.NewLine + @"Select a new folder location and press OK."; tDirDialog.ShowNewFolderButton = false; if (!string.IsNullOrEmpty(_controller.TemplatesDirectory)) { tDirDialog.SelectedPath = _controller.TemplatesDirectory; } else { tDirDialog.RootFolder = Environment.SpecialFolder.Desktop; } var dialogResult = tDirDialog.ShowDialog(); if (dialogResult == DialogResult.OK) { var tdir = tDirDialog.SelectedPath; if (tDirDialog.SelectedPath.LastIndexOf('\\') != tDirDialog.SelectedPath.Length - 1) { tdir += @"\"; } _controller.TemplatesDirectory = tdir; ConfigTools.Change("TemplatesDirectory", _controller.TemplatesDirectory); } }
private static object _parseGenericArrayConfigField(string typeName, string fieldName, string data, Type fieldType) { //重载分隔符 string splitChar = "+"; if (typeName.Contains("[]@")) { splitChar = typeName.Split('@')[1]; } int dimension = ConfigTools.GetGenericDimension(fieldType); Type elementType = ConfigTools.GetGenericElementType(fieldType); Type d1T = elementType.MakeArrayType(); if (dimension == 3) { Type wrapD2T = fieldType.GetGenericArguments()[0]; Type wrapD1T = wrapD2T.GetGenericArguments()[0]; Type d2T = wrapD1T.MakeArrayType(); string[] line = data.Split('`'); Array arrayD3 = Array.CreateInstance(d2T, line.Length); object wrapArrayD3 = Activator.CreateInstance(fieldType, arrayD3); for (int i = 0; i < line.Length; i++) { string[] p2 = line[i].Split('|'); Array arrayD2 = Array.CreateInstance(d1T, p2.Length); object wrapArrayD2 = Activator.CreateInstance(wrapD2T, arrayD2); for (int j = 0; j < p2.Length; j++) { object wrapArrayD1 = Activator.CreateInstance(wrapD1T, _parseArray(d1T, p2[j], splitChar)); arrayD2.SetValue(wrapArrayD1, j); } arrayD3.SetValue(wrapArrayD2, i); } return(wrapArrayD3); } if (dimension == 2) { Type wrapD1T = fieldType.GetGenericArguments()[0]; string[] line = data.Split('|'); Array arrayD2 = Array.CreateInstance(wrapD1T, line.Length); object wrapArrayD2 = Activator.CreateInstance(fieldType, arrayD2); for (int i = 0; i < line.Length; i++) { object wrapArrayD1 = Activator.CreateInstance(wrapD1T, _parseArray(d1T, line[i], splitChar)); arrayD2.SetValue(wrapArrayD1, i); } return(wrapArrayD2); } if (dimension == 1) { object wrapArrayD1 = Activator.CreateInstance(fieldType, _parseArray(d1T, data, splitChar)); return(wrapArrayD1); } return(null); }
public void TestAvailableLanguages() { ConfigTools.InitConf("Config.xml"); ICollection <CultureInfo> languages = ConfigTools.GetAvailableLanguage(); Assert.IsTrue(languages.Contains(CultureInfo.GetCultureInfo("en"))); Assert.IsTrue(languages.Contains(CultureInfo.GetCultureInfo("fr"))); }
public void VerifOverride() { ConfigTools.InitConf("Config_override.xml"); Assert.AreEqual(Globale.OUTPUT_FOLDER, "outputFolder_override"); Assert.IsFalse(Globale.INTERACTIVE_MODE); Assert.AreEqual(Globale.PUBLISHER, "publisher_override"); Assert.AreEqual(Globale.DEFAULT_CHAPTER_TITLE, "defaultChapterTitle_override"); Assert.AreEqual(Globale.MAX_CHAPTER_ON_ERROR_COUNT_BEFORE_STOP, 20); }
/// <summary> /// 开启 http 服务监听 9910 /// </summary> public static void StartHttp() { var url = string.Format("http://{0}:{1}/", ConfigTools.Get("addr"), ConfigTools.Get("httpPort")); HttpServices httpServer; httpServer = new HttpServices(url); var thread = new Thread(new ThreadStart(httpServer.Run)); thread.Start(); }
public static void Main(string[] args) { try { ConfigTools.InitConf("Config.xml"); ConfigTools.InitConf("Config_user.xml"); ConfigTools.InitLightNovels("LightNovels.xml", true); ConfigTools.InitLightNovels("LightNovels_user.xml", true); consoleTools = new ConsoleTools(1); ConsoleTools ctForWebcrawler = new ConsoleTools(3); webCrawler = new WebCrawler(ctForWebcrawler, ctForWebcrawler); } catch (ApplicationException e) { consoleTools.Log(e.Message); return; } if (!consoleTools.Ask(String.Format(LightNovelSniffer_CLI_Strings.AskOutputFolderConfirmation, Globale.OUTPUT_FOLDER))) { string folder = consoleTools.AskInformation(LightNovelSniffer_CLI_Strings.AskOutputFolder); if (!string.IsNullOrEmpty(folder)) { Globale.OUTPUT_FOLDER = folder; } } consoleTools.Log(LightNovelSniffer_CLI_Strings.LogProgramStart); foreach (LnParameters ln in Globale.LN_TO_RETRIEVE) { if (consoleTools.Ask(string.Format(LightNovelSniffer_CLI_Strings.AskRetrieveLn, ln.name))) { GetNovel(ln); } } if (Globale.INTERACTIVE_MODE && consoleTools.AskNegative(LightNovelSniffer_CLI_Strings.LogEndOfLnInConfig)) { LnParameters ln; do { ln = BuildDynamicLn(); GetNovel(ln); } while (!string.IsNullOrEmpty(ln.name)); } consoleTools.Log(LightNovelSniffer_CLI_Strings.LogProgramEnd); if (Globale.INTERACTIVE_MODE) { Console.ReadLine(); } }
/// <summary> /// 从控制台启动Electron程序 /// </summary> public static void StartElectronApp() { var cmd = ConfigTools.Get("ElectronAppPath"); if (cmd.IndexOf("|DataDirectory|") >= 0) { cmd = cmd.Replace("|DataDirectory|", Application.StartupPath); } var str = CmdTools.RunCmd(cmd); Console.WriteLine(str); }
public void TestNullCultureInfo() { ConfigTools.InitConf("Config.xml"); try { ConfigTools.SetLanguage((CultureInfo)null); } catch (LanguageException e) { Console.WriteLine(e.Message); throw; } }
public void TestNullLanguageString() { ConfigTools.InitConf("Config.xml"); try { ConfigTools.SetLanguage((string)null); } catch (LanguageException e) { Console.WriteLine(e.Message); throw; } }
public void TestInconsistentLanguageString() { ConfigTools.InitConf("Config.xml"); try { ConfigTools.SetLanguage("coucou"); } catch (LanguageException e) { Console.WriteLine(e.Message); throw; } }
internal void ReSortMruItems() { string[] original = MruItems.ToArray(); MruItems.Clear(); foreach (var item in original) { if (!MruItems.Contains(item)) { MruItems.Add(item); } } ConfigTools.ChangeMru(MruItems); }
/// <summary> /// インスタンス同士が等しいかどうかを判定します. /// </summary> public override bool Equals(object obj) { if (!(obj is GlobalConfig)) { return(false); } var conf = (GlobalConfig)obj; return (ConfigTools.IsEquivalent(SystemConfig, conf.SystemConfig) && ConfigTools.IsEquivalent(BaloonConfig, conf.BaloonConfig) && ConfigTools.IsEquivalent(ShellConfig, conf.ShellConfig) && ConfigTools.IsEquivalent(UserInputConfig, conf.UserInputConfig)); }
public async Task MainAsync() { _client = new DiscordSocketClient(new DiscordSocketConfig { AlwaysDownloadUsers = true, MessageCacheSize = 10000, GatewayIntents = GatewayIntents.Guilds | GatewayIntents.GuildMessages | GatewayIntents.GuildMessageReactions | GatewayIntents.GuildPresences | GatewayIntents.GuildVoiceStates | GatewayIntents.GuildMembers | GatewayIntents.GuildPresences, LogLevel = LogSeverity.Info }); // build or create config ConfigTools configBuilder = new ConfigTools(); _config = configBuilder.Build(); // Download required files from my server PrerequisiteFilesDownloader.StartupCheck(); var services = ConfigureServices(); services.GetRequiredService <LogService>(); await services.GetRequiredService <CommandHandlingService>().InitializeAsync(services); services.GetRequiredService <DatabaseService>().Initialize(); services.GetRequiredService <ServerPreferenceService>().Initialize(); services.GetRequiredService <SpotifyService>().Initialize(); _lavaNode = services.GetRequiredService <LavaNode>(); if (_config["token"] == "insert token here") { Console.WriteLine("NO TOKEN SET IN CONFIG FILE"); Environment.Exit(0); } // log in the bot with the supplied bot token await _client.LoginAsync(TokenType.Bot, _config["token"]); await _client.StartAsync(); _client.Ready += OnClientReady; await Task.Delay(-1); }
public static IPersistence GetPersistencePlugIn() { string dbConfig = ConfigTools.GetAppValue("PersistenceDataBase"); switch (dbConfig) { case "SQL": return(new SqlPlugIn()); case "ORACLE": // return new OraclePlugIn(); return(null); default: return(new SqlPlugIn()); } }
private static object _parseArrayConfigField(string typeName, string fieldName, string data, Type fieldType) { //重载分隔符 string splitChar = "+"; if (typeName.Contains("[]@")) { splitChar = typeName.Split('@')[1]; } int dimension = ConfigTools.GetArrayDimension(fieldType); if (dimension == 3) { string[] line = data.Split('`'); Array arrConfig2 = Array.CreateInstance(fieldType.GetElementType(), line.Length); for (int i = 0; i < line.Length; i++) { string[] p2 = line[i].Split('|'); Array tempElem = Array.CreateInstance(fieldType.GetElementType().GetElementType(), p2.Length); for (int j = 0; j < p2.Length; j++) { tempElem.SetValue( _parseArray(fieldType.GetElementType().GetElementType(), p2[j], splitChar), j); } arrConfig2.SetValue(tempElem, i); } return(arrConfig2); } //字符串数据转换为指定类型数组数据 if (dimension == 2) { string[] line = data.Split('|'); Array arrConfig2 = Array.CreateInstance(fieldType.GetElementType(), line.Length); for (int i = 0; i < line.Length; i++) { arrConfig2.SetValue(_parseArray(fieldType.GetElementType(), line[i], splitChar), i); } return(arrConfig2); } if (dimension == 1) { return(_parseArray(fieldType, data, splitChar)); } return(null); }
public void StartServer() { try { if (SockterServerEngine == null) { var port = ConfigTools.Get("port"); var _port = port == null || port.Length <= 0 ? 9909 : int.Parse(port); SockterServerEngine = NetworkEngineFactory.CreateTextTcpServerEngine(_port, new DefaultTextContractHelper("\0"));//DefaultTextContractHelper是StriveEngine内置的ITextContractHelper实现。使用UTF-8对EndToken进行编码。 } //判断 相关的监听事件是否注册 if (IsSocketServerInitialized) { SockterServerEngine.ChangeListenerState(true); } else { InitializeTcpServerEngine(); } //this.ShowListenStatus(); } catch (Exception ee) { Console.WriteLine(ee.Message); if (ee.Message.IndexOf("there's one StriveEngine server instance running") >= 0) { var res = MessageBox.Show("已打开一个实例或者前面实例的进程为未完全退出,是否重启?\r\n是:重启\r\n否:关闭\r\n取消:不做任何处理", "警告", MessageBoxButtons.YesNoCancel); if (DialogResult.Yes == res) { Application.ExitThread(); Application.Exit(); Application.Restart(); Process.GetCurrentProcess().Kill(); } else if (DialogResult.No == res) { Application.ExitThread(); Application.Exit(); Process.GetCurrentProcess().Kill(); } } } services = this; }
static void Main(string[] args) { ProgramTools.Setup(); var config = new Config(); ExecutableTools.LogArgs(new StderrWriteLine(), args, (arg) => { ConfigTools.SetProperty(config, arg); }); if (!config.Daemon) { Logger.TRACE = new StderrWriteLine(); } Stdio.SetStatus("Ready"); var line = Stdio.ReadLine(); while (line != null) { Logger.Trace("> {0}", line); if (line == "ping") { Stdio.WriteLine("pong"); Logger.Trace("< pong"); } //throw Exception Message if (line.StartsWith("throw")) { throw new Exception(line.Substring(6)); } if (line == "exit!") { return; } line = Stdio.ReadLine(); } Logger.Trace("Stdin closed"); Environment.Exit(0); }
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { _fileDialog.AutoUpgradeEnabled = true; _fileDialog.DefaultExt = "dll"; _fileDialog.InitialDirectory = GeneratorController.Current.ObjectsDirectory; _fileDialog.Filter = @"Assembly files (*.DLL) | *.DLL|Executable files (*.EXE) | *.EXE"; _fileDialog.RestoreDirectory = false; _fileDialog.Title = @"Select the Objects file"; DialogResult result = _fileDialog.ShowDialog(); if (result == DialogResult.Cancel) { return(value); } GeneratorController.Current.ObjectsDirectory = _fileDialog.FileName.Substring(0, _fileDialog.FileName.LastIndexOf('\\')); ConfigTools.SharedAppConfigChange("ObjectsDirectory", GeneratorController.Current.ObjectsDirectory); return(_fileDialog.FileName); }
//字段类型名转为配置表字段类型名 private string RuntimeTypeChangeToTypeName(Type t) { if (t.IsArray || t.IsGenericType) { if ((t.IsGenericType && t.Name.StartsWith("ReadonlyArray")) || t.IsArray) { string suff = ""; Type ementType = t; int d = t.IsArray ? ConfigTools.GetArrayDimension(t) : ConfigTools.GetGenericDimension(t); for (int i = 0; i < d; i++) { suff += "[]"; ementType = t.IsArray ? ementType.GetElementType() : ementType.GetGenericArguments()[0]; } return(BaseTypeNameChange(ementType, null, suff)); } return(null); } return(BaseTypeNameChange(t, null, "")); }
public void TestDefaultLanguageMessages() { ResourceManager rm = new ResourceManager(typeof(LightNovelSniffer_Strings)); string defaultTemplate = rm.GetString("CoverDownloadExceptionMessage"); string url = "coucou"; ConfigTools.InitConf("Config.xml"); try { WebCrawler.DownloadCover(url); } catch (CoverException e) { Console.WriteLine(e.Message); string localizedTemplate = rm.GetString("CoverDownloadExceptionMessage"); Assert.AreEqual(e.Message, string.Format(defaultTemplate, url)); Assert.AreEqual(e.Message, string.Format(localizedTemplate, url)); throw; } }
private void GetConfigRulesFolder() { var tDir = ConfigTools.SharedAppConfigGet("RulesDirectory"); if (string.IsNullOrEmpty(tDir)) { tDir = ConfigTools.AppConfigGet("RulesDirectory"); while (tDir.LastIndexOf(@"\\") == tDir.Length - 2) { tDir = tDir.Substring(0, tDir.Length - 1); } } if (string.IsNullOrEmpty(tDir)) { RulesDirectory = Environment.SpecialFolder.Desktop.ToString(); } else { RulesDirectory = tDir; } }
private void GetConfig() { var tDir = ConfigTools.Get("TemplatesDirectory"); if (string.IsNullOrEmpty(tDir)) { tDir = ConfigTools.OriginalGet("TemplatesDirectory"); while (tDir.LastIndexOf(@"\\") == tDir.Length - 2) { tDir = tDir.Substring(0, tDir.Length - 1); } } if (string.IsNullOrEmpty(tDir)) { TemplatesDirectory = Environment.SpecialFolder.Desktop.ToString(); } else { TemplatesDirectory = tDir; } }
//解析strInfo,将解析好的配置表导入配置管理表 private Config _loadConfigSource(Type t, long id) { Config instance = null; if (_byteDataDic.ContainsKey(t)) { instance = t.Assembly.CreateInstance(t.FullName) as Config; if (instance != null) { byte[] readBytes = _byteDataDic[t][id]; _byteBuffer.clear(); _byteBuffer.writeBytes(readBytes, 0, readBytes.Length); FieldInfo[] fields = instance.GetType().GetFields(); FieldInfo field; for (int m = 0; m < fields.Length; m++) { field = fields[m]; if (!field.IsInitOnly) { continue; } field.SetValue(instance, ConfigTools.ReadSimpleBuffer(field.FieldType, _byteBuffer)); } _configs[t].Add(id, instance); } else { Debug.Log("解析byte配置类型: " + t.Name + " ID: " + id + " 发生错误."); } return(instance); } if (_sourceData.ContainsKey(t)) { Type baseType = null; //derivedType不为空的特殊处理 FileLineInfo flInfo; if (!_sourceData[t].TryGetValue(id, out flInfo)) { Debug.Log("配置表 " + t + " 中未能找到: " + id); return(null); } if (flInfo.DerivedType != null) { baseType = t; t = _sourceData[t][id].DerivedType; } Type dicType = baseType ?? t; instance = _parseConfigSource(_dicFileFieldInfo[t.Name][0], _dicFileFieldInfo[t.Name][2], _sourceData[dicType][id].LineData, t); if (instance != null) { _configs[dicType].Add(id, instance); } else { Debug.Log("解析配置类型: " + t.Name + " ID: " + id + " 发生错误."); } return(instance); } return(null); }