private void ParseAttributes(Attribute[] attributes)
        {
            CausesStateChange = attributes.Any(a => a is ODataAction);

            ContentTypes = ParseNames(attributes
                                      .Where(a => a is ContentTypesAttribute)
                                      .SelectMany(a => ((ContentTypesAttribute)a).Names));
            if (ContentTypes.Length == 0)
            {
                ContentTypes = new[] { N.CT.GenericContent }
            }
            ;
            else if (ContentTypes.Contains(N.CT.GenericContent) && ContentTypes.Contains(N.CT.ContentType))
            {
                ContentTypes = _empty;
            }

            Scenarios = ParseNames(attributes
                                   .Where(a => a is ScenarioAttribute)
                                   .Select(a => ((ScenarioAttribute)a).Name));

            Permissions = ParseNames(attributes
                                     .Where(a => a is RequiredPermissionsAttribute)
                                     .SelectMany(a => ((RequiredPermissionsAttribute)a).Names));

            Roles = ParseNames(attributes
                               .Where(a => a is AllowedRolesAttribute)
                               .SelectMany(a => ((AllowedRolesAttribute)a).Names));

            Policies = ParseNames(attributes
                                  .Where(a => a is RequiredPoliciesAttribute)
                                  .SelectMany(a => ((RequiredPoliciesAttribute)a).Names));
        }
Example #2
0
        private async void DisplayRequest(Request request)
        {
            var headers = request.Headers ?? new List <Header>();

            var accept = headers.GetValue(Header.Accept);

            if (!Accepts.Contains(accept))
            {
                accept = Accepts.First();
            }

            var contentType = headers.GetValue(Header.ContentType);

            if (!ContentTypes.Contains(contentType))
            {
                contentType = ContentTypes.First();
            }

            headers = headers
                      .Where(h =>
                             !h.Name.Equals(Header.Accept, StringComparison.OrdinalIgnoreCase) &&
                             !h.Name.Equals(Header.AcceptEncoding, StringComparison.OrdinalIgnoreCase) &&
                             !h.Name.Equals(Header.ContentType, StringComparison.OrdinalIgnoreCase))
                      .ToList();

            headers.Add(new Header(Header.Accept, accept));
            headers.Add(new Header(Header.AcceptEncoding, Header.AcceptEncodingValue));
            headers.Add(new Header(Header.ContentType, contentType));

            SelectedMethod      = request.Method;
            Url                 = request.Url;
            SelectedAccept      = accept;
            RequestBody         = new TextDocument(await Prettify(request.Body, contentType));
            SelectedContentType = contentType;
            Headers             = new BindableCollection <Header>(headers.OrderBy(h => h.Name));
            HeaderName          = null;
            HeaderValue         = null;

            var token = request.NamedAuthorizationState;

            if (token == null || token.AuthorizationState == null)
            {
                SelectedToken = _anonymousToken;
            }
            else
            {
                if (Tokens.All(t => t.Guid != token.Guid))
                {
                    Tokens.Add(token);
                }

                SelectedToken = token;
            }

            var response    = request.Response;
            var hasResponse = response != null;

            if (!hasResponse)
            {
                ResponseBody = null;
                return;
            }

            ResponseTime        = request.ResponseTime;
            ResponseBody        = new TextDocument(await Prettify(response.Body, response.ContentType));
            ResponseContentType = response.ContentType;
            HttpStatusCode      = response.HttpStatusCode;
            ResponseHeaders     = new BindableCollection <Header>(response.Headers.OrderBy(h => h.Name));
        }