Пример #1
0
        async Task IAsyncLogProviderCommandHandler.ContinueAsynchronously(CommandContext ctx)
        {
            result = new DateBoundPositionResponseData();

            result.Position = await PositionedMessagesUtils.LocateDateBound(ctx.Reader, date, bound, ctx.Cancellation);

            ctx.Tracer.Info("Position to return: {0}", result.Position);

            if (result.Position == ctx.Reader.EndPosition)
            {
                result.IsEndPosition = true;
                ctx.Tracer.Info("It is END position");
            }
            else if (result.Position == ctx.Reader.BeginPosition - 1)
            {
                result.IsBeforeBeginPosition = true;
                ctx.Tracer.Info("It is BEGIN-1 position");
            }
            else
            {
                ctx.Cancellation.ThrowIfCancellationRequested();
                if (messageRequested)
                {
                    result.Message = await PositionedMessagesUtils.ReadNearestMessage(ctx.Reader, result.Position, MessagesParserFlag.HintMessageContentIsNotNeeed);

                    ctx.Tracer.Info("Details to return: {0} at {1}", result.Message?.Time, result.Message?.Position);
                }
            }
            dateBoundsCache.Set(date, result);
        }
Пример #2
0
            public bool Update()
            {
                using (owner.trace.NewNamedFrame("Updating {0}", this.fileName))
                {
                    CheckDisposed();

                    try
                    {
                        if (simpleMedia == null)
                        {
                            owner.trace.Info("SimpleMedia object not created yet. Creating");
                            simpleMedia = new SimpleFileMedia(
                                owner.fileSystem,
                                SimpleFileMedia.CreateConnectionParamsFromFileName(Path.Combine(owner.baseDirectory, FileName))
                                );
                        }

                        owner.trace.Info("Updating simple media");
                        simpleMedia.Update();

                        if (!simpleMedia.IsAvailable)
                        {
                            owner.trace.Info("File is not avaliable (i.e. has been deleted)");
                            return(false);
                        }

                        if (firstMessageTime == null)
                        {
                            owner.trace.Info("First message time is unknown. Calcalating it");
                            using (IPositionedMessagesReader reader = (IPositionedMessagesReader)Activator.CreateInstance(
                                       owner.logReaderType, new MediaBasedReaderParams(owner.tempThreads, SimpleMedia, owner.tempFilesManager), owner.logFormatInfo))
                            {
                                owner.trace.Info("Reader created");

                                reader.UpdateAvailableBounds(false);
                                owner.trace.Info("Bounds found");

                                IMessage first = PositionedMessagesUtils.ReadNearestMessage(reader, reader.BeginPosition);
                                if (first == null)
                                {
                                    owner.trace.Warning("No messages found");
                                    return(false);
                                }

                                owner.trace.Info("First message: {0} '{1}'", first.Time, first.Text);
                                firstMessageTime = first.Time;
                            }
                        }

                        owner.trace.Info("Part updated OK");
                        return(true);
                    }
                    catch (Exception e)
                    {
                        owner.trace.Error(e, "Failure during part update");
                        return(false);
                    }
                }
            }