private static void AddCategory(ICustomDestinationList cdl, string category, List <JumpList._ShellObjectPair> jumpItems, List <JumpItem> successList, List <JumpList._RejectedJumpItemPair> rejectionList)
 {
     JumpList.AddCategory(cdl, category, jumpItems, successList, rejectionList, true);
 }
        private static void AddCategory(ICustomDestinationList cdl, string category, List <JumpList._ShellObjectPair> jumpItems, List <JumpItem> successList, List <JumpList._RejectedJumpItemPair> rejectionList, bool isHeterogenous)
        {
            IObjectCollection objectCollection = (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("2d3468c1-36a7-43b6-ac24-d3f02fd9607a")));

            foreach (JumpList._ShellObjectPair shellObjectPair in jumpItems)
            {
                objectCollection.AddObject(shellObjectPair.ShellObject);
            }
            HRESULT hrLeft;

            if (string.IsNullOrEmpty(category))
            {
                hrLeft = cdl.AddUserTasks(objectCollection);
            }
            else
            {
                hrLeft = cdl.AppendCategory(category, objectCollection);
            }
            if (hrLeft.Succeeded)
            {
                int num = jumpItems.Count;
                while (--num >= 0)
                {
                    successList.Add(jumpItems[num].JumpItem);
                }
                return;
            }
            if (isHeterogenous && hrLeft == HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER)
            {
                if (TraceShell.IsEnabled)
                {
                    TraceShell.Trace(TraceEventType.Error, TraceShell.RejectingJumpListCategoryBecauseNoRegisteredHandler(new object[]
                    {
                        category
                    }));
                }
                Utilities.SafeRelease <IObjectCollection>(ref objectCollection);
                List <JumpList._ShellObjectPair> list = new List <JumpList._ShellObjectPair>();
                foreach (JumpList._ShellObjectPair shellObjectPair2 in jumpItems)
                {
                    if (shellObjectPair2.JumpItem is JumpPath)
                    {
                        rejectionList.Add(new JumpList._RejectedJumpItemPair
                        {
                            JumpItem = shellObjectPair2.JumpItem,
                            Reason   = JumpItemRejectionReason.NoRegisteredHandler
                        });
                    }
                    else
                    {
                        list.Add(shellObjectPair2);
                    }
                }
                if (list.Count > 0)
                {
                    JumpList.AddCategory(cdl, category, list, successList, rejectionList, false);
                    return;
                }
            }
            else
            {
                foreach (JumpList._ShellObjectPair shellObjectPair3 in jumpItems)
                {
                    rejectionList.Add(new JumpList._RejectedJumpItemPair
                    {
                        JumpItem = shellObjectPair3.JumpItem,
                        Reason   = JumpItemRejectionReason.InvalidItem
                    });
                }
            }
        }
        private void ApplyList()
        {
            Verify.IsApartmentState(ApartmentState.STA);
            if (!Utilities.IsOSWindows7OrNewer)
            {
                this.RejectEverything();
                return;
            }
            List <List <JumpList._ShellObjectPair> > list  = null;
            List <JumpList._ShellObjectPair>         list2 = null;
            ICustomDestinationList customDestinationList   = (ICustomDestinationList)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("77f10cf0-3db5-4966-b520-b7c54fd35ed6")));
            List <JumpItem>        list3;
            List <JumpList._RejectedJumpItemPair> list4;

            try
            {
                string runtimeId = JumpList._RuntimeId;
                if (!string.IsNullOrEmpty(runtimeId))
                {
                    customDestinationList.SetAppID(runtimeId);
                }
                Guid         guid = new Guid("92CA9DCD-5622-4bba-A805-5E9F541BD8C9");
                uint         num;
                IObjectArray shellObjects = (IObjectArray)customDestinationList.BeginList(out num, ref guid);
                list2 = JumpList.GenerateJumpItems(shellObjects);
                list3 = new List <JumpItem>(this.JumpItems.Count);
                list4 = new List <JumpList._RejectedJumpItemPair>(this.JumpItems.Count);
                list  = new List <List <JumpList._ShellObjectPair> >
                {
                    new List <JumpList._ShellObjectPair>()
                };
                foreach (JumpItem jumpItem in this.JumpItems)
                {
                    if (jumpItem == null)
                    {
                        list4.Add(new JumpList._RejectedJumpItemPair
                        {
                            JumpItem = jumpItem,
                            Reason   = JumpItemRejectionReason.InvalidItem
                        });
                    }
                    else
                    {
                        object obj = null;
                        try
                        {
                            obj = JumpList.GetShellObjectForJumpItem(jumpItem);
                            if (obj == null)
                            {
                                list4.Add(new JumpList._RejectedJumpItemPair
                                {
                                    Reason   = JumpItemRejectionReason.InvalidItem,
                                    JumpItem = jumpItem
                                });
                            }
                            else if (JumpList.ListContainsShellObject(list2, obj))
                            {
                                list4.Add(new JumpList._RejectedJumpItemPair
                                {
                                    Reason   = JumpItemRejectionReason.RemovedByUser,
                                    JumpItem = jumpItem
                                });
                            }
                            else
                            {
                                JumpList._ShellObjectPair item = new JumpList._ShellObjectPair
                                {
                                    JumpItem    = jumpItem,
                                    ShellObject = obj
                                };
                                if (string.IsNullOrEmpty(jumpItem.CustomCategory))
                                {
                                    list[0].Add(item);
                                }
                                else
                                {
                                    bool flag = false;
                                    foreach (List <JumpList._ShellObjectPair> list5 in list)
                                    {
                                        if (list5.Count > 0 && list5[0].JumpItem.CustomCategory == jumpItem.CustomCategory)
                                        {
                                            list5.Add(item);
                                            flag = true;
                                            break;
                                        }
                                    }
                                    if (!flag)
                                    {
                                        list.Add(new List <JumpList._ShellObjectPair>
                                        {
                                            item
                                        });
                                    }
                                }
                                obj = null;
                            }
                        }
                        finally
                        {
                            Utilities.SafeRelease <object>(ref obj);
                        }
                    }
                }
                list.Reverse();
                if (this.ShowFrequentCategory)
                {
                    customDestinationList.AppendKnownCategory(KDC.FREQUENT);
                }
                if (this.ShowRecentCategory)
                {
                    customDestinationList.AppendKnownCategory(KDC.RECENT);
                }
                foreach (List <JumpList._ShellObjectPair> list6 in list)
                {
                    if (list6.Count > 0)
                    {
                        string customCategory = list6[0].JumpItem.CustomCategory;
                        JumpList.AddCategory(customDestinationList, customCategory, list6, list3, list4);
                    }
                }
                customDestinationList.CommitList();
            }
            catch
            {
                if (TraceShell.IsEnabled)
                {
                    TraceShell.Trace(TraceEventType.Error, TraceShell.RejectingJumpItemsBecauseCatastrophicFailure);
                }
                this.RejectEverything();
                return;
            }
            finally
            {
                Utilities.SafeRelease <ICustomDestinationList>(ref customDestinationList);
                if (list != null)
                {
                    foreach (List <JumpList._ShellObjectPair> list7 in list)
                    {
                        JumpList._ShellObjectPair.ReleaseShellObjects(list7);
                    }
                }
                JumpList._ShellObjectPair.ReleaseShellObjects(list2);
            }
            list3.Reverse();
            this._jumpItems = list3;
            EventHandler <JumpItemsRejectedEventArgs> jumpItemsRejected      = this.JumpItemsRejected;
            EventHandler <JumpItemsRemovedEventArgs>  jumpItemsRemovedByUser = this.JumpItemsRemovedByUser;

            if (list4.Count > 0 && jumpItemsRejected != null)
            {
                List <JumpItem> list8 = new List <JumpItem>(list4.Count);
                List <JumpItemRejectionReason> list9 = new List <JumpItemRejectionReason>(list4.Count);
                foreach (JumpList._RejectedJumpItemPair rejectedJumpItemPair in list4)
                {
                    list8.Add(rejectedJumpItemPair.JumpItem);
                    list9.Add(rejectedJumpItemPair.Reason);
                }
                jumpItemsRejected(this, new JumpItemsRejectedEventArgs(list8, list9));
            }
            if (list2.Count > 0 && jumpItemsRemovedByUser != null)
            {
                List <JumpItem> list10 = new List <JumpItem>(list2.Count);
                foreach (JumpList._ShellObjectPair shellObjectPair in list2)
                {
                    if (shellObjectPair.JumpItem != null)
                    {
                        list10.Add(shellObjectPair.JumpItem);
                    }
                }
                if (list10.Count > 0)
                {
                    jumpItemsRemovedByUser(this, new JumpItemsRemovedEventArgs(list10));
                }
            }
        }