Esempio n. 1
0
        // TODO
        private static void DefaultMain()
        {
            var loader = new JsonConfigLoader();
            var config = new DatabasesConfig
            {
                Accounts = new DatabaseSettings
                {
                    FileName = "accounts.db",
                    Password = "******"
                },

                Characters = new DatabaseSettings
                {
                    FileName = "characters.db",
                    Password = null
                },

                World = new DatabaseSettings
                {
                    FileName = "world.db",
                    Password = null
                }
            };

            var accounts = new AccountsDatabase(config.Accounts);

            try
            {
                config = loader.Load <DatabasesConfig>("database");
                ConnectToMasterRouterAsync(IPAddress.Loopback, 12000).RunAsync();
                Console.ReadLine();
            }
            catch (DirectoryNotFoundException ex)
            {
                Console.Error.WriteLine("Config directory not found, attempting to create default file...");
                Directory.CreateDirectory(loader.RootDirectory);
                loader.CreateDefault("database", config);
            }
            catch (FileNotFoundException ex)
            {
                Console.Error.WriteLine("Config file not found, attempting to create default file...");
                loader.CreateDefault("database", config);
            }
            finally
            {
                accounts.Dispose();
            }
        }
Esempio n. 2
0
        public List <ITableInfo> CreateTableListFromConfig(DatabasesConfig databasesConfig)
        {
            if (databasesConfig == null)
            {
                throw new ArgumentNullException("The DatabaseConfigurationSection input parameter is null.");
            }

            var dbs = databasesConfig.Databases;

            if (dbs == null)
            {
                return(new List <ITableInfo>());
            }

            var dbConfigsToRemove = new List <DatabaseConfig>();

            foreach (var dbConfig in databasesConfig.Databases)
            {
                if (!_configValidator.IsDbConfigValid(dbConfig))
                {
                    dbConfigsToRemove.Add(dbConfig);
                }

                var tableConfigsToRemove = new List <TableConfig>();
                foreach (var tableConfig in dbConfig.Tables)
                {
                    if (!_configValidator.IsTableConfigValid(dbConfig, tableConfig))
                    {
                        tableConfigsToRemove.Add(tableConfig);
                    }
                    else
                    {
                        ConstructFullTableName(tableConfig);
                    }

                    if (!_parameterValidator.AreTheParamsValid(dbConfig.ConnectionString, tableConfig) ||
                        !_whereConditionValidator.IsWhereConditionValid(dbConfig.ConnectionString, tableConfig) ||
                        !_linkedServerValidator.AreLinkedServerParamsValid(dbConfig.ConnectionString, tableConfig))
                    {
                        tableConfigsToRemove.Add(tableConfig);
                    }
                }
                dbConfig.Tables.RemoveAll(t => tableConfigsToRemove.Contains(t));
            }
            databasesConfig.Databases.RemoveAll(d => dbConfigsToRemove.Contains(d));

            var tableInfos = new List <ITableInfo>();

            foreach (var dbConfig in databasesConfig.Databases)
            {
                foreach (var tableConfig in dbConfig.Tables)
                {
                    try
                    {
                        var tableInfo = CreateTableInfo(dbConfig, tableConfig);
                        tableInfos.Add(tableInfo);
                    }
                    catch (Exception ex)
                    {
                        Log.Error($"An error happened while getting table information for table {tableConfig.FullTableName}. " +
                                  $"DbConnectionString: {dbConfig.ConnectionString}. Error message: {ex.Message}");
                    }
                }
            }

            return(tableInfos);
        }
Esempio n. 3
0
        private async Task <SchedulingResult> ScheduleScramblingJob <JobType>(string jobName, string jobGroup, string triggerDescription,
                                                                              string cronExpression, string description, DatabasesConfig jobConfig)
            where JobType : IJob
        {
            if (!CronExpression.IsValidExpression(cronExpression))
            {
                return(new SchedulingResult {
                    IsSuccessful = false, ErrorMessage = "The cron expression is invalid."
                });
            }
            var jobDetail = _scheduler.GetJobDetail(new JobKey(jobName, jobGroup));

            if (_scheduler.GetJobDetail(new JobKey(jobName, jobGroup)).Status != TaskStatus.WaitingForActivation)
            {
                return(new SchedulingResult {
                    IsSuccessful = false, ErrorMessage = "The jobname is already taken."
                });
            }

            var job = JobBuilder.CreateForAsync <JobType>()
                      .WithIdentity(jobName, jobGroup)
                      .UsingJobData("configStr", JsonConvert.SerializeObject(jobConfig))
                      .WithDescription(description)
                      .RequestRecovery()
                      .Build();

            var trigger = (ICronTrigger)TriggerBuilder.Create()
                          .WithDescription(triggerDescription)
                          .WithCronSchedule(cronExpression)
                          .Build();

            //Console.WriteLine($"Trigger before: name: {trigger.Key.Name} group: {trigger.Key.Group}" );
            try
            {
                await _scheduler.ScheduleJob(job, trigger);

                //Console.WriteLine($"Trigger after: name: {trigger.Key.Name} group: {trigger.Key.Group}");
            }
            catch (ObjectAlreadyExistsException ex)
            {
                return(new SchedulingResult
                {
                    IsSuccessful = false,
                    ErrorMessage = ex.Message
                });
            }
            catch (JobPersistenceException ex)
            {
                return(new SchedulingResult
                {
                    IsSuccessful = false,
                    ErrorMessage = ex.Message
                });
            }

            return(new SchedulingResult {
                IsSuccessful = true, JobKey = job.Key, TriggerKey = trigger.Key
            });
        }
Esempio n. 4
0
 public async Task <SchedulingResult> ScheduleMySqlScramblingJob(string jobName, string jobGroup, string triggerDescription,
                                                                 string cronExpression, string description, DatabasesConfig jobConfig)
 {
     return(await ScheduleScramblingJob <MySqlScramblingJob>(jobName, jobGroup, triggerDescription, cronExpression, description, jobConfig));
 }