public async Task <IEnumerable <JobServiceModel> > GetJobsAsync(
            JobType?jobType,
            JobStatus?jobStatus,
            int?pageSize,
            string queryFrom,
            string queryTo)
        {
            var from = DateTimeOffsetExtension.Parse(queryFrom, DateTimeOffset.MinValue);
            var to   = DateTimeOffsetExtension.Parse(queryTo, DateTimeOffset.MaxValue);

            var query = this.tenantConnectionHelper.GetJobClient().CreateQuery(
                JobServiceModel.ToJobTypeAzureModel(jobType),
                JobServiceModel.ToJobStatusAzureModel((Microsoft.Azure.Devices.JobStatus?)jobStatus),
                pageSize);

            var results = new List <JobServiceModel>();

            while (query.HasMoreResults)
            {
                var jobs = await query.GetNextAsJobResponseAsync();

                results.AddRange(jobs
                                 .Where(j => j.CreatedTimeUtc >= from && j.CreatedTimeUtc <= to)
                                 .Select(r => new JobServiceModel(r)));
            }

            return(results);
        }
Beispiel #2
0
        public async Task <IEnumerable <JobServiceModel> > GetJobsAsync(
            JobType?jobType,
            JobStatus?jobStatus,
            int?pageSize,
            string queryFrom,
            string queryTo)
        {
            var from = DateTimeOffsetExtension.Parse(queryFrom, DateTimeOffset.MinValue);
            var to   = DateTimeOffsetExtension.Parse(queryTo, DateTimeOffset.MaxValue);
            var data = await this.client.GetAllAsync(DEVICE_JOBS_COLLECTION_ID);

            var Coverteddata = data.Items.Select(CreatejobServiceModel);
            //var query = this.jobClient.CreateQuery(
            //    JobServiceModel.ToJobTypeAzureModel(jobType),
            //    JobServiceModel.ToJobStatusAzureModel(jobStatus),
            //    pageSize);

            var results = new List <JobServiceModel>();

            results.AddRange(Coverteddata
                             .Where(j => j.CreatedTimeUtc >= from && j.CreatedTimeUtc <= to &&
                                    (jobType == null || j.Type.ToString() == JobServiceModel.ToJobTypeAzureModel(jobType).ToString()) &&
                                    (jobStatus == null || j.Status.ToString() == JobServiceModel.ToJobStatusAzureModel(jobStatus).ToString()))
                             .Select(r => r));
            //while (query.HasMoreResults)
            //{
            //    var jobs = await query.GetNextAsJobResponseAsync();

            //}

            return(results);
        }