private String CreateJob(Uri entityUri, String tenantId, CalloutData calloutData) { var token = calloutData.CallbackUrl.Split('(', ')')[1]; SetCoreServiceCredentialsBasedOnConfigValues(); _coreService.AddToJobs(new Job { State = JobStateEnum.Running.ToString(), Type = CALLOUT_JOB_TYPE, Parameters = JsonConvert.SerializeObject(calloutData), ReferencedItemId = entityUri.ToString(), TenantId = tenantId, Token = token }); _coreService.SaveChanges(); return(token); }
private Job CreateSampleJob() { var calloutData = new CalloutData { EntityType = "EntityType", EntityId = ENTITY_ID }; return(new Job { Id = 1, Type = CALLOUT_JOB_TYPE, State = JobStateEnum.Running.ToString(), Parameters = JsonConvert.SerializeObject(calloutData), Token = SAMPLE_TOKEN }); }
public void ExecuteCallout(String definitionParameters, CalloutData data) { var requestUrl = ExtractUrlFromDefinition(definitionParameters); var headers = ExtractAuthorizationHeadersFromDefinition(definitionParameters); if (null == data) { Debug.WriteLine("CalloutData is null"); throw new ArgumentNullException("data", "CalloutData must not be null"); } Debug.WriteLine("Executing callout to '{0}'", requestUrl.ToString()); try { _restCallExecutor.Invoke(HttpMethod.Post, requestUrl.ToString(), headers, JsonConvert.SerializeObject(data)); } catch (HttpRequestException e) { Debug.WriteLine("Error occurred while executing callout: {0}", e.Message); throw; } }
private void DoPostCallout(Uri entityUri, String entity, String condition, String tenantId) { CalloutData postCalloutData = null; String token = null; try { var postCalloutDefinition = LoadCalloutDefinition(condition, entityUri, tenantId, Model.CalloutDefinition.CalloutDefinitionType.Post.ToString()); ChangeEntityState(entityUri, entity, condition); if (null != postCalloutDefinition) { postCalloutData = CreatePostCalloutData(entityUri, entity, condition); token = CreateJob(entityUri, tenantId, postCalloutData); lock (_lock) { _calloutExecutor.ExecuteCallout(postCalloutDefinition.Parameters, postCalloutData); } } } catch (Exception e) { Debug.WriteLine("An error occurred while preparing or executing post '{0}' callout for entity with id '{1}'", condition, entityUri.ToString()); if (null != token) { ChangeJobState(token, JobStateEnum.Failed); } if (postCalloutData != null) { SetEntityState(entityUri, entity, postCalloutData.OriginalState); } DeleteStateChangeLockOfEntity(entityUri); throw new InvalidOperationException(e.Message); } }
internal PcreCallout(CalloutData data) { _data = data; }