Exemplo n.º 1
0
        public async Task RegisterCurrentDeviceAsync()
        {
            if (Interlocked.CompareExchange(ref _registrationInProgress, 1, 0) != 0)
            {
                throw new AppacitiveRuntimeException("Current device is already being initialized.");
            }
            try
            {
                /// Get device from local storage.
                /// Incase one does not exist then we set it up.
                var currentDevice = _platform.DeviceState.GetDevice();
                if (currentDevice != null)
                {
                    return;
                }
                var deviceState = _platform.DeviceState;

                var instanceId = Guid.NewGuid().ToString();
                var device     = new APDevice(deviceState.DeviceType);
                device.SetAttribute("instance-id", instanceId);
                device.DeviceToken = "-";
                await device.SaveAsync();

                deviceState.SetDevice(device);
            }
            finally
            {
                _registrationInProgress = 0;
            }
        }
Exemplo n.º 2
0
        private void UpdateIfCurrentDevice(APDevice updatedDevice)
        {
            var platform = InternalApp.Current.Platform as IDevicePlatform;

            if (platform == null)
            {
                return;
            }
            var device = platform.DeviceState.GetDevice();

            if (device == null || device.Id != updatedDevice.Id)
            {
                return;
            }

            // As the updated device is the same as the current device, then update the current device.
            platform.DeviceState.SetDevice(updatedDevice);
        }
Exemplo n.º 3
0
        public async Task RegisterCurrentDeviceAsync()
        {
            if (Interlocked.CompareExchange(ref _registrationInProgress, 1, 0) != 0)
                throw new AppacitiveRuntimeException("Current device is already being initialized.");
            try
            {
                /// Get device from local storage. 
                /// Incase one does not exist then we set it up.
                var currentDevice = _platform.DeviceState.GetDevice();
                if (currentDevice != null) return;
                var deviceState = _platform.DeviceState;

                var instanceId = Guid.NewGuid().ToString();
                var device = new APDevice(deviceState.DeviceType);
                device.SetAttribute("instance-id", instanceId);
                device.DeviceToken = "-";
                await device.SaveAsync();
                deviceState.SetDevice(device);
            }
            finally
            {
                _registrationInProgress = 0;
            }
        }
Exemplo n.º 4
0
        private void UpdateIfCurrentDevice(APDevice updatedDevice)
        {
            var platform = InternalApp.Current.Platform as IDevicePlatform;
            if (platform == null) return;
            var device = platform.DeviceState.GetDevice();
            if (device == null || device.Id != updatedDevice.Id) return;

            // As the updated device is the same as the current device, then update the current device.
            platform.DeviceState.SetDevice(updatedDevice);
        }