Selaa lähdekoodia

Merge remote-tracking branch 'origin/frank' into kenric

Kenric Nugteren 2 vuotta sitten
vanhempi
commit
cc7e33801a

+ 69 - 25
InABox.Mobile/Shared/MobileUtils.cs

@@ -73,13 +73,14 @@ namespace InABox.Mobile
                     SecureStorage.SetAsync(GlobalVariables.CachePasswordString, App.Settings.Password);
 
                 if (App.DBSettings.URLs.Count() > 0)
-                    SecureStorage.SetAsync(GlobalVariables.CacheSettingsURL1, App.DBSettings.URLs[0]);
-
-                if (App.DBSettings.URLs.Count() > 1)
-                    SecureStorage.SetAsync(GlobalVariables.CacheSettingsURL2, App.DBSettings.URLs[1]);
-
-                if (App.DBSettings.URLs.Count() > 2)
-                    SecureStorage.SetAsync(GlobalVariables.CacheSettingsURL3, App.DBSettings.URLs[2]);
+                {
+                    int count = 0;
+                    foreach (string url in App.DBSettings.URLs)
+                    {
+                        SecureStorage.SetAsync(GlobalVariables.CacheSettingsURL + count, url);
+                        count++;
+                    }
+                }
             }
             catch { }
         }
@@ -88,33 +89,76 @@ namespace InABox.Mobile
         {
             try
             {
-                var s = Encryption.Decrypt(GlobalVariables.LoadFromLinkString, "logindetailslink");
-                var array = s.Split(',');
-                DateTime expiry = DateTime.Parse(array[4]);
-                if (DateTime.Now.Subtract(expiry) < new TimeSpan(0, 5, 0))
+                var arr = GetArray();
+                var array = arr.Item1;
+                var s = arr.Item2;
+                if (!CheckExpiry(array))
                 {
-                    App.Settings.URL = array[0];
-                    App.Settings.Port = int.Parse(array[1]);
-                    App.Settings.UserID = array[2];
-                    App.Settings.Password = array[3];
-                    ClientFactory.InvalidateUser();
-                    new LocalConfiguration<ConnectionSettings>().Delete();
-                    new LocalConfiguration<ConnectionSettings>().Save(App.Settings);
-                    App.Settings = new LocalConfiguration<ConnectionSettings>().Load();
-                    if (App.Current.Properties.ContainsKey("SessionID"))
-                        App.Current.Properties.Remove("SessionID");
-                    MobileUtils.SaveToSecureStorage();
-                }
-                else
                     GlobalVariables.LoadFromLinkString = "Link has expired";
+                    return;
+                }
+
+                SetDBSettings(array, s);
+                SaveSettings();
+                RemoveSessionID();
+                PingAndSetClient();
             }
             catch (Exception e)
             {
-                if (String.IsNullOrWhiteSpace(App.Settings.URL))
+                if (String.IsNullOrWhiteSpace(App.DBSettings.URLs[0]))
                     LoadDemoSettings(App.DBSettings);
             }
         }
 
+        private static void PingAndSetClient()
+        {
+            var result = JsonClient<User>.Ping(App.DBSettings.URLs, out DatabaseInfo info);
+
+            ClientFactory.SetClientType(typeof(JsonClient<>), "TimeBench", MobileUtils.AppVersion.InstalledVersionNumber + App.DeviceString, result, true);
+        }
+
+        private static Tuple<string[], string> GetArray()
+        {
+            var s = Encryption.Decrypt(GlobalVariables.LoadFromLinkString, "logindetailslink");
+            var index = s.IndexOf("ENDURLS");
+            var substring = s.Substring(index + 8, s.Length - index - 8);
+            return new Tuple<string[], string>(substring.Split(","), s);
+        }
+
+        private static bool CheckExpiry(string[] array)
+        {
+            DateTime expiry = DateTime.Parse(array[2]);
+            if (DateTime.Now.Subtract(expiry) < new TimeSpan(0, 5, 0))
+                return true;
+            else
+                return false;
+        }
+
+        private static void SetDBSettings(string[] array, string s)
+        {
+            var urls = s.Substring(0, s.IndexOf("ENDURLS") - 1);
+            App.DBSettings.URLs = urls.Split(",");
+            App.DBSettings.UserID = array[0];
+            App.DBSettings.Password = array[1];
+        }
+
+        private static void SaveSettings()
+        {
+            ClientFactory.InvalidateUser();
+            new LocalConfiguration<DatabaseSettings>().Delete();
+            new LocalConfiguration<DatabaseSettings>().Save(App.DBSettings);
+            App.DBSettings = new LocalConfiguration<DatabaseSettings>().Load();
+            GlobalVariables.ChangeUser = true;
+
+            SaveToSecureStorage();
+        }
+
+        private static void RemoveSessionID()
+        {
+            if (App.Current.Properties.ContainsKey("SessionID"))
+                App.Current.Properties.Remove("SessionID");
+        }
+
         public static void LoadDemoSettings(DatabaseSettings settings)
         {
             List<string> list = new List<string>();

+ 1 - 1
InABox.Server/Rest/RestListener.cs

@@ -572,7 +572,7 @@ namespace InABox.API
             host = Host.Create();
 
             host.Handler(new RestHandlerBuilder(notifier?.Port))
-                .Defaults();
+                .Defaults().Backlog(1024);
         }
     }
 }

+ 68 - 18
inabox.wpf/DigitalForms/Designer/Controls/Fields/DFVideoControl.cs

@@ -1,12 +1,16 @@
 using InABox.Core;
 using InABox.WPF;
+using Microsoft.Win32;
+using Syncfusion.XPS;
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Media;
 
 namespace InABox.DynamicGrid
 {
@@ -14,21 +18,24 @@ namespace InABox.DynamicGrid
     {
         Button PlayButton;
         Button PauseButton;
+        Button DownloadButton;
         MediaElement Player;
+        Grid grid;
+        Point center;
+        int rotation = 90;
         bool firstPlay = true;
 
         byte[]? Data;
 
         protected override FrameworkElement Create()
         {
-            var grid = new Grid();
+            grid = new Grid();
 
             grid.ColumnDefinitions.Add(new ColumnDefinition { Width = GridLength.Auto });
             grid.ColumnDefinitions.Add(new ColumnDefinition { Width = new GridLength(1, GridUnitType.Star) });
 
-            grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
             grid.RowDefinitions.Add(new RowDefinition { Height = new GridLength(1, GridUnitType.Star) });
-
+            grid.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto });
 
             PlayButton = new Button
             {
@@ -42,51 +49,94 @@ namespace InABox.DynamicGrid
                 Source = Wpf.Resources.play_button.AsBitmapImage(),
             };
             PlayButton.Click += PlayButton_Click;
-            PlayButton.SetGridPosition(0, 0);
 
             PauseButton = new Button
             {
                 Width = 25,
                 Height = 25,
-                Margin = new Thickness(5),
-                Visibility = Visibility.Hidden
+                Margin = new Thickness(5)
             };
             PauseButton.Content = new Image
             {
-                Source = Wpf.Resources.pause_button.AsBitmapImage()
+                Source = Wpf.Resources.pause_button.AsBitmapImage(),
             };
             PauseButton.Click += PauseButton_Click;
-            PauseButton.SetGridPosition(0, 0);
+
+            DownloadButton = new Button
+            {
+                Width = 25,
+                Height = 25,
+                Margin = new Thickness(5)
+            };
+            DownloadButton.Content = new Image
+            {
+                Source = Wpf.Resources.download.AsBitmapImage(),
+            };
+            DownloadButton.Click += DownloadButton_Click;
+
+            StackPanel panel = new StackPanel();
+            panel.Orientation = Orientation.Horizontal;
+            panel.Children.Add(PlayButton);
+            panel.Children.Add(PauseButton);
+            panel.Children.Add(DownloadButton);
+            panel.HorizontalAlignment = HorizontalAlignment.Center;
+            panel.SetGridPosition(1, 0, 1, 2);
 
             Player = new MediaElement();
             Player.Stretch = System.Windows.Media.Stretch.Fill;
             Player.Visibility = Visibility.Visible;
-            Player.SetGridPosition(1, 0, 1, 2);
+            Player.VerticalAlignment = VerticalAlignment.Center;
+            Player.HorizontalAlignment = HorizontalAlignment.Center;
+            Player.SetGridPosition(0, 0, 1, 2);
+            Player.LoadedBehavior = MediaState.Manual;
 
-            grid.Children.Add(PlayButton);
-            grid.Children.Add(PauseButton);
+            grid.Children.Add(panel);
             grid.Children.Add(Player);
 
             return grid;
         }
 
+        private void DownloadButton_Click(object sender, RoutedEventArgs e)
+        {
+            var dlg = new SaveFileDialog();
+            dlg.AddExtension = true;
+            dlg.DefaultExt = ".mp4";
+            dlg.ShowDialog();
+            if (!string.IsNullOrWhiteSpace(dlg.FileName))
+            {
+                System.IO.File.WriteAllBytes(dlg.FileName, GetValue());
+                MessageBox.Show("Success - file saved to: "
+                    + System.Environment.NewLine
+                    + dlg.FileName);
+
+                var dir = System.IO.Path.GetDirectoryName(dlg.FileName);
+
+                ProcessStartInfo startInfo = new ProcessStartInfo
+                {
+                    Arguments = dir,
+                    FileName = "explorer.exe"
+                };
+                Process.Start(startInfo);
+            }
+        }
+
+        private void PauseButton_Click(object sender, RoutedEventArgs e)
+        {
+            Player.Pause();
+        }
+
         private void PlayButton_Click(object sender, RoutedEventArgs e)
         {
             var path = System.IO.Path.GetTempFileName();
             path = path.Substring(0, path.Length - 4) + ".mp4";
 
             System.IO.File.WriteAllBytes(path, GetValue());
+
             Player.Source = new Uri(path);
 
-            firstPlay = false;
+            Player.Play();
         }
 
-        private void PauseButton_Click(object sender, RoutedEventArgs e)
-        {
-            Player.Pause();
-            PauseButton.Visibility = Visibility.Hidden;
-            PlayButton.Visibility = Visibility.Visible;
-        }
 
         public override byte[] GetValue()
         {