Ejemplo n.º 1
0
 public NodeTelegram SetPayload(FieldBase64 Payload)
 {
     if (Payload == null)
     {
         throw new ArgumentNullException(m_PayloadName);
     }
     return(new NodeTelegram(this.SetField(new FieldIdentifier(m_PayloadName), Payload), ChildCollection));
 }
Ejemplo n.º 2
0
        public static NodeDevice StaticBuild()
        {
            FieldIdentifier code;
            FieldGuid typeId;
            FieldString address;
            FieldBase64 configuration;
            FieldDeviceName deviceName;

            code = new FieldIdentifier(CODE);
            typeId = new FieldGuid(TYPE_ID);
            address = new FieldString(string.Empty);
            configuration = new FieldBase64(string.Empty);
            deviceName = new FieldDeviceName(Resources.Strings.Unknown_Phidget_Name);

            NodeDevice device = NodeDevice.BuildWith(code, typeId, address, configuration, deviceName);

            return device;
        }
Ejemplo n.º 3
0
        public static NodeDevice StaticBuildHelper(string deviceName, int serialNumber, string code, string typeId, 
            int discreteInputs, int discreteOutputs, int analogInputs, int analogOutputs, int stringInputs, int stringOutputs,
            string analogOutputNameOverride, string discreteOutputNameOverride)
        {
            FieldIdentifier c;
            FieldGuid typ;
            FieldString address;
            FieldBase64 configuration;
            FieldDeviceName dName;

            c = new FieldIdentifier(code);
            typ = new FieldGuid(typeId);
            address = new FieldString(serialNumber.ToString());
            configuration = new FieldBase64(string.Empty);
            dName = new FieldDeviceName(deviceName);

            NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName);

            // Add the inputs
            var inputsMutable = new Collection<NodeDiscreteInput>();
            for (int i = 0; i < discreteInputs; i++)
            {
                inputsMutable.Add(NodeDiscreteInput.BuildWith(
                    new FieldIdentifier(Resources.Strings.Input + i),
                    new FieldString(i.ToString()),
                    new FieldSignalName(Resources.Strings.Input + " " + i)));
            }
            var inputs = new ReadOnlyCollection<NodeDiscreteInput>(inputsMutable);
            device = device.NodeDiscreteInputChildren.Append(inputs);

            var analogInputsMutable = new Collection<NodeAnalogInput>();
            for (int i = 0; i < analogInputs; i++)
            {
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                    new FieldIdentifier(Resources.Strings.AnalogInput + i),
                    new FieldString(i.ToString()),
                    new FieldSignalName(Resources.Strings.AnalogInput + " " + i)));
            }
            device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection<NodeAnalogInput>(analogInputsMutable));

            var stringInputsMutable = new Collection<NodeStringInput>();
            for (int i = 0; i < stringInputs; i++)
            {
                stringInputsMutable.Add(NodeStringInput.BuildWith(
                    new FieldIdentifier(Resources.Strings.StringInput + i),
                    new FieldString(i.ToString()),
                    new FieldSignalName(Resources.Strings.StringInput + " " + i)));
            }
            device = device.NodeStringInputChildren.Append(new ReadOnlyCollection<NodeStringInput>(stringInputsMutable));

            // Add the outputs
            var outputsMutable = new Collection<NodeDiscreteOutput>();
            for (int i = 0; i < discreteOutputs; i++)
            {
                outputsMutable.Add(NodeDiscreteOutput.BuildWith(
                    new FieldIdentifier(Resources.Strings.Output + i),
                    new FieldString(i.ToString()),
                    new FieldSignalName(discreteOutputNameOverride + " " + i)));
            }
            var outputs = new ReadOnlyCollection<NodeDiscreteOutput>(outputsMutable);
            device = device.NodeDiscreteOutputChildren.Append(outputs);

            var analogOutputsMutable = new Collection<NodeAnalogOutput>();
            for (int i = 0; i < analogOutputs; i++)
            {
                analogOutputsMutable.Add(NodeAnalogOutput.BuildWith(
                    new FieldIdentifier(Resources.Strings.AnalogOutput + i),
                    new FieldString(i.ToString()),
                    new FieldSignalName(analogOutputNameOverride + " " + i)));
            }
            device = device.NodeAnalogOutputChildren.Append(new ReadOnlyCollection<NodeAnalogOutput>(analogOutputsMutable));

            var stringOutputsMutable = new Collection<NodeStringOutput>();
            for (int i = 0; i < stringOutputs; i++)
            {
                stringOutputsMutable.Add(NodeStringOutput.BuildWith(
                    new FieldIdentifier(Resources.Strings.StringOutput + i),
                    new FieldString(i.ToString()),
                    new FieldSignalName(Resources.Strings.StringOutput + " " + i)));
            }
            device = device.NodeStringOutputChildren.Append(new ReadOnlyCollection<NodeStringOutput>(stringOutputsMutable));

            return device;
        }
Ejemplo n.º 4
0
 public NodeDevice SetConfiguration(FieldBase64 Configuration)
 {
     if (Configuration == null)
     {
         throw new ArgumentNullException(m_ConfigurationName);
     }
     return new NodeDevice(this.SetField(new FieldIdentifier(m_ConfigurationName), Configuration), ChildCollection);
 }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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();
            }
        }
Ejemplo n.º 7
0
 public static NodeRuntimeApplication BuildWith(
     FieldIdentifier Code, FieldGuid TypeId, FieldGuid RuntimeId,
     FieldString Address, FieldBase64 Configuration, FieldBool ExecuteOnStartup,
     NodePageCollection Logic, NodeDeviceConfiguration DeviceConfiguration)
 {
     var rta = NodeRuntimeApplication.BuildWith(
             Code, TypeId, RuntimeId, Address, Configuration, ExecuteOnStartup);
     rta = rta.SetLogic(Logic);
     return rta.SetDeviceConfiguration(DeviceConfiguration);
 }
Ejemplo n.º 8
0
        public static NodeRuntimeApplication BuildWith(
            FieldIdentifier Code, FieldGuid TypeId, FieldGuid RuntimeId,
            FieldString Address, FieldBase64 Configuration, FieldBool ExecuteOnStartup)
        {
            //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_RuntimeIdName), RuntimeId);
            mutableFields.Add(new FieldIdentifier(m_AddressName), Address);
            mutableFields.Add(new FieldIdentifier(m_ConfigurationName), Configuration);
            mutableFields.Add(new FieldIdentifier(m_ExecuteOnStartupName), ExecuteOnStartup);
            mutableFields.Add(new FieldIdentifier(m_TryModeName), new FieldBool(false));
            //Add Fields here: mutableFields.Add(new FieldIdentifier("Code"), Code);

            //build children
            KeyedNodeCollection<NodeBase> mutableChildren =
                new KeyedNodeCollection<NodeBase>();
            var pc = NodePageCollection.BuildWith(
                    new FieldPageCollectionName(m_LogicName)
                );
            pc = pc.SetLogicRoot(new FieldBool(true));
            mutableChildren.Add(pc);
            mutableChildren.Add(
                NodeDeviceConfiguration.BuildWith(
                    new ReadOnlyCollection<NodeDriver>(new Collection<NodeDriver>())
                ));
            //Add Children here: mutableChildren.Add(SomeChild);

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

            return Builder;
        }
Ejemplo n.º 9
0
        public static NodeDevice StaticBuildHelper(string deviceName, string typeId, Guid instanceId, string code,
            int buttons, int axes, int povhats)
        {
            FieldIdentifier c;
            FieldGuid typ;
            FieldString address;
            FieldBase64 configuration;
            FieldDeviceName dName;

            c = new FieldIdentifier(code);
            typ = new FieldGuid(typeId);
            address = new FieldString(instanceId.ToString());
            configuration = new FieldBase64(string.Empty);
            dName = new FieldDeviceName(deviceName);

            NodeDevice device = NodeDevice.BuildWith(c, typ, address, configuration, dName);

            // Add the inputs
            var inputsMutable = new Collection<NodeDiscreteInput>();
            for (int i = 0; i < buttons; i++)
            {
                int buttonNumber = i + 1;
                inputsMutable.Add(NodeDiscreteInput.BuildWith(
                    new FieldIdentifier(Resources.Strings.Button + buttonNumber),
                    new FieldString(i.ToString()),
                    new FieldSignalName(Resources.Strings.Button + " " + buttonNumber)));
            }
            var inputs = new ReadOnlyCollection<NodeDiscreteInput>(inputsMutable);
            device = device.NodeDiscreteInputChildren.Append(inputs);

            var analogInputsMutable = new Collection<NodeAnalogInput>();
            for (int i = 0; i < axes; i++)
            {
                if (i == 3) break; // only supports up to 3 axes

                int axisNumber = i + 1;
                string axisName =
                    axisNumber == 1 ? "X" :
                    axisNumber == 2 ? "Y" :
                    axisNumber == 3 ? "Z" :
                    null;

                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                    new FieldIdentifier(axisName),
                    new FieldString(axisName),
                    new FieldSignalName(axisName)));

                string rotationName = "Rotation" + axisName;
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                    new FieldIdentifier(rotationName),
                    new FieldString(rotationName),
                    new FieldSignalName(rotationName)));

            }
            for (int i = 0; i < povhats; i++)
            {
                int povNumber = i + 1;
                analogInputsMutable.Add(NodeAnalogInput.BuildWith(
                    new FieldIdentifier(Resources.Strings.PoVHat + povNumber.ToString()),
                    new FieldString(i.ToString()),
                    new FieldSignalName(Resources.Strings.PoVHat + " " + povNumber.ToString())));
            }
            device = device.NodeAnalogInputChildren.Append(new ReadOnlyCollection<NodeAnalogInput>(analogInputsMutable));

            return device;
        }
Ejemplo n.º 10
0
        public static NodeTelegram BuildWith(FieldGuid MessageId, FieldString MessageType, FieldBase64 Payload)
        {
            //build fields
            Dictionary <FieldIdentifier, FieldBase> mutableFields =
                new Dictionary <FieldIdentifier, FieldBase>();

            mutableFields.Add(new FieldIdentifier(m_MessageIdName), MessageId);
            mutableFields.Add(new FieldIdentifier(m_MessageTypeName), MessageType);
            mutableFields.Add(new FieldIdentifier(m_PayloadName), Payload);
            //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
            NodeTelegram Builder = new NodeTelegram(
                new ReadOnlyDictionary <FieldIdentifier, FieldBase>(mutableFields),
                new ReadOnlyCollection <NodeBase>(mutableChildren));

            return(Builder);
        }
Ejemplo n.º 11
0
 public NodeTelegram SetPayload(FieldBase64 Payload)
 {
     if (Payload == null)
     {
         throw new ArgumentNullException(m_PayloadName);
     }
     return new NodeTelegram(this.SetField(new FieldIdentifier(m_PayloadName), Payload), ChildCollection);
 }
Ejemplo n.º 12
0
        public static NodeTelegram BuildWith(FieldGuid MessageId, FieldString MessageType, FieldBase64 Payload)
        {
            //build fields
            Dictionary<FieldIdentifier, FieldBase> mutableFields =
                new Dictionary<FieldIdentifier, FieldBase>();
            mutableFields.Add(new FieldIdentifier(m_MessageIdName), MessageId);
            mutableFields.Add(new FieldIdentifier(m_MessageTypeName), MessageType);
            mutableFields.Add(new FieldIdentifier(m_PayloadName), Payload);
            //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
            NodeTelegram Builder = new NodeTelegram(
                new ReadOnlyDictionary<FieldIdentifier, FieldBase>(mutableFields),
                new ReadOnlyCollection<NodeBase>(mutableChildren));

            return Builder;
        }