Пример #1
0
        public static void ParseUrlRequestData(HttpRequest req, Container request_data)
        {
            string[] param_names = req.QueryString.AllKeys;
            for (int param_index = 0; param_index < param_names.Length; param_index++)
            {
                string param_name = param_names[param_index];
                if (param_name == null)
                {
                    continue;
                }

                string[] param_values = req.QueryString.GetValues(param_name);

                // handle containers
                string[] name_parts = param_name.Replace("]", "").Split('[');

                // iterate over the group
                for (int pvalue_index = 0; pvalue_index < param_values.Length; pvalue_index++)
                {
                    string param_value = param_values[pvalue_index];
                    object cur_holder  = request_data;

                    for (int i = 0; i < name_parts.Length; i++)
                    {
                        if (i == (name_parts.Length - 1))
                        {
                            PutValueInUnknownHolder(cur_holder, name_parts[i], param_value);
                        }
                        else
                        {
                            object next_holder = GetValueInUnknownHolder(cur_holder, name_parts[i]);
                            if (next_holder != null)
                            {
                                // holder already exists, move on
                                cur_holder = next_holder;
                            }
                            else
                            {
                                // holder doesn't exist, need to create it, should it be an array or a container? let's rely on the next index
                                string next_field = name_parts[i + 1];
                                if (String.IsNullOrEmpty(next_field) || Helpers.IsNumeric(next_field))
                                {
                                    next_holder = new Appixia.Engine.Mediums.Array();
                                }
                                else
                                {
                                    next_holder = new Container();
                                }
                                // put it
                                PutValueInUnknownHolder(cur_holder, name_parts[i], next_holder);
                                cur_holder = next_holder;
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        public static async Task DieOnErrorAsync(HttpResponse res, TextWriter output, Encoder encoder, string error, string message)
        {
            var root   = encoder.CreateRoot();
            var result = encoder.AddContainer(root, "Result");

            encoder.AddBoolean(result, "Success", false);
            Appixia.Engine.Mediums.Array details = encoder.AddArray(result, "Detail");
            var detail = encoder.AddContainerToArray(details);

            encoder.AddString(detail, "Error", error);
            encoder.AddString(detail, "Message", message);
            await encoder.RenderAsync(res, output, root);

            await output.FlushAsync();

            throw new DieException();
        }