コード例 #1
0
 public static Task SerializePostprocessorOutput(
     IEnumerableAsync <Event[]> events,
     Task <ILogPartToken> rotatedLogPartToken,
     Func <object, TextLogEventTrigger> triggersConverter,
     string contentsEtagAttr,
     string outputFileName,
     ITempFilesManager tempFiles,
     CancellationToken cancellation
     )
 {
     return(events.SerializePostprocessorOutput <Event, EventsSerializer, IEventsVisitor>(
                triggerSerializer => new EventsSerializer(triggerSerializer),
                rotatedLogPartToken,
                triggersConverter,
                contentsEtagAttr,
                "root",
                outputFileName,
                tempFiles,
                cancellation
                ));
 }
コード例 #2
0
        public static async Task SerializePostprocessorOutput(
            IEnumerableAsync <M.Event[]> events,
            IEnumerableAsync <TLBlock.Event[]> timelineComments,
            IEnumerableAsync <SIBlock.Event[]> stateInspectorComments,
            Task <ILogPartToken> logPartToken,
            ILogPartTokenFactories logPartTokenFactories,
            Func <object, TextLogEventTrigger> triggersConverter,
            string contentsEtagAttr,
            string outputFileName,
            ITempFilesManager tempFiles,
            CancellationToken cancellation
            )
        {
            events                 = events ?? new List <M.Event[]>().ToAsync();
            timelineComments       = timelineComments ?? new List <TLBlock.Event[]>().ToAsync();
            stateInspectorComments = stateInspectorComments ?? new List <SIBlock.Event[]>().ToAsync();
            logPartToken           = logPartToken ?? Task.FromResult <ILogPartToken>(null);

            var eventsTmpFile                = tempFiles.GenerateNewName();
            var timelineCommentsTmpFile      = tempFiles.GenerateNewName();
            var stateInsectorCommentsTmpFile = tempFiles.GenerateNewName();

            var serializeMessagingEvents = events.SerializePostprocessorOutput <M.Event, M.EventsSerializer, M.IEventsVisitor>(
                triggerSerializer => new M.EventsSerializer(triggerSerializer),
                null, logPartTokenFactories, triggersConverter, null, messagingEventsElementName, eventsTmpFile, tempFiles, cancellation
                );

            var serializeTimelineComments = timelineComments.SerializePostprocessorOutput <TLBlock.Event, TLBlock.EventsSerializer, TLBlock.IEventsVisitor>(
                triggerSerializer => new TLBlock.EventsSerializer(triggerSerializer),
                null, logPartTokenFactories, triggersConverter, null, timelineCommentsElementName, timelineCommentsTmpFile, tempFiles, cancellation
                );

            var serializeStateInspectorComments = stateInspectorComments.SerializePostprocessorOutput <SIBlock.Event, SIBlock.EventsSerializer, SIBlock.IEventsVisitor>(
                triggerSerializer => new SIBlock.EventsSerializer(triggerSerializer),
                null, logPartTokenFactories, triggersConverter, null, stateCommentsElementName, stateInsectorCommentsTmpFile, tempFiles, cancellation
                );

            await Task.WhenAll(serializeMessagingEvents, serializeTimelineComments, serializeStateInspectorComments, logPartToken);

            using (var outputWriter = XmlWriter.Create(outputFileName, new XmlWriterSettings()
            {
                Indent = true, Async = true
            }))
                using (var messagingEventsReader = XmlReader.Create(eventsTmpFile))
                    using (var timelineCommentsReader = XmlReader.Create(timelineCommentsTmpFile))
                        using (var stateInspectorCommentsReader = XmlReader.Create(stateInsectorCommentsTmpFile))
                        {
                            outputWriter.WriteStartElement("root");

                            new PostprocessorOutputETag(contentsEtagAttr).Write(outputWriter);
                            logPartTokenFactories.SafeWriteTo(await logPartToken, outputWriter);

                            messagingEventsReader.ReadToFollowing(messagingEventsElementName);
                            await outputWriter.WriteNodeAsync(messagingEventsReader, false);

                            timelineCommentsReader.ReadToFollowing(timelineCommentsElementName);
                            await outputWriter.WriteNodeAsync(timelineCommentsReader, false);

                            stateInspectorCommentsReader.ReadToFollowing(stateCommentsElementName);
                            await outputWriter.WriteNodeAsync(stateInspectorCommentsReader, false);

                            outputWriter.WriteEndElement();     // root
                        }

            File.Delete(eventsTmpFile);
            File.Delete(timelineCommentsTmpFile);
            File.Delete(stateInsectorCommentsTmpFile);
        }