Exemplo n.º 1
0
 public DeviceItem(ISolutionItem parent, NodeDevice device)
     : base(parent, device.DeviceName.ToString())
 {
     ContextMenu = extensionService.Sort(contextMenu);
     Device = device;
     HeaderIsEditable = true;
 }
Exemplo n.º 2
0
        public static NodeDevice BuildWith(
            FieldIdentifier Code, FieldGuid TypeId,
            FieldString Address, FieldBase64 Configuration,
            FieldDeviceName DeviceName)
        {
            //build fields
            Dictionary <FieldIdentifier, FieldBase> mutableFields =
                new Dictionary <FieldIdentifier, FieldBase>();

            mutableFields.Add(new FieldIdentifier(m_CodeName), Code);
            mutableFields.Add(new FieldIdentifier(m_TypeIdName), TypeId);
            mutableFields.Add(new FieldIdentifier(m_AddressName), Address);
            mutableFields.Add(new FieldIdentifier(m_ConfigurationName), Configuration);
            mutableFields.Add(new FieldIdentifier(m_DeviceNameName), DeviceName);
            //Add Fields here: mutableFields.Add(new FieldIdentifier(m_CodeName), Code);

            //build children
            KeyedNodeCollection <NodeBase> mutableChildren =
                new KeyedNodeCollection <NodeBase>();
            //Add Children here: mutableChildren.Add(SomeChild);

            //build node
            NodeDevice Builder = new NodeDevice(
                new ReadOnlyDictionary <FieldIdentifier, FieldBase>(mutableFields),
                new ReadOnlyCollection <NodeBase>(mutableChildren));

            return(Builder);
        }
Exemplo n.º 3
0
        public static NodeDevice BuildWith(
            FieldIdentifier Code, FieldGuid TypeId,
            FieldString Address, FieldBase64 Configuration,
            FieldDeviceName DeviceName)
        {
            //build fields
            Dictionary<FieldIdentifier, FieldBase> mutableFields =
                new Dictionary<FieldIdentifier, FieldBase>();
            mutableFields.Add(new FieldIdentifier(m_CodeName), Code);
            mutableFields.Add(new FieldIdentifier(m_TypeIdName), TypeId);
            mutableFields.Add(new FieldIdentifier(m_AddressName), Address);
            mutableFields.Add(new FieldIdentifier(m_ConfigurationName), Configuration);
            mutableFields.Add(new FieldIdentifier(m_DeviceNameName), DeviceName);
            //Add Fields here: mutableFields.Add(new FieldIdentifier(m_CodeName), Code);

            //build children
            KeyedNodeCollection<NodeBase> mutableChildren =
                new KeyedNodeCollection<NodeBase>();
            //Add Children here: mutableChildren.Add(SomeChild);

            //build node
            NodeDevice Builder = new NodeDevice(
                new ReadOnlyDictionary<FieldIdentifier, FieldBase>(mutableFields),
                new ReadOnlyCollection<NodeBase>(mutableChildren));

            return Builder;
        }
Exemplo n.º 4
0
            public void SetUserStatusMonitor(NodeDevice device, IEnumerable<TwitterStatus> statuses)
            {
                if (device == null)
                {
                    throw new ArgumentNullException("device");
                }

                lock (this)
                {
                    if (!m_UserStatusMonitorResults.ContainsKey(device))
                    {
                        m_UserStatusMonitorResults.Add(device, statuses);
                    }
                    else
                    {
                        m_UserStatusMonitorResults[device] = statuses;
                    }
                }
            }
Exemplo n.º 5
0
            public void SetIsRunning(NodeDevice device, bool value)
            {
                if (device == null)
                {
                    throw new ArgumentNullException("device");
                }

                lock (this)
                {
                    if (!m_IsRunning.ContainsKey(device))
                    {
                        m_IsRunning.Add(device, value);
                    }
                    else
                    {
                        m_IsRunning[device] = value;
                    }
                }
            }
Exemplo n.º 6
0
            public bool IsRunning(NodeDevice device)
            {
                if (device == null)
                {
                    throw new ArgumentNullException("device");
                }

                bool retVal;
                lock (this)
                {
                    if (!m_IsRunning.ContainsKey(device))
                    {
                        SetIsRunning(device, false);
                    }
                    retVal = m_IsRunning[device];
                }
                return retVal;
            }
Exemplo n.º 7
0
            public ReadOnlyCollection<TwitterStatus> GetUserStatusMonitor(NodeDevice device)
            {
                if (device == null)
                {
                    throw new ArgumentNullException("device");
                }

                ReadOnlyCollection<TwitterStatus> retVal;
                lock (this)
                {
                    if (m_UserStatusMonitorResults.ContainsKey(device) && m_UserStatusMonitorResults[device] != null)
                    {
                        retVal = new ReadOnlyCollection<TwitterStatus>(m_UserStatusMonitorResults[device].ToList());
                    }
                    else
                    {
                        retVal = new ReadOnlyCollection<TwitterStatus>(new List<TwitterStatus>());
                    }
                }
                return retVal;
            }
Exemplo n.º 8
0
        private void kickOffBackgroundRequestIfNecessary(NodeDevice device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            if (deviceShouldBeRunning(device) && !deviceState.IsRunning(device))
            {
                // start it
                deviceState.SetIsRunning(device, true);
                string[] addressParts = device.Address.ToString().Split(new string[] { AbstractTwitterDevice.ADDRESS_SEPARATOR }, StringSplitOptions.None);
                string token = new FieldBase64(addressParts[0]).Decode();
                string tokenSecret = new FieldBase64(addressParts[1]).Decode();

                var twitter = FluentTwitter.CreateRequest()
                    .AuthenticateWith(TwitterConsumer.ConsumerKey, TwitterConsumer.ConsumerSecret, token, tokenSecret)
                    .Statuses().OnUserTimeline();
                twitter.CallbackTo((sender, result, userstate) =>
                {
                    deviceState.SetUserStatusMonitor(device, result.AsStatuses());
                    // Implement some rate limiting
                    long waitSeconds100Percent = 20;
                    if (result.RateLimitStatus.RemainingHits > 0)
                    {
                        long secondsBeforeReset = (long)result.RateLimitStatus.ResetTime.Subtract(DateTime.Now).TotalSeconds;
                        waitSeconds100Percent = secondsBeforeReset / result.RateLimitStatus.RemainingHits;
                    }
                    long waitSecondsMinimum = 20;
                    if (result.RateLimitStatus.HourlyLimit > 0)
                    {
                        waitSecondsMinimum = 3600 / result.RateLimitStatus.HourlyLimit;
                    }
                    long waitSeconds = Math.Max((long)((1/50.Percent()) * waitSeconds100Percent), waitSecondsMinimum); // limits to a certain percentage, with a floor
                    System.Threading.Thread.Sleep((int)(waitSeconds * 1000));
                    deviceState.SetIsRunning(device, false);
                });
                twitter.BeginRequest();
            }
        }
Exemplo n.º 9
0
        private bool deviceShouldBeRunning(NodeDevice device)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            return device.Address.ToString() != string.Empty && Running;
        }
Exemplo n.º 10
0
 private void scanJoystickInputs(NodeDevice device, Joystick joystick)
 {
     var state = joystick.GetCurrentState();
     foreach (var discreteInput in device.NodeDiscreteInputChildren)
     {
         int buttonIndex = Convert.ToInt32(discreteInput.Address.ToString());
         var buttons = state.GetButtons();
         discreteInput.Value = buttons[buttonIndex];
     }
     foreach (var analogInput in device.NodeAnalogInputChildren)
     {
         int rawValue = 0;
         if (analogInput.Code.ToString().StartsWith(Resources.Strings.PoVHat))
         {
             var povIndex = Convert.ToInt32(analogInput.Address.ToString());
             rawValue = state.GetPointOfViewControllers()[povIndex];
         }
         else
         {
             switch (analogInput.Address.ToString())
             {
                 case "X":
                     rawValue = state.X;
                     break;
                 case "Y":
                     rawValue = state.Y;
                     break;
                 case "Z":
                     rawValue = state.Z;
                     break;
                 case "RotationX":
                     rawValue = state.RotationX;
                     break;
                 case "RotationY":
                     rawValue = state.RotationY;
                     break;
                 case "RotationZ":
                     rawValue = state.RotationZ;
                     break;
             }
         }
         analogInput.Value = rawValue;
     }
 }
Exemplo n.º 11
0
 public PhidgetsDevice(Phidget phidget)
 {
     m_Phidget = phidget;
     m_Device = buildDevice();
 }
Exemplo n.º 12
0
        private void scanJoystickInputs(NodeDevice device)
        {
            var address = device.Address.ToString();
            Guid instanceId = Guid.Parse(address);
            if (deviceAttached(instanceId))
            {
                Joystick joystick;
                if (this.acquiredJoysticks.ContainsKey(instanceId))
                {
                    joystick = this.acquiredJoysticks[instanceId];
                }
                else
                {
                    joystick = new Joystick(this.directInput, instanceId);
                    joystick.Acquire();
                    this.acquiredJoysticks.Add(instanceId, joystick);
                }

                scanJoystickInputs(device, joystick);
            }
            else
            {
                clearJoystickInputs(device);
                if (this.acquiredJoysticks.ContainsKey(instanceId))
                {
                    var joystick = this.acquiredJoysticks[instanceId];
                    joystick.Unacquire();
                    joystick.Dispose();
                    this.acquiredJoysticks.Remove(instanceId);
                }
            }
        }
Exemplo n.º 13
0
 private void clearJoystickInputs(NodeDevice device)
 {
     foreach (var discreteInput in device.NodeDiscreteInputChildren)
     {
         discreteInput.Value = false;
     }
     foreach (var analogInput in device.NodeAnalogInputChildren)
     {
         analogInput.Value = 0M;
     }
 }
Exemplo n.º 14
0
 private TextLCD OpenTextLCD(NodeDevice device)
 {
     string address = device.Address.ToString();
     if (address == string.Empty)
     {
         throw new ArgumentOutOfRangeException();
     }
     if (!textLCDs.ContainsKey(address))
     {
         textLCDs.Add(address, new TextLCD());
         textLCDs[address].open(Int32.Parse(address));
     }
     return textLCDs[address];
 }
Exemplo n.º 15
0
 private Servo OpenServo(NodeDevice device)
 {
     string address = device.Address.ToString();
     if (address == string.Empty)
     {
         throw new ArgumentOutOfRangeException();
     }
     if (!servos.ContainsKey(address))
     {
         servos.Add(address, new Servo());
         servos[address].open(Int32.Parse(address));
     }
     return servos[address];
 }
Exemplo n.º 16
0
 private InterfaceKit OpenInterfaceKit(NodeDevice device)
 {
     string address = device.Address.ToString();
     if (address == string.Empty)
     {
         throw new ArgumentOutOfRangeException();
     }
     if (!ifKits.ContainsKey(address))
     {
         ifKits.Add(address, new InterfaceKit());
         ifKits[address].open(Int32.Parse(address));
     }
     return ifKits[address];
 }