Esempio n. 1
0
        /// <summary>
        /// Process every input object to group them.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (InputObject != null && InputObject != AutomationNull.Value)
            {
                OrderByPropertyEntry currentEntry = null;

                if (!_hasProcessedFirstInputObject)
                {
                    if (Property == null)
                    {
                        Property = OrderByProperty.GetDefaultKeyPropertySet(InputObject);
                    }
                    _orderByProperty.ProcessExpressionParameter(this, Property);

                    currentEntry = _orderByProperty.CreateOrderByPropertyEntry(this, InputObject, CaseSensitive, _cultureInfo);
                    bool[] ascending = new bool[currentEntry.orderValues.Count];
                    for (int index = 0; index < currentEntry.orderValues.Count; index++)
                    {
                        ascending[index] = true;
                    }
                    _orderByPropertyComparer = new OrderByPropertyComparer(ascending, _cultureInfo, CaseSensitive);

                    _hasProcessedFirstInputObject = true;
                }
                else
                {
                    currentEntry = _orderByProperty.CreateOrderByPropertyEntry(this, InputObject, CaseSensitive, _cultureInfo);
                }

                DoGrouping(currentEntry, this.NoElement, _groups, _tupleToGroupInfoMappingDictionary, _orderByPropertyComparer);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// </summary>
        protected override void ProcessRecord()
        {
            if (ReferenceObject == null || ReferenceObject.Length == 0)
            {
                HandleDifferenceObjectOnly();
                return;
            }
            else if (DifferenceObject == null || DifferenceObject.Length == 0)
            {
                HandleReferenceObjectOnly();
                return;
            }

            if (_comparer == null && 0 < DifferenceObject.Length)
            {
                InitComparer();
            }

            List <PSObject>             differenceList    = new List <PSObject>(DifferenceObject);
            List <OrderByPropertyEntry> differenceEntries =
                OrderByProperty.CreateOrderMatrix(
                    this, differenceList, _orderByProperty.MshParameterList);

            foreach (OrderByPropertyEntry incomingEntry in differenceEntries)
            {
                Process(incomingEntry);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// </summary>
        protected override void EndProcessing()
        {
            OrderByProperty orderByProperty = new OrderByProperty(
                this, InputObjects, Property, !Descending, ConvertedCulture, CaseSensitive);

            var dataToProcess = orderByProperty.OrderMatrix;
            var comparer      = orderByProperty.Comparer;

            if (comparer == null || dataToProcess == null || dataToProcess.Count == 0)
            {
                return;
            }

            // Track the number of items that will be output from the data once it is sorted
            int sortedItemCount = dataToProcess.Count;

            // If -Stable, -Top & -Bottom were not used, invoke an in-place full sort
            if (!Stable && Top == 0 && Bottom == 0)
            {
                sortedItemCount = FullSort(dataToProcess, comparer);
            }
            // Otherwise, use an indexed min-/max-heap to perform an in-place heap sort (heap
            // sorts are inheritantly stable, meaning they will preserve the respective order
            // of duplicate objects as they are sorted on the heap)
            else
            {
                sortedItemCount = Heapify(dataToProcess, comparer);
            }

            // Write out the portion of the processed data that was sorted
            for (int index = 0; index < sortedItemCount; index++)
            {
                WriteObject(dataToProcess[index].inputObject);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// </summary>
        protected override void EndProcessing()
        {
            OrderByProperty orderByProperty = new OrderByProperty(
                this, InputObjects, Property, !Descending, ConvertedCulture, CaseSensitive);

            var dataToProcess = orderByProperty.OrderMatrix;
            var comparer      = orderByProperty.Comparer;

            if (comparer == null || dataToProcess == null || dataToProcess.Count == 0)
            {
                return;
            }

            // Track the number of items that will be output from the data once it is sorted
            int sortedItemCount = dataToProcess.Count;

            // If -Top & -Bottom were not used, or if -Top or -Bottom would return all objects, invoke
            // an in-place full sort
            if ((Top == 0 && Bottom == 0) || Top >= dataToProcess.Count || Bottom >= dataToProcess.Count)
            {
                sortedItemCount = FullSort(dataToProcess, comparer);
            }
            // Otherwise, use an indexed min-/max-heap to perform an in-place sort of all objects
            else
            {
                sortedItemCount = Heapify(dataToProcess, comparer);
            }

            // Write out the portion of the processed data that was sorted
            for (int index = 0; index < sortedItemCount; index++)
            {
                WriteObject(dataToProcess[index].inputObject);
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Process every input object to group them.
        /// </summary>
        protected override void ProcessRecord()
        {
            if (InputObject != null && InputObject != AutomationNull.Value)
            {
                OrderByPropertyEntry currentEntry;

                if (!_hasProcessedFirstInputObject)
                {
                    if (Property == null)
                    {
                        Property = OrderByProperty.GetDefaultKeyPropertySet(InputObject);
                    }

                    _orderByProperty.ProcessExpressionParameter(this, Property);

                    if (AsString && !AsHashTable)
                    {
                        ArgumentException ex = new ArgumentException(UtilityCommonStrings.GroupObjectWithHashTable);
                        ErrorRecord       er = new ErrorRecord(ex, "ArgumentException", ErrorCategory.InvalidArgument, AsString);
                        ThrowTerminatingError(er);
                    }

                    if (AsHashTable && !AsString && (Property != null && (Property.Length > 1 || _orderByProperty.MshParameterList.Count > 1)))
                    {
                        ArgumentException ex = new ArgumentException(UtilityCommonStrings.GroupObjectSingleProperty);
                        ErrorRecord       er = new ErrorRecord(ex, "ArgumentException", ErrorCategory.InvalidArgument, Property);
                        ThrowTerminatingError(er);
                    }

                    currentEntry = _orderByProperty.CreateOrderByPropertyEntry(this, InputObject, CaseSensitive, _cultureInfo);
                    bool[] ascending = new bool[currentEntry.orderValues.Count];
                    for (int index = 0; index < currentEntry.orderValues.Count; index++)
                    {
                        ascending[index] = true;
                    }

                    _orderByPropertyComparer = new OrderByPropertyComparer(ascending, _cultureInfo, CaseSensitive);

                    _hasProcessedFirstInputObject = true;
                }
                else
                {
                    currentEntry = _orderByProperty.CreateOrderByPropertyEntry(this, InputObject, CaseSensitive, _cultureInfo);
                }

                _entriesToOrder.Add(currentEntry);

                var currentEntryOrderValues = currentEntry.orderValues;
                if (!_hasDifferentValueTypes)
                {
                    UpdateOrderPropertyTypeInfo(currentEntryOrderValues);
                }
            }
        }
Esempio n. 6
0
        protected override void EndProcessing()
        {
            OrderByProperty property = new OrderByProperty(this, base.InputObjects, base.Property, true, base.ConvertedCulture, (bool)base.CaseSensitive);

            if (((property.Comparer != null) && (property.OrderMatrix != null)) && (property.OrderMatrix.Count != 0))
            {
                List <GroupInfo> sendToPipeline = DoGrouping(property.OrderMatrix, property.Comparer, (bool)this.NoElement);
                tracer.WriteLine(sendToPipeline.Count);
                if (sendToPipeline != null)
                {
                    if (this.ashashtable != 0)
                    {
                        Hashtable hashtable = CollectionsUtil.CreateCaseInsensitiveHashtable();
                        try
                        {
                            foreach (GroupInfo info in sendToPipeline)
                            {
                                if (this.asstring != 0)
                                {
                                    hashtable.Add(info.Name, info.Group);
                                }
                                else if (info.Values.Count == 1)
                                {
                                    hashtable.Add(info.Values[0], info.Group);
                                }
                                else
                                {
                                    ArgumentException exception   = new ArgumentException(UtilityCommonStrings.GroupObjectSingleProperty);
                                    ErrorRecord       errorRecord = new ErrorRecord(exception, "ArgumentException", ErrorCategory.InvalidArgument, base.Property);
                                    base.ThrowTerminatingError(errorRecord);
                                }
                            }
                        }
                        catch (ArgumentException exception2)
                        {
                            this.WriteNonTerminatingError(exception2, UtilityCommonStrings.InvalidOperation, ErrorCategory.InvalidArgument);
                            return;
                        }
                        base.WriteObject(hashtable);
                    }
                    else if (this.asstring != 0)
                    {
                        ArgumentException exception3 = new ArgumentException(UtilityCommonStrings.GroupObjectWithHashTable);
                        ErrorRecord       record2    = new ErrorRecord(exception3, "ArgumentException", ErrorCategory.InvalidArgument, this.asstring);
                        base.ThrowTerminatingError(record2);
                    }
                    else
                    {
                        base.WriteObject(sendToPipeline, true);
                    }
                }
            }
        }
Esempio n. 7
0
 private void HandleDifferenceObjectOnly()
 {
     if ((this.DifferenceObject != null) && (this.DifferenceObject.Length != 0))
     {
         List <PSObject> inputObjects = new List <PSObject>(this.DifferenceObject);
         this.orderByProperty = new OrderByProperty(this, inputObjects, this.Property, true, base._cultureInfo, (bool)base.CaseSensitive);
         foreach (OrderByPropertyEntry entry in OrderByProperty.CreateOrderMatrix(this, inputObjects, this.orderByProperty.MshParameterList))
         {
             this.EmitDifferenceOnly(entry);
         }
     }
 }
Esempio n. 8
0
 protected override void EndProcessing()
 {
     OrderByProperty property = new OrderByProperty(this, base.InputObjects, base.Property, true, base.ConvertedCulture, (bool) base.CaseSensitive);
     if (((property.Comparer != null) && (property.OrderMatrix != null)) && (property.OrderMatrix.Count != 0))
     {
         List<GroupInfo> sendToPipeline = DoGrouping(property.OrderMatrix, property.Comparer, (bool) this.NoElement);
         tracer.WriteLine(sendToPipeline.Count);
         if (sendToPipeline != null)
         {
             if (this.ashashtable != 0)
             {
                 Hashtable hashtable = CollectionsUtil.CreateCaseInsensitiveHashtable();
                 try
                 {
                     foreach (GroupInfo info in sendToPipeline)
                     {
                         if (this.asstring != 0)
                         {
                             hashtable.Add(info.Name, info.Group);
                         }
                         else if (info.Values.Count == 1)
                         {
                             hashtable.Add(info.Values[0], info.Group);
                         }
                         else
                         {
                             ArgumentException exception = new ArgumentException(UtilityCommonStrings.GroupObjectSingleProperty);
                             ErrorRecord errorRecord = new ErrorRecord(exception, "ArgumentException", ErrorCategory.InvalidArgument, base.Property);
                             base.ThrowTerminatingError(errorRecord);
                         }
                     }
                 }
                 catch (ArgumentException exception2)
                 {
                     this.WriteNonTerminatingError(exception2, UtilityCommonStrings.InvalidOperation, ErrorCategory.InvalidArgument);
                     return;
                 }
                 base.WriteObject(hashtable);
             }
             else if (this.asstring != 0)
             {
                 ArgumentException exception3 = new ArgumentException(UtilityCommonStrings.GroupObjectWithHashTable);
                 ErrorRecord record2 = new ErrorRecord(exception3, "ArgumentException", ErrorCategory.InvalidArgument, this.asstring);
                 base.ThrowTerminatingError(record2);
             }
             else
             {
                 base.WriteObject(sendToPipeline, true);
             }
         }
     }
 }
Esempio n. 9
0
 private void InitComparer()
 {
     if (this.comparer == null)
     {
         List <PSObject> inputObjects = new List <PSObject>(this.ReferenceObject);
         this.orderByProperty = new OrderByProperty(this, inputObjects, this.Property, true, base._cultureInfo, (bool)base.CaseSensitive);
         if (((this.orderByProperty.Comparer != null) && (this.orderByProperty.OrderMatrix != null)) && (this.orderByProperty.OrderMatrix.Count != 0))
         {
             this.comparer         = this.orderByProperty.Comparer;
             this.referenceEntries = this.orderByProperty.OrderMatrix;
         }
     }
 }
Esempio n. 10
0
 protected override void EndProcessing()
 {
     OrderByProperty orderByProperty = new OrderByProperty(this, base.InputObjects, base.Property, this.Descending == 0, base.ConvertedCulture, (bool) base.CaseSensitive);
     if (((orderByProperty.Comparer != null) && (orderByProperty.OrderMatrix != null)) && (orderByProperty.OrderMatrix.Count != 0))
     {
         orderByProperty.OrderMatrix.Sort(orderByProperty.Comparer);
         if (this.unique)
         {
             RemoveDuplicates(orderByProperty);
         }
         foreach (OrderByPropertyEntry entry in orderByProperty.OrderMatrix)
         {
             base.WriteObject(entry.inputObject);
         }
     }
 }
Esempio n. 11
0
        protected override void EndProcessing()
        {
            OrderByProperty orderByProperty = new OrderByProperty(this, base.InputObjects, base.Property, this.Descending == 0, base.ConvertedCulture, (bool)base.CaseSensitive);

            if (((orderByProperty.Comparer != null) && (orderByProperty.OrderMatrix != null)) && (orderByProperty.OrderMatrix.Count != 0))
            {
                orderByProperty.OrderMatrix.Sort(orderByProperty.Comparer);
                if (this.unique)
                {
                    RemoveDuplicates(orderByProperty);
                }
                foreach (OrderByPropertyEntry entry in orderByProperty.OrderMatrix)
                {
                    base.WriteObject(entry.inputObject);
                }
            }
        }
Esempio n. 12
0
 private static void RemoveDuplicates(OrderByProperty orderByProperty)
 {
     int num = 0;
     OrderByPropertyEntry firstEntry = orderByProperty.OrderMatrix[num];
     while ((num + 1) < orderByProperty.OrderMatrix.Count)
     {
         int index = num + 1;
         OrderByPropertyEntry secondEntry = orderByProperty.OrderMatrix[index];
         if (orderByProperty.Comparer.Compare(firstEntry, secondEntry) == 0)
         {
             orderByProperty.OrderMatrix.RemoveAt(index);
         }
         else
         {
             num = index;
             firstEntry = secondEntry;
         }
     }
 }
Esempio n. 13
0
        private static void RemoveDuplicates(OrderByProperty orderByProperty)
        {
            int num = 0;
            OrderByPropertyEntry firstEntry = orderByProperty.OrderMatrix[num];

            while ((num + 1) < orderByProperty.OrderMatrix.Count)
            {
                int index = num + 1;
                OrderByPropertyEntry secondEntry = orderByProperty.OrderMatrix[index];
                if (orderByProperty.Comparer.Compare(firstEntry, secondEntry) == 0)
                {
                    orderByProperty.OrderMatrix.RemoveAt(index);
                }
                else
                {
                    num        = index;
                    firstEntry = secondEntry;
                }
            }
        }
Esempio n. 14
0
        /// <summary>
        /// Remove duplicates.
        /// </summary>
        private static void RemoveDuplicates(OrderByProperty orderByProperty)
        {
            int current = 0, lookAhead;
            OrderByPropertyEntry currentObj = orderByProperty.OrderMatrix[current];
            while (current + 1 < orderByProperty.OrderMatrix.Count)
            {
                lookAhead = current + 1;
                OrderByPropertyEntry lookAheadObj = orderByProperty.OrderMatrix[lookAhead];

                if (orderByProperty.Comparer.Compare(currentObj, lookAheadObj) == 0)
                {
                    orderByProperty.OrderMatrix.RemoveAt(lookAhead);
                }
                else
                {
                    current = lookAhead;
                    currentObj = lookAheadObj;
                }
            }
        }
Esempio n. 15
0
        private void HandleDifferenceObjectOnly()
        {
            if (DifferenceObject == null || DifferenceObject.Length == 0)
            {
                return;
            }

            List <PSObject> differenceList = new List <PSObject>(DifferenceObject);

            _orderByProperty = new OrderByProperty(
                this, differenceList, Property, true, _cultureInfo, CaseSensitive);
            List <OrderByPropertyEntry> differenceEntries =
                OrderByProperty.CreateOrderMatrix(
                    this, differenceList, _orderByProperty.MshParameterList);

            foreach (OrderByPropertyEntry entry in differenceEntries)
            {
                EmitDifferenceOnly(entry);
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Remove duplicates.
        /// </summary>
        private static void RemoveDuplicates(OrderByProperty orderByProperty)
        {
            int current = 0, lookAhead;
            OrderByPropertyEntry currentObj = orderByProperty.OrderMatrix[current];

            while (current + 1 < orderByProperty.OrderMatrix.Count)
            {
                lookAhead = current + 1;
                OrderByPropertyEntry lookAheadObj = orderByProperty.OrderMatrix[lookAhead];

                if (orderByProperty.Comparer.Compare(currentObj, lookAheadObj) == 0)
                {
                    orderByProperty.OrderMatrix.RemoveAt(lookAhead);
                }
                else
                {
                    current    = lookAhead;
                    currentObj = lookAheadObj;
                }
            }
        }
Esempio n. 17
0
        /// <summary>
        /// 
        /// </summary>
        protected override void EndProcessing()
        {
            OrderByProperty orderByProperty = new OrderByProperty(
                this, InputObjects, Property, !Descending, ConvertedCulture, CaseSensitive);
            if (orderByProperty.Comparer == null || orderByProperty.OrderMatrix == null || orderByProperty.OrderMatrix.Count == 0)
            {
                return;
            }
            orderByProperty.OrderMatrix.Sort(orderByProperty.Comparer);

            if (_unique)
            {
                RemoveDuplicates(orderByProperty);
            }

            // write to output stream
            foreach (OrderByPropertyEntry x in orderByProperty.OrderMatrix)
            {
                WriteObject(x.inputObject);
            }
        }
Esempio n. 18
0
        /// <summary>
        ///
        /// </summary>
        protected override void EndProcessing()
        {
            OrderByProperty orderByProperty = new OrderByProperty(
                this, InputObjects, Property, !Descending, ConvertedCulture, CaseSensitive);

            if (orderByProperty.Comparer == null || orderByProperty.OrderMatrix == null || orderByProperty.OrderMatrix.Count == 0)
            {
                return;
            }
            orderByProperty.OrderMatrix.Sort(orderByProperty.Comparer);

            if (_unique)
            {
                RemoveDuplicates(orderByProperty);
            }

            // write to output stream
            foreach (OrderByPropertyEntry x in orderByProperty.OrderMatrix)
            {
                WriteObject(x.inputObject);
            }
        }
Esempio n. 19
0
 protected override void ProcessRecord()
 {
     if ((this.ReferenceObject == null) || (this.ReferenceObject.Length == 0))
     {
         this.HandleDifferenceObjectOnly();
     }
     else if ((this.DifferenceObject == null) || (this.DifferenceObject.Length == 0))
     {
         this.HandleReferenceObjectOnly();
     }
     else
     {
         if ((this.comparer == null) && (0 < this.DifferenceObject.Length))
         {
             this.InitComparer();
         }
         List <PSObject> inputObjects = new List <PSObject>(this.DifferenceObject);
         foreach (OrderByPropertyEntry entry in OrderByProperty.CreateOrderMatrix(this, inputObjects, this.orderByProperty.MshParameterList))
         {
             this.Process(entry);
         }
     }
 }
Esempio n. 20
0
        private void InitComparer()
        {
            if (_comparer != null)
            {
                return;
            }

            List <PSObject> referenceObjectList = new List <PSObject>(ReferenceObject);

            _orderByProperty = new OrderByProperty(
                this, referenceObjectList, Property, true, _cultureInfo, CaseSensitive);
            Diagnostics.Assert(_orderByProperty.Comparer != null, "no comparer");
            Diagnostics.Assert(
                _orderByProperty.OrderMatrix != null &&
                _orderByProperty.OrderMatrix.Count == ReferenceObject.Length,
                "no OrderMatrix");
            if (_orderByProperty.Comparer == null || _orderByProperty.OrderMatrix == null || _orderByProperty.OrderMatrix.Count == 0)
            {
                return;
            }

            _comparer         = _orderByProperty.Comparer;
            _referenceEntries = _orderByProperty.OrderMatrix;
        }
Esempio n. 21
0
 private void HandleDifferenceObjectOnly()
 {
     if ((this.DifferenceObject != null) && (this.DifferenceObject.Length != 0))
     {
         List<PSObject> inputObjects = new List<PSObject>(this.DifferenceObject);
         this.orderByProperty = new OrderByProperty(this, inputObjects, this.Property, true, base._cultureInfo, (bool) base.CaseSensitive);
         foreach (OrderByPropertyEntry entry in OrderByProperty.CreateOrderMatrix(this, inputObjects, this.orderByProperty.MshParameterList))
         {
             this.EmitDifferenceOnly(entry);
         }
     }
 }
Esempio n. 22
0
        private void InitComparer()
        {
            if (null != _comparer)
                return;

            List<PSObject> referenceObjectList = new List<PSObject>(ReferenceObject);
            _orderByProperty = new OrderByProperty(
                this, referenceObjectList, Property, true, _cultureInfo, CaseSensitive);
            Diagnostics.Assert(_orderByProperty.Comparer != null, "no comparer");
            Diagnostics.Assert(
                _orderByProperty.OrderMatrix != null &&
                _orderByProperty.OrderMatrix.Count == ReferenceObject.Length,
                "no OrderMatrix");
            if (_orderByProperty.Comparer == null || _orderByProperty.OrderMatrix == null || _orderByProperty.OrderMatrix.Count == 0)
            {
                return;
            }

            _comparer = _orderByProperty.Comparer;
            _referenceEntries = _orderByProperty.OrderMatrix;
        }
Esempio n. 23
0
        private void HandleDifferenceObjectOnly()
        {
            if (DifferenceObject == null || DifferenceObject.Length == 0)
            {
                return;
            }

            List<PSObject> differenceList = new List<PSObject>(DifferenceObject);
            _orderByProperty = new OrderByProperty(
                this, differenceList, Property, true, _cultureInfo, CaseSensitive);
            List<OrderByPropertyEntry> differenceEntries =
                OrderByProperty.CreateOrderMatrix(
                this, differenceList, _orderByProperty.MshParameterList);

            foreach (OrderByPropertyEntry entry in differenceEntries)
            {
                EmitDifferenceOnly(entry);
            }
        }
Esempio n. 24
0
 private void InitComparer()
 {
     if (this.comparer == null)
     {
         List<PSObject> inputObjects = new List<PSObject>(this.ReferenceObject);
         this.orderByProperty = new OrderByProperty(this, inputObjects, this.Property, true, base._cultureInfo, (bool) base.CaseSensitive);
         if (((this.orderByProperty.Comparer != null) && (this.orderByProperty.OrderMatrix != null)) && (this.orderByProperty.OrderMatrix.Count != 0))
         {
             this.comparer = this.orderByProperty.Comparer;
             this.referenceEntries = this.orderByProperty.OrderMatrix;
         }
     }
 }