public IActionResult Put([FromBody] BatchTypeInfo info) { try { var stopwatch = StopwatchLogger.Start(_log); _log.Info("Called BatchTypeController Put {0}=", JsonConvert.SerializeObject(info)); var retVal = _managerBatchType.Update(TenantCode, info); stopwatch.StopAndLog("End BatchTypeController put"); return(Ok(retVal)); } catch (Exception ex) { _log.Error(ExceptionFormatter.SerializeToString(ex)); return(StatusCode((int)HttpStatusCode.InternalServerError, ApiConstant.CustomErrorMessage)); } }
private BatchTypeInfo GetBatchType(string body) { BatchTypeInfo result = new BatchTypeInfo(); var contentArray = body.Split(new string[] { "\r\n" }, StringSplitOptions.None); var splitIndex = contentArray[0].IndexOf(":"); if (splitIndex <= 0) { var fragment = new TextFragment() { Code = TextCodes.CrmBatchResponseItemFormatError, DefaultFormatting = "Crm的Batch操作响应项格式错误,响应项内容:{0},错误提示:{1}", ReplaceParameters = new List <object>() { body, "Not correct header format" } }; throw new UtilityException((int)Errors.CrmBatchResponseItemFormatError, fragment); } if (contentArray[0].Length - splitIndex - 1 < 0) { var fragment = new TextFragment() { Code = TextCodes.CrmBatchResponseItemFormatError, DefaultFormatting = "Crm的Batch操作响应项格式错误,响应项内容:{0},错误提示:{1}", ReplaceParameters = new List <object>() { body, "Not correct header format" } }; throw new UtilityException((int)Errors.CrmBatchResponseItemFormatError, fragment); } var headerName = contentArray[0].Substring(0, splitIndex).Trim(); var headerValue = contentArray[0].Substring(splitIndex + 1, contentArray[0].Length - splitIndex - 1).Trim(); if (headerName.ToLower() != "content-type") { var fragment = new TextFragment() { Code = TextCodes.CrmBatchResponseItemFormatError, DefaultFormatting = "Crm的Batch操作响应项格式错误,响应项内容:{0},错误提示:{1}", ReplaceParameters = new List <object>() { body, "First line need content-type" } }; throw new UtilityException((int)Errors.CrmBatchResponseItemFormatError, fragment); } var arrayValue = headerValue.Split(';'); if (arrayValue[0].Trim().ToLower() != "multipart/mixed") { result.Type = 0; } else { result.Type = 1; if (arrayValue.Length < 2) { var fragment = new TextFragment() { Code = TextCodes.CrmBatchResponseItemFormatError, DefaultFormatting = "Crm的Batch操作响应项格式错误,响应项内容:{0},错误提示:{1}", ReplaceParameters = new List <object>() { body, "First line need content-type" } }; throw new UtilityException((int)Errors.CrmBatchResponseItemFormatError, fragment); } var arrayBoundary = arrayValue[1].Split('='); if (arrayBoundary.Length != 2) { var fragment = new TextFragment() { Code = TextCodes.CrmBatchResponseItemFormatError, DefaultFormatting = "Crm的Batch操作响应项格式错误,响应项内容:{0},错误提示:{1}", ReplaceParameters = new List <object>() { body, "Miss changeset boundary" } }; throw new UtilityException((int)Errors.CrmBatchResponseItemFormatError, fragment); } result.Exension = arrayBoundary[1].Trim(); } return(result); }
BatchTypeReturnMessage IBatchTypes.OnExecute(dynamic obj) { try { var tenantId = (Guid)obj[0]; BatchTypeInfo batchType = (BatchTypeInfo)obj[1]; var result = _iSettingManager.GetSettingsByContext(tenantId, SettingContextTypeEnum.EMAIL); if (result != null) { EmailSenderOptions options = Newtonsoft.Json.JsonConvert.DeserializeObject <EmailSenderOptions>(result.Content); //get mail in draft mode var queryFilter1 = new List <QueryFilter>(); queryFilter1.Add(new QueryFilter { FieldName = "CurrentWorkFlowStep", Operator = "Equal", Value = WorkFlowEngine.Draft.ToString() }); queryFilter1.Add(new QueryFilter { FieldName = "TenantId", Operator = "Equal", Value = tenantId.ToString() }); // queryFilter1.Add(new QueryFilter{FieldName="CurrentWorkFlowStep",Operator="Equal" ,Value= WorkFlowEngine.Fail.ToString()}); var queryContext1 = new QueryContext { Fields = "Date,Recipient,Sender,Subject,Body,CurrentWorkFlowStep", Filters = queryFilter1, PageSize = 100, PageIndex = 1 }; var emails = _iEntityResourceManager.GetResult(tenantId, "email", queryContext1); var emailMapped = EntityMapper <Email> .Mappers(emails); if (emailMapped.Count > 0) { foreach (var emailMap in emailMapped) { var currentWorkFlowId = Guid.Empty; if (emailMap.CurrentWorkFlowStep.Value == "Draft") { currentWorkFlowId = WorkFlowEngine.Draft; } else if (emailMap.CurrentWorkFlowStep.Value == "Send") { currentWorkFlowId = WorkFlowEngine.Sent; } else if (emailMap.CurrentWorkFlowStep.Value == "Failure") { currentWorkFlowId = WorkFlowEngine.Fail; } else if (emailMap.CurrentWorkFlowStep.Value == "Cancel") { currentWorkFlowId = WorkFlowEngine.Cancel; } var nextSteps = _workFlow.GetNextPossibleSteps(tenantId, "email", "Standard", currentWorkFlowId); var nextTransition = (from nextStep in nextSteps where nextStep.TransitionType.Id == WorkFlowEngine.Sent select nextStep).FirstOrDefault(); try { SendEmail(emailMap.Recipient.Value, emailMap.Subject.Value, emailMap.Body.Value, options); } catch (System.Exception ex) { _log.Error("An error has occurred while sending email", ex.Message); nextTransition = (from nextStep in nextSteps where nextStep.TransitionType.Id == WorkFlowEngine.Fail select nextStep).FirstOrDefault(); } var transitionWapper = new TransitionWapper { EntityName = "email", SubTypeName = "Standard", StepId = nextTransition.InnerStepId, RefId = Guid.Parse(emailMap.InternalId.Value), CurrentTransitionType = currentWorkFlowId, NextTransitionType = nextTransition.TransitionType.Id }; _workFlow.ManageTransitionFirstStep(tenantId, transitionWapper); } } } else { _log.Error("Email gateway not configured"); } } catch (System.Exception ex) { _log.Error("Email send failed", ex.Message); } return(new BatchTypeReturnMessage { NoDataFound = true }); }