Example #1
0
        /// <summary>
        /// Define a <handler> function to call when a web service call starting with <apiCall> is received.
        /// This is used to create and handle user-defined web service API methods.
        /// </summary>
        /// <returns>EventsHelper</returns>
        /// <param name="apiCall">API call.</param>
        /// <param name="handler">Handler.</param>
        /// <remarks />
        /// <example>
        /// Example:
        /// <code>
        ///     When.WebServiceCallReceived( "Hello.World", (args) =>
        ///     {
        ///         var returnstring = "";
        ///         if (args == "Greet")
        ///         {
        ///             returnstring = "Hello HomeGenie World!";
        ///         }
        ///         return returnstring;
        ///     });
        /// </code>
        /// In the snippet above, if we wanted to create an "Hello World" program that respond to the custom API call:
        /// \n
        /// http://<hg_server_address>/api/Hello.World/Greet
        /// </example>
        public EventsHelper WebServiceCallReceived(string apiCall, Func <object, object> handler)
        {
            var program = homegenie.ProgramEngine.Programs.Find(p => p.Address.ToString() == myProgramId.ToString());

            program.registeredApiCalls.Add(apiCall);
            homegenie.RegisterDynamicApi(apiCall, handler);
            return(this);
        }
Example #2
0
        public EventsHelper WebServiceCallReceived(string apicall, Func <object, string> handler)
        {
            ProgramBlock pb = _homegenie.ProgramEngine.Programs.Find(p => p.Address.ToString() == _myprogramid.ToString());

            pb._registeredapicalls.Add(apicall);
            _homegenie.RegisterDynamicApi(apicall, handler);
            return(this);
        }