void IOperationFlowEngine.FirstOperation(Guid tenantId, WorkFlowProcessProperties properties) { var entityId = iMetadataManager.GetEntityContextByEntityName(properties.EntityName); var workFlow = _managerWorkFlow.GetWorkFlow(tenantId, entityId, properties.SubTypeCode); if (workFlow != null) { var steps = _managerWorkFlowStep.GetWorkFlowSteps(tenantId, workFlow.WorkFlowId).ToList(); if (steps.Count > 0) { transactionHistory.CreateTransitionHistory(tenantId, new WorkFlowTransition { TransitionHistoryId = Guid.NewGuid(), RefId = properties.resultId, EntityId = entityId, WorkFlowStepId = steps[0].WorkFlowStepId, StartTime = DateTime.UtcNow, EndTime = DateTime.UtcNow, AssignedUserId = Guid.Empty, AuditInfo = new Entities.Common.AuditDetail { CreatedBy = properties.UserId } }); dynamic jsonObject = new JObject(); jsonObject.CurrentWorkFlowStep = steps[0].TransitionType.Id; IEntityResourceManager _iEntityResourceManager = new VPC.Framework.Business.EntityResourceManager.Contracts.EntityResourceManager(); _iEntityResourceManager.UpdateSpecificField(tenantId, properties.EntityName, properties.resultId, "CurrentWorkFlowStep", steps[0].TransitionType.Id.ToString()); // var resultId = _iEntityResourceManager.UpdateResult (tenantId, properties.UserId,properties.resultId,properties.EntityName, jsonObject, properties.SubTypeCode); } } }
void IBatchTypes.OnExecute(dynamic obj) { VPC.Entities.BatchType.BatchType batchType = (VPC.Entities.BatchType.BatchType)obj[0]; var tenantId = Guid.Parse(batchType.TenantId.Value); try { ISettingManager _iSettingManager = new SettingManager(); IEntityResourceManager _iEntityResourceManager = new VPC.Framework.Business.EntityResourceManager.Contracts.EntityResourceManager(); IManagerBatchItem _managerBatchItem = new ManagerBatchItem(); var result = _iSettingManager.GetSettingsByContext(tenantId, SettingContextTypeEnum.EMAIL); if (result != null) { EmailSenderOptions options = Newtonsoft.Json.JsonConvert.DeserializeObject <EmailSenderOptions>(result.Content); //Get Batch Item var allBatchItems = _managerBatchItem.GetBatchItems(tenantId, new Guid(batchType.InternalId.Value), (batchType.ItemRetryCount.Value.Length > 0 ? (int?)Int32.Parse(batchType.ItemRetryCount.Value) : (int?)null)); foreach (var allBatchItem in allBatchItems) { try { var queryContext = new QueryContext { Fields = "Body,Sender,Recipient,Subject,Id" }; DataTable templatedt = _queryManager.GetResultById(tenantId, "email", allBatchItem.ReferenceId, queryContext); _managerBatchItem.BatchItemUpdateStartTime(tenantId, allBatchItem.BatchItemId); var email = EntityMapper <Email> .Mapper(templatedt); SendEmail(tenantId, allBatchItem, email.Recipient.Value, email.Subject.Value, email.Body.Value, options); //Update batch History _managerBatchItem.BatchHistoryCreate(tenantId, new BatchItemHistory { BatchHistoryId = Guid.NewGuid(), BatchItemId = allBatchItem.BatchItemId, EntityId = allBatchItem.EntityId, ReferenceId = allBatchItem.ReferenceId, Status = EmailEnum.Send, RunTime = allBatchItem.NextRunTime }); //Update Email Status _iEntityResourceManager.UpdateSpecificField(tenantId, "email", allBatchItem.ReferenceId, "Status", ((int)EmailEnum.Send).ToString()); } catch (System.Exception ex) { _log.Error("An error has occurred while sending email", ex.Message); //Update batch History _managerBatchItem.BatchHistoryCreate(tenantId, new BatchItemHistory { BatchHistoryId = Guid.NewGuid(), BatchItemId = allBatchItem.BatchItemId, EntityId = allBatchItem.EntityId, ReferenceId = allBatchItem.ReferenceId, Status = EmailEnum.Fail, RunTime = allBatchItem.NextRunTime, FailedReason = ex.Message }); //Update Batch item status _managerBatchItem.BatchItemUpdate(tenantId, (batchType.ItemRetryCount.Value.Length > 0 ? (int?)Int32.Parse(batchType.ItemRetryCount.Value) : (int?)null), new BatchItem { BatchItemId = allBatchItem.BatchItemId, Status = EmailEnum.Fail, FailedReason = ex.Message }); //Update Email Status _iEntityResourceManager.UpdateSpecificField(tenantId, "email", allBatchItem.ReferenceId, "Status", ((int)EmailEnum.Fail).ToString()); throw ex; } //Update Batch item status _managerBatchItem.BatchItemUpdateStatus(tenantId, new BatchItem { Status = EmailEnum.Send, BatchItemId = allBatchItem.BatchItemId }); } } else { _log.Error("Email gateway not configured"); } } catch (System.Exception ex) { _log.Error("Email send failed", ex.Message); } }