示例#1
0
        protected override async Task <int> Run()
        {
            var connection = _connectionFactory.Connect(_connection);

            using (var input = _fileInputFeature.OpenInput())
            {
                var line = input.ReadLine();
                while (line != null)
                {
                    if (!string.IsNullOrWhiteSpace(line))
                    {
                        // Explicitly copying fields here ensures we don't try copying links or ids; for other
                        // entity types it'll ensure we notice places that "referential integrity" has to be
                        // maintained.
                        var src  = _serializer.Deserialize <SignalEntity>(new JsonTextReader(new StringReader(line)));
                        var dest = await connection.Signals.TemplateAsync();

                        dest.Title             = src.Title;
                        dest.Description       = src.Description;
                        dest.ExplicitGroupName = src.ExplicitGroupName;
                        dest.Grouping          = src.Grouping;
                        dest.IsProtected       = src.IsProtected;
                        dest.Filters           = src.Filters;
                        dest.TaggedProperties  = src.TaggedProperties;
                        await connection.Signals.AddAsync(dest);
                    }

                    line = input.ReadLine();
                }
            }

            return(0);
        }
示例#2
0
        protected override async Task <int> Run()
        {
            try
            {
                var enrichers = new List <ILogEventEnricher>();
                foreach (var property in _properties.Properties)
                {
                    enrichers.Add(new ScalarPropertyEnricher(property.Key, property.Value));
                }

                Func <LogEvent, bool> filter = null;
                if (_filter != null)
                {
                    var expr = _filter.Replace("@Level", SurrogateLevelProperty.PropertyName);
                    var eval = FilterLanguage.CreateFilter(expr);
                    filter = evt => true.Equals(eval(evt));
                }

                using (var input = _fileInputFeature.OpenInput())
                {
                    var reader = _json ?
                                 (ILogEventReader) new JsonLogEventReader(input) :
                                 new PlainTextLogEventReader(input, _pattern);

                    return(await LogShipper.ShipEvents(
                               _connectionFactory.Connect(_connection),
                               reader,
                               enrichers,
                               _invalidDataHandlingFeature.InvalidDataHandling,
                               _sendFailureHandlingFeature.SendFailureHandling,
                               filter));
                }
            }
            catch (Exception ex)
            {
                Log.Error(ex, "Ingestion failed: {ErrorMessage}", ex.Message);
                return(1);
            }
        }
示例#3
0
        protected override async Task <int> Run()
        {
            var connection = _connectionFactory.Connect(_connection);

            using var input = _fileInputFeature.OpenInput();
            var line = await input.ReadLineAsync();

            while (line != null)
            {
                if (!string.IsNullOrWhiteSpace(line))
                {
                    // Explicitly copying fields here ensures we don't try copying links or ids; for other
                    // entity types it'll ensure we notice places that "referential integrity" has to be
                    // maintained.
                    var src = _serializer.Deserialize <SignalEntity>(new JsonTextReader(new StringReader(line)));
                    if (src == null)
                    {
                        continue;
                    }

                    SignalEntity dest;
                    if (_merge)
                    {
                        try
                        {
                            dest = await connection.Signals.FindAsync(src.Id);
                        }
                        catch (Exception)
                        {
                            dest = await connection.Signals.TemplateAsync();
                        }
                    }
                    else
                    {
                        dest = await connection.Signals.TemplateAsync();
                    }

                    dest.Title             = src.Title;
                    dest.Description       = src.Description;
                    dest.ExplicitGroupName = src.ExplicitGroupName;
                    dest.Grouping          = src.Grouping;
                    dest.IsProtected       = src.IsProtected;
                    dest.Filters           = src.Filters;
                    dest.Columns           = src.Columns;
                    dest.OwnerId           = _entityOwner.OwnerId;

                    if (_merge && dest.Id != null)
                    {
                        await connection.Signals.UpdateAsync(dest);
                    }
                    else
                    {
                        await connection.Signals.AddAsync(dest);
                    }
                }

                line = await input.ReadLineAsync();
            }

            return(0);
        }