public void ExportJobTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                JobQueryParameter jqp = new JobQueryParameter();

                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                var exportJobResponse = (JobOperationResponse)client.Jobs.Export(jqp, RequestHeaders);

                Assert.True(exportJobResponse != null, "Export Jobs did not return Job Object");
                Assert.False(string.IsNullOrEmpty(exportJobResponse.Job.Name), "Job Id Absent");

                stopWatch.Stop();

                Assert.Equal<string>(exportJobResponse.Job.Properties.State, "Succeeded");
                Assert.Equal(HttpStatusCode.OK, exportJobResponse.StatusCode);
                Assert.True(exportJobResponse.Job.Properties.CustomDetails.InstanceType.Equals(
                    "ExportJobDetails"));
                Assert.False(string.IsNullOrEmpty(
                    ((ExportJobDetails)exportJobResponse.Job.Properties.CustomDetails).BlobUri));
                Assert.False(string.IsNullOrEmpty(
                    ((ExportJobDetails)exportJobResponse.Job.Properties.CustomDetails).SasToken));
            }
        }
        public void ExportJobTest()
        {
            int timeToWaitInMins = 2;
            int waitBeforeRetryInSec = 1;
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                DateTime from = DateTime.Now.ToUniversalTime() - (new TimeSpan(7, 0, 0, 0));
                DateTime to = DateTime.Now.ToUniversalTime();

                JobQueryParameter jqp = new JobQueryParameter();
                jqp.StartTime = from.ToBinary().ToString();
                jqp.EndTime = to.ToBinary().ToString();
                jqp.AffectedObjectTypes = new List<string>();
                jqp.AffectedObjectTypes.Add("Any");
                jqp.JobStatus = new List<string>();
                jqp.JobStatus.Add("Completed");

                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                var exportResponse = client.Jobs.Export(jqp, RequestHeaders);

                Assert.True(exportResponse != null, "Export Jobs did not return Job Object");
                Assert.False(string.IsNullOrEmpty(exportResponse.Job.Name), "Job Id Absent");

                JobResponse getJobResponse = null;
                while (stopWatch.Elapsed.Minutes < timeToWaitInMins)
                {
                    getJobResponse = client.Jobs.Get(exportResponse.Job.Name, RequestHeaders);
                    Assert.True(getJobResponse != null, "Get call on export job returned null");
                    if (getJobResponse.Job.Properties.State.Equals("Succeeded"))
                    {
                        break;
                    }
                    System.Threading.Thread.Sleep(waitBeforeRetryInSec * 1000);
                }
                stopWatch.Stop();

                Assert.Equal<string>(getJobResponse.Job.Properties.State, "Succeeded");
                Assert.Equal(HttpStatusCode.OK, getJobResponse.StatusCode);
                Assert.True(getJobResponse.Job.Properties.CustomDetails.InstanceType.Equals(
                    "ExportJobDetails"));
                Assert.False(string.IsNullOrEmpty(
                    ((ExportJobDetails)getJobResponse.Job.Properties.CustomDetails).BlobUri));
                Assert.False(string.IsNullOrEmpty(
                    ((ExportJobDetails)getJobResponse.Job.Properties.CustomDetails).SasToken));
            }
        }
        /// <summary>
        /// Queries by Parameters.
        /// </summary>
        private void GetByParam()
        {
            JobQueryParameter jqp = new JobQueryParameter();

            IList<Management.SiteRecovery.Models.Job> completeJobsList = RecoveryServicesClient.GetAzureSiteRecoveryJob().Jobs;

            IEnumerable<Management.SiteRecovery.Models.Job> filteredJobsList = completeJobsList.ToArray().AsEnumerable();           
            if (this.StartTime.HasValue)
            {
                filteredJobsList = filteredJobsList.Where(j => j.Properties.StartTime.Value.ToUniversalTime().ToBinary() >= this.StartTime.Value.ToUniversalTime().ToBinary());
            }

            if (this.EndTime.HasValue)
            {
                filteredJobsList = filteredJobsList.Where(j => j.Properties.EndTime.Value.ToUniversalTime().ToBinary() <= this.EndTime.Value.ToUniversalTime().ToBinary());
            }

            if (this.State != null)
            {
                filteredJobsList = filteredJobsList.Where(j => 0 == string.Compare(j.Properties.State.ToString(),
                    this.State.ToString(),StringComparison.OrdinalIgnoreCase));
            }

            if(this.TargetObjectId != null)
            {
                filteredJobsList = filteredJobsList.Where(j => 0 == string.Compare(j.Properties.TargetObjectId.ToString(),
                     this.TargetObjectId.ToString(), StringComparison.OrdinalIgnoreCase));
            }

            this.WriteJobs(filteredJobsList.ToList());
        }
        public void EnumerateJobsTest()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                JobQueryParameter jobQueryParameter = new JobQueryParameter();
                var response = client.Jobs.List(jobQueryParameter, RequestHeaders);

                Assert.True(response.Jobs.Count > 0, "Jobs count can't be less than 1");
                Assert.True(response.Jobs.All(
                    protectedContainer => !string.IsNullOrEmpty(protectedContainer.Name)),
                    "Job name can't be null or empty");
                Assert.True(response.Jobs.All(
                    protectedContainer => !string.IsNullOrEmpty(protectedContainer.Id)),
                    "Job Id can't be null or empty");
                Assert.Equal(HttpStatusCode.OK, response.StatusCode);
            }
        }
 /// <summary>
 /// Get the list of all jobs.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.SiteRecovery.IJobOperations.
 /// </param>
 /// <param name='parameters'>
 /// Optional. Job query parameter.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The response model for the list Jobs operation.
 /// </returns>
 public static Task<JobListResponse> ListAsync(this IJobOperations operations, JobQueryParameter parameters, CustomRequestHeaders customRequestHeaders)
 {
     return operations.ListAsync(parameters, customRequestHeaders, CancellationToken.None);
 }
 /// <summary>
 /// Get the list of all jobs.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.SiteRecovery.IJobOperations.
 /// </param>
 /// <param name='parameters'>
 /// Optional. Job query parameter.
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// The response model for the list Jobs operation.
 /// </returns>
 public static JobListResponse List(this IJobOperations operations, JobQueryParameter parameters, CustomRequestHeaders customRequestHeaders)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IJobOperations)s).ListAsync(parameters, customRequestHeaders);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
        /// <summary>
        /// Queries by Parameters.
        /// </summary>
        private void GetByParam()
        {
            JobQueryParameter jqp = new JobQueryParameter();

            //if (this.StartTime.HasValue)
            //{
            //    jqp.StartTime =
            //        this.StartTime.Value.ToUniversalTime().ToBinary().ToString();
            //}

            //if (this.EndTime.HasValue)
            //{
            //    jqp.EndTime =
            //        this.EndTime.Value.ToUniversalTime().ToBinary().ToString();
            //}

            //jqp.State = this.State;
            //jqp.ObjectId = this.TargetObjectId;

            this.WriteJobs(RecoveryServicesClient.GetAzureSiteRecoveryJob(jqp).Jobs);
        }
 /// <summary>
 /// Get Azure Site Recovery Job.
 /// </summary>
 /// <returns>Job list response</returns>
 public JobListResponse GetAzureSiteRecoveryJob(JobQueryParameter jqp)
 {
     return this.GetSiteRecoveryClient().Jobs.List(jqp, this.GetRequestHeaders(false));
 }
 /// <summary>
 /// Export jobs to blob.
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.SiteRecovery.IJobOperations.
 /// </param>
 /// <param name='parameters'>
 /// Required. Job Query Filters
 /// </param>
 /// <param name='customRequestHeaders'>
 /// Optional. Request header parameters.
 /// </param>
 /// <returns>
 /// A standard service response for long running operations.
 /// </returns>
 public static Task<LongRunningOperationResponse> ExportAsync(this IJobOperations operations, JobQueryParameter parameters, CustomRequestHeaders customRequestHeaders)
 {
     return operations.ExportAsync(parameters, customRequestHeaders, CancellationToken.None);
 }