public TranslateService(IDatabase database, LicenseService license, LogHandler logger, DiscordShardedClient client, LocalManagementService localManagementService) { Database = database; License = license; Logger = logger; Client = client; LocalManagementService = localManagementService; Config = GetTranslateConfig(); if (Config.APIKey != null && Config.Enabled) { if (Config.ApiKeyType == TranslateConfig.ApiKey.Google) { Translator = new GoogleTranslator(Config.APIKey); } else if (Config.ApiKeyType == TranslateConfig.ApiKey.Yandex) { Translator = new YandexTranslator(Config.APIKey); } else { throw new NotImplementedException("The specified api type is not implemented"); } Client.ReactionAdded += ReactionAdded; } else if (Config.APIKey == null && Config.Enabled) { logger.Log("Translate API is enabled but no API Key is specified.", LogSeverity.Warning); } }
public TranslateSupport(TranslateConfig Config, string OrderHeaderFile, string OrderDetailFile, string OrderPaymentFile) { PluginConfig = Config; TotalStores = new List <string>(); _OrderDetailFile = OrderDetailFile; _OrderHeaderFile = OrderHeaderFile; _OrderPaymentFile = OrderPaymentFile; }
public TranslateConfig GetTranslateConfig() { var config = Database.Load <TranslateConfig>(TranslateConfig.DocumentName()); if (config == null) { config = new TranslateConfig(); Database.Store(config, TranslateConfig.DocumentName()); } return(config); }
/// <summary> /// Used to start the translate. /// </summary> /// <param name="PluginName"></param> /// <param name="strSourceFile"></param> public void ExecuteTranslate(string PluginName, string strSourceFile) { _config = new TranslateConfig(PluginName); if (String.IsNullOrEmpty(strSourceFile)) { if (_config.SourceFile != "") { SourceFile = SourceFileLocation + "\\" + _config.SourceFile; } } else { SourceFile = strSourceFile; } if (OnPreProcess != null) { OnPreProcess(); } Process(); }
public void SaveTranslateConfig(TranslateConfig config) { Database.Store(config, TranslateConfig.DocumentName()); }
private static void ExecuteTranslate(string[] args) { //Make sure the translate is not already runnin if (!isAlreadyRunning(args)) { //Populate the plugins passed in that need to be run PopulatePlugins(args); //Load the current configuration System.Configuration.Configuration Appconfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); // Get the collection of the translate plugin groups. ConfigurationSectionGroup PluginConfiguration = Appconfig.GetSectionGroup("TranslatePlugins"); //Load the plugins and execute them for (int i = 0; i < PluginConfiguration.Sections.Count; i++) { System.Configuration.ConfigurationSection TransConfigSection = PluginConfiguration.Sections[i]; TranslateConfig transConfig = new TranslateConfig(TransConfigSection.SectionInformation.Name); string[] AssemInfo = transConfig.ExecutionName.Split(','); string CurrentPlugin = AssemInfo[0].Trim(); string PluginFullName = AssemInfo[1].Trim(); //Check to see if we need to execute this plugin string Config = CurrentPlugin; if (!_PluningsToRun.Contains(CurrentPlugin.ToLower())) { if (!_PluningsToRun.Contains(TransConfigSection.SectionInformation.Name.ToLower())) { continue; } else { Config = TransConfigSection.SectionInformation.Name; } } //Load the assembly Assembly assembly = Assembly.Load(CurrentPlugin); Type ClassType = assembly.GetType(PluginFullName); object transItem; try { transItem = Activator.CreateInstance(ClassType); } catch (Exception ex) { Logger log = Logger.Create(); log.LogMessage("Unhandled exception while trying to create an instance of " + PluginFullName + "\r\n" + ex.StackTrace); continue; } //Check to make sure the plugin is the correct type if (transItem is TranslateItem) { TranslateItem transPlugin = (TranslateItem)transItem; //Execute the translate for this plugin try { transPlugin.ExecuteTranslate(Config); } catch (Exception ex) { Logger log = Logger.Create(); log.LogMessage("Unhandled exception during translate " + ex.Message + "\r\n" + ex.StackTrace); } } else { Logger log = Logger.Create(); log.LogMessage("Invalid Plugin Loaded. Plugin needs to be of type " + typeof(TranslateItem).FullName); } } } else { Logger log = Logger.Create(); log.LogMessage("Translate Already Running."); log.LogMessage("Exiting."); System.Threading.Thread.Sleep(5000); } }
public TranslateSupport(TranslateConfig Config) { PluginConfig = Config; }