Ejemplo n.º 1
0
        private void OnDeviceDetected(DeviceAnnouncement device)
        {
            var location = device.Locations.FirstOrDefault();

            var success = _provider.IsWeMoDevice(location);

            if (!success)
            {
                return;
            }

            var newDevice = !_provider.Exists(device.Udn);

            var updatedDevice = _provider.Exists(device.Udn) &&
                                _provider.Get(device.Udn).Location != location;

            var existingDevice = _provider.Exists(device.Udn);

            if (newDevice)
            {
                var weMoDevice = _provider.Create(location);
                Console.WriteLine($"Found new WeMo: {weMoDevice.FriendlyName} @ {weMoDevice.Host}");
            }
            else if (updatedDevice)
            {
                var weMoDevice = _provider.Update(device.Udn, location);
                Console.WriteLine($"Found updated WeMo: {weMoDevice.FriendlyName} @ {weMoDevice.Host}");
            }
            else if (existingDevice)
            {
                var weMoDevice = _provider.Update(device.Udn, location);
                Console.WriteLine($"Found existing WeMo: {weMoDevice.FriendlyName} @ {weMoDevice.Host}");
            }
        }
Ejemplo n.º 2
0
 public async Task <ActionResult> Edit(DeviceEditModel model)
 {
     try
     {
         if (model.Device != null)
         {
             var provider = new DeviceProvider(DomainSession.GetDataContextForUserContext(this.HttpContext));
             model.Result = StatusResponseGenerator.GetStatusResponseResultForReturnParam(provider.Update(model.Device));
             return(View(model));
         }
         else
         {
             model.Result = StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Error.", RequestStatus.Failure);
         }
     }
     catch (Exception e)
     {
         model.Result = StatusResponseGenerator.GetAlertPanelWithMsgAndStat("Error.", RequestStatus.Failure);
     }
     return(View(model));
 }