Exemple #1
0
        public async void GetJobsTest()
        {
            List <string> jobResponses = new List <string>()
            {
                @"{
                    ""jobId"": ""73439503-321d-417a-8df6-e816bd618285"",
                    ""queryCondition"": ""select * from devices where deviceId = 'bb544c4d-1e45-4fed-83ef-aee17eb3810a'"",
                    ""createdTime"": ""2016-11-29T07:21:12.4816525Z"",
                    ""startTime"": ""2016-11-29T07:21:11.4793989Z"",
                    ""endTime"": ""2016-11-29T07:22:00.6324486Z"",
                    ""maxExecutionTimeInSeconds"": 3600,
                    ""type"": ""scheduleUpdateTwin"",
                    ""updateTwin"": {
                           ""deviceId"": null,
                           ""etag"": ""*"",
                           ""tags"": {""position"": ""Redmond""},
                           ""properties"": {""desired"": {},""reported"": {}}
                    },
                    ""status"": ""completed""
                }",
            };
            JobRepositoryModel repositoryModel = fixture.Create <JobRepositoryModel>();

            iotHubDeviceManager.Setup(x => x.GetJobResponsesAsync()).ReturnsAsync(jobResponses);
            jobRepository.Setup(x => x.QueryByJobIDAsync(It.IsNotNull <string>())).ReturnsAsync(repositoryModel);
            var result = await controller.GetJobs();

            result.AssertOnError();
            result.ExtractContentAs <DataTablesResponse <DeviceJobModel> >();
        }
Exemple #2
0
        public async Task <IEnumerable <JobRepositoryModel> > UpdateAssociatedFilterNameAsync(IEnumerable <JobRepositoryModel> jobs)
        {
            var tasks = jobs.Select(async job => {
                var operation = TableOperation.Replace(new JobTableEntity(job)
                {
                    ETag = "*"
                });
                try
                {
                    return(await _azureTableStorageClient.ExecuteAsync(operation));
                }
                catch
                {
                    return(null);
                }
            });

            var tableResults = await Task.WhenAll(tasks);

            return(tableResults.Select(r =>
            {
                JobRepositoryModel model = null;
                if (r?.Result != null && r.Result.GetType() == typeof(JobTableEntity))
                {
                    model = new JobRepositoryModel((JobTableEntity)r.Result);
                }
                return model;
            }));
        }
        public static async Task AddMoreDetailsToJobAsync(DeviceJobModel job, Task <JobRepositoryModel> queryJobRepositoryTask)
        {
            try
            {
                JobRepositoryModel repositoryModel = await queryJobRepositoryTask;

                job.JobName  = repositoryModel.JobName ?? Strings.NotApplicableValue;
                job.FilterId = repositoryModel.FilterId;

                string filterName = repositoryModel.FilterName;
                if (string.IsNullOrEmpty(filterName))
                {
                    filterName = job.QueryCondition ?? Strings.NotApplicableValue;
                }
                if (filterName == "*" || DeviceListFilterRepository.DefaultDeviceListFilter.Id.Equals(job.FilterId))
                {
                    filterName = Strings.AllDevices;
                }
                job.FilterName = filterName;

                if (repositoryModel.JobType != ExtendJobType.Unknown)
                {
                    job.OperationType = repositoryModel.JobType.LocalizedString();
                }
            }
            catch
            {
                job.JobName    = string.Format(Strings.ExternalJobNamePrefix, job.JobId);
                job.FilterId   = string.Empty;
                job.FilterName = job.QueryCondition ?? Strings.NotApplicableValue;
            }
        }
Exemple #4
0
        public async Task AddAsync(JobRepositoryModel job)
        {
            var entity = new JobTableEntity(job);
            var result = await _azureTableStorageClient.DoTableInsertOrReplaceAsync(entity, e => (object)null);

            if (result.Status != TableStorageResponseStatus.Successful)
            {
                throw new JobRepositorySaveException(job.JobId);
            }
        }
Exemple #5
0
 private bool IsModelCreatedByEntity(JobRepositoryModel model, JobTableEntity entity)
 {
     return(model.JobId == entity.JobId &&
            model.FilterName == entity.FilterName &&
            model.JobName == entity.JobName);
 }