Beispiel #1
0
 protected void Button1_Click(object sender, EventArgs e)
 {
     Cleanup();
     Label10.Visible = false;
     if (TextBox1.Text != string.Empty)
     {
         Model.ReportFinder(TextBox1.Text.ToUpper());
         ResultSet          list  = Model.ResultSet as ResultSet;
         List <BindResults> enums = new List <BindResults>();
         foreach (var l1 in list.results)
         {
             var br = new BindResults();
             br.type = l1.Enum_id;
             foreach (var l2 in l1.Enums)
             {
                 br.name  = l2.Name;
                 br.value = l2.value;
                 enums.Add(br);
             }
         }
         BindData <List <BindResults> >(GridView1, enums, SesMatches);
         Grid1.Visible = true;
     }
 }
Beispiel #2
0
        public DispatchContext(RestRequest req)
        {
            Info.EnsureBlankLine();
            Info.Write("Dispatching request ");
            var snippets = SnippetRegistry.Methods <RestResourceAttribute>();

            Info.WriteLine("(across {0} handlers)...", snippets.Count());
            BindResults = snippets.Select(snippet => new BindContext(req, snippet)).ToReadOnly();

            // todo. maybe invent some novel way to do dispatch
            // so that "http://localhost/daas/ldab/Users?$filter=substringof('Bu', Name)"
            // doesn't get dispatched to "/{relativeFilePath}" and cause a crash with 400
            // but rather becomes a 404 because it's just "/daas/ldap/{s_dataQuery}" with a typo
            var bestMatch = PickBestMatch(BindResults);

            if (bestMatch == null)
            {
                if (BindResults.Any(r => r.Result == BindResult.UrlMismatch))
                {
                    Result = DispatchResult.UrlMismatch;
                }
                if (BindResults.Any(r => r.Result == BindResult.ArgsMismatch))
                {
                    Result = DispatchResult.ArgsMismatch;
                }
                if (BindResults.Any(r => r.Result == BindResult.MethodMismatch))
                {
                    Result = DispatchResult.MethodNotAllowed;
                }
                if (BindResults.Any(r => r.Result == BindResult.NotAuthenticated))
                {
                    Result = DispatchResult.NotAuthenticated;
                }
                if (BindResults.Any(r => r.Result == BindResult.NotAuthorized))
                {
                    Result = DispatchResult.NotAuthorized;
                }
                if (BindResults.Count(r => r.Result == BindResult.Success) > 1)
                {
                    Result = DispatchResult.Ambiguous;
                }
            }
            else
            {
                BestMatch = bestMatch;
                Result    = (DispatchResult)Enum.Parse(typeof(DispatchResult), bestMatch.Result.ToString());
            }

            Info.EnsureBlankLine();
            Info.WriteLine("Dispatch summary: {0}", Result);
            Info.WriteLine(BindResults.Select(r => "    * " + r.ToString()).StringJoin(Environment.NewLine));

            Info.EnsureBlankLine();
            if (Result != DispatchResult.Success)
            {
                Error.WriteLine("Dispatch has failed with status code {0}", Result.ToHttpStatusCode());
            }
            else
            {
                Info.WriteLine("Bound handler: {0}", BestMatch.HandlerContext);
            }
        }