コード例 #1
0
        /// <summary>
        /// Unregisters a device.
        /// </summary>
        /// <param name="account"></param>
        /// <param name="device"></param>
        /// <returns></returns>
        public IDeviceRegistrationResult UnRegisterDevice(IAccount account, IDevice device)
        {
            IDeviceRegistrationResult result = null;

            if (account != null)
            {
                //Validate that the account actually exists.
                if (!(_accountService.GetItem(account.AccountId) is AccountSuccessResult))
                {
                    result = new DeviceRegistrationFailureResult();
                    result.AddData(new List <string> {
                        "Account does not exist."
                    });
                }
                else
                {
                    var deleteResult = _deviceRepository.DeleteItem(device);

                    if (deleteResult is DeviceRegistrationSuccessResult)
                    {
                        result = new DeviceRegistrationSuccessResult()
                        {
                            Item = device
                        };
                    }
                    else
                    {
                        result = new DeviceRegistrationFailureResult()
                        {
                            Data = deleteResult.Data
                        };
                    }
                }
            }

            return(result);
        }
コード例 #2
0
        /// <summary>
        /// Registers a new device (or re-registers an existing device).
        /// </summary>
        /// <param name="account"></param>
        /// <param name="device"></param>
        /// <returns></returns>
        public IDeviceRegistrationResult RegisterDevice(IAccount account, IDevice device)
        {
            IDeviceRegistrationResult result = null;

            if (account != null)
            {
                //Validate that the account actually exists.
                if (!(_accountService.GetItem(account.AccountId) is AccountSuccessResult))
                {
                    result = new DeviceRegistrationFailureResult();
                    result.AddData(new List <string> {
                        "Account does not exist."
                    });
                }
                else
                {
                    //Validate the device.
                    var deviceValidationResult = ValidateDevice(device);

                    if (ValidateDevice(device) is DeviceFailureResult)
                    {
                        result = new DeviceRegistrationFailureResult {
                            Item = device, Data = deviceValidationResult.Data
                        };
                    }
                    else
                    {
                        //Check to see if a device with the same MAC Address is already registered.
                        if (_deviceRepository.DeviceWithMACAddressExists(device.MACAddress))
                        {
                            result = new DeviceRegistrationFailureResult();
                            result.AddData(new List <string> {
                                "A device with the same MAC address is already registered."
                            });
                        }
                        else
                        {
                            device.AccountId = account.AccountId;
                            var createResult = _deviceRepository.CreateItem(device);

                            if (createResult is DeviceRegistrationSuccessResult)
                            {
                                result = new DeviceRegistrationSuccessResult()
                                {
                                    Item = device
                                };
                            }
                            else
                            {
                                result = new DeviceRegistrationFailureResult()
                                {
                                    Data = createResult.Data
                                };
                            }
                        }
                    }
                }
            }

            return(result);
        }