public DeviceItem(ISolutionItem parent, NodeDevice device) : base(parent, device.DeviceName.ToString()) { ContextMenu = extensionService.Sort(contextMenu); Device = device; HeaderIsEditable = true; }
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); }
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; }
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; } } }
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; } } }
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; }
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; }
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(); } }
private bool deviceShouldBeRunning(NodeDevice device) { if (device == null) { throw new ArgumentNullException("device"); } return device.Address.ToString() != string.Empty && Running; }
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; } }
public PhidgetsDevice(Phidget phidget) { m_Phidget = phidget; m_Device = buildDevice(); }
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); } } }
private void clearJoystickInputs(NodeDevice device) { foreach (var discreteInput in device.NodeDiscreteInputChildren) { discreteInput.Value = false; } foreach (var analogInput in device.NodeAnalogInputChildren) { analogInput.Value = 0M; } }
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]; }
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]; }
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]; }