Ejemplo n.º 1
0
        public static ActiveDevice CreateActiveDevice(int deviceId)
        {
            ActiveDevice ad = null;

            try {
                ad = Populate(deviceId);
            } catch {
                // Device not active, actiavate it

                ad         = new ActiveDevice();
                ad.context = new marcdissertation_dbEntities();

                ad.DeviceId       = deviceId;
                ad.LastActiveSend = DateTime.Now;
                ad.LastFetch      = DateTime.Now.AddMinutes(-3);

                ad     = ad.context.ActiveDevices.Add(ad);
                errors = ad.context.GetValidationErrors();

                try {
                    ad.context.SaveChanges();
                } catch {
                    throw App.ExceptionFormatter(errors);
                }
            }

            return(ad);
        }
Ejemplo n.º 2
0
        public static ActiveDevice CreateActiveDevice(int deviceId)
        {
            ActiveDevice ad = null;
            try {
                ad = Populate(deviceId);
            } catch {
                // Device not active, actiavate it

                ad = new ActiveDevice();
                ad.context = new marcdissertation_dbEntities();

                ad.DeviceId = deviceId;
                ad.LastActiveSend = DateTime.Now;
                ad.LastFetch = DateTime.Now.AddMinutes(-3);

                ad = ad.context.ActiveDevices.Add(ad);
                errors = ad.context.GetValidationErrors();

                try {
                    ad.context.SaveChanges();
                } catch {
                    throw App.ExceptionFormatter(errors);
                }

            }

            return ad;
        }
Ejemplo n.º 3
0
        public static ActiveDevice Populate(int deviceId)
        {
            try {
                marcdissertation_dbEntities ctxt = new marcdissertation_dbEntities();

                //  ad.context
                //ActiveDevice ad = new ActiveDevice();
                //ad.context = new marcdissertation_dbEntities();


                ActiveDevice ad = (from x in ctxt.ActiveDevices
                                   where x.DeviceId == deviceId
                                   select x).First();
                ad.context = ctxt;

                return(ad);
            } catch {
                throw new Exception("Device not active");
            }
        }