private void ExportTemplatesButton_Click(object sender, RoutedEventArgs e) { if (_browserDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK) { return; } foreach (TemplateDescription templateDescription in TemplatesListBox.SelectedItems) { try { using (var admin = new AdministrationDbContext()) using (var meta = new MetadataDbContext()) { // Create a Template Layout Service var templateLayoutService = new TemplateLayoutService(admin, meta); // Get the Layout Information for the Template var templateLayout = templateLayoutService.GetTemplateLayout(templateDescription.Template.Id, State); // Serialize the Layout Information to an XML File. using (var s = new StreamWriter(Path.Combine(_browserDialog.SelectedPath, templateDescription.Template.Name + " Template.xml"))) { s.Write(Serializer <TemplateLayout> .Serialize(templateLayout)); } } } catch (Exception ex) { System.Windows.MessageBox.Show(ex.Message); } } }
private static void InstallOrUpdateTemplatesInAgency(Domain.Administration.Aggregates.Agency.Agency agency, string implementation, IAdministrationUnitOfWork admin, IMetadataUnitOfWork meta) { Log.Info("Processing {0} templates for {1}", implementation, agency.Jurisdiction.Ori); // Template Manager Service Instance var templateManager = new TemplateManagementService(admin, meta); var templateLayoutService = new TemplateLayoutService(admin, meta); // Load All the Metadata var dataEntryContracts = meta.GetAllDataEntryContracts(); // Load All the Template Layouts var templateLayouts = LoadTemplateLayoutsFromFolder(TemplateFolder); // Setup the Default Templates for Each DataEntryContract defined in the Metadata foreach (var contract in dataEntryContracts) { // Find any layouts defined for the Implementation var impTemplateLayouts = templateLayouts.Where(t => t.ModuleType == contract.ModuleType && t.Implementation == implementation).ToList(); // If none are defined use the "Generic" templates if (impTemplateLayouts.Count == 0) { impTemplateLayouts = templateLayouts.Where(t => t.ModuleType == contract.ModuleType && t.Implementation == StateImplementations.Generic).ToList(); } // Setup the Templates in the Agency foreach (var templateLayout in impTemplateLayouts) { // Find or Create the Template var agencyTemplate = agency.GetTemplate(templateLayout.ModuleType, templateLayout.Name); if (agencyTemplate == null) { Log.Info("Installing {0}", templateLayout.Name); agencyTemplate = agency.CreateTemplate(contract.Id, contract.ModuleType, templateLayout.Name); // TODO: This assumes the First Workflow is the Correct Workflow agencyTemplate.SetWorkflow(agency.Workflows.First()); // Make the Template Active agencyTemplate.MakeActive(); // Assign all roles to the Template agency.Roles.ForEach(x => agencyTemplate.AssignRole(x)); // Determine if the template should be set as the Agency Default var templateIsDefault = templateLayout.IsDefault || // Template is Explicitly Marked as a Default. impTemplateLayouts.Count == 1; // There is only one template being installed for this contract. // Set the template as the Agency Default if (templateIsDefault) { agency.SetDefaultTemplate(agencyTemplate); } } else { Log.Info("Updating {0}", templateLayout.Name); // Reset the Template templateManager.ResetTemplateLayout(agencyTemplate); } // Load the Template Layout Information templateLayoutService.LoadLayout(templateLayout, agencyTemplate); } } }