示例#1
0
        public void ParsesEmpty()
        {
            var context = new SortingContext(Enumerable.Empty <KeyValuePair <string, string> >());

            var actual = context.Properties;

            Assert.Equal(Enumerable.Empty <SortingProperty>(), actual);
        }
示例#2
0
        /// <summary>
        /// See base class documentation.
        /// </summary>
        /// <param name="actionContext">The action context.</param>
        public override void OnActionExecuting(HttpActionContext actionContext)
        {
            var queryParams = actionContext.Request.GetQueryNameValuePairs().ToList();
            var sorting     = new SortingContext(queryParams);
            var filtering   = new FilteringContext(queryParams);

            var queryContext = GetQueryContext(actionContext);

            queryContext.Sorting   = sorting;
            queryContext.Filtering = filtering;

            base.OnActionExecuting(actionContext);
        }
示例#3
0
        internal void ParsesCorrectly(string query, string[] properties, SortingDirection[] directions)
        {
            var context  = new SortingContext(GetQuery(query));
            var expected = properties.Zip(directions, (s, d) => new
            {
                Name      = s,
                Direction = d
            }).ToList();
            var actual = context.Properties.Select(p => new
            {
                p.Name,
                p.Direction
            }).ToList();

            Assert.Equal(expected, actual);
        }
示例#4
0
        static void Main(string[] args)
        {
            DateTime       startingTime, endTime;
            SortingContext sortingContext;
            List <int>     sortedList = new List <int>();
            List <int>     list       = new List <int>
            {
                45, 6, 87, 2, 43, 6, 87, 23, 54, 88, 25, 13, 15, 97, 34, 42, 12, 52, 88, 61, 40, 20, 10, 50
            };

            //BubbleSort
            sortingContext = new SortingContext(new BubbleSortStrategy());
            sortedList     = new List <int>();
            startingTime   = DateTime.Now;
            sortedList     = sortingContext.Sort(list);
            endTime        = DateTime.Now;
            Console.WriteLine("BubbleSort");
            Helper.WriteConsole(sortedList);
            Console.WriteLine("Çalışma Zamanı: " + (endTime.Millisecond - startingTime.Millisecond).ToString() + " ms");

            //QuickSort
            sortingContext = new SortingContext(new QuickSortStrategy());

            startingTime = DateTime.Now;
            sortedList   = sortingContext.Sort(list);
            endTime      = DateTime.Now;
            Console.WriteLine("QuickSort");
            Helper.WriteConsole(sortedList);
            Console.WriteLine("Çalışma Zamanı: " + (endTime.Millisecond - startingTime.Millisecond).ToString() + " ms");

            //InsertionSort
            sortingContext = new SortingContext(new InsertionSortStrategy());

            startingTime = DateTime.Now;
            sortedList   = sortingContext.Sort(list);
            endTime      = DateTime.Now;
            Console.WriteLine("InsertionSort");
            Helper.WriteConsole(sortedList);
            Console.WriteLine("Çalışma Zamanı: " + (endTime.Millisecond - startingTime.Millisecond).ToString() + " ms");

            Console.ReadLine();
        }
示例#5
0
        public static object ApplySorting(object data, SortingContext context, ApiResource resource)
        {
            var queryable = data as IQueryable;

            if (queryable != null)
            {
                return(new SortingInterpreter(context, resource).Apply(queryable));
            }

            var enumerable = data as IEnumerable;

            if (enumerable != null)
            {
                // all queryables are enumerable, so this needs to be after
                // the queryable case
                return(new SortingInterpreter(context, resource).Apply(enumerable));
            }

            return(data);
        }
示例#6
0
        static void Main(string[] args)
        {
            int[] array1Int32 = { -2, 5, -1, 3, 1, 2, -3, 4, 0 };
            int[] array2Int32 = { -8, 5, -1, 33, 81, -2, -3, 4, 0 };

            double[] array1Double = { -6.2, 5.82, -11.56, 13.34, 1.8, 2.98, -13.46, 4.34, 0.0 };
            double[] array2Double = { -18.34, 25.245, -31.3, 33.53, 81.535, -12.13, -3.04, 4.532, 0.1353 };

            //SortingContext<int> sortingContext = new SortingContext<int>(new QuickSortAlgorithm<int>(SortingAlgorithm<int>.CreateRandomArray(20000000))); // ~6000 ms
            SortingContext <int>    sortingContextInt32  = new SortingContext <int>(new QuickSortAlgorithm <int>(array1Int32));
            SortingContext <double> sortingContextDouble = new SortingContext <double>(new QuickSortAlgorithm <double>(array1Double));

            Stopwatch sw = new Stopwatch();

            #region Int32 Sorting
            Console.WriteLine("Quicksort(Int32):");
            sw.Start();
            sortingContextInt32.Sort();
            sw.Stop();
            sortingContextInt32.Show();

            Console.WriteLine($"\nTotal time: {sw.Elapsed.TotalMilliseconds.ToString("0.00 ms")}");

            sw.Reset();
            Console.WriteLine();

            Console.WriteLine("Mergesort(Int32):");
            //sortingContext.SetAlgorithm<int>(new MergeSortAlgorithm<int>(SortingAlgorithm<int>.CreateRandomArray(20000000))); // ~11000 ms
            sortingContextInt32.SetAlgorithm(new MergeSortAlgorithm <int>(array2Int32));

            sw.Start();
            sortingContextInt32.Sort();
            sw.Stop();
            sortingContextInt32.Show();

            Console.WriteLine($"\nTotal time: {sw.Elapsed.TotalMilliseconds.ToString("0.00 ms")}");
            #endregion
            Console.WriteLine("*****************************");
            #region Double Sorting
            sw.Reset();
            Console.WriteLine("Quicksort(Double):");
            sw.Start();
            sortingContextDouble.Sort();
            sw.Stop();
            sortingContextDouble.Show();

            Console.WriteLine($"\nTotal time: {sw.Elapsed.TotalMilliseconds.ToString("0.00 ms")}");

            sw.Reset();
            Console.WriteLine();

            Console.WriteLine("Mergesort(Double):");
            //sortingContext.SetAlgorithm<double>(new MergeSortAlgorithm<double>(SortingAlgorithm<double>.CreateRandomArray(20000000))); // ~11000 ms
            sortingContextDouble.SetAlgorithm(new MergeSortAlgorithm <double>(array2Double));

            sw.Start();
            sortingContextDouble.Sort();
            sw.Stop();
            sortingContextDouble.Show();

            Console.WriteLine($"\nTotal time: {sw.Elapsed.TotalMilliseconds.ToString("0.00 ms")}");
            #endregion
            Console.ReadLine();
        }
示例#7
0
 public void Init()
 {
     _sortingContext = new SortingContext <int>();
 }
示例#8
0
 public void Init()
 {
     _sortingContext = new SortingContext <double>();
 }