public List <PluginDetails> SearchPlugins(List <PluginDetails> pluginsList, PluginFilter filter) { if (pluginsList is null) { pluginsList = new List <PluginDetails>(); } var searchedPluginList = new List <PluginDetails>(pluginsList); if (!string.IsNullOrEmpty(filter?.Query)) { searchedPluginList = FilterByQuery(searchedPluginList, filter.Query); } if (!string.IsNullOrEmpty(filter?.Price)) { searchedPluginList = FilterByPrice(searchedPluginList, filter.Price); } if (!string.IsNullOrEmpty(filter?.StudioVersion)) { searchedPluginList = FilterByVersion(searchedPluginList, filter.StudioVersion); } if (filter?.CategoryId?.Count > 0) { searchedPluginList = FilterByCategory(searchedPluginList, filter.CategoryId); } searchedPluginList = ApplySort(searchedPluginList, filter.SortBy); return(searchedPluginList); }
public void EqualsReturnsFalseForDifferentOperationData() { PluginFilter left = PluginFilter.Create.IsNamed("name"); PluginFilter right = PluginFilter.Create.IsNamed("othername"); Assert.IsFalse(left.Equals(right)); }
public void EqualsReturnFalseForDifferentSubFilter() { PluginFilter left = PluginFilter.Create.IsNamed("name").Implements("type"); PluginFilter right = PluginFilter.Create.IsNamed("name").DerivesFrom("type"); Assert.IsFalse(left.Equals(right)); }
public IEnumerable <PluginDescriptor> Plugins(PluginFilter filter) { this.log.DebugFormat("Finding plugins statisfying {0}", filter); FindPlugin cmd = new FindPlugin() { Filter = filter }; PluginDescriptor[] foundPlugins = new PluginDescriptor[0]; this.bus.PublishRequest(cmd, cb => { // cb.SetRequestExpiration(TimeSpan.FromSeconds(10)); <--- Bug that causes exception on RabbitMq (fixed in trunk but not on NuGet) cb.HandleTimeout(TimeSpan.FromSeconds(10), msg => { this.log.WarnFormat("Timeout requesting {0}", filter); }); cb.Handle <FindPluginResponse>((context, message) => { foundPlugins = message.FoundPlugins; this.log.DebugFormat("Found {0} plugins for {1}", foundPlugins.Length, filter); }); }); return(foundPlugins); }
public void ShouldOnlyReportPluginsThatMatchesFilter() { PluginRepository tested = new PluginRepository(); MockPluginSource pluginSource = new MockPluginSource(); tested.AddPluginSource(pluginSource); PluginDescriptor plugin1 = new PluginDescriptor() { QualifiedName = typeof(MockPlugin1), Name = "plugin1" }; PluginDescriptor plugin2 = new PluginDescriptor() { QualifiedName = typeof(MockPlugin2), Name = "plugin2" }; pluginSource.RaisePluginAdded(plugin1); pluginSource.RaisePluginAdded(plugin2); PluginFilter filter = PluginFilter.Create.IsNamed("plugin1"); var foundPlugins = tested.Plugins(filter); Assert.AreEqual(1, foundPlugins.Count()); Assert.AreSame(plugin1, foundPlugins.First()); }
private void QueryAndRunPlugins() { Console.WriteLine("Creating AppDomain PluginDomain"); AppDomain pluginDomain = AppDomain.CreateDomain("PluginDomain"); pluginDomain.AssemblyLoad += (s, e) => Console.WriteLine("{0} loaded {1}", AppDomain.CurrentDomain.FriendlyName, e.LoadedAssembly.FullName); IPluginCreator pluginCreator = PluginCreator.GetCreator(pluginDomain); try { ITestPlugin plugin; Dictionary <string, object> settings = new Dictionary <string, object>(); settings.Add("Name", "SettingName"); PluginFilter filter = PluginFilter.Create.Implements(typeof(ITestPlugin)).HasMinVersion("1.0"); Console.WriteLine("Querying for plugins satisfying {0}", filter); PluginDescriptor[] foundPlugins = this.pluginRepository.Plugins(filter).ToArray(); Console.WriteLine(string.Format("{0} plugins found", foundPlugins.Length)); foreach (var pluginDescriptor in foundPlugins) { Console.WriteLine(string.Format("Creating plugin {0} inside {1}", pluginDescriptor.QualifiedName.TypeFullName, pluginDomain.FriendlyName)); plugin = pluginCreator.Create(pluginDescriptor, this.assemblyRepository, settings) as ITestPlugin; Console.WriteLine("Say hello plugin..."); plugin.SayHello(); } } catch (Exception ex) { Console.WriteLine(ex); } Console.WriteLine("Unloading {0}", pluginDomain.FriendlyName); AppDomain.Unload(pluginDomain); }
public void CombineShouldReturnLeftIfRightIsPassthrough() { var passthrough = PluginFilter.Create; var expected = PluginFilter.Create.IsNamed("something"); var actual = PluginFilter.Combine(PluginFilter.FilterOperation.And, expected, passthrough); Assert.AreSame(expected, actual); }
public void ConstructingDefault() { PluginFilter tested = new PluginFilter(); Assert.AreEqual((PluginFilter.FilterOperation) 0, tested.Operation); Assert.IsNull(tested.OperationData); Assert.IsNull(tested.SubFilters); }
public void FilterShouldApplyHasInfoValue() { PluginFilter tested = PluginFilter.Create.HasInfoValue("validkey", "validvalue"); PluginDescriptor[] filtered = tested.Filter(this.descriptors).ToArray(); Assert.AreEqual(1, filtered.Length); Assert.AreSame(this.plugin1, filtered.First()); }
public void FilterShouldApplyIsNamed() { PluginFilter tested = PluginFilter.Create.IsNamed("MockPlugin1"); PluginDescriptor[] filtered = tested.Filter(this.descriptors).ToArray(); Assert.AreEqual(1, filtered.Length); Assert.AreSame(this.plugin1, filtered.First()); }
public void FilterShouldApplyDerivesFrom() { PluginFilter tested = PluginFilter.Create.DerivesFrom(typeof(MockPluginBase)); PluginDescriptor[] filtered = tested.Filter(this.descriptors).ToArray(); Assert.AreEqual(1, filtered.Length); Assert.AreSame(this.plugin1, filtered.First()); }
public void ShouldLogToDebugOnPluginQuery() { PluginRepository tested = new PluginRepository(); MockLog log = new MockLog(tested); PluginFilter filter = PluginFilter.Create.IsNamed("plugin name").Implements(typeof(IMockPluginInterface1)); tested.Plugins(filter); Assert.IsTrue(log.Any(x => x.Level == MockLog.Level.Debug && x.Message.Contains("Returning plugins for") && x.Message.Contains(filter.ToString()))); }
public void ToStringOrOperatorExpectedValue() { var sub1 = PluginFilter.Create.IsNamed("sub1"); var sub2 = PluginFilter.Create.IsNamed("sub2"); string expected = "(" + sub1.ToString() + " | " + sub2.ToString() + ")"; PluginFilter tested = sub1.Or(sub2); Assert.AreEqual(expected, tested.ToString()); }
public void FilterShouldApplyAndOperation() { PluginFilter tested = PluginFilter.Create.HasMaxVersion("55.66").And(PluginFilter.Create.HasMinVersion("55.66")); PluginDescriptor[] filtered = tested.Filter(this.descriptors).ToArray(); Assert.AreEqual(1, filtered.Length); Assert.AreSame(plugin1, filtered.First()); }
public void FilterShouldApplyImplements() { PluginFilter tested = PluginFilter.Create.Implements(typeof(IMockPluginInterface1)); PluginDescriptor[] filtered = tested.Filter(this.descriptors).ToArray(); Assert.AreEqual(2, filtered.Length); Assert.IsTrue(filtered.Contains(plugin1)); Assert.IsTrue(filtered.Contains(plugin3)); }
public void FilterShouldApplyHasMaxVersion() { PluginFilter tested = PluginFilter.Create.HasMaxVersion("55.66"); PluginDescriptor[] filtered = tested.Filter(this.descriptors).ToArray(); Assert.AreEqual(2, filtered.Length); Assert.IsTrue(filtered.Contains(plugin1)); Assert.IsTrue(filtered.Contains(plugin2)); }
public void HasInfoShouldAndCombineWithNewIsTypeOfFilter() { var name = "name"; PluginFilter original = PluginFilter.Create.IsNamed("original"); PluginFilter tested = original.HasInfo(name); Assert.AreEqual(PluginFilter.FilterOperation.And, tested.Operation); Assert.AreEqual(2, tested.SubFilters.Length); Assert.IsTrue(tested.SubFilters.Contains(original)); Assert.IsTrue(tested.SubFilters.Any(x => x.Operation == PluginFilter.FilterOperation.HasInfo && x.OperationData == name)); }
public void DerivesFromShouldAndCombineWithNewIsTypeOfFilter() { PluginFilter original = PluginFilter.Create.IsNamed("original"); Type type = typeof(UnitTest_PluginFilter); PluginFilter tested = original.DerivesFrom(type); Assert.AreEqual(PluginFilter.FilterOperation.And, tested.Operation); Assert.AreEqual(2, tested.SubFilters.Length); Assert.IsTrue(tested.SubFilters.Contains(original)); Assert.IsTrue(tested.SubFilters.Any(x => x.Operation == PluginFilter.FilterOperation.DerivesFrom && x.OperationData == type.AssemblyQualifiedName)); }
public void HasMaxVersionShouldAndCombineWithNewIsTypeOfFilter() { var version = "1.0"; PluginFilter original = PluginFilter.Create.IsNamed("original"); PluginFilter tested = original.HasMaxVersion(version); Assert.AreEqual(PluginFilter.FilterOperation.And, tested.Operation); Assert.AreEqual(2, tested.SubFilters.Length); Assert.IsTrue(tested.SubFilters.Contains(original)); Assert.IsTrue(tested.SubFilters.Any(y => y.Operation == PluginFilter.FilterOperation.MaxVersion && y.OperationData == version)); }
public void OrCreatesOrOperatorWithSubFilters() { PluginFilter original = PluginFilter.Create.IsNamed("original"); PluginFilter added = PluginFilter.Create.HasInfo("added"); PluginFilter tested = original.Or(added); Assert.AreEqual(PluginFilter.FilterOperation.Or, tested.Operation); Assert.IsNull(tested.OperationData); Assert.AreEqual(2, tested.SubFilters.Length); Assert.IsTrue(tested.SubFilters.Contains(original)); Assert.IsTrue(tested.SubFilters.Contains(added)); }
public void HasInfoValueShouldAndCombineWithNewIsTypeOfFilter() { var key = "key"; var value = "value"; PluginFilter original = PluginFilter.Create.IsNamed("original"); PluginFilter tested = original.HasInfoValue(key, value); Assert.AreEqual(PluginFilter.FilterOperation.And, tested.Operation); Assert.AreEqual(2, tested.SubFilters.Length); Assert.IsTrue(tested.SubFilters.Contains(original)); Assert.IsTrue(tested.SubFilters.Any(x => x.Operation == PluginFilter.FilterOperation.InfoValue && x.OperationData == key + "=" + value)); }
public void CombineBecomesSubFilters() { var left = PluginFilter.Create.IsNamed("left"); var right = PluginFilter.Create.IsNamed("right"); PluginFilter tested = PluginFilter.Combine(PluginFilter.FilterOperation.And, left, right); Assert.AreEqual(PluginFilter.FilterOperation.And, tested.Operation); Assert.IsNull(tested.OperationData); Assert.IsNotNull(tested.SubFilters); Assert.AreEqual(2, tested.SubFilters.Length); Assert.AreSame(left, tested.SubFilters[0]); Assert.AreSame(right, tested.SubFilters[1]); }
public async Task<IActionResult> Get([FromQuery]PluginFilter filter) { List<PluginDetails> pluginsList; string sortOrder = string.IsNullOrEmpty(filter?.SortOrder) ? "asc" : filter.SortOrder; pluginsList = await PluginRepository.GetAll(sortOrder); if (!string.IsNullOrEmpty(filter.Price) || !string.IsNullOrEmpty(filter.Query) || !string.IsNullOrEmpty(filter.StudioVersion) || !string.IsNullOrEmpty(filter.SortOrder)) { var plugins = PluginRepository.SearchPlugins(pluginsList,filter); return Ok(plugins); } return Ok(pluginsList); }
public void ToStringUnaryOperatorExpectedValue() { PluginFilter.FilterOperation[] binaryOperators = new PluginFilter.FilterOperation[] { PluginFilter.FilterOperation.And, PluginFilter.FilterOperation.Or, }; var unaryOperators = Enum.GetValues(typeof(PluginFilter.FilterOperation)).OfType <PluginFilter.FilterOperation>().Except(binaryOperators); foreach (var op in unaryOperators) { PluginFilter tested = new PluginFilter(op, "opdata", null); Assert.AreEqual(op.ToString() + "(opdata)", tested.ToString()); } }
public void CombineShouldMergeIfLeftIsSameOperator() { var op = PluginFilter.FilterOperation.Or; PluginFilter left1 = PluginFilter.Create.IsNamed("left1"); PluginFilter right1 = PluginFilter.Create.IsNamed("right1"); PluginFilter combined1 = PluginFilter.Combine(op, left1, right1); PluginFilter right2 = PluginFilter.Create.IsNamed("right2"); PluginFilter tested = PluginFilter.Combine(op, combined1, right2); Assert.AreEqual(op, tested.Operation); Assert.AreEqual(3, tested.SubFilters.Length); Assert.IsTrue(tested.SubFilters.Contains(left1)); Assert.IsTrue(tested.SubFilters.Contains(right1)); Assert.IsTrue(tested.SubFilters.Contains(right2)); }
public IEnumerable<PluginDescriptor> Plugins(PluginFilter filter = null) { for (int i = 0; i < 30; i++) try { this.log.DebugFormat("Finding plugins statisfying {0}", filter); var foundPlugins = this.Service.Plugins(filter); this.log.DebugFormat("Found {0} plugins for {1}", foundPlugins.Count(), filter); return foundPlugins; } catch (EndpointNotFoundException) { this.log.Debug("Endpoint not found, retrying in 1 second"); System.Threading.Thread.Sleep(1000); } throw new PluginException("Endpoint not found WcfHost"); }
public async Task OnGetAsync() { PrivatePlugins = new List <PrivatePlugin>(); var pluginFiler = new PluginFilter { SortOrder = "asc" }; var privatePluginsResult = await _pluginsController.Get(pluginFiler); if (privatePluginsResult is OkObjectResult resultObject && resultObject.StatusCode == 200) { if (resultObject.Value is List <PluginDetails> privatePlugins) { InitializePrivatePlugins(privatePlugins); } } }
public IEnumerable <PluginDescriptor> Plugins(PluginFilter filter = null) { for (int i = 0; i < 30; i++) { try { this.log.DebugFormat("Finding plugins statisfying {0}", filter); var foundPlugins = this.Service.Plugins(filter); this.log.DebugFormat("Found {0} plugins for {1}", foundPlugins.Count(), filter); return(foundPlugins); } catch (EndpointNotFoundException) { this.log.Debug("Endpoint not found, retrying in 1 second"); System.Threading.Thread.Sleep(1000); } } throw new PluginException("Endpoint not found WcfHost"); }
public void CanSerializeDeserialize() { PluginFilter toSerialize = PluginFilter.Create.IsNamed("some name").Implements(typeof(string)).Or(PluginFilter.Create.DerivesFrom(typeof(int)).IsNamed("a name").HasVersion("1.0")); var knownTypes = new Type[] { typeof(PluginFilter.FilterOperation), typeof(PluginFilter[]) }; PluginFilter deserialized; using (var memstream = new MemoryStream()) { XmlTextWriter writer = new XmlTextWriter(memstream, Encoding.UTF8); var serializer = new DataContractSerializer(toSerialize.GetType(), knownTypes); serializer.WriteObject(writer, toSerialize); writer.Flush(); memstream.Seek(0, SeekOrigin.Begin); XmlTextReader reader = new XmlTextReader(memstream); deserialized = serializer.ReadObject(reader) as PluginFilter; } Assert.IsTrue(deserialized.Equals(toSerialize)); }
public IEnumerable<PluginDescriptor> Plugins(PluginFilter filter) { this.log.DebugFormat("Finding plugins statisfying {0}", filter); FindPlugin cmd = new FindPlugin() { Filter = filter }; PluginDescriptor[] foundPlugins = new PluginDescriptor[0]; this.bus.PublishRequest(cmd, cb => { // cb.SetRequestExpiration(TimeSpan.FromSeconds(10)); <--- Bug that causes exception on RabbitMq (fixed in trunk but not on NuGet) cb.HandleTimeout(TimeSpan.FromSeconds(10), msg => { this.log.WarnFormat("Timeout requesting {0}", filter); }); cb.Handle<FindPluginResponse>((context, message) => { foundPlugins = message.FoundPlugins; this.log.DebugFormat("Found {0} plugins for {1}", foundPlugins.Length, filter); }); }); return foundPlugins; }
public void CombineOnlyAcceptBooleanOperators() { PluginFilter.FilterOperation[] valid = new PluginFilter.FilterOperation[] { PluginFilter.FilterOperation.And, PluginFilter.FilterOperation.Or, }; var invalid = Enum.GetValues(typeof(PluginFilter.FilterOperation)).OfType <PluginFilter.FilterOperation>().Except(valid); var left = PluginFilter.Create.IsNamed("left"); var right = PluginFilter.Create.IsNamed("right"); foreach (var value in invalid) { try { PluginFilter.Combine(value, left, right); Assert.Fail(); } catch (ArgumentException) { } } }
public void ConstructingDefault() { PluginFilter tested = new PluginFilter(); Assert.AreEqual((PluginFilter.FilterOperation)0, tested.Operation); Assert.IsNull(tested.OperationData); Assert.IsNull(tested.SubFilters); }
public void ToStringUnaryOperatorExpectedValue() { PluginFilter.FilterOperation[] binaryOperators = new PluginFilter.FilterOperation[] { PluginFilter.FilterOperation.And, PluginFilter.FilterOperation.Or, }; var unaryOperators = Enum.GetValues(typeof(PluginFilter.FilterOperation)).OfType<PluginFilter.FilterOperation>().Except(binaryOperators); foreach (var op in unaryOperators) { PluginFilter tested = new PluginFilter(op, "opdata", null); Assert.AreEqual(op.ToString() + "(opdata)", tested.ToString()); } }
public IEnumerable<PluginDescriptor> Plugins(PluginFilter filter = null) { log.DebugFormat("Processing request find plugins: {0}", filter); return this.pluginRepository.Plugins(filter); }
/// <summary> /// Method for querying for plugins that satisfies a supplied filter /// </summary> /// <param name="filter">The requirements that plugins must fulfill to be returned. If no filter is provided then all known plugins is returned.</param> /// <returns> /// Enumerable of plugins that fulfills the requirements /// </returns> public IEnumerable<PluginDescriptor> Plugins(PluginFilter filter) { this.log.Debug(Resources.ReturningPluginsFor, filter); return filter != null ? filter.Filter(this.plugins) : this.plugins; }
public IEnumerable <PluginDescriptor> Plugins(PluginFilter filter = null) { log.DebugFormat("Processing request find plugins: {0}", filter); return(this.pluginRepository.Plugins(filter)); }