示例#1
0
        int Compare(PSObject x, PSObject y)
        {
            if (Descending.ToBool())
            {
                var temp = x;
                x = y;
                y = temp;
            }

            if (this.Property == null)
            {
                return(LanguagePrimitives.Compare(x, y));
            }

            foreach (var property in this.Property)
            {
                var xPropertyValue = x.Properties[property.ToString()].Value;
                var yPropertyValue = y.Properties[property.ToString()].Value;

                var result = LanguagePrimitives.Compare(xPropertyValue, yPropertyValue);
                if (result != 0)
                {
                    return(result);
                }
            }

            return(0);
        }
示例#2
0
        int Compare(PSObject x, PSObject y)
        {
            if (Descending.ToBool())
            {
                var temp = x;
                x = y;
                y = temp;
            }

            if (this.Property == null)
            {
                return(LanguagePrimitives.Compare(x, y));
            }

            foreach (var property in this.Property)
            {
                var xPropertyValue = x.BaseObject.GetType().GetProperty(property.ToString(), BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).GetValue(x.BaseObject, null);
                var yPropertyValue = y.BaseObject.GetType().GetProperty(property.ToString(), BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase).GetValue(y.BaseObject, null);

                var result = LanguagePrimitives.Compare(xPropertyValue, yPropertyValue);
                if (result != 0)
                {
                    return(result);
                }
            }

            return(0);
        }
 public override int GetHashCode()
 {
     unchecked
     {
         return((UnescapedName.GetHashCode() * 397) ^ Descending.GetHashCode());
     }
 }
示例#4
0
        public override int GetHashCode()
        {
            int hash = 17;

            hash = hash * 31 + Descending.GetHashCode();
            hash = hash * 31 + Order.GetHashCode();
            return(hash);
        }
示例#5
0
 /// <summary>
 /// Recursion method ascending & descending order.
 /// </summary>
 /// <param name="element"></param>
 public static void AscendingAndDescendingOrder(int element)
 {
     if (0 < element)
     {
         Descending.Append(element);
         AscendingAndDescendingOrder(element - 1);
         Ascending.Append(element);
     }
 }
示例#6
0
        public override int GetSemanticHashCode(ExpressionEqualityComparer comparer)
        {
            unchecked
            {
                var hash = comparer.GetHashCode(Previous);

                hash = (hash * 16777619) ^ comparer.GetHashCode(Expression);
                hash = (hash * 16777619) ^ Descending.GetHashCode();

                return(hash);
            }
        }
 public bool Equals(SortExpression other)
 {
     if (ReferenceEquals(null, other))
     {
         return(false);
     }
     if (ReferenceEquals(this, other))
     {
         return(true);
     }
     return(string.Equals(UnescapedName, other.UnescapedName) && Descending.Equals(other.Descending));
 }
示例#8
0
        /// <inheritdoc />
        protected override async Task <Result <Array <T>, IError> > Run(
            IStateMonad stateMonad,
            CancellationToken cancellationToken)
        {
            var array = await Array.Run(stateMonad, cancellationToken);

            if (array.IsFailure)
            {
                return(array.ConvertFailure <Array <T> >());
            }

            var descending = await Descending.Run(stateMonad, cancellationToken);

            if (descending.IsFailure)
            {
                return(descending.ConvertFailure <Array <T> >());
            }

            Array <T> sortedArray;

            if (KeySelector == null)
            {
                sortedArray = array.Value.Sort(descending.Value);
            }
            else
            {
                var currentState = stateMonad.GetState().ToImmutableDictionary();

                async ValueTask <string> GetKey(T entity, CancellationToken cancellation)
                {
                    var scopedMonad = new ScopedStateMonad(
                        stateMonad,
                        currentState,
                        new KeyValuePair <VariableName, object>(VariableName.Entity, entity !)
                        );

                    var result = await KeySelector.Run(scopedMonad, cancellation)
                                 .Map(x => x.GetStringAsync());

                    if (result.IsFailure)
                    {
                        throw new ErrorException(result.Error);
                    }

                    return(result.Value);
                }

                sortedArray = array.Value.Sort(descending.Value, GetKey);
            }

            return(sortedArray);
        }
        public static void CreateOrdering(object sender, object selectedItem)
        {
            if (selectedItem is OrderingCollectionViewModel orderingCollectionViewModel)
            {
                CreateOrdering(sender, orderingCollectionViewModel.Parent);
                return;
            }

            if (!(selectedItem is GroupViewModel entityGroupViewModel))
            {
                return;
            }

            var button = (Button)sender;

            var type = (string)button.CommandParameter;

            OrderByBase entity;

            switch (type)
            {
            case nameof(Ascending):
                entity = Ascending.New("Property");
                break;

            case nameof(Descending):
                entity = Descending.New("Property");
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            entityGroupViewModel.Element.Ordering.Add(entity);
            var viewModelCollection = entityGroupViewModel.Children.OfType <OrderingCollectionViewModel>().First();

            var viewModel = new OrderingViewModel(entity, viewModelCollection);

            viewModelCollection.Children.Add(viewModel);

            entityGroupViewModel.IsExpanded = true;
            viewModelCollection.IsExpanded  = true;
            viewModel.IsSelected            = true;
            viewModel.IsExpanded            = true;
        }
示例#10
0
        // Module defining this command


        // Optional custom code for this activity


        /// <summary>
        /// Returns a configured instance of System.Management.Automation.PowerShell, pre-populated with the command to run.
        /// </summary>
        /// <param name="context">The NativeActivityContext for the currently running activity.</param>
        /// <returns>A populated instance of Sytem.Management.Automation.PowerShell</returns>
        /// <remarks>The infrastructure takes responsibility for closing and disposing the PowerShell instance returned.</remarks>
        protected override ActivityImplementationContext GetPowerShell(NativeActivityContext context)
        {
            System.Management.Automation.PowerShell invoker       = global::System.Management.Automation.PowerShell.Create();
            System.Management.Automation.PowerShell targetCommand = invoker.AddCommand(PSCommandName);

            // Initialize the arguments

            if (Descending.Expression != null)
            {
                targetCommand.AddParameter("Descending", Descending.Get(context));
            }

            if (Unique.Expression != null)
            {
                targetCommand.AddParameter("Unique", Unique.Get(context));
            }

            if (InputObject.Expression != null)
            {
                targetCommand.AddParameter("InputObject", InputObject.Get(context));
            }

            if (Property.Expression != null)
            {
                targetCommand.AddParameter("Property", Property.Get(context));
            }

            if (Culture.Expression != null)
            {
                targetCommand.AddParameter("Culture", Culture.Get(context));
            }

            if (CaseSensitive.Expression != null)
            {
                targetCommand.AddParameter("CaseSensitive", CaseSensitive.Get(context));
            }


            return(new ActivityImplementationContext()
            {
                PowerShellInstance = invoker
            });
        }
示例#11
0
        public async Task pagination_returns_items_in_correct_order_descending()
        {
            const int page     = 1;
            const int pageSize = 5;

            var sorting = Descending <Person, DateTime> .By(c => c.BirthDate);

            var pagination = Pagination.Set(page, pageSize);

            var customers =
                await _realDbFixture.QueryAsync(ctx =>
                                                ctx.Persons
                                                .TakeSortedPage(sorting, pagination)
                                                .ToListAsync());

            IsOrderedDescending(
                items: customers.Select(x => x.BirthDate.Ticks),
                compare: LongsComparer,
                equal: LongsEquals).ShouldBeTrue();
        }
示例#12
0
 public void Test_DescendingOrder(int input, int expectedResult)
 {
     Assert.AreEqual(expectedResult, Descending.DescendingOrder(input));
 }
示例#13
0
        public IEnumerable <KeyValuePair <string, string> > ToKeyValues()
        {
            if (IncludeDocs)
            {
                yield return(new KeyValuePair <string, string>("include_docs", IncludeDocs.ToString().ToLower()));
            }

            if (Descending)
            {
                yield return(new KeyValuePair <string, string>("descending", Descending.ToString().ToLower()));
            }

            if (!Reduce)
            {
                yield return(new KeyValuePair <string, string>("reduce", Reduce.ToString().ToLower()));
            }

            if (!InclusiveEnd)
            {
                yield return(new KeyValuePair <string, string>("inclusive_end", InclusiveEnd.ToString().ToLower()));
            }

            if (UpdateSeq)
            {
                yield return(new KeyValuePair <string, string>("update_seq", UpdateSeq.ToString().ToLower()));
            }

            if (Group)
            {
                yield return(new KeyValuePair <string, string>("group", Group.ToString().ToLower()));
            }

            if (HasValue(GroupLevel))
            {
                yield return(new KeyValuePair <string, string>("group_level", GroupLevel.ToString()));
            }

            if (HasValue(Stale))
            {
                yield return(new KeyValuePair <string, string>("stale", FormatValue(Stale)));
            }

            if (HasValue(Key))
            {
                yield return(new KeyValuePair <string, string>("key", FormatValue(Key)));
            }

            if (HasValue(Keys))
            {
                yield return(new KeyValuePair <string, string>("keys", FormatValue(Keys)));
            }

            if (HasValue(StartKey))
            {
                yield return(new KeyValuePair <string, string>("startkey", FormatValue(StartKey)));
            }

            if (HasValue(StartKeyDocId))
            {
                yield return(new KeyValuePair <string, string>("startkey_docid", FormatValue(StartKeyDocId)));
            }

            if (HasValue(EndKey))
            {
                yield return(new KeyValuePair <string, string>("endkey", FormatValue(EndKey)));
            }

            if (HasValue(EndKeyDocId))
            {
                yield return(new KeyValuePair <string, string>("endkey_docid", FormatValue(EndKeyDocId)));
            }

            if (HasValue(Limit))
            {
                yield return(new KeyValuePair <string, string>("limit", Limit.ToString()));
            }

            if (HasValue(Skip))
            {
                yield return(new KeyValuePair <string, string>("skip", Skip.ToString()));
            }
        }