Exemplo n.º 1
0
 private void RemoveDeviceMAC(PersonalDevice device, RockContext rockContext)
 {
     device.LoadAttributes();
     //Archive the mac address
     device.SetAttributeValue("ArchivedMACAddress", device.MACAddress);
     device.MACAddress = "";
     device.SaveAttributeValues();
     rockContext.SaveChanges();
 }
Exemplo n.º 2
0
        public void deleteDevice(PersonalDevice personalDevice, RockContext rockContext)
        {
            // Check to see if a mac address exists, if so, delete from front Porch

            string macAddress = personalDevice.MACAddress;

            if (macAddress != null)
            {
                var authToken      = GlobalAttributesCache.Value("APIAuthorizationToken");
                var hostAddr       = GlobalAttributesCache.Value("Host");
                var authentication = string.Format("authorization-token:{0}", authToken);
                var url            = string.Format("https://{0}/api/user/delete?mac={1}", hostAddr, macAddress);
                if (authToken.IsNotNullOrWhiteSpace() && hostAddr.IsNotNullOrWhiteSpace())
                {
                    HttpWebRequest request = ( HttpWebRequest )WebRequest.Create(url);

                    try
                    {
                        HttpWebResponse response = ( HttpWebResponse )request.GetResponse();

                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            devicesProcessed++;
                            personalDevice.ModifiedDateTime = RockDateTime.Now;
                            if (personalDevice.MACAddress != null)
                            {
                                personalDevice.LoadAttributes();
                                if (personalDevice.Attributes.ContainsKey("ArchivedMACAddress"))
                                {
                                    personalDevice.SetAttributeValue("ArchivedMACAddress", personalDevice.MACAddress);
                                }
                                personalDevice.MACAddress = null;
                                personalDevice.SaveAttributeValues(rockContext);
                                rockContext.SaveChanges();
                            }
                        }
                        else
                        {
                            deviceErrors++;
                            _processingErrors.Add(string.Format("{0}", macAddress));
                        }
                    }
                    catch (Exception ex)
                    {
                        string deviceDetails = string.Format("{0}", macAddress);
                        _exceptionMsgs.Add(deviceDetails + ": " + ex.Message);
                        //throw new Exception( "Exception occurred processing workflow: " + deviceDetails, ex );
                    }
                }
            }
        }