Exemplo n.º 1
0
        private void AssociatedObject_Sorting(object sender, GridViewSortingEventArgs e)
        {
            e.Cancel = true;
            var sortByPropertyName = (( GridViewDataColumn )e.Column).DataMemberBinding.Path.Path;

            switch (e.OldSortingState)
            {
            case SortingState.None:
                e.NewSortingState = SortingState.Ascending;
                SortDirection     = ListSortDirection.Ascending;
                SortBy            = sortByPropertyName;
                break;

            case SortingState.Ascending:
                e.NewSortingState = SortingState.Descending;
                SortDirection     = ListSortDirection.Descending;
                SortBy            = sortByPropertyName;
                break;

            case SortingState.Descending:
                SortDirection = ListSortDirection.Ascending;
                SortBy        = sortByPropertyName;
                break;

            default:
                break;
            }

            // Sort executed server-side.
            SortCommand.Execute(null);
        }
Exemplo n.º 2
0
        public IList <Book> FindAll(SortCommand sortCommand = null, IList <FilterCommand> filterCommands = null, PageCommand pageCommand = null)
        {
            IQuery query = null;

            if (!string.IsNullOrWhiteSpace(sortCommand?.SortKey))
            {
                query = ApplySortCommand(sortCommand, query);
            }

            if (!ListUtils.IsListNullOrEmpty(filterCommands))
            {
                query = ApplyFilterCommands(filterCommands, query);
            }

            if (pageCommand?.Limit > 0 || pageCommand?.Offset > 0)
            {
                query = ApplyPageCommand(pageCommand, query);
            }

            if (query != null)
            {
                return(query.Execute <Book>());
            }

            return(FindAll());
        }
Exemplo n.º 3
0
        public void CorrectInstancesAreUsedForSortCommand()
        {
            this.BuildTournamentSelector();

            // Send a simple sort command and wait for completion.
            var originalCommand = new SortCommand <TestInstance>(
                this.CreateGenomesAdheringToParameterTree(GenomeSorterTest.TotalNumberEvaluationActors),
                this._singleTestInstance);

            this._genomeSorter.Tell(originalCommand);
            this.ExpectMsg <SortResult>();

            // Build a new sort command with several new instances.
            var instances = new List <TestInstance>
            {
                new TestInstance("1"),
                new TestInstance("2"),
            };
            var genomes       = this.CreateGenomesAdheringToParameterTree(GenomeSorterTest.TotalNumberEvaluationActors);
            var selectCommand = new SortCommand <TestInstance>(genomes, instances.ToImmutableList());

            // Send it & wait for completion.
            this._genomeSorter.Tell(selectCommand);
            this.ExpectMsg <SortResult>();

            // Check that storage actor has knowledge about both new instances for both genomes.
            foreach (var genome in genomes)
            {
                foreach (var instance in instances)
                {
                    this._resultStorageActor.Tell(new ResultRequest <TestInstance>(genome, instance));
                    this.ExpectMsg <ResultMessage <TestInstance, IntegerResult> >();
                }
            }
        }
Exemplo n.º 4
0
        public void SetUp()
        {
            new ArbiterMSBuildLocator().RegisterDefaults();

            var container = ContainerHelper.ConfigureContainer().WithRealFileSystem().Build();

            _command = container.Resolve <SortCommand>();
            _console = container.Resolve <IConsole>();
        }
Exemplo n.º 5
0
 public ChildCommands(DiffCommand diff, SetupComCommand setupCom, CleanCommand cleanCom, SortCommand sort, GraphCommand graph, AnalyzeCommand analyze)
 {
     Diff     = diff;
     SetupCom = setupCom;
     CleanCom = cleanCom;
     Sort     = sort;
     Graph    = graph;
     Analyze  = analyze;
 }
        public ArrayVisualizerViewModel(Canvas canvas)
        {
            Sort = new SortCommand(this);

            ValueModels = new ValueModel[amount];
            for (int i = 0; i < amount; i++)
            {
                ValueModels[i] = new ValueModel(canvas, i);
            }
        }
Exemplo n.º 7
0
 private void ItemPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (FindUnusedAndMissingCommand != null)
     {
         FindUnusedAndMissingCommand.RaiseCanExecuteChanged();
         SortCommand.RaiseCanExecuteChanged();
     }
     ViewComplexObjectsCommand?.RaiseCanExecuteChanged();
     DeleteCommand?.RaiseCanExecuteChanged();
 }
 /// <summary>
 /// Actor is ready to process <see cref="SortCommand{TInstance}"/>s.
 /// </summary>
 protected override void Ready()
 {
     // Switch to working state if a genome sorting command was sent.
     this.Receive <SortCommand <TInstance> >(
         command =>
     {
         this._sortCommand  = command;
         this.CommandIssuer = this.Sender;
         this.BecomeWorking();
     });
 }
Exemplo n.º 9
0
 private void OnSorting(object sender, DataGridSortingEventArgs eventArgs)
 {
     eventArgs.Handled = true;
     if (SortCommand != null)
     {
         var column        = eventArgs.Column;
         var sortDirection = GetNextSortDirection(column.SortDirection);
         column.SortDirection = sortDirection;
         SortCommand.Execute(new SortData(column.Header.ToString(), sortDirection));
     }
 }
Exemplo n.º 10
0
        static void SortObj(Dictionary <int, Car> Cars)
        {
            string SortCommand;

            Console.WriteLine("Izberite atribut po katerem želite sortirati avtomobile");
            Console.WriteLine();
            Console.WriteLine("1. Moč");
            Console.WriteLine("2. Hitrost");
            Console.WriteLine("3. Teža");
            Console.WriteLine("4. Znamka");

            SortCommand = Console.ReadLine();

            if (SortCommand.Equals("1"))
            {
                var CarsSorted = Cars.Values.OrderBy(v => v.Power);

                foreach (Car car in CarsSorted)
                {
                    Console.WriteLine(car.PrintWithUnit());
                }
            }

            if (SortCommand.Equals("2"))
            {
                var CarsSorted = Cars.Values.OrderBy(v => v.TopSpeed);

                foreach (Car car in CarsSorted)
                {
                    Console.WriteLine(car.PrintWithUnit());
                }
            }

            if (SortCommand.Equals("3"))
            {
                var CarsSorted = Cars.Values.OrderBy(v => v.Weight);

                foreach (Car car in CarsSorted)
                {
                    Console.WriteLine(car.PrintWithUnit());
                }
            }

            if (SortCommand.Equals("4"))
            {
                var CarsSorted = Cars.Values.OrderBy(v => v.Brand);

                foreach (Car car in CarsSorted)
                {
                    Console.WriteLine(car.PrintWithUnit());
                }
            }
        }
Exemplo n.º 11
0
        static void Main(string[] args)
        {
            // setup description of this application
            var app = new CommandLineApplication();

            app.Name        = "name-sorter";
            app.Description = "This command tool help to sort names by last name then given name.";
            app.HelpOption("-? | -h | --help");

            // configure sort command
            SortCommand.Configure(app);
            app.Execute(args);
        }
Exemplo n.º 12
0
        public void ParseArgumentsSetsIndexAndDescendingWhenDescendingProvided()
        {
            SortCommand cmd = new SortCommand();

            cmd.ArgumentsString = @"""col 3"" DESC";
            Document         doc     = new Document();
            var              slide   = new SlideElement(doc);
            ShapeElementBase element = (ShapeElementBase)(ShapeElementBaseTest.Create());

            cmd.TargetElement = element;
            cmd.ParseArguments();
            Assert.AreEqual("col 3", cmd.Index.Name);
            Assert.AreEqual(SortOrder.Descending, cmd.SortOrder);
        }
        private void HeaderCell_OnHeaderTapped(object sender, DataGridColumn dataGridColumn)
        {
            if (_currentSortingColumn != dataGridColumn && dataGridColumn.SortingEnabled)
            {
                _currentSortingColumn?.ResetOrderType();
                _currentSortingColumn = dataGridColumn;
            }

            if (_autoSort && _currentSortingColumn != null && _currentSortingColumn.SortingEnabled)
            {
                var orderQuery = ItemsSource.AsQueryable().SortBy(_currentSortingColumn.PropertyName, _currentSortingColumn.SortOrderType);

                SortCommand?.Execute(orderQuery);
            }
            HeaderTappedCommand?.Execute(dataGridColumn);
        }
Exemplo n.º 14
0
        public Stream GetExcel(string filter, SortCommand sortCommand, bool isSortedDesc)
        {
            List <ContactDto> table;

            using (var database = new PhoneBookDatabaseEntities())
            {
                table = GetFullData(filter, database.Contact, sortCommand, isSortedDesc).ToList();
            }

            using (var workbook = new XLWorkbook())
            {
                var worksheet = workbook.Worksheets.Add("Контакты");

                worksheet.ColumnWidth = 20;

                worksheet.Cell("A1").Value = "Фамилия";
                worksheet.Cell("B1").Value = "Имя";
                worksheet.Cell("C1").Value = "Телефон";

                var i = 2;
                foreach (var contact in table)
                {
                    worksheet.Cell("A" + i).Value = contact.Surname;
                    worksheet.Cell("B" + i).Value = contact.Name;
                    worksheet.Cell("C" + i).Value = contact.Phone;
                    ++i;
                }

                var range = worksheet.Range("A1", "C" + (i - 1));

                worksheet.Range("C2", "C" + (i - 1)).DataType = XLCellValues.Text;

                range.CreateTable();

                var memoryStream = new MemoryStream();
                workbook.SaveAs(memoryStream);

                HttpContext.Current.Response.Headers["Content-Disposition"] = "attachment; filename=contacts.xlsx";
                HttpContext.Current.Response.ContentType = "application/octet-stream";

                memoryStream.Position = 0;
                return(memoryStream);
            }
        }
Exemplo n.º 15
0
 public MainWindowVM()
 {
     using (FileStream fs = new FileStream("Words.dat", FileMode.OpenOrCreate))
     {
         BinaryFormatter formater = new BinaryFormatter();
         if (fs.Length > 0)
         {
             _wordsList = (ObservableCollection <Words>)formater.Deserialize(fs);
         }
         else
         {
             _wordsList = new ObservableCollection <Words>();
         }
     }
     deleteCommand   = new DeleteCommand(this);
     newWordCommand  = new AddWordCommand(this);
     sortCommand     = new SortCommand(this);
     ViewList        = new CollectionViewSource();
     ViewList.Source = _wordsList;
 }
Exemplo n.º 16
0
        public void ApplyToDataSortsData()
        {
            SortCommand cmd = new SortCommand()
            {
                Index = new Index("column 1"), SortOrder = SortOrder.Descending
            };
            DataElement da = Helpers.CreateTestDataElement();

            cmd.ApplyToData(da);
            Assert.AreEqual(5.05, da.Columns[0].Data[0]);
            Assert.AreEqual(1.0, da.Columns[0].Data[1]);
            Assert.AreEqual("client 2", da.Columns[1].Data[0]);
            Assert.AreEqual("client 1", da.Columns[1].Data[1]);
            Assert.AreEqual(true, da.Columns[2].Data[0]);
            Assert.AreEqual(false, da.Columns[2].Data[1]);
            Assert.AreEqual(da.Columns[0].Data[0], da.Rows[0].Data[0]);
            Assert.AreEqual(da.Columns[0].Data[1], da.Rows[1].Data[0]);
            Assert.AreEqual(da.Columns[1].Data[0], da.Rows[0].Data[1]);
            Assert.AreEqual(da.Columns[1].Data[1], da.Rows[1].Data[1]);
            Assert.AreEqual(da.Columns[2].Data[0], da.Rows[0].Data[2]);
            Assert.AreEqual(da.Columns[2].Data[1], da.Rows[1].Data[2]);
        }
        private void MouseDownOnHeaderCell(object sender, MouseEventArgs args)
        {
            var cellClicked = (( FrameworkElement )args.OriginalSource).ParentOfType <GridViewHeaderCell> ();

            if (cellClicked == null)
            {
                return;
            }
            var column             = ( GridViewDataColumn )cellClicked.Column;
            var sortByPropertyName = (column).DataMemberBinding.Path.Path;

            var oldSortDirection = SortDirection;

            if (sortByPropertyName != SortBy)
            {
                oldSortDirection = ListSortDirection.Descending;
            }

            switch (oldSortDirection)
            {
            case ListSortDirection.Ascending:
                column.SortingState = SortingState.Descending;
                SortDirection       = ListSortDirection.Descending;
                SortBy = sortByPropertyName;
                break;

            case ListSortDirection.Descending:
                column.SortingState = SortingState.Ascending;
                SortDirection       = ListSortDirection.Ascending;
                SortBy = sortByPropertyName;
                break;

            default:
                break;
            }

            // Sort executed server-side.
            SortCommand.Execute(null);
        }
Exemplo n.º 18
0
 public IEnumerable <Book> Get(SortCommand sortCommand, BookFilterCommand filterCommand, PageCommand pageCommand)
 {
     return(bookService.FindAll(sortCommand, bookService.GetFilterCommands(filterCommand), pageCommand));
 }
Exemplo n.º 19
0
 /// <summary>
 /// Creates a sorting query.
 /// </summary>
 /// <param name="sortCommand">The sort command to use.</param>
 /// <param name="query">Optional query to append to.</param>
 /// <returns>A query with the sorting command applied.</returns>
 private IQuery ApplySortCommand(SortCommand sortCommand, IQuery query = null)
 {
     return((query == null) ? firestoreService.OrderBy(CollectionId, sortCommand.SortKey, sortCommand.SortBy)
     : query.OrderBy(sortCommand.SortKey, sortCommand.SortBy));
 }
 /// <summary>
 /// Resets all fields that change between two different commands.
 /// </summary>
 protected override void ResetCommandSpecificFields()
 {
     this._sortCommand = null;
     base.ResetCommandSpecificFields();
 }
Exemplo n.º 21
0
        private static IQueryable <ContactDto> GetFullData(string filter, IQueryable <Contact> contact, SortCommand sortCommand,
                                                           bool isSortedDesc)
        {
            var data = contact.Select(c => new ContactDto
            {
                Id      = c.Id,
                Name    = c.Name,
                Surname = c.Surname,
                Phone   = c.Phone
            }).Where(c => c.Surname.Contains(filter) || c.Name.Contains(filter) || c.Phone.Contains(filter));

            if (!isSortedDesc)
            {
                if (sortCommand == SortCommand.Name)
                {
                    return(data.OrderBy(c => c.Name));
                }
                if (sortCommand == SortCommand.Surname)
                {
                    return(data.OrderBy(c => c.Surname));
                }
                return(data.OrderBy(c => c.Phone));
            }
            if (sortCommand == SortCommand.Name)
            {
                return(data.OrderByDescending(c => c.Name));
            }
            if (sortCommand == SortCommand.Surname)
            {
                return(data.OrderByDescending(c => c.Surname));
            }
            return(data.OrderByDescending(c => c.Phone));
        }
        public Command ParseCommand(string commandInput)
        {
            var commandArguments = commandInput.Split(new [] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            // first check if it's a valid command

            var length = commandArguments.Length;

            Command command = null;

            var action     = commandArguments[0];
            var parameters = commandArguments.Skip(1).ToList();


            // make it with reflection, if you hate your life
            switch (action)
            {
            case "append":
                ValidateCommandLength(length, Constants.AppendCommandLength);
                command = new AppendCommand(parameters);
                break;

            case "prepend":
                ValidateCommandLength(length, Constants.PrependCommandLength);
                command = new PrependCommand(parameters);
                break;

            case "reverse":
                ValidateCommandLength(length, Constants.ReverseCommandLength);
                command = new ReverseCommand(parameters);
                break;

            case "insert":
                ValidateCommandLength(length, Constants.InsertCommandLength);
                command = new InsertCommand(parameters);
                break;

            case "delete":
                ValidateCommandLength(length, Constants.DeleteCommandLength);
                command = new DeleteCommand(parameters);
                break;

            case "roll":
                ValidateCommandLength(length, Constants.RollCommandLength);
                command = new RollCommand(parameters);
                break;

            case "sort":
                ValidateCommandLength(length, Constants.SortCommandLength);
                command = new SortCommand(parameters);
                break;

            case "count":
                ValidateCommandLength(length, Constants.CountCommandLength);
                command = new CountCommand(parameters);
                break;

            case "end":
                this.logger.Write(Constants.FinishedMessage);
                command = new EndCommand(parameters);
                break;

            default:
                throw new ArgumentException(Constants.InvalidCommand);
            }

            return(command);
        }
 public void RefreshSorting()
 {
     SortCommand.Refresh(LastSortDescr);
 }
        public void InstancesAreSetCorrectly()
        {
            var result = new SortCommand <TestInstance>(this._items, this._instances);

            TestUtils.SetsAreEquivalent(this._instances, result.Instances);
        }