public CurrencyConversionController(ILoader loader)
 {
     _currencyConversionService = new CurrencyConversionService(loader);
     _dateChecker         = new DateChecker();
     _dateRange           = new DateRange(loader);
     _currencyNameChecker = new CurrencyNameChecker();
 }
示例#2
0
 public CurrencyComparisionController(ILoader loader)
 {
     _currenciesComparator = new CurrenciesComparator(loader);
     _dateChecker          = new DateChecker();
     _dateRange            = new DateRange(loader);
     _currencyNameChecker  = new CurrencyNameChecker();
 }
        public List <SailingBoat> GetAvailableBoats(DateTime reservationDate, TimeSpan duration)
        {
            var boats          = _boatService.GetAllBoats();
            var availableBoats = new List <SailingBoat>();

            foreach (var boat in boats)
            {
                var available = true;

                if ((BoatState)boat.Status != BoatState.InService)
                {
                    foreach (var reserv in boat.SailingReservations)
                    {
                        if (!DateChecker.AvailableOn(reserv.Date, reserv.Duration, reservationDate, duration))
                        {
                            available = false;
                        }
                    }

                    if (available)
                    {
                        availableBoats.Add(boat);
                    }
                }
            }

            return(availableBoats);
        }
示例#4
0
        private static void Main(string[] args)
        {
            DateChecker ch    = new DateChecker("0", "0", "1", "*", "*");
            DateTime    timer = DateTime.Now;

            for (int i = 0; i < 10000; i++)
            {
                try
                {
                    DateTime dt = ch.GetNextDate(DateTime.Now);
                    if (i == 0)
                    {
                        Console.WriteLine(dt);
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }



            Console.WriteLine("{0} ms ", (DateTime.Now - timer).TotalMilliseconds);

            Console.ReadKey();
        }
        /// <summary>
        ///     A function to check if a reservation is valid
        /// </summary>
        /// <param name="date">Starting DateTime of reservation</param>
        /// <param name="duration">Duration of the reservation</param>
        /// <param name="reservationService">Reservation service to check if there are more than 2 reservations already</param>
        /// <param name="accountId">The account to check</param>
        /// <returns>A message to indicate if a reservation is valid with info why or why not</returns>
        public static ReservationConstraintsMessage IsValid(DateTime date, TimeSpan duration,
                                                            IReservationService reservationService, int accountId)
        {
            if (date < DateTime.Now || date + duration < DateTime.Now)
            {
                return(new ReservationConstraintsMessage(false, "Reservatie is in het verleden."));
            }
            if (duration > TimeSpan.FromHours(2))
            {
                return(new ReservationConstraintsMessage(false, "Reservatie is te lang (max 2 uur)."));
            }
            if (reservationService.GetFutureReservations(accountId).Count >= 2)
            {
                return(new ReservationConstraintsMessage(false,
                                                         "U heeft al teveel reservaties geplaatst voor de toekomst."));
            }
            if (!DayChecker.IsDay(date, duration))
            {
                return(new ReservationConstraintsMessage(false,
                                                         "Reservaties kunnen alleen tijdens de dag geplaatst worden."));
            }
            if (reservationService.GetFutureReservations(accountId)
                .Any(x => !DateChecker.AvailableOn(x.Date, x.Duration, date, duration)))
            {
                return(new ReservationConstraintsMessage(false,
                                                         "De reservering overlapt met een al bestaande reservering."));
            }

            return(new ReservationConstraintsMessage(true, "All is fine"));
        }
示例#6
0
文件: Create.cs 项目: dusty3ntity/Log
            public async Task <LearningListDto> Handle(Command request, CancellationToken cancellationToken)
            {
                var dictionary = await _context.Dictionaries.FindAsync(request.DictionaryId);

                if (dictionary == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, ErrorType.DictionaryNotFound);
                }

                var learningList = await _context.LearningLists
                                   .Where(l => l.DictionaryId == request.DictionaryId)
                                   .Include(l => l.LearningItems)
                                   .FirstOrDefaultAsync();

                if (learningList != null)
                {
                    if (!DateChecker.IsLearningListOutdated(learningList))
                    {
                        return(_mapper.Map <LearningList, LearningListDto>(learningList));
                    }
                    await _learningListRemover.Remove(learningList);
                }

                learningList = await _learningListGenerator.HandleGeneration(dictionary);

                _context.LearningLists.Add(learningList);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(_mapper.Map <LearningList, LearningListDto>(learningList));
                }
                throw new RestException(HttpStatusCode.InternalServerError, ErrorType.SavingChangesError);
            }
示例#7
0
 public void AvailibilityTest(string a_start, int a_duration, string b_start, int b_duration, bool expected)
 {
     Assert.AreEqual(expected, DateChecker.AvailableOn(DateTime.Parse(a_start),
                                                       TimeSpan.FromMinutes(a_duration),
                                                       DateTime.Parse(b_start),
                                                       TimeSpan.FromMinutes(b_duration)
                                                       ));
 }
        public void DateRangeIsValid_StartDateCannotBeInThePast_ThrowsArgumentException(DateTime startDate, DateTime endDate)
        {
            //Object to test
            DateChecker dc = new DateChecker();

            //Test parameters
            //DateTime startDate = DateTime.Now.AddDays(-14);
            //DateTime endDate = DateTime.Today.AddDays(7);
            //Test
            Assert.Throws <ArgumentException>(() => dc.DateRangeIsValid(startDate, endDate));
        }
        public void DateRangeIsValid_EndDateIsNotOnStartDate_ThrowsArgumentException(DateTime startDate, DateTime endDate)
        {
            //Object to test
            DateChecker dc = new DateChecker();

            //Test parameters
            //DateTime startDate = DateTime.Today.AddDays(14);
            //DateTime endDate = DateTime.Today.AddDays(14);
            //Test
            Assert.Throws <ArgumentException>(() => dc.DateRangeIsValid(startDate, endDate));
        }
    void Start()
    {
        maincam           = Camera.main;
        dateCheckerScript = maincam.gameObject.GetComponent <DateChecker>();

        //Store the current time when it starts
        currentDate = System.DateTime.Now;

        refreshTime();
        coroutine = WaitAndUpdate(1.0f);
        StartCoroutine(coroutine);
    }
示例#11
0
 private void Awake()
 {
     if (DateChecker.instance == null)
     {
         instance = this;
     }
     else
     {
         Debug.Log("An instance of DateChecker already exists. Calling Destroy(gameObject) on the duplicate instance");
         Destroy(gameObject);
     }
 }
        public void DateRangeIsValid_StartdateCanBeToday_ThrowsArgumentException(DateTime startDate, DateTime endDate)
        {
            //Object to test
            DateChecker dc = new DateChecker();
            //Test parameters
            //DateTime startDate = DateTime.Today;
            //DateTime endDate = DateTime.Today.AddDays(7);
            //Test
            var actualResult   = dc.DateRangeIsValid(startDate, endDate);
            var expectedResult = true;

            Assert.Equal(expectedResult, actualResult);
        }
示例#13
0
 private void Awake()
 {
     m_Canvas.gameObject.SetActive(true);
     m_UI.transform.position     = m_UIStartPosition.position;
     m_PrincessIconStartPosition = m_PrincessIcon.position;
     m_PrincessGoToPosition      = m_PrincessIconStartPosition;
     m_Instance     = this;
     m_MoveToCrown  = false;
     GetObjectPool  = GetComponent <ObjectPool>();
     GetScoreSystem = GetComponent <ScoreSystem>();
     GetEventSystem = GetComponent <EventsSystem>();
     m_DateChecker  = GetComponent <DateChecker>();
     GetEventSystem.m_PrincessCaughtEvent += PrincessCaught;
 }
示例#14
0
            public async Task <Unit> Handle(Command request, CancellationToken cancellationToken)
            {
                var dictionary = await _context.Dictionaries.FindAsync(request.DictionaryId);

                if (dictionary == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, ErrorType.DictionaryNotFound);
                }

                var learningList = await _context.LearningLists
                                   .Where(l => l.DictionaryId == request.DictionaryId)
                                   .Include(l => l.LearningItems)
                                   .FirstOrDefaultAsync();

                if (learningList == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, ErrorType.LearningListNotFound);
                }

                if (DateChecker.IsLearningListOutdated(learningList))
                {
                    throw new RestException(HttpStatusCode.Gone, ErrorType.LearningListOutdated);
                }

                if (learningList.TimesCompleted == 0 || !learningList.IsCompleted)
                {
                    throw new RestException(HttpStatusCode.BadRequest, ErrorType.LearningListNotCompleted);
                }

                if (learningList.TimesCompleted == 2)
                {
                    throw new RestException(HttpStatusCode.BadRequest, ErrorType.LearningListCompletedTwoTimes);
                }

                learningList.IsCompleted         = false;
                learningList.CompletedItemsCount = 0;

                var learningItemsList = learningList.LearningItems.ToList();

                LearningListShuffler.Shuffle(learningItemsList);

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return(Unit.Value);
                }
                throw new RestException(HttpStatusCode.InternalServerError, ErrorType.SavingChangesError);
            }
示例#15
0
    void Awake()
    {
        if (!_instance)
        {
            DontDestroyOnLoad(this.gameObject);
            _instance = this;
        }
        else
        {
            Destroy(this.gameObject);

            // 再開処理
            LoadData();
        }
    }
示例#16
0
        public MainForm(DateChecker dateChecker)
        {
            InitializeComponent();
            //numericUpDownSum.Controls[0].Visible = false;
            numericUpDownSum.Controls.RemoveAt(0);

            this.dateChecker = dateChecker;
            ConnectionManager connectionManager = new ConnectionManager();

            this.Load           += MainForm_CalcBalance;
            this.VisibleChanged += MainForm_CalcBalance;

            this.Load           += MainForm_UpdateDiagram;
            this.VisibleChanged += MainForm_UpdateDiagram;
        }
示例#17
0
        private void calculateTargetHours(InputChangedEventArgs dateChangedEventArgs)
        {
            DateChecker dc = new DateChecker();

            TargetHours = TimeSpan.Zero;
            TimeSpan duration = dateChangedEventArgs.Till - dateChangedEventArgs.From;

            foreach (var day in EachDay(dateChangedEventArgs.From, dateChangedEventArgs.Till))
            {
                if (dc.IsWorkday(day))
                {
                    TargetHours = TargetHours.Add(TimeSpan.FromHours(8));
                }
            }
        }
        public MainForm()
        {
            InitializeComponent();
            Logger.CreateCommonLogFile();

            KeyPreview = true;

            DelayInfo = FileService.LoadData <DelayInfo>(DELAY_SETTINGS_FILE_PATH);

            DateCheckers = DateChecker.CreateFromPlatformInfos <DateChecker>(
                Platforms, DelayInfo,
                Checker_OnRequestError,
                Checker_OnRequestOk
                );

            InitBrowsers();

            PlatformSelector.Items.AddRange(Platforms);
            PlatformSelector.SelectedIndex = 0;

            Orders   = FileService.LoadData <List <ReservationOrder> >(ORDERS_FILE_PATH);
            Reserved = FileService.LoadData <List <ReservedInfo> >(OUTPUT_FILE_PATH);
            Schedule = FileService.LoadData <BootSchedule>(SCHEDULE_FILE_PATH);

            Profile        = FileService.LoadData <Profile>(PROFILE_FILE_PATH);
            LogChatId.Text = Profile?.TelegramChatId;

            CommonSettings commonSettings = FileService.LoadData <CommonSettings>(COMMON_SETTINGS_FILE_PATH);

            ApplyCommonSettings(commonSettings);

            SavedBrowserSettings = FileService.LoadData <List <BrowserSettings> >(BROWSER_SETTINGS_FILE_PATH);
            foreach (BrowserSettings settings in SavedBrowserSettings)
            {
                if (settings.BrowserNumber < 0 || settings.BrowserNumber >= Reservers.Count)
                {
                    continue;
                }

                Reservers[settings.BrowserNumber].ApplySettings(settings);
            }

            UpdateDateCheckersFlowStrategy();

            //TryLogIn();
        }
示例#19
0
            public async Task <LearningItemDto> Handle(Query request,
                                                       CancellationToken cancellationToken)
            {
                var dictionary = await _context.Dictionaries.FindAsync(request.DictionaryId);

                if (dictionary == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, ErrorType.DictionaryNotFound);
                }

                var learningList = await _context.LearningLists.FindAsync(request.LearningListId);

                if (learningList == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, ErrorType.LearningListNotFound);
                }

                if (DateChecker.IsLearningListOutdated(learningList))
                {
                    throw new RestException(HttpStatusCode.Gone, ErrorType.LearningListOutdated);
                }

                if (learningList.IsCompleted)
                {
                    return(null);
                }

                var learningItem = await _context.LearningItems
                                   .Where(i =>
                                          i.LearningListId == learningList.Id &&
                                          i.NumberInSequence == learningList.CompletedItemsCount)
                                   .Include(i => i.Item)
                                   .FirstAsync();

                var itemToReturn = new LearningItemDto
                {
                    Id = learningItem.Id,

                    NumberInSequence = learningItem.NumberInSequence,
                    LearningMode     = learningItem.LearningMode,

                    Item = TestItemCreator.Create(learningItem)
                };

                return(itemToReturn);
            }
示例#20
0
        static void ConfigureServices(IDocumentStoreRepository documentStoreRepository, IPublicTransportRepository publicTransportRepository)
        {
            var converter         = new Converter();
            var filterHelper      = new FilterHelper();
            var helperTimeService = new TimeService();
            var convertingHelper  = new ConvertingHelper(converter, filterHelper, documentStoreRepository);
            var stopTimesService  = new StopTimesService(documentStoreRepository, publicTransportRepository);
            var downloadHelper    = new DownloadHelper(documentStoreRepository, helperTimeService, publicTransportRepository);
            var timeTableService  = new TimeTableService(documentStoreRepository, helperTimeService, convertingHelper, stopTimesService, downloadHelper);

            var polandPublicHoliday    = new PolandPublicHoliday();
            var dateChecker            = new DateChecker(polandPublicHoliday);
            var stopTimesFetcher       = new StopTimesFetcher(dateChecker, documentStoreRepository);
            var minuteTimeTableBuilder = new MinuteTimeTableBuilder(stopTimesFetcher);
            var minuteTimeTableService = new MinuteTimeTableService(minuteTimeTableBuilder, documentStoreRepository);

            UpdateTimeTableService.Init(timeTableService, minuteTimeTableService);
        }
示例#21
0
        public BookingManagerTests()
        {
            connection = new SqliteConnection("DataSource=:memory:");

            // In-memory database only exists while the connection is open
            connection.Open();

            // Initialize test database
            var options = new DbContextOptionsBuilder <HotelBookingContext>()
                          .UseSqlite(connection).Options;
            var dbContext = new HotelBookingContext(options);

            DbInitializer.Initialize(dbContext);

            // Create repositories and BookingManager
            var bookingRepos = new BookingRepository(dbContext);
            var roomRepos    = new RoomRepository(dbContext);
            var dateChecker  = new DateChecker();

            bookingManager = new BookingManager(bookingRepos, roomRepos, dateChecker);
        }
 public ReservationController()
 {
     _datechecker = new DateChecker();
     _context     = new ApplicationDbContext();
 }
        private void Checker_OnRequestError(object sender, DateCheckerErrorEventArgs e)
        {
            DateChecker checker = sender as DateChecker;

            Log($"Date check error at checker {checker.CityInfo.Name} : {checker.OperationInfo}; Code: {e.ErrorCode}; Check your VPN and internet connection!", null);
        }
        private void Checker_OnRequestOk(object sender, DateCheckerOkEventArgs e)
        {
            DateChecker checker = sender as DateChecker;

            Log($"Date check ok at checker {checker.CityInfo.Name} : {checker.OperationInfo}; Content: {e.Content}", null);
        }
示例#25
0
            public async Task <LearningItemResult> Handle(Command request, CancellationToken cancellationToken)
            {
                var dictionary = await _context.Dictionaries.FindAsync(request.DictionaryId);

                if (dictionary == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, ErrorType.DictionaryNotFound);
                }

                var learningList = await _context.LearningLists.FindAsync(request.LearningListId);

                if (learningList == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, ErrorType.LearningListNotFound);
                }

                if (DateChecker.IsLearningListOutdated(learningList))
                {
                    throw new RestException(HttpStatusCode.Gone, ErrorType.LearningListOutdated);
                }

                var learningItem = await _context.LearningItems
                                   .Where(i => i.Id == request.LearningItemId)
                                   .Include(i => i.Item)
                                   .FirstOrDefaultAsync();

                if (learningItem == null)
                {
                    throw new RestException(HttpStatusCode.NotFound, ErrorType.LearningItemNotFound);
                }

                if (learningItem.NumberInSequence != learningList.CompletedItemsCount)
                {
                    throw new RestException(HttpStatusCode.NotFound, ErrorType.LearningItemNotFound);
                }

                var answer = request.Answer.ToLower();
                var item   = learningItem.Item;

                var isAnswerCorrect = learningItem.LearningMode == LearningMode.Primary
                    ? answer.ToLower().Equals(item.Original.ToLower())
                    : answer.ToLower().Equals(item.Translation.ToLower());

                if (isAnswerCorrect)
                {
                    learningList.CorrectAnswersCount++;
                }

                ItemAnswerProcessor.ProcessItemAnswer(dictionary, learningList, learningItem, isAnswerCorrect);

                learningList.CompletedItemsCount++;
                learningList.TotalCompletedItemsCount++;

                if (learningList.Size == learningList.CompletedItemsCount)
                {
                    learningList.CompletedItemsCount = 0;
                    learningList.IsCompleted         = true;
                    learningList.TimesCompleted++;
                }

                var success = await _context.SaveChangesAsync() > 0;

                if (success)
                {
                    return new LearningItemResult
                           {
                               IsAnswerCorrect  = isAnswerCorrect,
                               UserAnswer       = request.Answer ?? "",
                               NumberInSequence = learningItem.NumberInSequence,

                               Item = new TestItemAnswer
                               {
                                   Id     = item.Id,
                                   Item   = learningItem.LearningMode == LearningMode.Primary ? item.Translation : item.Original,
                                   Answer = learningItem.LearningMode == LearningMode.Primary
                                ? item.Original
                                : item.Translation,
                                   Definition       = item.Definition,
                                   DefinitionOrigin = item.DefinitionOrigin,
                                   Type             = item.Type,

                                   IsStarred = item.IsStarred,
                                   IsLearned = item.IsLearned,
                                   CorrectAnswersToCompletionCount = item.CorrectAnswersToCompletionCount,
                               }
                           }
                }
                ;
                throw new RestException(HttpStatusCode.InternalServerError, ErrorType.SavingChangesError);
            }
        }
示例#26
0
 public LocalExtremeController(ILoader loader)
 {
     _extremeServices = new ExtremesServices(loader);
     _dateChecker     = new DateChecker();
     _dateRange       = new DateRange(loader);
 }