コード例 #1
0
        public LogEntryViewModel(DataProcessingServiceLog logEntry)
        {
            Model = logEntry;
            switch (logEntry.Details)
            {
            case ExecutionStartLogEntryDetails executionStartLogEntryDetails:
                ExecutorType   = executionStartLogEntryDetails.ExecutorType;
                ProcessorName  = executionStartLogEntryDetails.ProcessorName;
                InputTypeName  = executionStartLogEntryDetails.InputTypeName;
                OutputTypeName = executionStartLogEntryDetails.OutputTypeName;
                break;

            case ExecutionSummaryLogEntryDetails executionSummaryLogEntryDetails:
                ExecutorType   = executionSummaryLogEntryDetails.ExecutorType;
                ProcessorName  = executionSummaryLogEntryDetails.ProcessorName;
                InputTypeName  = executionSummaryLogEntryDetails.InputTypeName;
                OutputTypeName = executionSummaryLogEntryDetails.OutputTypeName;
                ExecutionTime  = executionSummaryLogEntryDetails.ExecutionTime;
                IsError        = executionSummaryLogEntryDetails.IsError;
                break;

            case CrashLogEntryDetails crashLogEntryDetails:
                IsError = true;
                break;
            }
        }
コード例 #2
0
        public void NullDetailsSerializationRoundTrip()
        {
            var logEntry = new DataProcessingServiceLog("Test", null);
            var json     = JsonConvert.SerializeObject(logEntry);
            DataProcessingServiceLog roundtripLogEntry = null;

            Assert.That(() => roundtripLogEntry = JsonConvert.DeserializeObject <DataProcessingServiceLog>(json), Throws.Nothing);
            Assert.That(roundtripLogEntry.Message, Is.EqualTo("Test"));
        }
コード例 #3
0
 private async Task LogTaskStarting(ScheduledTask task)
 {
     var logEntry = new DataProcessingServiceLog(
         $"Starting execution of task '{task.Task.DisplayName}'",
         new ExecutionStartLogEntryDetails(
             DataProcessingServiceExecutorType.Task,
             task.Task.DisplayName));
     await dataProcessingServiceLogger.Log(logEntry);
 }
コード例 #4
0
 public async Task LogExecutionStarting(IProcessor processor)
 {
     var logEntry = new DataProcessingServiceLog(
         $"Starting execution of processor '{processor.DisplayName}'",
         new ExecutionStartLogEntryDetails(
             DataProcessingServiceExecutorType.Processor,
             processor.DisplayName,
             processor.InputTypes.Count == 1 ? processor.InputTypes.First() : "Multiple",
             (processor as ISingleOutputProcessor)?.OutputTypeName ?? "Multiple"));
     await dataProcessingServiceLogger.Log(logEntry);
 }
コード例 #5
0
 private async Task LogTaskCompleted(ScheduledTask task, string summary, bool isSuccess, bool isWorkDone, Stopwatch stopWatch)
 {
     var logEntry = new DataProcessingServiceLog(
         $"Execution of task '{task.Task.DisplayName}' finished: {summary}",
         new ExecutionSummaryLogEntryDetails(
             DataProcessingServiceExecutorType.Task,
             task.Task.DisplayName,
             stopWatch.Elapsed.TotalSeconds.To(Unit.Second),
             !isSuccess,
             isWorkDone));
     await dataProcessingServiceLogger.Log(logEntry);
 }
コード例 #6
0
ファイル: MainViewModel.cs プロジェクト: mindleaving/dataapi
 private bool IsAppropriateForAllMessagesList(DataProcessingServiceLog logEntry)
 {
     if (logEntry.Details is ExecutionStartLogEntryDetails)
     {
         return(false);
     }
     if (logEntry.Details is ExecutionSummaryLogEntryDetails executionSummaryLogEntryDetails)
     {
         if (executionSummaryLogEntryDetails.IsError)
         {
             return(true);
         }
         if (!executionSummaryLogEntryDetails.IsWorkDone)
         {
             return(false);
         }
     }
     return(true);
 }
コード例 #7
0
        public void ExecutionSummaryDetailsSerializationRoundTrip()
        {
            var logEntry = new DataProcessingServiceLog("Test", new ExecutionSummaryLogEntryDetails(
                                                            DataProcessingServiceExecutorType.Processor,
                                                            "TestProcessor",
                                                            1.To(Unit.Second),
                                                            false,
                                                            false,
                                                            "TestID",
                                                            "TestType"));
            var json = JsonConvert.SerializeObject(logEntry);
            DataProcessingServiceLog roundtripLogEntry = null;

            Assert.That(() => roundtripLogEntry = JsonConvert.DeserializeObject <DataProcessingServiceLog>(json), Throws.Nothing);
            Assert.That(roundtripLogEntry.Message, Is.EqualTo("Test"));
            Assert.That(roundtripLogEntry.Details.Type, Is.EqualTo(nameof(ExecutionSummaryLogEntryDetails)));
            var logEntryDetails = (ExecutionSummaryLogEntryDetails)roundtripLogEntry.Details;

            Assert.That(logEntryDetails.ExecutorType, Is.EqualTo(DataProcessingServiceExecutorType.Processor));
            Assert.That(logEntryDetails.InputDataObjectId, Is.EqualTo("TestID"));
        }
コード例 #8
0
 public async Task LogExecutionFinished(
     IProcessor processor,
     string outputTypeName,
     string inputId,
     string summary,
     bool isSuccess,
     bool isWorkDone,
     Stopwatch stopWatch)
 {
     var log = new DataProcessingServiceLog(
         summary,
         new ExecutionSummaryLogEntryDetails(
             DataProcessingServiceExecutorType.Processor,
             processor.DisplayName,
             stopWatch.Elapsed.TotalSeconds.To(Unit.Second),
             !isSuccess,
             isWorkDone,
             inputId,
             processor.InputTypes.Count == 1 ? processor.InputTypes.First() : "Multiple",
             outputTypeName));
     await dataProcessingServiceLogger.Log(log);
 }
コード例 #9
0
ファイル: MainViewModel.cs プロジェクト: mindleaving/dataapi
        private void LogEntryMonitor_NewLogEntry(object sender, DataProcessingServiceLog logEntry)
        {
            Application.Current.Dispatcher.BeginInvoke((Action)(() =>
            {
                var logEntryViewModel = new LogEntryViewModel(logEntry);
                if (IsAppropriateForAllMessagesList(logEntry))
                {
                    AllLogMessages.Add(logEntryViewModel);
                }
                if (logEntryViewModel.IsError)
                {
                    ErrorLogMessages.Add(logEntryViewModel);
                }
                if (logEntryViewModel.ExecutorType.HasValue)
                {
                    switch (logEntryViewModel.ExecutorType.Value)
                    {
                    case DataProcessingServiceExecutorType.Processor:
                        if (logEntryViewModel.ProcessorName != "Unknown")
                        {
                            var matchingProcessor = Processors.SingleOrDefault(p => p.Details.Name == logEntryViewModel.ProcessorName);
                            if (matchingProcessor == null)
                            {
                                matchingProcessor = new ProcessorViewModel(
                                    new ProcessorDetails(
                                        logEntryViewModel.ProcessorName,
                                        logEntryViewModel.InputTypeName,
                                        logEntryViewModel.OutputTypeName)
                                    );
                                // Sort alphabetically
                                var insertIndex = Processors.Count(processor =>
                                                                   processor.Details.Name.CompareTo(matchingProcessor.Details.Name) < 0);
                                Processors.Insert(insertIndex, matchingProcessor);
                            }

                            matchingProcessor.LogEntries.Add(logEntryViewModel);
                        }
                        break;

                    case DataProcessingServiceExecutorType.Task:
                        var matchingTask = Tasks.SingleOrDefault(t => t.Details.Name == logEntryViewModel.ProcessorName);
                        if (matchingTask == null)
                        {
                            matchingTask = new TaskViewModel(new TaskDetails(logEntryViewModel.ProcessorName));
                            // Sort alphabetically
                            var insertIndex = Tasks.Count(task => task.Details.Name.CompareTo(matchingTask.Details.Name) <= 0);
                            Tasks.Insert(insertIndex, matchingTask);
                        }
                        matchingTask.LogEntries.Add(logEntryViewModel);
                        if (logEntry.Details is ExecutionSummaryLogEntryDetails &&
                            (!matchingTask.LastExecutionTime.HasValue || matchingTask.LastExecutionTime < logEntry.Timestamp))
                        {
                            matchingTask.LastExecutionTime = logEntry.Timestamp;
                        }
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
            }));
        }
コード例 #10
0
ファイル: Distributor.cs プロジェクト: mindleaving/dataapi
        private async Task Run(CancellationToken cancellationToken)
        {
            try
            {
                await dataProcessingServiceLogger.Log(new DataProcessingServiceLog($"{nameof(Distributor)} started", null));

                await dataProcessingServiceLogger.Log(new DataProcessingServiceLog(
                                                          $"{nameof(Distributor)} running for types '{processorDatabase.InputTypes.Aggregate((a, b) => a + ", " + b)}'", null));
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }

            try
            {
                while (!cancellationToken.IsCancellationRequested)
                {
                    if (dataApiClient.IsAvailable())
                    {
                        if (!dataApiClient.IsLoggedIn && !dataApiClient.RetryLogin().IsAuthenticated)
                        {
                            cancellationToken.WaitHandle.WaitOne(TimeSpan.FromSeconds(60));
                            continue;
                        }

                        try
                        {
                            var subscriptionNotifications = await dataApiClient.GetSubscribedObjects();

                            foreach (var subscriptionNotification in subscriptionNotifications)
                            {
                                if (cancellationToken.IsCancellationRequested)
                                {
                                    break;
                                }
                                var dataType = subscriptionNotification.DataType;
                                if (subscriptionNotification.ModificationType != DataModificationType.Deleted)
                                {
                                    var exists = await dataApiClient.ExistsAsync(
                                        dataType,
                                        subscriptionNotification.DataObjectId);

                                    if (!exists)
                                    {
                                        await MarkAsProcessed(subscriptionNotification.Id);

                                        continue;
                                    }
                                }

                                try
                                {
                                    var typeProcessors = processorDatabase.GetForType(dataType);
                                    switch (subscriptionNotification.ModificationType)
                                    {
                                    case DataModificationType.Created:
                                    case DataModificationType.Replaced:
                                        var typeObject = await LoadObject(subscriptionNotification);
                                        await ApplyProcessorsToObject(
                                            subscriptionNotification.ModificationType,
                                            dataType,
                                            subscriptionNotification.DataObjectId,
                                            typeObject,
                                            typeProcessors);

                                        break;

                                    case DataModificationType.Deleted:
                                        await ApplyProcessorsToObject(
                                            subscriptionNotification.ModificationType,
                                            dataType,
                                            subscriptionNotification.DataObjectId,
                                            null,
                                            typeProcessors);

                                        break;

                                    default:
                                        throw new ArgumentOutOfRangeException();
                                    }

                                    await MarkAsProcessed(subscriptionNotification.Id);
                                }
                                catch (Exception e)
                                {
                                    var logEntry = new DataProcessingServiceLog(
                                        $"Processing of '{dataType}' with ID '{subscriptionNotification.DataObjectId}' failed: {e.Message}",
                                        new ExecutionSummaryLogEntryDetails(
                                            DataProcessingServiceExecutorType.Processor,
                                            "Unknown",
                                            0.To(Unit.Second),
                                            isError: true,
                                            isWorkDone: false,
                                            inputDataObjectId: subscriptionNotification.DataObjectId,
                                            inputTypeName: dataType));
                                    await dataProcessingServiceLogger.Log(logEntry);
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            var logEntry = new DataProcessingServiceLog(
                                $"Processing of subscription notifications failed: {e.InnermostException().Message}",
                                new CrashLogEntryDetails(nameof(Distributor), e.InnermostException().Message));
                            await dataProcessingServiceLogger.Log(logEntry);
                        }
                    }

                    pollNowEventHandle.Reset();
                    WaitHandle.WaitAny(new[] { cancellationToken.WaitHandle, pollNowEventHandle }, PollInterval);
                }
            }
            catch (Exception e)
            {
                await dataProcessingServiceLogger.Log(new DataProcessingServiceLog(
                                                          $"Distributor crashed: {e.InnermostException().Message}",
                                                          new CrashLogEntryDetails(nameof(Distributor), e.InnermostException().Message)));
            }

            try
            {
                await dataProcessingServiceLogger.Log(new DataProcessingServiceLog($"{nameof(Distributor)} stopped", null));
            }
            catch
            {
                // Ignore logging errors
            }
        }
コード例 #11
0
 public Task Log(DataProcessingServiceLog logEntry)
 {
     return(Task.CompletedTask);
 }