Пример #1
0
        private static void FinaliseCurrentSaveOperation(
            IList <AssociateHistorySaveOperation> saveOperations,
            AssociateEditHistoryItem lastHistoryItem,
            AssociateHistorySaveOperation currentSaveOperation)
        {
            currentSaveOperation.LastSaveTimeStamp = lastHistoryItem.ModifiedTime;

            if (saveOperations.Count > 1)
            {
                // If the two most recent items in the list are save operations from the user
                // we are just about to add another record for then replace the middle one
                // rather than add a new one. (We only show the first and last save per
                // contiguous edit session)
                AssociateHistorySaveOperation p1 = saveOperations[saveOperations.Count - 1];
                AssociateHistorySaveOperation p2 = saveOperations[saveOperations.Count - 2];

                if (p1.ModifiedBy == currentSaveOperation.ModifiedBy &&
                    p1.ModifiedSource == currentSaveOperation.ModifiedSource && p1.ModifiedBy == p2.ModifiedBy &&
                    p1.ModifiedSource == p2.ModifiedSource)
                {
                    saveOperations[saveOperations.Count - 1] = currentSaveOperation;
                    return;
                }
            }

            saveOperations.Add(currentSaveOperation);
        }
Пример #2
0
        public IEnumerable <AssociateHistorySaveOperation> GetAssociateCollapsedEditHistory(
            int associateId, out bool associateChangeAfterAdmin)
        {
            IEnumerable <AssociateEditHistoryItem> editHistory =
                this.dataMapper.MapEditHistoryM2E(this.associateRepo.GetAssociateEditHistory(associateId));

            /* The list is ordered in ascending order of ModifiedTime. Where there are multiple consecutive edits
             * by the same user we only show the first and last save in each session. Slightly complicating matters
             * is that each "save" as perceived by the user may actually be carried out by separate SQL statements with
             * slightly different timestamps. If two consecutive saves have the same ModifiedSource, ModifiedTime and
             * are separated by <= one second we regard this as one operation.
             *
             * So timestamps of 10:00, 11:13:00,11:13:01,11:13:02, 14:00 would be treated as 3 saves (at 10:00, 11:13:00 and 14:00).
             *
             * We need to keep track internally of the fact that this save spans from 11:13:00 to 11:13:02 however.
             *
             * Because if we compare the 10:00 version with the 11:13:00 version we should include the changes up until 11:13:02 in what is displayed.
             *
             */
            AssociateEditHistoryItem lastHistoryItem = null;

            AssociateHistorySaveOperation currentSaveOperation = null;

            var saveOperations = new List <AssociateHistorySaveOperation>();

            foreach (AssociateEditHistoryItem historyItem in editHistory)
            {
                if (lastHistoryItem != null
                    &&
                    (lastHistoryItem.ModifiedBy != historyItem.ModifiedBy ||
                     lastHistoryItem.ModifiedSource != historyItem.ModifiedSource ||
                     historyItem.ModifiedTime.Subtract(lastHistoryItem.ModifiedTime).TotalMilliseconds > 1000))
                {
                    FinaliseCurrentSaveOperation(saveOperations, lastHistoryItem, currentSaveOperation);

                    currentSaveOperation = null;
                }

                if (currentSaveOperation == null)
                {
                    currentSaveOperation = new AssociateHistorySaveOperation
                    {
                        FirstSaveTimeStamp = historyItem.ModifiedTime,
                        ModifiedBy         = historyItem.ModifiedBy,
                        ModifiedSource     = historyItem.ModifiedSource
                    };
                }

                lastHistoryItem = historyItem;
            }

            if (currentSaveOperation != null)
            {
                FinaliseCurrentSaveOperation(saveOperations, lastHistoryItem, currentSaveOperation);
            }

            AssociateEditHistoryItem lastAdminEdit     = editHistory.FirstOrDefault(e => e.ModifiedSource == "Admin");
            AssociateEditHistoryItem lastAssociateEdit =
                editHistory.FirstOrDefault(e => e.ModifiedSource == "AssociatePortal");

            associateChangeAfterAdmin = lastAdminEdit != null && lastAssociateEdit != null &&
                                        lastAssociateEdit.ModifiedTime > lastAdminEdit.ModifiedTime;

            return(saveOperations);
        }
Пример #3
0
        private static void FinaliseCurrentSaveOperation(
            IList<AssociateHistorySaveOperation> saveOperations, 
            AssociateEditHistoryItem lastHistoryItem, 
            AssociateHistorySaveOperation currentSaveOperation)
        {
            currentSaveOperation.LastSaveTimeStamp = lastHistoryItem.ModifiedTime;

            if (saveOperations.Count > 1)
            {
                // If the two most recent items in the list are save operations from the user
                // we are just about to add another record for then replace the middle one
                // rather than add a new one. (We only show the first and last save per
                // contiguous edit session)
                AssociateHistorySaveOperation p1 = saveOperations[saveOperations.Count - 1];
                AssociateHistorySaveOperation p2 = saveOperations[saveOperations.Count - 2];

                if (p1.ModifiedBy == currentSaveOperation.ModifiedBy
                    && p1.ModifiedSource == currentSaveOperation.ModifiedSource && p1.ModifiedBy == p2.ModifiedBy
                    && p1.ModifiedSource == p2.ModifiedSource)
                {
                    saveOperations[saveOperations.Count - 1] = currentSaveOperation;
                    return;
                }
            }

            saveOperations.Add(currentSaveOperation);
        }