Exemple #1
0
 private void OnAddLocalButtonClicked(object sender, EventArgs e)
 {
     AssemblySelectionDialog dialog = new AssemblySelectionDialog(base.ServiceProvider);
     if (dialog.ShowDialog() == DialogResult.OK)
     {
         IApplicationIdentity identity = base.ServiceProvider.GetService(typeof(IApplicationIdentity)) as IApplicationIdentity;
         bool flag = false;
         AssemblyName[] selectedAssemblies = dialog.SelectedAssemblies;
         try
         {
             for (int i = 0; i < selectedAssemblies.Length; i++)
             {
                 Assembly assembly = Assembly.Load(selectedAssemblies[i]);
                 if (!assembly.GlobalAssemblyCache)
                 {
                     Uri uri = new Uri(assembly.CodeBase);
                     string localPath = uri.LocalPath;
                     if (!Directory.Exists(identity.PluginsPath))
                     {
                         Directory.CreateDirectory(identity.PluginsPath);
                     }
                     string path = Path.Combine(identity.PluginsPath, Path.GetFileName(localPath));
                     if (localPath.ToLower() != path.ToLower())
                     {
                         if (File.Exists(path))
                         {
                             IMxUIService service = (IMxUIService) base.ServiceProvider.GetService(typeof(IMxUIService));
                             if ((service != null) && (service.ShowMessage("The assembly " + Path.GetFileName(path) + "' has previously been added. Do you wish to replace it?", "Add-in Organizer", MessageBoxIcon.Question, MessageBoxButtons.YesNo, MessageBoxDefaultButton.Button1) == DialogResult.No))
                             {
                                 continue;
                             }
                         }
                         File.Copy(localPath, path, true);
                     }
                 }
                 flag |= this.ProcessAssembly(assembly);
             }
         }
         catch (Exception exception)
         {
             this.ReportError("A problem was encountered.\n\nDetails:\n" + exception.Message, false);
         }
         if (flag)
         {
             this._addInList.SelectedIndex = this._addInList.Items.Count - 1;
         }
         else
         {
             this.ReportError("No new add-ins were found.", true);
         }
     }
 }
Exemple #2
0
 public override bool Customize(int command, IServiceProvider serviceProvider)
 {
     switch (command)
     {
         case 0:
         {
             IComponentGalleryService service = (IComponentGalleryService) serviceProvider.GetService(typeof(IComponentGalleryService));
             try
             {
                 Library library = service.BrowseGallery(this.ComponentType.FullName);
                 if (library != null)
                 {
                     this.AddComponents(library, serviceProvider);
                 }
             }
             catch (UnauthorizedAccessException exception)
             {
                 this.ShowMessage("Error", exception.Message + Environment.NewLine + "The assembly may be in use.  Please save your work, restart the application, and try again.", serviceProvider);
             }
             catch (Exception exception2)
             {
                 this.ShowMessage("Error", exception2.Message, serviceProvider);
             }
             return true;
         }
         case 1:
         {
             AssemblySelectionDialog dialog = new AssemblySelectionDialog(serviceProvider);
             if (dialog.ShowDialog() == DialogResult.OK)
             {
                 try
                 {
                     this.AddComponents(dialog.SelectedAssemblies, serviceProvider);
                     Library[] selectedLibraries = dialog.SelectedLibraries;
                     for (int i = 0; i < selectedLibraries.Length; i++)
                     {
                         this.AddComponents(selectedLibraries[i], serviceProvider);
                     }
                 }
                 catch (UnauthorizedAccessException exception3)
                 {
                     this.ShowMessage("Error", exception3.Message + Environment.NewLine + "The assembly may be in use. Please save your work, restart the application, and try again.", serviceProvider);
                 }
                 catch (Exception exception4)
                 {
                     this.ShowMessage("Error", exception4.Message, serviceProvider);
                 }
             }
             return true;
         }
         case 2:
         {
             ArrayList list = new ArrayList(base.ToolboxDataItems);
             this.ClearToolboxDataItems();
             Hashtable hashtable = new Hashtable(base.ToolboxDataItems.Count);
             foreach (ToolboxDataItem item in list)
             {
                 Type type = Type.GetType(item.ToolboxData, false, true);
                 if (type != null)
                 {
                     Assembly key = type.Assembly;
                     if (!hashtable.Contains(key))
                     {
                         foreach (Type type2 in key.GetTypes())
                         {
                             if (this.IsValidToolboxComponent(type2))
                             {
                                 ToolboxDataItem item2 = this.CreateToolboxDataItem(type2.AssemblyQualifiedName);
                                 base.AddToolboxDataItem(item2);
                             }
                         }
                         hashtable[key] = string.Empty;
                     }
                 }
             }
             return true;
         }
     }
     return false;
 }