/// <summary> /// Creates a new instance of <see cref="Driver"/> with the specified argument, /// and loads it according to the specified <see cref="DriverLoad"/> method. /// </summary> /// <param name="Config">The configuration.</param> /// <exception cref="System.ArgumentNullException">Config</exception> /// <exception cref="System.IO.FileNotFoundException">The driver file does not exist.</exception> public static Driver CreateAndLoad(DriverConfig Config) { if (Config == null) { throw new ArgumentNullException(nameof(Config)); } if (!Driver.CanConnectTo(Config.SymbolicLink)) { if (Config.DriverFile == null || !Config.DriverFile.Exists) { throw new FileNotFoundException("The driver file does not exist."); } } var DriverObject = new Driver(Config); try { DriverObject.Load(); } catch (Exception) { // .. } return(DriverObject); }
/// <summary> /// Loads the specified driver/system file. /// </summary> public bool Load() { if (!this.Loader.CreateDriver(this)) { Log.Error(typeof(Driver), "Failed to create the driver at Load()."); return(false); } if (!Driver.CanConnectTo(this.Config.SymbolicLink)) { if (!this.Loader.LoadDriver()) { Log.Error(typeof(Driver), "Failed to load the driver at Load()."); return(false); } } else { Log.Warning(typeof(Driver), "Warning, driver already exist at Load()."); } this.IsLoaded = true; if (this.IO.IsConnected) { this.IO.Disconnect(); } this.IO.Connect(); if (!this.IO.IsConnected) { Log.Error(typeof(Driver), "Failed to open the symbolic file."); } if (this.Loaded != null) { try { this.Loaded.Invoke(this, EventArgs.Empty); } catch (Exception) { // .. } } return(true); }
/// <summary> /// Loads the specified driver/system file. /// </summary> public bool Load() { if (!this.Loader.CreateDriver(this)) { Log.Error(typeof(Driver), "Failed to create the driver at Load()."); return(false); } switch (this.Config.LoadMethod) { case DriverLoad.Normal: { if (!this.Loader.LoadDriver()) { Log.Error(typeof(Driver), "Failed to load the driver at Load()."); return(false); } break; } default: { if (!Driver.CanConnectTo(this.Config.SymbolicLink, this.Config.IoMethod)) { if (!this.Loader.LoadDriver()) { Log.Error(typeof(Driver), "Failed to load the driver at Load()."); return(false); } } break; } } this.IsLoaded = true; if (this.Config.IoMethod != IoMethod.None) { if (!this.IO.IsConnected) { this.IO.Connect(); } if (!this.IO.IsConnected) { Log.Error(typeof(Driver), "Failed to initialize the IO communication."); } } if (this.Loaded != null) { try { this.Loaded.Invoke(this, EventArgs.Empty); } catch (Exception) { // .. } } return(true); }