diff --git a/LICENSE b/LICENSE index 261eeb9..c897155 100644 --- a/LICENSE +++ b/LICENSE @@ -186,7 +186,7 @@ same "printed page" as the copyright notice for easier identification within third-party archives. - Copyright [yyyy] [name of copyright owner] + Copyright (2012-2023) G-Labs (https://github.com/genielabs) Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/MIG/Gateways/Defs.cs b/MIG/Gateways/Defs.cs index c5ea353..f57c740 100644 --- a/MIG/Gateways/Defs.cs +++ b/MIG/Gateways/Defs.cs @@ -54,6 +54,7 @@ public static class WebSocketGatewayOptions public const string Authentication = "Authentication"; public const string AuthenticationRealm = "AuthenticationRealm"; public const string IgnoreExtensions = "IgnoreExtensions"; + public const string MessagePack = "MessagePack"; } public static class TcpSocketGatewayOptions diff --git a/MIG/Gateways/WebServiceGateway.cs b/MIG/Gateways/WebServiceGateway.cs index d54ef77..9e81b43 100644 --- a/MIG/Gateways/WebServiceGateway.cs +++ b/MIG/Gateways/WebServiceGateway.cs @@ -516,71 +516,11 @@ private void Worker(object state) WebFile webFile = GetWebFile(requestedFile); response.ContentEncoding = webFile.Encoding; response.ContentType += "; charset=" + webFile.Encoding.BodyName; - // We don't need to parse the content again if it's coming from the cache - if (!webFile.IsCached) - { - string body = webFile.Content; - if (requestedFile.EndsWith(".md")) - { - // Built-in Markdown files support - body = CommonMarkConverter.Convert(body); - // TODO: add a way to include HTML header and footer template to be appended to the - // TODO: translated markdown text - } - else - { - // HTML file - // replace prepocessor directives with values - bool tagFound; - do - { - tagFound = false; - int ts = body.IndexOf("{include "); - if (ts >= 0) - { - int te = body.IndexOf("}", ts); - if (te > ts) - { - string rs = body.Substring(ts + (te - ts) + 1); - string cs = body.Substring(ts, te - ts + 1); - string ls = body.Substring(0, ts); - // - try - { - if (cs.StartsWith("{include ")) - { - string fileName = cs.Substring(9).TrimEnd('}').Trim(); - fileName = GetWebFilePath(fileName); - // - Encoding fileEncoding = DetectWebFileEncoding(fileName); - if (fileEncoding == null) - fileEncoding = defaultWebFileEncoding; - var incFile = File.ReadAllText(fileName, fileEncoding) + rs; - body = ls + incFile; - } - } - catch - { - body = ls + "
Error processing '" + cs.Replace("{", "[").Replace("}", "]") + "'
" + rs; - } - tagFound = true; - } - } - } while (tagFound); // continue if a pre processor tag was found - // {hostos} - body = body.Replace("{hostos}", Environment.OSVersion.Platform.ToString()); - // {filebase} - body = body.Replace("{filebase}", Path.GetFileNameWithoutExtension(requestedFile)); - } - // update the cache content with parsing results - webFile.Content = body; - } // Store the cache item if the file cache is enabled if (enableFileCache) { UpdateWebFileCache(requestedFile, webFile.Content, response.ContentEncoding); } - // WebServiceUtility.WriteStringToContext(context, webFile.Content); } catch (Exception ex) diff --git a/MIG/Gateways/WebSocketGateway.cs b/MIG/Gateways/WebSocketGateway.cs index d340dd1..49e3630 100644 --- a/MIG/Gateways/WebSocketGateway.cs +++ b/MIG/Gateways/WebSocketGateway.cs @@ -23,10 +23,8 @@ limitations under the License. using System; using System.Collections.Generic; -using System.Linq; using MIG.Config; using MIG.Gateways.Authentication; - using WebSocketSharp; using WebSocketSharp.Net; using WebSocketSharp.Server; @@ -77,6 +75,7 @@ public class WebSocketGateway : IMigGateway private string authenticationSchema = WebAuthenticationSchema.None; private string authenticationRealm = "MIG Secure Zone"; private bool ignoreExtensions = false; + private bool messagePack = false; public WebSocketGateway() { @@ -103,6 +102,9 @@ public void OnSetOption(Option option) case WebSocketGatewayOptions.IgnoreExtensions: bool.TryParse(option.Value, out ignoreExtensions); break; + case WebSocketGatewayOptions.MessagePack: + bool.TryParse(option.Value, out messagePack); + break; } } @@ -113,7 +115,17 @@ public void OnInterfacePropertyChanged(object sender, InterfacePropertyChangedEv WebSocketServiceHost host; webSocketServer.WebSocketServices.TryGetServiceHost("/events", out host); if (host == null) return; - host.Sessions.BroadcastAsync(MigService.JsonSerialize(args.EventData), () => {}); + + if (messagePack) + { + //var lz4Options = MessagePackSerializerOptions.Standard.WithCompression(MessagePackCompression.Lz4BlockArray); + //byte[] eventBytes = MessagePackSerializer.Serialize(args.EventData, lz4Options); + host.Sessions.BroadcastAsync(MigService.Pack(args.EventData), () => {}); + } + else + { + host.Sessions.BroadcastAsync(MigService.JsonSerialize(args.EventData), () => {}); + } } } diff --git a/MIG/MIG.csproj b/MIG/MIG.csproj index ec9a750..302a611 100644 --- a/MIG/MIG.csproj +++ b/MIG/MIG.csproj @@ -14,7 +14,6 @@ - README.md @@ -22,6 +21,8 @@ + + diff --git a/MIG/MIG.nuspec b/MIG/MIG.nuspec deleted file mode 100644 index 1466e18..0000000 --- a/MIG/MIG.nuspec +++ /dev/null @@ -1,28 +0,0 @@ - - - - MIG - $version$ - MIG Service - Generoso Martello - G-Labs - https://github.com/genielabs/mig-service-dotnet/blob/master/LICENSE - https://github.com/genielabs/mig-service-dotnet/ - false - MIG is a .Net library providing an integrated solution for developing multi-protocol networked applications and real time web applications. - MIG Service (.NET / Mono) - - G-Labs - web gateway middleware multi-protocol networking interoperability - - - - - - - - - - - - diff --git a/MIG/MigEvent.cs b/MIG/MigEvent.cs index a7e3e4e..354a13a 100644 --- a/MIG/MigEvent.cs +++ b/MIG/MigEvent.cs @@ -22,15 +22,18 @@ limitations under the License. */ using System; +using MessagePack; namespace MIG { - [Serializable()] + [Serializable, MessagePackObject] public class MigEvent { + [Key(0)] public DateTime Timestamp { get; set; } + [Key(1)] public double UnixTimestamp { get @@ -40,12 +43,20 @@ public double UnixTimestamp } } - public string Domain { get; } - public string Source { get; } - public string Description { get; } - public string Property { get; } + [Key(2)] + public string Domain { get; init; } + [Key(3)] + public string Source { get; init; } + [Key(4)] + public string Description { get; init; } + [Key(5)] + public string Property { get; init; } + [Key(6)] public object Value { get; set; } + public MigEvent() + { + } public MigEvent(string domain, string source, string description, string propertyPath, object propertyValue) { Timestamp = DateTime.UtcNow; @@ -60,10 +71,9 @@ public override string ToString() { //string date = this.Timestamp.ToLocalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffffffzzz"); //string logentrytxt = date + "\t" + this.Domain + "\t" + this.Source + "\t" + (this.Description == "" ? "-" : this.Description) + "\t" + this.Property + "\t" + this.Value; - string logentrytxt = this.Domain + "\t" + this.Source + "\t" + (this.Description == "" ? "-" : this.Description) + "\t" + this.Property + "\t" + this.Value; - return logentrytxt; + string logEntryTxt = Domain + "\t" + Source + "\t" + (Description == "" ? "-" : Description) + "\t" + Property + "\t" + Value; + return logEntryTxt; } } } - diff --git a/MIG/MigService.cs b/MIG/MigService.cs index 6cc846e..9329509 100644 --- a/MIG/MigService.cs +++ b/MIG/MigService.cs @@ -27,6 +27,7 @@ limitations under the License. using System.Linq; using NLog; using System.Reflection; +using MessagePack; using MIG.Config; using Gateway = MIG.Config.Gateway; @@ -446,6 +447,16 @@ public static string JsonSerialize(object data, bool indent = false) return Utility.Serialization.JsonSerialize(data, indent); } + public static byte[] Pack(MigEvent e) + { + return MessagePackSerializer.Serialize(e); + } + + public static MigEvent Unpack(byte[] data) + { + return MessagePackSerializer.Deserialize(data, MessagePackSerializerOptions.Standard); + } + public static void ShellCommand(string command, string args) { var processInfo = new System.Diagnostics.ProcessStartInfo(command, args); diff --git a/MIG/packages.config b/MIG/packages.config deleted file mode 100644 index f4678e2..0000000 --- a/MIG/packages.config +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - diff --git a/appveyor.yml b/appveyor.yml index e3afcf9..0efe27c 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,8 +13,6 @@ test: after_test: - ps: .\MIG\nuget_pack.ps1 artifacts: - - path: .\MIG\bin\Debug\MIG.dll - name: MIG - path: '*.nupkg' name: MIG nupkg deploy: