示例#1
0
 private void EmitMatch(OrderByPropertyEntry entry)
 {
     if (this.IncludeEqual != 0)
     {
         this.Emit(entry, "==");
     }
 }
示例#2
0
        /// <summary>
        /// Utility function used to create OrderByPropertyEntry for the supplied input object.
        /// </summary>
        /// <param name="cmdlet">PSCmdlet</param>
        /// <param name="inputObject">Input Object.</param>
        /// <param name="isCaseSensitive">Indicates if the Property value comparisons need to be case sensitive or not.</param>
        /// <param name="cultureInfo">Culture Info that needs to be used for comparison.</param>
        /// <returns>OrderByPropertyEntry for the supplied InputObject.</returns>
        internal OrderByPropertyEntry CreateOrderByPropertyEntry(
            PSCmdlet cmdlet,
            PSObject inputObject,
            bool isCaseSensitive,
            CultureInfo cultureInfo)
        {
            Diagnostics.Assert(cmdlet != null, "cmdlet must be an instance");

            if (_unExpandedParametersWithWildCardPattern != null)
            {
                ExpandExpressions(inputObject, _unExpandedParametersWithWildCardPattern, _mshParameterList);
            }

            List <ErrorRecord>   evaluationErrors     = new List <ErrorRecord>();
            List <string>        propertyNotFoundMsgs = new List <string>();
            OrderByPropertyEntry result =
                OrderByPropertyEntryEvaluationHelper.ProcessObject(inputObject, _mshParameterList, evaluationErrors, propertyNotFoundMsgs, isCaseSensitive, cultureInfo);

            foreach (ErrorRecord err in evaluationErrors)
            {
                cmdlet.WriteError(err);
            }
            foreach (string debugMsg in propertyNotFoundMsgs)
            {
                cmdlet.WriteDebug(debugMsg);
            }

            return(result);
        }
示例#3
0
 private void EmitMatch(OrderByPropertyEntry entry)
 {
     if (this.IncludeEqual != 0)
     {
         this.Emit(entry, "==");
     }
 }
示例#4
0
 internal GroupInfo(OrderByPropertyEntry groupValue)
 {
     Group = new Collection <PSObject>();
     this.Add(groupValue.inputObject);
     GroupValue = groupValue;
     Name       = BuildName(groupValue.orderValues);
 }
示例#5
0
 private void EmitMatch(OrderByPropertyEntry entry)
 {
     if (_includeEqual)
     {
         Emit(entry, SideIndicatorMatch);
     }
 }
示例#6
0
        internal static List <OrderByPropertyEntry> CreateOrderMatrix(
            PSCmdlet cmdlet,
            List <PSObject> inputObjects,
            List <MshParameter> mshParameterList
            )
        {
            List <OrderByPropertyEntry> orderMatrixToCreate = new List <OrderByPropertyEntry>();

            foreach (PSObject so in inputObjects)
            {
                if (so == null || so == AutomationNull.Value)
                {
                    continue;
                }
                List <ErrorRecord>   evaluationErrors     = new List <ErrorRecord>();
                List <string>        propertyNotFoundMsgs = new List <string>();
                OrderByPropertyEntry result =
                    OrderByPropertyEntryEvaluationHelper.ProcessObject(so, mshParameterList, evaluationErrors, propertyNotFoundMsgs);
                foreach (ErrorRecord err in evaluationErrors)
                {
                    cmdlet.WriteError(err);
                }
                foreach (string debugMsg in propertyNotFoundMsgs)
                {
                    cmdlet.WriteDebug(debugMsg);
                }
                orderMatrixToCreate.Add(result);
            }

            return(orderMatrixToCreate);
        }
示例#7
0
        internal static OrderByPropertyEntry ProcessObject(PSObject inputObject, List <MshParameter> mshParameterList,
                                                           List <ErrorRecord> errors, List <string> propertyNotFoundMsgs, bool isCaseSensitive = false, CultureInfo cultureInfo = null)
        {
            Diagnostics.Assert(errors != null, "errors cannot be null!");
            Diagnostics.Assert(propertyNotFoundMsgs != null, "propertyNotFoundMsgs cannot be null!");
            OrderByPropertyEntry entry = new OrderByPropertyEntry();

            entry.inputObject = inputObject;

            if (mshParameterList == null || mshParameterList.Count == 0)
            {
                // we do not have a property to evaluate, we sort on $_
                entry.orderValues.Add(new ObjectCommandPropertyValue(inputObject, isCaseSensitive, cultureInfo));
                return(entry);
            }

            // we need to compute the properties
            foreach (MshParameter p in mshParameterList)
            {
                string propertyNotFoundMsg = null;
                EvaluateSortingExpression(p, inputObject, entry.orderValues, errors, out propertyNotFoundMsg);
                if (!string.IsNullOrEmpty(propertyNotFoundMsg))
                {
                    propertyNotFoundMsgs.Add(propertyNotFoundMsg);
                }
            }
            return(entry);
        }
示例#8
0
 private void EmitReferenceOnly(OrderByPropertyEntry entry)
 {
     if (!ExcludeDifferent)
     {
         Emit(entry, SideIndicatorReference);
     }
 }
示例#9
0
 private void EmitReferenceOnly(OrderByPropertyEntry entry)
 {
     if (this.ExcludeDifferent == 0)
     {
         this.Emit(entry, "<=");
     }
 }
示例#10
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);
            }
        }
示例#11
0
 private void EmitReferenceOnly(OrderByPropertyEntry entry)
 {
     if (this.ExcludeDifferent == 0)
     {
         this.Emit(entry, "<=");
     }
 }
示例#12
0
        private void Process(OrderByPropertyEntry differenceEntry)
        {
            OrderByPropertyEntry firstEntry = null;

            if (this.referenceObjectIndex < this.referenceEntries.Count)
            {
                firstEntry = this.referenceEntries[this.referenceObjectIndex++];
            }
            if (((firstEntry != null) && (differenceEntry != null)) && (this.comparer.Compare(firstEntry, differenceEntry) == 0))
            {
                this.EmitMatch(firstEntry);
            }
            else
            {
                OrderByPropertyEntry entry = this.MatchAndRemove(differenceEntry, this.referenceEntryBacklog);
                if (entry != null)
                {
                    this.EmitMatch(entry);
                    differenceEntry = null;
                }
                if (this.MatchAndRemove(firstEntry, this.differenceEntryBacklog) != null)
                {
                    this.EmitMatch(firstEntry);
                    firstEntry = null;
                }
                if (differenceEntry != null)
                {
                    if (0 < this.SyncWindow)
                    {
                        while (this.differenceEntryBacklog.Count >= this.SyncWindow)
                        {
                            this.EmitDifferenceOnly(this.differenceEntryBacklog[0]);
                            this.differenceEntryBacklog.RemoveAt(0);
                        }
                        this.differenceEntryBacklog.Add(differenceEntry);
                    }
                    else
                    {
                        this.EmitDifferenceOnly(differenceEntry);
                    }
                }
                if (firstEntry != null)
                {
                    if (0 < this.SyncWindow)
                    {
                        while (this.referenceEntryBacklog.Count >= this.SyncWindow)
                        {
                            this.EmitReferenceOnly(this.referenceEntryBacklog[0]);
                            this.referenceEntryBacklog.RemoveAt(0);
                        }
                        this.referenceEntryBacklog.Add(firstEntry);
                    }
                    else
                    {
                        this.EmitReferenceOnly(firstEntry);
                    }
                }
            }
        }
示例#13
0
        private void Emit(OrderByPropertyEntry entry, string sideIndicator)
        {
            Diagnostics.Assert(entry != null, "null entry");

            PSObject mshobj;

            if (PassThru)
            {
                mshobj = PSObject.AsPSObject(entry.inputObject);
            }
            else
            {
                mshobj = new PSObject();
                if (Property == null || 0 == Property.Length)
                {
                    PSNoteProperty inputNote = new PSNoteProperty(
                        InputObjectPropertyName, entry.inputObject);
                    mshobj.Properties.Add(inputNote);
                }
                else
                {
                    List <MshParameter> mshParameterList = _orderByProperty.MshParameterList;
                    Diagnostics.Assert(mshParameterList != null, "null mshParameterList");
                    Diagnostics.Assert(mshParameterList.Count == Property.Length, "mshParameterList.Count " + mshParameterList.Count);

                    for (int i = 0; i < Property.Length; i++)
                    {
                        // 2005/07/05 This is the closest we can come to
                        // the string typed by the user
                        MshParameter mshParameter = mshParameterList[i];
                        Diagnostics.Assert(mshParameter != null, "null mshParameter");
                        Hashtable hash = mshParameter.hash;
                        Diagnostics.Assert(hash != null, "null hash");
                        object prop = hash[FormatParameterDefinitionKeys.ExpressionEntryKey];
                        Diagnostics.Assert(prop != null, "null prop");
                        string         propName     = prop.ToString();
                        PSNoteProperty propertyNote = new PSNoteProperty(
                            propName,
                            entry.orderValues[i].PropertyValue);
                        try
                        {
                            mshobj.Properties.Add(propertyNote);
                        }
                        catch (ExtendedTypeSystemException)
                        {
                            // this is probably a duplicate add
                        }
                    }
                }
            }

            mshobj.Properties.Remove(SideIndicatorPropertyName);
            PSNoteProperty sideNote = new PSNoteProperty(
                SideIndicatorPropertyName, sideIndicator);

            mshobj.Properties.Add(sideNote);
            WriteObject(mshobj);
        }
示例#14
0
 private static int FindInObjectGroups(List <GroupInfo> groups, OrderByPropertyEntry target, OrderByPropertyComparer comparer)
 {
     for (int i = 0; i < groups.Count; i++)
     {
         if (comparer.Compare(groups[i].GroupValue, target) == 0)
         {
             return(i);
         }
     }
     return(-1);
 }
示例#15
0
        /// <summary>
        /// Utility function called by Group-Object to create Groups.
        /// </summary>
        /// <param name="currentObjectEntry">Input object that needs to be grouped.</param>
        /// <param name="noElement">True if we are not accumulating objects.</param>
        /// <param name="groups">List containing Groups.</param>
        /// <param name="groupInfoDictionary">Dictionary used to keep track of the groups with hash of the property values being the key.</param>
        /// <param name="orderByPropertyComparer">The Comparer to be used while comparing to check if new group has to be created.</param>
        private static void DoOrderedGrouping(
            OrderByPropertyEntry currentObjectEntry,
            bool noElement,
            List <GroupInfo> groups,
            Dictionary <object, GroupInfo> groupInfoDictionary,
            OrderByPropertyComparer orderByPropertyComparer)
        {
            var currentObjectOrderValues = currentObjectEntry.orderValues;

            if (currentObjectOrderValues != null && currentObjectOrderValues.Count > 0)
            {
                object currentTupleObject = PSTuple.ArrayToTuple(currentObjectOrderValues);

                if (groupInfoDictionary.TryGetValue(currentTupleObject, out var currentGroupInfo))
                {
                    // add this inputObject to an existing group
                    currentGroupInfo.Add(currentObjectEntry.inputObject);
                }
                else
                {
                    bool isCurrentItemGrouped = false;

                    if (groups.Count > 0)
                    {
                        var lastGroup = groups[groups.Count - 1];

                        // Check if the current input object can be converted to one of the already known types
                        // by looking up in the type to GroupInfo mapping.
                        if (orderByPropertyComparer.Compare(lastGroup.GroupValue, currentObjectEntry) == 0)
                        {
                            lastGroup.Add(currentObjectEntry.inputObject);
                            isCurrentItemGrouped = true;
                        }
                    }

                    if (!isCurrentItemGrouped)
                    {
                        // create a new group
                        s_tracer.WriteLine("Create a new group: {0}", currentObjectOrderValues);
                        GroupInfo newObjGrp = noElement
                            ? new GroupInfoNoElement(currentObjectEntry)
                            : new GroupInfo(currentObjectEntry);

                        groups.Add(newObjGrp);

                        groupInfoDictionary.Add(currentTupleObject, newObjGrp);
                    }
                }
            }
        }
示例#16
0
 private OrderByPropertyEntry MatchAndRemove(OrderByPropertyEntry match, List <OrderByPropertyEntry> list)
 {
     if ((match != null) && (list != null))
     {
         for (int i = 0; i < list.Count; i++)
         {
             OrderByPropertyEntry secondEntry = list[i];
             if (this.comparer.Compare(match, secondEntry) == 0)
             {
                 list.RemoveAt(i);
                 return(secondEntry);
             }
         }
     }
     return(null);
 }
示例#17
0
        /// <summary>
        /// Utility function called by Group-Object to create Groups.
        /// </summary>
        /// <param name="currentObjectEntry">Input object that needs to be grouped.</param>
        /// <param name="noElement">true if we are not accumulating objects</param>
        /// <param name="groups">List containing Groups.</param>
        /// <param name="groupInfoDictionary">Dictionary used to keep track of the groups with hash of the property values being the key.</param>
        /// <param name="orderByPropertyComparer">The Comparer to be used while comparing to check if new group has to be created.</param>
        internal static void DoGrouping(OrderByPropertyEntry currentObjectEntry, bool noElement, List <GroupInfo> groups, Dictionary <object, GroupInfo> groupInfoDictionary,
                                        OrderByPropertyComparer orderByPropertyComparer)
        {
            if (currentObjectEntry != null && currentObjectEntry.orderValues != null && currentObjectEntry.orderValues.Count > 0)
            {
                object currentTupleObject = PSTuple.ArrayToTuple(currentObjectEntry.orderValues.ToArray());

                GroupInfo currentGroupInfo = null;
                if (groupInfoDictionary.TryGetValue(currentTupleObject, out currentGroupInfo))
                {
                    if (currentGroupInfo != null)
                    {
                        //add this inputObject to an existing group
                        currentGroupInfo.Add(currentObjectEntry.inputObject);
                    }
                }
                else
                {
                    bool isCurrentItemGrouped = false;

                    for (int groupsIndex = 0; groupsIndex < groups.Count; groupsIndex++)
                    {
                        // Check if the current input object can be converted to one of the already known types
                        // by looking up in the type to GroupInfo mapping.
                        if (orderByPropertyComparer.Compare(groups[groupsIndex].GroupValue, currentObjectEntry) == 0)
                        {
                            groups[groupsIndex].Add(currentObjectEntry.inputObject);
                            isCurrentItemGrouped = true;
                            break;
                        }
                    }

                    if (!isCurrentItemGrouped)
                    {
                        // create a new group
                        s_tracer.WriteLine("Create a new group: {0}", currentObjectEntry.orderValues);
                        GroupInfo newObjGrp = noElement ? new GroupInfoNoElement(currentObjectEntry) : new GroupInfo(currentObjectEntry);
                        groups.Add(newObjGrp);

                        groupInfoDictionary.Add(currentTupleObject, newObjGrp);
                    }
                }
            }
        }
示例#18
0
        private void Emit(OrderByPropertyEntry entry, string sideIndicator)
        {
            Diagnostics.Assert(entry != null, "null entry");

            PSObject mshobj;

            if (PassThru)
            {
                mshobj = PSObject.AsPSObject(entry.inputObject);
            }
            else
            {
                mshobj = new PSObject();
                if (Property is null || 0 == Property.Length)
                {
                    PSNoteProperty inputNote = new PSNoteProperty(
                        InputObjectPropertyName, entry.inputObject);
                    mshobj.Properties.Add(inputNote);
                }
示例#19
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;
                }
            }
        }
示例#20
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;
                }
            }
        }
示例#21
0
 private OrderByPropertyEntry MatchAndRemove(
     OrderByPropertyEntry match,
     List <OrderByPropertyEntry> list)
 {
     if (match == null || list == null)
     {
         return(null);
     }
     Diagnostics.Assert(_comparer != null, "null comparer");
     for (int i = 0; i < list.Count; i++)
     {
         OrderByPropertyEntry listEntry = list[i];
         Diagnostics.Assert(listEntry != null, "null listEntry " + i);
         if (0 == _comparer.Compare(match, listEntry))
         {
             list.RemoveAt(i);
             return(listEntry);
         }
     }
     return(null);
 }
 internal static OrderByPropertyEntry ProcessObject(PSObject inputObject, List<MshParameter> mshParameterList, List<ErrorRecord> errors, List<string> propertyNotFoundMsgs)
 {
     OrderByPropertyEntry entry = new OrderByPropertyEntry {
         inputObject = inputObject
     };
     if ((mshParameterList == null) || (mshParameterList.Count == 0))
     {
         entry.orderValues.Add(new ObjectCommandPropertyValue(inputObject));
         return entry;
     }
     foreach (MshParameter parameter in mshParameterList)
     {
         string propertyNotFoundMsg = null;
         EvaluateSortingExpression(parameter, inputObject, entry.orderValues, errors, out propertyNotFoundMsg);
         if (!string.IsNullOrEmpty(propertyNotFoundMsg))
         {
             propertyNotFoundMsgs.Add(propertyNotFoundMsg);
         }
     }
     return entry;
 }
示例#23
0
        private void Emit(OrderByPropertyEntry entry, string sideIndicator)
        {
            PSObject obj2;

            if (this.PassThru != 0)
            {
                obj2 = PSObject.AsPSObject(entry.inputObject);
            }
            else
            {
                obj2 = new PSObject();
                if ((this.Property == null) || (this.Property.Length == 0))
                {
                    PSNoteProperty property = new PSNoteProperty("InputObject", entry.inputObject);
                    obj2.Properties.Add(property);
                }
                else
                {
                    List <MshParameter> mshParameterList = this.orderByProperty.MshParameterList;
                    for (int i = 0; i < this.Property.Length; i++)
                    {
                        MshParameter   parameter = mshParameterList[i];
                        object         obj3      = parameter.hash["expression"];
                        PSNoteProperty property2 = new PSNoteProperty(obj3.ToString(), entry.orderValues[i].PropertyValue);
                        try
                        {
                            obj2.Properties.Add(property2);
                        }
                        catch (ExtendedTypeSystemException)
                        {
                        }
                    }
                }
            }
            obj2.Properties.Remove("SideIndicator");
            PSNoteProperty member = new PSNoteProperty("SideIndicator", sideIndicator);

            obj2.Properties.Add(member);
            base.WriteObject(obj2);
        }
        internal static OrderByPropertyEntry ProcessObject(PSObject inputObject, List <MshParameter> mshParameterList, List <ErrorRecord> errors, List <string> propertyNotFoundMsgs)
        {
            OrderByPropertyEntry entry = new OrderByPropertyEntry {
                inputObject = inputObject
            };

            if ((mshParameterList == null) || (mshParameterList.Count == 0))
            {
                entry.orderValues.Add(new ObjectCommandPropertyValue(inputObject));
                return(entry);
            }
            foreach (MshParameter parameter in mshParameterList)
            {
                string propertyNotFoundMsg = null;
                EvaluateSortingExpression(parameter, inputObject, entry.orderValues, errors, out propertyNotFoundMsg);
                if (!string.IsNullOrEmpty(propertyNotFoundMsg))
                {
                    propertyNotFoundMsgs.Add(propertyNotFoundMsg);
                }
            }
            return(entry);
        }
示例#25
0
 private void Emit(OrderByPropertyEntry entry, string sideIndicator)
 {
     PSObject obj2;
     if (this.PassThru != 0)
     {
         obj2 = PSObject.AsPSObject(entry.inputObject);
     }
     else
     {
         obj2 = new PSObject();
         if ((this.Property == null) || (this.Property.Length == 0))
         {
             PSNoteProperty property = new PSNoteProperty("InputObject", entry.inputObject);
             obj2.Properties.Add(property);
         }
         else
         {
             List<MshParameter> mshParameterList = this.orderByProperty.MshParameterList;
             for (int i = 0; i < this.Property.Length; i++)
             {
                 MshParameter parameter = mshParameterList[i];
                 object obj3 = parameter.hash["expression"];
                 PSNoteProperty property2 = new PSNoteProperty(obj3.ToString(), entry.orderValues[i].PropertyValue);
                 try
                 {
                     obj2.Properties.Add(property2);
                 }
                 catch (ExtendedTypeSystemException)
                 {
                 }
             }
         }
     }
     obj2.Properties.Remove("SideIndicator");
     PSNoteProperty member = new PSNoteProperty("SideIndicator", sideIndicator);
     obj2.Properties.Add(member);
     base.WriteObject(obj2);
 }
示例#26
0
        internal static List <OrderByPropertyEntry> CreateOrderMatrix(PSCmdlet cmdlet, List <PSObject> inputObjects, List <MshParameter> mshParameterList)
        {
            List <OrderByPropertyEntry> list = new List <OrderByPropertyEntry>();

            foreach (PSObject obj2 in inputObjects)
            {
                if ((obj2 != null) && (obj2 != AutomationNull.Value))
                {
                    List <ErrorRecord>   errors = new List <ErrorRecord>();
                    List <string>        propertyNotFoundMsgs = new List <string>();
                    OrderByPropertyEntry item = OrderByPropertyEntryEvaluationHelper.ProcessObject(obj2, mshParameterList, errors, propertyNotFoundMsgs);
                    foreach (ErrorRecord record in errors)
                    {
                        cmdlet.WriteError(record);
                    }
                    foreach (string str in propertyNotFoundMsgs)
                    {
                        cmdlet.WriteDebug(str);
                    }
                    list.Add(item);
                }
            }
            return(list);
        }
示例#27
0
 internal GroupInfo(OrderByPropertyEntry groupValue)
 {
     this.Add(groupValue.inputObject);
     this.groupValue = groupValue;
     this.name       = BuildName(groupValue.orderValues);
 }
示例#28
0
 private void EmitReferenceOnly(OrderByPropertyEntry entry)
 {
     if (!ExcludeDifferent)
         Emit(entry, SideIndicatorReference);
 }
示例#29
0
 private static int FindInObjectGroups(List<GroupInfo> groups, OrderByPropertyEntry target, OrderByPropertyComparer comparer)
 {
     for (int i = 0; i < groups.Count; i++)
     {
         if (comparer.Compare(groups[i].GroupValue, target) == 0)
         {
             return i;
         }
     }
     return -1;
 }
示例#30
0
 internal GroupInfoNoElement(OrderByPropertyEntry groupValue)
     : base(groupValue)
 {
 }
示例#31
0
 private OrderByPropertyEntry MatchAndRemove(
     OrderByPropertyEntry match,
     List<OrderByPropertyEntry> list)
 {
     if (null == match || null == list)
         return null;
     Diagnostics.Assert(null != _comparer, "null comparer");
     for (int i = 0; i < list.Count; i++)
     {
         OrderByPropertyEntry listEntry = list[i];
         Diagnostics.Assert(null != listEntry, "null listEntry " + i);
         if (0 == _comparer.Compare(match, listEntry))
         {
             list.RemoveAt(i);
             return listEntry;
         }
     }
     return null;
 }
示例#32
0
        /// <summary>
        /// The following is the matching algorithm:
        /// Retrieve the incoming object (differenceEntry) if any
        /// Retrieve the next reference object (referenceEntry) if any
        /// If differenceEntry matches referenceEntry
        ///   Emit referenceEntry as a match
        ///   Return
        /// If differenceEntry matches any entry in referenceEntryBacklog
        ///   Emit the backlog entry as a match
        ///   Remove the backlog entry from referenceEntryBacklog
        ///   Clear differenceEntry
        /// If referenceEntry (if any) matches any entry in differenceEntryBacklog
        ///   Emit referenceEntry as a match
        ///   Remove the backlog entry from differenceEntryBacklog
        ///   Clear referenceEntry
        /// If differenceEntry is still present
        ///   If SyncWindow is 0
        ///     Emit differenceEntry as unmatched
        ///   Else
        ///     While there is no space in differenceEntryBacklog
        ///       Emit oldest entry in differenceEntryBacklog as unmatched
        ///       Remove oldest entry from differenceEntryBacklog
        ///     Add differenceEntry to differenceEntryBacklog
        /// If referenceEntry is still present
        ///   If SyncWindow is 0
        ///     Emit referenceEntry as unmatched
        ///   Else
        ///     While there is no space in referenceEntryBacklog
        ///       Emit oldest entry in referenceEntryBacklog as unmatched
        ///       Remove oldest entry from referenceEntryBacklog
        ///     Add referenceEntry to referenceEntryBacklog
        /// </summary>
        /// <param name="differenceEntry"></param>
        private void Process(OrderByPropertyEntry differenceEntry)
        {
            Diagnostics.Assert(null != _referenceEntries, "null referenceEntries");

            // Retrieve the next reference object (referenceEntry) if any
            OrderByPropertyEntry referenceEntry = null;
            if (_referenceObjectIndex < _referenceEntries.Count)
            {
                referenceEntry = _referenceEntries[_referenceObjectIndex++];
            }

            // If differenceEntry matches referenceEntry
            //   Emit referenceEntry as a match
            //   Return
            // 2005/07/19 Switched order of referenceEntry and differenceEntry
            //   so that we cast differenceEntry to the type of referenceEntry.
            if (null != referenceEntry && null != differenceEntry &&
                0 == _comparer.Compare(referenceEntry, differenceEntry))
            {
                EmitMatch(referenceEntry);
                return;
            }

            // If differenceEntry matches any entry in referenceEntryBacklog
            //   Emit the backlog entry as a match
            //   Remove the backlog entry from referenceEntryBacklog
            //   Clear differenceEntry
            OrderByPropertyEntry matchingEntry =
                MatchAndRemove(differenceEntry, _referenceEntryBacklog);
            if (null != matchingEntry)
            {
                EmitMatch(matchingEntry);
                differenceEntry = null;
            }

            // If referenceEntry (if any) matches any entry in differenceEntryBacklog
            //   Emit referenceEntry as a match
            //   Remove the backlog entry from differenceEntryBacklog
            //   Clear referenceEntry
            matchingEntry =
                MatchAndRemove(referenceEntry, _differenceEntryBacklog);
            if (null != matchingEntry)
            {
                EmitMatch(referenceEntry);
                referenceEntry = null;
            }

            // If differenceEntry is still present
            //   If SyncWindow is 0
            //     Emit differenceEntry as unmatched
            //   Else
            //     While there is no space in differenceEntryBacklog
            //       Emit oldest entry in differenceEntryBacklog as unmatched
            //       Remove oldest entry from differenceEntryBacklog
            //     Add differenceEntry to differenceEntryBacklog
            if (null != differenceEntry)
            {
                if (0 < SyncWindow)
                {
                    while (_differenceEntryBacklog.Count >= SyncWindow)
                    {
                        EmitDifferenceOnly(_differenceEntryBacklog[0]);
                        _differenceEntryBacklog.RemoveAt(0);
                    }
                    _differenceEntryBacklog.Add(differenceEntry);
                }
                else
                {
                    EmitDifferenceOnly(differenceEntry);
                }
            }

            // If referenceEntry is still present
            //   If SyncWindow is 0
            //     Emit referenceEntry as unmatched
            //   Else
            //     While there is no space in referenceEntryBacklog
            //       Emit oldest entry in referenceEntryBacklog as unmatched
            //       Remove oldest entry from referenceEntryBacklog
            //     Add referenceEntry to referenceEntryBacklog
            if (null != referenceEntry)
            {
                if (0 < SyncWindow)
                {
                    while (_referenceEntryBacklog.Count >= SyncWindow)
                    {
                        EmitReferenceOnly(_referenceEntryBacklog[0]);
                        _referenceEntryBacklog.RemoveAt(0);
                    }
                    _referenceEntryBacklog.Add(referenceEntry);
                }
                else
                {
                    EmitReferenceOnly(referenceEntry);
                }
            }
        }
示例#33
0
 private void Process(OrderByPropertyEntry differenceEntry)
 {
     OrderByPropertyEntry firstEntry = null;
     if (this.referenceObjectIndex < this.referenceEntries.Count)
     {
         firstEntry = this.referenceEntries[this.referenceObjectIndex++];
     }
     if (((firstEntry != null) && (differenceEntry != null)) && (this.comparer.Compare(firstEntry, differenceEntry) == 0))
     {
         this.EmitMatch(firstEntry);
     }
     else
     {
         OrderByPropertyEntry entry = this.MatchAndRemove(differenceEntry, this.referenceEntryBacklog);
         if (entry != null)
         {
             this.EmitMatch(entry);
             differenceEntry = null;
         }
         if (this.MatchAndRemove(firstEntry, this.differenceEntryBacklog) != null)
         {
             this.EmitMatch(firstEntry);
             firstEntry = null;
         }
         if (differenceEntry != null)
         {
             if (0 < this.SyncWindow)
             {
                 while (this.differenceEntryBacklog.Count >= this.SyncWindow)
                 {
                     this.EmitDifferenceOnly(this.differenceEntryBacklog[0]);
                     this.differenceEntryBacklog.RemoveAt(0);
                 }
                 this.differenceEntryBacklog.Add(differenceEntry);
             }
             else
             {
                 this.EmitDifferenceOnly(differenceEntry);
             }
         }
         if (firstEntry != null)
         {
             if (0 < this.SyncWindow)
             {
                 while (this.referenceEntryBacklog.Count >= this.SyncWindow)
                 {
                     this.EmitReferenceOnly(this.referenceEntryBacklog[0]);
                     this.referenceEntryBacklog.RemoveAt(0);
                 }
                 this.referenceEntryBacklog.Add(firstEntry);
             }
             else
             {
                 this.EmitReferenceOnly(firstEntry);
             }
         }
     }
 }
示例#34
0
 private void EmitMatch(OrderByPropertyEntry entry)
 {
     if (_includeEqual)
         Emit(entry, SideIndicatorMatch);
 }
示例#35
0
 internal GroupInfo(OrderByPropertyEntry groupValue)
 {
     this.Add(groupValue.inputObject);
     this.groupValue = groupValue;
     this.name = BuildName(groupValue.orderValues);
 }
示例#36
0
        /// <summary>
        /// Utility function called by Group-Object to create Groups.
        /// </summary>
        /// <param name="currentObjectEntry">Input object that needs to be grouped.</param>
        /// <param name="noElement">true if we are not accumulating objects</param>
        /// <param name="groups">List containing Groups.</param>
        /// <param name="groupInfoDictionary">Dictionary used to keep track of the groups with hash of the property values being the key.</param>
        /// <param name="orderByPropertyComparer">The Comparer to be used while comparing to check if new group has to be created.</param>
        internal static void DoGrouping(OrderByPropertyEntry currentObjectEntry, bool noElement, List<GroupInfo> groups, Dictionary<object, GroupInfo> groupInfoDictionary,
            OrderByPropertyComparer orderByPropertyComparer)
        {
            if (currentObjectEntry != null && currentObjectEntry.orderValues != null && currentObjectEntry.orderValues.Count > 0)
            {
                object currentTupleObject = PSTuple.ArrayToTuple(currentObjectEntry.orderValues.ToArray());

                GroupInfo currentGroupInfo = null;
                if (groupInfoDictionary.TryGetValue(currentTupleObject, out currentGroupInfo))
                {
                    if (currentGroupInfo != null)
                    {
                        //add this inputObject to an existing group
                        currentGroupInfo.Add(currentObjectEntry.inputObject);
                    }
                }
                else
                {
                    bool isCurrentItemGrouped = false;

                    for (int groupsIndex = 0; groupsIndex < groups.Count; groupsIndex++)
                    {
                        // Check if the current input object can be converted to one of the already known types 
                        // by looking up in the type to GroupInfo mapping.
                        if (orderByPropertyComparer.Compare(groups[groupsIndex].GroupValue, currentObjectEntry) == 0)
                        {
                            groups[groupsIndex].Add(currentObjectEntry.inputObject);
                            isCurrentItemGrouped = true;
                            break;
                        }
                    }

                    if (!isCurrentItemGrouped)
                    {
                        // create a new group
                        s_tracer.WriteLine("Create a new group: {0}", currentObjectEntry.orderValues);
                        GroupInfo newObjGrp = noElement ? new GroupInfoNoElement(currentObjectEntry) : new GroupInfo(currentObjectEntry);
                        groups.Add(newObjGrp);

                        groupInfoDictionary.Add(currentTupleObject, newObjGrp);
                    }
                }
            }
        }
示例#37
0
        /// <summary>
        /// The following is the matching algorithm:
        /// Retrieve the incoming object (differenceEntry) if any
        /// Retrieve the next reference object (referenceEntry) if any
        /// If differenceEntry matches referenceEntry
        ///   Emit referenceEntry as a match
        ///   Return
        /// If differenceEntry matches any entry in referenceEntryBacklog
        ///   Emit the backlog entry as a match
        ///   Remove the backlog entry from referenceEntryBacklog
        ///   Clear differenceEntry
        /// If referenceEntry (if any) matches any entry in differenceEntryBacklog
        ///   Emit referenceEntry as a match
        ///   Remove the backlog entry from differenceEntryBacklog
        ///   Clear referenceEntry
        /// If differenceEntry is still present
        ///   If SyncWindow is 0
        ///     Emit differenceEntry as unmatched
        ///   Else
        ///     While there is no space in differenceEntryBacklog
        ///       Emit oldest entry in differenceEntryBacklog as unmatched
        ///       Remove oldest entry from differenceEntryBacklog
        ///     Add differenceEntry to differenceEntryBacklog
        /// If referenceEntry is still present
        ///   If SyncWindow is 0
        ///     Emit referenceEntry as unmatched
        ///   Else
        ///     While there is no space in referenceEntryBacklog
        ///       Emit oldest entry in referenceEntryBacklog as unmatched
        ///       Remove oldest entry from referenceEntryBacklog
        ///     Add referenceEntry to referenceEntryBacklog.
        /// </summary>
        /// <param name="differenceEntry"></param>
        private void Process(OrderByPropertyEntry differenceEntry)
        {
            Diagnostics.Assert(_referenceEntries != null, "null referenceEntries");

            // Retrieve the next reference object (referenceEntry) if any
            OrderByPropertyEntry referenceEntry = null;

            if (_referenceObjectIndex < _referenceEntries.Count)
            {
                referenceEntry = _referenceEntries[_referenceObjectIndex++];
            }

            // If differenceEntry matches referenceEntry
            //   Emit referenceEntry as a match
            //   Return
            // 2005/07/19 Switched order of referenceEntry and differenceEntry
            //   so that we cast differenceEntry to the type of referenceEntry.
            if (referenceEntry != null && differenceEntry != null &&
                0 == _comparer.Compare(referenceEntry, differenceEntry))
            {
                EmitMatch(referenceEntry);
                return;
            }

            // If differenceEntry matches any entry in referenceEntryBacklog
            //   Emit the backlog entry as a match
            //   Remove the backlog entry from referenceEntryBacklog
            //   Clear differenceEntry
            OrderByPropertyEntry matchingEntry =
                MatchAndRemove(differenceEntry, _referenceEntryBacklog);

            if (matchingEntry != null)
            {
                EmitMatch(matchingEntry);
                differenceEntry = null;
            }

            // If referenceEntry (if any) matches any entry in differenceEntryBacklog
            //   Emit referenceEntry as a match
            //   Remove the backlog entry from differenceEntryBacklog
            //   Clear referenceEntry
            matchingEntry =
                MatchAndRemove(referenceEntry, _differenceEntryBacklog);
            if (matchingEntry != null)
            {
                EmitMatch(referenceEntry);
                referenceEntry = null;
            }

            // If differenceEntry is still present
            //   If SyncWindow is 0
            //     Emit differenceEntry as unmatched
            //   Else
            //     While there is no space in differenceEntryBacklog
            //       Emit oldest entry in differenceEntryBacklog as unmatched
            //       Remove oldest entry from differenceEntryBacklog
            //     Add differenceEntry to differenceEntryBacklog
            if (differenceEntry != null)
            {
                if (0 < SyncWindow)
                {
                    while (_differenceEntryBacklog.Count >= SyncWindow)
                    {
                        EmitDifferenceOnly(_differenceEntryBacklog[0]);
                        _differenceEntryBacklog.RemoveAt(0);
                    }

                    _differenceEntryBacklog.Add(differenceEntry);
                }
                else
                {
                    EmitDifferenceOnly(differenceEntry);
                }
            }

            // If referenceEntry is still present
            //   If SyncWindow is 0
            //     Emit referenceEntry as unmatched
            //   Else
            //     While there is no space in referenceEntryBacklog
            //       Emit oldest entry in referenceEntryBacklog as unmatched
            //       Remove oldest entry from referenceEntryBacklog
            //     Add referenceEntry to referenceEntryBacklog
            if (referenceEntry != null)
            {
                if (0 < SyncWindow)
                {
                    while (_referenceEntryBacklog.Count >= SyncWindow)
                    {
                        EmitReferenceOnly(_referenceEntryBacklog[0]);
                        _referenceEntryBacklog.RemoveAt(0);
                    }

                    _referenceEntryBacklog.Add(referenceEntry);
                }
                else
                {
                    EmitReferenceOnly(referenceEntry);
                }
            }
        }
示例#38
0
 internal GroupInfo(OrderByPropertyEntry groupValue)
 {
     Group = new Collection<PSObject>();
     this.Add(groupValue.inputObject);
     GroupValue = groupValue;
     Name = BuildName(groupValue.orderValues);
 }
示例#39
0
 internal GroupInfoNoElement(OrderByPropertyEntry groupValue)
     : base(groupValue)
 {
 }
示例#40
0
        private void Emit(OrderByPropertyEntry entry, string sideIndicator)
        {
            Diagnostics.Assert(null != entry, "null entry");

            PSObject mshobj;
            if (PassThru)
            {
                mshobj = PSObject.AsPSObject(entry.inputObject);
            }
            else
            {
                mshobj = new PSObject();
                if (null == Property || 0 == Property.Length)
                {
                    PSNoteProperty inputNote = new PSNoteProperty(
                        InputObjectPropertyName, entry.inputObject);
                    mshobj.Properties.Add(inputNote);
                }
                else
                {
                    List<MshParameter> mshParameterList = _orderByProperty.MshParameterList;
                    Diagnostics.Assert(null != mshParameterList, "null mshParameterList");
                    Diagnostics.Assert(mshParameterList.Count == Property.Length, "mshParameterList.Count " + mshParameterList.Count);

                    for (int i = 0; i < Property.Length; i++)
                    {
                        // 2005/07/05 This is the closest we can come to
                        // the string typed by the user
                        MshParameter mshParameter = mshParameterList[i];
                        Diagnostics.Assert(null != mshParameter, "null mshParameter");
                        Hashtable hash = mshParameter.hash;
                        Diagnostics.Assert(null != hash, "null hash");
                        object prop = hash[FormatParameterDefinitionKeys.ExpressionEntryKey];
                        Diagnostics.Assert(null != prop, "null prop");
                        string propName = prop.ToString();
                        PSNoteProperty propertyNote = new PSNoteProperty(
                            propName,
                            entry.orderValues[i].PropertyValue);
                        try
                        {
                            mshobj.Properties.Add(propertyNote);
                        }
                        catch (ExtendedTypeSystemException)
                        {
                            // this is probably a duplicate add
                        }
                    }
                }
            }
            mshobj.Properties.Remove(SideIndicatorPropertyName);
            PSNoteProperty sideNote = new PSNoteProperty(
                SideIndicatorPropertyName, sideIndicator);
            mshobj.Properties.Add(sideNote);
            WriteObject(mshobj);
        }
示例#41
0
 private OrderByPropertyEntry MatchAndRemove(OrderByPropertyEntry match, List<OrderByPropertyEntry> list)
 {
     if ((match != null) && (list != null))
     {
         for (int i = 0; i < list.Count; i++)
         {
             OrderByPropertyEntry secondEntry = list[i];
             if (this.comparer.Compare(match, secondEntry) == 0)
             {
                 list.RemoveAt(i);
                 return secondEntry;
             }
         }
     }
     return null;
 }