Example #1
0
		/// <summary>Updates the plugin dictinary with new and changed plugins.</summary>
		private void CheckLocalPlugins()
		{
			var dir = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, pluginManagerData.PluginPath));
			if (!dir.Exists)
				return;

			foreach (var file in dir.EnumerateFiles())
			{
				Plugin plugin;
				if (plugins.TryGetValue(file.Name, out plugin))
				{
					if (plugin.status == PluginStatus.Disabled || plugin.status == PluginStatus.Active)
						continue;
					else if (plugin.status == PluginStatus.Ready || plugin.status == PluginStatus.Off)
					{
						UnloadPlugin(plugin, false);
						plugin.Prepare();
					}
				}
				else
				{
					plugin = new Plugin(file, mainBot, GetFreeId());

					if (plugin.Prepare() != PluginResponse.Ok)
						continue;

					plugins.Add(file.Name, plugin);
				}
			}
		}
Example #2
0
		/// <summary>Updates the plugin dictinary with new and changed plugins.</summary>
		private void CheckLocalPlugins()
		{
			var dir = new DirectoryInfo(Path.Combine(Environment.CurrentDirectory, pluginManagerData.PluginPath));
			if (!dir.Exists)
				return;

			foreach (var file in dir.EnumerateFiles())
			{
				Plugin plugin;
				if (plugins.TryGetValue(file.Name, out plugin))
				{
					if (plugin.status == PluginStatus.Disabled || plugin.status == PluginStatus.Active)
						continue;
					else if (plugin.status == PluginStatus.Ready || plugin.status == PluginStatus.Off)
					{
						UnloadPlugin(plugin, false);
						plugin.Prepare();
					}
				}
				else
				{
					plugin = new Plugin(file, mainBot, GetFreeId());

					if (plugin.Prepare() != PluginResponse.Ok)
						continue;

					plugins.Add(file.Name, plugin);
				}
			}
		}
Example #3
0
		private R LoadPlugin(Plugin plugin)
		{
			if (plugin == null)
				return "Plugin not found";

			if (plugin.status == PluginStatus.Off || plugin.status == PluginStatus.Disabled)
			{
				var response = plugin.Prepare();
				if (response != PluginResponse.Ok)
					return response.ToString();
			}

			if (plugin.status == PluginStatus.Ready)
			{
				try
				{
					plugin.proxy.Run(mainBot);
					mainBot.CommandManager.RegisterPlugin(plugin);
					plugin.status = PluginStatus.Active;
					return R.OkR;
				}
				catch (Exception ex)
				{
					UnloadPlugin(plugin, false);
					string errMsg = "Plugin could not be loaded: " + ex.Message;
					Log.Write(Log.Level.Warning, errMsg);
					return errMsg;
				}
			}
			return "Unknown plugin error";
		}
Example #4
0
		private string LoadPlugin(Plugin plugin)
		{
			if (plugin == null)
				return "Plugin not found";

			if (plugin.status == PluginStatus.Off || plugin.status == PluginStatus.Disabled)
			{
				var response = plugin.Prepare();
				if (response != PluginResponse.Ok)
					return response.ToString();
			}

			if (plugin.status == PluginStatus.Ready)
			{
				try
				{
					plugin.proxy.Run(mainBot);
					mainBot.CommandManager.RegisterPlugin(plugin);
					plugin.status = PluginStatus.Active;
					return "Ok";
				}
				catch (Exception ex)
				{
					UnloadPlugin(plugin, false);
					string errMsg = "Plugin could not be loaded: " + ex.Message;
					Log.Write(Log.Level.Warning, errMsg);
					return errMsg;
				}
			}
			return "Unknown plugin error";
		}