const int ktagMinVp = 0x7f000000; // copied from VwCacheDa.h, mimimum value for assigned virtual props. /// <summary> /// We implement this to record modify times. /// </summary> /// <param name="hvo"></param> /// <param name="tag"></param> /// <param name="ivMin"></param> /// <param name="cvIns"></param> /// <param name="cvDel"></param> public void PropChanged(int hvo, int tag, int ivMin, int cvIns, int cvDel) { CheckDisposed(); if (m_fModifyChangeInProgress) // ignore PropChanged on the DateModified property! { return; } // Typically an Undo will restore the modify time to what it was before the // main change. We don't want to reverse that by recording the time of the Undo! // Note that there is one pathological scenario: // t1: make a change. // t2: undo the change. // t3: export all changed records (since before t1). // t4: redo the change. Record appears to have been modified at time t2. // t5: export all changed records (since t3). // If this was the only change to the record, it is not part of either export, // and the change might be lost. // To prevent this, I think the 'export changed records' function should clear // the Undo stack. if (m_cache.ActionHandlerAccessor != null && m_cache.ActionHandlerAccessor.IsUndoOrRedoInProgress) { return; } if (tag < 0 || tag >= ktagMinVp) { return; // phony or virtual properties, not real changes (e.g., different filter applied, or selection moving in browse). } try { DateTime dtNow = DateTime.Now; int hvoMajor = 0; // hvo of the 'major' object that has the DateModified property. if (SameMinute(dtNow, m_currentMinute)) { // We can use our Dictionary if (m_recentMods.ContainsKey(hvo)) { hvoMajor = m_recentMods[hvo]; } } else { ResetDelay(); } int flidModify = 0; if (hvoMajor == 0) { for (int hvoCandidate = hvo; hvoCandidate != 0; hvoCandidate = m_cache.GetOwnerOfObject(hvoCandidate)) { // We assume that this is a dummy object at this point and GetClassOfObject // only accepts real objects. Since it's a dummy object, changes should never // affect the modify time of a real object. Maybe at some point we can get an // interface method to check for dummy objects. if (hvoCandidate < 0) { return; } int clid = m_cache.GetClassOfObject(hvoCandidate); if (clid == 0) { return; // maybe a deleted object, no good to us, we can't record modify time. } flidModify = (int)m_mdc.GetFieldId2((uint)clid, "DateModified", true); if (flidModify != 0) { hvoMajor = hvoCandidate; break; } } if (hvoMajor == 0) { return; // found no owner with DateCreated property. } m_recentMods[hvo] = hvoMajor; // lets us find it fast if modified again soon. } else { // We need to set flidModify! int clid = m_cache.GetClassOfObject(hvoMajor); if (clid != 0) { flidModify = (int)m_mdc.GetFieldId2((uint)clid, "DateModified", true); } } if (flidModify == 0) { return; // can't set the time prop without a field... } DateTime oldModifyTime = m_cache.GetTimeProperty(hvoMajor, flidModify); // If we already noted a modify time in the current minute, don't do it again. // This is intended to keep down the overhead of recording modify times for frequently // modified objects. if (SameMinute(oldModifyTime, dtNow)) { //Trace.TraceInformation("New Modify Time ({0}) for {1} is same minute as the old ({2}).\n", // dtNow, hvoMajor, oldModifyTime); return; } // if (m_currentMinute != null && // m_currentMinute.Date == dtNow.Date && m_currentMinute.Hour = dtNow.Hour && m_currentMinute.Minute == dtNow.Minute) // return; // Set the modify time. If possible tack this on to the last Undo task (or the current one, if a // transaction is open). if (m_cache.ActionHandlerAccessor != null && m_cache.VwOleDbDaAccessor != null && ((m_cache.DatabaseAccessor != null && m_cache.DatabaseAccessor.IsTransactionOpen()) || m_cache.CanUndo)) { m_cache.ContinueUndoTask(); m_cache.SetTimeProperty(hvoMajor, flidModify, dtNow); m_cache.EndUndoTask(); } else { // We don't have an Undo task to append to, so somehow a Save has occurred // in the midst of the operation that caused the time stamp modification. // If we make an empty undo task, the user will typically have no idea what // could be undone, and will be confused. Best to make it impossible to // undo the timestamp change also. using (new SuppressSubTasks(m_cache)) { m_cache.SetTimeProperty(hvoMajor, flidModify, dtNow); } } //Trace.TraceInformation("Setting new Modify Time ({0}) for {1}\n", // dtNow, hvoMajor); } finally { m_fModifyChangeInProgress = false; } }