Browse Source

Tweaks for SocketTransport Settings

Frank van den Bos 2 years ago
parent
commit
7852f2bcb2

+ 1 - 1
InABox.Client.RPC/Transports/Socket/RPCClientSocketTransport.cs

@@ -48,7 +48,7 @@ namespace InABox.Rpc
             var socket = new WebSocket($"{(secure ? "wss" : "ws")}://{_url}");            
             
             // Time to wait before disconnect - the default meant that the client disconnected during debugging, since the ping would fail
-            socket.WaitTime = TimeSpan.FromMinutes(10);
+            socket.WaitTime = TimeSpan.FromSeconds(5);
             
             socket.Connect();
             if (socket.ReadyState == WebSocketState.Open)

+ 1 - 0
InABox.Mobile/Shared/InABox.Mobile.Shared.projitems

@@ -15,6 +15,7 @@
     <Compile Include="$(MSBuildThisFileDirectory)IDeviceID.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)DropDownMenuCommand.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)ISettings.cs" />
+    <Compile Include="$(MSBuildThisFileDirectory)MobileLogging.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)MobileUtils.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)HideableToolbarItem.cs" />
     <Compile Include="$(MSBuildThisFileDirectory)WrapLayout.cs" />

+ 93 - 0
InABox.Mobile/Shared/MobileLogging.cs

@@ -0,0 +1,93 @@
+using System;
+using System.IO;
+using Serilog;
+using Serilog.Core;
+using Xamarin.Forms;
+
+namespace InABox.Mobile
+{
+    public enum LogType
+    {
+        Query,
+        Save,
+        Delete,
+        Validate,
+        UIUpdate,
+        BackgroundProcess
+    }
+    
+    public static class MobileLogging
+    {
+
+        private static Logger _logger = null;
+
+        private static string _logfilenameincludingpath;
+        
+        private static void CheckLogger()
+        {
+            if (_logger == null)
+            {
+                var libraryPath = Device.RuntimePlatform.Equals(Device.iOS)
+                    ? Environment.GetFolderPath(Environment.SpecialFolder.Resources)
+                    : Environment.GetFolderPath(Environment.SpecialFolder.Personal);
+
+
+                var filename = $"{DateTime.Today:yyyy-MMM-dd}.prsmobile";
+                _logfilenameincludingpath = Path.Combine(libraryPath, filename);
+                
+                var files = Directory.GetFiles(libraryPath, "*.prsmobile");
+                foreach (var file in files)
+                {
+                    if (!String.Equals(filename.ToUpper(), Path.GetFileName(file).ToUpper()))
+                        File.Delete(file);
+                }
+
+                _logger = new LoggerConfiguration()
+                    .WriteTo.File(_logfilenameincludingpath)
+                    .CreateLogger();
+            }
+        }
+        
+        public static void Log(LogType type, string entitytype, string message, string page)
+        {
+            CheckLogger();
+            System.Diagnostics.Debug.WriteLine($"[Log] {message}");
+            Console.WriteLine($"[Log] {message}");
+            _logger.Information("{Type} {Entity} {Message} {Page}", type, entitytype, message, page);
+        }
+        
+        public static void Log(string message)
+        {
+            CheckLogger();
+            System.Diagnostics.Debug.WriteLine($"[Log] {message}");
+            Console.WriteLine($"[Log] {message}");
+            _logger.Information("{Log}", message);
+        }
+
+        public static void Log(Exception exception, String tag = "")
+        {
+            CheckLogger();
+            if (String.IsNullOrWhiteSpace(tag))
+                _logger.Error("{Message} {StackTrace}",exception.Message, exception.StackTrace);
+            else
+                _logger.Error("{Tag} {Message} {StackTrace}", tag, exception.Message, exception.StackTrace);
+        }
+
+        public static void Clear()
+        {
+            CheckLogger();
+            File.WriteAllText(_logfilenameincludingpath,"");
+        }
+
+        public static String ReadLog()
+        {
+            CheckLogger();
+            return File.Exists(_logfilenameincludingpath)
+                ? File.ReadAllText(_logfilenameincludingpath)
+                : "";
+        }
+        
+        
+    }
+
+}

+ 1 - 0
InABox.RPC.Shared/Commands/Save/RpcSaveParameters.cs

@@ -15,6 +15,7 @@ namespace InABox.Rpc
         public RpcSaveParameters()
         {
             Items = Array.Empty<Entity>();
+            AuditNote = "";
         }
         
         public void SerializeBinary(CoreBinaryWriter writer)

+ 2 - 1
InABox.RPC.Shared/Commands/Save/RpcSaveResult.cs

@@ -25,7 +25,8 @@ namespace InABox.Rpc
                 foreach (var (key, value) in delta)
                 {
                     writer.Write(key);
-                    writer.WriteBinaryValue(value);
+                    var prop = CoreUtils.GetProperty(Type, key);
+                    writer.WriteBinaryValue(prop.PropertyType, value);
                 }
             }
         }