Skip to content

Commit

Permalink
Merge pull request #144 from datalust/dev
Browse files Browse the repository at this point in the history
2020.2 Release
  • Loading branch information
nblumhardt authored Aug 20, 2020
2 parents e95266e + 090743c commit 5701d46
Show file tree
Hide file tree
Showing 26 changed files with 774 additions and 52 deletions.
2 changes: 1 addition & 1 deletion Build.Docker.ps1
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
$IsCIBuild = $null -ne $env:APPVEYOR_BUILD_NUMBER
$IsPublishedBuild = ($env:APPVEYOR_REPO_BRANCH -eq "master" -or $env:APPVEYOR_REPO_BRANCH -eq "dev") -and $null -eq $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH
$IsPublishedBuild = ($env:APPVEYOR_REPO_BRANCH -eq "main" -or $env:APPVEYOR_REPO_BRANCH -eq "dev") -and $null -eq $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH

$version = @{ $true = $env:APPVEYOR_BUILD_VERSION; $false = "99.99.99" }[$env:APPVEYOR_BUILD_VERSION -ne $NULL];
$framework = "netcoreapp3.1"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ There are three kinds of matchers:
| `level` | A logging level name | `INF` |
| `line` | Any single-line content | `one line!` |
| `n` | A newline character or sequence | |
| `nat` | A nonzero number | `123` |
| `nat` | A nonnegative number | `123` |
| `s` | One or more space or tab characters | ` ` |
| `serilogdt` | A datetime in the default Serilog file logging format | `2020-01-28 13:50:01.123 +10:00` |
| `syslogdt` | A datetime in syslog format | `Dec 8 09:12:13` |
Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version: 2020.1.{build}
version: 2020.2.{build}
skip_tags: true
image:
- Visual Studio 2019
Expand Down Expand Up @@ -32,7 +32,7 @@ for:
artifact: /seqcli-.*\.(zip|tar\.gz)/
tag: v$(appveyor_build_version)
on:
branch: master
branch: main
-
matrix:
only:
Expand Down
3 changes: 3 additions & 0 deletions seqcli.sln.DotSettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/UserDictionary/Words/=apikey/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=appinstance/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=BASEURI/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Camelize/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=cmds/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=command_0027s/@EntryIndexedValue">True</s:Boolean>
Expand All @@ -13,6 +15,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Serilog/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=serilogdt/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=STDIN/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=STORAGEPATH/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=subcommand/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=syslogdt/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Tokenizes/@EntryIndexedValue">True</s:Boolean>
Expand Down
11 changes: 6 additions & 5 deletions src/SeqCli/Apps/AppLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace SeqCli.Apps
{

class AppLoader : IDisposable
{
readonly string _packageBinaryPath;
Expand Down Expand Up @@ -70,7 +69,7 @@ public bool TryLoadSeqAppType(string seqAppTypeName, out Type seqAppType)
}
}

if (seqAppType == null)
if (seqAppType == null && seqAppTypeName != null)
seqAppType = Type.GetType(seqAppTypeName);

return seqAppType != null;
Expand All @@ -85,13 +84,13 @@ IEnumerable<Assembly> LoadPackageAssemblies()
var fn = Path.GetFileNameWithoutExtension(assemblyFile);

if (_contracts
.Any(hosted => hosted.GetName().Name.Equals(fn, StringComparison.OrdinalIgnoreCase)))
.Any(hosted => hosted.GetName().Name!.Equals(fn, StringComparison.OrdinalIgnoreCase)))
continue;

try
{
var assembly = Assembly.LoadFrom(assemblyFile);
loaded.Add(assembly.FullName, assembly);
loaded.Add(assembly.FullName!, assembly);
}
// ReSharper disable once EmptyGeneralCatchClause
catch
Expand All @@ -104,11 +103,13 @@ IEnumerable<Assembly> LoadPackageAssemblies()

Assembly OnAssemblyResolve(object _, ResolveEventArgs e)
{
if (e.Name == null) return null;

var target = new AssemblyName(e.Name);

foreach (var contract in _contracts)
{
if (contract.GetName().Name.Equals(target.Name))
if (contract.GetName().Name!.Equals(target.Name))
return contract;
}

Expand Down
31 changes: 31 additions & 0 deletions src/SeqCli/Apps/Definitions/AppDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2020 Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.Collections.Generic;

namespace SeqCli.Apps.Definitions
{
// ReSharper disable all
class AppDefinition
{
public string Name { get; set; }
public string Description { get; set; }
public bool AllowReprocessing { get; set; }
public string Executable { get; set; }
public string Arguments { get; set; }
public List<string> Capabilities { get; set; } = new List<string>();
public Dictionary<string, AppPlatformDefinition> Platform { get; set; }
public Dictionary<string, AppSettingDefinition> Settings { get; set; }
}
}
112 changes: 112 additions & 0 deletions src/SeqCli/Apps/Definitions/AppMetadataReader.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
// Copyright 2020 Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using Seq.Apps;

namespace SeqCli.Apps.Definitions
{
static class AppMetadataReader
{
public static AppDefinition ReadFromSeqAppType(Type seqAppType)
{
if (seqAppType == null) throw new ArgumentNullException(nameof(seqAppType));

var declared = seqAppType.GetCustomAttribute<SeqAppAttribute>();
if (declared == null)
throw new ArgumentException($"The provided type '{seqAppType}' is not marked with [SeqApp].");

var app = new AppDefinition
{
Name = declared.Name,
Description = declared.Description,
AllowReprocessing = declared.AllowReprocessing,
Settings = GetAvailableSettings(seqAppType),
Capabilities = GetCapabilities(seqAppType),
Platform = new Dictionary<string, AppPlatformDefinition>
{
["hosted-dotnet"] = new AppPlatformDefinition
{
SeqAppTypeName = seqAppType.FullName
}
}
};

return app;
}

static List<string> GetCapabilities(Type mainReactorType)
{
var caps = new List<string>();
if (typeof(IPublishJson).IsAssignableFrom(mainReactorType))
caps.Add("input");
return caps;
}

static Dictionary<string, AppSettingDefinition> GetAvailableSettings(Type mainReactorType)
{
var properties = mainReactorType.GetProperties(BindingFlags.Public | BindingFlags.Instance);
return properties
.Select(pi => new { pi, attr = pi.GetCustomAttribute<SeqAppSettingAttribute>() })
.Where(p => p.attr != null)
.ToDictionary(
p => p.pi.Name,
p => new AppSettingDefinition
{
DisplayName = p.attr.DisplayName,
IsOptional = p.attr.IsOptional,
HelpText = p.attr.HelpText,
InputType = p.attr.InputType == SettingInputType.Unspecified ?
GetSettingType(p.pi.PropertyType) :
(AppSettingType)Enum.Parse(typeof(AppSettingType), p.attr.InputType.ToString()),
IsInvocationParameter = p.attr.IsInvocationParameter
});
}

static readonly HashSet<Type> IntegerTypes = new HashSet<Type>
{
typeof(short), typeof(short?), typeof(ushort), typeof(ushort?),
typeof(int), typeof(int?), typeof(uint), typeof(uint?),
typeof(long), typeof(long?), typeof(ulong), typeof(ulong?)
};

static readonly HashSet<Type> DecimalTypes = new HashSet<Type>
{
typeof(float), typeof(double), typeof(decimal),
typeof(float?), typeof(double?), typeof(decimal?)
};

static readonly HashSet<Type> BooleanTypes = new HashSet<Type>
{
typeof(bool), typeof(bool?)
};

static AppSettingType GetSettingType(Type type)
{
if (IntegerTypes.Contains(type))
return AppSettingType.Integer;

if (DecimalTypes.Contains(type))
return AppSettingType.Decimal;

if (BooleanTypes.Contains(type))
return AppSettingType.Checkbox;

return AppSettingType.Text;
}
}
}
29 changes: 29 additions & 0 deletions src/SeqCli/Apps/Definitions/AppPlatformDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2020 Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using Newtonsoft.Json;

namespace SeqCli.Apps.Definitions
{
// ReSharper disable all
class AppPlatformDefinition
{
public string Executable { get; set; }
public string Arguments { get; set; }

// The generic host for assembly-based apps uses this.
[JsonProperty(DefaultValueHandling = DefaultValueHandling.Ignore)]
public string SeqAppTypeName { get; set; }
}
}
26 changes: 26 additions & 0 deletions src/SeqCli/Apps/Definitions/AppSettingDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright 2020 Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace SeqCli.Apps.Definitions
{
// ReSharper disable all
class AppSettingDefinition
{
public string DisplayName { get; set; }
public string HelpText { get; set; }
public bool IsOptional { get; set; }
public AppSettingType InputType { get; set; }
public bool IsInvocationParameter { get; set; }
}
}
30 changes: 30 additions & 0 deletions src/SeqCli/Apps/Definitions/AppSettingType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright 2020 Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

namespace SeqCli.Apps.Definitions
{
// Matches https://github.com/datalust/seq-apps-runtime/blob/dev/src/Seq.Apps/Apps/SettingInputType.cs
public enum AppSettingType
{
Text,
LongText,
Checkbox,
Integer,
Decimal,
Password,

// Unused; required for (very early) legacy app support.
Number = 1000
}
}
51 changes: 51 additions & 0 deletions src/SeqCli/Apps/Definitions/PackageInterrogator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright 2020 Datalust Pty Ltd and Contributors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Serialization;
using SeqCli.Apps.Hosting;

namespace SeqCli.Apps.Definitions
{
static class PackageInterrogator
{
public static string FindAppConfiguration(string path, string mainAppTypeName, bool formatIndented)
{
using var appLoader = new AppLoader(path);
if (appLoader.TryLoadSeqAppType(mainAppTypeName, out var reactorType))
{
var json = new StringWriter();
var serializer = JsonSerializer.Create(
new JsonSerializerSettings
{
Formatting = formatIndented ? Formatting.Indented : Formatting.None,
ContractResolver = new CamelCasePropertyNamesContractResolver
{
NamingStrategy = new CamelCaseNamingStrategy { ProcessDictionaryKeys = false }
},
Converters =
{
new StringEnumConverter(new CamelCaseNamingStrategy())
}
});

serializer.Serialize(json, AppMetadataReader.ReadFromSeqAppType(reactorType));
return json.ToString();
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

// ReSharper disable SuspiciousTypeConversion.Global

namespace SeqCli.Apps
namespace SeqCli.Apps.Hosting
{
class AppContainer : IAppHost, IDisposable
{
Expand Down
Loading

0 comments on commit 5701d46

Please sign in to comment.