private void Initialize(ManagedAddIn addIn) { _markedAddIn = addIn; if (_markedAddIn != null) { _addIn = addIn.AddIn; } if (_addIn != null) { UpdateMembers(); } }
private AddIn GetInstalledOrMarkedAddInForNuGetPackage(IPackage package) { if (package == null) { throw new ArgumentNullException("package"); } ManagedAddIn foundAddIn = AddInsWithMarkedForInstallation.Where( a => ((a.AddIn.Manifest != null) && (a.AddIn.Manifest.PrimaryIdentity == package.Id)) || (a.AddIn.Properties.Contains(ManagedAddIn.NuGetPackageIDManifestAttribute) && (a.AddIn.Properties[ManagedAddIn.NuGetPackageIDManifestAttribute] == package.Id))) .FirstOrDefault(); return((foundAddIn != null) ? foundAddIn.AddIn : null); }
public OfflineAddInsViewModel(IAddInManagerServices services, ManagedAddIn addIn) : base(services) { Initialize(addIn); }
public OfflineAddInsViewModel(ManagedAddIn addIn) : base() { Initialize(addIn); }
public AddIn InstallAddIn(IPackage package, string packageDirectory) { // Lookup for .addin file in package output var addInManifestFile = Directory.EnumerateFiles(packageDirectory, "*.addin", SearchOption.TopDirectoryOnly).FirstOrDefault(); if (addInManifestFile != null) { SD.Log.DebugFormatted("[AddInManager2] Installing AddIn from package {0} {1}", package.Id, package.Version.ToString()); // Patch metadata of AddIn to have a permanent link to the NuGet package if (!PatchAddInManifest(addInManifestFile, package)) { _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); return null; } AddIn addIn = _sdAddInManagement.Load(addInManifestFile); if (addIn.Manifest.PrimaryIdentity == null) { _events.OnAddInOperationError( new AddInOperationErrorEventArgs( new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity")))); return null; } // Just for safety also patch the properties of AddIn object directly PatchAddInProperties(addIn, package); // Try to find this AddIn in current registry string identity = addIn.Manifest.PrimaryIdentity; AddIn foundAddIn = null; foreach (AddIn treeAddIn in _sdAddInManagement.AddIns) { if (treeAddIn.Manifest.Identities.ContainsKey(identity)) { foundAddIn = treeAddIn; break; } } // Prevent this AddIn from being uninstalled, if marked for deinstallation foreach (string installedIdentity in addIn.Manifest.Identities.Keys) { _sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity); } // Create target directory for AddIn in user profile & copy package contents there CopyAddInFromPackage(addIn, packageDirectory); // Install the AddIn using manifest if (foundAddIn != null) { addIn.Action = AddInAction.Update; SD.Log.DebugFormatted("[AddInManager2] Marked AddIn {0} for update.", addIn.Name); } else { addIn.Action = AddInAction.Install; _sdAddInManagement.AddToTree(addIn); } // Some debug output about AddIn's manifest if ((addIn.Manifest != null) && !String.IsNullOrEmpty(addIn.Manifest.PrimaryIdentity)) { SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states identity '{0}'", addIn.Manifest.PrimaryIdentity); } else { SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states no identity."); } if (addIn.Properties.Contains(ManagedAddIn.NuGetPackageIDManifestAttribute)) { SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states NuGet ID '{0}'", addIn.Properties[ManagedAddIn.NuGetPackageIDManifestAttribute]); } else { SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states no NuGet ID."); } // Mark this AddIn ManagedAddIn foundAddInManaged = new ManagedAddIn(foundAddIn); ManagedAddIn markedAddIn = new ManagedAddIn(addIn) { InstallationSource = AddInInstallationSource.NuGetRepository, IsTemporary = true, IsUpdate = (foundAddIn != null), OldVersion = (foundAddIn != null) ? new Version(foundAddInManaged.LinkedNuGetPackageVersion ?? foundAddIn.Version.ToString()) : null }; _addInsMarkedForInstall.Add(markedAddIn); // Successful installation AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn); _events.OnAddInInstalled(eventArgs); _events.OnAddInStateChanged(eventArgs); return addIn; } else { // This is not a valid SharpDevelop AddIn package! _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); } return null; }
public AddIn InstallAddIn(string fileName) { if (fileName != null) { AddIn addIn = null; bool installAsExternal = false; switch (Path.GetExtension(fileName).ToLowerInvariant()) { case ".addin": SD.Log.DebugFormatted("[AddInManager2] Loading {0} as manifest.", fileName); if (FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, fileName)) { // Don't allow to install AddIns from application root path _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager.CannotInstallIntoApplicationDirectory"))); return null; } // Load directly from location addIn = _sdAddInManagement.Load(fileName); installAsExternal = true; break; case ".sdaddin": case ".zip": SD.Log.DebugFormatted("[AddInManager2] Trying to load {0} as local AddIn package.", fileName); // Try to load the *.sdaddin file as ZIP archive ZipFile zipFile = null; try { zipFile = new ZipFile(fileName); addIn = LoadAddInFromZip(zipFile); } catch (Exception) { // ZIP file seems not to be valid _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); return null; } finally { if (zipFile != null) { zipFile.Close(); } } break; default: // Unknown format of file _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager.UnknownFileFormat") + " " + Path.GetExtension(fileName))); return null; } if (addIn != null) { if ((addIn.Manifest == null) || (addIn.Manifest.PrimaryIdentity == null)) { _events.OnAddInOperationError( new AddInOperationErrorEventArgs( new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity")))); return null; } // Try to find this AddIn in current registry string identity = addIn.Manifest.PrimaryIdentity; AddIn foundAddIn = null; foreach (AddIn treeAddIn in _sdAddInManagement.AddIns) { if (treeAddIn.Manifest.Identities.ContainsKey(identity)) { foundAddIn = treeAddIn; break; } } // Prevent this AddIn from being uninstalled, if marked for deinstallation foreach (string installedIdentity in addIn.Manifest.Identities.Keys) { _sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity); } if (!installAsExternal) { // Create target directory for AddIn in user profile & copy package contents there CopyAddInFromZip(addIn, fileName); // Install the AddIn using manifest if (foundAddIn != null) { addIn.Action = AddInAction.Update; } else { addIn.Action = AddInAction.Install; _sdAddInManagement.AddToTree(addIn); } } else { // Only add a reference to an external manifest _sdAddInManagement.AddExternalAddIns(new AddIn[] { addIn }); } // Mark this AddIn ManagedAddIn markedAddIn = new ManagedAddIn(addIn) { IsTemporary = true, IsUpdate = (foundAddIn != null), OldVersion = (foundAddIn != null) ? foundAddIn.Version : null }; _addInsMarkedForInstall.Add(markedAddIn); // Successful installation AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn); _events.OnAddInInstalled(eventArgs); _events.OnAddInStateChanged(eventArgs); return addIn; } } // In successful cases we should have exited somewhere else, in error cases the error event was already fired. return null; }
public AddIn InstallAddIn(IPackage package, string packageDirectory) { // Lookup for .addin file in package output var addInManifestFile = Directory.EnumerateFiles(packageDirectory, "*.addin", SearchOption.TopDirectoryOnly).FirstOrDefault(); if (addInManifestFile != null) { SD.Log.DebugFormatted("[AddInManager2] Installing AddIn from package {0} {1}", package.Id, package.Version.ToString()); // Patch metadata of AddIn to have a permanent link to the NuGet package if (!PatchAddInManifest(addInManifestFile, package)) { _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); return(null); } AddIn addIn = _sdAddInManagement.Load(addInManifestFile); if (addIn.Manifest.PrimaryIdentity == null) { _events.OnAddInOperationError( new AddInOperationErrorEventArgs( new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity")))); return(null); } // Just for safety also patch the properties of AddIn object directly PatchAddInProperties(addIn, package); // Try to find this AddIn in current registry string identity = addIn.Manifest.PrimaryIdentity; AddIn foundAddIn = null; foreach (AddIn treeAddIn in _sdAddInManagement.AddIns) { if (treeAddIn.Manifest.Identities.ContainsKey(identity)) { foundAddIn = treeAddIn; break; } } // Prevent this AddIn from being uninstalled, if marked for deinstallation foreach (string installedIdentity in addIn.Manifest.Identities.Keys) { _sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity); } // Create target directory for AddIn in user profile & copy package contents there CopyAddInFromPackage(addIn, packageDirectory); // Install the AddIn using manifest if (foundAddIn != null) { addIn.Action = AddInAction.Update; SD.Log.DebugFormatted("[AddInManager2] Marked AddIn {0} for update.", addIn.Name); } else { addIn.Action = AddInAction.Install; _sdAddInManagement.AddToTree(addIn); } // Some debug output about AddIn's manifest if ((addIn.Manifest != null) && !String.IsNullOrEmpty(addIn.Manifest.PrimaryIdentity)) { SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states identity '{0}'", addIn.Manifest.PrimaryIdentity); } else { SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states no identity."); } if (addIn.Properties.Contains(ManagedAddIn.NuGetPackageIDManifestAttribute)) { SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states NuGet ID '{0}'", addIn.Properties[ManagedAddIn.NuGetPackageIDManifestAttribute]); } else { SD.Log.DebugFormatted("[AddInManager2] AddIn's manifest states no NuGet ID."); } // Mark this AddIn ManagedAddIn foundAddInManaged = new ManagedAddIn(foundAddIn); ManagedAddIn markedAddIn = new ManagedAddIn(addIn) { InstallationSource = AddInInstallationSource.NuGetRepository, IsTemporary = true, IsUpdate = (foundAddIn != null), OldVersion = (foundAddIn != null) ? new Version(foundAddInManaged.LinkedNuGetPackageVersion ?? foundAddIn.Version.ToString()) : null }; _addInsMarkedForInstall.Add(markedAddIn); // Successful installation AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn); _events.OnAddInInstalled(eventArgs); _events.OnAddInStateChanged(eventArgs); return(addIn); } else { // This is not a valid SharpDevelop AddIn package! _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); } return(null); }
public AddIn InstallAddIn(string fileName) { if (fileName != null) { AddIn addIn = null; bool installAsExternal = false; switch (Path.GetExtension(fileName).ToLowerInvariant()) { case ".addin": SD.Log.DebugFormatted("[AddInManager2] Loading {0} as manifest.", fileName); if (FileUtility.IsBaseDirectory(FileUtility.ApplicationRootPath, fileName)) { // Don't allow to install AddIns from application root path _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager.CannotInstallIntoApplicationDirectory"))); return(null); } // Load directly from location addIn = _sdAddInManagement.Load(fileName); installAsExternal = true; break; case ".sdaddin": case ".zip": SD.Log.DebugFormatted("[AddInManager2] Trying to load {0} as local AddIn package.", fileName); // Try to load the *.sdaddin file as ZIP archive ZipFile zipFile = null; try { zipFile = new ZipFile(fileName); addIn = LoadAddInFromZip(zipFile); } catch (Exception) { // ZIP file seems not to be valid _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager2.InvalidPackage"))); return(null); } finally { if (zipFile != null) { zipFile.Close(); } } break; default: // Unknown format of file _events.OnAddInOperationError( new AddInOperationErrorEventArgs( SD.ResourceService.GetString("AddInManager.UnknownFileFormat") + " " + Path.GetExtension(fileName))); return(null); } if (addIn != null) { if ((addIn.Manifest == null) || (addIn.Manifest.PrimaryIdentity == null)) { _events.OnAddInOperationError( new AddInOperationErrorEventArgs( new AddInLoadException(SD.ResourceService.GetString("AddInManager.AddInMustHaveIdentity")))); return(null); } // Try to find this AddIn in current registry string identity = addIn.Manifest.PrimaryIdentity; AddIn foundAddIn = null; foreach (AddIn treeAddIn in _sdAddInManagement.AddIns) { if (treeAddIn.Manifest.Identities.ContainsKey(identity)) { foundAddIn = treeAddIn; break; } } // Prevent this AddIn from being uninstalled, if marked for deinstallation foreach (string installedIdentity in addIn.Manifest.Identities.Keys) { _sdAddInManagement.AbortRemoveUserAddInOnNextStart(installedIdentity); } if (!installAsExternal) { // Create target directory for AddIn in user profile & copy package contents there CopyAddInFromZip(addIn, fileName); // Install the AddIn using manifest if (foundAddIn != null) { addIn.Action = AddInAction.Update; } else { addIn.Action = AddInAction.Install; _sdAddInManagement.AddToTree(addIn); } } else { // Only add a reference to an external manifest _sdAddInManagement.AddExternalAddIns(new AddIn[] { addIn }); } // Mark this AddIn ManagedAddIn markedAddIn = new ManagedAddIn(addIn) { IsTemporary = true, IsUpdate = (foundAddIn != null), OldVersion = (foundAddIn != null) ? foundAddIn.Version : null }; _addInsMarkedForInstall.Add(markedAddIn); // Successful installation AddInInstallationEventArgs eventArgs = new AddInInstallationEventArgs(addIn); _events.OnAddInInstalled(eventArgs); _events.OnAddInStateChanged(eventArgs); return(addIn); } } // In successful cases we should have exited somewhere else, in error cases the error event was already fired. return(null); }