Beispiel #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            double[] baseTemps = { 20.4, 20.5, 20.8, 20.4, 19.9, 20.5, 21.0, 21.4, 22.1, 22.9, 22.3, 21.8,
                                   21.5, 21.6, 21.8, 21.1, 20.7, 20.9, 20.5, 21.0, 20.8, 20.6, 20.5, 20.3 };

            using (var db = new HAMSContext())
            {
                foreach (var participant in db.Participants.Where(p => p.Activated))
                {
                    Guid personId = participant.HVPersonId.Value;
                    Guid recordId = participant.HVRecordId.Value;

                    response += String.Format("Seeding: {0} {1}{2}", participant.FirstName, participant.LastName, Environment.NewLine);

                    Methods.PurgeCustomData(personId, recordId);

                    response += String.Format("Old data purged.{0}", Environment.NewLine);

                    if (participant.NestAuthCode == null)
                    {
                        response += String.Format("No access code, skipping.{0}", Environment.NewLine);
                        continue;
                    }

                    DateTime current = DateTime.Now.Subtract(new TimeSpan(24 * 7, 0, 0));
                    Random   random  = new Random();

                    double baseHumidity = random.Next(20, 60);

                    for (int day = 0; day < 7; day++)
                    {
                        for (int time = 0; time < 24; time++)
                        {
                            Nest.NestData data = new Nest.NestData {
                                Temperature = Math.Round(baseTemps[time] + random.NextDouble() * 0.5 * RandomSign(), 1),
                                Humidity    = baseHumidity + random.Next(5) * RandomSign(),
                                CoState     = RandomState(),
                                SmokeState  = RandomState()
                            };
                            Nest.PushDataToHV(data, personId, recordId, current);

                            current = current.AddHours(1.0);
                        }
                    }

                    response += String.Format("New data pushed.{0}", Environment.NewLine);
                }
            }
        }
Beispiel #2
0
        public static void CollectAndPushThings()
        {
            using (var db = new HAMSContext())
            {
                foreach (var participant in db.Participants.Where(p => p.NestAuthCode != null))
                {
                    if (!participant.HVPersonId.HasValue || !participant.HVRecordId.HasValue)
                    {
                        continue;
                    }

                    NestData data = GetData(participant.NestAuthCode);

                    PushDataToHV(data, participant.HVPersonId.Value, participant.HVRecordId.Value);
                }
            }
        }
Beispiel #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string authCode      = Request.QueryString["code"];
            string participantId = Request.QueryString["state"];

            if (authCode == null || participantId == null)
            {
                throw new Exception("Invalid parameters");
            }

            string token = HAMS.Devices.Nest.GetToken(authCode);

            if (token == null)
            {
                throw new Exception("Invalid auth code");
            }

            Guid participantIdAsGuid;

            try
            {
                participantIdAsGuid = Guid.Parse(participantId);
            }
            catch (FormatException ex)
            {
                throw new Exception("Invalid parameters");
            }

            using (var db = new HAMSContext())
            {
                Participant participant = db.Participants.Find(participantIdAsGuid);
                if (participant == null)
                {
                    throw new Exception("Can't find participant: " + participantId);
                }
                participant.NestAuthorized = true;
                participant.NestAuthCode   = token;
                db.SaveChanges();
            }
        }
Beispiel #4
0
        public static void CheckForValidatedConnections()
        {
            Collection <ValidatedPatientConnection> connectionList = Connections.GetValidatedConnectionsInPastDays(0);

            using (var db = new HAMSContext())
            {
                try
                {
                    // reset connections
                    foreach (Participant participant in db.Participants)
                    {
                        participant.Activated  = false;
                        participant.HVPersonId = null;
                        participant.HVRecordId = null;
                    }

                    // add validated connections
                    foreach (ValidatedPatientConnection connection in connectionList)
                    {
                        Guid        participantId = Guid.Parse(connection.ApplicationPatientId);
                        Participant participant   = db.Participants.Find(participantId);
                        if (participant == null || participant.Activated)
                        {
                            continue;
                        }
                        participant.Activated  = true;
                        participant.HVPersonId = connection.PersonId;
                        participant.HVRecordId = connection.RecordId;
                        db.SaveChanges();
                    }
                }
                catch (Exception ex)
                {
                    throw new Exception("ERROR: Unable to update Participants information: " + ex.Message.ToString(), ex);
                }
            }
        }