/// <summary> /// Gets the MergeTemplateType MEF Component for the specified MergeTemplate /// </summary> /// <returns></returns> public MergeTemplateType GetMergeTemplateType() { var mergeTemplateTypeEntityType = EntityTypeCache.Read(this.MergeTemplateTypeEntityTypeId); if (mergeTemplateTypeEntityType == null) { return(null); } return(MergeTemplateTypeContainer.GetComponent(mergeTemplateTypeEntityType.Name)); }
/// <summary> /// Gets the type of the merge template. /// </summary> /// <param name="rockContext">The rock context.</param> /// <param name="mergeTemplate">The merge template.</param> /// <returns></returns> private MergeTemplateType GetMergeTemplateType(RockContext rockContext, MergeTemplate mergeTemplate) { mergeTemplate = new MergeTemplateService(rockContext).Get(mtPicker.SelectedValue.AsInteger()); if (mergeTemplate == null) { return(null); } var mergeTemplateTypeEntityType = EntityTypeCache.Read(mergeTemplate.MergeTemplateTypeEntityTypeId); if (mergeTemplateTypeEntityType == null) { return(null); } return(MergeTemplateTypeContainer.GetComponent(mergeTemplateTypeEntityType.Name)); }
/// <summary> /// Handles the FileUploaded event of the fuTemplateBinaryFile control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> protected void fuTemplateBinaryFile_FileUploaded(object sender, EventArgs e) { nbFileTypeWarning.Visible = false; var mergeTemplateEntityType = EntityTypeCache.Get(ddlMergeTemplateType.SelectedValue.AsInteger()); var binaryFile = new BinaryFileService(new RockContext()).Get(fuTemplateBinaryFile.BinaryFileId ?? 0); if (binaryFile != null) { string fileExtension = Path.GetExtension(binaryFile.FileName); fileExtension = fileExtension.TrimStart('.'); if (string.IsNullOrWhiteSpace(fileExtension)) { // nothing more to do return; } MergeTemplateType mergeTemplateType = null; if (mergeTemplateEntityType != null) { mergeTemplateType = MergeTemplateTypeContainer.GetComponent(mergeTemplateEntityType.Name); } else { // if a merge template type isn't selected, automatically pick the first matching one foreach (var item in MergeTemplateTypeContainer.Instance.Components.Values) { if (item.Value.IsActive) { var testMergeTemplateType = item.Value; if (testMergeTemplateType.SupportedFileExtensions != null && testMergeTemplateType.SupportedFileExtensions.Any()) { if (testMergeTemplateType.SupportedFileExtensions.Contains(fileExtension)) { mergeTemplateType = testMergeTemplateType; var entityType = EntityTypeCache.Get(mergeTemplateType.EntityType.Id); if (entityType != null) { ddlMergeTemplateType.SetValue(entityType.Id); } break; } } } } } if (mergeTemplateType == null) { // couldn't automatically pick one, so warn that they need to pick it nbFileTypeWarning.Text = "Warning: Please select a template type."; nbFileTypeWarning.Visible = true; nbFileTypeWarning.Dismissable = true; return; } if (mergeTemplateType.SupportedFileExtensions != null && mergeTemplateType.SupportedFileExtensions.Any()) { if (!mergeTemplateType.SupportedFileExtensions.Contains(fileExtension)) { nbFileTypeWarning.Text = string.Format( "Warning: The selected template type doesn't support '{0}' files. Please use a {1} file for this template type.", fileExtension, mergeTemplateType.SupportedFileExtensions.Select(a => a.Quoted()).ToList().AsDelimited(", ", " or ")); nbFileTypeWarning.Visible = true; nbFileTypeWarning.Dismissable = true; return; } } } if (binaryFile != null && string.IsNullOrWhiteSpace(tbName.Text)) { tbName.Text = Path.GetFileNameWithoutExtension(binaryFile.FileName).SplitCase().ReplaceWhileExists(" ", " "); } }