private static void AddCategory(ICustomDestinationList cdl, string category, List <_ShellObjectPair> jumpItems, List <JumpItem> successList, List <_RejectedJumpItemPair> rejectionList, bool isHeterogenous) { Debug.Assert(jumpItems.Count != 0); Debug.Assert(cdl != null); HRESULT hr; var shellObjectCollection = (IObjectCollection)Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid(CLSID.EnumerableObjectCollection))); foreach (var itemMap in jumpItems) { shellObjectCollection.AddObject(itemMap.ShellObject); } if (string.IsNullOrEmpty(category)) { hr = cdl.AddUserTasks((IObjectArray)shellObjectCollection); } else { hr = cdl.AppendCategory(category, (IObjectArray)shellObjectCollection); } if (hr.Succeeded) { // Woot! Add these items to the list. // Do it in reverse order so Apply has the items in the correct order. for (int i = jumpItems.Count; --i >= 0;) { successList.Add(jumpItems[i].JumpItem); } } else { // If the list contained items that could not be added because this object isn't a handler // then drop all ShellItems and retry without them. if (isHeterogenous && hr == HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER) { if (TraceShell.IsEnabled) { TraceShell.Trace(TraceEventType.Error, TraceShell.RejectingJumpListCategoryBecauseNoRegisteredHandler(category)); } Utilities.SafeRelease(ref shellObjectCollection); var linksOnlyList = new List <_ShellObjectPair>(); foreach (var itemMap in jumpItems) { if (itemMap.JumpItem is JumpPath) { rejectionList.Add(new _RejectedJumpItemPair { JumpItem = itemMap.JumpItem, Reason = JumpItemRejectionReason.NoRegisteredHandler }); } else { linksOnlyList.Add(itemMap); } } if (linksOnlyList.Count > 0) { // There's not a reason I know of that we should reject a list of only links... Debug.Assert(jumpItems.Count != linksOnlyList.Count); AddCategory(cdl, category, linksOnlyList, successList, rejectionList, false); } } else { Debug.Assert(HRESULT.DESTS_E_NO_MATCHING_ASSOC_HANDLER != hr); // If we failed for some other reason, just reject everything. foreach (var item in jumpItems) { rejectionList.Add(new _RejectedJumpItemPair { JumpItem = item.JumpItem, Reason = JumpItemRejectionReason.InvalidItem }); } } } }
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 }); } } }