Beispiel #1
0
        public static string GetUserEmail(HttpContext httpContext, CookieFailKeyInfo keyInfo, AppSettings appSettings)
        {
            var assignments = AvailableAssignmentsHelper.GetAvailableAssignments(httpContext, null);

            for (int assignmentIndex = 0; assignmentIndex < assignments.Count; assignmentIndex++)
            {
                var currentAssignment = assignments[assignmentIndex];

                if (currentAssignment != null)
                {
                    var assignmentDetail = AssignmentDetailHelper.GetAssignmentDetail(httpContext, keyInfo, appSettings, currentAssignment);
                    if (assignmentDetail != null)
                    {
                        var matchingPairs = assignmentDetail.InterestsValues.Where(pair => pair.Key == "login").ToList();
                        if (matchingPairs.Count > 0)
                        {
                            // We have found email
                            return(matchingPairs[0].Value);
                        }
                    }
                }
                assignmentIndex++;
            }
            return(string.Empty);
        }
        public static List <Assignment> AdvancedFilerItems(List <Assignment> items, AvailableAssignmentFilterSettings filterSettings, HttpContext httpContext, CookieFailKeyInfo cookieKeyInfo, AppSettings appSettings, out int skipCount)
        {
            skipCount = 0;
            List <Assignment> filteredItems = new List <Assignment>(items);

            var isFilterOnlyAssignmentsThatCanBeBooked = filterSettings.NeverShowSpecTypes.Any(x => x == 0);
            var isFilterNotOverbookedAssignments       = filterSettings.NeverShowSpecTypes.Any(x => x == 1);

            if (isFilterOnlyAssignmentsThatCanBeBooked || isFilterNotOverbookedAssignments)
            {
                // filters out items that we are not interested in
                var indexesToRemove = new List <int>();
                var ourWeekNumber   = -1;
                var hasWeekNumber   = false;

                for (int assignmentIndex = 0; assignmentIndex < items.Count; assignmentIndex++)
                {
                    var assignment = items[assignmentIndex];

                    DateTime date;
                    if (DateTime.TryParse(assignment.Date, out date))
                    {
                        var weekNumber = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(date, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
                        if (hasWeekNumber)
                        {
                            if (ourWeekNumber != weekNumber)
                            {
                                // Only do this for one week at the time, ignore rest (because of performance issues on orginal server)
                                // It takes 30-40 seconds to do this for all assignments at the same time.
                                indexesToRemove.Add(assignmentIndex);
                                continue;
                            }
                        }

                        var details      = AssignmentDetailHelper.GetAssignmentDetail(httpContext, cookieKeyInfo, appSettings, assignment);
                        var shouldBeKept = true;

                        if (isFilterOnlyAssignmentsThatCanBeBooked)
                        {
                            shouldBeKept = details.InterestsValues.Count > 0;
                        }

                        if (shouldBeKept && isFilterNotOverbookedAssignments)
                        {
                            int currentNumberOfPeople, wantedNumberOfPeople;
                            if (int.TryParse(details.CurrentNumberOfPeople, out currentNumberOfPeople) && int.TryParse(details.WantedNumberOfPeople, out wantedNumberOfPeople))
                            {
                                shouldBeKept = currentNumberOfPeople < wantedNumberOfPeople;
                            }
                        }

                        if (shouldBeKept)
                        {
                            if (!hasWeekNumber)
                            {
                                ourWeekNumber = weekNumber;
                                hasWeekNumber = true;
                            }
                            skipCount++;
                        }
                        else
                        {
                            indexesToRemove.Add(assignmentIndex);
                            skipCount++;
                        }
                        // Make some efforts to not DDOS orginal server
                        //System.Threading.Thread.Sleep(10);
                    }
                }

                if (indexesToRemove.Count > 0)
                {
                    indexesToRemove.Reverse();

                    for (var removeIndex = 0; removeIndex < indexesToRemove.Count; removeIndex++)
                    {
                        var indexToRemove = indexesToRemove[removeIndex];
                        filteredItems.RemoveAt(indexToRemove);
                    }
                }
            }

            return(filteredItems);
        }