public WeblogConfigurationWizardPanelSelectProvider()
        {
            // This call is required by the Windows.Forms Form Designer.
            InitializeComponent();

            this.labelHeader.Text = Res.Get(StringId.ConfigWizardSelectProvider);
            this.labelSelectProvider.Text = Res.Get(StringId.CWSelectProviderWeblogTypeLabel);
            this.labelServerAPIUrl.Text = Res.Get(StringId.CWSelectProviderApiUrlLabel);
            this.labelText.Text = Res.Get(StringId.CWSelectProviderText);

            if (BidiHelper.IsRightToLeft)
                textBoxServerApiUrl.TextAlign = HorizontalAlignment.Right;

            this.textBoxServerApiUrl.RightToLeft = RightToLeft.No;

            // Load up the combo and select the first item
            //adding marketization--only show providers for this market
            HashSet marketSupportedIds = new HashSet();
            marketSupportedIds.AddAll(
                StringHelper.Split(
                    MarketizationOptions.GetFeatureParameter(MarketizationOptions.Feature.BlogProviders, "supported"), ";"));
            foreach (IBlogProvider provider in BlogProviderManager.Providers)
                if (provider.Visible && marketSupportedIds.Contains(provider.Id))
                    comboBoxSelectProvider.Items.Add(new BlogProviderDescriptionProxy(provider));

            comboBoxSelectProvider.SelectedIndex = 0;

            labelText.Text = string.Format(CultureInfo.CurrentCulture, labelText.Text, ApplicationEnvironment.ProductNameQualified);
        }
        private static object ReadXmlVideoProviders(XmlDocument providersDocument)
        {
            XmlNode providersNode = providersDocument.SelectSingleNode("//videoProviders");
            if (providersNode == null)
                throw new Exception("Invalid videoProviders.xml file detected");

            // get the list of providers from the xml
            ArrayList providers = new ArrayList();
            HashSet marketSupportedIds = new HashSet();
            marketSupportedIds.AddAll(
                StringHelper.Split(
                MarketizationOptions.GetFeatureParameter(MarketizationOptions.Feature.VideoProviders, "supported"), ";"));
            XmlNodeList providerNodes = providersDocument.SelectNodes("//videoProviders/provider");
            foreach (XmlNode providerNode in providerNodes)
            {
                VideoProvider provider = VideoProviderFromXml(providerNode);
                if (marketSupportedIds.Contains(provider.ServiceId))
                    providers.Add(provider);
            }

            // return list of providers
            return providers.ToArray(typeof(VideoProvider));
        }
 /// <summary>
 /// Instructs the command manager to respond to the shortcut again.
 /// </summary>
 public void UnignoreShortcut(Shortcut shortcut)
 {
     Trace.Assert(maskedShortcuts != null, "UnignoreShortcut called before IgnoreShortcut");
     if (maskedShortcuts != null)
     {
         bool wasPresent = maskedShortcuts.Remove(shortcut);
         Trace.Assert(wasPresent, "Shortcut " + shortcut + " was not masked");
         if (maskedShortcuts.Count == 0)
             maskedShortcuts = null;
     }
 }
 /// <summary>
 /// Instructs the command manager to ignore the shortcut until
 /// UnignoreShortcut is called.
 ///
 /// LIMITATION: You cannot currently ignore an AdvancedShortcut
 /// (i.e. one based on Keys instead of Shortcut).
 /// </summary>
 public void IgnoreShortcut(Shortcut shortcut)
 {
     if (maskedShortcuts == null)
         maskedShortcuts = new HashSet();
     bool isNewElement = maskedShortcuts.Add(shortcut);
     Debug.Assert(isNewElement, "Shortcut " + shortcut + " was already masked");
 }
 public void LoadCategories()
 {
     initMode = true;
     try
     {
         nodes = CategoriesToNodes(ctx.Categories);
         treeView.Nodes.Clear();
         treeView.Nodes.AddRange(FilteredNodes(RealNodes, delegate { return true; }));
         HashSet selectedCategories = new HashSet();
         selectedCategories.AddAll(ctx.SelectedCategories);
         if (selectedCategories.Count > 0)
             WalkNodes(treeView.Nodes, delegate (TreeNode n)
                     {
                         n.Checked = selectedCategories.Contains(((TreeNode)n.Tag).Tag as BlogPostCategory);
                     });
         treeView.ExpandAll();
     }
     finally
     {
         initMode = false;
     }
 }
        private static void BuildMenuString(StringBuilder structure, XmlElement el, HashSet commandIds, Hashtable pairs)
        {
            int startLen = structure.Length;
            int pos = 0;
            bool lastWasSeparator = false;
            foreach (XmlNode childNode in el.ChildNodes)
            {
                XmlElement childEl = childNode as XmlElement;
                if (childEl == null)
                    continue;

                if (childEl.HasAttribute("Position"))
                    pos = int.Parse(childEl.GetAttribute("Position"), CultureInfo.InvariantCulture);

                string separator = "";
                if (childEl.Name == "Separator")
                {
                    lastWasSeparator = true;
                    continue;
                }
                else if (lastWasSeparator)
                {
                    separator = "-";
                    lastWasSeparator = false;
                }

                if (childEl.Name == "Menu" || childEl.Name == "Command")
                {
                    if (!childEl.HasAttribute("Identifier"))
                        throw new ConfigurationErrorsException(childEl.Name + " element was missing required attribute 'Identifier'");
                    string id = childEl.GetAttribute("Identifier");

                    if (childEl.Name == "Command")
                    {
                        if (!commandIds.Contains(id))
                            throw new ConfigurationErrorsException("Main menu definition uses unknown command id: " + id);
                    }

                    string idWithOrder = string.Format(CultureInfo.InvariantCulture, "{0}{1}@{2}", separator, id, (pos++ * 10));

                    if (structure.Length != 0)
                        structure.Append(" ");

                    switch (childEl.Name)
                    {
                        case "Menu":
                            if (!childEl.HasAttribute("Text"))
                                throw new ConfigurationErrorsException("Menu with id '" + id + "' was missing the required Text attribute");
                            string menuText = childEl.GetAttribute("Text");
                            pairs.Add("MainMenu." + id, new Values(menuText, ""));

                            structure.Append("(" + idWithOrder);
                            BuildMenuString(structure, childEl, commandIds, pairs);
                            structure.Append(")");
                            break;
                        case "Command":
                            structure.Append(idWithOrder);
                            break;
                    }
                }
                else
                    throw new ConfigurationErrorsException("Unexpected element " + childEl.Name);
            }
        }
        private static bool ParseCommandXml(string[] inputFiles, Hashtable pairs, Hashtable pairsNonLoc, Type t, string xpath, string KEY_FORMAT, out HashSet ids)
        {
            bool seenMenu = false;

            Hashtable propTable = new Hashtable();
            foreach (PropertyInfo prop in t.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                propTable.Add(prop.Name, prop);
            }

            ids = new HashSet();

            foreach (string relativeInputFile in inputFiles)
            {
                string inputFile = Path.GetFullPath(relativeInputFile);
                try
                {
                    if (!File.Exists(inputFile))
                        throw new ConfigurationErrorsException("File not found");

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(inputFile);
                    foreach (XmlElement el in xmlDoc.SelectNodes(xpath))
                    {
                        string id = el.GetAttribute("Identifier");
                        if (id == "")
                            throw new ConfigurationErrorsException(
                                String.Format(CultureInfo.CurrentCulture, "The following command is missing an identifier:\r\n{0}", el.OuterXml));

                        if (!ids.Add(id))
                            throw new ConfigurationErrorsException("Duplicate command identifier: " + id);

                        foreach (XmlAttribute attr in el.Attributes)
                        {
                            if (attr.NamespaceURI.Length != 0)
                                continue;

                            string name = attr.Name;

                            if (name == "DebugOnly" || name == "Identifier")
                                continue;

                            object val;
                            PropertyInfo thisProp = propTable[name] as PropertyInfo;
                            if (thisProp == null)
                                throw new ConfigurationErrorsException(string.Format(CultureInfo.CurrentCulture, "Attribute {0} does not have a corresponding property", name));

                            if (thisProp.PropertyType.IsEnum)
                            {
                                try
                                {
                                    val = Enum.Parse(thisProp.PropertyType, attr.Value, false).ToString();
                                }
                                catch (ArgumentException)
                                {
                                    throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, "Invalid attribute value: {0}=\"{1}\"", attr.Name, attr.Value));
                                }
                            }
                            else if (thisProp.PropertyType.IsPrimitive)
                            {
                                try
                                {
                                    val = Convert.ChangeType(attr.Value, thisProp.PropertyType).ToString();
                                }
                                catch (ArgumentException)
                                {
                                    throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, "Invalid attribute value: {0}=\"{1}\"", attr.Name, attr.Value));
                                }
                            }
                            else if (thisProp.PropertyType == typeof(string))
                            {
                                val = attr.Value;
                            }
                            else
                            {
                                throw new ConfigurationErrorsException("Unexpected attribute: " + attr.Name);
                            }

                            string comment = GetComment(el, name);

                            object[] locAttr = thisProp.GetCustomAttributes(typeof(LocalizableAttribute), true);
                            bool isNonLoc = locAttr.Length == 0 || !((LocalizableAttribute)locAttr[0]).IsLocalizable;
                            if (isNonLoc)
                                pairsNonLoc.Add(string.Format(CultureInfo.InvariantCulture, KEY_FORMAT, id, name), new Values(val, comment));
                            else
                                pairs.Add(string.Format(CultureInfo.InvariantCulture, KEY_FORMAT, id, name), new Values(val, comment));
                        }
                    }

                    foreach (XmlElement mainMenuEl in xmlDoc.SelectNodes("/Commands/MainMenu"))
                    {
                        if (seenMenu)
                            throw new ConfigurationErrorsException("Duplicate main menu definition detected");
                        seenMenu = true;

                        Console.WriteLine("Parsing main menu definition");
                        StringBuilder menuStructure = new StringBuilder();
                        BuildMenuString(menuStructure, mainMenuEl, ids, pairs);
                        pairsNonLoc.Add("MainMenuStructure", new Values(menuStructure.ToString(), ""));
                    }
                }
                catch (ConfigurationErrorsException ce)
                {
                    Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "Error in file {0}: {1}", inputFile, ce.Message));
                    return false;
                }
            }

            return true;
        }
        private static bool ParseRibbonXml(string[] inputFiles, Hashtable pairs, Hashtable pairsNonLoc, Type t, string xpath, string KEY_FORMAT, out HashSet ids, out Hashtable values)
        {
            // Add to the proptable
            Hashtable propTable = new Hashtable();
            foreach (PropertyInfo prop in t.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                propTable.Add(prop.Name, prop);
            }

            ids = new HashSet();
            values = new Hashtable();

            foreach (string relativeInputFile in inputFiles)
            {
                string inputFile = Path.GetFullPath(relativeInputFile);
                try
                {
                    if (!File.Exists(inputFile))
                        throw new ConfigurationErrorsException("File not found");

                    XmlNamespaceManager nsm = new XmlNamespaceManager(new NameTable());
                    nsm.AddNamespace(RibbonMarkup.XPathPrefix, RibbonMarkup.NamespaceUri);

                    XmlDocument xmlDoc = new XmlDocument();
                    xmlDoc.Load(inputFile);

                    foreach (XmlElement el in xmlDoc.SelectNodes(xpath, nsm))
                    {

                        string id = el.GetAttribute("Id");
                        string symbol = el.GetAttribute("Symbol");
                        if (id == "")
                            throw new ConfigurationErrorsException(
                                string.Format(CultureInfo.CurrentCulture, "The following command is missing an identifier:\r\n{0}", el.OuterXml));

                        // RibbonDUI.js requires that command names begin with the prefix "cmd".
                        // We will strip that prefix when generating the CommandId enum.
                        int cmdIndex = symbol.IndexOf("cmd");
                        if (cmdIndex >= 0)
                        {
                            symbol = symbol.Substring(cmdIndex + 3);
                        }

                        if (!ids.Add(symbol))
                            throw new ConfigurationErrorsException("Duplicate command: " + symbol + " with id " + id);
                        values.Add(symbol, id);

                        foreach (XmlAttribute attr in el.Attributes)
                        {
                            if (attr.NamespaceURI.Length != 0)
                                continue;

                            string name = attr.Name;

                            object val;
                            PropertyInfo thisProp = propTable[name] as PropertyInfo;
                            if (thisProp == null)
                                continue; // This attribute does not have a corresponding property in the type.

                            if (thisProp.PropertyType.IsPrimitive)
                            {
                                try
                                {
                                    val = Convert.ChangeType(attr.Value, thisProp.PropertyType).ToString();
                                }
                                catch (ArgumentException)
                                {
                                    throw new ConfigurationErrorsException(string.Format(CultureInfo.InvariantCulture, "Invalid attribute value: {0}=\"{1}\"", attr.Name, attr.Value));
                                }
                            }
                            else if (thisProp.PropertyType == typeof(string))
                            {
                                val = attr.Value;
                            }
                            else
                            {
                                throw new ConfigurationErrorsException("Unexpected attribute: " + attr.Name);
                            }

                            string comment = GetComment(el, name);

                            object[] locAttr = thisProp.GetCustomAttributes(typeof(LocalizableAttribute), true);
                            bool isNonLoc = locAttr.Length == 0 || !((LocalizableAttribute)locAttr[0]).IsLocalizable;
                            if (isNonLoc)
                                pairsNonLoc.Add(string.Format(CultureInfo.InvariantCulture, KEY_FORMAT, symbol, name), new Values(val, comment));
                            else
                                pairs.Add(string.Format(CultureInfo.InvariantCulture, KEY_FORMAT, symbol, name), new Values(val, comment));
                        }
                    }
                }
                catch (ConfigurationErrorsException ce)
                {
                    Console.Error.WriteLine(string.Format(CultureInfo.InvariantCulture, "Error in file {0}: {1}", inputFile, ce.Message));
                    return false;
                }
            }

            return true;
        }
        // @RIBBON TODO: For now the union of the command in Commands.xml and Ribbon.xml will go into the CommandId enum.
        private static bool GenerateEnum(HashSet commandIds, string enumName, string enumPath, Hashtable descriptions, Hashtable values)
        {
            const string TEMPLATE = @"namespace OpenLiveWriter.Localization
                            {{
                                public enum {0}
                                {{
                                    None,
                                    {1}
                                }}
                            }}
                            ";

            ArrayList commandList = commandIds.ToArrayList();
            commandList.Sort(new CaseInsensitiveComparer(CultureInfo.InvariantCulture));
            using (StreamWriter sw = new StreamWriter(Path.GetFullPath(enumPath)))
            {
                if (descriptions == null && values == null)
                {
                    sw.Write(string.Format(CultureInfo.InvariantCulture, TEMPLATE, enumName, StringHelper.Join(commandList.ToArray(), ",\r\n\t\t")));
                }
                else if (descriptions == null)
                {
                    // insert values
                    const string VALUE_TEMPLATE = "{0} = {1}";
                    const string VALUELESS_TEMPLATE = "{0}";
                    ArrayList pairs = new ArrayList();
                    ArrayList unmappedCommands = new ArrayList();
                    foreach (string command in commandList.ToArray())
                    {
                        string value = values[command] as string;
                        if (value != null)
                        {
                            pairs.Add(string.Format(CultureInfo.InvariantCulture, VALUE_TEMPLATE, command, value));
                        }
                        else
                        {
                            ConsoleColor color = Console.ForegroundColor;
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Error.WriteLine("ERROR: Command " + command + " is missing an Id (required for instrumentation)");
                            Console.Beep();
                            Console.ForegroundColor = color;
                            Console.Error.Flush();

                            // This command is not mapped to a ribbon command
                            // We'll keep track of these and put them at the end
                            unmappedCommands.Add(command);
                        }
                    }

                    if (unmappedCommands.Count > 0)
                    {
                        return false;
                    }

                    // Now add the commands that were not mapped to a value
                    int index = 1;
                    foreach (string command in unmappedCommands.ToArray())
                    {
                        if (index == 1)
                            pairs.Add(string.Format(CultureInfo.InvariantCulture, VALUE_TEMPLATE, command, index));
                        else
                            pairs.Add(string.Format(CultureInfo.InvariantCulture, VALUELESS_TEMPLATE, command));
                        index++;
                    }

                    sw.Write(string.Format(CultureInfo.InvariantCulture, TEMPLATE, enumName, StringHelper.Join(pairs.ToArray(), ",\r\n\t\t")));
                }
                else if (values == null)
                {
                    const string DESC_TEMPLATE = @"/// <summary>
                                                    /// {0}
                                                    /// </summary>
                                                    {1}";
                    ArrayList descs = new ArrayList();
                    foreach (string command in commandList.ToArray())
                    {
                        string description = ((Values)descriptions[command]).Val as string;
                        description = description.Replace("\n", "\n\t\t/// ");
                        descs.Add(string.Format(CultureInfo.InvariantCulture, DESC_TEMPLATE, description, command));
                    }
                    sw.Write(string.Format(CultureInfo.InvariantCulture, TEMPLATE, enumName, StringHelper.Join(descs.ToArray(), ",\r\n\t\t")));
                }
                else
                {
                    // insert values and descriptions
                    throw new NotImplementedException("Inserting values and descriptions not supported presently");
                }
            }

            return true;
        }
        protected BlogPost[] GetRecentPostsInternal(string blogId, int maxPosts, bool includeCategories, DateTime? now)
        {
            Login();

            FixupBlogId(ref blogId);

            HashSet seenIds = new HashSet();

            ArrayList blogPosts = new ArrayList();
            try
            {
                while (true)
                {
                    XmlDocument doc;
                    Uri thisUri = new Uri(blogId);

                    // This while-loop nonsense is necessary because New Blogger has a bug
                    // where the official URL for getting recent posts doesn't work when
                    // the orderby=published flag is set, but there's an un-official URL
                    // that will work correctly. Therefore, subclasses need the ability
                    // to inspect exceptions that occur, along with the URI that was used
                    // to make the request, and determine whether an alternate URI should
                    // be used.
                    while (true)
                    {
                        try
                        {
                            doc = xmlRestRequestHelper.Get(ref thisUri, RequestFilter);
                            break;
                        }
                        catch (Exception e)
                        {
                            Trace.WriteLine(e.ToString());
                            if (AttemptAlternateGetRecentPostUrl(e, ref blogId))
                                continue;
                            else
                                throw;
                        }
                    }

                    XmlNodeList nodeList = doc.SelectNodes("/atom:feed/atom:entry", _nsMgr);
                    if (nodeList.Count == 0)
                        break;
                    foreach (XmlElement node in nodeList)
                    {
                        BlogPost blogPost = this.Parse(node, includeCategories, thisUri);
                        if (blogPost != null)
                        {
                            if (seenIds.Contains(blogPost.Id))
                                throw new DuplicateEntryIdException();
                            seenIds.Add(blogPost.Id);

                            if (!now.HasValue || blogPost.DatePublished.CompareTo(now.Value) < 0)
                                blogPosts.Add(blogPost);
                        }
                        if (blogPosts.Count >= maxPosts)
                            break;
                    }
                    if (blogPosts.Count >= maxPosts)
                        break;

                    XmlElement nextNode = doc.SelectSingleNode("/atom:feed/atom:link[@rel='next']", _nsMgr) as XmlElement;
                    if (nextNode == null)
                        break;
                    blogId = XmlHelper.GetUrl(nextNode, "@href", thisUri);
                    if (blogId.Length == 0)
                        break;
                }
            }
            catch (DuplicateEntryIdException)
            {

                if (ApplicationDiagnostics.AutomationMode)
                    Trace.WriteLine("Duplicate IDs detected in feed");
                else
                    Trace.Fail("Duplicate IDs detected in feed");
            }
            return (BlogPost[])blogPosts.ToArray(typeof(BlogPost));
        }