Beispiel #1
0
        public void StartModuleResponseTest()
        {
            try
            {
                // arrange
                StartModuleResponse smResponse = new StartModuleResponse(moduleId: "foo-bar_cheese-Module-v1-0",
                                                                         variantId: "503f191e8fcc19729de860ea", caseId: "5d9300d0-1574-4ae5-9d19-4e896b959f1c", userId: "userId",
                                                                         kpiId: "cheese-taste-kpi", status: ModuleStatus.Processing);
                var    message  = File.ReadAllText(@"../../TestData/Json/ModuleResponse/StartModuleResponse.txt");
                object obj      = JsonConvert.DeserializeObject(message);
                string expected = JsonConvert.SerializeObject(obj);

                // act
                string actual = Serialize.ToJsonString(smResponse);

                // assert
                Assert.AreEqual(expected, actual, false, "\nNot Json-serialized correctly:\n\n" + expected + "\n\n" + actual); //TODO is unordered => makes comparisson hard.
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Beispiel #2
0
        static void StartModuleResponseExemple()
        {
            //This module's id
            string moduleId = "foo-bar_cheese-Module-v1-0";

            //The dashboard message recieved (as a json-string)
            string message = "{" +
                             "\"type\": \"request\"," +
                             "\"method\": \"startModule\"," +
                             "\"moduleId\": \"foo-bar_cheese-Module-v1-0\"," +
                             "\"variantId\": \"503f191e8fcc19729de860ea\"," +
                             "\"kpiId\": \"cheese-taste-kpi\"," +
                             "\"inputData\": {" +
                             "\"cheese-type\": \"alp-kase\"," +
                             "\"age\": 2.718" +
                             "}" +
                             "}";
            //Message reconstructed into a .Net object.
            StartModuleRequest recievedMessage = Deserialize <StartModuleRequest> .JsonString(message);

            //Is this message meant for me?
            if (recievedMessage.moduleId == moduleId)
            {
                //For the selected kpi, create a input specification describing what data
                //the module need in order to calculate the selected kpi.
                Ecodistrict.Messaging.Output.Outputs outputs = new Ecodistrict.Messaging.Output.Outputs();
                if (recievedMessage.kpiId == "cheese-taste-kpi")
                {
                    //Inform the dashboard that you have started calculating
                    StartModuleResponse mResponse = new StartModuleResponse(
                        moduleId: recievedMessage.moduleId,
                        variantId: recievedMessage.variantId,
                        caseId: recievedMessage.caseId,
                        userId: recievedMessage.userId,
                        kpiId: recievedMessage.kpiId,
                        status: ModuleStatus.Processing);
                    //Send the response message...

                    //Do your calculations...


                    //Add the result in outputs
                    //E.g.
                    Ecodistrict.Messaging.Output.Output otp = new Ecodistrict.Messaging.Output.Kpi(
                        value: 99,
                        info: "Cheese tastiness",
                        unit: "ICQU (International Cheese Quality Units)");
                    outputs.Add(otp);
                }
                else
                {
                    //...
                }

                //Inform the dashboard of your results
                ModuleResult mResult = new ModuleResult(
                    moduleId: recievedMessage.moduleId,
                    variantId: recievedMessage.variantId,
                    userId: recievedMessage.userId,
                    kpiId: recievedMessage.kpiId,
                    outputs: outputs);
                //Send the result message...


                string resMessage = Serialize.ToJsonString(mResult);
                Console.WriteLine(resMessage);
            }
        }