Esempio n. 1
0
        public DateBoundPositionResponseData GetDateBoundPosition(DateTime d, ValueBound bound)
        {
            var idx = ListUtils.GetBound(messages, (IMessage)null, bound, new DatesComparer(d));

            if (idx < 0)
            {
                return new DateBoundPositionResponseData()
                       {
                           Position = -1,
                           Index    = -1,
                           IsBeforeBeginPosition = true,
                       }
            }
            ;
            if (idx >= messages.Count)
            {
                return new DateBoundPositionResponseData()
                       {
                           Position      = messages.Count == 0 ? 0 : (messages[messages.Count - 1].Position + 1),
                           Index         = messages.Count,
                           IsEndPosition = true,
                       }
            }
            ;
            return(new DateBoundPositionResponseData()
            {
                Position = messages[idx].Position,
                Index = idx,
                Message = messages[idx]
            });
        }
    };
}
Esempio n. 2
0
        static void TestBound(int value, ValueBound bound, int expectedIdx)
        {
            List <int> lst    = new List <int>(new int[] { 0, 2, 2, 2, 3, 5, 7, 8, 8, 10 });
            int        actual = ListUtils.GetBound(lst, value, bound, Comparer <int> .Default);

            Assert.AreEqual(expectedIdx, actual);
        }
Esempio n. 3
0
 public GetDateBoundCommand(DateTime date, bool getMessage, ValueBound bound, IDateBoundsCache dateBoundsCache)
 {
     this.date             = date;
     this.bound            = bound;
     this.messageRequested = getMessage;
     this.dateBoundsCache  = dateBoundsCache;
 }
Esempio n. 4
0
        static void TestBound(int value, ValueBound bound, int expectedIdx)
        {
            List <int> lst    = new List <int>(new int[] { 0, 2, 2, 2, 3, 5, 7, 8, 8, 10 });
            int        actual = GetBound(lst, value, bound, Comparer <int> .Default);

            System.Diagnostics.Debug.Assert(actual == expectedIdx);
        }
Esempio n. 5
0
		static void FindDateBoundTest(ValueBound bound, long dateTicks, 
			string expectedMessage, EntryPartition? searchRangeBegin = null, EntryPartition? searchRangeEnd = null)
		{
			var entry = AzureDiagnosticsUtils.FindDateBound(
				new AzureDiagnosticLogsTableMock()
					.Add(TestEventTimestampFromMinutes(1), "1")
					.Add(TestEventTimestampFromMinutes(1) + 2, "1+2")
					.Add(TestEventTimestampFromMinutes(1) + 2, "1+2.2")
					.Add(TestEventTimestampFromMinutes(1) + 3, "1+3")
					.Add(TestEventTimestampFromMinutes(1) + 10, "1+10")
					.Add(TestEventTimestampFromMinutes(2), "2")
					.Add(TestEventTimestampFromMinutes(3) + 100, "3+100")
					.Add(TestEventTimestampFromMinutes(3) + 200, "3+200")
					.Add(TestEventTimestampFromMinutes(3) + 300, "3+300")
					.Add(TestEventTimestampFromMinutes(3) + 300, "3+300.2")
					.Add(TestEventTimestampFromMinutes(1000) + 10, "1000+10")
					.Add(TestEventTimestampFromMinutes(1000) + 20, "1000+20")
					.Add(TestEventTimestampFromMinutes(100000), "100000")
					.Add(TestEventTimestampFromMinutes(100000) + 100, "100000+100"),
				new DateTime(dateTicks, DateTimeKind.Utc), bound, 
					searchRangeBegin.GetValueOrDefault(EntryPartition.MinValue), 
					searchRangeEnd.GetValueOrDefault(EntryPartition.MaxValue), 
					CancellationToken.None);
			if (expectedMessage == null)
			{
				Assert.IsTrue(!entry.HasValue);
			}
			else
			{
				Assert.IsTrue(entry.HasValue);
				Assert.AreEqual(expectedMessage, (entry.Value.Entry as WADLogsTableEntry).Message);
			}
		}
Esempio n. 6
0
 Task <DateBoundPositionResponseData> ITimeGapsSource.GetDateBoundPosition(
     DateTime d,
     ValueBound bound,
     CancellationToken cancellation
     )
 {
     return(source.Provider.GetDateBoundPosition(d, bound, true, LogProviderCommandPriority.BackgroundActivity, cancellation));
 }
Esempio n. 7
0
        Task <DateBoundPositionResponseData> ILogProvider.GetDateBoundPosition(
            DateTime d, ValueBound bound, bool getDate,
            LogProviderCommandPriority priority, CancellationToken cancellation)
        {
            CheckDisposed();
            var ret = new GetDateBoundCommand(d, getDate, bound, dateBoundsCache);
            var cmd = new Command(Command.CommandType.GetDateBound, priority, tracer, cancellation, ret);

            PostCommand(cmd);
            return(ret.Task);
        }
Esempio n. 8
0
        static string ToString(ValueBound bound)
        {
            switch (bound)
            {
            case LogJoint.ValueBound.Lower: return("L");

            case LogJoint.ValueBound.LowerReversed: return("LR");

            case LogJoint.ValueBound.Upper: return("U");

            case LogJoint.ValueBound.UpperReversed: return("UR");

            default: Assert.Fail(); return("");
            }
        }
Esempio n. 9
0
        public static IndexedAzureDiagnosticLogEntry?FindDateBound(
            IAzureDiagnosticLogsTable wadTable,
            DateTime date,
            ValueBound bound,
            EntryPartition searchRangeBegin,
            EntryPartition searchRangeEnd,
            CancellationToken cancellationToken)
        {
            switch (bound)
            {
            case ValueBound.Lower:
                return(FindLowerDateBound(wadTable, date, searchRangeEnd, cancellationToken));

            case ValueBound.LowerReversed:
                return(FindLowerReversedDateBound(wadTable, date, searchRangeBegin, cancellationToken));

            default:
                throw new NotImplementedException("Searching for " + bound.ToString() + " bound in Azure Diagnostics Logs is not implemented");
            }
        }
 public static long LocateDateBound(IPositionedMessagesReader reader, DateTime date, ValueBound bound)
 {
     return(LocateDateBound(reader, date, bound, CancellationToken.None));
 }
Esempio n. 11
0
        public static async Task <int> GetBoundAsync <T>(this IList <T> sortedList, int begin, int end, T value, ValueBound bound, Func <T, T, Task <int> > comparer)
        {
            Func <T, Task <bool> > pred;

            if (bound == ValueBound.Lower || bound == ValueBound.UpperReversed)
            {
                pred = async x => await comparer(x, value) < 0;
            }
            else if (bound == ValueBound.Upper || bound == ValueBound.LowerReversed)
            {
                pred = async x => await comparer(x, value) <= 0;
            }
            else
            {
                throw new ArgumentException();
            }
            int ret = await BinarySearchAsync <T>(sortedList, begin, end, pred);

            if (bound == ValueBound.LowerReversed || bound == ValueBound.UpperReversed)
            {
                ret--;
            }
            return(ret);
        }
Esempio n. 12
0
        public static int GetBound <T>(this IList <T> sortedList, int begin, int end, T value, ValueBound bound, IComparer <T> comparer)
        {
            Predicate <T> pred;

            if (bound == ValueBound.Lower || bound == ValueBound.UpperReversed)
            {
                pred = delegate(T x) { return(comparer.Compare(x, value) < 0); }
            }
            ;
            else if (bound == ValueBound.Upper || bound == ValueBound.LowerReversed)
            {
                pred = delegate(T x) { return(comparer.Compare(x, value) <= 0); }
            }
            ;
            else
            {
                throw new ArgumentException();
            }
            int ret = BinarySearch <T>(sortedList, begin, end, pred);

            if (bound == ValueBound.LowerReversed || bound == ValueBound.UpperReversed)
            {
                ret--;
            }
            return(ret);
        }
Esempio n. 13
0
 public static int GetBound <T>(this IList <T> sortedList, T value, ValueBound bound, IComparer <T> comparer)
 {
     return(GetBound <T>(sortedList, 0, sortedList.Count, value, bound, comparer));
 }
 Task <DateBoundPositionResponseData> IMessagesSource.GetDateBoundPosition(DateTime d, ValueBound bound,
                                                                           LogProviderCommandPriority priority, CancellationToken cancellation)
 {
     if (ls.IsDisposed)
     {
         throw new OperationCanceledException();
     }
     return(ls.Provider.GetDateBoundPosition(d, bound, false, priority, cancellation));
 }
Esempio n. 15
0
 DateBoundPositionResponseData ICombinedSourceSearchResult.GetDateBoundPosition(DateTime d, ValueBound bound)
 {
     return(messages.GetDateBoundPosition(d, bound));
 }
Esempio n. 16
0
        Task <DateBoundPositionResponseData> ITimeGapsSource.GetDateBoundPosition(DateTime d, ValueBound bound, CancellationToken cancellation)
        {
            var ret = new DateBoundPositionResponseData()
            {
                IsEndPosition         = true,
                IsBeforeBeginPosition = true
            };

            bool findSmallestDate = bound == ValueBound.Lower || bound == ValueBound.Upper;

            foreach (var r in EnumVisibleResults().Select(r => r.GetLastSnapshot()).Where(s => s != null))
            {
                var bnd = r.GetDateBoundPosition(d, bound);

                if (bnd.Message != null)
                {
                    if (ret.Message == null)
                    {
                        ret.Message = bnd.Message;
                    }
                    else if (findSmallestDate)
                    {
                        if (bnd.Message.Time < ret.Message.Time)
                        {
                            ret.Message = bnd.Message;
                        }
                    }
                    else
                    {
                        if (bnd.Message.Time > ret.Message.Time)
                        {
                            ret.Message = bnd.Message;
                        }
                    }
                }

                if (!bnd.IsBeforeBeginPosition)
                {
                    ret.IsBeforeBeginPosition = false;
                }
                if (!bnd.IsEndPosition)
                {
                    ret.IsEndPosition = false;
                }

                ret.Position += bnd.Index;                 // use sum of indexes as virtual position
            }

            return(Task.FromResult(ret));
        }
        public static long LocateDateBound(IPositionedMessagesReader reader, DateTime date, ValueBound bound, CancellationToken cancellation)
        {
            var d = new MessageTimestamp(date);

            long begin = reader.BeginPosition;
            long end   = reader.EndPosition;

            long pos   = begin;
            long count = end - begin;

            for (; 0 < count;)
            {
                long count2 = count / 2;

                MessageTimestamp d2        = ReadNearestMessageTimestamp(reader, pos + count2).GetValueOrDefault(MessageTimestamp.MaxValue);
                bool             moveRight = false;
                switch (bound)
                {
                case ValueBound.Lower:
                case ValueBound.UpperReversed:
                    moveRight = d2 < d;
                    break;

                case ValueBound.Upper:
                case ValueBound.LowerReversed:
                    moveRight = d2 <= d;
                    break;
                }
                if (moveRight)
                {
                    pos   += count2 + 1;
                    count -= count2 + 1;
                }
                else
                {
                    count = count2;
                }

                cancellation.ThrowIfCancellationRequested();
            }

            if (bound == ValueBound.LowerReversed || bound == ValueBound.UpperReversed)
            {
                long?tmp = FindPrevMessagePosition(reader, pos);
                if (tmp == null)
                {
                    return(begin - 1);
                }
                pos = tmp.Value;
            }

            return(pos);
        }
Esempio n. 18
0
 Task <DateBoundPositionResponseData> LogViewer.IMessagesSource.GetDateBoundPosition(
     DateTime d, ValueBound bound,
     LogProviderCommandPriority priority, CancellationToken cancellation)
 {
     return(Task.FromResult(ssr.GetDateBoundPosition(d, bound)));
 }
Esempio n. 19
0
 public static async Task <long> LocateDateBound(IPositionedMessagesReader reader, DateTime date, ValueBound bound)
 {
     return(await LocateDateBound(reader, date, bound, CancellationToken.None));
 }
Esempio n. 20
0
 Task <DateBoundPositionResponseData> IMessagesSource.GetDateBoundPosition(DateTime d, ValueBound bound, LogProviderCommandPriority priority, System.Threading.CancellationToken cancellation)
 {
     return(Task.FromResult(messages.GetDateBoundPosition(d, bound)));
 }