コード例 #1
0
        public async Task <StartActivityResponse> StartActivity(StartActivityRequest activityRequest)
        {
            var result = new StartActivityResponse();

            try
            {
                _bamActivityLogger.Debug($"Starting Stage Activity - {JsonConvert.SerializeObject(activityRequest)}");
                activityRequest.Validate();


                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.BusinessProcess, activityRequest.BusinessProcess);
                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.BusinessTransaction, activityRequest.BusinessTransaction);
                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.CurrentStage, activityRequest.CurrentStage);
                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.MainActivityId, activityRequest.MainActivityId.ToString());
                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.PreviousStage, activityRequest.PreviousStage);
                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.ArchiveMessage, Convert.ToString(activityRequest.IsArchiveEnabled));
                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.BatchId, activityRequest.BatchId);
                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.ResourceId, activityRequest.ResourceId);

                if (activityRequest.MessageHeader == null)
                {
                    activityRequest.MessageHeader = "{\"Content-Type\":\"application/json\"}";
                }

                if (activityRequest.MessageBody == null)
                {
                    activityRequest.MessageBody = "{}";
                }

                if (string.IsNullOrEmpty(activityRequest.PreviousStage))
                {
                    activityRequest.PreviousStage = ".";
                }

                var header = JsonConvert.DeserializeObject <Dictionary <string, string> >(activityRequest.MessageHeader);
                header["Content-Type"] = "application/json";

                var activityContent = new ActivityContent
                {
                    MessageBody   = activityRequest.MessageBody,
                    MessageHeader = activityRequest.MessageHeader
                };

                var uri      = $"{_url}/api/{Constants.Operations.StartActivity}";
                var data     = new StringContent(JsonConvert.SerializeObject(activityContent), Encoding.UTF8, "application/json");
                var response = await _client.PostAsync(uri, data);

                if (response.IsSuccessStatusCode)
                {
                    result = JsonConvert.DeserializeObject <StartActivityResponse>(response.Content.ReadAsStringAsync().Result);
                }
            }
            catch (Exception ex)
            {
                _bamActivityLogger.Error(ex.Message);
            }

            return(result);
        }
コード例 #2
0
 public static bool IsValid(this StartActivityResponse activityResponse)
 {
     if (activityResponse.MainActivityId != Guid.Empty && activityResponse.StageActivityId != Guid.Empty)
     {
         return(true);
     }
     return(false);
 }