internal CloudJobSchedule( BatchClient parentBatchClient, Models.CloudJobSchedule protocolObject, IEnumerable<BatchClientBehavior> baseBehaviors) { this.parentBatchClient = parentBatchClient; InheritUtil.InheritClientBehaviorsAndSetPublicProperty(this, baseBehaviors); this.propertyContainer = new PropertyContainer(protocolObject); }
/// <summary> /// Builds a CloudJobScheduleGetResponse object /// </summary> public static ProxyModels.CloudJobScheduleGetResponse CreateCloudJobScheduleGetResponse(string jobScheduleId) { ProxyModels.CloudJobScheduleGetResponse response = new ProxyModels.CloudJobScheduleGetResponse(); response.StatusCode = HttpStatusCode.OK; ProxyModels.JobSpecification jobSpec = new ProxyModels.JobSpecification(); ProxyModels.Schedule schedule = new ProxyModels.Schedule(); ProxyModels.CloudJobSchedule jobSchedule = new ProxyModels.CloudJobSchedule(jobScheduleId, schedule, jobSpec); response.JobSchedule = jobSchedule; return(response); }
/// <summary> /// Builds a CloudJobScheduleGetResponse object /// </summary> public static AzureOperationResponse <ProxyModels.CloudJobSchedule, ProxyModels.JobScheduleGetHeaders> CreateCloudJobScheduleGetResponse(string jobScheduleId) { var response = new AzureOperationResponse <ProxyModels.CloudJobSchedule, ProxyModels.JobScheduleGetHeaders>(); response.Response = new HttpResponseMessage(HttpStatusCode.OK); ProxyModels.JobSpecification jobSpec = new ProxyModels.JobSpecification(); ProxyModels.Schedule schedule = new ProxyModels.Schedule(); ProxyModels.CloudJobSchedule jobSchedule = new ProxyModels.CloudJobSchedule(id: jobScheduleId, schedule: schedule, jobSpecification: jobSpec); response.Body = jobSchedule; return(response); }
public void CloudJobSchedule_WhenReturnedFromServer_HasExpectedBoundProperties() { const string jobScheduleId = "id-123"; const string displayName = "DisplayNameFoo"; MetadataItem metadataItem = new MetadataItem("foo", "bar"); using (BatchClient client = ClientUnitTestCommon.CreateDummyClient()) { DateTime creationTime = DateTime.Now; var cloudJobSchedule = new Models.CloudJobSchedule { Id = jobScheduleId, DisplayName = displayName, Metadata = new[] { new Models.MetadataItem { Name = metadataItem.Name, Value = metadataItem.Value } }, CreationTime = creationTime, JobSpecification = new Models.JobSpecification { OnAllTasksComplete = Models.OnAllTasksComplete.TerminateJob, OnTaskFailure = Models.OnTaskFailure.PerformExitOptionsJobAction } }; CloudJobSchedule boundJobSchedule = client.JobScheduleOperations.GetJobSchedule( jobScheduleId, additionalBehaviors: InterceptorFactory.CreateGetJobScheduleRequestInterceptor(cloudJobSchedule)); Assert.Equal(jobScheduleId, boundJobSchedule.Id); // reading is allowed from a jobSchedule that is returned from the server. Assert.Equal(creationTime, boundJobSchedule.CreationTime); Assert.Equal(displayName, boundJobSchedule.DisplayName); Assert.Equal(OnAllTasksComplete.TerminateJob, boundJobSchedule.JobSpecification.OnAllTasksComplete); Assert.Equal(OnTaskFailure.PerformExitOptionsJobAction, boundJobSchedule.JobSpecification.OnTaskFailure); Assert.Throws <InvalidOperationException>(() => boundJobSchedule.DisplayName = "cannot-change-display-name"); Assert.Throws <InvalidOperationException>(() => boundJobSchedule.Id = "cannot-change-id"); boundJobSchedule.JobSpecification.OnAllTasksComplete = OnAllTasksComplete.TerminateJob; boundJobSchedule.JobSpecification.OnTaskFailure = OnTaskFailure.NoAction; Assert.Equal(OnAllTasksComplete.TerminateJob, boundJobSchedule.JobSpecification.OnAllTasksComplete); Assert.Equal(OnTaskFailure.NoAction, boundJobSchedule.JobSpecification.OnTaskFailure); } }
/// <summary> /// Refreshes the current <see cref="CloudJobSchedule"/>. /// </summary> /// <param name="detailLevel">The detail level for the refresh. If a detail level which omits the <see cref="Id"/> property is specified, refresh will fail.</param> /// <param name="additionalBehaviors">A collection of <see cref="BatchClientBehavior"/> instances that are applied to the Batch service request after the <see cref="CustomBehaviors"/>.</param> /// <param name="cancellationToken">A <see cref="CancellationToken"/> for controlling the lifetime of the asynchronous operation.</param> /// <returns>A <see cref="System.Threading.Tasks.Task"/> representing the asynchronous refresh operation.</returns> public async System.Threading.Tasks.Task RefreshAsync( DetailLevel detailLevel = null, IEnumerable <BatchClientBehavior> additionalBehaviors = null, CancellationToken cancellationToken = default(CancellationToken)) { // craft the behavior manager for this call BehaviorManager bhMgr = new BehaviorManager(this.CustomBehaviors, additionalBehaviors, detailLevel); // start call System.Threading.Tasks.Task <AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders> > asyncTask = this.parentBatchClient.ProtocolLayer.GetJobSchedule(this.Id, bhMgr, cancellationToken); AzureOperationResponse <Models.CloudJobSchedule, Models.JobScheduleGetHeaders> response = await asyncTask.ConfigureAwait(continueOnCapturedContext : false); // get job schedule from response Models.CloudJobSchedule newProtocolJobSchedule = response.Body; this.propertyContainer = new PropertyContainer(newProtocolJobSchedule); }
public void CloudJobSchedule_WhenReturnedFromServer_HasExpectedBoundProperties() { const string jobScheduleId = "id-123"; const string displayName = "DisplayNameFoo"; MetadataItem metadataItem = new MetadataItem("foo", "bar"); BatchSharedKeyCredentials credentials = ClientUnitTestCommon.CreateDummySharedKeyCredential(); using (BatchClient client = BatchClient.Open(credentials)) { DateTime creationTime = DateTime.Now; var cloudJobSchedule = new Models.CloudJobSchedule { Id = jobScheduleId, DisplayName = displayName, Metadata = new[] { new Models.MetadataItem { Name = metadataItem.Name, Value = metadataItem.Value } }, CreationTime = creationTime }; CloudJobSchedule boundJobSchedule = client.JobScheduleOperations.GetJobSchedule( jobScheduleId, additionalBehaviors: InterceptorFactory.CreateGetJobScheduleRequestInterceptor(cloudJobSchedule)); Assert.Equal(jobScheduleId, boundJobSchedule.Id); // reading is allowed from a jobSchedule that is returned from the server. Assert.Equal(creationTime, boundJobSchedule.CreationTime); Assert.Equal(displayName, boundJobSchedule.DisplayName); Assert.Throws <InvalidOperationException>(() => boundJobSchedule.DisplayName = "cannot-change-display-name"); Assert.Throws <InvalidOperationException>(() => boundJobSchedule.Id = "cannot-change-id"); } }
public PropertyContainer(Models.CloudJobSchedule protocolObject) : base(BindingState.Bound) { this.CreationTimeProperty = this.CreatePropertyAccessor( protocolObject.CreationTime, nameof(CreationTime), BindingAccess.Read); this.DisplayNameProperty = this.CreatePropertyAccessor( protocolObject.DisplayName, nameof(DisplayName), BindingAccess.Read); this.ETagProperty = this.CreatePropertyAccessor( protocolObject.ETag, nameof(ETag), BindingAccess.Read); this.ExecutionInformationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.ExecutionInfo, o => new JobScheduleExecutionInformation(o).Freeze()), nameof(ExecutionInformation), BindingAccess.Read); this.IdProperty = this.CreatePropertyAccessor( protocolObject.Id, nameof(Id), BindingAccess.Read); this.JobSpecificationProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.JobSpecification, o => new JobSpecification(o)), nameof(JobSpecification), BindingAccess.Read | BindingAccess.Write); this.LastModifiedProperty = this.CreatePropertyAccessor( protocolObject.LastModified, nameof(LastModified), BindingAccess.Read); this.MetadataProperty = this.CreatePropertyAccessor( MetadataItem.ConvertFromProtocolCollection(protocolObject.Metadata), nameof(Metadata), BindingAccess.Read | BindingAccess.Write); this.PreviousStateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum<Models.JobScheduleState, Common.JobScheduleState>(protocolObject.PreviousState), nameof(PreviousState), BindingAccess.Read); this.PreviousStateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.PreviousStateTransitionTime, nameof(PreviousStateTransitionTime), BindingAccess.Read); this.ScheduleProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Schedule, o => new Schedule(o)), nameof(Schedule), BindingAccess.Read | BindingAccess.Write); this.StateProperty = this.CreatePropertyAccessor( UtilitiesInternal.MapNullableEnum<Models.JobScheduleState, Common.JobScheduleState>(protocolObject.State), nameof(State), BindingAccess.Read); this.StateTransitionTimeProperty = this.CreatePropertyAccessor( protocolObject.StateTransitionTime, nameof(StateTransitionTime), BindingAccess.Read); this.StatisticsProperty = this.CreatePropertyAccessor( UtilitiesInternal.CreateObjectWithNullCheck(protocolObject.Stats, o => new JobScheduleStatistics(o).Freeze()), nameof(Statistics), BindingAccess.Read); this.UrlProperty = this.CreatePropertyAccessor( protocolObject.Url, nameof(Url), BindingAccess.Read); }
public static IEnumerable <Protocol.RequestInterceptor> CreateGetJobScheduleRequestInterceptor(Protocol.Models.CloudJobSchedule jobScheduleToReturn) { return(CreateGetRequestInterceptor <Protocol.Models.JobScheduleGetOptions, Protocol.Models.CloudJobSchedule, Protocol.Models.JobScheduleGetHeaders>(jobScheduleToReturn)); }
/// <summary> /// Builds a CloudJobScheduleGetResponse object /// </summary> public static ProxyModels.CloudJobScheduleGetResponse CreateCloudJobScheduleGetResponse(string jobScheduleId) { ProxyModels.CloudJobScheduleGetResponse response = new ProxyModels.CloudJobScheduleGetResponse(); response.StatusCode = HttpStatusCode.OK; ProxyModels.JobSpecification jobSpec = new ProxyModels.JobSpecification(); ProxyModels.Schedule schedule = new ProxyModels.Schedule(); ProxyModels.CloudJobSchedule jobSchedule = new ProxyModels.CloudJobSchedule(jobScheduleId, schedule, jobSpec); response.JobSchedule = jobSchedule; return response; }