Пример #1
0
        public static async Task GenerateCodeAsync(IReadOnlyCollection <GenerationItem> generationItems, bool withRegeneration, IUnitTestGeneratorPackage package, Dictionary <Project, Tuple <HashSet <TargetAsset>, HashSet <IReferencedAssembly> > > requiredAssetsByProject, IMessageLogger messageLogger)
        {
            var solution = package.Workspace.CurrentSolution;
            var options  = package.Options;

            foreach (var generationItem in generationItems)
            {
                await GenerateItemAsync(withRegeneration, options, solution, generationItem).ConfigureAwait(true);
            }

            await package.JoinableTaskFactory.SwitchToMainThreadAsync();

            Attempt.Action(
                () =>
            {
                ThreadHelper.ThrowIfNotOnUIThread();

                messageLogger.LogMessage("Adding required assets to target project...");
                foreach (var pair in requiredAssetsByProject)
                {
                    AddTargetAssets(options, pair);

                    if (options.GenerationOptions.AddReferencesAutomatically)
                    {
                        ReferencesHelper.AddReferencesToProject(pair.Key, pair.Value.Item2.ToList(), messageLogger.LogMessage);
                    }
                }

                if (generationItems.All(x => string.IsNullOrWhiteSpace(x.TargetContent)))
                {
                    throw new InvalidOperationException("None of the selected targets contained a testable type. Tests can only be generated for classes and structs");
                }

                messageLogger.LogMessage("Adding generated items to target project...");
                foreach (var generationItem in generationItems.Where(x => !string.IsNullOrWhiteSpace(x.TargetContent)))
                {
                    if (generationItem.TargetProjectItems != null)
                    {
                        AddTargetItem(generationItems, options, generationItem);
                    }
                    else
                    {
                        CreateUnsavedFile(package, generationItem);
                    }
                }

                messageLogger.LogMessage("Generation complete.");
            }, package);
        }
Пример #2
0
        public bool Announce(IMessage message, IMessageSettingsOut messageSettings)
        {
            _processor.Type = messageSettings.MessageSettings["produce.ontopic"];
            var valueToSend = JsonHelperSerialiser.ToJson(message, JsonHelperSerialiserSettings.CamelCaseSerialiseSettings);

            var deliveryReport = producer.ProduceAsync(messageSettings.MessageSettings["produce.ontopic"], null, valueToSend);

            var result = deliveryReport.ConfigureAwait(false).GetAwaiter().GetResult(); // synchronously waits for message to be produced.

            if (result.IsSuccess())
            {
                producer.Flush(TimeSpan.FromSeconds(10));

                var messageToLog = new AllsaintsMessageLogger.LogMessage()
                {
                    Id           = message.Id,
                    DateStampUtc = message.DateStampUtc,
                    IsTest       = message.IsTest,
                    Message      = message,
                };
                _messageLogger.LogMessage(EventTypes.Sent, _processor, messageToLog);
                return(true);
            }
            else
            {
                OnError(result.Error.ToString());
                return(false);
            }
        }
Пример #3
0
        public static LogMessageRecord LogMessage(this IMessageLogger logger, LogLevel level, string message)
        {
            LogMessageRecord rec = new LogMessageRecord(level, message);

            logger?.LogMessage(rec);
            return(rec);;
        }
Пример #4
0
        public static LogMessageRecord LogMessageDetail(this IMessageLogger logger, string category, LogLevel level, string message, string detail)
        {
            var rec = new LogMessageRecord {
                Category = category, Message = message, Detail = detail, Level = level
            };

            logger?.LogMessage(rec);
            return(rec);
        }
Пример #5
0
        public IConsumerResponse LogMessage(IConsumerRequest request, IConsumerResponse response)
        {
            if (MessageLogger != null)
            {
                MessageLogger.LogMessage(request, response);
            }

            return(response);
        }
Пример #6
0
        public static LogMessageRecord LogMessage(this IMessageLogger logger, string category, LogLevel level, string format, params object[] args)
        {
            string msg = format;

            if (args.Length > 0)
            {
                msg = String.Format(format, args);
            }
            var rec = new LogMessageRecord {
                Category = category, Message = msg, Level = level
            };

            logger?.LogMessage(rec);
            return(rec);
        }
Пример #7
0
        private void Consumer_OnMessage(object sender, Message <string, string> msg)
        {
            var messageObject = JsonHelperSerialiser.FromJson <T>(msg.Value, JsonHelperSerialiserSettings.CamelCaseSerialiseSettings);

            OnMessage(messageObject);
            var committedOffsets = consumer.CommitAsync(msg).ConfigureAwait(false).GetAwaiter().GetResult();             // synchronously waits for message to be produced.

            var messageToLog = new AllsaintsMessageLogger.LogMessage()
            {
                Id           = messageObject.Id,
                DateStampUtc = messageObject.DateStampUtc,
                IsTest       = messageObject.IsTest,
                Message      = messageObject,
            };

            _messageLogger.LogMessage(EventTypes.Reveived, _processor, messageToLog);
        }
Пример #8
0
 public static LogMessageRecord Error(this IMessageLogger logger, string message, params object[] args)
 {
     return(logger.LogMessage(LogLevel.Error, String.Format(message, args)));
 }
Пример #9
0
 public static LogMessageRecord Error(this IMessageLogger logger, string message)
 {
     return(logger.LogMessage(LogLevel.Error, message));
 }
Пример #10
0
 public static LogMessageRecord Warning(this IMessageLogger logger, string message)
 {
     return(logger.LogMessage(LogLevel.Warning, message));
 }
Пример #11
0
 public static LogMessageRecord Info(this IMessageLogger logger, string message)
 {
     return(logger.LogMessage(LogLevel.Information, message));
 }
Пример #12
0
 public static LogMessageRecord Trace(this IMessageLogger logger, string message)
 {
     return(logger.LogMessage(LogLevel.Trace, message));
 }
Пример #13
0
 public static LogMessageRecord LogMessageEx(this IMessageLogger logger, LogMessageRecord rec)
 {
     logger.LogMessage(rec);
     return(rec);
 }