static void Main(string[] args) { logger.Info($"TaskProcessor Started..."); var databaseName = ConfigurationManager.AppSettings["databaseName"]; var client = new MongoClient(); var mongoDB = client.GetDatabase(databaseName); logger.Info($"Connected to {databaseName}"); var tasksRepo = new ServerTasksRepository(mongoDB); List <ServerTask> tasks = tasksRepo.GetEntitiesByExpression(t => t.Status != ServerTask.TaskStatus.Completed).ToList(); logger.Info($"Retrived {tasks.Count} to process"); foreach (var task in tasks) { try { logger.Info($"Process\n{task}"); ITaskProcessor processor = TaskProcessorFactory.GetTaskProcessor(task.Type, mongoDB); processor.ProcessTask(task); } catch (Exception e) { logger.Error($"{e}"); } } logger.Info($"TaskProcessor Finished..."); }
private void CloseTask(ServerTask task) { var taskRepo = new ServerTasksRepository(DataBase); task.Status = ServerTask.TaskStatus.Completed; taskRepo.Update(task); logger.Info($"Task Completed successfully!"); }
public ChatService(string databaseName) { var client = new MongoClient(); mongoDB = client.GetDatabase(databaseName); MessagesRepository = new MessagesRepository(mongoDB); AccountRepository = new AccountsRepository(mongoDB); GroupsRepository = new GroupsRepository(mongoDB); TasksRepository = new ServerTasksRepository(mongoDB); }