示例#1
0
        static void Main(string[] args)
        {
            UInt32 errorCode = RmsAdapter.GetSerializedLicenseFromFile(@"C:\Temp\p.docx");
            string message   = RmsAdapter.GetErrorMessage(errorCode);

            Console.WriteLine(message);
            Console.ReadLine();
        }
示例#2
0
        public GroupCalcInput GetCalcInputForIndex(RmsAdapter rmsAdapter, Dictionary <int, string> roomsNumber, Dictionary <int, string> mealsNumber)
        {
            var            result = rmsAdapter.GetGroupCalculationResult();
            GroupCalcInput gc     = new GroupCalcInput();

            gc.Start  = DateTime.Today;
            gc.End    = DateTime.Today;
            gc.Inputs = new List <GroupCalcDayInput> {
                GetNewInput(DateTime.Today, roomsNumber, mealsNumber, result)
            };
            return(gc);
        }
示例#3
0
        public async Task <RmsAdapter> InitRmsAdapter(DateTime start, DateTime end, int hotelId, RmsDbContext db)
        {
            return(await
                   Task.Run(() =>
            {
                HotelSettings hotel = db.HotelSettings.Find(hotelId);

                if (hotel == null || !hotel.IsRmsEnalbed)
                {
                    return null;
                }
                var calculations = new List <Calculation>();
                for (var s = start.Date; s <= end.Date; s = s.AddDays(1))
                {
                    calculations.Add(db.Calculations.Where(c => c.HotelId == hotelId && DbFunctions.TruncateTime(c.PredictionDate) == s).OrderByDescending(c => c.CalculatedOn).FirstOrDefault());
                }
                IEnumerable <Reservation> reservations = db.Reservations.Where(r => r.HotelId == hotelId && (r.CheckInDate <= end.Date && DbFunctions.AddDays(r.CheckInDate, r.DaysCount - 1) >= start.Date)).ToList();
                IEnumerable <Reservation> groupReservations = db.Reservations.Where(r => r.HotelId == hotelId && r.ReservationType == ReservationType.Group).ToList();
                var rmsAdapter = new RmsAdapter();
                rmsAdapter.RunGroupCalculation(start, end, reservations, groupReservations, calculations, hotel.Settings);
                return rmsAdapter;
            }));
        }
示例#4
0
        public GroupCalcInput GetInputPartialView(GroupCalcInput viewModel, RmsAdapter rmsAdapter)
        {
            var roomInfoResult = rmsAdapter.GetGroupCalculationResult();

            if (viewModel.Inputs != null && viewModel.Inputs.Any() && viewModel.Inputs[0].RoomTypes.Any())
            {
                var roomTotal = viewModel.Inputs[0].RoomTypes.ToDictionary(c => Convert.ToInt32(c.Key), c => c.Value.Name);
                var mealTotal = new Dictionary <int, string>();
                if (viewModel.Inputs[0].MealTypes != null && viewModel.Inputs[0].MealTypes.Any())
                {
                    mealTotal = viewModel.Inputs[0].MealTypes.ToDictionary(c => Convert.ToInt32(c.Key), c => c.Value.Name);
                }
                for (DateTime i = viewModel.Start; i <= viewModel.End; i = i.AddDays(1))
                {
                    if (!viewModel.Inputs.Any(c => c.Date == i))
                    {
                        viewModel.Inputs.Add(GetNewInput(i, roomTotal, mealTotal, roomInfoResult.Where(c => c.Date == i)));
                    }
                }
                viewModel.Inputs.RemoveAll(c => c.Date < viewModel.Start || viewModel.End < c.Date);
            }
            viewModel.Inputs = viewModel.Inputs.OrderBy(c => c.Date).ToList();
            return(viewModel);
        }
        public void Run(int hotelId)
        {
            using (var context = new RmsDbContext())
            {
                HotelSettings hotel = context.HotelSettings.Find(hotelId);

                if (hotel == null || !hotel.IsRmsEnalbed)
                {
                    RecurringJob.RemoveIfExists(GetJobName(hotelId));
                    return;
                }

                if (string.IsNullOrWhiteSpace(hotel.Settings))
                {
                    context.Logs.Add(new Log {
                        LogType = LogType.Error, CreatedOn = DateTime.Now, Body = "Configuration not found.", HotelId = hotelId
                    });
                    context.SaveChanges();
                    return;
                }

                //Calculation lastCalculation = context.Calculations.Where(c => c.HotelId == hotelId).OrderByDescending(c => c.CalculatedOn).FirstOrDefault();

                //if ((lastCalculation == null && context.Reservations.Any(r => r.HotelId == hotelId)) ||
                //    (lastCalculation != null && context.Reservations.Any(r => r.HotelId == hotelId && r.CreatedOn > lastCalculation.CalculatedOn)))
                if (hotel.IsNeedRecalc)
                {
                    IEnumerable <Reservation> reservations = context.Reservations.Where(r => r.HotelId == hotelId).ToList();
                    IEnumerable <Event>       events       = context.Events.Where(r => r.HotelId == hotelId).ToList();

                    IEnumerable <Parser_RoomData> actualParserData = new List <Parser_RoomData>();
                    if (context.Parser_RoomDatas.Any(r => r.Parser_RoomInfo.HotelId == hotelId))
                    {
                        var lastDate = context.Parser_RoomDatas.Where(r => r.Parser_RoomInfo.HotelId == hotelId).Max(r => r.CreationDate);
                        actualParserData = context.Parser_RoomDatas.Where(r => r.Parser_RoomInfo.HotelId == hotelId && r.CreationDate == lastDate).ToList();
                    }

                    IEnumerable <Inflation> inflations = context.Inflations.ToList();

                    IRmsAdapter rmsAdapter   = new RmsAdapter();
                    string      startDateStr = ConfigurationManager.AppSettings["start_date"];
                    DateTime    startDate    = DateTime.Now;
                    if (!string.IsNullOrEmpty(startDateStr))
                    {
                        startDate = DateTime.ParseExact(startDateStr, "dd.MM.yyyy", null);
                    }
                    var result = rmsAdapter.Run(startDate, hotel.PlanningHorizon, hotel.HistoryPeriod, reservations, inflations, events, actualParserData, hotel.Settings, hotel.BookingRating).ToList();

                    var calculatedOn = DateTime.Now;
                    foreach (Calculation calculation in result)
                    {
                        calculation.CalculatedOn = calculatedOn;
                        calculation.HotelId      = hotel.Id;
                        calculation.Settings     = hotel.Settings;
                    }

                    if (result.Any())
                    {
                        context.Calculations.AddRange(result);
                        context.Logs.Add(new Log {
                            LogType = LogType.Info, CreatedOn = DateTime.Now, Body = "New predictions have been successfully calculated.", HotelId = hotelId
                        });
                        hotel.IsNeedRecalc = false;
                        context.SaveChanges();
                    }
                }
                else
                {
                    context.Logs.Add(new Log {
                        LogType = LogType.Info, CreatedOn = DateTime.Now, Body = "New data not found for calculate predictions.", HotelId = hotelId
                    });
                    context.SaveChanges();
                }
            }
        }