-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #144 from datalust/dev
2020.2 Release
- Loading branch information
Showing
26 changed files
with
774 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.