コード例 #1
0
ファイル: ProgramManager.cs プロジェクト: xzflin/HomeGenie
        public object TryDynamicApi(MigInterfaceCommand command)
        {
            object response = "";
            // Dynamic Interface API
            var registeredApi = command.Domain + "/" + command.Address + "/" + command.Command;
            var handler       = ProgramDynamiApi.Find(registeredApi);

            if (handler != null)
            {
                // explicit command API handlers registered in the form <domain>/<address>/<command>
                // receives only the remaining part of the request after the <command>
                var args = command.OriginalRequest.Substring(registeredApi.Length).Trim('/');
                response = handler(args);
            }
            else
            {
                handler = ProgramDynamiApi.FindMatching(command.OriginalRequest.Trim('/'));
                if (handler != null)
                {
                    // other command API handlers
                    // receives the full request string
                    response = handler(command.OriginalRequest.Trim('/'));
                }
            }
            return(response);
        }
コード例 #2
0
ファイル: ProgramManager.cs プロジェクト: xzflin/HomeGenie
 public void UnRegisterDynamicApi(string apiCall)
 {
     ProgramDynamiApi.UnRegister(apiCall);
 }
コード例 #3
0
ファイル: ProgramManager.cs プロジェクト: xzflin/HomeGenie
 //TODO: should the following 3 methods moved to ProgramEngine?
 public void RegisterDynamicApi(string apiCall, Func <object, object> handler)
 {
     ProgramDynamiApi.Register(apiCall, handler);
 }