private Envelope GetEnvelope(ActionContextInfo context) { var envId = context.CurrentDocument.Fields.GetByID(Configuration.InputParameters.EnvelopeFieldId).GetValue().ToString(); var apiClient = new ApiClient(); _logger.AppendLine("Downloading envelope"); return(new ApiHelper(apiClient, Configuration.ApiSettings, _logger).GetEnvelop(envId)); }
private void SaveEmbededInfoOnForm(ActionContextInfo context, EnvelopeDefinition envelop, string documentsInfoToSave) { var signer = envelop.CompositeTemplates.First().InlineTemplates.First().Recipients.Signers.First(); context.CurrentDocument.Fields.GetByID(Configuration.EmbededSigningConfig.SignerNameFieldId).SetValue(signer.Name); context.CurrentDocument.Fields.GetByID(Configuration.EmbededSigningConfig.SignerMailFieldId).SetValue(signer.Email); context.CurrentDocument.Fields.GetByID(Configuration.EmbededSigningConfig.RecipientIdFieldId).SetValue(signer.RecipientId); context.CurrentDocument.Fields.GetByID(Configuration.EmbededSigningConfig.ClientUserIdFieldId).SetValue(signer.ClientUserId); context.CurrentDocument.Fields.GetByID(Configuration.OutputParameters.TechnicalFieldID).SetValue(documentsInfoToSave); }
private AttachmentData GetAttachment(ActionContextInfo context) { if (Configuration.AttConfig.InputAttType == InputType.Category) { _log.AppendLine("Downloading attachments by category"); var allAttachments = DocumentAttachmentsManager.GetAttachments(new GetAttachmentsParams() { DocumentId = context.CurrentDocument.ID, IncludeContent = true }); if (Configuration.AttConfig.CatType == CategoryType.ID) { return(allAttachments.FirstOrDefault(x => x.FileGroup.ID == Configuration.AttConfig.InputCategoryId.ToString() && (string.IsNullOrEmpty(Configuration.AttConfig.AttRegularExpression) || Regex.IsMatch(x.FileName, Configuration.AttConfig.AttRegularExpression)))); } else if (Configuration.AttConfig.CatType == CategoryType.None) { return(allAttachments.FirstOrDefault(x => x.FileGroup == null && (string.IsNullOrEmpty(Configuration.AttConfig.AttRegularExpression) || Regex.IsMatch(x.FileName, Configuration.AttConfig.AttRegularExpression)))); } else { return(allAttachments.First()); } } else { _log.AppendLine("Downloading attachments by SQL query"); var attId = SqlExecutionHelper.ExecSqlCommandScalar(Configuration.AttConfig.AttQuery, context); if (attId == null) { throw new Exception("Sql query not returning result"); } return(DocumentAttachmentsManager.GetAttachment(Convert.ToInt32(attId))); } }
public async Task <Result <object> > Add(ManageEntityRequest request) { using (var repository = _implementations.GetBusinessRepository()) { var map = new Dictionary <string, object>(); var actionContext = new ActionContextInfo { CurrentEntity = request.Entity, EntityType = _implementations.Metadata[request.EntityTypeName], Type = ActionContextType.Add }; var result = await AddRecursive(request, repository, map, "", actionContext); if (!result.Succeeded) { return(result); } await _entityHandler.SaveChanges(repository, request.EntityTypeName); return(map[""]); } }
private void SetFields(Tuple <EnvelopeSummary, string> summary, ActionContextInfo context) { context.CurrentDocument.Fields.GetByID(Configuration.OutputParameters.EnvelopeFieldId).SetValue(summary.Item1.EnvelopeId); context.CurrentDocument.Fields.GetByID(Configuration.OutputParameters.TechnicalFieldID).SetValue(summary.Item2); }
public DataHelper(StringBuilder logger, ActionContextInfo context) { _logger = logger; Context = context; }
private EnvelopeSummary SendEmails(List <AttachmentData> documents, List <SignerData> signer, ActionContextInfo context) { var envelope = CreateEnvelope(); var sendHelper = new EnvelopSendingHelper(_logger, Configuration, Configuration.RecipientSelection.UseSMS); sendHelper.CompleteEnvelopeData(envelope, documents, signer, out string documentsInfoToSave); envelope.CompositeTemplates.FirstOrDefault().InlineTemplates.FirstOrDefault().Recipients.Signers.FirstOrDefault().ClientUserId = Guid.NewGuid().ToString(); SaveEmbededInfoOnForm(context, envelope, documentsInfoToSave); var apiClient = new ApiClient(); _logger.AppendLine("Sending envelope"); return(new ApiHelper(apiClient, Configuration.ApiSettings, _logger).SendEnvelope(envelope)); }
private async Task <Result <object> > AddRecursive(ManageEntityRequest request, IDisposable repository, Dictionary <string, object> map , string currentObjectPath, ActionContextInfo actionContext) { var entityType = _implementations.Metadata[request.EntityTypeName]; object entity; if (!entityType.NotMapped()) { foreach (var prop in entityType.GetAllProperties().Where(x => x.DataType == DataTypes.NavigationEntity)) { if (prop.HideInInsert() || prop.ForeignKey == null) { continue; } if (actionContext.ExcludedProperties == null) { actionContext.ExcludedProperties = new List <string> { }; } (actionContext.ExcludedProperties as List <string>).Add(prop.ForeignKey.Name); } var result = await _entityHandler.Add(request, repository, actionContext); if (!result.Succeeded) { // TODO: Here, the error messages should be prepended by the path to the current entity return(result); } entity = result.Data; } else { entity = Activator.CreateInstance(_implementations.Reflector.GetType(request.EntityTypeName)); } if (map.TryGetValue(currentObjectPath, out var existingValue)) { existingValue.GetType().GetMethod("Add").Invoke(existingValue, new object[] { entity }); } if (map.TryGetValue(currentObjectPath, out var list)) { (list as IList).Add(entity); } else { map.Add(currentObjectPath, entity); } foreach (var pair in map) { if (!currentObjectPath.StartsWith(pair.Key)) { continue; } var itemType = pair.Value.GetType(); if (itemType.IsGenericType) { itemType = itemType.GetGenericArguments().Single(); } var typeMetadata = _implementations.Metadata[itemType.Name]; foreach (var property in typeMetadata.GetAllProperties()) { var path = JoinPath(pair.Key, property.Name); if (path == currentObjectPath) { SetPropertyValue(pair.Value, property, entity); } } } foreach (var propertyMetadata in entityType.GetAllProperties()) { var propertyPath = JoinPath(currentObjectPath, propertyMetadata.Name); if (map.TryGetValue(propertyPath, out var val)) { SetPropertyValue(entity, propertyMetadata, val); } if (propertyMetadata.HideInInsert()) { continue; } var value = (request.Entity as JObject)[propertyMetadata.Name]; //if (propertyMetadata.DataType == DataTypes.NavigationEntity) //{ // var relatedEntity = await AddRecursive(new ManageEntityRequest // { // EntityTypeName = propertyMetadata.EntityTypeName, // Entity = value // }, repository, map, propertyPath); //} if (propertyMetadata.DataType == DataTypes.NavigationList) { map.Add(propertyPath, Activator.CreateInstance(typeof(List <>).MakeGenericType(_implementations.Reflector.GetType(propertyMetadata.EntityTypeName)))); if (!(value is IEnumerable collection)) { continue; } foreach (var item in collection) { var childActionContext = new ActionContextInfo { CurrentEntity = item, CurrentList = collection, EntityType = _implementations.Metadata[propertyMetadata.EntityTypeName], Masters = actionContext.Masters.Concat(new MasterReference(entity, propertyMetadata)), Parent = actionContext, Property = propertyMetadata, Type = ActionContextType.Add }; await AddRecursive(new ManageEntityRequest { EntityTypeName = propertyMetadata.EntityTypeName, Entity = item }, repository, map, propertyPath, childActionContext); } } } return(map[currentObjectPath]); }
private void AddDocumentsToAttachments(List <ApiHelper.DocumentFromEnvelope> documents, ActionContextInfo context) { var documentsToOverride = context.CurrentDocument.Fields.GetByID(Configuration.DocumentSettings.TechnicalFieldID).GetValue()?.ToString()?.Split(';'); foreach (var doc in documents) { var currentDocAttId = documentsToOverride .Where(x => TextHelper.GetPairName(x) == doc.DocumentID.ToString()) .Select(x => TextHelper.GetPairId(x)).FirstOrDefault(); var group = CreateGroup(); if (string.IsNullOrEmpty(Configuration.Output.Suffix) && !string.IsNullOrEmpty(currentDocAttId)) { var att = context.CurrentDocument.Attachments.GetByID(Int32.Parse(currentDocAttId)); att.Content = doc.DocumentContent; if (group != null) { att.FileGroup = group; } } else { var att = new NewAttachmentData(CreateNameWithSuffix(doc.Name), doc.DocumentContent); if (group != null) { att.FileGroup = group; } context.CurrentDocument.Attachments.AddNew(att); } } }