Ejemplo n.º 1
0
		private void RunPluginOperation(IPlugin plugin, Action<IPlugin, IAgent> runAction)
		{
			bool isPluginInstalled = false;
			bool hasAvailableSlots = false;

			foreach (IAgent agent in AgentsList)
			{
				if (!isPluginInstalled && agent.IsPluginInstalled(plugin.PluginIdentifier))//TODO: Should check if plugin is actually used on any slots, not if it is installed on the agent.
					isPluginInstalled = true;

				if (agent.HasAvailableSlots(plugin.PluginIdentifier))
				{
					try
					{
						if (plugin.GetOperationRight())
							runAction(plugin, agent);
					}
					catch (Exception)
					{
						plugin.ReleaseOperationRight();

						throw;
					}

					hasAvailableSlots = true;

					break;
				}
			}

			if (!isPluginInstalled)
				throw new PluginNotInstalledException("Plugin: " + plugin.PluginIdentifier + ", not installed.");

			if (!hasAvailableSlots)
				throw new NoOpenExecutionSlotsException("No slots able to run: " + plugin.PluginIdentifier + ", are available.");
		}