protected override void OnStart(string[] args)
        {
            _log.Info("BEGIN OnStart (args: " + args.JoinAsString(", ") + ")");
            try
            {
                LoadConfiguration();

                IocContainer.Instance.Compose(this);

                // verify connection with database
                _log.Debug("Verifing connection with database");
                ZigBeeCoordinatorContext.ConnectionString = "metadata=res://*/Models.Db.ZigBeeCoordinatorModel.csdl|res://*/Models.Db.ZigBeeCoordinatorModel.ssdl|res://*/Models.Db.ZigBeeCoordinatorModel.msl;provider=System.Data.SqlClient;provider connection string=\"Data Source=fileserver;Initial Catalog=ZigBeeCoordinator;Integrated Security=True;MultipleActiveResultSets=True\"";
                using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
                {
                    ctx.DbCtx.CoordinatorUsers.FirstOrDefault();
                }

                _zigBeeCommunicationsController.PortName = _portName;
                _zigBeeCommunicationsController.BaudRate = _baudRate;
                _zigBeeCommunicationsController.PacketArrived += PacketArrived;
                _zigBeeCommunicationsController.Start();
            }
            catch (Exception ex)
            {
                _log.Error("Could not start", ex);
                throw;
            }
            _log.Info("END OnStart");
            base.OnStart(args);
        }
Пример #2
0
        // **************************************
        // URL: /Account/LogOff
        // **************************************
        public ActionResult LogOff()
        {
            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                CoordinatorUser.Finder.SignOutCurrentUser(ctx);
            }

            return RedirectToAction("Index", "Home");
        }
Пример #3
0
 public ActionResult Detail(int id)
 {
     using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
     {
         ZigBeeDevice device = ctx.DbCtx.ZigBeeDevices
             .Include(d => d.ZigBeeDeviceType)
             .Include(d => d.Capabilities)
             .FirstOrDefault(d => d.ZigBeeDeviceId == id);
         ctx.DbCtx.LoadProperty(device, d => d.ZigBeeDeviceLogs);
         return View(device);
     }
 }
Пример #4
0
        public ActionResult Index()
        {
            ViewBag.Message = "";

            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                ViewBag.Devices = ctx.DbCtx.ZigBeeDevices
                    .Include(d => d.ZigBeeDeviceType)
                    .ToList();
            }

            return View();
        }
Пример #5
0
        protected void Application_Start()
        {
            MyLogManager.ConfigureFromWebConfig();

            // verify connection with database
            MyLogManager.GetLogger(typeof(MvcApplication)).Debug("Verifing connection with database");
            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                ctx.DbCtx.CoordinatorUsers.FirstOrDefault();
            }

            AreaRegistration.RegisterAllAreas();

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }
Пример #6
0
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {
                using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
                {
                    if (CoordinatorUser.Finder.GetCurrentUser(ctx).ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
                    {
                        return RedirectToAction("ChangePasswordSuccess");
                    }
                }
                ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
            }

            // If we got this far, something failed, redisplay form
            ViewBag.PasswordLength = CoordinatorUser.MinPasswordLength;
            return View(model);
        }
Пример #7
0
        public ActionResult DeleteValue(int wirelessScaleDataId)
        {
            int? userId = CoordinatorUser.Finder.GetCurrentUserId();
            if (userId == null)
            {
                throw new Exception("You must be logged in");
            }

            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                WirelessScaleData data = ctx.DbCtx.WirelessScaleDatas
                    .FirstOrDefault(d => d.WirelessScaleDataId == wirelessScaleDataId);
                ctx.DbCtx.WirelessScaleDatas.DeleteObject(data);
                ctx.DbCtx.SaveChanges();
            }

            return RedirectToAction("Index", new { userId = userId });
        }
Пример #8
0
 private void PacketArrived(ZigBeeCommunicationsController source, ZigBeeCommunicationsController.Packet packet)
 {
     try
     {
         if (_log.IsDebugEnabled)
         {
             _log.Debug("Packet received [length: " + packet.PacketData.Length + "]\n" + packet.PacketData.ToHexStringWithAscii(16));
         }
         using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
         {
             ZigBeeDeviceLog.Finder.LogPacket(ctx, packet);
         }
     }
     catch (Exception ex)
     {
         _log.Error("Could not process packet [length: " + packet.PacketData.Length + "]\n" + packet.PacketData.ToHexStringWithAscii(16), ex);
     }
 }
Пример #9
0
        public ActionResult HistoryChart(int userId, int? width, int? height, HistoryChartType? chartType)
        {
            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                double minX = UserSetting.Finder.GetSettingAsDouble(ctx, userId, GoalWeightSettingKey, 100.0);

                string title = "History";
                IEnumerable<WirelessScaleData> datas = GetUserHistory(ctx, userId);
                if (chartType == null || chartType.Value == HistoryChartType.All)
                {
                    title = "History - All";
                }
                else if (chartType.Value == HistoryChartType.Month)
                {
                    title = "History - 30-days";
                    DateTime start = DateTime.Now.Subtract(new TimeSpan(30, 0, 0, 0));
                    datas = datas.Where(d => d.ReceivedDateTime > start);
                    WirelessScaleData smallest = datas.Smallest(d => d.Value);
                    if (smallest != null)
                    {
                        minX = smallest.Value;
                    }
                }
                else if (chartType.Value == HistoryChartType.Week)
                {
                    title = "History - 7-days";
                    DateTime start = DateTime.Now.Subtract(new TimeSpan(7, 0, 0, 0));
                    datas = datas.Where(d => d.ReceivedDateTime > start);
                    WirelessScaleData smallest = datas.Smallest(d => d.Value);
                    if (smallest != null)
                    {
                        minX = smallest.Value;
                    }
                }
                ViewBag.Chart = BuildHistoryChart(datas, minX, width ?? 400, height ?? 300, title);
                return View();
            }
        }
Пример #10
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                CoordinatorUser user;
                using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
                {
                    if ((user = CoordinatorUser.Finder.ValidateUser(ctx, model.UserName, model.Password)) != null)
                    {
                        user.SignIn(model.RememberMe);
                        if (Url.IsLocalUrl(returnUrl))
                        {
                            return Redirect(returnUrl);
                        }
                        return RedirectToAction("Index", "Home");
                    }
                }
                ModelState.AddModelError("", "The user name or password provided is incorrect.");
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Пример #11
0
        public ActionResult Index(int userId, string extension)
        {
            ViewBag.Message = "";

            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                IEnumerable<WirelessScaleData> datas = GetUserHistory(ctx, userId);
                ViewBag.WirelessScaleDatas = datas;
                ViewBag.GoalWeight = UserSetting.Finder.GetSetting(ctx, userId, GoalWeightSettingKey);

                if (extension == "json")
                {
                    object jsonData = datas
                        .Select(d => new
                        {
                            ReceivedDateTime = d.ReceivedDateTime,
                            Weight = d.Value
                        })
                        .ToList();
                    return Json(jsonData, JsonRequestBehavior.AllowGet);
                }
                return View();
            }
        }
Пример #12
0
 private IEnumerable<WirelessScaleData> GetUserHistory(ZigBeeCoordinatorContext ctx, int userId)
 {
     return ctx.DbCtx.WirelessScaleDatas
         .Include(d => d.CoordinatorUser)
         .Where(d => d.UserId == userId)
         .OrderBy(d => d.ReceivedDateTime)
         .ToList();
 }
Пример #13
0
        public ActionResult UserSettings(double goalWeight)
        {
            int? userId = CoordinatorUser.Finder.GetCurrentUserId();
            if (userId == null)
            {
                throw new Exception("You must be logged in");
            }

            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                UserSetting.Finder.SetSetting(ctx, userId.Value, GoalWeightSettingKey, goalWeight.ToString());
                ctx.DbCtx.SaveChanges();
            }

            return RedirectToAction("Index", new { userId = userId });
        }
Пример #14
0
        public ActionResult ManualInput(DateTime date, string time, double weight)
        {
            int? userId = CoordinatorUser.Finder.GetCurrentUserId();
            if (userId == null)
            {
                throw new Exception("You must be logged in");
            }

            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                DateTime t = DateTime.Parse(date.ToString("d") + " " + time);

                WirelessScaleData data = new WirelessScaleData
                {
                    UserId = userId.Value,
                    ReceivedDateTime = t,
                    Value = weight,
                    ZigBeeDevice = null
                };
                ctx.DbCtx.WirelessScaleDatas.AddObject(data);
                ctx.DbCtx.SaveChanges();
            }

            return RedirectToAction("Index", new { userId = userId });
        }