示例#1
0
文件: Log.cs 项目: pbazydlo/bluepath
        public static DateTime AssureTimeMonotonicity(DateTime currentTime, IExtendedStorage storage, string storageKey)
        {
            using (var l = storage.AcquireLock(string.Format("{0}_lock", storageKey)))
            {
                var previousTime = default(DateTime);
                try
                {
                    previousTime = storage.Retrieve<DateTime>(storageKey);
                }
                catch
                {
                }

                if (currentTime <= previousTime)
                {
                    currentTime = previousTime.AddMilliseconds(1);
                }

                storage.StoreOrUpdate(storageKey, currentTime);
            }

            return currentTime;
        }