示例#1
0
        private void Sort(object sender, RoutedEventArgs e)
        {
            if (_targetFolder == null)
            {
                MessageBox.Show("Select a directory to organize.");
                return;
            }

            Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;

            processor = new SortProcessor(SortFactory.Resolve(sortType), new DirectoryInfo(_targetFolder));
            bool success = processor.Organize();

            SortBtn.IsEnabled = false;
            _targetFolder     = string.Empty;

            if (success)
            {
                StatusLabel.Content = "Folder organized successfully";
                MessageBox.Show("Files sorted successfully");
            }
            else
            {
                StatusLabel.Content = "Error";
                MessageBox.Show("Something went wrong!");
            }

            Mouse.OverrideCursor = System.Windows.Input.Cursors.Arrow;

            //TODO: implement rollback
        }
        public void GetLambda_ThrowsOnMissingFieldname()
        {
            var factory = new SortFactory <User, long>(new SortSpecification[0], new Dictionary <string, dynamic>());
            var ex      = Assert.Throws <ArgumentException>(() => factory.GetLambda("bogus"));

            Assert.Contains("does not exist in provided selectors", ex.Message);
        }
        public void Page_SortsDescAsRequested()
        {
            var r = new List <Role>()
            {
                new Role()
                {
                    Created = new DateTime(2011, 3, 14)
                },
                new Role()
                {
                    Created = new DateTime(2013, 3, 14)
                },
                new Role()
                {
                    Created = new DateTime(2016, 3, 14)
                },
            };
            var repo = GetRepoWithData(r, nameof(Page_SortsDescAsRequested));
            var a    = new Dictionary <string, dynamic>()
            {
                { "Created", (Expression <Func <Role, DateTime> >)(t => t.Created) }
            };
            var f = new SortFactory <Role, long>(new[] { new SortSpecification("Created", SortDirection.Descending) }, a);

            var results = repo.Page(Specification <Role> .All(), 0, 3, f);

            Assert.True(r.OrderByDescending(c => c.Created).SequenceEqual(results, new EqComparer <Role>()));
        }
        public void ApplySorts_UsesDefaultWhenNoSorts()
        {
            var factory = new SortFactory <User, long>(new SortSpecification[0], new Dictionary <string, dynamic>());
            var list    = new List <User>()
            {
                new User()
                {
                    Id = 3
                },
                new User()
                {
                    Id = 1
                },
                new User()
                {
                    Id = 4
                }
            }.AsQueryable();

            var sorted = factory.ApplySorts(list);

            Assert.Equal(1, sorted.First().Id);
            Assert.Equal(3, sorted.ElementAt(1).Id);
            Assert.Equal(4, sorted.Last().Id);
        }
        public void Page_SortsAsRequested()
        {
            // Setup
            var corresp = new List <User>()
            {
                new User()
                {
                    Created = new DateTime(2016, 3, 14)
                },
                new User()
                {
                    Created = new DateTime(2013, 3, 14)
                },
                new User()
                {
                    Created = new DateTime(2011, 3, 14)
                },
            };
            var repo = GetRepoWithData(corresp, nameof(Page_SortsAsRequested));
            var a    = new Dictionary <string, dynamic>()
            {
                { "Created", (Expression <Func <User, DateTime> >)(t => t.Created) }
            };
            var f = new SortFactory <User, long>(new[] { new SortSpecification("Created", SortDirection.Ascending) }, a);

            // Test
            var results = repo.Page(Specification <User> .All(), 0, 3, f);

            // Assert
            Assert.True(corresp.OrderBy(c => c.Created).SequenceEqual(results, new EqComparer <User>()));
        }
        public void Page_SortsDescAsRequested()
        {
            var r = new List <V_MyView>()
            {
                new V_MyView()
                {
                    Id = "1"
                },
                new V_MyView()
                {
                    Id = "3"
                },
                new V_MyView()
                {
                    Id = "2"
                },
            };
            var repo = GetRepoWithData(r, nameof(Page_SortsDescAsRequested));
            var a    = new[] { new SortSpecification("Id", SortDirection.Descending), };
            var d    = new Dictionary <string, dynamic>()
            {
                { "Id", (Expression <Func <V_MyView, string> >)(t => t.Id) }
            };
            var f       = new SortFactory <V_MyView, string>(a, d);
            var results = repo.Page(Specification <V_MyView> .All(), f, 0, 3);

            Assert.True(r.OrderByDescending(c => c.Id).SequenceEqual(results, new ReadOnlyEqComparer <V_MyView>()));
        }
示例#7
0
        public static void Process()
        {
            string input    = "";
            string sortType = "";

            Console.WriteLine("Please enter your input numbers separated by comma: ");
            input = Console.ReadLine();
            Console.WriteLine("Thank you. Please enter mode of sorting\n1. Quick Sort\n2. Merge Sort\n3. Heap Sort\n4. Bubble Sort");
            sortType = Console.ReadLine();

            List <int>   unsorted    = input.Split(',').Select(int.Parse).ToList();
            ISortFactory sortFactory = new SortFactory();
            ISortedList  sortedList  = sortFactory.SortedList(sortType);


            (sortedList.Sort(unsorted)).ForEach(Console.WriteLine);

            Console.WriteLine("Do you want to continue...");

            switch (Console.ReadLine())
            {
            case "Y":
                Process();
                break;
            }
        }
示例#8
0
        private void StartSortTask()
        {
            sortAlgorithm = SortFactory.GetRandomSortAlgorithm(window, shapes, tokenSource.Token);

            sortTask = new Task(sortAlgorithm.Sort, tokenSource.Token);

            sortTask.Start();
        }
示例#9
0
        public ActionResult OrderBy(string key, string order)
        {
            sortFactory = new SortFactory(jobContext.Jobs, order);

            var sortMethod = sortFactory.GetSortMethod(key);

            var result = sortMethod();



            return(Json(result));
        }
        public void Page_Includes()
        {
            var a = new[] { new SortSpecification("Id", SortDirection.Descending), };
            var d = new Dictionary <string, dynamic>()
            {
                { "Id", (Expression <Func <V_MyView, string> >)(t => t.Id) }
            };
            var f     = new SortFactory <V_MyView, string>(a, d);
            var repoM = GetRepoMock <V_MyView>(nameof(Page_Includes));

            repoM.Object.Page(Specification <V_MyView> .All(), f, includes: r => r.Id);
            repoM.Verify();
        }
示例#11
0
        public async Task RunQuickSortAscending(int amount)
        {
            SortFactory             factory        = new SortFactory();
            ISortable               sortable       = factory.GetSortable(Algorithm.QuickSort);
            IGeneratorItems         generatorItems = new AscendingGenerator();
            CancellationTokenSource cts            = new CancellationTokenSource();

            var p = new Progress <SortingCore.Services.TimeWatchSortable.TimeAndValue>(async m =>
            {
                await _hubContext.Clients.All.ReceiveProgressAscSortQuick(m.time, m.value);
            });

            await Sort(sortable, generatorItems, amount, p, cts);
        }
示例#12
0
 /// <summary>
 /// Operation with string from the first text box which extracts from the string massive and sorts him.
 /// </summary>
 /// <param name="sender">
 /// Pressing button activates the event
 /// </param>
 /// <param name="e">
 /// Arguments are being sended
 /// </param>
 private void SortOperation(object sender, EventArgs e)
 {
     try
     {
         var calculatorName          = ((Button)sender).Name.Substring(6);
         var calculator              = SortFactory.CreateSortCalculator(calculatorName);
         var stringListOfArguments   = txtFirst.Text;
         ValidateAndConvert convert  = new ValidateAndConvert();
         List <int>         argument = convert.StringToList(stringListOfArguments);
         calculator.Calculate(argument);
         txtResult.Text = convert.ListToString(argument);
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error: " + ex.ToString());
     }
 }
        public virtual IViewModel <T, long>[] Filter(
            ISpecification <T> spec, int page, int pageSize, SortSpecification[] sortSpecs)
        {
            Auth.AuthorizeGet();
            Logger.Information($"Requesting filtered {typeof(T).FullName}s (@{page} of {pageSize}, {JsonConvert.SerializeObject(sortSpecs?.Select(s => s.ToString()))})");
            Logger.Information($"Filter: {JsonConvert.SerializeObject(spec.Metadata)}");
            //var s = Expression.And((Expression<Func<T, bool>>)((T t) => spec(t)), (Expression<Func<T, bool>>)((T t) => Auth.GenerateFilterGet()(t)));
            var sortFactory = new SortFactory <T, long>(sortSpecs, this.SortSelectors);
            var res         = Repo
                              .Page(spec.And(Auth.GenerateFilterGet()), page, pageSize,
                                    sortFactory, includes: FilterIncludes, track: false)
                              .ToList();
            var resm = Mapper.Map <IEnumerable <IViewModel <T> > >(res);

            Logger.Information($"Returning {typeof(T).FullName} count:{resm.Count()}.");
            return(resm.ToArray());
        }
示例#14
0
        static void Main(string[] args)
        {
            //TODO:
            //la copia del array no hacerla aca, aunque revisar como se comporta con gran cantidad de datos: uso de memoria
            //implementar un Comparable en el core
            //Incluir el llamado tambn a random y ordenarlo.
            //Incluir Signal R para realizar una grafica en el front (y sea el back el q envia los datos)
            //https://docs.microsoft.com/en-us/aspnet/core/fundamentals/websockets?view=aspnetcore-2.1
            //desacoplar del hub el llamado directo a los sort y demas.
            //para las graficas agregar la del insert y en una sola grafica poder mostrar las 3 comparaciones.
            //el back devuelva cuando termina de ordenar, de esa forma se puede hacer el clean del interval

            SortFactory factory           = new SortFactory();
            ISortable   sortable          = factory.GetSortable(Algorithm.BubbleSort);
            ISortable   sortableSelection = factory.GetSortable(Algorithm.SelectionSort);
            ISortable   sortableInsertion = factory.GetSortable(Algorithm.InsertionSort);
            ISortable   sortableShell     = factory.GetSortable(Algorithm.ShellSort);
            ISortable   sortableQuick     = factory.GetSortable(Algorithm.QuickSort);
            ISortable   sortableMerge     = factory.GetSortable(Algorithm.MergeSort);

            IGeneratorItems generatorItems = new AscendingGenerator();

            List <int> iterations = new List <int>();

            iterations.Add(10000);
            //iterations.Add(100000);
            //iterations.Add(1000000);
            //iterations.Add(10000000);
            FileService fileService = new FileService();

            fileService.Delete(path);
            foreach (int iteration in iterations)
            {
                Sort(sortable, generatorItems, iteration, fileService);
                Sort(sortableSelection, generatorItems, iteration, fileService);
                Sort(sortableInsertion, generatorItems, iteration, fileService);
                Sort(sortableShell, generatorItems, iteration, fileService);
                Sort(sortableQuick, generatorItems, iteration, fileService);
                Sort(sortableMerge, generatorItems, iteration, fileService);
            }

            Console.ReadKey();
        }
        static void Main(string[] args)
        {
            try
            {
                string       input      = Console.ReadLine();
                string[]     strArray   = input.Split(" ");
                int[]        intArray   = Array.ConvertAll(strArray, int.Parse);
                ISortFactory factoryObj = new SortFactory();
                ISort        sortObj    = factoryObj.GetSort("bubble");
                sortObj.Sort(intArray);
                Console.Write("Sorted Array => ");
                Array.ForEach(intArray, k => Console.Write(k + " "));
            }
            catch (Exception ex)
            {
                Console.WriteLine(string.Format("Exception occurred, details are {0}", ex.Message));
            }

            Console.ReadKey();
        }
        public void ApplySorts_AppliesAllSorts(SortDirection dir, string expFirst1, string expFirst2)
        {
            var specs = new SortSpecification[]
            {
                new SortSpecification("Id", SortDirection.Ascending),
                new SortSpecification("First", dir),
            };
            var available = new Dictionary <string, dynamic>()
            {
                { "Id", (Expression <Func <User, long> >)(u => u.Id) },
                { "First", (Expression <Func <User, string> >)(u => u.First) }
            };

            var factory = new SortFactory <User, long>(specs, available);
            var list    = new List <User>()
            {
                new User()
                {
                    Id = 3, First = expFirst1
                },
                new User()
                {
                    Id = 3, First = expFirst2
                },
                new User()
                {
                    Id = 1
                },
                new User()
                {
                    Id = 4
                }
            }.AsQueryable();

            var sorted = factory.ApplySorts(list);

            Assert.Equal(1, sorted.First().Id);
            Assert.Equal(expFirst1, sorted.ElementAt(1).First);
            Assert.Equal(expFirst2, sorted.ElementAt(2).First);
            Assert.Equal(4, sorted.Last().Id);
        }
        public void Page_Filters()
        {
            var r = new List <V_MyView>()
            {
                new V_MyView()
                {
                    Id = "1"
                },
                new V_MyView()
                {
                    Id = "2"
                },
                new V_MyView()
                {
                    Id = "3"
                },
                new V_MyView()
                {
                    Id = "4"
                },
                new V_MyView()
                {
                    Id = "5"
                },
            };
            var repo = GetRepoWithData(r, nameof(Page_Filters));
            var a    = new[] { new SortSpecification("Id", SortDirection.Ascending), };
            var d    = new Dictionary <string, dynamic>()
            {
                { "Id", (Expression <Func <V_MyView, string> >)(t => t.Id) }
            };
            var f = new SortFactory <V_MyView, string>(a, d);

            var results = repo.Page <V_MyView>(
                Specification <V_MyView> .Start(
                    c => c.Id == "3" || c.Id == "5"), f, 0, 2);

            Assert.Equal("3", results.First().Id);
            Assert.Equal("5", results.Skip(1).First().Id);
        }
示例#18
0
 public void RadixSortTest() => TestSort(SortFactory <int> .CreateRadixSort());
示例#19
0
 public void BubbleSortTest() => TestSort(SortFactory <int> .CreateBubbleSort());
示例#20
0
 public void CocktailSortTest() => TestSort(SortFactory <int> .CreateCocktailSort());
示例#21
0
 public void GnomeSortTest() => TestSort(SortFactory <int> .CreateGnomeSort());
示例#22
0
 public void SelectionSortTest() => TestSort(SortFactory <int> .CreateSelectionSort());
示例#23
0
 public void InsertionSortTest() => TestSort(SortFactory <int> .CreateInsertionSort());
示例#24
0
 public void ShellSortTest() => TestSort(SortFactory <int> .CreateShellSort());
示例#25
0
 public void QuickSortTest() => TestSort(SortFactory <int> .CreateQuickSort());
示例#26
0
 public void MergeSortTest() => TestSort(SortFactory <int> .CreateMergeSort());
示例#27
0
        public void SortFactoryTest(Type type, string name)
        {
            Type resultType = SortFactory.CreateSortCalculator(name).GetType();

            Assert.AreEqual(type, resultType);
        }
示例#28
0
 public void TreeSortTest() => TestSort(SortFactory <int> .CreateTreeSortt());
示例#29
0
 public PersonListSortFactoryTests()
 {
     _sut = new SortFactory();
 }
示例#30
0
 public void HeapSortTest() => TestSort(SortFactory <int> .CreateHeapSort());