示例#1
0
		private PluginResponse PrepareSource()
		{
			var provider = CodeDomProvider.CreateProvider("CSharp");
			var cp = GenerateCompilerParameter();
			var result = provider.CompileAssemblyFromFile(cp, file.FullName);

			if (result.Errors.Count > 0)
			{
				bool containsErrors = false;
				foreach (CompilerError error in result.Errors)
				{
					containsErrors |= !error.IsWarning;
					Log.Write(Log.Level.Warning, "Plugin_{0}: {1} L{2}/C{3}: {4}\n",
						Id,
						error.IsWarning ? "Warning" : "Error",
						error.Line,
						error.Column,
						error.ErrorText);
				}

				if (containsErrors)
					return PluginResponse.CompileError;
			}
			return proxy.LoadAssembly(domain, result.CompiledAssembly.GetName());
		}
示例#2
0
        public PluginResponse Prepare()
        {
            try
            {
                if (file.Extension != ".cs" && file.Extension != ".dll" && file.Extension != ".exe")
                {
                    return(PluginResponse.UnsupportedFile);
                }

                //todo test shadowcopying
                domain = AppDomain.CreateDomain(
                    "Plugin_" + file.Name,
                    AppDomain.CurrentDomain.Evidence,
                    new AppDomainSetup
                {
                    ApplicationBase     = ts3File.Directory.FullName,
                    PrivateBinPath      = "Plugin/..;Plugin",
                    PrivateBinPathProbe = ""
                });
                domain.UnhandledException += (s, e) => Unload();
                proxy = (PluginProxy)domain.CreateInstanceAndUnwrap(
                    proxType.Assembly.FullName,
                    proxType.FullName);

                PluginResponse result;
                if (file.Extension == ".cs")
                {
                    result = PrepareSource();
                }
                else if (file.Extension == ".dll" || file.Extension == ".exe")
                {
                    result = proxy.LoadAssembly(domain, file);
                }
                else
                {
                    throw new InvalidProgramException();
                }

                if (result == PluginResponse.Ok)
                {
                    status = PluginStatus.Ready;
                }
                return(result);
            }
            catch (Exception ex)
            {
                Log.Write(Log.Level.Warning, "Possible plugin failed to load: ", ex);
                return(PluginResponse.Crash);
            }
        }
示例#3
0
		public PluginResponse Prepare()
		{
			try
			{
				if (file.Extension != ".cs" && file.Extension != ".dll" && file.Extension != ".exe")
					return PluginResponse.UnsupportedFile;

				//todo test shadowcopying
				domain = AppDomain.CreateDomain(
					"Plugin_" + file.Name,
					AppDomain.CurrentDomain.Evidence,
					new AppDomainSetup
					{
						ApplicationBase = ts3File.Directory.FullName,
						PrivateBinPath = "Plugin/..;Plugin",
						PrivateBinPathProbe = ""
					});
				domain.UnhandledException += (s, e) => Unload();
				proxy = (PluginProxy)domain.CreateInstanceAndUnwrap(
					proxType.Assembly.FullName,
					proxType.FullName);

				PluginResponse result;
				if (file.Extension == ".cs")
					result = PrepareSource();
				else if (file.Extension == ".dll" || file.Extension == ".exe")
					result = proxy.LoadAssembly(domain, file);
				else throw new InvalidProgramException();

				if (result == PluginResponse.Ok)
					status = PluginStatus.Ready;
				return result;
			}
			catch (Exception ex)
			{
				Log.Write(Log.Level.Warning, "Possible plugin failed to load: ", ex);
				return PluginResponse.Crash;
			}
		}