예제 #1
0
        /// <summary>
        /// Starts the activity.
        /// </summary>
        /// <param name="activityRequest">The activity request.</param>
        /// <returns></returns>
        public async Task <StartActivityResponse> StartActivity(StartActivityRequest activityRequest)
        {
            var result = new StartActivityResponse();

            try
            {
                _bamActivityLogger.Debug($"Starting Stage Activity - {activityRequest.Serialize()}");
                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);

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

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

                var header = activityRequest.MessageHeader.DeSerialize <Dictionary <string, string> >();
                header["Content-Type"] = "application/json";
                var body = new ActivityContent
                {
                    MessageBody   = activityRequest.MessageBody,
                    MessageHeader = header.Serialize <Object>()
                };


                var uri      = $"{_url}/api/{Constants.Operations.StartActivity}?code={_key}";
                var data     = body.Serialize();
                var response = await _client.PostAsync(uri, new StringContent(data, Encoding.UTF8, "application/json"));

                if (response.IsSuccessStatusCode)
                {
                    result = await response.Content.ReadAsJsonAsync <StartActivityResponse>();
                }
            }
            catch (Exception ex)
            {
                _bamActivityLogger.Error(ex.Message);
            }
            return(result);
        }
예제 #2
0
        /// <summary>
        /// Updates the activity.
        /// </summary>
        /// <param name="activityRequest">The activity request.</param>
        /// <returns></returns>
        public async Task <bool> UpdateActivity(UpdateActivityRequest activityRequest)
        {
            try
            {
                _bamActivityLogger.Debug($"Updating Stage Activity - {activityRequest.Serialize()}");
                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.StageActivityId, activityRequest.StageActivityId.ToString());
                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.Status, Enum.GetName(typeof(StageStatus), activityRequest.Status));
                _client.DefaultRequestHeaders.AddOrReplace(Constants.Headers.ArchiveMessage, Convert.ToString(activityRequest.IsArchiveEnabled));


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

                var header = activityRequest.MessageHeader.DeSerialize <Dictionary <string, object> >();
                header["Content-Type"] = "application/json";
                var body = new ActivityContent
                {
                    MessageBody   = activityRequest.MessageBody,
                    MessageHeader = header.Serialize()
                };

                var uri = $"{_url}/api/{Constants.Operations.UpdateActivity}?code={_key}";

                var data    = body.Serialize();
                var content = await _client.PostAsync(uri, new StringContent(data, Encoding.UTF8, "application/json"));

                return(content.IsSuccessStatusCode);
            }
            catch (Exception ex)
            {
                _bamActivityLogger.Error(ex.Message);
            }

            return(false);
        }