Esempio n. 1
0
        public async Task <IActionResult> Order(int category = 0)
        {
            if (category > 0)
            {
                Category selectedСategory = await _context.Categories.Where(c => c.Id == category).Include(s => s.Services).SingleOrDefaultAsync();

                if (selectedСategory != null)
                {
                    if (selectedСategory.Services != null && selectedСategory.Services.Count > 0)
                    {
                        UserInformer   informer = new UserInformer(User, _context, _userManager);
                        var            user     = informer.GetUser();
                        OrderViewModel model    = new OrderViewModel();
                        model.SelectedCategoryId   = category;
                        model.SelectedCategoryName = await _context.Categories.Where(c => c.Id == category).Select(c => c.Name).FirstOrDefaultAsync();

                        model.Services = selectedСategory.Services.OrderBy(s => s.Name).ToList();
                        model.City     = await _context.Cities.Where(c => c.Id == user.CityId).Include(c => c.Districts).FirstOrDefaultAsync();

                        if (model.City == null)
                        {
                            RedirectToAction(nameof(Error));
                        }

                        return(View(model));
                    }
                }
            }

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IEnumerable <OrderDataModel> > GetOrders()
        {
            PutOrderDataModel data = CheackRequest();

            if (data == null)
            {
                return(null);
            }

            UserInformerOption option = UserInformerOption.New;

            if (Request.Query.ContainsKey("option"))
            {
                switch (Request.Query["option"].ToString().ToLower())
                {
                case "work": option = UserInformerOption.Work; break;

                case "all": option = UserInformerOption.All; break;

                default: break;
                }
            }

            UserInformer          informer = new UserInformer(_context, Request.Query["guid"]);
            List <OrderDataModel> model    = await informer.GetOrdersDataModelAsync(option);

            return(model);
        }
Esempio n. 3
0
        private void eWeLinkWachdog()
        {
            if (Wachdog || eWeRebootiong)
            {
                return;
            }
            Wachdog = true;
            Task.Run(() =>
            {
                for (int i = 0; i < WachdogDelay; i++)
                {
                    if (Status == IPStatus.Success || !InternetConnection)
                    {
                        goto EndWachdog;
                    }
                    Thread.Sleep(1000);
                }
                if (Status == IPStatus.Success || !InternetConnection)
                {
                    goto EndWachdog;
                }
                if (UserInformer.Alarm)
                {
                    UserInformer.SendMSG(Config.Name, "Ping: Worker offline");
                }

                WachingStop();
                eWeReboot();
                EndWachdog:
                Wachdog = false;
            });
        }
Esempio n. 4
0
        public async Task <IActionResult> IndexRead()
        {
            UserInformer informer = new UserInformer(User, _context, _userManager);

            var model = await informer.GetUserPageDataAsync();

            return(PartialView("_UserReadPartial", model));
        }
Esempio n. 5
0
        public async Task <IActionResult> Index()
        {
            UserInformer informer = new UserInformer(User, _context, _userManager);

            var model = await informer.GetUserPageDataAsync();

            return(View(model));
        }
Esempio n. 6
0
        public async Task <IActionResult> WorkerSettings()
        {
            UserInformer        informer            = new UserInformer(User, _context, _userManager);
            WorkerPageViewModel workerPageViewModel = await informer.GetWorkerPageDataAsync(UserInformerOption.Settings);

            if (workerPageViewModel == null)
            {
                return(NotFound());
            }
            return(PartialView("_WorkerSettingsPartial", workerPageViewModel));
        }
Esempio n. 7
0
        public async Task <IActionResult> Office()
        {
            UserInformer        informer            = new UserInformer(User, _context, _userManager);
            WorkerPageViewModel workerPageViewModel = await informer.GetWorkerPageDataAsync(UserInformerOption.New);

            if (workerPageViewModel == null)
            {
                return(NotFound());
            }
            return(View(workerPageViewModel));
        }
Esempio n. 8
0
        private void eWeReboot()
        {
            if (Config.eWeDevice != null && App.Ewelink != null)
            {
                if (eWeRebootiong)
                {
                    return;
                }
                eWeRebootiong = true;
                while (App.Live && eWeRebootiong)
                {
                    Task.Run(() =>
                    {
                        UserInformer.SendMSG(Config.Name, "eWeReboot");

                        EwelinkNet.Classes.SwitchDevice dev = null;
                        try
                        {
                            dev = App.Ewelink.Devices.
                                  Where(d => d.name == Config.eWeDevice).First()
                                  as EwelinkNet.Classes.SwitchDevice;
                        }
                        catch
                        {
                            eWeRebootiong = false;
                            UserInformer.SendMSG(Config.Name, "eWeReboot error");
                            return;
                        }

                        if (dev != null)
                        {
                            dev.TurnOff();
                            Thread.Sleep(8000);
                            dev.TurnOn();
                        }
                        else
                        {
                            eWeRebootiong = false;
                            UserInformer.SendMSG(Config.Name, "eWeReboot error");
                            return;
                        }
                    });

                    for (int i = 0; i < Config.eWeDelayTimeout; i++)
                    {
                        Thread.Sleep(1000);
                        if (Status == IPStatus.Success || !InternetConnection)
                        {
                            eWeRebootiong = false; return;
                        }
                    }
                }
            }
        }
Esempio n. 9
0
 private void AlarmSwitch(bool b)
 {
     if (b && !Alarm)
     {
         Alarm = true;
         UserInformer.AlarmStart(this);
     }
     if (!b && Alarm)
     {
         Alarm = false;
         UserInformer.AlarmStop(this);
     }
 }
Esempio n. 10
0
        public async Task <IActionResult> SaveUser(UserPageViewModel model)
        {
            if (!ModelState.IsValid)
            {
                model.Cities = await _context.Cities.ToListAsync();

                model.City = model.Cities.Where(c => c.Id == model.CityId).Select(c => c.Name).SingleOrDefault();

                return(View(model));
            }

            UserInformer informer = new UserInformer(User, _context, _userManager);
            var          user     = await informer.GetUserWorkerAsync();

            if (user != null)
            {
                user.UserName    = model.Name;
                user.PhoneNumber = model.PhoneNumber;
                user.CityId      = model.CityId;

                WorkerSetting workerSettings = user.Worker.WorkerSettingJson.ParseToWorkerSetting();
                if (workerSettings.CityId != model.CityId)
                {
                    workerSettings.CityId         = model.CityId;
                    workerSettings.DistrictIds    = new List <int>();
                    user.Worker.WorkerSettingJson = workerSettings.ToJSON();
                }

                _context.Entry(user).State        = EntityState.Modified;
                _context.Entry(user.Worker).State = EntityState.Modified;
                try
                {
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                }
            }
            return(RedirectToAction(nameof(Index)));
        }
Esempio n. 11
0
 private void StopAlarm(object sender, System.Windows.Input.MouseButtonEventArgs e)
 {
     UserInformer.AlarmStop();
 }
Esempio n. 12
0
                public void StartWach()
                {
                    if (!HiveWach)
                    {
                        HiveWach = true;

                        if (!HiveWachdog)
                        {
                            HiveWachdog = true;
                            Task.Run(() =>
                            {
                                Thread.Sleep(HiveOSWachdogDelay * 1000);
                                CurrentHiveStatus = HiveStatus.Normal;
                                UserInformer.SendMSG(Config.Name, "Start hive wach");
                                BackToLoop:
                                while (CurrentHiveStatus == HiveStatus.Normal && InternetConnection)
                                {
                                    Thread.Sleep(1000);
                                }
                                if (InternetConnection)
                                {
                                    //задержка
                                    for (int n = 0; n < 100; n++)
                                    {
                                        if (CurrentHiveStatus == HiveStatus.Normal)
                                        {
                                            goto BackToLoop;
                                        }
                                        Thread.Sleep(100);
                                    }

                                    string msg = "";
                                    switch (CurrentHiveStatus)
                                    {
                                    case HiveStatus.LowHashrate:
                                        {
                                            msg = "Hive: Low hashrate";
                                        }
                                        break;

                                    case HiveStatus.WorkerOffline:
                                        {
                                            msg = "Hive: Worker offline";
                                        }
                                        break;
                                    }
                                    UserInformer.SendMSG(Config.Name, msg);
                                    Rig.eWeReboot();
                                }
                                HiveWachdog = false;
                            });
                        }
                        Task.Run(() =>
                        {
                            while (!App.HiveConnection)
                            {
                                Thread.Sleep(100);
                            }

                            while (HiveWach && InternetConnection)
                            {
                                var mi = HiveClient.GetWorkerInfo(Config.HiveFarmID.Value,
                                                                  Config.HiveWorkerID.Value);

                                if (mi != null)
                                {
                                    InformReceived?.Invoke(new RigInform
                                    {
                                        Indication      = true,
                                        InfHashrates    = mi.Value.Hashrates,
                                        InfTemperatures = mi.Value.Temperatures
                                    });

                                    // low hashrate wachdog
                                    if (Config.WachdogMinHashrate != null)
                                    {
                                        if (mi.Value.Hashrates.Length > 0)
                                        {
                                            CurrentHiveStatus =
                                                mi.Value.Hashrates.Sum() < Config.WachdogMinHashrate.Value ?
                                                HiveStatus.LowHashrate : HiveStatus.Normal;
                                        }
                                        else
                                        {
                                            CurrentHiveStatus = HiveStatus.LowHashrate;
                                        }
                                    }
                                    else
                                    {
                                        CurrentHiveStatus = HiveStatus.Normal;
                                    }
                                }
                                else
                                {
                                    InformReceived?.Invoke(new RigInform {
                                        Indication = false
                                    });

                                    CurrentHiveStatus = HiveStatus.WorkerOffline;

                                    goto EndHiveWach;
                                }

                                Thread.Sleep(new TimeSpan(0, 0, HiveOSRequestDelay));
                            }
                            EndHiveWach:
                            HiveWach = false;
                        });
                    }
                }