Esempio n. 1
0
        /// <summary>
        /// Merges the explicitly provided values with the extra object
        /// </summary>
        /// <param name="explicitValues">The explicit values.</param>
        /// <param name="extra">The extra.</param>
        /// <returns></returns>
        public Dictionary <string, string> Merge(Dictionary <string, string> explicitValues, object extra = null)
        {
            var merged = explicitValues;

            if (AuthenticationStyle == AuthenticationStyle.PostValues)
            {
                merged.Add(OidcConstants.TokenRequest.ClientId, ClientId);

                if (ClientSecret.IsPresent())
                {
                    merged.Add(OidcConstants.TokenRequest.ClientSecret, ClientSecret);
                }
            }

            var additionalValues = ValuesHelper.ObjectToDictionary(extra);

            if (additionalValues != null)
            {
                merged =
                    explicitValues.Concat(additionalValues.Where(add => !explicitValues.ContainsKey(add.Key)))
                    .ToDictionary(final => final.Key, final => final.Value);
            }

            return(merged);
        }
        /// <summary>
        /// Return a <see cref="ContentResult"/> that automatically POSTs the values.
        /// </summary>
        /// <param name="url">Where to post the values.</param>
        /// <param name="values">The values to post.</param>
        /// <returns></returns>
        // ReSharper disable once UnusedMember.Local
        private ContentResult Post(string url, object values)
        {
            var response = HttpContext.Response;

            response.Clear();

            var p = ValuesHelper.ObjectToDictionary(values);

            var s = new StringBuilder();

            s.Append("<html><head><title></title></head>");
            s.Append("<body onload='document.forms[\"form\"].submit()'>");
            s.Append($"<form name='form' action='{url}' method='post'>");
            foreach (var pair in p)
            {
                s.Append($"<input type='hidden' name='{pair.Key}' value='{pair.Value}' />");
            }
            s.Append("</form></body></html>");
            return(new ContentResult
            {
                Content = s.ToString(),
                ContentType = "text/html",
                StatusCode = StatusCodes.Status200OK
            });
        }
Esempio n. 3
0
 public void Check_That_nonPublished_Article_notLoaded([Values(ContentAccess.Live)] ContentAccess access, [MappingValues] Mapping mapping)
 {
     using (var context = GetDataContext(access, mapping))
     {
         var status            = ValuesHelper.GetNonPublishedStatus(mapping);
         var nonpublishedItems = context.PublishedNotPublishedItems.Where(x => x.StatusTypeId == status).ToArray();
         Assert.That(nonpublishedItems, Is.Null.Or.Empty);
     }
 }
Esempio n. 4
0
 public void Check_That_nonPublished_Article_isLoaded([Values(ContentAccess.StageNoDefaultFiltration)] ContentAccess access, [MappingValues] Mapping mapping)
 {
     using (var context = GetDataContext(access, mapping))
     {
         var status = ValuesHelper.GetNonPublishedStatus(mapping);
         var items  = context.PublishedNotPublishedItems.Where(x => x.StatusTypeId == status).ToArray();
         Assert.That(items, Is.Not.Null.And.Not.Empty);
     }
 }
Esempio n. 5
0
 public void Check_That_FileFieldUploadPath_isCorrect_Fill([ContentAccessValues] ContentAccess access, [MappingValues] Mapping mapping)
 {
     using (var context = GetDataContext(access, mapping))
     {
         var items = context.FileFieldsItems.FirstOrDefault();
         var expectedUploadPath = UPLOAD_PATH + ValuesHelper.GetFileContentId(mapping);
         Assert.That(items.FileItemUploadPath, Is.EqualTo(expectedUploadPath));
     }
 }
Esempio n. 6
0
        public void DataContext_Schema_GetContentInfo([ContentAccessValues] ContentAccess access, [MappingValues] Mapping mapping)
        {
            using (var context = GetDataContext(access, mapping))
            {
                var contentId         = context.GetInfo <Schema>().Id;
                int expectedContentId = ValuesHelper.GetSchemaContentId(mapping);

                Assert.That(contentId, Is.EqualTo(expectedContentId));
            }
        }
Esempio n. 7
0
        public void DataContext_Schema_GetAttributeInfo([ContentAccessValues] ContentAccess access, [MappingValues] Mapping mapping)
        {
            using (var context = GetDataContext(access, mapping))
            {
                var attributeId         = context.GetInfo <Schema>(a => a.Title).Id;
                var expectedattributeId = ValuesHelper.GetSchemaTitleFieldId(mapping);

                Assert.That(attributeId, Is.EqualTo(expectedattributeId));
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Creates URL based on key/value input pairs.
        /// </summary>
        /// <param name="values">The values (either as a Dictionary of string/string or as a type with properties).</param>
        /// <returns></returns>
        public string Create(object values)
        {
            var dictionary = ValuesHelper.ObjectToDictionary(values);

            if (dictionary == null || !dictionary.Any())
            {
                return(_baseUrl);
            }

            return(QueryHelpers.AddQueryString(_baseUrl, dictionary));
        }
Esempio n. 9
0
 private string ExpectedUploadUrl(string pref, string fileName, Mapping mapping)
 {
     if (string.IsNullOrEmpty(pref))
     {
         return(String.Format("{0}{1}/{2}", UploadUrlRel, ValuesHelper.GetFileContentId(mapping), fileName));
     }
     else
     {
         return(String.Format("{0}{1}/{2}", UploadUrlAbs, ValuesHelper.GetFileContentId(mapping), fileName));
     }
 }
Esempio n. 10
0
        /// <summary>
        /// Creates URL based on key/value input pairs.
        /// </summary>
        /// <param name="values">The values (either as a Dictionary of string/string or as a type with properties).</param>
        /// <returns></returns>
        public string Create(object values)
        {
            var dictionary = ValuesHelper.ObjectToDictionary(values);

            if (dictionary == null || !dictionary.Any())
            {
                return(_baseUrl);
            }

            var qs = string.Join("&", dictionary.Select(kvp => string.Format("{0}={1}", WebUtility.UrlEncode(kvp.Key), WebUtility.UrlEncode(kvp.Value))).ToArray());

            return(string.Format("{0}?{1}", _baseUrl, qs));
        }
Esempio n. 11
0
        public IActionResult OnGet()
        {
            var time      = DateTime.Now;
            var isMorning = time.Hour < 12;

            Workout = new WorkoutCreateViewModel
            {
                Date      = time.Date,
                Name      = ValuesHelper.ComposeWorkoutName(time, isMorning),
                Place     = _configuration["DefaultSwimPlace"],
                IsMorning = isMorning
            };
            return(Page());
        }
        /// <summary>
        /// Creates a end_session URL.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="idTokenHint">The id_token hint.</param>
        /// <param name="postLogoutRedirectUri">The post logout redirect URI.</param>
        /// <param name="state">The state.</param>
        /// <param name="extra">The extra parameters.</param>
        /// <returns></returns>
        public static string CreateEndSessionUrl(this RequestUrl request,
                                                 string idTokenHint           = null,
                                                 string postLogoutRedirectUri = null,
                                                 string state = null,
                                                 object extra = null)
        {
            var values = new Dictionary <string, string>();

            values.AddOptional(OidcConstants.EndSessionRequest.IdTokenHint, idTokenHint);
            values.AddOptional(OidcConstants.EndSessionRequest.PostLogoutRedirectUri, postLogoutRedirectUri);
            values.AddOptional(OidcConstants.EndSessionRequest.State, state);

            return(request.Create(ValuesHelper.Merge(values, ValuesHelper.ObjectToDictionary(extra))));
        }
Esempio n. 13
0
        /// <summary>
        /// Creates URL based on key/value input pairs.
        /// </summary>
        /// <param name="values">The values (either as a Dictionary of string/string or as a type with properties).</param>
        /// <returns></returns>
        public string Create(object values)
        {
            var dictionary = ValuesHelper.ObjectToDictionary(values);

            if (dictionary == null || !dictionary.Any())
            {
                return(_baseUrl);
            }

            var encoder = UrlEncoder.Default;

            var qs = string.Join("&", dictionary.Where(d => d.Value != null).Select(kvp => string.Format("{0}={1}", encoder.Encode(kvp.Key), encoder.Encode(kvp.Value))).ToArray());

            return(string.Format("{0}?{1}", _baseUrl, qs));
        }
Esempio n. 14
0
        public IActionResult GetWorkoutName(DateTime selectedDate, bool isMorning)
        {
            string result;

            if (selectedDate > DateTime.MinValue)
            {
                //if (!string.IsNullOrEmpty(value) && DateTime.TryParse(value, out DateTime date))
                //{
                //    var dateAndTime = new DateTime(date.Year, date.Month, date.Day, DateTime.Now.Hour, 0, 0);
                result = ValuesHelper.ComposeWorkoutName(selectedDate, isMorning);
            }
            else
            {
                result = string.Empty;
            }

            return(new JsonResult(result));
        }
Esempio n. 15
0
        public async Task OnGetAsync(int?pageNo)
        {
            var pageIndex = ValuesHelper.GetPageIndex(pageNo);

            //static IQueryable<Workout> queryModifier(IQueryable<Workout> q) => q.Include(w => w.Start).OrderByDescending(w => w.Start);
            var workoutList = await _repository.GetList(new WorkoutsSortedByDateWithPagingSpecification(pageIndex, _pageSize))
                              .ConfigureAwait(false);

            //var workoutList = await _repository.GetList(w => w.Start, true, _pageSize, pageIndex)
            var totalCount = await _repository.GetCount()
                             .ConfigureAwait(false);

            Workouts = new ListWithPaging <WorkoutViewModel>(totalCount, pageIndex, _pageSize, nameof(pageNo));

            foreach (var item in workoutList)
            {
                Workouts.Add(_mapper.Map <WorkoutViewModel>(item));
            }
        }
        /// <summary>
        /// Creates an authorize URL.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <param name="clientId">The client identifier.</param>
        /// <param name="responseType">The response type.</param>
        /// <param name="scope">The scope.</param>
        /// <param name="redirectUri">The redirect URI.</param>
        /// <param name="state">The state.</param>
        /// <param name="nonce">The nonce.</param>
        /// <param name="loginHint">The login hint.</param>
        /// <param name="acrValues">The acr values.</param>
        /// <param name="prompt">The prompt.</param>
        /// <param name="responseMode">The response mode.</param>
        /// <param name="codeChallenge">The code challenge.</param>
        /// <param name="codeChallengeMethod">The code challenge method.</param>
        /// <param name="display">The display option.</param>
        /// <param name="maxAge">The max age.</param>
        /// <param name="uiLocales">The ui locales.</param>
        /// <param name="idTokenHint">The id_token hint.</param>
        /// <param name="extra">Extra parameters.</param>
        /// <returns></returns>
        public static string CreateAuthorizeUrl(this RequestUrl request,
                                                string clientId,
                                                string responseType,
                                                string scope               = null,
                                                string redirectUri         = null,
                                                string state               = null,
                                                string nonce               = null,
                                                string loginHint           = null,
                                                string acrValues           = null,
                                                string prompt              = null,
                                                string responseMode        = null,
                                                string codeChallenge       = null,
                                                string codeChallengeMethod = null,
                                                string display             = null,
                                                int?maxAge         = null,
                                                string uiLocales   = null,
                                                string idTokenHint = null,
                                                object extra       = null)
        {
            var values = new Dictionary <string, string>
            {
                { OidcConstants.AuthorizeRequest.ClientId, clientId },
                { OidcConstants.AuthorizeRequest.ResponseType, responseType }
            };

            values.AddOptional(OidcConstants.AuthorizeRequest.Scope, scope);
            values.AddOptional(OidcConstants.AuthorizeRequest.RedirectUri, redirectUri);
            values.AddOptional(OidcConstants.AuthorizeRequest.State, state);
            values.AddOptional(OidcConstants.AuthorizeRequest.Nonce, nonce);
            values.AddOptional(OidcConstants.AuthorizeRequest.LoginHint, loginHint);
            values.AddOptional(OidcConstants.AuthorizeRequest.AcrValues, acrValues);
            values.AddOptional(OidcConstants.AuthorizeRequest.Prompt, prompt);
            values.AddOptional(OidcConstants.AuthorizeRequest.ResponseMode, responseMode);
            values.AddOptional(OidcConstants.AuthorizeRequest.CodeChallenge, codeChallenge);
            values.AddOptional(OidcConstants.AuthorizeRequest.CodeChallengeMethod, codeChallengeMethod);
            values.AddOptional(OidcConstants.AuthorizeRequest.Display, display);
            values.AddOptional(OidcConstants.AuthorizeRequest.MaxAge, maxAge?.ToString());
            values.AddOptional(OidcConstants.AuthorizeRequest.UiLocales, uiLocales);
            values.AddOptional(OidcConstants.AuthorizeRequest.IdTokenHint, idTokenHint);

            return(request.Create(ValuesHelper.Merge(values, ValuesHelper.ObjectToDictionary(extra))));
        }
 /// <summary>
 /// Creates an authorize URL.
 /// </summary>
 /// <param name="request">The request.</param>
 /// <param name="values">The values (either using a string Dictionary or an object's properties).</param>
 /// <returns></returns>
 public static string Create(this RequestUrl request, object values)
 {
     return(request.Create(ValuesHelper.ObjectToDictionary(values)));
 }
Esempio n. 18
0
        public IEnumerable <string> Get()
        {
            var result = ValuesHelper.ReadFile();

            return(new string[] { "Is OpenShift Working", "Yes!!! It seems to be working...", result });
        }
Esempio n. 19
0
 /// <summary>
 /// Requests a token using a custom request
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="values">The values.</param>
 /// <param name="cancellationToken">The cancellation token.</param>
 /// <returns></returns>
 public static Task <TokenResponse> RequestCustomAsync(this TokenClient client, object values, CancellationToken cancellationToken = default(CancellationToken))
 {
     return(client.RequestAsync(client.Merge(ValuesHelper.ObjectToDictionary(values)), cancellationToken));
 }
Esempio n. 20
0
        public async Task OnGet(int?pageNo, string sortBy, bool?descending)
        {
            Expression <Func <WorkoutInterval, object> > sortSelector;

            switch (sortBy)
            {
            case DistanceSortKey: { sortSelector = i => i.Distance; break; }

            case DurationSortKey: { sortSelector = i => i.Duration; break; }

            case StrokeCountSortKey: { sortSelector = i => i.StrokeCount; break; }

            case PaceSortKey: { sortSelector = i => i.Pace; break; }

            case SwolfSortKey: { sortSelector = i => i.Swolf; break; }

            default: { sortSelector = i => i.Workout.WorkoutDate; break; }
            }

            var newSortOrder   = string.IsNullOrWhiteSpace(sortBy) ? DateSortKey : sortBy;
            var sortDescending = descending ?? true;

            var pageIndex = ValuesHelper.GetPageIndex(pageNo);

            var intervals = await _intervalRepository.GetList(new SortedIntervalsByTypeSpecification(SelectedIntervalType, sortSelector, sortDescending, pageIndex, _pageSize))
                            //var intervals = await _intervalRepository.GetList(
                            //    q => q
                            //        .Where(i => i.WorkoutIntervalTypeId == SelectedIntervalType)
                            //        .Include(i => i.WorkoutIntervalType)
                            //        .Include(i => i.Workout),
                            //    _pageSize, pageIndex, sortSelector, sortDescending)
                            .ConfigureAwait(false);

            //var intervals = await _intervalRepository.GetList(i => i.WorkoutIntervalTypeId == SelectedIntervalType, sortSelector, sortDescending, _pageSize, pageIndex, i => i.WorkoutIntervalType, i => i.Workout)
            var totalCount = await _intervalRepository.GetCount(new IntervalsByTypeSpecification(SelectedIntervalType))
                             //var totalCount = await _intervalRepository.GetCount(i => i.WorkoutIntervalTypeId == SelectedIntervalType)
                             .ConfigureAwait(false);

            var sortKeys = new Dictionary <string, string>
            {
                { DateFieldName, DateSortKey },
                { DistanceFieldName, DistanceSortKey },
                { DurationFieldName, DurationSortKey },
                { StrokeCountFieldName, StrokeCountSortKey },
                { PaceFieldName, PaceSortKey },
                { SwolfFieldName, SwolfSortKey }
            };

            Intervals = new ListWithPagingAndSorting <WorkoutIntervalViewModel>(totalCount, pageIndex, _pageSize, nameof(pageNo), nameof(sortBy), nameof(descending), newSortOrder, sortDescending, sortKeys);

            foreach (var interval in intervals)
            {
                var displayItem = _mapper.Map <WorkoutIntervalViewModel>(interval);
                displayItem.WorkoutName = interval.Workout.Name;
                displayItem.WorkoutDate = interval.Workout.WorkoutDate;
                Intervals.Add(displayItem);
            }

            Intervals.FirstPageRouteValues.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant());
            Intervals.LastPageRouteValues.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant());
            Intervals.PrevPageRouteValues.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant());
            Intervals.NextPageRouteValues.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant());
            foreach (var routeValues in Intervals.SortRouteValues)
            {
                routeValues.Value.Add(nameof(SelectedIntervalType), SelectedIntervalType.ToStringInvariant());
            }

            var intervalTypes = await _intervalTypeRepository.GetList()
                                .ConfigureAwait(false);

            WorkoutIntervalTypeSelectList = new SelectList(intervalTypes, "Id", "Name");
        }