Example #1
0
 public NodeConnection SetCode(FieldIdentifier Code)
 {
     if (Code == null)
     {
         throw new ArgumentNullException(m_CodeName);
     }
     return new NodeConnection(this.SetField(new FieldIdentifier(m_CodeName), Code), ChildCollection);
 }
 public FieldInstructionType(FieldIdentifier language, FieldIdentifier library, FieldIdentifier code)
     : base(language.ToString() + SEPARATOR + 
     library.ToString() + SEPARATOR + 
     code.ToString())
 {
     m_Language = language;
     m_Library = library;
     m_Code = code;
 }
        public FieldInstructionType(String resurrect)
            : base(resurrect)
        {
            // The base class checks the syntax, so we can assume this works
            string[] parts = resurrect.Split(new string[] { SEPARATOR }, StringSplitOptions.None);

            m_Language = new FieldIdentifier(parts[0]);
            m_Library = new FieldIdentifier(parts[1]);
            m_Code = new FieldIdentifier(parts[2]);
        }
Example #4
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;
        }
Example #5
0
        public static NodeConnection BuildWith(FieldIdentifier Code)
        {
            //build fields
            Dictionary<FieldIdentifier, FieldBase> mutableFields =
                new Dictionary<FieldIdentifier, FieldBase>();
            mutableFields.Add(new FieldIdentifier(m_CodeName), Code);

            //build children
            KeyedNodeCollection<NodeBase> mutableChildren =
                new KeyedNodeCollection<NodeBase>();

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

            return Builder;
        }
Example #6
0
        internal static NodePeer BuildWith(FieldIdentifier Code)
        {
            //build fields
            Dictionary<FieldIdentifier, FieldBase> mutableFields =
                new Dictionary<FieldIdentifier, FieldBase>();
            mutableFields.Add(new FieldIdentifier(m_CodeName), Code);

            //build children
            KeyedNodeCollection<NodeBase> mutableChildren =
                new KeyedNodeCollection<NodeBase>();

            //build node
            NodePeer Builder = new NodePeer(
                new ReadOnlyDictionary<FieldIdentifier, FieldBase>(mutableFields),
                new ReadOnlyCollection<NodeBase>(mutableChildren), 
                true /* peers built by the Communication manager are local */);

            return Builder;
        }
 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);
 }
        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;
        }
Example #9
0
        public static NodeAnalogInput BuildWith(FieldIdentifier Code, FieldString Address, FieldSignalName InputName)
        {
            //build fields
            Dictionary<FieldIdentifier, FieldBase> mutableFields =
                new Dictionary<FieldIdentifier, FieldBase>();
            mutableFields.Add(new FieldIdentifier(m_CodeName), Code);
            mutableFields.Add(new FieldIdentifier(m_AddressName), Address);
            mutableFields.Add(new FieldIdentifier(m_ForcedName), new FieldBool(false));
            mutableFields.Add(new FieldIdentifier(m_ForcedValueName), new FieldConstant(FieldDataType.DataTypeEnum.NUMBER, FieldDataType.DefaultValue(FieldDataType.DataTypeEnum.NUMBER)));
            mutableFields.Add(new FieldIdentifier(m_InputNameName), InputName);
            //Add Fields here: mutableFields.Add(new FieldIdentifier(m_CodeName), Code);

            //build children
            KeyedNodeCollection<NodeBase> mutableChildren =
                new KeyedNodeCollection<NodeBase>();
            mutableChildren.Add(NodeSignal.BuildWith(
                InputName, new FieldDataType(FieldDataType.DataTypeEnum.NUMBER),
                new FieldBool(false), new FieldConstant(FieldDataType.DataTypeEnum.NUMBER, FieldDataType.DefaultValue(FieldDataType.DataTypeEnum.NUMBER))));
            //Add Children here: mutableChildren.Add(SomeChild);

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

            return Builder;
        }
 public NodeInstructionGroup SetLanguage(FieldIdentifier Language)
 {
     if (Language == null)
     {
         throw new ArgumentNullException(m_LanguageName);
     }
     return new NodeInstructionGroup(this.SetField(new FieldIdentifier(m_LanguageName), Language), ChildCollection);
 }
        public static NodeInstructionGroup BuildWith(FieldIdentifier Language)
        {
            //build fields
            Dictionary<FieldIdentifier, FieldBase> mutableFields =
                new Dictionary<FieldIdentifier, FieldBase>();
            mutableFields.Add(new FieldIdentifier(m_LanguageName), Language);
            mutableFields.Add(new FieldIdentifier(m_CommentName), new FieldString());
            //Add Fields here: mutableFields.Add(new FieldIdentifier(m_CodeName), Code);

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

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

            return Builder;
        }
        private static void ServerThreadStart(object o)
        {
            TcpClient client = o as TcpClient;

            SslStream sslStream = new SslStream(client.GetStream(),
                false, //leave inner stream open
                new RemoteCertificateValidationCallback(CertificateValidationCallback)
                );

            bool authenticationPassed = true;
            try
            {
                X509Certificate cert = GetServerCert(SERVER_CERT_FILENAME, SERVER_CERT_PASSWORD);
                sslStream.AuthenticateAsServer(
                    cert,
                    true, //client cert required 
                    SslProtocols.Default,
                    false); //check for revoked cert
            }
            catch (AuthenticationException)
            {
                authenticationPassed = false;
            }
            if (authenticationPassed)
            {
                FieldIdentifier Code = new FieldIdentifier("Incoming_" + new FieldGuid().ToString().Replace("-","_"));
                NodeConnection newConnection = NodeConnection.BuildWith(Code);
                OnNewIncomingConnection(newConnection);
                newConnection.ThreadStart(sslStream); //essentially blocks until the connection dies
            }
        }
        public static NodeConnection StartOutgoingConnection(FieldIdentifier Code, string hostName, int port)
        {
            if (hostName == null)
            {
                throw new ArgumentNullException("hostName");
            }
            if (port <= 0)
            {
                throw new ArgumentOutOfRangeException("port");
            }

            TcpClient client = new TcpClient();
            client.Connect(hostName, port);

            SslStream sslStream = new SslStream(client.GetStream(),
                false,
                new RemoteCertificateValidationCallback(CertificateValidationCallback),
                new LocalCertificateSelectionCallback(CertificateSelectionCallback));

            bool authenticationPassed = true;
            try
            {
                string serverName = System.Environment.MachineName;

                X509Certificate cert = GetServerCert(SERVER_CERT_FILENAME, SERVER_CERT_PASSWORD);
                X509CertificateCollection certs = new X509CertificateCollection();
                certs.Add(cert);

                sslStream.AuthenticateAsClient(
                    serverName,
                    certs,
                    SslProtocols.Default,
                    false); // check cert revokation
            }
            catch (AuthenticationException)
            {
                authenticationPassed = false;
            }
            if (authenticationPassed)
            {
                NodeConnection newConnection = NodeConnection.BuildWith(Code);
                ThreadPool.QueueUserWorkItem(new WaitCallback(newConnection.ThreadStart), sslStream);

                return newConnection;
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// Registers a new local peer.  The calling function has to pass
        /// in a Code that is a unique name for the peer.  No other peer
        /// by this name can exist locally.  Returns null if it already 
        /// exists, or a new NodePeer object if successful.
        /// </summary>
        /// <param name="Code">Unique name for the new peer</param>
        /// <returns></returns>
        public static NodePeer RegisterLocalPeer(FieldIdentifier Code)
        {
            if (Code == null)
            {
                throw new ArgumentNullException("Code");
            }

            lock (Instance.m_localPeerList_Lock)
            {
                //make sure "Local.{thisCode}" doesn't exist yet
                //(no duplicate peer names)
                bool found = false;
                foreach (NodePeer p in Instance.m_localPeerList.Peers)
                {
                    if (p.Code == Code)
                    {
                        found = true;
                        break;
                    }
                }
                if (found)
                {
                    return null;
                }
                else
                {
                    NodePeer newPeer = NodePeer.BuildWith(Code);
                    LocalPeerList = LocalPeerList.Peers.Append(newPeer);
                    return newPeer;
                }
            }
        }
Example #15
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;
        }
Example #16
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;
        }
        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;
        }