public void PluginFileTest() { PluginStore target = new PluginStore(); #region insert and retrieve a plugin file int oldCount = target.Plugins.Count(); // store a new entry in the db string name = RandomName(); target.Persist(new PluginDescription(name, new Version(0, 1)), enc.GetBytes("Zipped " + name)); int newCount = target.Plugins.Count(); // make sure the new entry was added to the db Assert.AreEqual(oldCount + 1, newCount); // get matching description from db and try to retrieve the stored file PluginDescription pluginDescription = target.Plugins.Where(p => p.Name == name).Single(); byte[] expected = enc.GetBytes("Zipped " + name); byte[] actual = target.PluginFile(pluginDescription); // check retrieved file Assert.AreEqual(expected.Length, actual.Length); for (int i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i], actual[i]); } #endregion }
private ObservableCollection <StepFullInfo> LoadPlugins(PluginDescription pluginDescription, View currentView) { List <StepFullInfo> filterPlugins = FilterPlugins(pluginDescription); ObservableCollection <StepFullInfo> list = null; switch (currentView) { case View.ByAssembly: list = FillTreeByAssembly(filterPlugins); break; case View.ByMessage: list = FillTreeByMessage(filterPlugins); break; case View.ByEntity: default: list = FillTreeByEntity(filterPlugins); break; } ExpandNodes(list); return(list); }
public void TestLoad1() { var assemblyFileName = "Foo1.dll"; if (File.Exists(assemblyFileName)) { File.Delete(assemblyFileName); } var builder = new PluginBuilder("Simon", "Foo1", "Foo1", "Simon", "None of your business", "Get of my lawn"); builder.ImplementInterface <IFileFormatPlugin>("Foo1.MyAwesomePlugin"); builder.Save(); var description = new PluginDescription { FilePath = assemblyFileName, Plugins = new Dictionary <Type, string> { { typeof(IFileFormatPlugin), "Foo1.MyAwesomePlugin" } } }; using (var scanner = new PluginAssemblyLoader()) { var plugin = scanner.Load <IFileFormatPlugin>(description); plugin.Should().NotBeNull(); plugin.GetType().FullName.Should().Be("Foo1.MyAwesomePlugin"); } }
public void TestLoad2() { var assemblyFileName = "Foo2.dll"; if (File.Exists(assemblyFileName)) { File.Delete(assemblyFileName); } var builder = new PluginBuilder("Simon", "Foo2", "Foo2", "Simon", "None of your business", "Get of my lawn"); builder.ImplementInterface <IFileFormatPlugin>("Foo2.MyAwesomePlugin"); builder.Save(); var description = new PluginDescription { FilePath = assemblyFileName, PluginImplementations = new List <IPluginImplementationDescription> { new PluginImplementationDescription("Foo2.MyAwesomePlugin", typeof(IFileFormatPlugin)) } }; using (var scanner = new PluginAssemblyLoader()) { var plugin = scanner.Load <IFileFormatPlugin>(description, description.PluginImplementations[0]); plugin.Should().NotBeNull(); plugin.GetType().FullName.Should().Be("Foo2.MyAwesomePlugin"); } }
/// <summary> /// Fetches the plugin descriptions out of the assembly. /// </summary> private PluginDescription[] LoadPluginsList([NotNull] IList <Type> plugintypes) { if (plugintypes == null) { throw new ArgumentNullException("plugintypes"); } if (_assembly == null) { throw new InvalidOperationException(string.Format("Need an assembly to load the plugins list.")); } // Create descriptions var descriptions = new List <PluginDescription>(); foreach (Type plugintype in plugintypes) { try { descriptions.Add(PluginDescription.CreateFromPluginType(plugintype)); } catch (Exception ex) { Core.ReportBackgroundException(ex); } } return(descriptions.ToArray()); }
public Plugin(string assemblyName, string assemblyType, AppDomain domain, string location) { PluginDescription desc = new PluginDescription(); List<string> osapdFiles = new List<string>(); string[] pluginFile = Directory.GetFiles(location, "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { desc = new PluginDescription(); desc.Deserialize(path); _pluginVersion = desc.Version; } } _pluginType = desc.Type; _pluginName = osae.GetPluginName(_pluginType, osae.ComputerName); _assemblyType = assemblyType; _assemblyName = assemblyName; _domain = domain; _location = location; _latestAvailableVersion = ""; }
public void TestLoadFromFile() { string registryPath = Path.Combine(TestData.PATH, "registry/registry.xml"); Registry registry = Registry.LoadFromFile(registryPath); Assert.AreEqual("registry.google.unity", registry.groupId); Assert.AreEqual("jarresolver-google-registry", registry.artifactId); Assert.AreEqual("0.0.1.1", registry.version); Assert.AreEqual(1482171836, registry.lastUpdated); Assert.NotNull(registry.modules); Assert.AreEqual(1, registry.modules.module.Count); Assert.AreEqual("com.google.unity.example", registry.modules.module[0]); string barPluginPath = Path.Combine(TestData.PATH, "registry/com.google.unity.example/package-manifest.xml"); PluginMetaData pluginMetaData = PluginMetaData.LoadFromFile(barPluginPath); Assert.AreEqual("com.google.unity.example", pluginMetaData.groupId); Assert.AreEqual("gpm-example-plugin", pluginMetaData.artifactId); Assert.AreEqual("unitypackage", pluginMetaData.packaging); Assert.NotNull(pluginMetaData.versioning); Assert.AreEqual("1.0.0.0", pluginMetaData.versioning.release); Assert.NotNull(pluginMetaData.versioning.versions); Assert.AreEqual(1, pluginMetaData.versioning.versions.Count); Assert.AreEqual(0, pluginMetaData.lastUpdated); string barDescriptionPath = Path.Combine(TestData.PATH, "registry/com.google.unity.example/gpm-example-plugin/1.0.0.0/description.xml"); PluginDescription description = PluginDescription.LoadFromFile(barDescriptionPath); Assert.NotNull(description.languages); Assert.AreEqual(1, description.languages.Count); }
public void ActivatePlugins(PluginDescription plugin) { HandleMessage(string.Format("Initialisiere ausgewähltes Plugin {0}", plugin.Name)); Logger.Debug("Beginne Plugin {0} mit Abhänhgigkeiten zu aktivieren", plugin.Name); _loader.ActivatePlugins(plugin); Logger.Debug("Plugin {0} mit Abhänhgigkeiten komplett aktiviert", plugin.Name); }
private async Task ExecuteActionPluginAssemblyDescription( PluginConfigurationAssemblyDescriptionHandler handler , PluginDescription pluginDescription , PluginAssembly pluginAssembly , Func <string, PluginConfigurationAssemblyDescriptionHandler, PluginDescription, PluginAssembly, Task> action) { if (!this.IsControlsEnabled) { return; } string folder = txtBFolder.Text.Trim(); if (string.IsNullOrEmpty(folder)) { _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportIsEmpty); folder = FileOperations.GetDefaultFolderForExportFilePath(); } else if (!Directory.Exists(folder)) { _iWriteToOutput.WriteToOutput(null, Properties.OutputStrings.FolderForExportDoesNotExistsFormat1, folder); folder = FileOperations.GetDefaultFolderForExportFilePath(); } await action(folder, handler, pluginDescription, pluginAssembly); }
public static ServiceHost CreatePlugin(PluginDescription description, params Uri[] serverBaseAddresses) { var impl = Type.GetType(description.ImplementationName); var baseAddresses = serverBaseAddresses .Select(addr => new Uri(addr, description.ServiceName)) .ToArray(); var serviceHost = new ServiceHost( impl, baseAddresses); foreach (var contract in description.Contracts) { var contractInterface = Type.GetType(contract.ContractInterfaceName); foreach (var endpoint in contract.EndPoints) { serviceHost.AddServiceEndpoint( contractInterface, new NetNamedPipeBinding(), endpoint); } } return(serviceHost); }
private static ListViewItem CreateListViewItem(PluginDescription plugin) { ListViewItem item = new ListViewItem(new string[] { plugin.Name, plugin.Version.ToString(), plugin.Description }); item.Tag = plugin; item.ImageIndex = 0; return(item); }
private List <StepFullInfo> FilterPlugins(PluginDescription pluginDescription) { IEnumerable <StepFullInfo> steps = null; if (this._pluginDescription != null) { steps = (from a in this._pluginDescription.PluginAssemblies from p in a.PluginTypes from s in p.PluginSteps select new StepFullInfo() { PluginDescription = this._pluginDescription, PluginAssembly = a, PluginType = p, PluginStep = s, } ); } else { steps = new List <StepFullInfo>(); } string entityName = string.Empty; string messageName = string.Empty; string pluginTypeName = string.Empty; this.Dispatcher.Invoke(() => { entityName = txtBEntityName.Text.Trim(); messageName = txtBMessageFilter.Text.Trim(); pluginTypeName = txtBPluginTypeFilter.Text.Trim(); }); if (!string.IsNullOrEmpty(pluginTypeName)) { steps = steps.Where(s => s.PluginType.TypeName.StartsWith(pluginTypeName, StringComparison.InvariantCultureIgnoreCase)); } if (!string.IsNullOrEmpty(messageName)) { steps = steps.Where(s => s.PluginStep.Message.StartsWith(messageName, StringComparison.InvariantCultureIgnoreCase)); } if (!string.IsNullOrEmpty(entityName)) { steps = steps.Where(s => s.PluginStep.PrimaryEntity.StartsWith(entityName, StringComparison.InvariantCultureIgnoreCase)); } var stages = GetStages(); if (stages.Count != 0 && stages.Count != 4) { steps = steps.Where(s => stages.Any(stage => IsFromStage(s, stage))); } return(steps.ToList()); }
public ThreadManagerPlugin(IDependencyResolver resolver, IDependencyResolverConfigurator configurator, IEventService eventService, ILogger logger) : base(resolver, configurator, eventService, logger) { _description = new PluginDescription { Name = "ThreadManager", Description = "Plugin zum verwalten von Threads", ProvidedServices = new[] { typeof(IThreadManager) } }; }
public GpxPlugin(IDependencyResolver resolver, IDependencyResolverConfigurator configurator, IEventService eventService, ILogger logger) : base(resolver, configurator, eventService, logger) { _description = new PluginDescription() { Name = "GPX-Plugin", ProvidedServices = new[] { typeof(IGpxDataAccess) } }; }
private void loadPlugins() { pluginList = new BindingList <PluginDescription>(); List <string> osapdFiles = new List <string>(); string[] pluginFile = Directory.GetFiles(Common.ApiPath + "\\Plugins", "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { PluginDescription desc = new PluginDescription(); desc.Deserialize(path); desc.Status = "Stopped"; desc.Enabled = false; if (desc.WikiUrl.Trim() == "") { desc.WikiUrl = "http://www.opensourceautomation.com/wiki/index.php?title=Plugins"; } OSAEObjectCollection objs = OSAEObjectManager.GetObjectsByType(desc.Type); foreach (OSAEObject o in objs) { if (OSAEObjectPropertyManager.GetObjectPropertyValue(o.Name, "Computer Name").Value == Common.ComputerName || desc.Type == o.Name) { desc.Name = o.Name; if (o.Enabled == 1) { desc.Enabled = true; } if (o.State.Value == "ON") { desc.Status = "Running"; } else { desc.Status = "Stopped"; } } } pluginList.Add(desc); Log.Info("Plugin found: Name:" + desc.Name + " Desc ID: " + desc.ID); } } // TODO: Load all other objects with base type of PLUGIN. These objects represent plugins on client instances. Maybe make a separate grid since it wont be able to load the osapd files on the clients checkForUpdates(); gvPlugins.DataSource = pluginList; gvPlugins.DataBind(); }
public MongoDbPlugin(IDependencyResolver resolver, IDependencyResolverConfigurator configurator, IEventService eventService, ILogger logger) : base(resolver, configurator, eventService, logger) { _description = new PluginDescription { Name = "MongoDbPlugin", ProvidedServices = new[] { typeof(IMongoFactory) }, NeededServices = new[] { typeof(IConfiguration) } }; }
public ConfigurationPlugin(IDependencyResolver resolver, IDependencyResolverConfigurator configurator, IEventService eventService, ILogger logger) : base(resolver, configurator, eventService, logger) { _description = new PluginDescription { Name = "Konfiguration", NeededServices = new[] { typeof(IXmlToObject) }, ProvidedServices = new[] { typeof(IConfiguration) } }; }
/// <summary> /// Initializes a new instance of the <see cref="TestTrackPlugin"/> class. /// </summary> /// <param name="notificationManager">The notification manager.</param> public TestTrackPlugin(INotificationManager notificationManager) { this.notificationManager = notificationManager; this.descrition = new PluginDescription(); this.descrition.Enabled = true; this.descrition.Description = "TestTrack Plugin"; this.descrition.Name = "TestTrack Plugin"; this.descrition.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.descrition.AssemblyPath = Assembly.GetExecutingAssembly().Location; }
/// <summary> /// Finds all types that are subtypes or equal to the specified type if they are part of the given /// <paramref name="pluginDescription"/>. /// </summary> /// <param name="type">Most general type for which to find matching types.</param> /// <param name="pluginDescription">The plugin the subtypes must be part of.</param> /// <param name="onlyInstantiable">Return only types that are instantiable /// <param name="includeGenericTypeDefinitions">Specifies if generic type definitions shall be included</param> /// (interfaces, abstract classes... are not returned)</param> /// <returns>Enumerable of the discovered types.</returns> internal static IEnumerable <Type> GetTypes(Type type, IPluginDescription pluginDescription, bool onlyInstantiable, bool includeGenericTypeDefinitions) { PluginDescription pluginDesc = (PluginDescription)pluginDescription; return(from asm in AppDomain.CurrentDomain.GetAssemblies() where !asm.IsDynamic && !string.IsNullOrEmpty(asm.Location) where pluginDesc.AssemblyLocations.Any(location => location.Equals(Path.GetFullPath(asm.Location), StringComparison.CurrentCultureIgnoreCase)) from t in GetTypes(type, asm, onlyInstantiable, includeGenericTypeDefinitions) select t); }
public XmlToObjectPlugin(IDependencyResolver resolver, IDependencyResolverConfigurator configurator, IEventService eventService, ILogger logger) : base(resolver, configurator, eventService, logger) { _description = new PluginDescription { Name = "XML To Object Converter", Description = "Liest XML Dateien aus und befüllt die dazugehörigen Objekte", ProvidedServices = new[] { typeof(IXmlToObject) } }; }
public QuartzPlugin(IDependencyResolver resolver, IDependencyResolverConfigurator configurator, IEventService eventService, ILogger logger) : base(resolver, configurator, eventService, logger) { _description = new PluginDescription { Name = "QuartzPlugin", Description = "Liefert Funktionalität um regelmäßig registrierte Task auszuführen", ProvidedServices = new[] { typeof(ISchedulingService) } }; }
/// <summary> /// Unistalls a plugin /// </summary> /// <param name="desc">The information about the plugin to be deleted</param> /// <returns>true if deleted false otherwise</returns> public bool UninstallPlugin(PluginDescription desc) { bool returnValue = false; OSAE.Types.AvailablePlugins avPlugins = GlobalUserControls.OSAEUserControls.AvailablePlugins; foreach (OSAE.Types.AvailablePlugin avPlugin in avPlugins) { avPlugin.Instance.Dispose(); } avPlugins.Clear(); GlobalUserControls.OSAEUserControls.ClosePlugins(); Thread.Sleep(2000); string exePath = OSAE.Common.ApiPath; string pluginFolder = exePath + "/UserControls/" + desc.Path; string webFolder = exePath + "/Plugins/Web Server/wwwroot/controls/usercontrols/" + desc.Path; if (Directory.Exists(pluginFolder)) { if (deleteFolder(pluginFolder)) { returnValue = true; } else { returnValue = false; } if (Directory.Exists(pluginFolder)) { returnValue = false; } } if (Directory.Exists(webFolder)) { if (deleteFolder(webFolder)) { returnValue = true; } else { returnValue = false; } if (Directory.Exists(webFolder)) { returnValue = false; } } else { returnValue = true; } return(returnValue); }
protected PluginDescriptionBase() { var pluginBuilder = PluginDescriptionBuilder.Create <TPlugin>(); foreach (var contract in typeof(TPlugin).GetInterfaces()) { var contractBuilder = new ServiceContractDescriptionBuilder(contract); pluginBuilder.ContractSet.Add(contractBuilder.ToDescription()); } Description = pluginBuilder.ToPluginDescription(); }
public void TestConstructionWithError() { var description = new PluginDescription { Error = "Someone screwed up" }; var viewModel = new InstalledPluginViewModel(description); viewModel.HasError.Should().BeTrue(); viewModel.Error.Should().Be("Someone screwed up"); }
private async Task LoadPluginConfiguration(string filePath, Action <PluginDescription> setter, TextBox textBox) { if (!this.IsControlsEnabled) { return; } textBox.Text = string.Empty; ToggleControls(false, Properties.OutputStrings.LoadingPluginConfiguration); if (string.IsNullOrEmpty(filePath)) { return; } if (!File.Exists(filePath)) { return; } PluginDescription pluginDescription = null; try { pluginDescription = await PluginDescription.LoadAsync(filePath); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(null, ex); pluginDescription = null; } setter(pluginDescription); this._allEntities = null; textBox.Dispatcher.Invoke(() => { if (pluginDescription != null) { textBox.Text = filePath; } else { textBox.Text = string.Empty; } }); ToggleControls(true, Properties.OutputStrings.LoadingPluginConfigurationCompleted); ShowExistingAssemblies(); }
/// <summary> /// Initializes a new instance of the <see cref="ExportOptions"/> class. /// </summary> /// <param name="gamePlugin">The game plugin.</param> /// <param name="editorPlugin">The editor plugin.</param> public ExportOptions(GamePlugin gamePlugin, EditorPlugin editorPlugin) { if (gamePlugin == null && editorPlugin == null) { throw new ArgumentException(); } GamePlugin = gamePlugin; EditorPlugin = editorPlugin; Description = gamePlugin?.Description ?? editorPlugin.Description; ShortName = ((Plugin)gamePlugin ?? editorPlugin).GetType().Name; }
public SortFilePlugin(IDependencyResolver resolver, IDependencyResolverConfigurator configurator, IEventService eventService, ILogger logger) : base(resolver, configurator, eventService, logger) { _description = new AutostartServicePluginDescription { Name = "FileSortingPlugin", NeededServices = new[] { typeof(IXmlToObject), typeof(IGpxDataAccess), //typeof(IEnvironmentParameters) } }; }
/// <summary> /// Initializes a new instance of the <see cref="SQGitPlugin" /> class. /// </summary> /// <param name="notificationManager">The notification manager.</param> public TestTrackPlugin(INotificationManager notificationManager, ISonarConfiguration configuration) { this.userConf = configuration; this.notificationManager = notificationManager; this.descrition = new PluginDescription(); this.descrition.Enabled = true; this.descrition.Description = "TestTrack Plugin"; this.descrition.Name = "TestTrack Plugin"; this.descrition.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.descrition.AssemblyPath = Assembly.GetExecutingAssembly().Location; this.testTrackIntegration = new TestTrackConnector(configuration.Username, configuration.Password, true, new TtConnection()); }
public void TestConstructionWithoutName([Values(null, "")] string emptyName) { var description = new PluginDescription { Id = new PluginId("SomeOrg.SomePlugin"), Name = emptyName }; var viewModel = new InstalledPluginViewModel(description); viewModel.Name.Should().Be("SomeOrg.SomePlugin", "because absent of a name, the id should be presented to the user as the plugin's name"); }
/// <summary> /// Initializes a new instance of the <see cref="SQGitPlugin"/> class. /// </summary> public SQGitPlugin(INotificationManager notificationManager, IVSSonarQubeCmdExecutor executor) { this.executor = executor; this.UseCommandLine = true; this.notificationManager = notificationManager; this.descrition = new PluginDescription(); this.descrition.Description = "Git Source Code Provider"; this.descrition.Enabled = true; this.descrition.Name = "Git Plugin"; this.descrition.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.descrition.AssemblyPath = Assembly.GetExecutingAssembly().Location; }
/// <summary> /// Initializes a new instance of the <see cref="SQGitPlugin" /> class. /// </summary> /// <param name="notificationManager">The notification manager.</param> public TestTrackPlugin(INotificationManager notificationManager, ISonarConfiguration configuration) { this.userConf = configuration; this.notificationManager = notificationManager; this.descrition = new PluginDescription(); this.descrition.Enabled = true; this.descrition.Description = "TestTrack Plugin"; this.descrition.Name = "TestTrack Plugin"; this.descrition.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.descrition.AssemblyPath = Assembly.GetExecutingAssembly().Location; this.testTrackIntegration = new TestTrackConnector(configuration.Username, configuration.Password, true, new TtConnection()); }
private async Task LoadPluginConfiguration(string filePath) { if (!this.IsControlsEnabled) { return; } this.Dispatcher.Invoke(() => { this._itemsSource.Clear(); txtBFilePath.Text = string.Empty; }); if (string.IsNullOrEmpty(filePath)) { return; } if (!File.Exists(filePath)) { return; } ToggleControls(false, Properties.OutputStrings.LoadingPluginConfiguration); try { this._pluginDescription = await PluginDescription.LoadAsync(filePath); } catch (Exception ex) { _iWriteToOutput.WriteErrorToOutput(null, ex); this._pluginDescription = null; } txtBFilePath.Dispatcher.Invoke(() => { if (this._pluginDescription != null) { txtBFilePath.Text = filePath; } else { txtBFilePath.Text = string.Empty; } }); ToggleControls(true, Properties.OutputStrings.LoadingPluginConfigurationCompleted); ShowExistingPluginTypes(); }
public static PluginInformation With( PluginId id, PluginTitle title, PluginVersion version, PluginDescription description, Uri uri) { return new PluginInformation( id, title, version, description, uri); }
public void PluginDescription_Constructor() { var name = "HelloWorld1"; var desc = "Description test!"; var pluginDescription = new PluginDescription(name, desc); TestUtils.AssertArgumentException(() => new PluginDescription(null, "")); TestUtils.AssertArgumentException(() => new PluginDescription("", "")); TestUtils.AssertArgumentException(() => new PluginDescription("!!!", "")); TestUtils.AssertArgumentException(() => new PluginDescription("A!0", "")); TestUtils.AssertArgumentException(() => new PluginDescription("ABC", null)); Assert.AreEqual(name, pluginDescription.Name); Assert.AreEqual(desc, pluginDescription.Description); }
public PluginInformation( PluginId id, PluginTitle title, PluginVersion version, PluginDescription description, Uri uri) { if (id == null) throw new ArgumentNullException(nameof(id)); if (title == null) throw new ArgumentNullException(nameof(title)); if (version == null) throw new ArgumentNullException(nameof(version)); if (description == null) throw new ArgumentNullException(nameof(description)); if (uri == null) throw new ArgumentNullException(nameof(uri)); Id = id; Title = title; Version = version; Description = description; Uri = uri; }
public void InsertPluginPerformanceTest() { int nPlugins = 100; int maxDependencies = 10; int avgZipFileLength = 32000; var store = new PluginStore(); Version vers01 = new Version(0, 1); // create a random byte array to represent file length byte[] zippedConstant = new byte[avgZipFileLength]; Random r = new Random(); r.NextBytes(zippedConstant); Stopwatch stopWatch = new Stopwatch(); stopWatch.Start(); // create plugins List<PluginDescription> plugins = new List<PluginDescription>(); for (int i = 0; i < nPlugins; i++) { string name = RandomName(); var dependencies = store.Plugins; if (dependencies.Count() > maxDependencies) dependencies = dependencies.Take(maxDependencies); var plugin = new PluginDescription(name, vers01, dependencies); store.Persist(plugin, zippedConstant); plugins.Add(plugin); } stopWatch.Stop(); Assert.Inconclusive("Created " + nPlugins + " plugins in " + stopWatch.ElapsedMilliseconds + " ms (" + (double)stopWatch.ElapsedMilliseconds / nPlugins + " ms / plugin )"); }
/// <summary> /// Initializes a new instance of the <see cref="SQGitPlugin" /> class. /// </summary> /// <param name="notificationManager">The notification manager.</param> public SQGitPlugin(INotificationManager notificationManager) { this.executor = new VSSonarQubeCmdExecutor(6000); this.UseCommandLine = true; this.notificationManager = notificationManager; this.descrition = new PluginDescription(); this.descrition.Description = "Git Source Code Provider"; this.descrition.Enabled = true; this.descrition.Name = "Git Plugin"; this.descrition.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.descrition.AssemblyPath = Assembly.GetExecutingAssembly().Location; }
/// <summary> /// Initializes a new instance of the <see cref="TestTrackPlugin"/> class. /// </summary> /// <param name="notificationManager">The notification manager.</param> public TestTrackPlugin(INotificationManager notificationManager) { this.notificationManager = notificationManager; this.descrition = new PluginDescription(); this.descrition.Enabled = true; this.descrition.Description = "TestTrack Plugin"; this.descrition.Name = "TestTrack Plugin"; this.descrition.Version = Assembly.GetExecutingAssembly().GetName().Version.ToString(); this.descrition.AssemblyPath = Assembly.GetExecutingAssembly().Location; }
public void PersistProductTest() { Version vers01 = new Version(0, 1); PluginStore target = new PluginStore(); #region persist a product without plugins to the db { string prodName = RandomName(); int oldCount = target.Products.Count(); ProductDescription product = new ProductDescription(prodName, vers01); target.Persist(product); int newCount = target.Products.Count(); Assert.AreEqual(oldCount + 1, newCount); } #endregion #region persist a product with the same name and version as an existant product { string prodName = RandomName(); int oldCount = target.Products.Count(); ProductDescription product = new ProductDescription(prodName, vers01); target.Persist(product); int newCount = target.Products.Count(); Assert.AreEqual(oldCount + 1, newCount); // write a product with same name and version oldCount = target.Products.Count(); product = new ProductDescription(prodName, vers01); target.Persist(product); newCount = target.Products.Count(); // make sure that the old entry was updated Assert.AreEqual(oldCount, newCount); // write a product with same name and different version oldCount = target.Products.Count(); product = new ProductDescription(prodName, new Version(0, 2)); target.Persist(product); newCount = target.Products.Count(); // make sure that a new entry was created Assert.AreEqual(oldCount + 1, newCount); } #endregion #region try to persist a product referencing an non-existant plugin and check the expected exception { // try to persist a product referencing a non-existant plugin string prodName = RandomName(); string pluginName = RandomName(); var plugin = new PluginDescription(pluginName, vers01); var product = new ProductDescription(prodName, vers01, Enumerable.Repeat(plugin, 1)); try { target.Persist(product); Assert.Fail("persist should fail with ArgumentException"); } catch (ArgumentException) { // this is expected Assert.IsTrue(true, "expected exception"); } } #endregion #region persist a product with a single plugin reference { string prodName = RandomName(); string pluginName = RandomName(); var plugin = new PluginDescription(pluginName, vers01); var product = new ProductDescription(prodName, vers01, Enumerable.Repeat(plugin, 1)); // persist the plugin first int oldCount = target.Products.Count(); target.Persist(plugin, enc.GetBytes("Zipped " + plugin.Name)); target.Persist(product); int newCount = target.Products.Count(); // make sure the store went through Assert.AreEqual(oldCount + 1, newCount); // retrieve the product and check if the plugin list was stored/retrieved correctly var dbProd = target.Products.Where(p => p.Name == prodName).Single(); Assert.AreEqual(dbProd.Plugins.Count(), 1); Assert.AreEqual(dbProd.Plugins.First().Name, pluginName); } #endregion #region update the plugin list of an existing product { string prodName = RandomName(); string plugin1Name = RandomName(); var plugin1 = new PluginDescription(plugin1Name, vers01); var product = new ProductDescription(prodName, vers01, Enumerable.Repeat(plugin1, 1)); // persist the plugin first int oldCount = target.Products.Count(); target.Persist(plugin1, enc.GetBytes("Zipped " + plugin1.Name)); target.Persist(product); int newCount = target.Products.Count(); // make sure the store went through Assert.AreEqual(oldCount + 1, newCount); var plugin2Name = RandomName(); var plugin2 = new PluginDescription(plugin2Name, vers01); target.Persist(plugin2, enc.GetBytes("Zipped " + plugin2.Name)); product = new ProductDescription(prodName, vers01, new PluginDescription[] { plugin1, plugin2 }); oldCount = target.Products.Count(); target.Persist(product); newCount = target.Products.Count(); // make sure that a new entry was not created Assert.AreEqual(oldCount, newCount); // check the plugin list of the product var dbProduct = target.Products.Where(p => p.Name == prodName).Single(); Assert.AreEqual(dbProduct.Plugins.Count(), 2); } #endregion #region insert a product which references the same plugin twice and check if the correct exception is thrown { string prodName = RandomName(); string plugin1Name = RandomName(); var plugin1 = new PluginDescription(plugin1Name, vers01); var product = new ProductDescription(prodName, vers01, Enumerable.Repeat(plugin1, 2)); // persist the plugin first target.Persist(plugin1, enc.GetBytes("Zipped " + plugin1.Name)); try { target.Persist(product); Assert.Fail("Expected ArgumentException"); } catch (ArgumentException) { Assert.IsTrue(true, "Expected exception was thrown."); } } #endregion }
/// <summary> /// Unistalls a plugin /// </summary> /// <param name="desc">The information about the plugin to be deleted</param> /// <returns>true if deleted false otherwise</returns> public static bool UninstallPlugin(PluginDescription desc) { bool returnValue = false; string exePath = Path.GetDirectoryName(Application.ExecutablePath); string pluginFolder = exePath + "/Plugins/" + desc.Path; if (Directory.Exists(pluginFolder)) { deleteFolder(pluginFolder); returnValue = true; if (Directory.Exists(pluginFolder)) returnValue = false; } return returnValue; }
/// <summary> /// Unistalls a plugin /// </summary> /// <param name="desc">The information about the plugin to be deleted</param> /// <returns>true if deleted false otherwise</returns> public bool UninstallPlugin(PluginDescription desc) { bool returnValue = false; Thread thread = new Thread(() => messageHost(OSAEWCFMessageType.PLUGIN, "ENABLEPLUGIN|" + desc.Type + "|False")); thread.Start(); Thread.Sleep(2000); string exePath = Path.GetDirectoryName(Application.ExecutablePath); string pluginFolder = exePath + "/Plugins/" + desc.Path; if (Directory.Exists(pluginFolder)) { if (deleteFolder(pluginFolder)) returnValue = true; else returnValue = false; if (Directory.Exists(pluginFolder)) returnValue = false; } else returnValue = true; return returnValue; }
public bool InstallPlugin(string PluginPackagePath, ref string ErrorText) { string exePath = Path.GetDirectoryName(Application.ExecutablePath); if (Directory.Exists(exePath + "/tempDir/")) { Directory.Delete(exePath + "/tempDir/", true); } PluginDescription desc = new PluginDescription(); string tempfolder = exePath + "/tempDir/"; string zipFileName = Path.GetFullPath(PluginPackagePath); string DescPath = null; bool NoError = true; ICSharpCode.SharpZipLib.Zip.FastZip fastZip = new ICSharpCode.SharpZipLib.Zip.FastZip(); try { fastZip.ExtractZip(zipFileName, tempfolder, null); // find all included plugin descriptions and install the plugins List<string> osapdFiles = new List<string>(); List<string> sqlFiles = new List<string>(); string[] pluginFile = Directory.GetFiles(tempfolder, "*.osapd", SearchOption.TopDirectoryOnly); osapdFiles.AddRange(pluginFile); string[] sqlFile = Directory.GetFiles(tempfolder, "*.sql", SearchOption.TopDirectoryOnly); sqlFiles.AddRange(sqlFile); if (osapdFiles.Count == 0) { MessageBox.Show("No plugin description files found."); return false; } if (osapdFiles.Count > 1) { MessageBox.Show("More than one plugin description file found."); return false; } if (osapdFiles.Count == 1) { DescPath = osapdFiles[0]; } if (!string.IsNullOrEmpty(DescPath)) { desc.Deserialize(DescPath); //NoError = desc.VerifyInstall(ref ErrorText); //uninstall previous plugin and delete the folder if (UninstallPlugin(desc)) { // get the plugin folder path string pluginFolder = desc.Path; if (!string.IsNullOrEmpty(pluginFolder)) //only extract valid plugins { string[] files = System.IO.Directory.GetFiles(tempfolder); string ConnectionString = string.Format("Uid={0};Pwd={1};Server={2};Port={3};Database={4};allow user variables=true", Common.DBUsername, Common.DBPassword, Common.DBConnection, Common.DBPort, Common.DBName); MySql.Data.MySqlClient.MySqlConnection connection = new MySql.Data.MySqlClient.MySqlConnection(ConnectionString); connection.Open(); foreach (string s in sqlFile) { try { MySql.Data.MySqlClient.MySqlScript script = new MySql.Data.MySqlClient.MySqlScript(connection, File.ReadAllText(s)); script.Execute(); } catch (Exception ex) { this.Log.Error("Error running sql script: " + s, ex); } } System.IO.Directory.Move(tempfolder, exePath + "/Plugins/" + pluginFolder); //Check if we are running a x64 bit architecture (This is a silly way to do it since I am not sure if every 64 bit machine has this directory...) bool is64bit = Environment.Is64BitOperatingSystem; //Do a check for any x64 assemblies, and prompt the user to install them if they are running a 64 bit machine if (is64bit && (desc.x64Assemblies.Count > 0)) { /* x64 assemblies generally have the same name as their x32 counterparts when referenced by the OSA app * however they are packaged as "filename.ext.x64" so we will replace the 32bit file which is installed by * default with the 64bit versioin with the same filename.ext */ if (MessageBox.Show( "You are running an x64 architecture and this plugin has specific assemblies built for 64bit machines." + " It is highly recommended that you install the 64bit versions to ensure proper compatibility", "Install 64bit Assemblies?", MessageBoxButtons.YesNo) == DialogResult.Yes) { //Install the 64bit assemblies over the 32 bit ones... string[] x64files = System.IO.Directory.GetFiles(exePath + "/Plugins/" + pluginFolder, "*.x64"); foreach (string str in x64files) { string destFile = System.IO.Path.Combine(exePath + "/Plugins/" + pluginFolder + "/", System.IO.Path.GetFileNameWithoutExtension(str)); //Copy it to the new destination overwriting the old file if it exists System.IO.File.Copy(str, destFile, true); } } } //Delete all the files with .x64 extensions since they aren't needed anymore string[] delfiles = System.IO.Directory.GetFiles(exePath + "/Plugins/" + pluginFolder, "*.x64"); foreach (string str in delfiles) System.IO.File.Delete(str); this.Log.Info("Sending message to service to load plugin."); } } else return false; } } catch (Exception ex) { MessageBox.Show("catch: " + ex.Message); return false; } if (Directory.Exists(exePath + "/tempDir/")) { deleteFolder(exePath + "/tempDir/"); } OSAEMethodManager.MethodQueueAdd("SERVICE-" + Common.ComputerName, "RELOAD PLUGINS", "", "", "Plugin Installer"); return NoError; }
/// <summary> /// Unistalls a plugin /// </summary> /// <param name="desc">The information about the plugin to be deleted</param> /// <returns>true if deleted false otherwise</returns> public bool UninstallPlugin(PluginDescription desc) { bool returnValue = false; string ip = Common.WcfServer; if (ip == "localhost") ip = "127.0.0.1"; NetworkComms.SendObject("Plugin", ip, 10000, desc.Type + "|False"); Thread.Sleep(2000); string exePath = Path.GetDirectoryName(Application.ExecutablePath); string pluginFolder = exePath + "/Plugins/" + desc.Path; if (Directory.Exists(pluginFolder)) { if (deleteFolder(pluginFolder)) returnValue = true; else returnValue = false; if (Directory.Exists(pluginFolder)) returnValue = false; } else returnValue = true; return returnValue; }
private void loadPlugins() { pluginList = new BindingList<PluginDescription>(); List<string> osapdFiles = new List<string>(); string[] pluginFile = Directory.GetFiles(Common.ApiPath + "\\Plugins", "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); bool bFoundObject = false; foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { bFoundObject = false; PluginDescription desc = new PluginDescription(); desc.Deserialize(path); desc.Status = "No Object"; desc.Enabled = false; this.Log.Info(desc.Type + ": Plugin DLL found, Desc ID = " + desc.ID); OSAEObjectCollection objs = OSAEObjectManager.GetObjectsByType(desc.Type); foreach (OSAEObject o in objs) { if (OSAEObjectPropertyManager.GetObjectPropertyValue(o.Name, "Computer Name").Value == Common.ComputerName || desc.Type == o.Name) { desc.Name = o.Name; bFoundObject = true; if (o.Enabled == 1) desc.Enabled = true; if (o.State.Value == "ON") desc.Status = "Running"; else if (o.State.Value == "OFF") desc.Status = "Stopped"; else desc.Status = o.State.Value; this.Log.Info(desc.Type + ": Plugin Object found, Object Name = " + o.Name); pluginList.Add(desc); } } // Here we try to create the Object if none was found above, we need a valid Object Type for this. if (bFoundObject == false) { this.Log.Info(desc.Type + ": Plugin Object Missing!"); bool bObjectTypeExists = OSAEObjectTypeManager.ObjectTypeExists(desc.Type); if (bObjectTypeExists) { this.Log.Info(desc.Type + ": Valid Object Type found. Attempting to create Object..."); OSAEObjectManager.ObjectAdd(desc.Type, desc.Type, desc.Type + " plugin's Object", desc.Type, "", "SYSTEM", false); OSAEObject obj = OSAEObjectManager.GetObjectByName(desc.Type); if (obj != null) { desc.Name = obj.Name; desc.Enabled = false; if (obj.State.Value == "ON") desc.Status = "Running"; else if (obj.State.Value == "OFF") desc.Status = "Stopped"; else desc.Status = obj.State.Value; this.Log.Info(desc.Type + ": Plugin Object now found!"); pluginList.Add(desc); } } else { this.Log.Info(desc.Type + ": NO Valid Object Type found! I cannot create an Object! Please run Install.sql for this plugin."); } } } } dgLocalPlugins.ItemsSource = pluginList; }
private void loadPlugins() { pluginList = new BindingList<PluginDescription>(); List<string> osapdFiles = new List<string>(); string[] pluginFile = Directory.GetFiles(Common.ApiPath + "\\Plugins", "*.osapd", SearchOption.AllDirectories); osapdFiles.AddRange(pluginFile); foreach (string path in osapdFiles) { if (!string.IsNullOrEmpty(path)) { PluginDescription desc = new PluginDescription(); desc.Deserialize(path); desc.Status = "Stopped"; desc.Enabled = false; OSAEObjectCollection objs = OSAEObjectManager.GetObjectsByType(desc.Type); foreach (OSAEObject o in objs) { if (OSAEObjectPropertyManager.GetObjectPropertyValue(o.Name, "Computer Name").Value == Common.ComputerName || desc.Type == o.Name) { desc.Name = o.Name; if (o.Enabled == 1) desc.Enabled = true; if (o.State.Value == "ON") desc.Status = "Running"; else if (o.State.Value == "OFF") desc.Status = "Stopped"; else desc.Status = o.State.Value; } } pluginList.Add(desc); this.Log.Info("Plugin found: Name:" + desc.Name + " Desc ID: " + desc.ID); } } dgLocalPlugins.ItemsSource = pluginList; }
public void PersistPluginTest() { var vers01 = new Version(0, 1); PluginStore target = new PluginStore(); #region persist single plugin without dependencies { string name = RandomName(); int oldCount = target.Plugins.Count(); PluginDescription pluginDescription = new PluginDescription(name, vers01); byte[] pluginPackage = enc.GetBytes("Zipped " + name); target.Persist(pluginDescription, pluginPackage); int newCount = target.Plugins.Count(); Assert.AreEqual(oldCount + 1, newCount); } #endregion #region persist a product with same name and version as an existent product { string name = RandomName(); int oldCount = target.Plugins.Count(); PluginDescription pluginDescription = new PluginDescription(name, vers01); byte[] pluginPackage = enc.GetBytes("Zipped " + name); target.Persist(pluginDescription, pluginPackage); int newCount = target.Plugins.Count(); Assert.AreEqual(oldCount + 1, newCount); // insert same name and version oldCount = target.Plugins.Count(); pluginDescription = new PluginDescription(name, vers01); pluginPackage = enc.GetBytes("Zipped " + name); target.Persist(pluginDescription, pluginPackage); newCount = target.Plugins.Count(); // make sure old entry was updated Assert.AreEqual(oldCount, newCount); // insert new with different version oldCount = target.Plugins.Count(); pluginDescription = new PluginDescription(name, new Version(0, 2)); pluginPackage = enc.GetBytes("Zipped " + name); target.Persist(pluginDescription, pluginPackage); newCount = target.Plugins.Count(); // make sure a new entry was created Assert.AreEqual(oldCount + 1, newCount); } #endregion #region persist a plugin with an already persisted dependency { string name = RandomName(); PluginDescription dependency = new PluginDescription(name, vers01); // insert dependency first target.Persist(dependency, enc.GetBytes("Zipped " + name)); // persist another plugin that has a dependency on the first plugin string name2 = RandomName(); int oldCount = target.Plugins.Count(); PluginDescription newEntity = new PluginDescription(name2, vers01, Enumerable.Repeat(dependency, 1)); byte[] newEntityPackage = enc.GetBytes("Zipped " + name2); target.Persist(newEntity, newEntityPackage); int newCount = target.Plugins.Count(); Assert.AreEqual(oldCount + 1, newCount); // only one new plugin should be added // retrieve second plugin and check dependencies newEntity = target.Plugins.Where(p => p.Name == name2).Single(); Assert.AreEqual(newEntity.Dependencies.Count(), 1); Assert.AreEqual(newEntity.Dependencies.First().Name, name); } #endregion #region try to persist a new plugin with a non-existant dependency and check the expected exception { // try to persist a new plugin with a non-existant dependency try { string pluginName = RandomName(); string dependencyName = RandomName(); var dependency = new PluginDescription(dependencyName, vers01); var newEntity = new PluginDescription(pluginName, vers01, Enumerable.Repeat(dependency, 1)); target.Persist(newEntity, enc.GetBytes("Zipped " + pluginName)); Assert.Fail("persist should fail with ArgumentException"); } catch (ArgumentException) { // this is expected Assert.IsTrue(true, "expected exception"); } } #endregion #region update the plugin file of an existing plugin { // insert new plugin string pluginName = RandomName(); var newPlugin = new PluginDescription(pluginName, vers01); target.Persist(newPlugin, enc.GetBytes("Zipped " + pluginName)); // update the plugin file byte[] expected = enc.GetBytes("Zipped2 " + pluginName); target.Persist(newPlugin, expected); // check if the updated file is returned byte[] actual = target.PluginFile(newPlugin); // check retrieved file Assert.AreEqual(expected.Length, actual.Length); for (int i = 0; i < expected.Length; i++) { Assert.AreEqual(expected[i], actual[i]); } } #endregion #region update the dependencies of an existing plugin { string dependency1Name = RandomName(); var newDependency1 = new PluginDescription(dependency1Name, vers01); target.Persist(newDependency1, enc.GetBytes("Zipped " + dependency1Name)); string pluginName = RandomName(); var newPlugin = new PluginDescription(pluginName, vers01, Enumerable.Repeat(newDependency1, 1)); target.Persist(newPlugin, enc.GetBytes("Zipped " + pluginName)); // retrieve plugin var dbPlugin = target.Plugins.Where(p => p.Name == pluginName).Single(); Assert.AreEqual(dbPlugin.Dependencies.Count(), 1); Assert.AreEqual(dbPlugin.Dependencies.First().Name, dependency1Name); // change dependencies string dependency2Name = RandomName(); var newDependency2 = new PluginDescription(dependency2Name, vers01); target.Persist(newDependency2, enc.GetBytes("Zipped " + pluginName)); newPlugin = new PluginDescription(pluginName, vers01, new PluginDescription[] { newDependency1, newDependency2 }); target.Persist(newPlugin, enc.GetBytes("Zipped " + pluginName)); // retrieve plugin dbPlugin = target.Plugins.Where(p => p.Name == pluginName).Single(); Assert.AreEqual(dbPlugin.Dependencies.Count(), 2); } #endregion #region try to insert a plugin that references the same dependency twice and check if the correct exception is thrown { string depName = RandomName(); var depPlugin = new PluginDescription(depName, vers01); target.Persist(depPlugin, enc.GetBytes("Zipped " + depName)); // insert new plugin string pluginName = RandomName(); var plugin = new PluginDescription(pluginName, vers01, new PluginDescription[] { depPlugin, depPlugin }); try { target.Persist(plugin, enc.GetBytes("Zipped " + depName)); Assert.Fail("Expected ArgumentException"); } catch (ArgumentException) { Assert.IsTrue(true, "Exception thrown as expected"); } } #endregion #region try to insert a plugin that with a cyclic reference { string depName = RandomName(); var depPlugin = new PluginDescription(depName, vers01); target.Persist(depPlugin, enc.GetBytes("Zipped " + depName)); // update the plugin so that it has a dependency on itself var plugin = new PluginDescription(depName, vers01, new PluginDescription[] { depPlugin }); try { target.Persist(plugin, enc.GetBytes("Zipped " + depName)); Assert.Fail("Expected ArgumentException"); } catch (ArgumentException) { Assert.IsTrue(true, "Exception thrown as expected"); } } #endregion }