/// <summary> /// Commits the changes to the <see cref="PluginOrderLog"/>. /// </summary> public void Commit() { PluginComparer pcpComparer = PluginComparer.Filename; Dictionary <Plugin, Plugin> dicPredecessors = new Dictionary <Plugin, Plugin>(); ThreadSafeObservableList <Plugin> oclUnorderedList = EnlistedPluginOrderLog.m_oclOrderedPlugins; // Removed faulty lock, it should no longer be necessary anyway //lock (EnlistedPluginOrderLog.m_oclOrderedPlugins) //{ EnlistedPluginOrderLog.m_oclOrderedPlugins.CollectionChanged -= MasterOrderedPlugins_CollectionChanged; IList <Plugin> lstOrderedList = m_oclOrderedPlugins; //sort the items whose order has been specified for (Int32 i = 0; i < lstOrderedList.Count; i++) { Int32 intOldIndex = 0; for (intOldIndex = 0; intOldIndex < oclUnorderedList.Count; intOldIndex++) { if (pcpComparer.Equals(oclUnorderedList[intOldIndex], lstOrderedList[i])) { break; } } if (intOldIndex == oclUnorderedList.Count) { oclUnorderedList.Insert(i, lstOrderedList[i]); continue; } if (intOldIndex != i) { oclUnorderedList.Move(intOldIndex, i); } } //as the transacted order list has been kept in sync with the master list // the transacted list is canonical (it contains all of the plugins, // and no plugins that shouldn't be present), so // if a plugin is not in the transacted list it means the plugin was removed, // and should be removed form the master list for (Int32 i = oclUnorderedList.Count - 1; i >= lstOrderedList.Count; i--) { oclUnorderedList.RemoveAt(i); } EnlistedPluginOrderLog.OrderValidator.CorrectOrder(oclUnorderedList); //} EnlistedPluginOrderLog.SavePluginLog(); m_booEnlisted = false; m_oclOrderedPlugins.Clear(); }
/// <summary> /// Sets the order of the plugins to the given order. /// </summary> /// <remarks> /// If the given list does not include all registered plugins, then the plugins are ordered in a manner /// so as to not displace the positions of the plugins whose order was not specified. /// </remarks> /// <param name="p_lstOrderedPlugins">The list indicating the desired order of the plugins.</param> public void SetPluginOrder(IList <Plugin> p_lstOrderedPlugins) { PluginComparer pcpComparer = PluginComparer.Filename; Dictionary <Plugin, Plugin> dicPredecessors = new Dictionary <Plugin, Plugin>(); ThreadSafeObservableList <Plugin> oclUnorderedList = m_oclOrderedPlugins; IList <Plugin> lstOrderedList = p_lstOrderedPlugins; string strError = String.Empty; try { strError = "Setup"; for (Int32 i = 0; i < oclUnorderedList.Count; i++) { if (!lstOrderedList.Contains(oclUnorderedList[i], pcpComparer)) { dicPredecessors[oclUnorderedList[i]] = (i > 0) ? oclUnorderedList[i - 1] : null; } } strError = "Specified"; //sort the items whose order has been specified for (Int32 i = 0; i < lstOrderedList.Count; i++) { strError = "intOldIndex"; Int32 intOldIndex = 0; for (intOldIndex = 0; intOldIndex < oclUnorderedList.Count; intOldIndex++) { if (pcpComparer.Equals(oclUnorderedList[intOldIndex], lstOrderedList[i])) { break; } } if (intOldIndex >= oclUnorderedList.Count) { strError = "Insert"; oclUnorderedList.Insert(i, lstOrderedList[i]); continue; } if (intOldIndex != i) { strError = "Move intOldIndex"; oclUnorderedList.Move(intOldIndex, i); } } strError = "Predecessor"; //sort the items whose order has not been specified // if an item's order hasn't been specified, it is placed after the // item it followed in the original, unordered, list for (Int32 i = lstOrderedList.Count; i < oclUnorderedList.Count; i++) { Plugin plgPredecessor = null; Int32 intNewIndex = -1; if (dicPredecessors.ContainsKey(oclUnorderedList[i])) { plgPredecessor = dicPredecessors[oclUnorderedList[i]]; } //if the predecessor is null, then the item was at the beginning of the list if (plgPredecessor != null) { for (intNewIndex = 0; intNewIndex < oclUnorderedList.Count; intNewIndex++) { if (pcpComparer.Equals(oclUnorderedList[intNewIndex], plgPredecessor)) { break; } } } strError = "intNewIndex + 1"; if (intNewIndex + 1 != i) { oclUnorderedList.Move(i, intNewIndex + 1); } } EnlistedPluginOrderLog.OrderValidator.CorrectOrder(oclUnorderedList); if (CurrentTransaction == null) { Commit(); } else { Enlist(); } } catch (Exception e) { throw new Exception(strError, e); } }