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); }
// ************************************** // URL: /Account/LogOff // ************************************** public ActionResult LogOff() { using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext()) { CoordinatorUser.Finder.SignOutCurrentUser(ctx); } return RedirectToAction("Index", "Home"); }
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); } }
public ActionResult Index() { ViewBag.Message = ""; using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext()) { ViewBag.Devices = ctx.DbCtx.ZigBeeDevices .Include(d => d.ZigBeeDeviceType) .ToList(); } return View(); }
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); }
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); }
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 }); }
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); } }
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(); } }
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); }
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(); } }
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(); }
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 }); }
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 }); }