Exemple #1
0
 private static void DownloadCompleted(IRuntime runtime, int caller, DownloadDataCompletedEventArgs e)
 {
     // item 255
     if (e.Cancelled) {
     // item 258
     runtime.SendMessage(
         caller,
         Cancel,
         null,
         0
     );
     } else {
     // item 259
     if (e.Error == null) {
         // item 262
         runtime.SendMessage(
             caller,
             CallResult.Completed,
             e.Result,
             0
         );
     } else {
         // item 261
         runtime.SendMessage(
             caller,
             CallResult.Error,
             e.Error,
             0
         );
     }
     }
 }
Exemple #2
0
 private static void ReportPrimes(IRuntime runtime, List<int> primes, int n, int client)
 {
     // item 229
     string[] primesAsText = primes
     .Select(p => p.ToString())
     .ToArray();
     // item 226
     string primeString = String.Join(
     "\n",
     primesAsText
     );
     // item 227
     string result = String.Format(
     "Prime numbers up to {0}: {1} found:\n{2}",
     n,
     primes.Count,
     primeString
     );
     // item 228
     runtime.SendMessage(
     client,
     CallResult.Completed,
     result,
     0
     );
 }
        /// <summary>
        /// Initializes the isolation provider.
        /// </summary>
        /// <param name="runtime">The runtime.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="runtime"/> is null.</exception>
        public PartCoverTestIsolationProvider(IRuntime runtime)
        {
            if (runtime == null)
                throw new ArgumentNullException("runtime");

            this.runtime = runtime;
        }
        /// <summary>
        /// Creates a host factory.
        /// </summary>
        /// <param name="runtime">The runtime.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="runtime"/> is null.</exception>
        public IsolatedProcessHostFactory(IRuntime runtime)
        {
            if (runtime == null)
                throw new ArgumentNullException("runtime");

            runtimePath = runtime.GetRuntimeSetup().RuntimePath;
        }
        /// <summary>
        /// Constructor used for unit testing
        /// </summary>
        /// <param name="runtime">IRuntime object to provide the data to the camera</param>
        internal IavaCamera(IRuntime runtime)
        {
            // Set the IRuntime object
            _runtime = runtime;

            InitializeDevice();
        }
        private static void SetMessageValuesIfNotSetInClient(RequestHeader message, IRuntime runtime)
        {
            if (runtime == null) return;
            if (message.MessageId.IsNullOrWhiteSpace())
                message.MessageId = Guid.NewGuid().ToString();
            if (message.Environment.IsNullOrWhiteSpace())
                message.Environment = runtime.Environment;
            if (message.ServiceName.IsNullOrWhiteSpace())
                message.ServiceName = runtime.ServiceName;
            if (message.ConfigSet.IsNullOrWhiteSpace())
                message.ConfigSet = Utilities.GetConfigSetName();
            if (message.TimeStamp == null)
                message.TimeStamp = DateTime.UtcNow;
            if (runtime.RequestContext.IsInstance() && runtime.RequestContext.RequestHeader.IsInstance())
            {
                message.ReferingMessageId = runtime.RequestContext.RequestHeader.MessageId;

            }
            string supportCode;
            if (runtime.TryGetSupportCode(out supportCode)) message.SupportCode = supportCode;
            else
            {
                if (runtime.RequestContext.IsInstance() && runtime.RequestContext.RequestHeader.IsInstance())
                {
                    message.SupportCode = runtime.RequestContext.RequestHeader.SupportCode;
                }
            }
        }
        /// <summary>
        /// Initializes the isolation provider.
        /// </summary>
        /// <param name="runtime">The runtime.</param>
        /// <param name="version">The NCover version.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="runtime"/> is null.</exception>
        public NCoverTestIsolationProvider(IRuntime runtime, NCoverVersion version)
        {
            if (runtime == null)
                throw new ArgumentNullException("runtime");

            this.runtime = runtime;
            this.version = version;
        }
Exemple #8
0
 public ExternalThread(string name, IRuntime runtime, IActorLogger logger, IErrorHandler errorHandler, Action<Action> dispatchMethod)
 {
     _name = name;
     _runtime = runtime;
     _logger = logger;
     _errorHandler = errorHandler;
     _dispatcher = dispatchMethod;
 }
        public static LazyDownloadArgs CreateSeleniumArgs(IRuntime runtime, int line, int threadCount, string cssElement, int cssTimeout, Table<ResultRow> table)
        {
            var args = new LazyDownloadArgs(runtime, threadCount);
            foreach (var row in table)
                args.Wires.Add(new SeleniumHttpWire(row[0].ToString(), cssElement, cssTimeout, runtime, line));

            return args;
        }
        public static LazyDownloadArgs CreateWebRequestArgs(IRuntime runtime, int line, int threadCount, Table<ResultRow> table)
        {
            var args = new LazyDownloadArgs(runtime, threadCount);
            foreach (var row in table)
                args.Wires.Add(new WebRequestHttpWire(row[0].ToString(), runtime, line));

            return args;
        }
Exemple #11
0
        public static RuntimeTable<DownloadImage> DownloadImage(IRuntime runtime, string url, int line)
        {
            var table = new RuntimeTable<DownloadImage>();

            var image = GetImage(runtime.RequestFactory, new WebRequestHttpWire(url, runtime, line));

            table.Add(image);
            return table;
        }
Exemple #12
0
 public DedicatedThread(string name, IRuntime runtime, IActorLogger logger, IErrorHandler errorHandler, int actorId, IActor actor)
 {
     _actor = actor;
     _actorId = actorId;
     _name = name;
     _runtime = runtime;
     _logger = logger;
     _errorHandler = errorHandler;
 }
Exemple #13
0
 public static void Deactivate(IRuntime runtime)
 {
     lock (_currentLock)
     {
         _active.ContainsKey(Thread.CurrentThread).AssertTrue();
         ReferenceEquals(_active[Thread.CurrentThread], runtime).AssertTrue();
         _active.Remove(Thread.CurrentThread);
     }
 }
Exemple #14
0
 public static IDisposable Activate(IRuntime runtime)
 {
     lock (_currentLock)
     {
         _active.ContainsKey(Thread.CurrentThread).AssertFalse();
         _active.ContainsValue(runtime).AssertFalse();
         _active.Add(Thread.CurrentThread, runtime);
         return new DisposableAction(() => Deactivate(runtime));
     }
 }
        /// <summary>
        /// Default Constructor
        /// </summary>
        static IavaCamera()
        {
            // Set the IRuntime object
            _runtime = new KinectRuntimeWrapper();

            InitializeDevice();

            // Since there is no such thing as a static destructor do
            // our clean up code when we recognize the ProcessExit event
            AppDomain.CurrentDomain.ProcessExit += ShutDown;
        }
Exemple #16
0
        private void ControlLoaded(object sender, RoutedEventArgs e)
        {
            if( null == Runtime )
            {
                Runtime = Execution.Platform.Runtime;
                Core.Runtime.Instance.WireUpDependencies(this);
                OnLoaded();

                Initialize();
                InitializeProperties();
            }
        }
Exemple #17
0
        private static RuntimeTable<DownloadPage> DownloadPage(IRuntime runtime, IHttpWire[] wires)
        {
            var table = new RuntimeTable<DownloadPage>();
            foreach (var wire in wires)
            {
                int contentlength;
                var doc = GetDocument(runtime.RequestFactory, wire, out contentlength);
                table.Add(new DownloadPage() { url = wire.Url, nodes = new[] { doc.DocumentNode }, date = DateTime.Now, size = contentlength });
            }

            return table;
        }
Exemple #18
0
 public InstallCommand(IRuntime runtime, IFileSystem fileSystem, ICakeEnvironment environment,
     ICakeLog log, INuGetPackageConfigurationCreator packageConfigCreator,
     IFileCopier fileCopier, IHttpDownloader downloader, IGitIgnorePatcher gitIgnorePatcher)
 {
     _runtime = runtime;
     _fileSystem = fileSystem;
     _environment = environment;
     _log = log;
     _packageConfigCreator = packageConfigCreator;
     _fileCopier = fileCopier;
     _downloader = downloader;
     _gitIgnorePatcher = gitIgnorePatcher;
 }
        public static bool TryGetSupportCode(IRuntime runtime, out string supportCode)
        {
            if (runtime == null || runtime.GetStateStorageContainer() == null)
            {
                supportCode = null;
                return false;
            }
            StateStorageItem item;
            var result = runtime.GetStateStorageContainer().TryGetItem("supportCode", out item);
            if (item != null && item.Value != null) supportCode = (string)item.Value;
            else supportCode = null;
            return result;

        }
Exemple #20
0
 public AutoRuntime(AutoConfig config, Type t_kernel)
     : base(config, t_kernel)
 {
     var cudaDevice = CudaDevice.Current;
     if (cudaDevice != null)
     {
         var cfg = CudaConfig.Default;
         _impl = new CudaRuntime(cfg, t_kernel);
     }
     else
     {
         var cfg = CpuConfig.Default;
         _impl = new CpuRuntime(cfg, t_kernel);
     }
 }
 private static void SetMessageValuesIfNotSetInClient(IRequestBase message, IRuntime runtime)
 {
     if (message.MessageId.IsNullOrWhiteSpace())
         message.MessageId = Guid.NewGuid().ToString();
     if (message.Environment.IsNullOrWhiteSpace())
         message.Environment = runtime.Environment;
     if (message.ServiceName.IsNullOrWhiteSpace())
         message.ServiceName = runtime.ServiceName;
     if (message.ConfigSet.IsNullOrWhiteSpace())
         message.ConfigSet = ConfigurationManagerHelper.GetValueOnKey("configSet");
     if (message.TimeStamp == null)
         message.TimeStamp = DateTime.UtcNow;
     if (runtime.RequestContext.IsInstance())
         message.ReferingMessageId = runtime.RequestContext.MessageId;
 }
Exemple #22
0
        private static LanguageGenerator GetGenerator(string language, string knockoutPrefix, IRuntime runtime)
        {
            switch (language)
                {
                    case TypeScriptGenerator.Id:
                        return new TypeScriptGenerator();

                    case KnockoutMappingGenerator.Id:
                        return new KnockoutMappingGenerator(knockoutPrefix);

                    default:
                        runtime.Error("Unknown language: {0}", language);
                        System.Environment.Exit(-1);
                        return (LanguageGenerator)null;
            }
        }
Exemple #23
0
		// --- constructors ---
		internal NetPlugin(string pluginFile, string trainFolder, IRuntime api, TrainManager.Train train) {
			base.PluginTitle = System.IO.Path.GetFileName(pluginFile);
			base.PluginValid = true;
			base.PluginMessage = null;
			base.Train = train;
			base.Panel = null;
			base.SupportsAI = false;
			base.LastTime = 0.0;
			base.LastReverser = -2;
			base.LastPowerNotch = -1;
			base.LastBrakeNotch = -1;
			base.LastAspects = new int[] { };
			base.LastSection = -1;
			base.LastException = null;
			this.PluginFolder = System.IO.Path.GetDirectoryName(pluginFile);
			this.TrainFolder = trainFolder;
			this.Api = api;
			this.SoundHandles = new SoundHandleEx[16];
			this.SoundHandlesCount = 0;
		}
 public IRuntime GetRuntime()
 {
     if (Runtime.IsNull())
         Runtime = RuntimeFactory.CreateRuntime();
     return Runtime;
 }
 public EnvironmentController(IEnvironmentTasks environmentTasks, IConfigSetTask configSetTasks, IRuntime runtime)
     : base(runtime)
 {
     this.reader         = environmentTasks;
     this.configSetTasks = configSetTasks;
 }
 public UserController(IRuntime runtime, IUserFacade userReader, IConfigSetTask reader) : base(runtime)
 {
     this.userReader = userReader;
     this.reader     = reader;
 }
Exemple #27
0
        /// <summary>Loads the specified plugin for the specified train.</summary>
        /// <param name="train">The train to attach the plugin to.</param>
        /// <param name="pluginFile">The file to the plugin.</param>
        /// <param name="trainFolder">The train folder.</param>
        /// <returns>Whether the plugin was loaded successfully.</returns>
        private static bool LoadPlugin(TrainManager.Train train, string pluginFile, string trainFolder)
        {
            string pluginTitle = System.IO.Path.GetFileName(pluginFile);

            if (!System.IO.File.Exists(pluginFile))
            {
                Interface.AddMessage(Interface.MessageType.Error, true, "The train plugin " + pluginTitle + " could not be found.");
                return(false);
            }

            /*
             * Unload plugin if already loaded.
             * */
            if (train.Plugin != null)
            {
                UnloadPlugin(train);
            }

            /*
             * Prepare initialization data for the plugin.
             * */
            BrakeTypes brakeType = (BrakeTypes)train.Cars[train.DriverCar].Specs.BrakeType;
            int        brakeNotches;
            int        powerNotches;
            bool       hasHoldBrake;

            if (brakeType == BrakeTypes.AutomaticAirBrake)
            {
                brakeNotches = 2;
                powerNotches = train.Specs.MaximumPowerNotch;
                hasHoldBrake = false;
            }
            else
            {
                brakeNotches = train.Specs.MaximumBrakeNotch + (train.Specs.HasHoldBrake ? 1 : 0);
                powerNotches = train.Specs.MaximumPowerNotch;
                hasHoldBrake = train.Specs.HasHoldBrake;
            }
            int                 cars  = train.Cars.Length;
            VehicleSpecs        specs = new VehicleSpecs(powerNotches, brakeType, brakeNotches, hasHoldBrake, cars);
            InitializationModes mode  = (InitializationModes)Game.TrainStart;

            /*
             * Check if the plugin is a .NET plugin.
             * */
            Assembly assembly;

            try {
                assembly = Assembly.LoadFile(pluginFile);
            } catch (BadImageFormatException) {
                assembly = null;
            } catch (Exception ex) {
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " could not be loaded due to the following exception: " + ex.Message);
                return(false);
            }
            if (assembly != null)
            {
                Type[] types;
                try {
                    types = assembly.GetTypes();
                } catch (ReflectionTypeLoadException ex) {
                    foreach (Exception e in ex.LoaderExceptions)
                    {
                        Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " raised an exception on loading: " + e.Message);
                    }
                    return(false);
                }
                foreach (Type type in types)
                {
                    if (typeof(IRuntime).IsAssignableFrom(type))
                    {
                        IRuntime api = assembly.CreateInstance(type.FullName) as IRuntime;
                        train.Plugin = new NetPlugin(pluginFile, trainFolder, api, train);
                        if (train.Plugin.Load(specs, mode))
                        {
                            return(true);
                        }
                        else
                        {
                            train.Plugin = null;
                            return(false);
                        }
                    }
                }
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }

            /*
             * Check if the plugin is a Win32 plugin.
             *
             */
            try {
                if (!CheckWin32Header(pluginFile))
                {
                    Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " is of an unsupported binary format and therefore cannot be used with openBVE.");
                    return(false);
                }
            } catch (Exception ex) {
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " could not be read due to the following reason: " + ex.Message);
                return(false);
            }
            if (!Program.CurrentlyRunningOnWindows | IntPtr.Size != 4)
            {
                Interface.AddMessage(Interface.MessageType.Warning, false, "The train plugin " + pluginTitle + " can only be used on 32-bit Microsoft Windows or compatible.");
                return(false);
            }
            if (Program.CurrentlyRunningOnWindows && !System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\AtsPluginProxy.dll"))
            {
                Interface.AddMessage(Interface.MessageType.Warning, false, "AtsPluginProxy.dll is missing or corrupt- Please reinstall.");
                return(false);
            }
            train.Plugin = new Win32Plugin(pluginFile, train);
            if (train.Plugin.Load(specs, mode))
            {
                return(true);
            }
            else
            {
                train.Plugin = null;
                Interface.AddMessage(Interface.MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }
        }
Exemple #28
0
 public IService Instantiate(Service service, IRuntime runtime)
 {
     return(TypeFactory.Instantiate <IService, Service, IRuntime>(this.TypeName, service, runtime));
 }
Exemple #29
0
        protected override IEnumerable <Assembly> LoadAssemblies()
        {
            IRuntime        runtime    = Container.Resolve <IRuntime>();
            List <Assembly> assemblies = new List <Assembly>();

            foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
            {
                assemblies.Add(assembly);
            }

            /*
             * var rocketDire = Path.GetDirectoryName(typeof(DllPluginManager).Assembly.Location);
             * var rocketAssemblies = ReflectionExtensions.GetAssembliesFromDirectory(rocketDir);
             * foreach (var entry in rocketAssemblies)
             *  Logger.LogDebug("Loaded rocket assembly: " + entry.Key + " -> " + entry.Value);
             */

            var packagesDirectory = Path.Combine(runtime.WorkingDirectory, "Packages");

            Directory.CreateDirectory(packagesDirectory);
            packageAssemblies = ReflectionExtensions.GetAssembliesFromDirectory(packagesDirectory);
            foreach (var entry in packageAssemblies)
            {
                Logger.LogDebug("Loaded library: " + entry.Key + " -> " + entry.Value);
            }

            var pluginsDirectory = Path.Combine(runtime.WorkingDirectory, "Plugins");

            Directory.CreateDirectory(pluginsDirectory);
            pluginAssemblies = ReflectionExtensions.GetAssembliesFromDirectory(pluginsDirectory);
            foreach (var entry in pluginAssemblies)
            {
                Logger.LogDebug("Loaded plugin: " + entry.Key + " -> " + entry.Value);
            }

            AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs args)
            {
                var name = ReflectionExtensions.GetVersionIndependentName(args.Name);

                try
                {
                    if (pluginAssemblies.TryGetValue(name, out string pluginFile))
                    {
                        return(LoadCachedAssembly(pluginFile));
                    }

                    if (packageAssemblies.TryGetValue(name, out string packageFile))
                    {
                        return(LoadCachedAssembly(packageFile));
                    }

                    foreach (var asm in assemblies)
                    {
                        var asmName = ReflectionExtensions.GetVersionIndependentName(asm.FullName);
                        if (asmName.Equals(name))
                        {
                            return(asm);
                        }
                    }

                    Logger.LogDebug("Could not find dependency: " + name);
                }
                catch (Exception ex)
                {
                    Logger.LogFatal("Failed to load assembly: " + name, ex);
                }
                return(null);
            };

            foreach (string pluginPath in pluginAssemblies.Values)
            {
                try
                {
                    Assembly pluginAssembly = LoadCachedAssembly(pluginPath);
                    assemblies.Add(pluginAssembly);
                }
                catch (Exception ex)
                {
                    Logger.LogError($"Failed to load plugin assembly at {pluginPath}", ex);
                }
            }

            return(assemblies);
        }
Exemple #30
0
        public void SetUp()
        {
            _runtime = A.Fake<IRuntime>();
            _actor = new HttpActors.StreamPump();
            _actor.InStream = new MemoryStream();
            _actor.OutStream = new MemoryStream();
            _actor.TotalLength = 100;

            _oldInBuffer = _actor.InBuffer;
            _oldOutBuffer = _actor.OutBuffer;
            _oldInBuffer.Data[0] = 1;
            _oldOutBuffer.Data[0] = 2;
        }
Exemple #31
0
 public ConsoleHost(IRuntime runtime)
 {
     Console = new StdConsole(runtime.Container);
 }
Exemple #32
0
        private static LanguageGenerator GetGenerator(string language, string knockoutPrefix, IRuntime runtime)
        {
            switch (language)
            {
            case TypeScriptGenerator.Id:
                return(new TypeScriptGenerator());

            case KnockoutMappingGenerator.Id:
                return(new KnockoutMappingGenerator(knockoutPrefix));

            default:
                runtime.Error("Unknown language: {0}", language);
                System.Environment.Exit(-1);
                return((LanguageGenerator)null);
            }
        }
 public AssemblyLoader(IRuntime runtime)
 {
     this.runtime = runtime;
 }
Exemple #34
0
 public IRuntimeTask SetExternalState(ref IRuntime runtime)
 {
     return(this);
 }
 public static AssemblyLoader FromExecutingAssembly(IRuntime runtime)
 {
     var loader = new AssemblyLoader(runtime);
     return loader;
 }
 public EnvironmentController(IEnvironmentTasks environmentTasks, IConfigSetTask configSetTasks, IRuntime runtime)
     : base(runtime)
 {
     this.reader = environmentTasks;
     this.configSetTasks = configSetTasks;
 }
 public EnvironmentParameterController(IEnvironmentTasks environmentTasks, IRuntime runtime)
     : base(runtime)
 {
     this.reader = environmentTasks;
 }
 public OpenModStringLocalizer(IStringLocalizerFactory stringLocalizerFactory, IRuntime runtime) : base(
         stringLocalizerFactory.Create("openmod.translations", runtime.WorkingDirectory))
 {
 }
        /// <summary>
        /// Sets the runtime instance.
        /// </summary>
        /// <remarks>
        /// <para>
        /// This method should only be used by applications that host Gallio
        /// and not generally by client code.
        /// </para>
        /// </remarks>
        /// <param name="runtime">The runtime instance, or null if none.</param>
        public static void SetRuntime(IRuntime runtime)
        {
            EventHandler instanceChangedHandlers = InstanceChanged;
            instance = runtime;

            EventHandlerPolicy.SafeInvoke(instanceChangedHandlers, null, EventArgs.Empty);
        }
Exemple #40
0
        /// <summary>Loads the specified plugin for the specified train.</summary>
        /// <param name="pluginFile">The file to the plugin.</param>
        /// <param name="trainFolder">The train folder.</param>
        /// <returns>Whether the plugin was loaded successfully.</returns>
        public bool LoadPlugin(string pluginFile, string trainFolder)
        {
            string pluginTitle = System.IO.Path.GetFileName(pluginFile);

            if (!System.IO.File.Exists(pluginFile))
            {
                TrainManagerBase.currentHost.AddMessage(MessageType.Error, true, "The train plugin " + pluginTitle + " could not be found.");
                return(false);
            }

            /*
             * Unload plugin if already loaded.
             * */
            if (Plugin != null)
            {
                UnloadPlugin();
            }

            /*
             * Prepare initialization data for the plugin.
             * */

            InitializationModes mode = (InitializationModes)TrainManagerBase.CurrentOptions.TrainStart;

            /*
             * Check if the plugin is a .NET plugin.
             * */
            Assembly assembly;

            try
            {
                assembly = Assembly.LoadFile(pluginFile);
            }
            catch (BadImageFormatException)
            {
                assembly = null;
                try
                {
                    AssemblyName myAssembly = AssemblyName.GetAssemblyName(pluginFile);
                    if (IntPtr.Size != 4 && myAssembly.ProcessorArchitecture == ProcessorArchitecture.X86)
                    {
                        TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " can only be used with the 32-bit version of OpenBVE");
                        return(false);
                    }
                }
                catch
                {
                    //ignored
                }
            }
            catch (Exception ex)
            {
                TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be loaded due to the following exception: " + ex.Message);
                return(false);
            }

            if (assembly != null)
            {
                Type[] types;
                try
                {
                    types = assembly.GetTypes();
                }
                catch (ReflectionTypeLoadException ex)
                {
                    foreach (Exception e in ex.LoaderExceptions)
                    {
                        TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " raised an exception on loading: " + e.Message);
                    }

                    return(false);
                }

                foreach (Type type in types)
                {
                    if (typeof(IRuntime).IsAssignableFrom(type))
                    {
                        if (type.FullName == null)
                        {
                            //Should never happen, but static code inspection suggests that it's possible....
                            throw new InvalidOperationException();
                        }

                        IRuntime api = assembly.CreateInstance(type.FullName) as IRuntime;
                        Plugin = new NetPlugin(pluginFile, trainFolder, api, this);
                        if (Plugin.Load(vehicleSpecs(), mode))
                        {
                            return(true);
                        }
                        else
                        {
                            Plugin = null;
                            return(false);
                        }
                    }
                }

                TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }

            /*
             * Check if the plugin is a Win32 plugin.
             *
             */
            try
            {
                if (!Win32Plugin.CheckHeader(pluginFile))
                {
                    TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " is of an unsupported binary format and therefore cannot be used with openBVE.");
                    return(false);
                }
            }
            catch (Exception ex)
            {
                TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " could not be read due to the following reason: " + ex.Message);
                return(false);
            }

            if (TrainManagerBase.currentHost.Platform != HostPlatform.MicrosoftWindows | IntPtr.Size != 4)
            {
                if (TrainManagerBase.currentHost.Platform == HostPlatform.MicrosoftWindows && IntPtr.Size != 4)
                {
                    //We can't load the plugin directly on x64 Windows, so use the proxy interface
                    Plugin = new ProxyPlugin(pluginFile, this);
                    if (Plugin.Load(vehicleSpecs(), mode))
                    {
                        return(true);
                    }

                    Plugin = null;
                    TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " failed to load.");
                    return(false);
                }

                //WINE doesn't seem to like the WCF proxy :(
                TrainManagerBase.currentHost.AddMessage(MessageType.Warning, false, "The train plugin " + pluginTitle + " can only be used on Microsoft Windows or compatible.");
                return(false);
            }

            if (TrainManagerBase.currentHost.Platform == HostPlatform.MicrosoftWindows && !System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\AtsPluginProxy.dll"))
            {
                TrainManagerBase.currentHost.AddMessage(MessageType.Warning, false, "AtsPluginProxy.dll is missing or corrupt- Please reinstall.");
                return(false);
            }

            Plugin = new Win32Plugin(pluginFile, this);
            if (Plugin.Load(vehicleSpecs(), mode))
            {
                return(true);
            }
            else
            {
                Plugin = null;
                TrainManagerBase.currentHost.AddMessage(MessageType.Error, false, "The train plugin " + pluginTitle + " does not export a train interface and therefore cannot be used with openBVE.");
                return(false);
            }
        }