/// <summary>
        /// Install the "TriTech Default" Templates into the Agency
        /// </summary>
        private static void UpdateTriTechDefaultTemplatesInAgency(Domain.Administration.Aggregates.Agency.Agency agency,
                                                                  IAdministrationUnitOfWork admin, IMetadataUnitOfWork meta)
        {
            Log.Info("Processing TriTech Default Templates for {0}", agency.Jurisdiction.Ori);

            // Create a Template Manager Service Instance
            var templateManager = new TemplateManagementService(admin, meta);

            // Create or Update the TriTech Default Template for all Modules.
            foreach (var dataEntryContract in meta.GetAllDataEntryContracts())
            {
                // Get the "TriTech Default" Template Name
                var defaultTemplateName = DataEntryContractInspector.GetContractNameForModule(dataEntryContract.ModuleType);

                // Find or Create the Default Template
                var triTechDefaultTemplate = agency.GetTemplate(dataEntryContract.ModuleType, defaultTemplateName);
                if (triTechDefaultTemplate == null)
                {
                    Log.Info("Installing {0}", defaultTemplateName);

                    // Create the TriTech Default Template.
                    triTechDefaultTemplate = agency.CreateTemplate(dataEntryContract.Id, dataEntryContract.ModuleType, defaultTemplateName);

                    // Set the Template Workflow [Until the Concept of a "Default" workflow is defined this is the best we can do.]
                    triTechDefaultTemplate.SetWorkflow(agency.Workflows.First());

                    // Assign all roles to the Template
                    agency.Roles.ForEach(x => triTechDefaultTemplate.AssignRole(x));
                }
                else
                {
                    Log.Info("Updating {0} ", defaultTemplateName);
                }

                // Reset the Template Layout
                templateManager.ResetTemplateLayout(triTechDefaultTemplate);

                // Load the Template Layout from the Metadata
                templateManager.LoadFromMeta(triTechDefaultTemplate, dataEntryContract);
            }
        }
        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);
                }
            }
        }