public void Setup() { PluginStore.AddPlugin(oneInput); PipelineState.InputDirectory = InputDir; PipelineState.OutputDirectory = OutputDir; }
public List <LoopPair> FindLoops() { List <int> done = new List <int>(); DependentNode[] nodes = dependencyGraph.Values.ToArray(); //sanity check for existing loops bool loopEnds = false; foreach (DependentNode node in nodes) { if (node.Type == LoopEnd.TypeName) { loopEnds = true; break; } } if (!loopEnds) { return(new List <LoopPair>()); } //find end points for (int i = nodes.Length - 1; i >= 0; i--) { DependentNode node = nodes[i]; if (PluginStore.isOutputPlugin(node.Type)) { FindLoopEnd(node, ref done); } } return(loopPairs); }
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 }
public void InsertProductPerformanceTest() { int nProducts = 50; int avgProductPlugins = 30; var store = new PluginStore(); Version vers01 = new Version(0, 1); Stopwatch stopWatch = new Stopwatch(); Random r = new Random(); var plugins = store.Plugins.ToList(); stopWatch.Start(); // create products for (int i = 0; i < nProducts; i++) { string name = RandomName(); List <PluginDescription> prodPlugins = new List <PluginDescription>(); for (int j = 0; j < avgProductPlugins; j++) { var selectedPlugin = plugins[r.Next(0, plugins.Count)]; if (!prodPlugins.Contains(selectedPlugin)) { prodPlugins.Add(selectedPlugin); } } var prod = new ProductDescription(name, vers01, prodPlugins); store.Persist(prod); } stopWatch.Stop(); Assert.Inconclusive("Created " + nProducts + " products in " + stopWatch.ElapsedMilliseconds + " ms (" + (double)stopWatch.ElapsedMilliseconds / nProducts + " ms / product )"); }
/// <summary> /// Removes the registration of a plugin host class /// </summary> public static void UnRegisterHost(PluginHosts hostType, Type pluginClass) { ArrayList pluginsList; if (_pluginsClassType.TryGetValue(hostType, out pluginsList)) { // remove from registered list pluginsList.Remove(pluginClass); } // remove from loaded list Dictionary <PluginHosts, List <PluginStore> > loadedList = LoadedPluginsList; List <PluginStore> plugins; if (loadedList != null && loadedList.TryGetValue(hostType, out plugins)) { for (int i = 0; i < plugins.Count; i++) { PluginStore plugin = plugins[i]; if (plugin.ClassType == pluginClass) { plugins.RemoveAt(i); break; } } } }
public void Setup() { PluginStore.AddPlugin(inputPlugin); PluginStore.AddPlugin(inputPlugin2); PluginStore.AddPlugin(EarlyEnd); PluginStore.AddPlugin(LateEnd); PluginStore.AddPlugin(LateData); PluginStore.AddPlugin(EarlyData); PluginStore.AddPlugin(ErrorPlugin); }
static void Main(string[] args) { PluginStore.Init(); Console.WriteLine("Starting Listener"); AsyncServer.StartListening(); while (AsyncServer.IsListening) { Thread.Sleep(1000); } }
/// <summary> /// Calls specified method of all specified hosts. /// </summary> internal static void CallPluginMethod(PluginHosts hostType, Enum methodNameEnum, params object[] arguments) { // Gets the available plugins list List <PluginStore> plugins = GetPluginsInstances(hostType); if (plugins != null && plugins.Count > 0) { // method name as enum string methodName = methodNameEnum.ToString(); for (int i = 0; i < plugins.Count; i++) { PluginStore pluginStore = plugins[i]; try { // getting requested method info using reflection MethodInfo info = pluginStore.ClassType .GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public); // call plugin with specifed arguments info.Invoke(pluginStore.Instance, arguments); } catch (EPluginStopRequest) { // The plugin requested to stop the process throw; } catch (Exception ex) { // the plugin requested to stop any operation if (ex.InnerException is EPluginStopRequest) { throw; } if (Systems.LogSystem.ErrorLogEnabled) { Systems.LogSystem.LogError(ex, "Plugin method failed. IPluginEngine Plugin=" + plugins[i].ClassType + " MethodName=" + methodName, string.Empty); } } } } }
private static InputData[] FindStartLocations() { List <InputData> inputNodes = new List <InputData>(); foreach (KeyValuePair <int, DependentNode> node in dependencyGraph) { if (!PluginStore.isRegisteredPlugin(node.Value.Type)) { throw new MissingPluginException(node.Value.Type + " could not be found"); } if (node.Value.Dependencies.Length == 0 && PluginStore.isInputPlugin(node.Value.Type)) { inputNodes.Add(new InputData(node.Key, PluginStore.getInputPlugin(dependencyGraph[node.Key].Type))); } } return(inputNodes.ToArray()); }
/// <summary> /// Start processing the active graph /// </summary> public static void Start() { if (inputs.Length == 0) { Console.WriteLine("No start locations could be found"); return; } else { Console.WriteLine("Starting Execution Preparation"); } Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); //gather static data foreach (KeyValuePair <int, DependentNode> pair in dependencyGraph) { if (PluginStore.isGeneratorPlugin(pair.Value.Type)) { IGeneratorPlugin plugin = PluginStore.getPlugin(pair.Value.Type) as IGeneratorPlugin; staticData.StoreResults(plugin.StaticData(pair.Value.Value), pair.Key, true); } } PipelineExecutor[] pipes = BuildPipelines(); stopwatch.Stop(); Console.WriteLine("Preparation duration: " + stopwatch.Elapsed + " ms"); //start the first wave of dependencies Console.WriteLine("Starting Processing"); Console.WriteLine(""); for (int p = 0; p < pipes.Length; p++) { for (int i = 0; i < inputs.Length; i++) { pipes[p].TriggerDependencies(inputs[i].nodeId); } } }
public void Finalize(ComputerStateType state = ComputerStateType.Shutdown) { if (IsDisposed) { return; } Logger.Info($"{new string('=', 64)}"); Logger.Info("Finalizing..."); _timerManager?.Dispose(); if (_deviceManager != null) { ApplyComputerStateProfile(state); } _sensorManager?.Dispose(); _deviceManager?.Dispose(); _configManager?.Dispose(); _pluginStore.Dispose(); _cache?.Clear(); _timerManager = null; _sensorManager = null; _deviceManager = null; _configManager = null; _pluginStore = null; _cache = null; Dispose(); IsDisposed = true; Logger.Info("Finalizing done!"); Logger.Info($"{new string('=', 64)}"); }
/// <summary> /// Searches for sync blocks in the graph and initializes them in preparation for execution /// </summary> /// <param name="dependencyGraph">graph representation of the pipeline</param> /// <param name="staticData">data object used by all pipelines for initialization of sync blocks</param> /// <returns>array of initialized sync blocks</returns> private static SyncNode[] PrepareSyncBlocks(Dictionary <int, DependentNode> dependencyGraph, DataStore staticData) { List <SyncNode> syncBlocks = new List <SyncNode>(); foreach (DependentNode node in dependencyGraph.Values) { if (node.Type == SyncNode.TypeName) { //check if the node is connected to a generator foreach (NodeSlot dependencies in node.Dependencies) { if (PluginStore.isGeneratorPlugin(dependencyGraph[dependencies.NodeId].Type)) { throw new InvalidConnectionException("Generators don't need to be synced as they are inherently consistent"); } } syncBlocks.Add(new SyncNode(node, staticData)); } } return(syncBlocks.ToArray()); }
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> /// Adds an assembly to the store /// </summary> /// <param name="buffer">byte[] of the assembly</param> /// <param name="state">Signed or unsigned</param> /// <param name="pluginStore">Global or Custom Store</param> public void AddPlugin(byte[] buffer, AssemblySigningRequirement state, PluginStore pluginStore) { try { Assembly asm = Assembly.ReflectionOnlyLoad(buffer); AssemblyName asmName = new AssemblyName(asm.FullName); string publicKeyToken = GetPublicToken(asm); if ((state == AssemblySigningRequirement.StoreSignedAssemblies) && (publicKeyToken == string.Empty)) { throw new AssemblyNotSignedException(); } string pluginStoreDirectory = GetPluginDirectory(asmName, publicKeyToken, pluginStore); if (!Directory.Exists(pluginStoreDirectory)) { Directory.CreateDirectory(pluginStoreDirectory); } WriteFile(buffer, pluginStoreDirectory, asmName); } catch (AssemblyNotSignedException ex) { if (OnExceptionOccured != null) { OnExceptionOccured(this, new PluginManagerEventArgs(ex)); } } catch { if (OnExceptionOccured != null) { OnExceptionOccured(this, new PluginManagerEventArgs(new StoreAddingException())); } } }
/// <summary> /// Queues nodes for execution /// </summary> /// <param name="nodes">node ids that will be triggered</param> /// <param name="triggeredBy">node that triggered the execution</param> private void StartNodes(int[] nodes, int triggeredBy) { foreach (int id in nodes) { string name = dependencyGraph[id].Type; //check if the node is a special type if (PluginStore.isInternalPlugin(name)) { InternalPluginAction(id, triggeredBy); continue; } TaskRunner pluginTask = new TaskRunner(PluginStore.getPlugin(name), dependencyGraph[id], data, staticData, this, depth); Task task = pluginTask.getTask(); if (task == null) { continue; } task.Start(PipelineState.Scheduler); } }
public string Response(HttpListenerRequest request) { return(JsonConvert.SerializeObject(PluginStore.AvailableNodes())); }
public void Clear() { PluginStore.ClearAll(); }
public bool Initialize() { Logger.Info($"{new string('=', 64)}"); Logger.Info("Initializing service, version \"{0}\"", FileVersionInfo.GetVersionInfo(Assembly.GetCallingAssembly().Location)?.ProductVersion); PluginLoader.LoadAll(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins")); var serializationContext = new TrackingSerializationContext(); serializationContext.Track(typeof(IPlugin)); serializationContext.Track(typeof(Identifier)); _configManager = new ConfigManager("config.json", serializationContext); if (!_configManager.LoadOrCreateConfig()) { return(false); } _config = _configManager.CurrentConfig; _cache = new DataCache(); _pluginStore = new PluginStore(serializationContext.Get <IPlugin>()); _sensorManager = new SensorManager(_config); _deviceManager = new DeviceManager(); _sensorManager.EnableSensors(_config.SensorConfigs.SelectMany(x => x.Sensors)); foreach (var profile in _config.Profiles) { Logger.Info("Processing profile \"{0}\"", profile.Name); if (_pluginStore.Get(profile).Any()) { Logger.Fatal("Duplicate profile \"{0}\" found!", profile.Name); return(false); } foreach (var effect in profile.Effects) { _pluginStore.Assign(effect, profile); } foreach (var speedController in profile.SpeedControllers) { _pluginStore.Assign(speedController, profile); } foreach (var port in profile.Ports) { _cache.StorePortConfig(port, PortConfig.Default); _cache.StoreDeviceConfig(port, DeviceConfig.Default); if (!_deviceManager.Controllers.SelectMany(c => c.Ports).Contains(port)) { Logger.Warn("Could not find matching controller for port {0}!", port); } } } _sensorManager.EnableSensors(serializationContext.Get <Identifier>()); foreach (var sensor in _sensorManager.EnabledSensors) { _cache.StoreSensorConfig(sensor, SensorConfig.Default); } foreach (var controller in _deviceManager.Controllers) { foreach (var port in controller.Ports) { _cache.StorePortConfig(port, PortConfig.Default); _cache.StoreDeviceConfig(port, DeviceConfig.Default); } } _configManager.Accept(_cache.AsWriteOnly()); if (_config.IpcServerEnabled && _config.IpcServer != null) { _ipcClient = new ServiceIpcClient(); _pluginStore.Add(_ipcClient); _config.IpcServer.RegisterClient(_ipcClient); foreach (var plugin in serializationContext.Get <IIpcClient>()) { _config.IpcServer.RegisterClient(plugin); } _config.IpcServer.Start(); } ApplyComputerStateProfile(ComputerStateType.Boot); _timerManager = new TimerManager(); _timerManager.RegisterTimer(_config.SensorTimerInterval, SensorTimerCallback); _timerManager.RegisterTimer(_config.DeviceSpeedTimerInterval, DeviceSpeedTimerCallback); _timerManager.RegisterTimer(_config.DeviceRgbTimerInterval, DeviceRgbTimerCallback); if (_config.IpcClientTimerInterval > 0) { _timerManager.RegisterTimer(_config.IpcClientTimerInterval, IpcClientTimerCallback); } if (LogManager.Configuration.LoggingRules.Any(r => r.IsLoggingEnabledForLevel(LogLevel.Debug))) { _timerManager.RegisterTimer(_config.DebugTimerInterval, DebugTimerCallback); } _timerManager.Start(); Logger.Info("Initializing done!"); Logger.Info($"{new string('=', 64)}"); return(true); }
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 }
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 }
public void Setup() { PluginStore.ClearAll(); PluginStore.AddPlugin(inputPlugin); PluginStore.Init(); }
/// <summary> /// Builds pipelines for data processing, will perform segregation of nodes to minimize node processing duplication /// </summary> /// <returns>prepared pipelines</returns> private static PipelineExecutor[] BuildPipelines() { if (specialNodes.SyncInformation.SyncNodes.Length == 0) { return(BuildLinearPipeline()); } //Build Pipelines with sync pipeline segregation int[] inputNodeIds = new int[inputs.Length]; for (var i = 0; i < inputs.Length; i++) { inputNodeIds[i] = inputs[i].nodeId; } Dictionary <int, InputData[]> groupInputLookup = new Dictionary <int, InputData[]>(); Dictionary <int, SyncSplitGroup> nodeToGroup = new Dictionary <int, SyncSplitGroup>(); //find groups which have input nodes foreach (SyncSplitGroup group in specialNodes.SyncInformation.NodeGroups) { List <InputData> inputs = new List <InputData>(); foreach (int nodeId in group.ControllingNodes) { if (inputNodeIds.Contains(nodeId)) { IInputPlugin plugin = PluginStore.getInputPlugin(dependencyGraph[nodeId].Type); if (!group.Input) { // Gather initial quantity requirements group.Input = true; group.RequiredPipes = plugin.InputDataQuantity(NodeValueOrInput(nodeId)); } else if (group.RequiredPipes != plugin.InputDataQuantity(NodeValueOrInput(nodeId))) { throw new InputPluginQuantityMismatchException(); } inputs.Add(new InputData(nodeId, plugin)); } nodeToGroup.Add(nodeId, group); } groupInputLookup.Add(group.SyncNodeId, inputs.ToArray()); } //check group dependencies are valid foreach (SyncSplitGroup group in specialNodes.SyncInformation.NodeGroups) { if (group.SyncNodeId == -1) { continue; //nodes outside of sync blocks } foreach (int dependent in group.Dependents) { SyncSplitGroup otherGroup = nodeToGroup[dependent]; if (otherGroup.Input) { throw new PipelineException("Co-dependent sync nodes with inputs are not supported"); } if (group.linked == null) { otherGroup.linked = group; } else { throw new PipelineException("Multi-Sync segmentation is not supported"); } } } //create new pipelines bool postBuildLinkRequired = false; List <PipelineExecutor> executors = new List <PipelineExecutor>(); foreach (SyncSplitGroup group in specialNodes.SyncInformation.NodeGroups) { if (group.linked != null) { group.RequiredPipes = group.linked.RequiredPipes; } else if (group.linked == null && !group.Input) { group.RequiredPipes = 1; } //Prepare pipelines if (group.linked == null) { group.pipes = new PipelineExecutor[group.RequiredPipes]; for (int i = 0; i < group.RequiredPipes; i++) { group.pipes[i] = new PipelineExecutor(dependencyGraph, staticData, i, specialNodes, InputDirectory, OutputDirectory); } } else { postBuildLinkRequired = true; } if (group.Input) { PrepareInputData(groupInputLookup[group.SyncNodeId], group.pipes); } if (group.pipes != null) { executors.AddRange(group.pipes); } } if (postBuildLinkRequired) { foreach (SyncSplitGroup group in specialNodes.SyncInformation.NodeGroups) { if (group.linked != null && group.pipes == null) { group.pipes = group.linked.pipes; } } } //Update sync nodes with trigger pipelines for (var i = 0; i < specialNodes.SyncInformation.NodeGroups.Count; i++) { SyncSplitGroup group = specialNodes.SyncInformation.NodeGroups[i]; if (group.CalledBy == -2) { continue; } int expectedPipes = ExtractSyncGroup(group.CalledBy).RequiredPipes; ExtractNodeSlot(group.CalledBy).StateInfo(expectedPipes, group.pipes); } return(executors.ToArray()); }
public void Finish() { PluginStore.ClearAll(); }
public void Clear() { PluginStore.ClearAll(); PipelineState.InputDirectory = PipelineState.OutputDirectory = ""; }
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 )"); }
public bool Initialize() { Logger.Info($"{new string('=', 64)}"); Logger.Info("Initializing..."); PluginLoader.LoadAll(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Plugins")); const string key = "config-file"; if (string.IsNullOrEmpty(AppSettingsHelper.ReadValue(key))) { AppSettingsHelper.WriteValue(key, "config.json"); } _configManager = new ConfigManager(AppSettingsHelper.ReadValue(key)); if (!_configManager.LoadOrCreateConfig()) { return(false); } _config = _configManager.CurrentConfig; _cache = new DataCache(); _pluginStore = new PluginStore(); _sensorManager = new SensorManager(_config); _deviceManager = new DeviceManager(); _sensorManager.EnableSensors(_config.SensorConfigs.SelectMany(x => x.Sensors)); foreach (var profile in _config.Profiles) { if (_pluginStore.Get(profile).Any()) { Logger.Fatal("Duplicate profile \"{0}\" found!", profile.Name); return(false); } foreach (var effect in profile.Effects) { _pluginStore.Add(profile, effect); _sensorManager.EnableSensors(effect.UsedSensors); } foreach (var speedController in profile.SpeedControllers) { _pluginStore.Add(profile, speedController); _sensorManager.EnableSensors(speedController.UsedSensors); } profile.Ports.RemoveAll(p => { var portExists = _deviceManager.Controllers.SelectMany(c => c.Ports).Contains(p); if (!portExists) { Logger.Warn("Removing invalid port: {0}", p); } return(!portExists); }); } foreach (var sensor in _sensorManager.EnabledSensors) { _cache.StoreSensorConfig(sensor, SensorConfig.Default); } foreach (var controller in _deviceManager.Controllers) { foreach (var port in controller.Ports) { _cache.StorePortConfig(port, PortConfig.Default); _cache.StoreDeviceConfig(port, DeviceConfig.Default); } } _configManager.Accept(_cache.AsWriteOnly()); ApplyComputerStateProfile(ComputerStateType.Boot); _timerManager = new TimerManager(); _timerManager.RegisterTimer(_config.SensorTimerInterval, SensorTimerCallback); _timerManager.RegisterTimer(_config.DeviceSpeedTimerInterval, DeviceSpeedTimerCallback); _timerManager.RegisterTimer(_config.DeviceRgbTimerInterval, DeviceRgbTimerCallback); if (LogManager.Configuration.LoggingRules.Any(r => r.IsLoggingEnabledForLevel(LogLevel.Debug))) { _timerManager.RegisterTimer(_config.LoggingTimerInterval, LoggingTimerCallback); } _timerManager.Start(); Logger.Info("Initializing done!"); Logger.Info($"{new string('=', 64)}"); return(true); }
/// <summary> /// Get the directory for the assembly /// </summary> /// <param name="assemblyName">Name of the assembly</param> /// <param name="publicKeyToken">Public token</param> /// <param name="pluginStore">Global or Custom Store</param> /// <returns>Returns the full directory name</returns> private string GetPluginDirectory(AssemblyName assemblyName, string publicKeyToken, PluginStore pluginStore) { string versionName = string.Empty; if (publicKeyToken == String.Empty) { versionName = Path.Combine(assemblyName.Name, assemblyName.Version.ToString()); } else { versionName = Path.Combine(assemblyName.Name, assemblyName.Version.ToString() + "__" + publicKeyToken); } switch (pluginStore) { case PluginStore.GlobalPluginStore: return(Path.Combine(globalPluginStore, versionName)); case PluginStore.CustomPluginStore: return(Path.Combine(customPluginStore, versionName)); } return(String.Empty); }
public void Setup() { PipelineState.ClearAll(); PluginStore.Init(); }
public void InsertProductPerformanceTest() { int nProducts = 50; int avgProductPlugins = 30; var store = new PluginStore(); Version vers01 = new Version(0, 1); Stopwatch stopWatch = new Stopwatch(); Random r = new Random(); var plugins = store.Plugins.ToList(); stopWatch.Start(); // create products for (int i = 0; i < nProducts; i++) { string name = RandomName(); List<PluginDescription> prodPlugins = new List<PluginDescription>(); for (int j = 0; j < avgProductPlugins; j++) { var selectedPlugin = plugins[r.Next(0, plugins.Count)]; if (!prodPlugins.Contains(selectedPlugin)) prodPlugins.Add(selectedPlugin); } var prod = new ProductDescription(name, vers01, prodPlugins); store.Persist(prod); } stopWatch.Stop(); Assert.Inconclusive("Created " + nProducts + " products in " + stopWatch.ElapsedMilliseconds + " ms (" + (double)stopWatch.ElapsedMilliseconds / nProducts + " ms / product )"); }
public void Setup() { PluginStore.Init(); PluginStore.AddPlugin(inputPlugin3); PluginStore.AddPlugin(inputPlugin4); }