Example #1
0
        public ActionResult MoveToArchives(int id)
        {
            User    user    = UserService.GetUserByEmail(User.Identity.Name);
            Auction auction = AuctionService.GetByID(id);

            if (auction == null || auction.Auto.UserID != user.ID)
            {
                return(HttpNotFound());
            }

            try
            {
                bool moveManually = true;
                AuctionService.Finish(auction, moveManually);
                HangfireService.CancelJob(auction.CompletionJobID);
                HangfireService.CancelJob(auction.DeletionJobID);
            }
            catch
            {
                return(HttpNotFound());
            }

            Thread.Sleep(1000);
            return(RedirectToAction("Index", "MyAuto"));
        }
        public HangfireServiceTests()
        {
            _mockStorageConnection = new Mock <IStorageConnection>();
            _mockMonitoringApi     = new Mock <IMonitoringApi>();

            var mockStorage = new Mock <JobStorage>();

            mockStorage.Setup(x => x.GetConnection()).Returns(_mockStorageConnection.Object);
            mockStorage.Setup(x => x.GetMonitoringApi()).Returns(_mockMonitoringApi.Object);

            _hangfire = new HangfireService(mockStorage.Object);
        }
Example #3
0
        public async Task CancelExpiredReservationsAsync_ShouldReturnCorrectResult()
        {
            var context = ApplicationDbContextInMemoryFactory.InitializeContext();
            var seeder  = new DbContextTestsSeeder();
            await seeder.SeedReservationsAsync(context);

            var reservationsRepository = new EfDeletableEntityRepository <Reservation>(context);
            var transfersRepository    = new EfDeletableEntityRepository <Transfer>(context);
            var hangfireService        = new HangfireService(reservationsRepository, transfersRepository);

            var result = await hangfireService.CancelExpiredReservationsAsync();

            Assert.True(result == 2, ErrorMessage);
        }
 public ActionResult Create(Monitoring monitoring)
 {
     try
     {
         monitoring.UserId    = User.Identity.GetUserId();
         monitoring.UserEmail = User.Identity.GetUserName();
         monitoring           = _monitoringRepository.Create(monitoring);
         RecurringJob.AddOrUpdate(monitoring.Id.ToString(), () => HangfireService.CheckTickets(monitoring), Cron.Minutely);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
Example #5
0
        public ActionResult FinishManually(int id)
        {
            try
            {
                Auction auction        = AuctionService.GetByID(id);
                bool    finishManually = true;
                AuctionService.Finish(auction, finishManually);
                HangfireService.CancelJob(auction.CompletionJobID);

                return(Json(new { result = "success" }));
            }
            catch (Exception ex)
            {
                return(Json(new { result = "Error: " + ex.Message }));
            }
        }
        public ActionResult Heartbeat()
        {
            // Re-Load the configuration
            ConfigurationService.Load();

            // Log the service state
            LogService.Info("Heartbeat requested!");

            // Hangfire
            HangfireBootstrapper.Instance.Start();

            // Log the service state
            LogService.Info("Hangfire re-started!");

            // Register the main job
            RecurringJob.AddOrUpdate("Daily Job Registration", () => HangfireService.UpdateJobs(), Cron.Daily);

            // Log the service state
            LogService.Info("Daily job registration service updated! Lub-dub!");

            return(Json("lub-dub", JsonRequestBehavior.AllowGet));
        }
Example #7
0
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            // Load the configuration
            ConfigurationService.Load();

            // Log the application initialization
            LogService.Debug("Lidia Scheduler UI initialized");

            // Hangfire
            HangfireBootstrapper.Instance.Start();

            // Register the main job
            RecurringJob.AddOrUpdate("Daily Job Registration", () => HangfireService.UpdateJobs(), Cron.Daily);

            #region [ Dependency Injection ]

            // Create the container as usual.
            var container = new ServiceContainer();
            var lifeTime  = new PerRequestLifeTime();

            // Register your types, for instanceScoped);
            container.Register <ITenantService, TenantService>(lifeTime);
            container.Register <IUserService, UserService>(lifeTime);
            container.Register <ISchedulerService, SchedulerService>(lifeTime);

            container.RegisterControllers();

            container.EnableMvc();

            #endregion
        }
Example #8
0
        public ActionResult MoveToArchives(int id)
        {
            User user = _userService.GetUserByEmail(User.Identity.Name);
            Auto auto = user.Autoes.FirstOrDefault(a => a.ID == id);

            if (auto == null)
            {
                return(HttpNotFound());
            }

            try
            {
                bool moveManually = true;
                _autoService.MoveToArchives(auto, moveManually);
                HangfireService.CancelJob(auto.CompletionJobID);
            }
            catch
            {
                return(HttpNotFound());
            }

            Thread.Sleep(1000);
            return(RedirectToAction("Index", new { statusID = 3 }));
        }
Example #9
0
        public ActionResult Publish(int id, int top, int days, bool balanceUsed = false)
        {
            User user = _userService.GetUserByEmail(User.Identity.Name);
            Auto auto = user.Autoes.FirstOrDefault(a => a.ID == id);

            if (auto == null)
            {
                return(HttpNotFound());
            }

            decimal oncePayedCost = 50;

            decimal.TryParse(XCarsConfiguration.AutoPublishOncePayedCost, out oncePayedCost);
            decimal price          = _billingService.GeneratePriceForAutoPublishing(oncePayedCost, top, days);
            decimal totalToBePayed = price;

            if (balanceUsed && user.Balance > 0)
            {
                totalToBePayed = price - user.Balance;
            }
            if (totalToBePayed < 0)
            {
                totalToBePayed = 0;
            }

            //create order
            int merchantID = 0;

            int.TryParse(XCarsConfiguration.LMI_MERCHANT_ID, out merchantID);

            int lmi_mode = 0;

            int.TryParse(XCarsConfiguration.LMI_MODE, out lmi_mode);

            try
            {
                PurchaseType purchaseType       = PurchaseTypeService.GetByID(1);
                string       paymentDescription = purchaseType?.Name ?? "autoPublish";

                Order order = new Order()
                {
                    LMI_MERCHANT_ID    = merchantID,
                    LMI_PAYMENT_AMOUNT = totalToBePayed,
                    LMI_MODE           = lmi_mode,
                    UserID             = user.ID,
                    DateCreated        = DateTime.Now,
                    PurchaseTypeID     = 1,
                    ObjectID           = auto.ID,
                    IsOpen             = true
                };

                OrderService.Create(order);

                order.LMI_HASH = Hash.GetHash(order.LMI_MERCHANT_ID + order.LMI_PAYMENT_NO + order.LMI_PAYMENT_AMOUNT.ToString().Replace(',', '.') + XCarsConfiguration.LMI_secretKey);

                if (price == totalToBePayed)
                {
                    order.UsedFromBalance = 0;
                }
                else if (price > totalToBePayed)
                {
                    order.UsedFromBalance = price - totalToBePayed;
                }

                order.OrderDetails.Add(new OrderDetail()
                {
                    Name = "top", Value = top.ToString()
                });
                order.OrderDetails.Add(new OrderDetail()
                {
                    Name = "days", Value = days.ToString()
                });

                OrderService.Edit(order);

                string successUrl = XCarsConfiguration.AutoPublishSuccessUrl;
                string failUrl    = XCarsConfiguration.AutoPublishPaymentFailUrl;

                if (totalToBePayed > 0)
                {
                    Uri    url         = new Uri(Request.Url.AbsoluteUri);
                    string hostAndPort = url.GetLeftPart(UriPartial.Authority);

                    return(Json(new
                    {
                        LMI_MERCHANT_ID = merchantID,
                        LMI_PAYMENT_NO = order.LMI_PAYMENT_NO,
                        LMI_PAYMENT_DESC = paymentDescription,
                        LMI_SUCCESS_URL = hostAndPort + successUrl,
                        LMI_FAIL_URL = hostAndPort + failUrl,
                        LMI_HASH = order.LMI_HASH
                    }));
                }
                else
                {
                    order.IsOpen = false;
                    OrderService.Edit(order);

                    user.Balance -= price;

                    //DateTime dateExpires = DateTime.Now.AddDays(days);
                    DateTime dateExpires = DateTime.Now.AddMinutes(2);
                    _autoService.Publish(auto, dateExpires);
                    _userService.EditUser(user);
                    auto.CompletionJobID = HangfireService.CreateJobForAuto(auto);
                    auto.Top             = top;
                    _autoService.Edit(auto);

                    return(Json(new { ok = 1, successUrl = successUrl }));
                }
            }
            catch (Exception ex)
            {
                return(Json(new { error = ex.Message }));
            }
        }
Example #10
0
 public RecurringModule(HangfireService hangfire)
 {
     _hangfire = hangfire;
 }
Example #11
0
 public CronModule(HangfireService hangfire)
 {
     _hangfire = hangfire;
 }
Example #12
0
 public TarefaBase(ILogger logger = null)
 {
     _util    = new Util(logger);
     _service = new HangfireService();
 }
Example #13
0
        public async Task <ActionResult> Register()
        {
            HangfireService.RegisterJobs();

            return(Json(new { Type = 200 }, JsonRequestBehavior.AllowGet));
        }
Example #14
0
 public PessoaTarefaTests()
 {
     HangfireService.InicializaHangfire();
 }
 /// <summary>
 /// Método responsável por instanciar os Jobs e colocar em execução.
 /// </summary>
 public static void Rodar()
 {
     HangfireService.InicializaHangfire();
     new PessoaTarefa().Rodar();
 }
 public ReminderController(ReminderDbContext context, EmailService emailService, HangfireService hangfireService)
 {
     this.context         = context;
     this.emailService    = emailService;
     this.hangfireService = hangfireService;
 }
Example #17
0
        public ActionResult Create(AuctionCreateVM modelVM)
        {
            User user = UserService.GetUserByEmail(User.Identity.Name);
            Auto auto = user?.Autoes.FirstOrDefault(a => a.ID == modelVM.AutoID);

            if (auto == null)
            {
                return(HttpNotFound());
            }

            Auction auction = AuctionService.GetUnactive(modelVM.ID);

            if (auction == null || auction.AutoID != auto.ID)
            {
                return(HttpNotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    //auction.AutoID = modelVM.AutoID;
                    auction.StartPrice   = modelVM.StartPrice;
                    auction.CurrentPrice = modelVM.StartPrice;
                    auction.CurrencyID   = modelVM.CurrencyID;
                    auction.Description  = modelVM.Description;
                    auction.DateCreated  = DateTime.Now;
                    auction.Deadline     = DateTime.Now.AddHours(modelVM.Hours + modelVM.Days * 24);
                    //auction.Deadline = DateTime.Now.AddMinutes(modelVM.Hours);
                    //auction.Deadline = DateTime.Now.AddMinutes(2);
                    auction.StatusID = 2;

                    List <AuctionBid> bids = auction.AuctionBids.ToList();
                    foreach (var item in bids)
                    {
                        AuctionBidService.Delete(item);
                    }

                    //AuctionService.Edit(auction);
                    HangfireService.CancelJob(auction.DeletionJobID);
                    auction.CompletionJobID = HangfireService.CreateJobForAuction(auction);
                    AuctionService.Edit(auction);

                    return(RedirectToAction("Details", "Auction", new { id = auction.ID }));
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("", Resource.SaveError + ": " + ex.Message);
                }
            }
            else
            {
                ModelState.AddModelError("", Resource.InvalidData);
            }

            //ViewBag.autoID = auto.ID;
            //ViewBag.auctionID = auction.ID;
            ViewBag.currencies       = CurrencyService.GetAllAsSelectList();
            ViewBag.recommendedPrice = AuctionService.GetRecommendedPrice(auto.PriceUSD, auto.PriceUAH);

            breadcrumbs.Add("#", Resource.AuctionCreate);
            ViewBag.breadcrumbs = breadcrumbs;

            int limit = 2000;

            int.TryParse(XCarsConfiguration.AutoDescriptionMaxLength, out limit);
            ViewBag.autoDescriptionMaxLength = limit;

            return(View(modelVM));
        }