예제 #1
0
 /// <summary>
 /// Get the hashcode of this object.
 /// </summary>
 public override Int32 GetHashCode()
 {
     unchecked
     {
         return(Plug.GetHashCode() * 7 ^
                Lockable.GetHashCode() * 5 ^
                CableAttached.GetHashCode() * 3 ^
                CableLength.GetHashCode());
     }
 }
예제 #2
0
        /// <summary>
        /// Compares two SocketOutlet for equality.
        /// </summary>
        /// <param name="SocketOutlet">An SocketOutlet to compare with.</param>
        /// <returns>True if both match; False otherwise.</returns>
        public Boolean Equals(SocketOutlet SocketOutlet)
        {
            if ((Object)SocketOutlet == null)
            {
                return(false);
            }

            return(Plug.Equals(SocketOutlet.Plug) &&
                   Lockable.Equals(SocketOutlet.Lockable) &&
                   CableAttached.Equals(SocketOutlet.CableAttached) &&
                   CableLength.Equals(SocketOutlet.CableLength));
        }
예제 #3
0
        private bool Initialise()
        {
            bool result = false;

            var devices = HidDevices.Enumerate(vid, pid);

            if (devices.Count() == 0)
            {
                configurationDevice = null;
                inputDevice         = null;
                result     = false;
                isDetected = false;
            }
            else
            {
                isDetected          = true;
                configurationDevice = devices.FirstOrDefault(x => x.DevicePath.Contains("&col01"));
                inputDevice         = devices.FirstOrDefault(x => x.DevicePath.Contains("&col02"));

                if (configurationDevice != null && inputDevice != null)
                {
                    var attached = Observable.FromEvent <InsertedEventHandler, Unit>(h => () => h(Unit.Default), h => configurationDevice.Inserted += h, h => configurationDevice.Inserted -= h);
                    var detached = Observable.FromEvent <RemovedEventHandler, Unit>(h => () => h(Unit.Default), h => configurationDevice.Removed += h, h => configurationDevice.Removed -= h);

                    CableAttached = attached.Select(s => true).Merge(detached.Select(s => false));

                    CableAttached.Subscribe(async connected =>
                    {
                        if (connected)
                        {
                            await Connect();
                        }
                        else
                        {
                            cancellationSource.Cancel();
                            inputDevice.CloseDevice();
                            configurationDevice.CloseDevice();
                            isConnected.OnNext(false);
                        }
                    });

                    configurationIdpInterface = new IdpInterface();

                    inputIdpInterface = new IdpInterface();

                    commandManager = new CommandManager();

                    commandManager.RegisterInterface(configurationIdpInterface);
                    commandManager.RegisterInterface(inputIdpInterface);

                    InitialiseCommands();

                    packetStream = inputIdpInterface.PacketParsed.Merge(configurationIdpInterface.PacketParsed);

                    Task.Run(() => Connect()).Wait();

                    result = true;
                }
            }

            return(result);
        }