public static void ApplyConfiguration()
        {
            // Apply database configuration
            ConfigurationSection sqlDbConfiguration = TridionConfig.ConfigurationManager.TryGetSection(DbConfiguration.SectionName);

            // Use reflection because SDL 2011 and SDL 2013 have different configuration structures
            Action <String, Object> setProperty = (Action <String, Object>)Delegate.CreateDelegate(typeof(Action <String, Object>),
                                                                                                   sqlDbConfiguration,
                                                                                                   typeof(ConfigurationElement).GetProperty("Item", BindingFlags.Instance | BindingFlags.NonPublic, null, typeof(Object), new Type[] { typeof(String) }, new ParameterModifier[] { })
                                                                                                   .GetSetMethod(true));

            if (sqlDbConfiguration != null)
            {
                setProperty("name", DebuggerConfig.Instance.Database.Name);
                setProperty("server", DebuggerConfig.Instance.Database.Server);
                setProperty("username", DebuggerConfig.Instance.Database.Username);
                setProperty("password", DebuggerConfig.Instance.Database.Password);
            }

            // Configure TRIDION_CM_HOME for the SchemaCache to find the required XSD files
            String rendererFolder = Path.GetFullPath(Path.Combine(ApplicationPath, DebuggerConfig.Instance.Templating.SchemaCache));

            Environment.SetEnvironmentVariable("TRIDION_CM_HOME", rendererFolder);

            // Enable impersonation for the current windows user?
            if (DebuggerConfig.Instance.Templating.EnableImpersonation)
            {
                ContentManagerSecurityConfiguration section = TridionConfig.ConfigurationManager.TryGetSection(ContentManagerSecurityConfiguration.SectionName) as ContentManagerSecurityConfiguration;

                if (section != null)
                {
                    section.ImpersonationUsers.Add(
                        new ImpersonationUserSettings()
                    {
                        Name = WindowsIdentity.GetCurrent().Name,
                        ImpersonationType = ImpersonationType.Windows
                    });
                }
            }

            // Enable templating settings and load the WrappedMediator
            TemplatingSettings templatingSettings = TemplateUtilities.GetTemplatingSettings();

            if (templatingSettings != null)
            {
                templatingSettings.DebuggingElement.PdbLocation = ApplicationPath;

                MediatorElement mediatorElement = templatingSettings.MediatorCollection
                                                  .Cast <MediatorElement>()
                                                  .FirstOrDefault(me => String.Equals(me.MatchMimeType, "text/x-tcm-csharpfragment"));

                if (mediatorElement != null)
                {
                    // Ensure the wrapped mediator is initialized (this loads the configured debug libraries)
                    WrappedCSharpMediator.Initialize();
                    mediatorElement.ClassName = typeof(WrappedCSharpMediator).AssemblyQualifiedName;
                }
            }
        }
Example #2
0
 /// <summary>
 /// Gets the Razor Mediator Configuration Section from the ContentManager.Settings.config configuration file.
 /// </summary>
 /// <returns></returns>
 public static RazorMediatorConfigurationSection GetConfiguration()
 {
     return((RazorMediatorConfigurationSection)TemplateUtilities.GetTemplatingSettings().CurrentConfiguration.GetSection("razor.mediator"));
 }