/// <summary> /// Member ClearInfoAbout /// </summary> /// <param name="rghvo">hvo</param><param name="chvo"/><param name="cia">cia</param> public void ClearInfoAboutAll(int[] rghvo, int chvo, VwClearInfoAction cia) { m_cache.ClearInfoAboutAll(rghvo, chvo, cia); }
/// <summary> /// Member ClearInfoAbout /// </summary> /// <param name="hvo">hvo</param><param name="cia">cia</param> public void ClearInfoAbout(int hvo, VwClearInfoAction cia) { m_cache.ClearInfoAbout(hvo, cia); }
/// <summary>Member ClearInfoAbout</summary> /// <param name='rghvo'>hvo</param> /// <param name="chvo"></param> /// <param name='cia'>cia</param> public void ClearInfoAboutAll(int[] rghvo, int chvo, VwClearInfoAction cia) { (m_sda as IVwCacheDa).ClearInfoAboutAll(rghvo, chvo, cia); }
/// <summary>Member ClearInfoAbout</summary> /// <param name='rghvo'>hvo</param> /// <param name="chvo"></param> /// <param name='cia'>cia</param> public void ClearInfoAboutAll(int[] rghvo, int chvo, VwClearInfoAction cia) { CheckDisposed(); throw new NotImplementedException("'ClearInfoAboutAll' not implemented yet."); }
/// <summary> /// /// </summary> /// <param name="hvo"></param> /// <param name="cia"></param> public void ClearInfoAbout(int hvo, VwClearInfoAction cia) { (m_sda as IVwCacheDa).ClearInfoAbout(hvo, cia); }
public void ClearInfoAboutAll(int[] _rghvo, int chvo, VwClearInfoAction cia) { throw new NotImplementedException(); }
/// <summary>Member ClearInfoAbout</summary> /// <param name='rghvo'>hvo</param> /// <param name="chvo"></param> /// <param name='cia'>cia</param> public void ClearInfoAboutAll(int[] rghvo, int chvo, VwClearInfoAction cia) { CheckDisposed(); // This default implementation has no MetaDataCache and so can't do anything useful. }
/// <summary> /// Delete the objects which are the ids in the Set. /// </summary> public static void DeleteObjects(Set<int> idsToDel, FdoCache cache, bool fRequiresFullRefreshOfViewInUndoRedo, VwClearInfoAction vwClearInfoAction, bool fUndo, ProgressState state) { Set<int> realIdsToDel = new Set<int>(); foreach (int hvo in idsToDel) { if (cache.IsDummyObject(hvo)) continue; // don't try removing dummy object from cache. otherwise, you can't undo it. realIdsToDel.Add(hvo); } if (realIdsToDel.Count == 0) return; if (fUndo && realIdsToDel.Count == 1 && fRequiresFullRefreshOfViewInUndoRedo || cache.DatabaseAccessor == null) { // Just one object...more efficient to to it directly, also, it lets many // tests pass that would otherwise need a real database. foreach (int hvo in realIdsToDel) { cache.DeleteObject(hvo); } } else { IActionHandler acth = cache.ActionHandlerAccessor; if (acth == null) fUndo = false; // May be null if we are currently suppressing Subtasks int iMin = 0; int[] ids = realIdsToDel.ToArray(); int step = 50; if (state != null) { // 600 4-digit ids, 500 5-digit ids, 428 6-digit ids, 375 7-digit ids int cChunks = (ids.Length / 450) + 1; step = 60 / cChunks; if (step == 0) step = 1; } while (iMin < ids.Length) { int iLim = iMin; string hvoList = CmObject.MakePartialIdList(ref iLim, ids); ObjectGroupUndoItem item; if (iMin > 0 || iLim < ids.Length) { Set<int> idsDel = new Set<int>(iLim - iMin); for (int i = iMin; i < iLim; ++i) idsDel.Add(ids[i]); item = new ObjectGroupUndoItem(idsDel, hvoList, cache, fRequiresFullRefreshOfViewInUndoRedo, fUndo); } else { item = new ObjectGroupUndoItem(realIdsToDel, hvoList, cache, fRequiresFullRefreshOfViewInUndoRedo, fUndo); } item.DoIt(vwClearInfoAction); if (fUndo) acth.AddAction(item); if (state != null) { int percent = state.PercentDone + step; state.PercentDone = percent; state.Breath(); } iMin = iLim; } } }
public void ClearInfoAbout(int hvo, VwClearInfoAction cia) { throw new NotImplementedException(); }
/// <summary> /// Delete the objects which are the ids in the Set. /// </summary> public static void DeleteObjects(Set<int> idsToDel, FdoCache cache, bool fRequiresFullRefreshOfViewInUndoRedo, VwClearInfoAction vwClearInfoAction) { DeleteObjects(idsToDel, cache, fRequiresFullRefreshOfViewInUndoRedo, vwClearInfoAction, true, null); }
/// <summary> /// Delete the objects which are the ids in the Set. /// Includes creating a suitable Undo action. /// </summary> /// <param name="idsToDel">Set of object IDs to be deleted.</param> /// <param name="cache"></param> /// <param name="vwClearInfoAction">specifies the level of information to clear from the cache for each id.</param> public static void DeleteObjects(Set<int> idsToDel, FdoCache cache, VwClearInfoAction vwClearInfoAction) { DeleteObjects(idsToDel, cache, true, vwClearInfoAction); }
/// <summary> /// This does the original delete. We do our best to fix the cache without Refresh, /// though it's possible one or more deleted objects is still displayed somewhere /// as part of a reference attribute. /// </summary> /// <param name="vwClearInfoAction">specifies the level of information that needs to be cleared from the cache for each object. </param> /// <returns></returns> public bool DoIt(VwClearInfoAction vwClearInfoAction) { Set<KeyValuePair<int, int>> modifiedOwningProps = new Set<KeyValuePair<int, int>>(); ISilDataAccess sda = m_cache.MainCacheAccessor; foreach (int hvo in m_ids) { if (m_cache.IsDummyObject(hvo)) continue; // don't clear it from the cache, or we won't be able to Undo. int hvoOwner = m_cache.GetOwnerOfObject(hvo); if (hvoOwner != 0 && !m_ids.Contains(hvoOwner)) { // It has an owner and the owner is not also being deleted. int flid = m_cache.GetOwningFlidOfObject(hvo); // If we don't get one, we can't clean up the owning property; presume it has not // been loaded into the cache and doesn't need clearing. // Since it is a set, it won't matter if the same pair is added repeatedly. if (flid != 0) modifiedOwningProps.Add(new KeyValuePair<int, int>(hvoOwner, flid)); } } // Forget anything we ever knew about the deleted objects and things they owned. m_cache.VwCacheDaAccessor.ClearInfoAboutAll(m_ids.ToArray(), m_ids.Count, vwClearInfoAction); // Delete all the objects at once // TODO (SteveM and SteveM): This block should probably be moved to a new // DbOps method. IOleDbCommand odc = null; IOleDbEncap dbAccess = m_cache.DatabaseAccessor; dbAccess.CreateCommand(out odc); try { // execute the command on groups of hvos string sSqlCommand = "exec DeleteObjects '{0}'"; int iNextGroup = 0; while (true) { string hvoList = CmObject.MakePartialIdList(ref iNextGroup, m_ids.ToArray()); if (hvoList == string.Empty) break; // Finished with the list of objects to delete COMException originalException = null; int cFailures = 0; while (true) { // Make sure there is a transaction or savepoint that we can rollback bool fNewTransaction = !dbAccess.IsTransactionOpen(); string sSavePointName = string.Empty; if (fNewTransaction) dbAccess.BeginTrans(); else dbAccess.SetSavePoint(out sSavePointName); try { odc.ExecCommand(string.Format(sSqlCommand, hvoList), (int)SqlStmtType.knSqlStmtStoredProcedure); if (fNewTransaction) dbAccess.CommitTrans(); break; // Successfully completed the call so get out of the loop } catch (COMException ex) { if (cFailures++ == 0) originalException = ex; // An error occured while executing the command. Rollback whatever // we got so we don't keep the DB in a bad state. if (fNewTransaction) dbAccess.RollbackTrans(); else dbAccess.RollbackSavePoint(sSavePointName); if (cFailures == 4) { // Tried 4 times to complete this command, but it still failed, // so just give up. Throw the first exception we got so we have // a better idea of what started the problem. throw originalException; } } } } } finally { DbOps.ShutdownODC(ref odc); } List<PropChangeInfo> propsToChange = new List<PropChangeInfo>(); // Now we've actually made the change, clean up the cache. foreach (KeyValuePair<int, int> kvp in modifiedOwningProps) { int hvoOwner = kvp.Key; int flid = kvp.Value; int chvo; int cpt = m_cache.MetaDataCacheAccessor.GetFieldType((uint)flid); if (sda.get_IsPropInCache(hvoOwner, flid, cpt, 0)) { // Since it is cached, we should fix the cache. if (cpt == (int)CellarModuleDefns.kcptOwningAtom) { m_cache.VwCacheDaAccessor.CacheObjProp(hvoOwner, flid, 0); propsToChange.Add(new PropChangeInfo(hvoOwner, flid, 0, 0, 1)); } else { // Fix the vector or collection, removing ALL things in it that are in the // delete collection. int ihvoFirstDel = -1; int ihvoLastDel = -1; int[] contents; int chvoMax = sda.get_VecSize(hvoOwner, flid); using (ArrayPtr arrayPtr = MarshalEx.ArrayToNative(chvoMax, typeof(int))) { sda.VecProp(hvoOwner, flid, chvoMax, out chvo, arrayPtr); Debug.Assert(chvo == chvoMax); contents = (int[])MarshalEx.NativeToArray(arrayPtr, chvo, typeof(int)); } // remove from currentValue all items in idsToDel int iout = 0; for (int i = 0; i < contents.Length; ++i) { if(!m_ids.Contains(contents[i])) { contents[iout++] = contents[i]; } else { // object at i is being deleted. ihvoLastDel = i; if (ihvoFirstDel < 0) ihvoFirstDel = i; } } m_cache.VwCacheDaAccessor.CacheVecProp(hvoOwner, flid, contents, iout); if (ihvoFirstDel >= 0) // Just possible the cache is out of date or already fixed. { // Fix the display of the owning property. // We simulate a replace from the first to the last deleted object. int chvoDel = ihvoLastDel - ihvoFirstDel + 1; int chvoIns = chvoDel + iout - contents.Length; propsToChange.Add(new PropChangeInfo(hvoOwner, flid, ihvoFirstDel, chvoIns, chvoDel)); } } } else { // It's not in the cache. This SHOULD mean nothing cares about it changing, but // sometimes we kick object info out of the cache for various reasons. Just in case, // issue a complete PropChanged for it. If it's really not in use, it won't take long. // (It may take a while to load, of course...but play safe. See LT-3945 for one problem.) // This may not give a totally accurate number for chvoDel, of course...best we can do. chvo = sda.get_VecSize(hvoOwner, flid); // will load it with correct current value propsToChange.Add(new PropChangeInfo(hvoOwner, flid, 0, chvo, chvo)); } } // We save up all the prop changes until we've finished clearing things out of the cache // because of problems like LT-7972, where a CmPicture and CmFile were deleted, and the // PropChanged for deleting the CmFile triggered something that failed because we had not // yet cleared the owner of the CmPicture. foreach(PropChangeInfo info in propsToChange) info.DoIt(sda); return true; }