/// <summary> /// Initializes the protocol type from another type /// </summary> public ProtocolType(IProtocolType from) { this.Provider = from.Provider; this.Type = from.Type; this.Name = from.Name; }
public bool Create(String assemblyFile, IProtocolType type) { this.SandboxedProtocol = null; try { // Load the assembly into our AppDomain var loaded = Assembly.LoadFile(assemblyFile); // Fetch a list of available game types by their attributes var protocolType = loaded.GetTypes() .Where(loadedType => typeof(IProtocol).IsAssignableFrom(loadedType)) .First(loadedType => { var firstOrDefault = loadedType.GetCustomAttributes(typeof (IProtocolType), false).Cast<IProtocolType>().FirstOrDefault(); return firstOrDefault != null && String.Equals(firstOrDefault.Provider, type.Provider) && String.Equals(firstOrDefault.Type, type.Type); }); this.SandboxedProtocol = (IProtocol)Activator.CreateInstance(protocolType); this.AssignEvents(); } // [Obviously copy/pasted from the plugin controller, it has the same meaning here] // We don't do any exception logging here, as simply updating Potato may log a bunch of exceptions // for plugins that are deprecated or simply forgotten about by the user. // The exceptions wouldn't be terribly detailed anyway, it would just specify that a fault occured // while loading the assembly/type and ultimately the original developer needs to fix something. // I would also hope that beyond Beta we will not make breaking changes to the plugin interface, // differing from Potato 1 in generic behaviour for IPluginController/ICoreController catch { this.SandboxedProtocol = null; } return this.SandboxedProtocol != null; }
/// <summary> /// Sets up the factory, then attempts to load a specific type into the protocol appdomain. /// </summary> public bool SetupProtocol(IProtocolAssemblyMetadata meta, IProtocolType type, ProtocolSetup setup) { if (this.ProtocolFactory == null) { this.SetupProtocolFactory(meta); } if (this.ProtocolFactory.Create(meta.Assembly.FullName, type) == true) { this.Protocol = this.ProtocolFactory; this.Protocol.Setup(setup); } return this.Protocol != null; }