Esempio n. 1
0
 /// <summary>
 /// Converts the <see cref="DateTime"/> to a date stamp <c>(100000000000000 - yyyyMMddHHmmss)</c>.
 /// </summary>
 /// <param name="value">
 /// The value to convert.
 /// </param>
 /// <returns>
 /// The <see cref="long"/>.
 /// </returns>
 private static long ToInverseDateStamp(DateTime value)
 {
     return(100000000000000 - DefaultFunctions.ToDateStamp(value));
 }
Esempio n. 2
0
        /// <summary>
        /// The register plugin.
        /// </summary>
        /// <param name="context">
        /// The context.
        /// </param>
        public void RegisterPlugin([NotNull] IPluginContext context)
        {
            context.FileFormats.Add(new CsvFileFormat());

            context.Functions
            .AddWithoutSideEffects("datediff", (DateDiffType type, DateTime first, DateTime second) => DefaultFunctions.DateDiff(type, first, second))
            .SetDescription("Calculates the difference between two date/times.", "The type of unit to use when calculating the difference.", "The first date/time.", "The second date/time.")
            .AddWithoutSideEffects("dateadd", (DateDiffType type, DateTime datetime, double value) => DefaultFunctions.DateAdd(type, datetime, value))
            .SetDescription("Adds an offset to the date/time.", "The type of unit to use when adding the offset.", "The date/time.", "The number of units to add.")
            .AddWithoutSideEffects("utcnow", () => DateTime.UtcNow)
            .SetDescription("Gets the current UTC time.")
            .AddWithoutSideEffects("todate", (int year, int month, int day) => new DateTime(year, month, day))
            .SetDescription("Converts a year, month and day to a date/time.", "The years.", "The months.", "The days.")
            .AddWithoutSideEffects("date", (string value) => DefaultFunctions.ParseDate(value))
            .SetDescription("Parses the date.", "The string to parse into a date")
            .AddWithoutSideEffects("date", (string value, string pattern) => DefaultFunctions.ParseDate(value, pattern))
            .SetDescription("Parses the date.", "The string to parse into a date", "The format to use")
            .AddWithoutSideEffects("now", () => DateTime.Now)
            .SetDescription("Gets the current local time.")
            .AddWithoutSideEffects("today", () => DateTime.Today)
            .SetDescription("Gets the current local time at last midnight.")
            .AddWithoutSideEffects("upper", (string value) => value.ToUpperInvariant())
            .SetDescription("Converts a string to uppercase.", "The string to convert.")
            .AddWithoutSideEffects("lower", (string value) => value.ToLowerInvariant())
            .SetDescription("Converts a string to lowercase.", "The string to convert.")
            .AddWithoutSideEffects("int", (object value) => DefaultFunctions.ToInt(value))
            .SetDescription("Converts a value to an int.", "The value to convert.")
            .AddWithoutSideEffects("float", (object value) => DefaultFunctions.ToFloat(value))
            .SetDescription("Converts a value to a float.", "The value to convert.")
            .AddWithoutSideEffects("floor", (double?value) => value == null ? null : (double?)Math.Floor(value.Value))
            .SetDescription("Returns the largest integer less than or equal to the value.", "The value.")
            .AddWithoutSideEffects("string", (object value) => (value ?? string.Empty).ToString())
            .SetDescription("Converts a value to a string.", "The value to convert.")
            .AddWithoutSideEffects("datetime", (string value) => DefaultFunctions.Parse(value))
            .SetDescription("Converts a string to a date/time.", "The value to convert.")
            .AddWithoutSideEffects("datetime", (int year, int month, int day) => new DateTime(year, month, day))
            .SetDescription("Converts a year, month and day to a date/time.", "The years.", "The months.", "The days.")
            .AddWithoutSideEffects("datetime", (int year, int month, int day, int hour, int minute, int second) => new DateTime(year, month, day, hour, minute, second))
            .SetDescription("Converts a year, month, day, hour, minute and second to a date/time.", "The years.", "The months.", "The days.", "The hours.", "The minutes.", "The seconds.")
            .AddWithoutSideEffects("isnull", (object first, object second) => first ?? second)
            .SetDescription("Returns the first value if it is not null, otherwise returns the second value.", "The first value.", "The second value.")
            .AddWithoutSideEffects("if", (bool condition, object isTrue, object isFalse) => condition ? isTrue : isFalse)
            .SetDescription("Checks the condition, and if it's true, returns the first value, otherwise the second value.", "The condition.", "The first value.", "The second value.")
            .AddWithoutSideEffects("year", (DateTime value) => value.Year)
            .SetDescription("Gets the year part of a date/time.", "The date/time.")
            .AddWithoutSideEffects("month", (DateTime value) => value.Month)
            .SetDescription("Gets the month part of a date/time.", "The date/time.")
            .AddWithoutSideEffects("day", (DateTime value) => value.Day)
            .SetDescription("Gets the day part of a date/time.", "The date/time.")
            .AddWithoutSideEffects("hour", (DateTime value) => value.Hour)
            .SetDescription("Gets the hour part of a date/time.", "The date/time.")
            .AddWithoutSideEffects("minute", (DateTime value) => value.Minute)
            .SetDescription("Gets the minute part of a date/time.", "The date/time.")
            .AddWithoutSideEffects("second", (DateTime value) => value.Second)
            .SetDescription("Gets the second part of a date/time.", "The date/time.")
            .AddWithoutSideEffects("weekday", (DateTime value) => value.DayOfWeek)
            .SetDescription("Gets the day number in the week of a date/time.", "The date/time.")
            .AddWithoutSideEffects("weekend", (DateTime value) => value.DayOfWeek == DayOfWeek.Saturday || value.DayOfWeek == DayOfWeek.Sunday)
            .SetDescription("Returns true if the date/time is in the weekend, false otherwise.", "The date/time.")
            .AddWithoutSideEffects("weeknum", (DateTime value) => DefaultFunctions.GetIso8601WeekOfYear(value))
            .SetDescription("Returns the ISO 8601 week number of the date/time.", "The date/time.")
            .AddWithoutSideEffects("localtime", (DateTime value) => (value.Kind != DateTimeKind.Local ? value.ToLocalTime() : value).ToString("o"))
            .SetDescription("Converts the date/time to local time if the date/time is universal.", "The date/time.")
            .AddWithoutSideEffects("utc", (DateTime value) => (value.Kind != DateTimeKind.Utc ? value.ToUniversalTime() : value).ToString("o"))
            .SetDescription("Converts the date/time to UTC time if the date/time is local.", "The date/time.")
            .AddWithoutSideEffects("tickstamp", (DateTime value) => DateTime.MaxValue.Ticks - value.ToUniversalTime().Ticks)
            .SetDescription("Gets the tick stamp (maximum ticks - utc time ticks) of the date/time.", "The date/time.")
            .AddWithoutSideEffects("inversetimestamp", (DateTime value) => DefaultFunctions.ToInverseDateStamp(value))
            .SetDescription("Gets the inverse time stamp (100000000000000 - YYYYMMddHHmmss) of the date/time.", "The date/time.")
            .AddWithoutSideEffects("timestamp", (DateTime value) => DefaultFunctions.ToDateStamp(value))
            .SetDescription("Gets the time stamp (YYYYMMddHHmmss) of the date/time.", "The date/time.")
            .AddWithoutSideEffects("unixtimestamp", (DateTime value) => DefaultFunctions.ToUnixTimestamp(value))
            .SetDescription("Gets the unix time stamp of the date/time.", "The date/time.")
            .AddWithoutSideEffects("avg", (IAsyncEnumerable <double?> value) => value.AverageAsync())
            .SetDescription("Gets the average of the values in a group.", "The value.")
            .AddWithoutSideEffects("sum", (IAsyncEnumerable <double?> value) => value.SumAsync())
            .SetDescription("Gets the sum of the values in a group.", "The value.")
            .AddWithoutSideEffects("min", (IAsyncEnumerable <object> value) => value.MinAsync())
            .SetDescription("Gets the minimum of the values in a group.", "The value.")
            .AddWithoutSideEffects("min", (double?first, double?second) => first != null && second != null ? Math.Min(first.Value, second.Value) : first ?? second)
            .SetDescription("Gets the minimum of two values.", "The first value.", "The second value.")
            .AddWithoutSideEffects("max", (IAsyncEnumerable <object> value) => value.MaxAsync())
            .SetDescription("Gets the maximum of the values in a group.", "The value.")
            .AddWithoutSideEffects("max", (double?first, double?second) => first != null && second != null ? Math.Max(first.Value, second.Value) : first ?? second)
            .SetDescription("Gets the maximum of two values.", "The first value.", "The second value.")
            .AddWithoutSideEffects("first", (IAsyncEnumerable <object> value) => value.FirstAsync())
            .SetDescription("Gets the first of the values in a group.", "The value.")
            .AddWithoutSideEffects("last", (IAsyncEnumerable <object> value) => value.LastAsync())
            .SetDescription("Gets the last of the values in a group.", "The value.")
            .AddWithoutSideEffects("count", (IAsyncEnumerable <object> value) => value.CountAsync())
            .SetDescription("Gets the count of the values in a group.", "The value.")
            .AddWithoutSideEffects("countdistinct", (IAsyncEnumerable <object> value) => value.Distinct().CountAsync())
            .SetDescription("Gets the count of the distinct values in a group.", "The value.")
            .AddWithoutSideEffects("join", (IAsyncEnumerable <string> value, string separator) => value.AggregateAsync(new StringBuilder(), (builder, item) => builder.Append(separator).Append(item)).ToString())
            .SetDescription("Joins the values in a group using a separator.", "The value.", "The separator.")
            .AddWithoutSideEffects("groupconcat", (IAsyncEnumerable <string> value) => value.AggregateAsync(new StringBuilder(), (sb, s) => sb.Append(s)).ToString())
            .SetDescription("Concatenates the values in a group using a separator.", "The value.")
            .AddWithoutSideEffects("time", (TimeSpan past, TimeSpan future) => new TimeDataSource(TimeDataSource.TimeOffset.Midnight, past, future, TimeSpan.FromMinutes(15)))
            .SetDescription("Creates a data source that returns rows containing a column 'Time' for every moment between past and future in intervals of 15 minutes.", "The amount of time in the past.", "The amount of time in the future.")
            .AddWithoutSideEffects("time", (TimeSpan past, TimeSpan future, TimeSpan interval) => new TimeDataSource(TimeDataSource.TimeOffset.Midnight, past, future, interval))
            .SetDescription("Creates a data source that returns rows containing a column 'Time' for every moment between past and future in the specified interval.", "The amount of time in the past.", "The amount of time in the future.", "The interval")
            .AddWithoutSideEffects("time", (TimeDataSource.TimeOffset moment, TimeSpan past, TimeSpan future, TimeSpan interval) => new TimeDataSource(moment, past, future, interval))
            .SetDescription("Creates a data source that returns rows containing a column 'Time' for every moment between past and future in the specified interval.", "The moment to calculate the times around.", "The amount of time in the past.", "The amount of time in the future.", "The interval")
            .AddWithoutSideEffects("file", (string uri) => new FileDataSource(uri))
            .SetDescription("Creates a connection to a file.", "The name of the file.")
            .AddWithoutSideEffects("file", (string uri, string encoding) => new FileDataSource(uri, Encoding.GetEncoding(encoding)))
            .SetDescription("Creates a connection to a file.", "The name of the file.", "The encoding of the file.")
            .AddWithoutSideEffects("split", (string value, string separator) => EnumerableDataSource.Create(value.Split(new[] { separator }, StringSplitOptions.None)))
            .SetDescription("Creates a data source containing a column 'Item' containing the splitted value.", "The value to split.", "The separator to use.")
            .AddWithoutSideEffects("regexreplace", (string value, string regex, string replacement) => Regex.Replace(value, regex, replacement, RegexOptions.ECMAScript))
            .SetDescription("Replaces all matches of regex in value with replacement and returns the result.", "The value.", "The regular expression to find.", "The text to replace a match with.")
            .AddWithoutSideEffects("trim", (string value) => value.Trim())
            .SetDescription("Trims whitespace of a value.", "The value.")
            .AddWithoutSideEffects("trimstart", (string value) => value.TrimStart())
            .SetDescription("Trims leading whitespace of a value.", "The value.")
            .AddWithoutSideEffects("trimend", (string value) => value.TrimEnd())
            .SetDescription("Trims trailing whitespace of a value.", "The value.")
            .AddWithoutSideEffects("triggerafter", (string jobName) => DefaultFunctions.AfterJob(jobName))
            .SetDescription("Triggers a job after the specified job.", "The name of the specified job.")
            .AddWithoutSideEffects("triggerevery", (TimeSpan interval) => DefaultFunctions.Interval(interval))
            .SetDescription("Triggers a job after every interval.", "The interval.")
            .AddWithoutSideEffects("temp", () => new TempDataSource())
            .SetDescription("Creates a temporary data source.")
            .AddWithoutSideEffects("dcast", (IAsyncEnumerable <Row> values, string columnName, string columnValue) => new DCast(values, columnName, columnValue, DCastFunction.First))
            .SetDescription("Creates a data source with value as the column name, and value as true.", "The rows", "The value to create column names from.", "The values for the column.")
            .AddWithoutSideEffects("dcast", (IAsyncEnumerable <Row> values, string columnName, string columnValue, DCastFunction function) => new DCast(values, columnName, columnValue, function))
            .SetDescription("Creates a data source with value as the column name, and value as true.", "The rows", "The value to create column names from.", "The values for the column.", "The function to use when casting multiple values.")
            .AddWithoutSideEffects("tocolumn", (string columnName) => ColumnDataSource.Create(columnName))
            .SetDescription("Creates a data source with value as the column name, and value as true.", "The value to create column names from.")
            .AddWithoutSideEffects("tocolumn", (string columnName, object columnValue) => ColumnDataSource.Create(columnName, columnValue))
            .SetDescription("Creates a data source with value as the column name, and value as true.", "The value to create column names from.", "The value to create column values from.")
            .AddWithoutSideEffects("classify", (string value, string classes, string values) => DefaultFunctions.Classify(value, classes, values, ",", null))
            .SetDescription("Looks up the value in the comma separated classes, an replaces it with the value at the same index in the comma separatored values.", "The value to look up.", "The classes, separated by commas.", "The values, separated by commas.")
            .AddWithoutSideEffects("classify", (string value, string separator, string classes, string values) => DefaultFunctions.Classify(value, classes, values, separator, null))
            .SetDescription("Looks up the value in the classes separated by separator, an replaces it with the value at the same index in the values separated by separator.", "The value to look up.", "The separator", "The classes, separated by commas.", "The values, separated by commas.")
            .AddWithoutSideEffects("classify", (string value, string separator, string classes, string values, string defaultValue) => DefaultFunctions.Classify(value, classes, values, separator, defaultValue))
            .SetDescription("Looks up the value in the classes separated by separator, an replaces it with the value at the same index in the values separated by separator. When value is not found, defaultValue is returned.", "The value to look up.", "The separator", "The classes, separated by commas.", "The values, separated by commas.", "The default value.");
        }