Example #1
0
        static void MakeParameters(
            string query,
            DateTime rangeStartUtc,
            DateTime?rangeEndUtc,
            SignalExpressionPart signal,
            SignalEntity unsavedSignal,
            TimeSpan?timeout,
            out SignalEntity body,
            out Dictionary <string, object> parameters)
        {
            parameters = new Dictionary <string, object>
            {
                { "q", query },
                { nameof(rangeStartUtc), rangeStartUtc }
            };

            if (rangeEndUtc != null)
            {
                parameters.Add(nameof(rangeEndUtc), rangeEndUtc.Value);
            }
            if (signal != null)
            {
                parameters.Add(nameof(signal), signal.ToString());
            }
            if (timeout != null)
            {
                parameters.Add("timeoutMS", timeout.Value.TotalMilliseconds.ToString("0"));
            }

            body = unsavedSignal ?? new SignalEntity();
        }
Example #2
0
        public async Task <ResultSetPart> DeleteInSignalAsync(
            SignalEntity signal   = null,
            string[] intersectIds = null,
            string filter         = null,
            DateTime?fromDateUtc  = null,
            DateTime?toDateUtc    = null)
        {
            var parameters = new Dictionary <string, object>();

            if (intersectIds != null && intersectIds.Length > 0)
            {
                parameters.Add("intersectIds", string.Join(",", intersectIds));
            }
            if (filter != null)
            {
                parameters.Add("filter", filter);
            }
            if (fromDateUtc != null)
            {
                parameters.Add("fromDateUtc", fromDateUtc.Value);
            }
            if (toDateUtc != null)
            {
                parameters.Add("toDateUtc", toDateUtc.Value);
            }

            var body = signal ?? new SignalEntity();

            return(await GroupPostAsync <SignalEntity, ResultSetPart>("DeleteInSignal", body, parameters).ConfigureAwait(false));
        }
        /// <summary>
        /// Delete matching events from the stream.
        /// </summary>
        /// <param name="unsavedSignal">A constructed signal that may not appear on the server, for example, a <see cref="SignalEntity"/> that has been
        /// created but not saved, a signal from another server, or the modified representation of an entity already persisted.</param>
        /// <param name="signal">If provided, a signal expression describing the set of events that will be filtered for the result.</param>
        /// <param name="filter">A strict Seq filter expression to match (text expressions must be in double quotes). To
        /// convert a "fuzzy" filter into a strict one the way the Seq UI does, use connection.Expressions.ToStrictAsync().</param>
        /// <param name="fromDateUtc">Earliest (inclusive) date/time from which to delete.</param>
        /// <param name="toDateUtc">Latest (exclusive) date/time from which to delete.</param>
        /// <returns>A result carrying the count of events deleted.</returns>
        public async Task <DeleteResultPart> DeleteInSignalAsync(
            SignalEntity unsavedSignal  = null,
            SignalExpressionPart signal = null,
            string filter        = null,
            DateTime?fromDateUtc = null,
            DateTime?toDateUtc   = null)
        {
            var parameters = new Dictionary <string, object>();

            if (signal != null)
            {
                parameters.Add("signal", signal.ToString());
            }
            if (filter != null)
            {
                parameters.Add("filter", filter);
            }
            if (fromDateUtc != null)
            {
                parameters.Add("fromDateUtc", fromDateUtc.Value);
            }
            if (toDateUtc != null)
            {
                parameters.Add("toDateUtc", toDateUtc.Value);
            }

            var body = unsavedSignal ?? new SignalEntity();

            return(await GroupDeleteAsync <SignalEntity, DeleteResultPart>("DeleteInSignal", body, parameters).ConfigureAwait(false));
        }
Example #4
0
        /// <summary>
        /// Retrieve a list of events that match a set of conditions. The complete result is buffered into memory,
        /// so if a large result set is expected, use InSignalAsync() and lastReadEventId to page the results.
        /// </summary>
        /// <param name="unsavedSignal">A constructed signal that may not appear on the server, for example, a <see cref="SignalEntity"/> that has been
        /// created but not saved, a signal from another server, or the modified representation of an entity already persisted.</param>
        /// <param name="signal">If provided, a signal expression describing the set of events that will be filtered for the result.</param>
        /// <param name="filter">A strict Seq filter expression to match (text expressions must be in double quotes). To
        /// convert a "fuzzy" filter into a strict one the way the Seq UI does, use connection.Expressions.ToStrictAsync().</param>
        /// <param name="count">The number of events to retrieve. If not specified will default to 30.</param>
        /// <param name="startAtId">An event id from which to start searching (inclusively).</param>
        /// <param name="afterId">An event id to search after (exclusively).</param>
        /// <param name="render">If specified, the event's message template and properties will be rendered into its RenderedMessage property.</param>
        /// <param name="fromDateUtc">Earliest (inclusive) date/time from which to search.</param>
        /// <param name="toDateUtc">Latest (exclusive) date/time from which to search.</param>
        /// <param name="shortCircuitAfter">If specified, the number of events after the first match to keep searching before a partial
        /// result set is returned. Used to improve responsiveness when the result is displayed in a user interface, not typically used in
        /// batch processing scenarios.</param>
        /// <param name="permalinkId">If the request is for a permalinked event, specifying the id of the permalink here will
        /// allow events that have otherwise been deleted to be found. The special value `"unknown"` provides backwards compatibility
        /// with versions prior to 5.0, which did not mark permalinks explicitly.</param>
        /// <param name="cancellationToken">Token through which the operation can be cancelled.</param>
        /// <returns>The complete list of events, ordered from least to most recent.</returns>
        public async Task <ResultSetPart> InSignalAsync(
            SignalEntity unsavedSignal  = null,
            SignalExpressionPart signal = null,
            string filter         = null,
            int count             = 30,
            string startAtId      = null,
            string afterId        = null,
            bool render           = false,
            DateTime?fromDateUtc  = null,
            DateTime?toDateUtc    = null,
            int?shortCircuitAfter = null,
            string permalinkId    = null,
            CancellationToken cancellationToken = default)
        {
            var parameters = new Dictionary <string, object> {
                { "count", count }
            };

            if (signal != null)
            {
                parameters.Add("signal", signal.ToString());
            }
            if (filter != null)
            {
                parameters.Add("filter", filter);
            }
            if (startAtId != null)
            {
                parameters.Add("startAtId", startAtId);
            }
            if (afterId != null)
            {
                parameters.Add("afterId", afterId);
            }
            if (render)
            {
                parameters.Add("render", true);
            }
            if (fromDateUtc != null)
            {
                parameters.Add("fromDateUtc", fromDateUtc.Value);
            }
            if (toDateUtc != null)
            {
                parameters.Add("toDateUtc", toDateUtc.Value);
            }
            if (shortCircuitAfter != null)
            {
                parameters.Add("shortCircuitAfter", shortCircuitAfter.Value);
            }
            if (permalinkId != null)
            {
                parameters.Add("permalinkId", permalinkId);
            }

            var body = unsavedSignal ?? new SignalEntity();

            return(await GroupPostAsync <SignalEntity, ResultSetPart>("InSignal", body, parameters, cancellationToken).ConfigureAwait(false));
        }
Example #5
0
        public static async Task CreateSignal(string signalName)
        {
            SignalEntity signal = await _seqConnection.Signals.TemplateAsync();

            signal.Title = signalName;

            if (applyChanges)
            {
                await _seqConnection.Signals.AddAsync(signal);
            }
        }
Example #6
0
 /// <summary>
 /// Execute an SQL query and retrieve the result set as a structured <see cref="QueryResultPart"/>.
 /// </summary>
 /// <param name="query">The query to execute.</param>
 /// <param name="rangeStartUtc">The earliest timestamp from which to include events in the query result.</param>
 /// <param name="rangeEndUtc">The exclusive latest timestamp to which events are included in the query result. The default is the current time.</param>
 /// <param name="signal">A signal expression over which the query will be executed.</param>
 /// <param name="unsavedSignal">A constructed signal that may not appear on the server, for example, a <see cref="SignalEntity"/> that has been
 /// created but not saved, a signal from another server, or the modified representation of an entity already persisted.</param>
 /// <param name="timeout">The query timeout; if not specified, the query will run until completion.</param>
 /// <returns>A structured result set.</returns>
 public async Task <QueryResultPart> QueryAsync(
     string query,
     DateTime rangeStartUtc,
     DateTime?rangeEndUtc        = null,
     SignalExpressionPart signal = null,
     SignalEntity unsavedSignal  = null,
     TimeSpan?timeout            = null)
 {
     MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, unsavedSignal, timeout, out var body, out var parameters);
     return(await GroupPostAsync <SignalEntity, QueryResultPart>("Query", body, parameters).ConfigureAwait(false));
 }
Example #7
0
 /// <summary>
 /// Execute an SQL query and retrieve the result set as a structured <see cref="QueryResultPart"/>.
 /// </summary>
 /// <param name="query">The query to execute.</param>
 /// <param name="rangeStartUtc">The earliest timestamp from which to include events in the query result.</param>
 /// <param name="rangeEndUtc">The exclusive latest timestamp to which events are included in the query result. The default is the current time.</param>
 /// <param name="signal">A signal expression over which the query will be executed.</param>
 /// <param name="unsavedSignal">A constructed signal that may not appear on the server, for example, a <see cref="SignalEntity"/> that has been
 /// created but not saved, a signal from another server, or the modified representation of an entity already persisted.</param>
 /// <param name="timeout">The query timeout; if not specified, the query will run until completion.</param>
 /// <returns>A CSV result set.</returns>
 public async Task <string> QueryCsvAsync(
     string query,
     DateTime rangeStartUtc,
     DateTime?rangeEndUtc        = null,
     SignalExpressionPart signal = null,
     SignalEntity unsavedSignal  = null,
     TimeSpan?timeout            = null)
 {
     MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, unsavedSignal, timeout, out var body, out var parameters);
     parameters.Add("format", "text/csv");
     return(await GroupPostReadStringAsync("Query", body, parameters).ConfigureAwait(false));
 }
Example #8
0
        public async Task <ResultSetPart> InSignalAsync(
            SignalEntity signal   = null,
            string[] intersectIds = null,
            string filter         = null,
            int count             = 30,
            string startAtId      = null,
            string afterId        = null,
            bool render           = false,
            DateTime?fromDateUtc  = null,
            DateTime?toDateUtc    = null,
            int?shortCircuitAfter = null)
        {
            var parameters = new Dictionary <string, object> {
                { "count", count }
            };

            if (intersectIds != null && intersectIds.Length > 0)
            {
                parameters.Add("intersectIds", string.Join(",", intersectIds));
            }
            if (filter != null)
            {
                parameters.Add("filter", filter);
            }
            if (startAtId != null)
            {
                parameters.Add("startAtId", startAtId);
            }
            if (afterId != null)
            {
                parameters.Add("afterId", afterId);
            }
            if (render)
            {
                parameters.Add("render", true);
            }
            if (fromDateUtc != null)
            {
                parameters.Add("fromDateUtc", fromDateUtc.Value);
            }
            if (toDateUtc != null)
            {
                parameters.Add("toDateUtc", toDateUtc.Value);
            }
            if (shortCircuitAfter != null)
            {
                parameters.Add("shortCircuitAfter", shortCircuitAfter.Value);
            }

            var body = signal ?? new SignalEntity();

            return(await GroupPostAsync <SignalEntity, ResultSetPart>("InSignal", body, parameters).ConfigureAwait(false));
        }
Example #9
0
        public async Task <QueryResultPart> QueryAsync(
            string query,
            DateTime rangeStartUtc,
            DateTime?rangeEndUtc  = null,
            SignalEntity signal   = null,
            string[] intersectIds = null)
        {
            SignalEntity body;
            Dictionary <string, object> parameters;

            MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, intersectIds, out body, out parameters);
            return(await GroupPostAsync <SignalEntity, QueryResultPart>("Query", body, parameters).ConfigureAwait(false));
        }
Example #10
0
        public async Task <string> QueryCsvAsync(
            string query,
            DateTime rangeStartUtc,
            DateTime?rangeEndUtc  = null,
            SignalEntity signal   = null,
            string[] intersectIds = null)
        {
            SignalEntity body;
            Dictionary <string, object> parameters;

            MakeParameters(query, rangeStartUtc, rangeEndUtc, signal, intersectIds, out body, out parameters);
            parameters.Add("format", "text/csv");
            return(await GroupPostReadStringAsync("Query", body, parameters).ConfigureAwait(false));
        }
Example #11
0
        static async Task <string> QueryAsync(
            SeqConnection connection,
            string query,
            DateTime?rangeStartUtc,
            DateTime?rangeEndUtc,
            SignalExpressionPart signalExpression,
            int?timeoutMS,
            string format = null)
        {
            // From dates should no longer be mandatory for QueryCsvAsync (issue raised)

            var parameters = new Dictionary <string, object>
            {
                ["q"] = query
            };

            if (format != null)
            {
                parameters.Add(nameof(format), format);
            }
            if (rangeStartUtc.HasValue)
            {
                parameters.Add(nameof(rangeEndUtc), rangeStartUtc.Value);
            }
            if (rangeEndUtc.HasValue)
            {
                parameters.Add(nameof(rangeEndUtc), rangeEndUtc.Value);
            }
            if (signalExpression != null)
            {
                parameters.Add("signal", signalExpression.ToString());
            }
            if (timeoutMS.HasValue)
            {
                parameters.Add("timeoutMS", timeoutMS.Value.ToString("0"));
            }
            var body = new SignalEntity();

            var drg = await connection.LoadResourceGroupAsync("Data");

            return(await connection.Client.PostReadStringAsync(drg, "Query", body, parameters));
        }
Example #12
0
        static void MakeParameters(string query, DateTime rangeStartUtc, DateTime?rangeEndUtc, SignalEntity signal,
                                   string[] intersectIds, out SignalEntity body, out Dictionary <string, object> parameters)
        {
            parameters = new Dictionary <string, object>
            {
                { "q", query },
                { nameof(rangeStartUtc), rangeStartUtc }
            };

            if (rangeEndUtc != null)
            {
                parameters.Add(nameof(rangeEndUtc), rangeEndUtc.Value);
            }
            if (intersectIds != null && intersectIds.Length > 0)
            {
                parameters.Add(nameof(intersectIds), string.Join(",", intersectIds));
            }

            body = signal ?? new SignalEntity();
        }
Example #13
0
 /// <summary>
 /// Remove an existing signal.
 /// </summary>
 /// <param name="entity">The signal to remove.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param>
 /// <returns>A task indicating completion.</returns>
 public async Task RemoveAsync(SignalEntity entity, CancellationToken cancellationToken = default)
 {
     await Client.DeleteAsync(entity, "Self", entity, cancellationToken : cancellationToken).ConfigureAwait(false);
 }
Example #14
0
 public async Task <SignalEntity> AddAsync(SignalEntity entity)
 {
     return(await Client.PostAsync <SignalEntity, SignalEntity>(entity, "Create", entity).ConfigureAwait(false));
 }
Example #15
0
        public static async Task DeleteSignal()
        {
            SignalEntity signal = await _seqConnection.Signals.FindAsync("signal-XXXX");

            await _seqConnection.Signals.RemoveAsync(signal);
        }
 public async Task <SignalEntity> AddAsync(SignalEntity entity)
 {
     return(await GroupCreateAsync <SignalEntity, SignalEntity>(entity).ConfigureAwait(false));
 }
 public async Task RemoveAsync(SignalEntity entity)
 {
     await Client.DeleteAsync(entity, "Self", entity).ConfigureAwait(false);
 }
 public async Task UpdateAsync(SignalEntity entity)
 {
     await Client.PutAsync(entity, "Self", entity).ConfigureAwait(false);
 }
Example #19
0
 /// <summary>
 /// Add a new signal.
 /// </summary>
 /// <param name="entity">The signal to add.</param>
 /// <param name="cancellationToken">A <see cref="CancellationToken"/> allowing the operation to be canceled.</param>
 /// <returns>The signal, with server-allocated properties such as <see cref="Entity.Id"/> initialized.</returns>
 public async Task <SignalEntity> AddAsync(SignalEntity entity, CancellationToken cancellationToken = default)
 {
     return(await GroupCreateAsync <SignalEntity, SignalEntity>(entity, cancellationToken : cancellationToken).ConfigureAwait(false));
 }