public async Task <HttpResponseMessage> UpdateDeviceAsync(dynamic device)
 {
     return(await GetServiceResponseAsync <bool>(async() =>
     {
         await _deviceLogic.UpdateDeviceAsync(device);
         return true;
     }));
 }
Exemple #2
0
 public async Task <HttpResponseMessage> UpdateDeviceAsync(DeviceModel device)
 {
     ValidateArgumentNotNull("device", device);
     return(await GetServiceResponseAsync <bool>(async() =>
     {
         await _deviceLogic.UpdateDeviceAsync(device);
         return true;
     }));
 }
Exemple #3
0
        public async Task <HttpResponseMessage> CheckInAsync(string id, string user)
        {
            ValidateArgumentNotNullOrWhitespace("id", id);

            return(await GetServiceResponseAsync <dynamic>(async() =>
            {
                dynamic device = await _deviceLogic.GetDeviceAsync(id);
                device.DeviceProperties.MessengerUser = user;
                try
                {
                    await _deviceLogic.UpdateDeviceAsync(device);
                    return true;
                }
                catch (Exception)
                {
                    return false;
                }
            }));
        }
Exemple #4
0
        private async Task UpdateDeviceAssociation(string deviceId, string iccid)
        {
            if (string.IsNullOrEmpty(deviceId))
            {
                throw new ArgumentNullException();
            }

            DeviceModel device = await _deviceLogic.GetDeviceAsync(deviceId);

            device.SystemProperties.ICCID = iccid;
            await _deviceLogic.UpdateDeviceAsync(device);
        }
        private async Task <ActionResult> Edit(EditDevicePropertiesModel model)
        {
            if (model != null)
            {
                var device = await _deviceLogic.GetDeviceAsync(model.DeviceId);

                if (device != null)
                {
                    _deviceLogic.ApplyDevicePropertyValueModels(device, model.DevicePropertyValueModels);
                    await _deviceLogic.UpdateDeviceAsync(device);
                }
            }

            return(RedirectToAction("Index"));
        }
        private async void UpdateDeviceRecord(FeedbackRecord record, DateTime enqueuDateTime)
        {
            Trace.TraceInformation(
                "{0}{0}*** Processing Feedback Record ***{0}{0}DeviceId: {1}{0}OriginalMessageId: {2}{0}Result: {3}{0}{0}",
                Console.Out.NewLine,
                record.DeviceId,
                record.OriginalMessageId,
                record.StatusCode);

            var device = await _deviceLogic.GetDeviceAsync(record.DeviceId);

            var existingCommand = device?.CommandHistory.FirstOrDefault(x => x.MessageId == record.OriginalMessageId);

            if (existingCommand == null)
            {
                return;
            }

            var updatedTime = record.EnqueuedTimeUtc;

            if (updatedTime == default(DateTime))
            {
                updatedTime = enqueuDateTime == default(DateTime) ? DateTime.UtcNow : enqueuDateTime;
            }

            existingCommand.UpdatedTime = updatedTime;
            existingCommand.Result      = record.StatusCode.ToString();

            if (record.StatusCode == FeedbackStatusCode.Success)
            {
                existingCommand.ErrorMessage = string.Empty;
            }


            await _deviceLogic.UpdateDeviceAsync(device);
        }
Exemple #7
0
        private async Task RunProcess(CancellationToken token)
        {
            FeedbackBatch batch;
            FeedbackReceiver <FeedbackBatch> batchReceiver;
            dynamic device;
            dynamic existingCommand;
            IEnumerable <FeedbackRecord> records;
            ServiceClient serviceClient;
            DateTime      updatedTime;

            if (token == null)
            {
                throw new ArgumentNullException("token");
            }

            serviceClient = null;
            try
            {
                serviceClient =
                    ServiceClient.CreateFromConnectionString(
                        _iotHubConnectionString);

                await serviceClient.OpenAsync();

                while (!token.IsCancellationRequested)
                {
                    batchReceiver = serviceClient.GetFeedbackReceiver();
                    batch         =
                        await batchReceiver.ReceiveAsync(
                            TimeSpan.FromSeconds(10.0));

                    if ((batch == null) ||
                        ((records = batch.Records) == null))
                    {
                        continue;
                    }

                    records =
                        records.Where(
                            t =>
                            (t != null) &&
                            !string.IsNullOrEmpty(t.DeviceId) &&
                            !string.IsNullOrEmpty(t.OriginalMessageId));
                    foreach (FeedbackRecord record in records)
                    {
                        device =
                            await _deviceLogic.GetDeviceAsync(record.DeviceId);

                        if (device == null)
                        {
                            continue;
                        }

                        Trace.TraceInformation(
                            "{0}{0}*** Processing Feedback Record ***{0}{0}DeviceId: {1}{0}OriginalMessageId: {2}{0}Result: {3}{0}{0}",
                            Console.Out.NewLine,
                            record.DeviceId,
                            record.OriginalMessageId,
                            record.StatusCode);

                        existingCommand =
                            CommandHistorySchemaHelper.GetCommandHistoryItemOrDefault(
                                device,
                                record.OriginalMessageId);

                        if (existingCommand == null)
                        {
                            continue;
                        }

                        updatedTime = record.EnqueuedTimeUtc;
                        if (updatedTime == default(DateTime))
                        {
                            updatedTime = batch.EnqueuedTime;
                        }

                        if (updatedTime == default(DateTime))
                        {
                            updatedTime = DateTime.UtcNow;
                        }

                        existingCommand.UpdatedTime = updatedTime;

                        existingCommand.Result = record.StatusCode.ToString();

                        if (record.StatusCode == FeedbackStatusCode.Success)
                        {
                            existingCommand.ErrorMessage = string.Empty;
                        }

                        CommandHistorySchemaHelper.UpdateCommandHistoryItem(
                            device,
                            existingCommand);

                        await _deviceLogic.UpdateDeviceAsync(device);
                    }

                    await batchReceiver.CompleteAsync(batch);
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError(
                    "Error in MessageFeedbackProcessor.RunProcess, Exception: {0}",
                    ex.Message);
            }

            if (serviceClient != null)
            {
                await serviceClient.CloseAsync();
            }

            _isRunning = false;
        }