Exemple #1
0
        private void _btnInstall_Click(object sender, System.EventArgs e)
        {
            if (_dlgBrowseForExtension.ShowDialog() == DialogResult.OK)
            {
                foreach (BlogExtensionData data in RSSPlugin.ExtensionManager.BlogExtensions)
                {
                    if (String.Compare(data.FileName, _dlgBrowseForExtension.FileName, true) == 0)
                    {
                        MessageBox.Show(this,
                                        "The extension '" + _dlgBrowseForExtension.FileName + "' is already installed",
                                        "Install Extension");
                        return;
                    }
                }

                BlogExtensionData extData = RSSPlugin.ExtensionManager.InstallExtension(_dlgBrowseForExtension.FileName);
                if (extData == null)
                {
                    MessageBox.Show(this, "The file you selected is not a weblog client extension", "Install Extension");
                }
                else
                {
                    AddExtensionDataToList(extData);
                }
            }
        }
Exemple #2
0
        private void AddExtensionDataToList(BlogExtensionData extData)
        {
            ListViewItem lvItem = _lvExtensions.Items.Add(extData.BlogExtension.DisplayName);

            lvItem.SubItems.Add(Path.GetFileName(extData.FileName));
            lvItem.Tag = extData;
            if (_lvExtensions.Items.Count == 1)
            {
                lvItem.Selected = true;
            }
        }
Exemple #3
0
        private void _btnUninstall_Click(object sender, System.EventArgs e)
        {
            BlogExtensionData extData = (BlogExtensionData)_lvExtensions.SelectedItems [0].Tag;

            if (MessageBox.Show(this, "Do you really want to uninstall the extension '" +
                                extData.BlogExtension.DisplayName + "'?",
                                "Uninstall Extension", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                RSSPlugin.ExtensionManager.UninstallExtension(extData);
                _lvExtensions.Items.RemoveAt(_lvExtensions.SelectedIndices [0]);
            }
        }
Exemple #4
0
        internal BlogExtensionData InstallExtension(string fileName)
        {
            BlogExtensionData extData = LoadExtension(fileName);

            if (extData == null)
            {
                return(null);
            }

            RegUtil.CreateSubKey(Registry.CurrentUser, _extensionKey);
            RegUtil.SetValue(Registry.CurrentUser, _extensionKey, Path.GetFileNameWithoutExtension(fileName), fileName);
            return(extData);
        }
Exemple #5
0
        private BlogExtensionData LoadExtension(string fileName)
        {
            Type[] pluginTypes;
            try
            {
                Assembly pluginAssembly = Assembly.LoadFrom(fileName);
                pluginTypes = pluginAssembly.GetExportedTypes();
            }
            catch (Exception e)
            {
                Trace.WriteLine(e.ToString());
                return(null);
            }

            // search for IPlugin instances
            foreach (Type aType in pluginTypes)
            {
                foreach (Type intfType in aType.GetInterfaces())
                {
                    if (intfType == typeof(IBlogExtension))
                    {
                        IBlogExtension extension;
                        try
                        {
                            extension = (IBlogExtension)Activator.CreateInstance(aType);
                        }
                        catch (Exception ex)
                        {
                            if (ex is TargetInvocationException)
                            {
                                ex = (ex as TargetInvocationException).InnerException;
                            }
                            DialogResult dr = MessageBox.Show(Core.MainWindow,
                                                              "Exception when initializing weblog posting extension " + fileName +
                                                              ":\r\n" + ex.Message + "\r\nWould you like to uninstall the extension?",
                                                              Core.ProductFullName, MessageBoxButtons.YesNo);
                            if (dr == DialogResult.Yes)
                            {
                                UninstallExtensionFile(fileName);
                            }
                            return(null);
                        }
                        IAction           extAction = RegisterBlogExtensionAction(extension);
                        BlogExtensionData extData   = new BlogExtensionData(fileName, extension, extAction);
                        _blogExtensions.Add(extData);
                        return(extData);
                    }
                }
            }
            return(null);
        }
Exemple #6
0
 private void _lvExtensions_SelectedIndexChanged(object sender, System.EventArgs e)
 {
     if (_lvExtensions.SelectedItems.Count > 0)
     {
         BlogExtensionData extData = (BlogExtensionData)_lvExtensions.SelectedItems [0].Tag;
         _btnConfigure.Enabled = extData.BlogExtension.HasConfiguration;
         _btnUninstall.Enabled = true;
     }
     else
     {
         _btnConfigure.Enabled = false;
         _btnUninstall.Enabled = false;
     }
 }
Exemple #7
0
 private void _btnConfigure_Click(object sender, System.EventArgs e)
 {
     if (_lvExtensions.SelectedItems.Count > 0)
     {
         BlogExtensionData extData = (BlogExtensionData)_lvExtensions.SelectedItems [0].Tag;
         try
         {
             extData.BlogExtension.Configure(this);
         }
         catch (Exception ex)
         {
             MessageBox.Show(this, "Error configuring extension: " + ex.Message,
                             "Configure Extension", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
Exemple #8
0
 internal void UninstallExtension(BlogExtensionData extData)
 {
     UninstallExtensionFile(extData.FileName);
     Core.ActionManager.UnregisterContextMenuAction(extData.Action);
     _blogExtensions.Remove(extData);
 }