Ejemplo n.º 1
0
        public string GetEditorTemplateHtml(BlogEditingTemplateType templateType, bool forceRTL)
        {
            SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY);
            string templateHtmlFile           = templates.GetString(templateType.ToString(), null);

            // Sometimes templateHtmlFile is relative, sometimes it is already absolute (from older builds).
            templateHtmlFile = MakeAbsolute(templateHtmlFile);

            if (templateHtmlFile != null && File.Exists(templateHtmlFile))
            {
                string templateHtml;
                using (StreamReader reader = new StreamReader(templateHtmlFile, Encoding.UTF8))
                    templateHtml = reader.ReadToEnd();

                if (File.Exists(templateHtmlFile + ".path"))
                {
                    string origPath = File.ReadAllText(templateHtmlFile + ".path");
                    string newPath  = Path.Combine(Path.GetDirectoryName(templateHtmlFile), Path.GetFileName(origPath));
                    string newUri   = UrlHelper.SafeToAbsoluteUri(new Uri(newPath));
                    templateHtml = templateHtml.Replace(origPath, newUri);
                }

                return(templateHtml);
            }
            else
            {
                return(BlogEditingTemplate.GetDefaultTemplateHtml(forceRTL, templateType != BlogEditingTemplateType.Normal));
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Load the default image decorators for the current image context.
 /// </summary>
 /// <returns></returns>
 public ImageDecoratorsList LoadDefaultImageDecoratorsList()
 {
     using (SettingsPersisterHelper contextImageSettings = GetImageSettingsPersister(_contextId, false))
     {
         ImageDecoratorsList decoratorsList;
         if (contextImageSettings == null)
         {
             decoratorsList = GetInitialLocalImageDecoratorsList();
         }
         else
         {
             decoratorsList = new ImageDecoratorsList(_decoratorsManager, new BlogPostSettingsBag(), false);
             string[] decoratorIds = contextImageSettings.GetString(ImageDecoratorsListKey, "").Split(',');
             foreach (string decoratorId in decoratorIds)
             {
                 ImageDecorator imageDecorator = _decoratorsManager.GetImageDecorator(decoratorId);
                 if (imageDecorator != null) //can be null if the decorator is no longer valid
                 {
                     decoratorsList.AddDecorator(imageDecorator);
                     using (SettingsPersisterHelper decoratorDefaultSettings = contextImageSettings.GetSubSettings(decoratorId))
                     {
                         PluginSettingsAdaptor settings = new PluginSettingsAdaptor(decoratorDefaultSettings);
                         CopySettings(settings, decoratorsList.GetImageDecoratorSettings(decoratorId));
                     }
                 }
             }
         }
         //now add the implicit decorators IFF they aren't already in the list
         decoratorsList.MergeDecorators(GetImplicitLocalImageDecorators());
         return(decoratorsList);
     }
 }
 private void AddPluginsFromKey(ArrayList pluginPaths, SettingsPersisterHelper settingsKey)
 {
     foreach (string name in settingsKey.GetNames())
     {
         string assemblyPath = settingsKey.GetString(name, String.Empty);
         if (!pluginPaths.Contains(assemblyPath))
         {
             pluginPaths.Add(assemblyPath);
         }
     }
 }
        /// <summary>
        /// Returns the profile associated with the key, or null if no such profile exists.
        /// </summary>
        /// <param name="key">The name of the registry key to define the profile under.</param>
        /// <returns></returns>
        public DestinationProfile loadProfile(String key)
        {
            SettingsPersisterHelper settings = getProfileSettings(key);

            if (settings.GetNames().Length == 0)
            {
                return(null);
            }
            DestinationProfile profile = new DestinationProfile();

            profile.Id               = key;
            profile.Name             = settings.GetString(PROFILE_NAME_KEY, "");
            profile.WebsiteURL       = settings.GetString(PROFILE_WEBSITE_URL_KEY, "");
            profile.FtpServer        = settings.GetString(PROFILE_FTP_SERVER_KEY, "");
            profile.UserName         = settings.GetString(PROFILE_FTP_USER_KEY, "");
            profile.FtpPublishPath   = settings.GetString(PROFILE_FTP_PUBLISH_DIR_KEY, "");
            profile.LocalPublishPath = settings.GetString(PROFILE_PUBLISH_DIR_KEY, "");
            profile.Type             = (DestinationProfile.DestType)settings.GetInt32(PROFILE_DESTINATION_TYPE_KEY, 0);

            //load the decrypted password
            try
            {
                profile.Password = settings.GetEncryptedString(PROFILE_FTP_PASSWORD_KEY);
            }
            catch (Exception e)
            {
                Trace.Fail("Failed to decrypt password: " + e);
            }

            return(profile);
        }
        private string GetStringValue(string pluginId, int index)
        {
            string strVal = _settings.GetString(pluginId, null);

            if (strVal == null)
            {
                return(null);
            }
            string[] chunks = strVal.Split(',');
            if (chunks.Length < index + 1)
            {
                return(null);
            }
            return(chunks[index]);
        }
        /// <summary>
        /// Loads preferences.
        /// </summary>
        protected override void LoadPreferences()
        {
            //	Obtain the type name of the application style.  If it's null, use SkyBlue.
            string name = SettingsPersisterHelper.GetString(APPLICATION_STYLE_TYPE_NAME, "ApplicationStyleSkyBlue");

            // strip "AplicationStyle" preface (for legacy settings format support)
            const string APPLICATION_STYLE = "ApplicationStyle";

            if (name.StartsWith(APPLICATION_STYLE))
            {
                name = name.Substring(APPLICATION_STYLE.Length);
            }

            switch (name)
            {
            case "SkyBlue":
                applicationStyleType = typeof(ApplicationStyleSkyBlue);
                break;

            case "Lavender":
                applicationStyleType = typeof(ApplicationStyleLavender);
                break;

            case "Sienna":
                applicationStyleType = typeof(ApplicationStyleSienna);
                break;

            case "Sterling":
                applicationStyleType = typeof(ApplicationStyleSterling);
                break;

            case "Wintergreen":
                applicationStyleType = typeof(ApplicationStyleWintergreen);
                break;

            default:
                Trace.Fail("Unexpected application style type: " + name);
                applicationStyleType = typeof(ApplicationStyleSkyBlue);
                break;
            }

            //	Set the new application style.
            if (ApplicationManager.ApplicationStyle.GetType() != applicationStyleType)
            {
                ApplicationManager.ApplicationStyle = Activator.CreateInstance(applicationStyleType) as ApplicationStyle;
            }
        }
        public string GetEditorTemplateHtml(BlogEditingTemplateType templateType, bool forceRTL)
        {
            SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY);
            string templateHtmlFile           = templates.GetString(templateType.ToString(), null);

            // Sometimes templateHtmlFile is relative, sometimes it is already absolute (from older builds).
            templateHtmlFile = MakeAbsolute(templateHtmlFile);

            if (templateHtmlFile != null && File.Exists(templateHtmlFile))
            {
                string templateHtml;
                using (StreamReader reader = new StreamReader(templateHtmlFile, Encoding.UTF8))
                    templateHtml = reader.ReadToEnd();

                if (File.Exists(templateHtmlFile + ".path"))
                {
                    string origPath = File.ReadAllText(templateHtmlFile + ".path");
                    string newPath  = Path.Combine(Path.GetDirectoryName(templateHtmlFile), Path.GetFileName(origPath));
                    string newUri   = UrlHelper.SafeToAbsoluteUri(new Uri(newPath));
                    templateHtml = templateHtml.Replace(origPath, newUri);
                }

                /*Parse meta tags in order to set CSS3 compatibility*/
                Regex metatag = new Regex(@"<(?i:meta)(\s)+(?i:http-equiv)(\s)*=""(?:X-UA-Compatible)""(\s)+(?i:content)(\s)*=""(?i:IE=edge)""(\s)*/>");
                Match match   = metatag.Match(templateHtml);

                if (!match.Success)
                {
                    // prepend the metatag to make css3 compatible at least on edge (Windows 8+)
                    int i = templateHtml.IndexOf("<HEAD>", StringComparison.OrdinalIgnoreCase);
                    if (i > 0)
                    {
                        templateHtml = (templateHtml.Substring(0, i + 6)
                                        + "<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />"
                                        + templateHtml.Substring(i + 6));
                    }
                }


                return(templateHtml);
            }
            else
            {
                return(BlogEditingTemplate.GetDefaultTemplateHtml(forceRTL, templateType != BlogEditingTemplateType.Normal));
            }
        }
Ejemplo n.º 8
0
        internal void CleanupUnusedTemplates()
        {
            try
            {
                using (SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY))
                {
                    // get the list of templates which are legit
                    ArrayList templatesInUse = new ArrayList();
                    foreach (string key in templates.GetNames())
                    {
                        templatesInUse.Add(MakeAbsolute(templates.GetString(key, String.Empty)).Trim().ToLower(CultureInfo.CurrentCulture));
                    }

                    // delete each of the template files in the directory which
                    // are not contained in our list of valid templates
                    if (templatesInUse.Count > 0)
                    {
                        string templateDirectory = Path.GetDirectoryName((string)templatesInUse[0]);
                        if (Directory.Exists(templateDirectory))
                        {
                            string[] templateFiles = Directory.GetFiles(templateDirectory, "*.htm");
                            foreach (string templateFile in templateFiles)
                            {
                                string templateFileNormalized = templateFile.Trim().ToLower(CultureInfo.CurrentCulture);
                                if (!templatesInUse.Contains(templateFileNormalized))
                                {
                                    CleanupTemplateAndSupportingFiles(templateFile);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Error occurred cleaning up unused templates: " + ex.ToString());
            }
        }
        public BlogProviderButtonDescriptionFromSettings(SettingsPersisterHelper settingsKey)
        {
            // id
            string id = settingsKey.GetString(ID, String.Empty);

            // image (required)
            string imageUrl = settingsKey.GetString(IMAGE_URL, String.Empty);

            byte[] imageData = settingsKey.GetByteArray(IMAGE, null);
            Bitmap image     = null;

            if (imageData != null)
            {
                try
                {
                    image = new Bitmap(new MemoryStream(imageData));
                }
                catch (Exception e)
                {
                    Trace.WriteLine(e.ToString());
                }
            }

            // tool-tip text
            string description = settingsKey.GetString(DESCRIPTION, String.Empty);

            // click-url
            string clickUrl = settingsKey.GetString(CLICK_URL, String.Empty);

            // has content
            string contentUrl         = settingsKey.GetString(CONTENT_URL, String.Empty);
            Size   contentDisplaySize = settingsKey.GetSize(CONTENT_DISPLAY_SIZE, Size.Empty);

            // has notification image
            string notificationUrl = settingsKey.GetString(NOTIFICATION_URL, String.Empty);

            // initialize
            Init(id, imageUrl, image, description, clickUrl, contentUrl, contentDisplaySize, notificationUrl);
        }
        private static ArrayList LoadAccountWizardsFromXml()
        {
            ArrayList accountWizardsFromXml = new ArrayList();

            try
            {
                using (SettingsPersisterHelper settingsKey = ApplicationEnvironment.UserSettingsRoot.GetSubSettings("AccountWizard\\Custom"))
                {
                    foreach (string customizationName in settingsKey.GetNames())
                    {
                        IBlogProviderAccountWizardDescription wizardDescription = LoadAccountWizardFromXml(settingsKey.GetString(customizationName, String.Empty));
                        if (wizardDescription != null)
                        {
                            accountWizardsFromXml.Add(wizardDescription);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Trace.Fail("Unexpected exception in LoadAccountWizardsFromXml: " + ex.ToString());
            }

            return(accountWizardsFromXml);
        }
 private static string GetContentSourceIdForFormat(LiveClipboardFormat format)
 {
     using (SettingsPersisterHelper formatSettings = _formatHandlerSettings.GetSubSettings(format.Id))
         return(formatSettings.GetString(CONTENT_SOURCE_ID, null));
 }
        public string GetEditorTemplateHtml(BlogEditingTemplateType templateType, bool forceRTL)
        {
            SettingsPersisterHelper templates = _editorTemplateSettings.GetSubSettings(EDITOR_TEMPLATES_KEY);
            string templateHtmlFile           = templates.GetString(templateType.ToString(), null);

            // Sometimes templateHtmlFile is relative, sometimes it is already absolute (from older builds).
            templateHtmlFile = MakeAbsolute(templateHtmlFile);

            if (templateHtmlFile != null && File.Exists(templateHtmlFile))
            {
                string templateHtml;
                using (StreamReader reader = new StreamReader(templateHtmlFile, Encoding.UTF8))
                    templateHtml = reader.ReadToEnd();

                if (File.Exists(templateHtmlFile + ".path"))
                {
                    string origPath = File.ReadAllText(templateHtmlFile + ".path");
                    string newPath  = Path.Combine(Path.GetDirectoryName(templateHtmlFile), Path.GetFileName(origPath));
                    string newUri   = UrlHelper.SafeToAbsoluteUri(new Uri(newPath));
                    templateHtml = templateHtml.Replace(origPath, newUri);
                }

                /* Parse meta tags in order to set MSHTML emulation for IE9
                 * As of Internet Explorer 10, support for element behaviors have been removed.
                 * Core OLW functionality, such as table management, currently rely on these mechanisms.
                 * An alternative to Element Behaviors must be found before we can push the IE version forward to allow for newer web standards. */

                // Search for an existing X-UA-Compatible tag in the template
                Regex metatag = new Regex(@"<(?i:meta)(?:\s)+(?i:http-equiv)(?:\s)*=""(?:X-UA-Compatible)""(?:\s)+(?i:content)(?:\s)*=""(\S*)""(?:\s)*/>");
                Match match   = metatag.Match(templateHtml);

                if (match.Success && match.Groups.Count > 1)
                {
                    // There already exists a 'X-UA-Compatible' meta tag in the template, modify it
                    // Grab info on the existing 'content' value
                    var contentVal = match.Groups[1];
                    // Remove the content value from the template
                    var templateContentRemoved = templateHtml.Remove(contentVal.Index, contentVal.Length);
                    // Add the IE9 emulation string into the HTML template
                    templateHtml = templateContentRemoved.Insert(contentVal.Index, UA_COMPATIBLE_STRING);
                }
                else
                {
                    // Prepend meta tag for IE9 emulation
                    int i = templateHtml.IndexOf("<HEAD>", StringComparison.OrdinalIgnoreCase);
                    if (i > 0)
                    {
                        templateHtml = (templateHtml.Substring(0, i + 6)
                                        + $"<meta http-equiv=\"X-UA-Compatible\" content=\"{UA_COMPATIBLE_STRING}\" />"
                                        + templateHtml.Substring(i + 6));
                    }
                }


                return(templateHtml);
            }
            else
            {
                return(BlogEditingTemplate.GetDefaultTemplateHtml(forceRTL, templateType != BlogEditingTemplateType.Normal));
            }
        }