示例#1
0
 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
        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]);
        }