コード例 #1
0
        public override void ProcessData(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, byte[] data)
        {
            int? userId = data[0];
            float weight = BitConverter.ToInt16(data, 1) / 10.0f;

            // user not specified
            if (userId == 0)
            {
                userId = FindUserBasedOnHistory(ctx, weight);
            }

            if (userId == null)
            {
                _log.Error("Could not find user based on weight '" + weight + "'");
                return;
            }

            _log.Info("Weight received for user [" + userId + "]: " + weight);

            WirelessScaleData wirelessScaleData = new WirelessScaleData
            {
                UserId = userId.Value,
                Value = weight,
                ZigBeeDevice = device,
                ReceivedDateTime = DateTime.Now
            };
            ctx.DbCtx.WirelessScaleDatas.AddObject(wirelessScaleData);
            ctx.DbCtx.SaveChanges();
        }
コード例 #2
0
        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);
        }
コード例 #3
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 }));
        }
コード例 #4
0
        public override void ProcessData(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, byte[] data)
        {
            int?  userId = data[0];
            float weight = BitConverter.ToInt16(data, 1) / 10.0f;

            // user not specified
            if (userId == 0)
            {
                userId = FindUserBasedOnHistory(ctx, weight);
            }

            if (userId == null)
            {
                _log.Error("Could not find user based on weight '" + weight + "'");
                return;
            }

            _log.Info("Weight received for user [" + userId + "]: " + weight);

            WirelessScaleData wirelessScaleData = new WirelessScaleData
            {
                UserId           = userId.Value,
                Value            = weight,
                ZigBeeDevice     = device,
                ReceivedDateTime = DateTime.Now
            };

            ctx.DbCtx.WirelessScaleDatas.AddObject(wirelessScaleData);
            ctx.DbCtx.SaveChanges();
        }
コード例 #5
0
        private void LogReceivePacket(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, ZigBeeCommunicationsController.ZigBeeReceivePacket packet)
        {
            FiveVoltPacket fiveVoltPacket = FiveVoltPacket.Decode(packet.ReceiveData);

            if (fiveVoltPacket is InvalidFileVoltPacket)
            {
                InvalidFileVoltPacket invalidPacket = (InvalidFileVoltPacket)fiveVoltPacket;
                _log.Error("Invalid five volt packet. Reason \"" + invalidPacket.Reason + "\"");
            }
            else if (fiveVoltPacket is CapabilityFiveVoltPacket)
            {
                CapabilityFiveVoltPacket capabilityFiveVoltPacket = (CapabilityFiveVoltPacket)fiveVoltPacket;
                LogCapabilityFiveVoltPacket(ctx, device, capabilityFiveVoltPacket);
            }
            else if (fiveVoltPacket is CapabilityDataFiveVoltPacket)
            {
                CapabilityDataFiveVoltPacket capabilityDataFiveVoltPacket = (CapabilityDataFiveVoltPacket)fiveVoltPacket;
                LogCapabilityDataFiveVoltPacket(ctx, device, capabilityDataFiveVoltPacket);
            }
            else if (fiveVoltPacket is MessageFiveVoltPacket)
            {
                MessageFiveVoltPacket messageFiveVoltPacket = (MessageFiveVoltPacket)fiveVoltPacket;
                LogMessageFiveVoltPacket(ctx, device, messageFiveVoltPacket);
            }
            else
            {
                _log.Error("Unhandled five volt packet type [" + fiveVoltPacket.GetType() + "]");
            }
        }
コード例 #6
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());
 }
コード例 #7
0
 private IEnumerable <WirelessScaleData> FindUsersMostRecentData(ZigBeeCoordinatorContext ctx)
 {
     return(ctx.DbCtx.WirelessScaleDatas
            .ToList()
            .GroupBy(q => q.UserId)
            .Select(userData => userData.OrderByDescending(d => d.ReceivedDateTime).FirstOrDefault())
            .ToList());
 }
コード例 #8
0
 private IEnumerable<WirelessScaleData> FindUsersMostRecentData(ZigBeeCoordinatorContext ctx)
 {
     return ctx.DbCtx.WirelessScaleDatas
         .ToList()
         .GroupBy(q => q.UserId)
         .Select(userData => userData.OrderByDescending(d => d.ReceivedDateTime).FirstOrDefault())
         .ToList();
 }
コード例 #9
0
ファイル: CoordinatorUser.cs プロジェクト: joeferner/fivevolt
 public CoordinatorUser GetCurrentUser(ZigBeeCoordinatorContext ctx)
 {
     int? userId = GetCurrentUserId();
     if (userId != null)
     {
         return GetUserByUserId(ctx, userId.Value);
     }
     return null;
 }
コード例 #10
0
        // **************************************
        // URL: /Account/LogOff
        // **************************************

        public ActionResult LogOff()
        {
            using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
            {
                CoordinatorUser.Finder.SignOutCurrentUser(ctx);
            }

            return(RedirectToAction("Index", "Home"));
        }
コード例 #11
0
ファイル: UserSetting.cs プロジェクト: joeferner/fivevolt
 public string GetSetting(ZigBeeCoordinatorContext ctx, int userId, string name)
 {
     UserSetting setting = ctx.DbCtx.UserSettings.FirstOrDefault(us => us.UserId == userId && us.Name == name);
     if (setting == null)
     {
         return null;
     }
     return setting.Value;
 }
コード例 #12
0
ファイル: UserSetting.cs プロジェクト: joeferner/fivevolt
 public double GetSettingAsDouble(ZigBeeCoordinatorContext ctx, int userId, string name, double defaultValue)
 {
     string val = GetSetting(ctx, userId, name);
     if (string.IsNullOrEmpty(val))
     {
         return defaultValue;
     }
     return double.Parse(val);
 }
コード例 #13
0
        public CoordinatorUser GetCurrentUser(ZigBeeCoordinatorContext ctx)
        {
            int?userId = GetCurrentUserId();

            if (userId != null)
            {
                return(GetUserByUserId(ctx, userId.Value));
            }
            return(null);
        }
コード例 #14
0
 private int? FindUserBasedOnHistory(ZigBeeCoordinatorContext ctx, float weight)
 {
     IEnumerable<WirelessScaleData> mostRecentHistory = FindUsersMostRecentData(ctx);
     WirelessScaleData closestData = mostRecentHistory.Smallest(d => Math.Abs(d.Value - weight));
     if (Math.Abs(closestData.Value - weight) > 20)
     {
         return null;
     }
     return closestData.UserId;
 }
コード例 #15
0
ファイル: UserSetting.cs プロジェクト: infinitoparra/fivevolt
        public double GetSettingAsDouble(ZigBeeCoordinatorContext ctx, int userId, string name, double defaultValue)
        {
            string val = GetSetting(ctx, userId, name);

            if (string.IsNullOrEmpty(val))
            {
                return(defaultValue);
            }
            return(double.Parse(val));
        }
コード例 #16
0
ファイル: UserSetting.cs プロジェクト: infinitoparra/fivevolt
        public string GetSetting(ZigBeeCoordinatorContext ctx, int userId, string name)
        {
            UserSetting setting = ctx.DbCtx.UserSettings.FirstOrDefault(us => us.UserId == userId && us.Name == name);

            if (setting == null)
            {
                return(null);
            }
            return(setting.Value);
        }
コード例 #17
0
ファイル: ZigBeeDevice.cs プロジェクト: joeferner/fivevolt
 public ZigBeeDevice FindByAddressOrDefault(ZigBeeCoordinatorContext ctx, byte[] address)
 {
     List<ZigBeeDevice> devices = ctx.DbCtx.ZigBeeDevices.ToList();
     ZigBeeDevice zigBeeDevice = devices.FirstOrDefault(d => address.EqualsAllItems(d.DeviceAddress));
     if (zigBeeDevice != null)
     {
         return zigBeeDevice;
     }
     return null;
 }
コード例 #18
0
        public ZigBeeDevice FindByAddressOrDefault(ZigBeeCoordinatorContext ctx, byte[] address)
        {
            List <ZigBeeDevice> devices      = ctx.DbCtx.ZigBeeDevices.ToList();
            ZigBeeDevice        zigBeeDevice = devices.FirstOrDefault(d => address.EqualsAllItems(d.DeviceAddress));

            if (zigBeeDevice != null)
            {
                return(zigBeeDevice);
            }
            return(null);
        }
コード例 #19
0
        private int?FindUserBasedOnHistory(ZigBeeCoordinatorContext ctx, float weight)
        {
            IEnumerable <WirelessScaleData> mostRecentHistory = FindUsersMostRecentData(ctx);
            WirelessScaleData closestData = mostRecentHistory.Smallest(d => Math.Abs(d.Value - weight));

            if (Math.Abs(closestData.Value - weight) > 20)
            {
                return(null);
            }
            return(closestData.UserId);
        }
コード例 #20
0
ファイル: ZigBeeDeviceLog.cs プロジェクト: joeferner/fivevolt
        private void LogCapabilityDataFiveVoltPacket(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, CapabilityDataFiveVoltPacket packet)
        {
            Capability capability = Capability.Finder.FindByIdOrDefault(ctx, packet.Capability);
            if (capability == null)
            {
                _log.Error("Could not find capability with id [" + packet.Capability + "]");
                return;
            }

            capability.ProcessData(ctx, device, packet.Data);
        }
コード例 #21
0
ファイル: ZigBeeDeviceLog.cs プロジェクト: joeferner/fivevolt
        private void LogCapabilityFiveVoltPacket(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, CapabilityFiveVoltPacket capabilityFiveVoltPacket)
        {
            Capability capability = Capability.Finder.FindByIdOrDefault(ctx, capabilityFiveVoltPacket.Capability);
            if (capability == null)
            {
                _log.Error("Could not find capability with id [" + capabilityFiveVoltPacket.Capability + "]");
                return;
            }

            _log.Info("New capability found [" + capability.Name + "] at address [" + device.DeviceAddressString + "]");
            device.Capabilities.Add(capability);
        }
コード例 #22
0
        public CoordinatorUser ValidateUser(ZigBeeCoordinatorContext ctx, string userName, string password)
        {
            CoordinatorUser user = GetUserByUserName(ctx, userName);
            string          hash = SecurityHelpers.GetMD5HashHexString(password);

            if (string.Equals(user.Password, hash, StringComparison.InvariantCultureIgnoreCase) ||
                string.Equals(user.Password, password, StringComparison.InvariantCultureIgnoreCase))
            {
                return(user);
            }
            return(null);
        }
コード例 #23
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));
     }
 }
コード例 #24
0
        private void LogCapabilityDataFiveVoltPacket(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, CapabilityDataFiveVoltPacket packet)
        {
            Capability capability = Capability.Finder.FindByIdOrDefault(ctx, packet.Capability);

            if (capability == null)
            {
                _log.Error("Could not find capability with id [" + packet.Capability + "]");
                return;
            }

            capability.ProcessData(ctx, device, packet.Data);
        }
コード例 #25
0
        public ActionResult Index()
        {
            ViewBag.Message = "";

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

            return(View());
        }
コード例 #26
0
        private void LogCapabilityFiveVoltPacket(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, CapabilityFiveVoltPacket capabilityFiveVoltPacket)
        {
            Capability capability = Capability.Finder.FindByIdOrDefault(ctx, capabilityFiveVoltPacket.Capability);

            if (capability == null)
            {
                _log.Error("Could not find capability with id [" + capabilityFiveVoltPacket.Capability + "]");
                return;
            }

            _log.Info("New capability found [" + capability.Name + "] at address [" + device.DeviceAddressString + "]");
            device.Capabilities.Add(capability);
        }
コード例 #27
0
ファイル: Capability.cs プロジェクト: joeferner/fivevolt
        public void ProcessData(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, byte[] data)
        {
            _log.Debug("Processing data for capability [" + CapabilityId + ": " + Name + "], from [" + device.DeviceAddressString + "], data [" + data.ToHexString() + "]");

            if (CapabilityHandler == null)
            {
                _log.Error("Unknown capability id [" + CapabilityId + "]");
            }
            else
            {
                CapabilityHandler.ProcessData(ctx, device, data);
            }
        }
コード例 #28
0
ファイル: Capability.cs プロジェクト: infinitoparra/fivevolt
        public void ProcessData(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, byte[] data)
        {
            _log.Debug("Processing data for capability [" + CapabilityId + ": " + Name + "], from [" + device.DeviceAddressString + "], data [" + data.ToHexString() + "]");

            if (CapabilityHandler == null)
            {
                _log.Error("Unknown capability id [" + CapabilityId + "]");
            }
            else
            {
                CapabilityHandler.ProcessData(ctx, device, data);
            }
        }
コード例 #29
0
ファイル: ZigBeeDeviceLog.cs プロジェクト: joeferner/fivevolt
 private void LogMessageFiveVoltPacket(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, MessageFiveVoltPacket packet)
 {
     string message = "Message from [" + device.NetworkAddress.ToHexString() + "]: " + packet.Message;
     switch (packet.Level)
     {
         case MessageLevel.Debug: _log.Debug(message); break;
         case MessageLevel.Info: _log.Info(message); break;
         case MessageLevel.Warning: _log.Warn(message); break;
         case MessageLevel.Error: _log.Error(message); break;
         default:
             _log.Error(message + " (Invalid message level: " + packet.Level + ")");
             break;
     }
 }
コード例 #30
0
ファイル: Global.asax.cs プロジェクト: infinitoparra/fivevolt
        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);
        }
コード例 #31
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 }));
        }
コード例 #32
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));
        }
コード例 #33
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);
     }
 }
コード例 #34
0
        private void LogMessageFiveVoltPacket(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, MessageFiveVoltPacket packet)
        {
            string message = "Message from [" + device.NetworkAddress.ToHexString() + "]: " + packet.Message;

            switch (packet.Level)
            {
            case MessageLevel.Debug: _log.Debug(message); break;

            case MessageLevel.Info: _log.Info(message); break;

            case MessageLevel.Warning: _log.Warn(message); break;

            case MessageLevel.Error: _log.Error(message); break;

            default:
                _log.Error(message + " (Invalid message level: " + packet.Level + ")");
                break;
            }
        }
コード例 #35
0
ファイル: UserSetting.cs プロジェクト: joeferner/fivevolt
 public void SetSetting(ZigBeeCoordinatorContext ctx, int userId, string name, string val)
 {
     _log.Debug("Setting user setting \"" + name + "\" = \"" + val + "\" (user id: " + userId + ")");
     UserSetting setting = ctx.DbCtx.UserSettings.FirstOrDefault(us => us.UserId == userId && us.Name == name);
     if (setting == null)
     {
         setting = new UserSetting
         {
             UserId = userId,
             Name = name,
             Value = val
         };
         ctx.DbCtx.UserSettings.AddObject(setting);
     }
     else
     {
         setting.Value = val;
     }
 }
コード例 #36
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 }));
        }
コード例 #37
0
ファイル: ZigBeeDeviceLog.cs プロジェクト: joeferner/fivevolt
        public void LogPacket(ZigBeeCoordinatorContext ctx, ZigBeeCommunicationsController.Packet packet)
        {
            ZigBeeDevice device = ZigBeeDevice.Finder.FindAddOrUpdate(ctx, packet.Address, packet.NetworkAddress);
            device.LastPacketDateTime = DateTime.Now;

            ZigBeeDeviceLog log = new ZigBeeDeviceLog
            {
                DateTime = packet.ReceivedDataTime,
                PacketData = packet.PacketData,
                ZigBeeDevice = device
            };
            ctx.DbCtx.ZigBeeDeviceLogs.AddObject(log);
            ctx.DbCtx.SaveChanges();

            if (packet is ZigBeeCommunicationsController.ZigBeeReceivePacket)
            {
                LogReceivePacket(ctx, device, (ZigBeeCommunicationsController.ZigBeeReceivePacket)packet);
            }
        }
コード例 #38
0
ファイル: UserSetting.cs プロジェクト: infinitoparra/fivevolt
        public void SetSetting(ZigBeeCoordinatorContext ctx, int userId, string name, string val)
        {
            _log.Debug("Setting user setting \"" + name + "\" = \"" + val + "\" (user id: " + userId + ")");
            UserSetting setting = ctx.DbCtx.UserSettings.FirstOrDefault(us => us.UserId == userId && us.Name == name);

            if (setting == null)
            {
                setting = new UserSetting
                {
                    UserId = userId,
                    Name   = name,
                    Value  = val
                };
                ctx.DbCtx.UserSettings.AddObject(setting);
            }
            else
            {
                setting.Value = val;
            }
        }
コード例 #39
0
        public void LogPacket(ZigBeeCoordinatorContext ctx, ZigBeeCommunicationsController.Packet packet)
        {
            ZigBeeDevice device = ZigBeeDevice.Finder.FindAddOrUpdate(ctx, packet.Address, packet.NetworkAddress);

            device.LastPacketDateTime = DateTime.Now;

            ZigBeeDeviceLog log = new ZigBeeDeviceLog
            {
                DateTime     = packet.ReceivedDataTime,
                PacketData   = packet.PacketData,
                ZigBeeDevice = device
            };

            ctx.DbCtx.ZigBeeDeviceLogs.AddObject(log);
            ctx.DbCtx.SaveChanges();

            if (packet is ZigBeeCommunicationsController.ZigBeeReceivePacket)
            {
                LogReceivePacket(ctx, device, (ZigBeeCommunicationsController.ZigBeeReceivePacket)packet);
            }
        }
コード例 #40
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());
            }
        }
コード例 #41
0
ファイル: CoordinatorUser.cs プロジェクト: joeferner/fivevolt
        public int? GetCurrentUserId()
        {
            object userIdObj = HttpContext.Current.Session["UserId"];
            if (userIdObj is int)
            {
                return (int)userIdObj;
            }

            if (HttpContext.Current.Request.IsAuthenticated)
            {
                string userName = HttpContext.Current.User.Identity.Name;
                using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
                {
                    CoordinatorUser user = GetUserByUserName(ctx, userName);
                    if (user != null)
                    {
                        user.UpdateSession();
                        return user.UserId;
                    }
                }
            }
            return null;
        }
コード例 #42
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));
        }
コード例 #43
0
ファイル: ZigBeeDevice.cs プロジェクト: joeferner/fivevolt
 public ZigBeeDevice FindAddOrUpdate(ZigBeeCoordinatorContext ctx, byte[] address, byte[] networkAddress)
 {
     ZigBeeDevice zigBeeDevice = FindByAddressOrDefault(ctx, address);
     if (zigBeeDevice != null)
     {
         if (!zigBeeDevice.NetworkAddress.EqualsAllItems(networkAddress))
         {
             zigBeeDevice.NetworkAddress = networkAddress;
         }
     }
     else
     {
         zigBeeDevice = new ZigBeeDevice
         {
             CreatedDateTime = DateTime.Now,
             DeviceAddress = address,
             NetworkAddress = networkAddress
         };
         ctx.DbCtx.ZigBeeDevices.AddObject(zigBeeDevice);
         ctx.DbCtx.SaveChanges();
     }
     return zigBeeDevice;
 }
コード例 #44
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());
            }
        }
コード例 #45
0
        public int?GetCurrentUserId()
        {
            object userIdObj = HttpContext.Current.Session["UserId"];

            if (userIdObj is int)
            {
                return((int)userIdObj);
            }

            if (HttpContext.Current.Request.IsAuthenticated)
            {
                string userName = HttpContext.Current.User.Identity.Name;
                using (ZigBeeCoordinatorContext ctx = new ZigBeeCoordinatorContext())
                {
                    CoordinatorUser user = GetUserByUserName(ctx, userName);
                    if (user != null)
                    {
                        user.UpdateSession();
                        return(user.UserId);
                    }
                }
            }
            return(null);
        }
コード例 #46
0
ファイル: ZigBeeDeviceLog.cs プロジェクト: joeferner/fivevolt
 private void LogReceivePacket(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, ZigBeeCommunicationsController.ZigBeeReceivePacket packet)
 {
     FiveVoltPacket fiveVoltPacket = FiveVoltPacket.Decode(packet.ReceiveData);
     if (fiveVoltPacket is InvalidFileVoltPacket)
     {
         InvalidFileVoltPacket invalidPacket = (InvalidFileVoltPacket)fiveVoltPacket;
         _log.Error("Invalid five volt packet. Reason \"" + invalidPacket.Reason + "\"");
     }
     else if (fiveVoltPacket is CapabilityFiveVoltPacket)
     {
         CapabilityFiveVoltPacket capabilityFiveVoltPacket = (CapabilityFiveVoltPacket)fiveVoltPacket;
         LogCapabilityFiveVoltPacket(ctx, device, capabilityFiveVoltPacket);
     }
     else if (fiveVoltPacket is CapabilityDataFiveVoltPacket)
     {
         CapabilityDataFiveVoltPacket capabilityDataFiveVoltPacket = (CapabilityDataFiveVoltPacket)fiveVoltPacket;
         LogCapabilityDataFiveVoltPacket(ctx, device, capabilityDataFiveVoltPacket);
     }
     else if (fiveVoltPacket is MessageFiveVoltPacket)
     {
         MessageFiveVoltPacket messageFiveVoltPacket = (MessageFiveVoltPacket)fiveVoltPacket;
         LogMessageFiveVoltPacket(ctx, device, messageFiveVoltPacket);
     }
     else
     {
         _log.Error("Unhandled five volt packet type [" + fiveVoltPacket.GetType() + "]");
     }
 }
コード例 #47
0
ファイル: CoordinatorUser.cs プロジェクト: joeferner/fivevolt
 public CoordinatorUser GetUserByUserId(ZigBeeCoordinatorContext ctx, int userId)
 {
     return ctx.DbCtx.CoordinatorUsers.FirstOrDefault(u => u.UserId == userId);
 }
コード例 #48
0
ファイル: Capability.cs プロジェクト: joeferner/fivevolt
 public Capability FindByIdOrDefault(ZigBeeCoordinatorContext ctx, UInt16 capabilityId)
 {
     return ctx.DbCtx.Capabilities.FirstOrDefault(c => c.CapabilityId == capabilityId);
 }
コード例 #49
0
 public abstract void ProcessData(ZigBeeCoordinatorContext ctx, ZigBeeDevice device, byte[] data);
コード例 #50
0
ファイル: CoordinatorUser.cs プロジェクト: joeferner/fivevolt
 public CoordinatorUser GetUserByUserName(ZigBeeCoordinatorContext ctx, string userName)
 {
     return ctx.DbCtx.CoordinatorUsers.FirstOrDefault(u => u.UserName == userName);
 }
コード例 #51
0
ファイル: CoordinatorUser.cs プロジェクト: joeferner/fivevolt
 public void SignOutCurrentUser(ZigBeeCoordinatorContext ctx)
 {
     FormsAuthentication.SignOut();
     HttpContext.Current.Session.Remove("UserId");
 }
コード例 #52
0
ファイル: CoordinatorUser.cs プロジェクト: joeferner/fivevolt
 public CoordinatorUser ValidateUser(ZigBeeCoordinatorContext ctx, string userName, string password)
 {
     CoordinatorUser user = GetUserByUserName(ctx, userName);
     string hash = SecurityHelpers.GetMD5HashHexString(password);
     if (string.Equals(user.Password, hash, StringComparison.InvariantCultureIgnoreCase)
         || string.Equals(user.Password, password, StringComparison.InvariantCultureIgnoreCase))
     {
         return user;
     }
     return null;
 }