/// <summary> /// Creates a new <see cref="IChannel" /> instance. /// </summary> /// <param name="channelDriver">The channel driver. Cannot be <c>null</c>.</param> /// <param name="applicationIdentifier">The application identifier must follow a reverse domain name format (ex. com.domainname.appname). Application /// identifiers can be formed from the set of alphanumeric ASCII characters (a-z, A-Z, 0-9). The hyphen (-) and /// underscore (_) characters are permitted if they are not adjacent to a period (.) character (i.e. not at the /// start or end of each segment), but are not permitted in the top-level domain. Application identifiers must have /// three or more segments. For example, if a company's domain is example.com and the application is named /// hello-world, one could use "com.example.hello-world" as a valid application identifier. The application identifier /// can be an empty string. The application identifier cannot be longer than 255 characters.</param> /// <param name="autostart">If set to <c>true</c>, the channel will be automatically started.</param> /// <returns> /// A new <see cref="IChannel" /> instance. /// </returns> /// <exception cref="System.ArgumentException"> /// The exception that is thrown when the <paramref name="applicationIdentifier"/> is invalid. /// </exception> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> or <paramref name="applicationIdentifier"/> is <c>null</c>. /// </exception> /// <exception cref="System.InvalidOperationException">Thrown when there is a failure to connect to the Bluetooth hub.</exception> public static IChannel Create(IChannelDriver channelDriver, string applicationIdentifier, bool autostart) { ////Contract.Requires<ArgumentNullException>(channelDriver != null, "channelDriver"); ////Contract.Requires<ArgumentNullException>(applicationIdentifier != null, "applicationIdentifier"); ////Contract.Requires<ArgumentException>(applicationIdentifier.Length <= 255, "The application identifier cannot be longer than 255 characters."); Contract.Ensures(Contract.Result <IChannel>() != null); return(new Channel(channelDriver, applicationIdentifier, autostart)); }
/// <summary> /// Creates a new <see cref="IChannel" /> instance. /// </summary> /// <param name="channelDriver">The channel driver.</param> /// <returns> /// Returns a new <see cref="IChannel" /> instance. /// </returns> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> is <c>null</c>. /// </exception> /// <exception cref="System.InvalidOperationException">Thrown when there is a failure to connect to the Bluetooth hub.</exception> public static IChannel Create(IChannelDriver channelDriver) { ////Contract.Requires<ArgumentNullException>(channelDriver != null, "channelDriver"); Contract.Ensures(Contract.Result <IChannel>() != null); var applicationIdentidier = string.Empty; Contract.Assume(applicationIdentidier.Length == 0); return(Create(channelDriver, applicationIdentidier)); }
/// <summary> /// Initializes a new instance of the <see cref="Channel" /> class. /// </summary> /// <param name="channelDriver">The channel driver. Cannot be <c>null</c>.</param> /// <param name="applicationIdentifier">The application identifier must follow a reverse domain name format (ex. com.domainname.appname). Application /// identifiers can be formed from the set of alphanumeric ASCII characters (a-z, A-Z, 0-9). The hyphen (-) and /// underscore (_) characters are permitted if they are not adjacent to a period (.) character (i.e. not at the /// start or end of each segment), but are not permitted in the top-level domain. Application identifiers must have /// three or more segments. For example, if a company's domain is example.com and the application is named /// hello-world, one could use "com.example.hello-world" as a valid application identifier. The application identifier /// can be an empty string. The application identifier cannot be longer than 255 characters.</param> /// <param name="autostart">If set to <c>true</c>, the channel will be automatically started.</param> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> or <paramref name="applicationIdentifier"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentException"> /// The exception that is thrown when <paramref name="applicationIdentifier"/> is invalid. /// </exception> /// <exception cref="System.InvalidOperationException"> /// The exception that is thrown when the hub fails to initialize. /// </exception> private Channel(IChannelDriver channelDriver, string applicationIdentifier, bool autostart) { _channelDriver = channelDriver; _handle = channelDriver.InitializeMyoHub(applicationIdentifier); if (_handle == IntPtr.Zero) { throw new InvalidOperationException("After an attempt to initialize the Myo hub, no pointer was provided."); } if (autostart) { StartListening(); } }
public CSScriptChannelDriver(string filename) { try { innerDriver = (IChannelDriver)CSScriptLibrary.CSScript .LoadCodeFrom(filename) .CreateObject("*") .AlignToInterface <IChannelDriver>();; scriptFilename = filename; } catch (Exception e) { throw new InvalidSettingsException("Unable to load class from given file!", e); } }
/// <summary> /// Initializes a new instance of the <see cref="Channel" /> class. /// </summary> /// <param name="channelDriver">The channel driver. Cannot be <c>null</c>.</param> /// <param name="applicationIdentifier">The application identifier must follow a reverse domain name format (ex. com.domainname.appname). Application /// identifiers can be formed from the set of alphanumeric ASCII characters (a-z, A-Z, 0-9). The hyphen (-) and /// underscore (_) characters are permitted if they are not adjacent to a period (.) character (i.e. not at the /// start or end of each segment), but are not permitted in the top-level domain. Application identifiers must have /// three or more segments. For example, if a company's domain is example.com and the application is named /// hello-world, one could use "com.example.hello-world" as a valid application identifier. The application identifier /// can be an empty string. The application identifier cannot be longer than 255 characters.</param> /// <param name="autostart">If set to <c>true</c>, the channel will be automatically started.</param> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> or <paramref name="applicationIdentifier"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentException"> /// The exception that is thrown when <paramref name="applicationIdentifier"/> is invalid. /// </exception> /// <exception cref="System.InvalidOperationException"> /// The exception that is thrown when the hub fails to initialize. /// </exception> private Channel(IChannelDriver channelDriver, string applicationIdentifier, bool autostart) { ////Contract.Requires<ArgumentNullException>(channelDriver != null, "channelDriver"); ////Contract.Requires<ArgumentNullException>(applicationIdentifier != null, "applicationIdentifier"); ////Contract.Requires<ArgumentException>(applicationIdentifier.Length <= 255, "The application identifier cannot be longer than 255 characters."); _channelDriver = channelDriver; _handle = channelDriver.InitializeMyoHub(applicationIdentifier); if (_handle == IntPtr.Zero) { throw new InvalidOperationException("After an attempt to initialize the Myo hub, no pointer was provided."); } if (autostart) { StartListening(); } }
/// <summary> /// Initializes a new instance of the <see cref="Channel" /> class. /// </summary> /// <param name="channelDriver">The channel driver. Cannot be <c>null</c>.</param> /// <param name="applicationIdentifier">The application identifier must follow a reverse domain name format (ex. com.domainname.appname). Application /// identifiers can be formed from the set of alphanumeric ASCII characters (a-z, A-Z, 0-9). The hyphen (-) and /// underscore (_) characters are permitted if they are not adjacent to a period (.) character (i.e. not at the /// start or end of each segment), but are not permitted in the top-level domain. Application identifiers must have /// three or more segments. For example, if a company's domain is example.com and the application is named /// hello-world, one could use "com.example.hello-world" as a valid application identifier. The application identifier /// can be an empty string. The application identifier cannot be longer than 255 characters.</param> /// <param name="autostart">If set to <c>true</c>, the channel will be automatically started.</param> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> or <paramref name="applicationIdentifier"/> is <c>null</c>. /// </exception> /// <exception cref="System.ArgumentException"> /// The exception that is thrown when <paramref name="applicationIdentifier"/> is invalid. /// </exception> /// <exception cref="System.InvalidOperationException"> /// The exception that is thrown when the hub fails to initialize. /// </exception> private Channel(IChannelDriver channelDriver, string applicationIdentifier, bool autostart) { Contract.Requires<ArgumentNullException>(channelDriver != null, "channelDriver"); Contract.Requires<ArgumentNullException>(applicationIdentifier != null, "applicationIdentifier"); Contract.Requires<ArgumentException>(applicationIdentifier.Length <= 255, "The application identifier cannot be longer than 255 characters."); _channelDriver = channelDriver; _handle = channelDriver.InitializeMyoHub(applicationIdentifier); if (_handle == IntPtr.Zero) { throw new InvalidOperationException("After an attempt to initialize the Myo hub, no pointer was provided."); } if (autostart) { StartListening(); } }
/// <summary> /// Creates a new <see cref="IChannel" /> instance. /// </summary> /// <param name="channelDriver">The channel driver.</param> /// <returns> /// Returns a new <see cref="IChannel" /> instance. /// </returns> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> is <c>null</c>. /// </exception> /// <exception cref="System.InvalidOperationException">Thrown when there is a failure to connect to the Bluetooth hub.</exception> public static IChannel Create(IChannelDriver channelDriver) { var applicationIdentidier = string.Empty; return(Create(channelDriver, applicationIdentidier)); }
/// <summary> /// Creates a new <see cref="IChannel" /> instance. /// </summary> /// <param name="channelDriver">The channel driver. Cannot be <c>null</c>.</param> /// <param name="applicationIdentifier">The application identifier must follow a reverse domain name format (ex. com.domainname.appname). Application /// identifiers can be formed from the set of alphanumeric ASCII characters (a-z, A-Z, 0-9). The hyphen (-) and /// underscore (_) characters are permitted if they are not adjacent to a period (.) character (i.e. not at the /// start or end of each segment), but are not permitted in the top-level domain. Application identifiers must have /// three or more segments. For example, if a company's domain is example.com and the application is named /// hello-world, one could use "com.example.hello-world" as a valid application identifier. The application identifier /// can be an empty string. The application identifier cannot be longer than 255 characters.</param> /// <param name="autostart">If set to <c>true</c>, the channel will be automatically started.</param> /// <returns> /// A new <see cref="IChannel" /> instance. /// </returns> /// <exception cref="System.ArgumentException"> /// The exception that is thrown when the <paramref name="applicationIdentifier"/> is invalid. /// </exception> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> or <paramref name="applicationIdentifier"/> is <c>null</c>. /// </exception> /// <exception cref="System.InvalidOperationException">Thrown when there is a failure to connect to the Bluetooth hub.</exception> public static IChannel Create(IChannelDriver channelDriver, string applicationIdentifier, bool autostart) { return(new Channel(channelDriver, applicationIdentifier, autostart)); }
/// <summary> /// Creates a new <see cref="IChannel" /> instance. /// </summary> /// <param name="channelDriver">The channel driver. Cannot be <c>null</c>.</param> /// <param name="applicationIdentifier">The application identifier must follow a reverse domain name format (ex. com.domainname.appname). Application /// identifiers can be formed from the set of alphanumeric ASCII characters (a-z, A-Z, 0-9). The hyphen (-) and /// underscore (_) characters are permitted if they are not adjacent to a period (.) character (i.e. not at the /// start or end of each segment), but are not permitted in the top-level domain. Application identifiers must have /// three or more segments. For example, if a company's domain is example.com and the application is named /// hello-world, one could use "com.example.hello-world" as a valid application identifier. The application identifier /// can be an empty string. The application identifier cannot be longer than 255 characters.</param> /// <returns> /// A new <see cref="IChannel" /> instance. /// </returns> /// <exception cref="System.ArgumentException"> /// The exception that is thrown when the <paramref name="applicationIdentifier"/> is invalid. /// </exception> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> or <paramref name="applicationIdentifier"/> is <c>null</c>. /// </exception> /// <exception cref="System.InvalidOperationException">Thrown when there is a failure to connect to the Bluetooth hub.</exception> public static IChannel Create(IChannelDriver channelDriver, string applicationIdentifier) { return(Create(channelDriver, applicationIdentifier, false)); }
public ChannelDriverPack(IChannelDriver driver, IFormView view = null) { Driver = driver; View = view; }
/// <summary> /// Creates a new <see cref="IChannel" /> instance. /// </summary> /// <param name="channelDriver">The channel driver. Cannot be <c>null</c>.</param> /// <param name="applicationIdentifier">The application identifier must follow a reverse domain name format (ex. com.domainname.appname). Application /// identifiers can be formed from the set of alphanumeric ASCII characters (a-z, A-Z, 0-9). The hyphen (-) and /// underscore (_) characters are permitted if they are not adjacent to a period (.) character (i.e. not at the /// start or end of each segment), but are not permitted in the top-level domain. Application identifiers must have /// three or more segments. For example, if a company's domain is example.com and the application is named /// hello-world, one could use "com.example.hello-world" as a valid application identifier. The application identifier /// can be an empty string. The application identifier cannot be longer than 255 characters.</param> /// <param name="autostart">If set to <c>true</c>, the channel will be automatically started.</param> /// <returns> /// A new <see cref="IChannel" /> instance. /// </returns> /// <exception cref="System.ArgumentException"> /// The exception that is thrown when the <paramref name="applicationIdentifier"/> is invalid. /// </exception> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> or <paramref name="applicationIdentifier"/> is <c>null</c>. /// </exception> /// <exception cref="System.InvalidOperationException">Thrown when there is a failure to connect to the Bluetooth hub.</exception> public static IChannel Create(IChannelDriver channelDriver, string applicationIdentifier, bool autostart) { Contract.Requires<ArgumentNullException>(channelDriver != null, "channelDriver"); Contract.Requires<ArgumentNullException>(applicationIdentifier != null, "applicationIdentifier"); Contract.Requires<ArgumentException>(applicationIdentifier.Length <= 255, "The application identifier cannot be longer than 255 characters."); Contract.Ensures(Contract.Result<IChannel>() != null); return new Channel(channelDriver, applicationIdentifier, autostart); }
/// <summary> /// Creates a new <see cref="IChannel" /> instance. /// </summary> /// <param name="channelDriver">The channel driver.</param> /// <returns> /// Returns a new <see cref="IChannel" /> instance. /// </returns> /// <exception cref="System.ArgumentNullException"> /// The exception that is thrown when <paramref name="channelDriver"/> is <c>null</c>. /// </exception> /// <exception cref="System.InvalidOperationException">Thrown when there is a failure to connect to the Bluetooth hub.</exception> public static IChannel Create(IChannelDriver channelDriver) { Contract.Requires<ArgumentNullException>(channelDriver != null, "channelDriver"); Contract.Ensures(Contract.Result<IChannel>() != null); var applicationIdentidier = string.Empty; Contract.Assume(applicationIdentidier.Length == 0); return Create(channelDriver, applicationIdentidier); }
/// <inheritdoc/> public void AddDriver(IChannelDriver d, int order) { drivers.Add(order, d); }
/// <summary> /// Load settings, open previously open instances, etc /// </summary> private void load() { // to enable deserializing types from plugins AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve; var appDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData); if (appDataDir != "") { appDataDir += "/netool"; if (!Directory.Exists(appDataDir)) { Directory.CreateDirectory(appDataDir); } try { using (var file = new FileStream(appDataDir + "/session.nest", FileMode.Open, FileAccess.Read)) { var formatter = new BinaryFormatter(); model = (MainModel)formatter.Deserialize(file); file.Close(); } } catch { model = new MainModel(); } } var invalidDrivers = new List <int>(); foreach (var driver in model.ChannelDrivers) { try { IChannelDriverPlugin plugin; itemID = Math.Max(itemID, driver.Key); if (channelDriverPlugins.TryGetValue(driver.Value.PluginID, out plugin)) { var pack = plugin.CreateChannelDriver(driver.Value.Settings); pack.Driver.Name = driver.Value.Name; channelDrivers.Add(driver.Key, pack.Driver); view.AddChannelDriver(driver.Key, pack); } } catch { invalidDrivers.Add(driver.Key); // TODO: some error reporting here } } foreach (var driver in invalidDrivers) { model.RemoveChannelDriver(driver); } var invalidInstances = new List <int>(); foreach (var instance in model.OpenInstances) { try { IProtocolPlugin plugin; itemID = Math.Max(itemID, instance.Key); if (protocolPlugins.TryGetValue(instance.Value.PluginID, out plugin)) { // temp log file - dont bother user with log file dialogs now var logger = new InstanceLogger(); logger.WritePluginID(plugin.ID); logger.WriteInstanceName(instance.Value.Name); var pack = plugin.CreateInstance(logger, instance.Value.Type, instance.Value.Settings); invalidDrivers.Clear(); foreach (var driver in instance.Value.Drivers) { IChannelDriver d = null; if (channelDrivers.TryGetValue(driver.Key, out d)) { pack.Controller.AddDriver(d, driver.Value); } else if (MessageBox.Show("Cannot load one of the attached drivers. Load the instance anyway?", "Missing Driver", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No) { throw new Exception("Missing driver"); } else { invalidDrivers.Add(driver.Key); } } foreach (var driver in invalidDrivers) { model.RemoveDriverFromInstance(instance.Key, driver); } bindInstanceEvents(pack.Controller.Instance); controllers.Add(instance.Key, new ControllerData(pack.Controller, true)); view.AddInstance(instance.Key, instance.Value.Name, pack.View); } } catch { invalidInstances.Add(instance.Key); } } foreach (var instance in invalidInstances) { model.RemoveInstance(instance); } }