コード例 #1
0
ファイル: CommandsService.cs プロジェクト: wortexx/zaz
 private static object BindFormToCommand(IDictionary<string, string> form, Type cmdType)
 {
     try
     {
         var binder = new CommandBinder();
         return binder.Build(cmdType, form);
     }
     catch (InvalidOperationException ex)
     {
         throw ExceptionsFactory.CreateApiException("Problems with binding command data. " + ex.Message);
     }
 }
コード例 #2
0
ファイル: CommandsController.cs プロジェクト: chaliy/zaz
        public HttpResponseMessage PostLegacy(HttpRequestMessage req)
        {
            var body = req.Content.ReadAsStringAsync().Result;

            // Parsing QueryString
            var nvc = HttpUtility.ParseQueryString(body);
            var form = nvc.Keys.Cast<string>().ToDictionary(x => x, x => nvc[x]);

            if (!form.ContainsKey("Zaz-Command-Id"))
            {
                throw ExceptionsFactory.CreateApiException("Required value 'Zaz-Command-Id' was not found.");
            }

            var cmdKey = form["Zaz-Command-Id"];
            var cmdType = _resolver.ResolveCommandType(cmdKey);

            object cmd;

            try
            {
                var binder = new CommandBinder();
                cmd = binder.Build(cmdType, form);
            }
            catch (InvalidOperationException ex)
            {
                throw ExceptionsFactory.CreateApiException("Problems with binding command data. " + ex.Message);
            }

            return _runner.RunCommand(cmdKey, cmd, new string[0]);
        }