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);
        }
Exemplo n.º 2
0
        public void EqualsReturnsFalseForDifferentOperationData()
        {
            PluginFilter left  = PluginFilter.Create.IsNamed("name");
            PluginFilter right = PluginFilter.Create.IsNamed("othername");

            Assert.IsFalse(left.Equals(right));
        }
Exemplo n.º 3
0
        public void EqualsReturnFalseForDifferentSubFilter()
        {
            PluginFilter left  = PluginFilter.Create.IsNamed("name").Implements("type");
            PluginFilter right = PluginFilter.Create.IsNamed("name").DerivesFrom("type");

            Assert.IsFalse(left.Equals(right));
        }
Exemplo n.º 4
0
        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);
        }
Exemplo n.º 5
0
        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());
        }
Exemplo n.º 6
0
        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);
        }
Exemplo n.º 7
0
        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);
        }
Exemplo n.º 8
0
        public void ConstructingDefault()
        {
            PluginFilter tested = new PluginFilter();

            Assert.AreEqual((PluginFilter.FilterOperation) 0, tested.Operation);
            Assert.IsNull(tested.OperationData);
            Assert.IsNull(tested.SubFilters);
        }
Exemplo n.º 9
0
        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());
        }
Exemplo n.º 10
0
        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());
        }
Exemplo n.º 11
0
        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());
        }
Exemplo n.º 12
0
        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())));
        }
Exemplo n.º 13
0
        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());
        }
Exemplo n.º 14
0
        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());
        }
Exemplo n.º 15
0
        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));
        }
Exemplo n.º 16
0
        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));
        }
Exemplo n.º 17
0
        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));
        }
Exemplo n.º 18
0
        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));
        }
Exemplo n.º 19
0
        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));
        }
Exemplo n.º 20
0
        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));
        }
Exemplo n.º 21
0
        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));
        }
Exemplo n.º 22
0
        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]);
        }
Exemplo n.º 23
0
		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);
		}
Exemplo n.º 24
0
        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());
            }
        }
Exemplo n.º 25
0
        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));
        }
Exemplo n.º 26
0
 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);
                }
            }
        }
Exemplo n.º 28
0
 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");
 }
Exemplo n.º 29
0
        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;
        }
Exemplo n.º 31
0
        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());
              }
        }
Exemplo n.º 34
0
 public IEnumerable<PluginDescriptor> Plugins(PluginFilter filter = null)
 {
     log.DebugFormat("Processing request find plugins: {0}", filter);
       return this.pluginRepository.Plugins(filter);
 }
Exemplo n.º 35
0
 /// <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;
 }
Exemplo n.º 36
0
 public IEnumerable <PluginDescriptor> Plugins(PluginFilter filter = null)
 {
     log.DebugFormat("Processing request find plugins: {0}", filter);
     return(this.pluginRepository.Plugins(filter));
 }