Esempio n. 1
0
        public ResponseFunc CallFunctionRaw(string funcName, string args)
        {
            String payload = String.Format(payloadCoreAPICallFunction,
                                           HttpUtility.UrlEncode(AccessToken),
                                           HttpUtility.UrlEncode(args));

            HttpWebRequest request = GetHttpWebRequest(webMethod.POST, String.Format(addrCoreAPICallFunction, this.CoreID, funcName), payload);

            object       jsonObj      = GetHttpWebResponseAsJSONData(request, typeof(ResponseFunc));
            ResponseFunc jsonResponse = jsonObj as ResponseFunc;

            // check for not connected
            if (jsonResponse.Connected == false)
            {
                throw new ApplicationException("SparkCore not connected.");
            }

            return(jsonResponse);
        }
Esempio n. 2
0
        public override void Test()
        {
            int          SumR = 0;
            int          MulR = 0;
            ResponseFunc f    = (RClay rc, object cp) => {
                int A = rc.GetSignals <int>("X");
                int B = rc.GetSignals <int>("Y");
                rc["Z"] = SumR = A + B;
            };

            ResponseFunc f2 = (RClay rc, object cp) => {
                int A = rc.GetSignals <int>("X");
                int B = rc.GetSignals <int>("Y");
                rc["Z"] = MulR = A * B;
            };

            RClay Add = new RClay(new Dictionary <string, object>()
            {
                { "Response", f },
                { "ConnectPoints", new List <Object> {
                      "X", "Y"
                  } }
            });

            RClay Mul = new RClay(new Dictionary <string, object>()
            {
                { "Response", f2 },
                { "ConnectPoints", new List <Object> {
                      "X", "Y"
                  } }
            });

            ///Conduit.CreateLink(Add, "Z", Mul, "X");

            SClay s = new SClay(new Dictionary <string, object>
            {
                {
                    "layoutMap", new List <SClayLayout> {
                        new SClayLayout {
                            HostConnectPoint  = "A",
                            AtConnectionPoint = "X",
                            WithClay          = Add
                        },
                        new SClayLayout {
                            HostConnectPoint  = "B",
                            AtConnectionPoint = "Y",
                            WithClay          = Add
                        },
                        new SClayLayout {
                            HostConnectPoint  = "SUM",
                            AtConnectionPoint = "Z",
                            WithClay          = Add
                        },
                        new SClayLayout {
                            HostConnectPoint  = "SUM",
                            AtConnectionPoint = "X",
                            WithClay          = Mul
                        },
                        new SClayLayout {
                            HostConnectPoint  = "C",
                            AtConnectionPoint = "Y",
                            WithClay          = Mul
                        }
                    }
                }
            });

            Clay.MakeConnection(s, this, "A");
            Clay.MakeConnection(s, this, "B");
            Clay.MakeConnection(s, this, "C");


            s["A"] = 2;

            Assert(SumR, 0);
            s["B"] = 3;
            Thread.Sleep(100);
            Assert(SumR, 5);

            s["C"] = 8;
            Thread.Sleep(100);
            Assert(MulR, 40);

            s["C"] = 4;
            Thread.Sleep(100);
            Assert(MulR, 20);


            s["A"] = 3;
            Thread.Sleep(100);
            Assert(SumR, 6);
            Assert(MulR, 24);

            s["B"] = 9;
            Thread.Sleep(100);
            Assert(SumR, 12);
            Assert(MulR, 48);
        }
Esempio n. 3
0
        public override void Test()
        {
            int          Result  = 0;
            int          Result2 = 0;
            int          Result3 = 0;
            ResponseFunc f       = (RClay rc, object cp) => {
                int A = Result = rc.GetSignals <int>("X");
                int B = Result = rc.GetSignals <int>("Y");
                Result = A + B;
            };

            ResponseFunc f2 = (RClay rc, object cp) =>
            {
                Result2 = rc.GetSignals <int>("A");
            };

            ResponseFunc f3 = (RClay rc, object cp) =>
            {
                Result3 += rc.GetSignals <int>("A");
            };

            RClay R = new RClay(new Dictionary <string, object>()
            {
                { "Response", f },
                { "ConnectPoints", new List <Object> {
                      "X", "Y"
                  } }
            });

            RClay R2 = new RClay(new Dictionary <string, object> {
                { "Response", f2 },
                { "ConnectPoints", new List <Object> {
                      "A"
                  } }
            });

            RClay R3 = new RClay(new Dictionary <string, object> {
                { "Response", f3 },
                { "ConnectPoints", new List <Object> {
                      "A"
                  } }
            });

            Conduit con = Conduit.CreateLink(this, "X", R, "X");

            con.Connect(R, "Y");
            con.Connect(R2, "A");

            con.ParallelTrx = false;             //Disable parallel transmission

            Signal = 1;

            Assert(Result, 2);
            Assert(Result2, 1);
            Signal = 2;

            Assert(Result, 4);
            Assert(Result2, 2);


            //con.ParallelTrx = true; //Enable parallel transmission
            Signal = 3;
            Thread.Sleep(100);             //Wait

            Assert(Result, 6);
            Assert(Result2, 3);

            Conduit con2 = Conduit.CreateLink(con, "RANDOM");

            con2.Connect(R3, "A");
            con2.Connect(con, "CDE");


            Signal = 7;
            Thread.Sleep(100);             //Wait
            Assert(Result, 14);
            Assert(Result2, 7);
            Signal = 7;
            //No Bounce
            Assert(Result3, 7);
        }
Esempio n. 4
0
        public override void Test()
        {
            RClay other = new RClay();

            int          Result = 0;
            int          Inited = 0;
            ResponseFunc r      = (RClay rc, object cp) => {
                int A = rc.GetSignals <int>("A");
                int B = rc.GetSignals <int>("B");
                Result = A + B;
            };
            InitFunc i = (RClay rc) => { Inited++; };

            RClay c = new RClay(new Dictionary <string, object> {
                { "P1", 1 },
                { "P2", 2 },
                { "ConnectPoints", new List <object> {
                      "A", "B"
                  } },
                { "Response", r },
                { "Init", i }
            });

            c.onConnection(this, "A");
            c.onConnection(this, "B");

            c.onCommunication(this, "A", 1);
            //Make sure that if clay has not collected every signal
            //There will be no response
            Assert(Result, 0);

            c.onCommunication(this, "B", 2);

            Assert(Result, 3);

            //Randomly check Init already got called and got called once only
            Assert(Inited, 1);

            c.onCommunication(this, "A", 2);

            Assert(Result, 4);

            //Make sure signal from stranger does not count
            c.onCommunication(other, "A", 6);
            Assert(Result, 4);

            c.Stage = true;

            c.onCommunication(this, "B", 4);
            Assert(Result, 6);

            //Randomly check Init already got called and got called once only
            Assert(Inited, 1);

            c.onCommunication(this, "B", 7);
            //Make sure that Stage did clear all signals
            //And result should be the same as the previous
            Assert(Result, 6);

            //Assign information to B again
            c.onCommunication(this, "B", 8);
            // Make sure no change
            //And result should be the same as the previous
            Assert(Result, 6);

            c.onCommunication(this, "A", 8);
            Assert(Result, 16);

            c.onCommunication(this, "B", 1);
            //Make sure that all signals got cleared again
            //And the result is still the same because response has not been called
            Assert(Result, 16);
        }