Beispiel #1
0
        static async Task StartScheduler()
        {
            var horarium =
                new HorariumServer(MongoRepositoryFactory.Create("mongodb://localhost:27017/schedOpenSource"));

            await horarium.CreateRecurrent <TestRecurrentJob>(Cron.SecondInterval(10)).Schedule();

            await new HorariumClient(MongoRepositoryFactory.Create("mongodb://localhost:27017/schedOpenSource"))
            .GetJobStatistic();

            var firstJobDelay = TimeSpan.FromSeconds(20);

            var secondJobDelay = TimeSpan.FromSeconds(15);

            await horarium
            .Create <TestJob, int>(1)  // 1-st job
            .WithDelay(firstJobDelay)
            .Next <TestJob, int>(2)    // 2-nd job
            .WithDelay(secondJobDelay)
            .Next <TestJob, int>(3)    // 3-rd job (global obsolete from settings and no delay will be applied)
            .Schedule();

            await horarium.Create <TestJob, int>(666)
            .WithDelay(TimeSpan.FromSeconds(25))
            .Schedule();

            await Task.Delay(20000);

            await horarium.CreateRecurrent <TestRecurrentJob>(Cron.SecondInterval(15))
            .WithKey(nameof(TestRecurrentJob))
            .Schedule();
        }
        public BaseService()
        {
            var connectionString = new ConnectionStringFactory();
            var mongoRepository  = new MongoRepositoryFactory(connectionString);

            Logger = new Logger(mongoRepository);
        }
Beispiel #3
0
        public Initializer(string connectionString = "mongodb://localhost:27017", string databaseName = "ReqTrack")
        {
            var database = new MongoReqTrackDatabase(connectionString, databaseName);

            RepositoryFactory      = new MongoRepositoryFactory(database);
            SecurityGatewayFactory = new MongoSecurityGatewayFactory(database);
        }
Beispiel #4
0
        protected HorariumServer CreateHorariumServer()
        {
            var dataBase = Environment.GetEnvironmentVariable("DataBase");

            IJobRepository jobRepository;

            switch (dataBase)
            {
            case "MongoDB":
                jobRepository = MongoRepositoryFactory.Create(ConnectionMongo);
                break;

            case "Memory":
                jobRepository = new InMemoryRepository();
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(dataBase), dataBase, null);
            }

            var horarium = new HorariumServer(jobRepository);

            horarium.Start();

            return(horarium);
        }
        public UserRegistrationService(IUserRepository userRepository)
        {
            _userRepository = userRepository;
            var connectionString = new ConnectionStringFactory();
            var mongoRepository  = new MongoRepositoryFactory(connectionString);

            _logger = new Logger(mongoRepository);
        }
Beispiel #6
0
        public WikiController(IUsefulLinkRepository usefulLinkRepository)
        {
            _usefulLinkRepository = usefulLinkRepository;
            var connectionString = new ConnectionStringFactory();
            var mongoRepository  = new MongoRepositoryFactory(connectionString);

            _logger = new Logger(mongoRepository);
        }
        public async Task Create_WellFormedUrl_AccessMongoLazily()
        {
            const string stubMongoUrl = "mongodb://fake-url:27017/fake_database_name/?serverSelectionTimeoutMs=100";

            var mongoRepository = MongoRepositoryFactory.Create(stubMongoUrl);

            await Assert.ThrowsAsync <TimeoutException>(() => mongoRepository.GetJobStatistic());
        }
Beispiel #8
0
        public frmMain()
        {
            InitializeComponent();
            _strapiApi = new StrapiApi();
            var mongoRepositoryFactory = new MongoRepositoryFactory(new ConnectionStringFactory());

            _serverToolsRepository = new ServerToolsRepository(mongoRepositoryFactory);
            _logger = new Logger(mongoRepositoryFactory);
        }
        public CsLogsApi()
        {
            var connectionString = new ConnectionStringFactory();
            var mongoRepository  = new MongoRepositoryFactory(connectionString);

            _attributeList    = Actions.Unknown.GetAttributeList().Where(x => !string.IsNullOrEmpty(x.Value));
            _playerRepository = new PlayerRepository(mongoRepository);
            _logger           = new Logger(mongoRepository);
        }
Beispiel #10
0
        public void LogWarningToMongoDb()
        {
            string message = "TEST MESSAGE";

            var repo         = new MongoRepositoryFactory().CreateRepository();
            var errorFactory = new WarningEntityFactory(message);

            var stringResult = repo.WriteLog(errorFactory);

            var result = this.DeserializeJsonObject <WarningLogEntity>(stringResult);

            Assert.Equal(result.Type, "WARNING");
            Assert.Equal(result.Message, message);
        }
        public Reader(string path, ICsLogsApi parsers, IBaseRepository logRepository,
                      ILogFileRepository logFileRepository, IProgress <string> progress)
        {
            this.path              = path;
            this.parsers           = parsers;
            this.logRepository     = logRepository;
            this.logFileRepository = logFileRepository;
            _progress              = progress;
            _cacheService          = new PlayersCacheService();
            var connectionString = new ConnectionStringFactory();
            var mongoRepository  = new MongoRepositoryFactory(connectionString);

            _logger = new Logger(mongoRepository);
        }
Beispiel #12
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            services.AddHorariumServer(MongoRepositoryFactory.Create("mongodb://localhost:27017/horarium"));

            services.AddSingleton(_ => new MongoContext("mongodb://localhost:27017/peka_db"));

            services.AddSingleton <IPekaRepository, PekaRepository>();
            services.AddSingleton <ICockroachPekaRepository, CockroachPekaRepository>();
            services.AddSingleton <ICounterRepository, CounterRepository>();

            services.AddSingleton <IFcmSender, FcmSender>();
            services.AddSingleton <DailyPekaJob>();
        }
Beispiel #13
0
        private IHorarium CreateScheduler(DataBase dataBase)
        {
            IJobRepository jobRepository;

            switch (dataBase)
            {
            case DataBase.MongoDB:
                jobRepository = MongoRepositoryFactory.Create(ConnectionMongo);
                break;

            default:
                throw new ArgumentOutOfRangeException(nameof(dataBase), dataBase, null);
            }

            var horarium = new HorariumServer(jobRepository);

            horarium.Start();

            return(horarium);
        }
        public void Create_NullMongoUrl_Exception()
        {
            MongoUrl mongoUrl = null;

            Assert.Throws <ArgumentNullException>(() => MongoRepositoryFactory.Create(mongoUrl));
        }
        public void Create_NullConnectionString_Exception()
        {
            string connectionString = null;

            Assert.Throws <ArgumentNullException>(() => MongoRepositoryFactory.Create(connectionString));
        }
Beispiel #16
0
        /// <summary>
        /// Değişiklikleri kaydet.
        /// </summary>
        /// <returns></returns>
        public int SaveChanges()
        {
            bool throwAnError =
                !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("THROW_UNIT_OF_WORK_ERROR"))
                    ? bool.Parse(Environment.GetEnvironmentVariable("THROW_UNIT_OF_WORK_ERROR"))
                    : false;
            int result = -1;

            try
            {
                using (TransactionScope tScope = new TransactionScope())
                {
                    List <HistoryCollectionModel> history = null;
                    if (_unitOfWorkSettings.ChangeDataCapture)
                    {
                        history = ChangeDataCapture();
                    }

                    result = DbContext.SaveChanges();
                    tScope.Complete();

                    if (history != null && history.Count > 0)
                    {
                        using (var mongoRepo = MongoRepositoryFactory.CreateMongoRepository <HistoryCollectionModel>())
                        {
                            mongoRepo.BulkInsert(history);
                        }
                    }
                }
            }
            catch (ValidationException ex)
            {
                string errorString = ex.Message;
                ErrorMessageList.Add(errorString);
                if (throwAnError)
                {
                    throw;
                }
            }
            catch (DbUpdateException ex)
            {
                string errorString = ex.Message;
                if (ex.InnerException != null)
                {
                    errorString += ex.InnerException.Message;
                    if (ex.InnerException.InnerException != null)
                    {
                        errorString += ex.InnerException.InnerException.Message;
                    }
                }

                ErrorMessageList.Add(errorString);
                if (throwAnError)
                {
                    throw;
                }
            }
            catch (Exception ex)
            {
                ErrorMessageList.Add(ex.Message);
                if (throwAnError)
                {
                    throw;
                }
            }
            finally
            {
                if (result == -1)
                {
                    ElasticLogger.Instance.Info(
                        $"UnitOfWork Save Error. Type : {typeof(T).Name} Error Messages : {JsonConvert.SerializeObject(ErrorMessageList)}");
                }
            }

            return(result);
        }