diff --git a/BeWoLauncher/App.config b/BeWoLauncher/App.config
index 6343a5ee7..dda023709 100644
--- a/BeWoLauncher/App.config
+++ b/BeWoLauncher/App.config
@@ -32,11 +32,12 @@
-
+
+
diff --git a/BeWoLauncher/BeWoLauncher.csproj b/BeWoLauncher/BeWoLauncher.csproj
index 7e572e3d1..e14bc2029 100644
--- a/BeWoLauncher/BeWoLauncher.csproj
+++ b/BeWoLauncher/BeWoLauncher.csproj
@@ -73,6 +73,8 @@
+
+
@@ -127,7 +129,11 @@
-
+
+
+
+
+
PasswortAenderungsView.xaml
@@ -135,8 +141,6 @@
02 UpdatePage.xaml
-
-
PopUpWindow.xaml
@@ -406,5 +410,8 @@
True
+
+
+
\ No newline at end of file
diff --git a/BeWoLauncher/Components/ProfileEditView.xaml b/BeWoLauncher/Components/ProfileEditView.xaml
index 42ed8899c..55ccc6c46 100644
--- a/BeWoLauncher/Components/ProfileEditView.xaml
+++ b/BeWoLauncher/Components/ProfileEditView.xaml
@@ -43,62 +43,20 @@
-
-
-
-
-
-
-
-
+
-
-
+
+
-
+
-
-
-
diff --git a/BeWoLauncher/Components/ProfileEditView.xaml.cs b/BeWoLauncher/Components/ProfileEditView.xaml.cs
index 0a8b9b78f..78e34dbcc 100644
--- a/BeWoLauncher/Components/ProfileEditView.xaml.cs
+++ b/BeWoLauncher/Components/ProfileEditView.xaml.cs
@@ -20,26 +20,10 @@ namespace BeWoLauncher.Components
set
{
_Profiles = value;
- profileControl.ItemsSource = _Profiles;
+ profileControl.ItemsSource = value;
}
}
-
- public string NewName
- {
- get => profileNameTextBox.Text;
- set => profileNameTextBox.Text = value;
- }
- public string NewServer
- {
- get => profileServerTextBox.Text;
- set => profileServerTextBox.Text = value;
- }
- public string NewTenant
- {
- get => profileTenantBox.Text;
- set => profileTenantBox.Text = value;
- }
-
+
public ProfileEditView()
{
InitializeComponent();
@@ -48,16 +32,12 @@ namespace BeWoLauncher.Components
private void ProfileAddClick(object sender, RoutedEventArgs e)
{
- var bp = new ConnectionProfile(NewName, NewServer, NewTenant);
+ var bp = new ConnectionProfile("", string.Empty, string.Empty);
if (Profiles.Contains(bp))
return;
Profiles.Add(bp);
-
- NewName = string.Empty;
- NewServer = string.Empty;
- NewTenant = string.Empty;
}
private void ProfileDeleteClick(object sender, RoutedEventArgs e)
@@ -68,8 +48,19 @@ namespace BeWoLauncher.Components
"Löschen nicht möglich", MessageBoxButton.OK, MessageBoxImage.Warning);
return;
}
+ if(profileControl.SelectedItem is null)
+ {
+ MessageBox.Show("Wählen Sie ein Profil aus",
+ "Löschen nicht möglich", MessageBoxButton.OK);
+ return;
+ }
Profiles.Remove(profileControl.SelectedItem as ConnectionProfile);
}
+
+ private void ProfileControl_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e)
+ {
+
+ }
}
}
diff --git a/BeWoLauncher/ConnectionProfile.cs b/BeWoLauncher/ConnectionProfile.cs
index affe6485c..b0074e8c2 100644
--- a/BeWoLauncher/ConnectionProfile.cs
+++ b/BeWoLauncher/ConnectionProfile.cs
@@ -26,22 +26,23 @@ namespace BeWoLauncher
return Name;
}
- public override int GetHashCode()
- {
- String key = String.Format("{0}_{1}_{2}", Name, Server, Tenant);
- return key.GetHashCode();
- }
+ // Mistery Bug:
+ //public override int GetHashCode()
+ //{
+ // String key = String.Format("{0}_{1}_{2}", Name, Server, Tenant);
+ // return key.GetHashCode();
+ //}
- public override bool Equals(object obj)
- {
- var profile = obj as ConnectionProfile;
- if (profile == null)
- {
- return false;
- }
- String key1 = String.Format("{0}_{1}_{2}", Name, Server, Tenant);
- String key2 = String.Format("{0}_{1}_{2}", profile.Name, profile.Server, profile.Tenant);
- return key1.Equals(key2);
- }
+ //public override bool Equals(object obj)
+ //{
+ // var profile = obj as ConnectionProfile;
+ // if (profile == null)
+ // {
+ // return false;
+ // }
+ // String key1 = String.Format("{0}_{1}_{2}", Name, Server, Tenant);
+ // String key2 = String.Format("{0}_{1}_{2}", profile.Name, profile.Server, profile.Tenant);
+ // return key1.Equals(key2);
+ //}
}
}
diff --git a/BeWoLauncher/Extensions/FileExtension.cs b/BeWoLauncher/Extensions/FileExtension.cs
deleted file mode 100644
index f634a583a..000000000
--- a/BeWoLauncher/Extensions/FileExtension.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BeWoLauncher.Extensions
-{
- public static class FileExtension
- {
- public static void ClearFolder(this string path) => ClearFolder(new DirectoryInfo(path));
- public static void ClearFolder(this DirectoryInfo di)
- {
- foreach (FileInfo file in di.EnumerateFiles())
- {
- file.Delete();
- }
- foreach (DirectoryInfo dir in di.EnumerateDirectories())
- {
- dir.Delete(true);
- }
- }
- }
-}
diff --git a/BeWoLauncher/LauncherApp.xaml.cs b/BeWoLauncher/LauncherApp.xaml.cs
index c709322f2..52a52f755 100644
--- a/BeWoLauncher/LauncherApp.xaml.cs
+++ b/BeWoLauncher/LauncherApp.xaml.cs
@@ -1,5 +1,8 @@
using BeWoLauncher.Components;
+using BeWoLauncher.Logic;
using BeWoLauncher.ServiceProxy;
+using BeWoLauncher.Utils;
+using BeWoLauncher.Utils.Update;
using BeWoLauncher.WindowImp;
using BS.SharedLauncher;
using BS.SharedLauncher.Information;
@@ -33,29 +36,12 @@ namespace BeWoLauncher
{
public static string ShortVersion => "3";
public static string Version => "Version 3.0";
-
-
- public static LauncherWindow Window { get; set; }
- public static LauncherApp CurrentLauncher => Current as LauncherApp;
-
- private static Process PlanerProcess { get; set; }
- private static bool PlanerRunning
- {
- get
- {
- if (PlanerProcess is null)
- return false;
- PlanerProcess.Refresh();
- return !PlanerProcess.HasExited;
- }
- }
-
-
+
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
- CheckForOtherInstance();
+ ProcessController.CheckForOtherInstance();
// Update Server Adresses
ConnectionInformation.LauncherServerAddress = ConnectionInformation.LauncherServerAddressOrigin.ToString();
@@ -75,29 +61,12 @@ namespace BeWoLauncher
};
FrameworkElement.LanguageProperty.OverrideMetadata(typeof(FrameworkElement), new FrameworkPropertyMetadata(XmlLanguage.GetLanguage(CultureInfo.CurrentCulture.IetfLanguageTag)));
-
-
-
- //XmlDocument doc = new XmlDocument();
- //doc.Load(Path.Combine("d:/ServerBeWoDataExample", "version.config"));
-
- //var default2 = doc.SelectSingleNode("/config/default/version");
- //var defaultValue = default2.InnerXml;
- //var specific2 = doc.SelectSingleNode("/config/tenant[@id='demo3']/version");
- //var specificVersion = specific2.InnerXml;
}
- private void CheckForOtherInstance()
+
+ private void Application_Exit(object sender, ExitEventArgs e)
{
- string procName = Process.GetCurrentProcess().ProcessName;
-
- Process[] processes = Process.GetProcessesByName(procName);
-
- if (processes.Length > 1)
- {
- MessageBox.Show("BeWo Prozess läuft bereits");
- StartShutdown();
- }
+ ProcessController.KillPlanerProcess();
}
#region ShowError
@@ -109,96 +78,22 @@ namespace BeWoLauncher
}
public static void ShowError(string message, string ex, bool showDetails)
{
- if (Window is null)
+ if (ViewController.Window is null)
{
MessageBox.Show(ex, message);
}
else
{
- Window.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
- Window.ShowControlAsModalPopUp(new ExceptionMessageBox(message, ex, showDetails))));
+ ViewController.Window.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() =>
+ ViewController.Window.ShowControlAsModalPopUp(new ExceptionMessageBox(message, ex, showDetails))));
}
}
#endregion
- public static void StartBeWo()
- {
- // based on https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-use-anonymous-pipes-for-local-interprocess-communication?redirectedfrom=MSDN
- PlanerProcess = new Process();
+
- PlanerProcess.StartInfo.FileName = UpdatePathManager.GetPlanerPath();
- PlanerProcess.EnableRaisingEvents = true;
- PlanerProcess.Exited += PlanerProcess_Exit;
+
- using (AnonymousPipeServerStream pipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
- {
- PlanerProcess.StartInfo.Arguments = pipeServer.GetClientHandleAsString();
- PlanerProcess.StartInfo.UseShellExecute = false;
- PlanerProcess.Start();
-
- pipeServer.DisposeLocalCopyOfClientHandle();
-
- try
- {
- using (StreamWriter sw = new StreamWriter(pipeServer))
- {
- sw.AutoFlush = true;
-
- sw.WriteLine("C-137");
- pipeServer.WaitForPipeDrain();
-
- sw.WriteLine(ConnectionInformation.Connection.ToString());
- pipeServer.WaitForPipeDrain();
- }
- }
- catch (IOException ex)
- {
-
- }
- }
-
- Window.Hide();
- }
-
- public static void StartShutdown()
- {
- Current.Shutdown();
- }
-
- private static void PlanerProcess_Exit(object sender, EventArgs e)
- {
- // ExitCode Übersicht:
- // 100 - Nutzer hat Logout in Core gedrückt
- // 0 - Nutzer hat Fenster geschlossen
- // 1 - Proess über TaskManager gekillt
-
- if (PlanerProcess.ExitCode == 100)
- {
- CurrentLauncher.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate{
- Window.ShowLoginPage();
- Window.Show();
- });
- return;
- }
-
- CurrentLauncher.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)StartShutdown);
- }
-
- private void Application_Exit(object sender, ExitEventArgs e)
- {
- BeWo_Process_Kill();
- }
-
- private static void BeWo_Process_Kill()
- {
- foreach (var process in Process.GetProcesses())
- {
- if (process.ProcessName.Contains("BeWoPlaner"))
- {
- process.Kill();
- }
- }
- }
}
}
diff --git a/BeWoLauncher/Logic/ProcessController.cs b/BeWoLauncher/Logic/ProcessController.cs
new file mode 100644
index 000000000..7bb6cb58f
--- /dev/null
+++ b/BeWoLauncher/Logic/ProcessController.cs
@@ -0,0 +1,122 @@
+using BeWoLauncher.Utils;
+using BS.SharedLauncher.Information;
+using System;
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.IO;
+using System.IO.Pipes;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Threading;
+
+namespace BeWoLauncher.Logic
+{
+ public static class ProcessController
+ {
+ private static Process PlanerProcess { get; set; }
+
+ public static Application Current => Application.Current;
+ public static LauncherApp CurrentLauncher => Current as LauncherApp;
+
+ private static bool PlanerRunning
+ {
+ get
+ {
+ if (PlanerProcess is null)
+ return false;
+ PlanerProcess.Refresh();
+ return !PlanerProcess.HasExited;
+ }
+ }
+
+ internal static void CheckForOtherInstance()
+ {
+ string procName = Process.GetCurrentProcess().ProcessName;
+
+ Process[] processes = Process.GetProcessesByName(procName);
+
+ if (processes.Length > 1)
+ {
+ MessageBox.Show("BeWo Prozess läuft bereits");
+ StartLauncherShutdown();
+ }
+ }
+
+
+
+ internal static void StartLauncherShutdown()
+ {
+ Current.Shutdown();
+ }
+
+ internal static void StartPlanerProcess()
+ {
+ // based on https://docs.microsoft.com/en-us/dotnet/standard/io/how-to-use-anonymous-pipes-for-local-interprocess-communication?redirectedfrom=MSDN
+ PlanerProcess = new Process();
+
+ PlanerProcess.StartInfo.FileName = BeWoPaths.GetPlanerExePath();
+ PlanerProcess.EnableRaisingEvents = true;
+ PlanerProcess.Exited += PlanerProcess_Exit;
+
+ using (AnonymousPipeServerStream pipeServer = new AnonymousPipeServerStream(PipeDirection.Out, HandleInheritability.Inheritable))
+ {
+ PlanerProcess.StartInfo.Arguments = pipeServer.GetClientHandleAsString();
+ PlanerProcess.StartInfo.UseShellExecute = false;
+ PlanerProcess.Start();
+
+ pipeServer.DisposeLocalCopyOfClientHandle();
+
+ try
+ {
+ using (StreamWriter sw = new StreamWriter(pipeServer))
+ {
+ sw.AutoFlush = true;
+
+ sw.WriteLine("C-137");
+ pipeServer.WaitForPipeDrain();
+
+ sw.WriteLine(ConnectionInformation.Connection.ToString());
+ pipeServer.WaitForPipeDrain();
+ }
+ }
+ catch (IOException ex)
+ {
+
+ }
+ }
+
+ ViewController.Window.Hide();
+ }
+ internal static void KillPlanerProcess()
+ {
+ foreach (var process in Process.GetProcesses())
+ {
+ if (process.ProcessName.Contains("BeWoPlaner"))
+ {
+ process.Kill();
+ }
+ }
+ }
+
+ internal static void PlanerProcess_Exit(object sender, EventArgs e)
+ {
+ // ExitCode Übersicht:
+ // 100 - Nutzer hat Logout in Core gedrückt
+ // 0 - Nutzer hat Fenster geschlossen
+ // 1 - Proess über TaskManager gekillt
+
+ if (PlanerProcess.ExitCode == 100)
+ {
+ CurrentLauncher.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)delegate {
+ ViewController.Window.ShowLoginPage();
+ ViewController.Window.Show();
+ });
+ return;
+ }
+
+ CurrentLauncher.Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)StartLauncherShutdown);
+ }
+ }
+}
diff --git a/BeWoLauncher/Logic/ViewController.cs b/BeWoLauncher/Logic/ViewController.cs
new file mode 100644
index 000000000..1a37bf58e
--- /dev/null
+++ b/BeWoLauncher/Logic/ViewController.cs
@@ -0,0 +1,124 @@
+using BeWoLauncher.PageImp;
+using BeWoLauncher.Utils;
+using BeWoLauncher.WindowImp;
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+using System.Windows.Threading;
+
+namespace BeWoLauncher.Logic
+{
+ public enum LauncherPageType
+ {
+ Login,
+ Update
+ }
+
+ public static class ViewController
+ {
+ public static LauncherWindow Window { get; set; }
+
+ public static Dispatcher Dispatcher => Window.Dispatcher;
+
+ public static void LoginLoaded(object sender, EventArgs e)
+ {
+ var autologin = bool.TryParse(ConfigurationManager.AppSettings.Get("AutoLogin"), out bool c) && c;
+
+ if (autologin)
+ if (sender is LoginPage loginPage)
+ loginPage.ClickLogin();
+ }
+ public static void LoginSuccessful(object sender, EventArgs e)
+ {
+ #region confirm demo
+#if DEBUG
+ //if (ConnectionInformation.Tenant == "demo")
+ //{
+ // var dlg = new ConfirmDemoDialog();
+ // dlg.ShowDialog();
+ //}
+#else
+ if (ConnectionInformation.Tenant == "demo")
+ {
+ var dlg = new ConfirmDemoDialog();
+ dlg.ShowDialog();
+ }
+#endif
+ #endregion
+
+ BeWoPaths.SetAndSaveInstallLocation(((LoginPage)sender).InstallLocation);
+
+ ShowPage(LauncherPageType.Update);
+ }
+ public static void UpdateSuccessful(object sender, EventArgs e)
+ {
+ ProcessController.StartPlanerProcess();
+ }
+ public static void UpdateFailed(object sender, EventArgs e)
+ {
+ throw new NotImplementedException();
+ }
+
+ public static UserControl GetNewPage(LauncherPageType type)
+ {
+ if (type == LauncherPageType.Login)
+ {
+ var login = new LoginPage();
+
+ login.Loaded += LoginLoaded;
+ login.LoginSuccessful += LoginSuccessful;
+
+ return login;
+ }
+ else if (type == LauncherPageType.Update)
+ {
+ bool showDelay = bool.TryParse(ConfigurationManager.AppSettings.Get("ShowUpdateDelay"), out bool b) && b;
+ bool forceUpdate = bool.TryParse(ConfigurationManager.AppSettings.Get("ForceUpdate"), out bool c) && c;
+
+ var update = new UpdatePage(showDelay, forceUpdate);
+
+ update.UpdateSuccessful += UpdateSuccessful;
+ update.UpdateFailed += UpdateFailed;
+
+ return update;
+ }
+
+ throw new NotImplementedException();
+ }
+ public static void ShowPage(LauncherPageType type)
+ {
+ var page = GetNewPage(type);
+
+ Dispatcher.BeginInvoke(DispatcherPriority.Normal,
+ (Action)delegate
+ {
+ Window.rootGrid.Children.Clear();
+ Window.rootGrid.Children.Add(page);
+ });
+ }
+
+
+ //public void ShowLoginPage()
+ //{
+ // var login = new LoginPage();
+
+ // login.LoginSuccessful += FinishLogin;
+ // login.Loaded += LoadedLogin;
+
+ // ShowPage(login);
+ //}
+ //private void ShowUpdatePage()
+ //{
+ // var update = new UpdatePage(bool.TryParse(ConfigurationManager.AppSettings.Get("ShowUpdateDelay"), out bool b) && b,
+ // bool.TryParse(ConfigurationManager.AppSettings.Get("ForceUpdate"), out bool c) && c);
+
+ // update.UpdateSuccessful += FinishUpdate;
+
+ // ShowPage(update);
+ //}
+ }
+}
diff --git a/BeWoLauncher/PageImp/01 LoginPage.xaml.cs b/BeWoLauncher/PageImp/01 LoginPage.xaml.cs
index e34e47948..88c540943 100644
--- a/BeWoLauncher/PageImp/01 LoginPage.xaml.cs
+++ b/BeWoLauncher/PageImp/01 LoginPage.xaml.cs
@@ -1,7 +1,8 @@
using BeWoLauncher;
using BeWoLauncher.Components;
-using BeWoLauncher.Extensions;
using BeWoLauncher.ServiceProxy;
+using BeWoLauncher.Utils;
+using BeWoLauncher.Utils.Update;
using BeWoLauncher.WindowImp;
using BS.SharedLauncher;
@@ -73,7 +74,7 @@ namespace BeWoLauncher.PageImp
DoTooMuchInitStuffIDontHaveANameForThisMethod();
- InstallLocation = UpdatePathManager.GetInstallLocationFromSettingOrDefault();
+ InstallLocation = BeWoPaths.GetInstallLocationFromSettingOrDefault();
}
public List ProfileList { get; set; }
@@ -117,12 +118,12 @@ namespace BeWoLauncher.PageImp
public string InstallLocation {
get
{
- return UpdatePathManager.LoginUpdateLocation;
+ return BeWoPaths.LoginSelectionPlanerLocation;
}
set
{
installTextBox.Text = value;
- UpdatePathManager.LoginUpdateLocation = value;
+ BeWoPaths.LoginSelectionPlanerLocation = value;
}
}
@@ -241,6 +242,10 @@ namespace BeWoLauncher.PageImp
//BeWoProfile profile = profileSelectionComboBox.SelectedItem as BeWoProfile;
//ChangeServerAndTenant(profile);
}));
+ }
+ catch (Exception e)
+ {
+
}
finally
{
@@ -266,7 +271,8 @@ namespace BeWoLauncher.PageImp
if (result == System.Windows.Forms.DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
- UpdatePathManager.ChangeLoginSelectedLocation(fbd.SelectedPath);
+ InstallLocation = fbd.SelectedPath;
+ BeWoPaths.ChangeLoginSelectedLocation(fbd.SelectedPath);
}
}
}
@@ -1168,6 +1174,6 @@ namespace BeWoLauncher.PageImp
}
- public void StartLogin() => button_login_Click(this, new RoutedEventArgs());
+ public void ClickLogin() => button_login_Click(this, new RoutedEventArgs());
}
}
diff --git a/BeWoLauncher/PageImp/02 UpdatePage.xaml.cs b/BeWoLauncher/PageImp/02 UpdatePage.xaml.cs
index 3cbeb7421..819fb46ca 100644
--- a/BeWoLauncher/PageImp/02 UpdatePage.xaml.cs
+++ b/BeWoLauncher/PageImp/02 UpdatePage.xaml.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
+using System.Configuration;
using System.Deployment.Application;
using System.IO;
using System.Linq;
@@ -16,8 +17,9 @@ using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
-using BeWoLauncher.Extensions;
using BeWoLauncher.ServiceProxy;
+using BeWoLauncher.Utils;
+using BeWoLauncher.Utils.Update;
using BS.SharedLauncher;
using BS.SharedLauncher.DataContract;
using BS.SharedLauncher.Information;
@@ -31,7 +33,7 @@ namespace BeWoLauncher.PageImp
public partial class UpdatePage : UserControl
{
public event EventHandler UpdateSuccessful;
- public event EventHandler UpdateFinished;
+ public event EventHandler UpdateFailed;
private bool _ShowDelay;
private bool _ForceUpdate;
@@ -43,18 +45,8 @@ namespace BeWoLauncher.PageImp
_ShowDelay = showDelay;
_ForceUpdate = forceUpdate;
- UpdateFileManager.ApplyFileEventHandler += ApplyFile;
- UpdateFileManager.DownloadFileEventHandler += DownloadFile;
- }
-
- private void ApplyFile(object sender, FileEventArgs fileEventArgs)
- {
-
- }
-
- private void DownloadFile(object sender, FileEventArgs fileEventArgs)
- {
-
+ //UpdateFileManager.ApplyFileEventHandler += ApplyFile;
+ //UpdateFileManager.DownloadFileEventHandler += DownloadFile;
}
public string Message
@@ -76,35 +68,57 @@ namespace BeWoLauncher.PageImp
private async void startUpdateAsync()
{
+ //try
+ //{
+ // Message = "Update wird vorbereitet...";
+ // SubMessage = "";
+ // UpdatePathManager.GetDownloadDirInfo().ClearFolder();
+ // if (_ForceUpdate)
+ // UpdatePathManager.GetApplyDirInfo().ClearFolder();
+ // await showDelay(5000);
+
+ // Message = "Update wird heruntergeladen...";
+ // SubMessage = "";
+ // await showDelay(1000);
+
+ // //UpdateFileManager.DownloadUpdateSync();
+
+ // Message = "Update wird installiert...";
+ // await showDelay(1000);
+
+ // //await UpdateFileManager.ApplyUpdate();
+
+ // Message = "Update wurde installiert!";
+ // SubMessage = "Starte BeWoPlaner...";
+ // await showDelay(1000);
+
+ // //UpdateFileManager.UpdateData = null;
+ // UpdateSuccessful(this, new EventArgs());
+
+ // UpdatePathManager.GetDownloadDirInfo().ClearFolder();
+ // //UpdateFinished(this, null);
+ //}
+ //catch (Exception e)
+ //{
+ // Message = "Update fehlgeschlagen!";
+ // SubMessage = string.Empty;
+
+ // throw e;
+ //}
+ }
+
+ private async void startUpdateAsync2()
+ {
+ var skipLock = bool.TryParse(ConfigurationManager.AppSettings.Get("SkipLock"), out bool c) && c;
+
+
+ var manager = new UpdateFileManager();
+
+ manager.StartUpdate(skipLock);
+
try
{
- Message = "Update wird vorbereitet...";
- SubMessage = "";
- UpdatePathManager.GetDownloadDirInfo().ClearFolder();
- if (_ForceUpdate)
- UpdatePathManager.GetApplyDirInfo().ClearFolder();
- await showDelay(5000);
-
- Message = "Update wird heruntergeladen...";
- SubMessage = "";
- await showDelay(1000);
-
- //UpdateFileManager.DownloadUpdateSync();
-
- Message = "Update wird installiert...";
- await showDelay(1000);
-
- //await UpdateFileManager.ApplyUpdate();
-
- Message = "Update wurde installiert!";
- SubMessage = "Starte BeWoPlaner...";
- await showDelay(1000);
-
- //UpdateFileManager.UpdateData = null;
- UpdateSuccessful(this, new EventArgs());
-
- UpdatePathManager.GetDownloadDirInfo().ClearFolder();
- //UpdateFinished(this, null);
+
}
catch (Exception e)
{
@@ -127,7 +141,7 @@ namespace BeWoLauncher.PageImp
this.gridUpdate.Margin = new Thickness(0, top, 0, 0);
//startUpdate();
- Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (Action)startUpdateAsync);
+ Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (Action)startUpdateAsync2);
}
}
}
diff --git a/BeWoLauncher/UpdateFileManager.cs b/BeWoLauncher/UpdateFileManager.cs
deleted file mode 100644
index 5bf00745f..000000000
--- a/BeWoLauncher/UpdateFileManager.cs
+++ /dev/null
@@ -1,131 +0,0 @@
-using BeWoLauncher.Extensions;
-using BeWoLauncher.ServiceProxy;
-using BS.SharedLauncher;
-using BS.SharedLauncher.DataContract;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-
-namespace BeWoLauncher
-{
- public class FileEventArgs : EventArgs
- {
- public object File { get; set; }
- //public FileToDo ToDo { get; set; }
- }
-
- public static class UpdateFileManager
- {
- public static event EventHandler DownloadFileEventHandler;
- public static event EventHandler ApplyFileEventHandler;
-
- //public static BeWoProgramPackageDC UpdateData { get; set; }
-
- static UpdateFileManager()
- {
-
- }
-
- //public static BeWoProgramPackageDC GetLastUpdate()
- //{
- // var last = new BeWoProgramPackageDC();
-
- // last.Files = UpdatePathManager.GetApplyDirInfo().GetFiles().Select(file => new BeWoProgramFileDC(file)).ToList();
-
- // return last;
- //}
-
- //public static void DownloadUpdateSync()
- //{
- // var last = GetLastUpdate();
-
- // UpdateData = LauncherServiceFacade.DoLauncherServiceSync(x => x.Update(last));
-
- // foreach (var file in UpdateData.Files)
- // {
- // switch (file.ToDo)
- // {
- // //case FileToDo.Update:
- // //case FileToDo.Add:
- // // using (var fs = new FileStream(Path.Combine(UpdatePathManager.GetDownloadPath(), file.FileName), FileMode.Create, FileAccess.Write))
- // // {
- // // fs.Write(file.FileData, 0, file.FileData.Length);
- // // }
- // // file.FileData = null;
- // // break;
- // //case FileToDo.Remove:
- // // break;
- // //case FileToDo.Nuthing:
- // // break;
- // }
-
- // DownloadFileEventHandler(null, new FileEventArgs { ToDo = file.ToDo, File = file });
- // }
- //}
-
- public static async Task DownloadUpdateAsync()
- {
- throw new NotImplementedException("#98341345");
- //var last = GetLastUpdate();
-
- //UpdateData = LauncherServiceFacade.DoLauncherServiceSync(x => x.Update(last));
-
- //foreach (var file in UpdateData.Files)
- //{
- // switch (file.ToDo)
- // {
- // case FileToDo.Update:
- // case FileToDo.Add:
- // using (var fs = new FileStream(Path.Combine(GetDownloadPath(), file.FileName), FileMode.Create, FileAccess.Write))
- // {
- // fs.Write(file.FileData, 0, file.FileData.Length);
- // }
- // file.FileData = null;
- // break;
- // case FileToDo.Remove:
- // break;
- // case FileToDo.Nuthing:
- // break;
- // }
-
- // DownloadFileEventHandler(null, new FileEventArgs { ToDo = file.ToDo, File = file });
- //}
- }
-
- //public static async Task ApplyUpdate()
- //{
- // foreach (var file in UpdateData.Files)
- // {
- // switch (file.ToDo)
- // {
- // case FileToDo.Update:
- // case FileToDo.Add:
- // var source = Path.Combine(UpdatePathManager.GetDownloadPath(), file.FileName);
- // var dest = Path.Combine(UpdatePathManager.GetApplyPath(), file.FileName);
- // File.Delete(dest);
- // File.Copy(source, dest);
- // break;
- // case FileToDo.Remove:
- // File.Delete(Path.Combine(UpdatePathManager.GetApplyPath(), file.FileName));
- // break;
- // case FileToDo.Nuthing:
- // break;
- // }
-
- // await showDelay(50);
-
- // ApplyFileEventHandler(null, new FileEventArgs { ToDo = file.ToDo, File = file });
- // }
- //}
-
- private static async Task showDelay(int millisec)
- {
- if (true)
- await Task.Delay(millisec);
- }
- }
-}
diff --git a/BeWoLauncher/Utils/BeWoHelper.cs b/BeWoLauncher/Utils/BeWoHelper.cs
new file mode 100644
index 000000000..c6ab11472
--- /dev/null
+++ b/BeWoLauncher/Utils/BeWoHelper.cs
@@ -0,0 +1,14 @@
+using System;
+using System.Collections.Generic;
+using System.Configuration;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BeWoLauncher.Utils
+{
+ public static class BeWoHelper
+ {
+
+ }
+}
diff --git a/BeWoLauncher/UpdatePathManager.cs b/BeWoLauncher/Utils/BeWoPaths.cs
similarity index 51%
rename from BeWoLauncher/UpdatePathManager.cs
rename to BeWoLauncher/Utils/BeWoPaths.cs
index a1c681408..dd0f96e3a 100644
--- a/BeWoLauncher/UpdatePathManager.cs
+++ b/BeWoLauncher/Utils/BeWoPaths.cs
@@ -1,4 +1,5 @@
-using BeWoLauncher.Extensions;
+using BS.SharedLauncher.Extensions;
+using BS.SharedLauncher.Information;
using System;
using System.Collections.Generic;
using System.IO;
@@ -7,13 +8,16 @@ using System.Text;
using System.Threading.Tasks;
using System.Windows;
-namespace BeWoLauncher
+namespace BeWoLauncher.Utils
{
- public static class UpdatePathManager
+ public static class BeWoPaths
{
- public static string LoginUpdateLocation { get; set; }
- public static string UpdateLocation { get; private set; }
- public static DirectoryInfo UpdateDirectoryInfo { get; private set; }
+ private static readonly string planerExeName = "BeWoPlaner.exe";
+
+ //private static readonly string versionXml = "bewo.version";
+
+ public static string LoginSelectionPlanerLocation { get; set; }
+ public static string ActualPlanerLocation { get; private set; }
///
/// Holt den Install Ort aus den Properties Settings.
@@ -31,19 +35,11 @@ namespace BeWoLauncher
return installLocation;
}
- ///
- /// Speichert den aktuellen Update Path
- ///
- public static void SaveInstallLocation()
- {
- Properties.Settings.Default.InstallLocation = UpdateLocation;
- Properties.Settings.Default.Save();
- }
public static void ChangeLoginSelectedLocation(string newLocation)
{
var info = new DirectoryInfo(newLocation);
- if (LoginUpdateLocation == newLocation)
+ if (LoginSelectionPlanerLocation == newLocation)
{
return;
}
@@ -55,39 +51,39 @@ namespace BeWoLauncher
}
// Annahme: Ordner ist leer und neuer Ort
- LoginUpdateLocation.ClearFolder();
+ LoginSelectionPlanerLocation.ClearFolder();
- LoginUpdateLocation = newLocation;
+ LoginSelectionPlanerLocation = newLocation;
}
- public static void SetUpdatePath(string path)
+ public static void SetAndSaveInstallLocation(string path)
{
- UpdateLocation = path;
- UpdateDirectoryInfo = new DirectoryInfo(path);
- // GetDownloadDirInfo();
- // GetApplyDirInfo();
+ ActualPlanerLocation = path;
+
+ Properties.Settings.Default.InstallLocation = ActualPlanerLocation;
+ Properties.Settings.Default.Save();
}
- // No cache
public static string GetDownloadPath()
{
- return Path.Combine(new string[] { UpdateLocation, "download" });
- }
- public static DirectoryInfo GetDownloadDirInfo()
- {
- return Directory.CreateDirectory(GetDownloadPath());
+ return Path.Combine(new string[] { ActualPlanerLocation, "download" });
}
public static string GetApplyPath()
{
- return Path.Combine(new string[] { UpdateLocation, "local", "BeWoPlaner" });
+ return Path.Combine(new string[] { ActualPlanerLocation, "apply" });
}
- public static DirectoryInfo GetApplyDirInfo()
+ public static string GetPlanerExeName() => planerExeName;
+ public static string GetPlanerExePath()
{
- return Directory.CreateDirectory(GetApplyPath());
+ return Path.Combine(GetApplyPath(), GetPlanerExeName());
}
- public static string GetMainExeName() => "BeWoPlaner.exe";
- public static string GetPlanerPath()
+
+ public static string GetApplyPackagePath()
{
- return Path.Combine(GetApplyPath(), GetMainExeName());
+ return Path.Combine(GetApplyPath(), BeWoPathFileConfig.LatestBeWoInfo);
+ }
+ public static string GetDownloadPackagePath()
+ {
+ return Path.Combine(GetDownloadPath(), BeWoPathFileConfig.LatestBeWoInfo);
}
}
}
\ No newline at end of file
diff --git a/BeWoLauncher/Utils/Update/UpdateFileManager.cs b/BeWoLauncher/Utils/Update/UpdateFileManager.cs
new file mode 100644
index 000000000..5e0c131cc
--- /dev/null
+++ b/BeWoLauncher/Utils/Update/UpdateFileManager.cs
@@ -0,0 +1,157 @@
+using BeWoLauncher.ServiceProxy;
+using BS.SharedLauncher;
+using BS.SharedLauncher.DataContract;
+using BS.SharedLauncher.Exceptions;
+using BS.SharedLauncher.Extensions;
+using BS.SharedLauncher.Information;
+using BS.SharedLauncher.Logic;
+using BS.SharedLauncher.Update;
+using BS.SharedLauncher.Utils;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Xml.Serialization;
+
+namespace BeWoLauncher.Utils.Update
+{
+ public class UpdateFileManager
+ {
+ public DownloadPlanerRequestDC Request { get; set; }
+ public DownloadPlanerResponseDC Response { get; set; }
+ public string DownloadZipPath { get; set; }
+
+ public string DownloadFolder => BeWoPaths.GetDownloadPath();
+ public string ApplyFolder => BeWoPaths.GetApplyPath();
+
+ public UpdateFileManager()
+ {
+ Request = null;
+ Response = null;
+ }
+
+ public void StartUpdate(bool skipLock)
+ {
+ CreateUpdateRequest();
+ GetUpdateResponse();
+
+ if (!Response.HasToDo())
+ {
+ return;
+ }
+
+ if (Response.HasToDoNewZip())
+ {
+ StartDownload(skipLock);
+ }
+
+ StartApply(skipLock);
+ DownloadFolder.ClearFolder();
+ }
+
+ private void CreateUpdateRequest()
+ {
+ Request = new DownloadPlanerRequestDC();
+
+ Request.PlanerRootFolderExists = DownloadFolder.Exists();
+
+ if (Request.DownloadFolderExists = DownloadFolder.Exists())
+ if (!(Request.DownloadFolderIsEmpty = DownloadFolder.IsFolderEmpty()))
+ Request.DownloadedPackages = FileController.LoadInfos(DownloadFolder);
+
+ if (Request.ApplyFolderExists = ApplyFolder.Exists())
+ if (!(Request.ApplyFolderIsEmpty = ApplyFolder.IsFolderEmpty()))
+ if (FileController.TryGetPackageInfo(BeWoPaths.GetApplyPackagePath(), out var planer))
+ Request.ApplyPackage = planer;
+ }
+
+ private void GetUpdateResponse()
+ {
+ Response = LauncherServiceFacade.DoDownloadBeWoServiceSync(x => x.Download2(Request));
+ }
+
+ private void StartDownload(bool skiplock)
+ {
+ DownloadFolder.CreateFolder();
+
+ DownloadFolder.Lock(skiplock);
+
+ DownloadZipPath = FileController.GetNewZipPath(BeWoPaths.GetDownloadPath());
+
+ FileController.SaveDZip(DownloadZipPath, Response.NewZipData);
+ FileController.SaveInfo(DownloadZipPath, Response.NewZipInfo);
+ FileController.SaveInfo(BeWoPaths.GetDownloadPackagePath(), Response.LatestApplicationInfo);
+
+ Response.NewZipData = null;
+
+ DownloadFolder.Unlock();
+ }
+
+ private void StartApply(bool skiplock)
+ {
+ ApplyFolder.CreateFolder();
+
+ ApplyFolder.Lock(skiplock);
+
+ if (Response.HasToDoDownload2Keep())
+ {
+ FileController.ApplyDZip(Response.DownloadFilesToKeep, ApplyFolder);
+ }
+
+ if (Response.HasToDoNewZip())
+ {
+ FileController.ApplyDZip(DownloadZipPath, ApplyFolder);
+ }
+
+ if (Response.HasToRemoveFiles)
+ {
+
+ }
+
+ // Überschreibe alle lokalen Dateien mit dem Update
+ //private void ApplyDZip(string path, PlanerPackageInfoDC planer)
+ //{
+ //using (ZipArchive archive = ZipFile.OpenRead(path))
+ //{
+ // foreach (ZipArchiveEntry entry in archive.Entries)
+ // {
+ // var planerFileInfo = PlanerPackage.FindPlanerFile(entry.Name);
+
+ // entry.ExtractToFile(ApplyPath.Combine(entry.Name), true);
+ // }
+ //}
+ //}
+
+ //// Entferne alte Dateien
+ //// Überprüfe mit neuer Version Xml
+ //var applyFiles = Directory.EnumerateFileSystemEntries(ApplyPath);
+ //foreach (var file in applyFiles)
+ //{
+ // var relative = PathUtils.MakeRelativePath(ApplyPath, file);
+
+ // if (PlanerPackage.FirstOrDefaultPlanerFile(relative) is object)
+ // continue;
+
+ // if (relative == BeWoPaths.GetLockFileName())
+ // continue;
+
+ // File.Delete(file);
+ //}
+
+ //// Überschreibe Update Version
+ //File.WriteAllText(BeWoPaths.GetVersionXmlPath(), PlanerVersionXml);
+
+ ////UnlockApply();
+ ///
+
+ throw new NotImplementedException();
+ }
+
+ // RE Auslagern
+
+ }
+}
diff --git a/BeWoLauncher/WindowImp/LauncherWindow.xaml.cs b/BeWoLauncher/WindowImp/LauncherWindow.xaml.cs
index 1757c71cc..dbaaf8123 100644
--- a/BeWoLauncher/WindowImp/LauncherWindow.xaml.cs
+++ b/BeWoLauncher/WindowImp/LauncherWindow.xaml.cs
@@ -11,8 +11,11 @@ using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Threading;
using BeWoLauncher.Components;
+using BeWoLauncher.Logic;
using BeWoLauncher.PageImp;
using BeWoLauncher.ServiceProxy;
+using BeWoLauncher.Utils;
+using BeWoLauncher.Utils.Update;
using BS.SharedLauncher;
using BS.SharedLauncher.Information;
@@ -31,81 +34,17 @@ namespace BeWoLauncher.WindowImp
_ModalPopUpControls = new Stack();
- LauncherApp.Window = this;
-
- ShowLoginPage();
+ ViewController.Window = this;
- LauncherServiceFacade.DoDownloadBeWoServiceSync(x => x.Download2(new BS.SharedLauncher.DataContract.DownloadPlanerRequestDC() { }));
+ ViewController.ShowPage(LauncherPageType.Login);
+
+ // RE Test
+ // LauncherServiceFacade.DoDownloadBeWoServiceSync(x => x.Download2(new BS.SharedLauncher.DataContract.DownloadPlanerRequestDC() { }));
}
-
- public void FinishLogin(object sender, EventArgs e)
- {
-#if DEBUG
- //if (ConnectionInformation.Tenant == "demo")
- //{
- // var dlg = new ConfirmDemoDialog();
- // dlg.ShowDialog();
- //}
-#else
- if (ConnectionInformation.Tenant == "demo")
- {
- var dlg = new ConfirmDemoDialog();
- dlg.ShowDialog();
- }
-#endif
- UpdatePathManager.SetUpdatePath(((LoginPage)sender).InstallLocation);
- UpdatePathManager.SaveInstallLocation();
-
- bool useUpdater = bool.TryParse(ConfigurationManager.AppSettings.Get("UseUpdater"), out bool b) && b;
-
- if (true)
- {
- ShowUpdatePage();
- }
- else
- {
- throw new NotImplementedException();
- // LauncherApp.StartBeWo();
- }
- }
-
- public void FinishUpdate(object sender, EventArgs e)
- {
- LauncherApp.StartBeWo();
- }
-
+
private void MainWindow_OnClosing(object s, CancelEventArgs e)
{
- LauncherApp.StartShutdown();
- }
-
- private void ShowPage(UserControl page)
- {
- Dispatcher.BeginInvoke(DispatcherPriority.Normal,
- (Action)delegate
- {
- rootGrid.Children.Clear();
- rootGrid.Children.Add(page);
- });
- }
-
- public void ShowLoginPage()
- {
- var login = new LoginPage();
-
- login.LoginSuccessful += FinishLogin;
-
- ShowPage(login);
- }
-
- private void ShowUpdatePage()
- {
- var update = new UpdatePage(bool.TryParse(ConfigurationManager.AppSettings.Get("ShowUpdateDelay"), out bool b) && b,
- bool.TryParse(ConfigurationManager.AppSettings.Get("ForceUpdate"), out bool c) && c);
-
- update.UpdateSuccessful += FinishUpdate;
-
- ShowPage(update);
+ ProcessController.StartLauncherShutdown();
}
private void ShowModalBackground()
diff --git a/LauncherHost/LauncherHost.csproj.user b/LauncherHost/LauncherHost.csproj.user
index c84674ae9..f95380675 100644
--- a/LauncherHost/LauncherHost.csproj.user
+++ b/LauncherHost/LauncherHost.csproj.user
@@ -29,7 +29,7 @@
- True
+ False
True
diff --git a/Service/Service.csproj b/Service/Service.csproj
index 31bdfd8d1..474e3e899 100644
--- a/Service/Service.csproj
+++ b/Service/Service.csproj
@@ -476,8 +476,9 @@
-
-
+
+
+
@@ -516,6 +517,7 @@
+
diff --git a/Service/ServiceImplementations/DownloadBeWoServiceImp.cs b/Service/ServiceImplementations/DownloadBeWoServiceImp.cs
index 303168df7..3bffb1f04 100644
--- a/Service/ServiceImplementations/DownloadBeWoServiceImp.cs
+++ b/Service/ServiceImplementations/DownloadBeWoServiceImp.cs
@@ -8,9 +8,12 @@ using System.ServiceModel;
using System.Xml;
using BeWo.Data;
using BeWo.Service.ServiceContracts;
+using BeWo.Service.ServiceUtils.Paths;
using BeWo.Service.ServiceUtils.Update;
using BS.SharedLauncher.DataContract;
using BS.SharedLauncher.Enums;
+using BS.SharedLauncher.Extensions;
+using BS.SharedLauncher.Logic;
using BS.SharedLauncher.Update;
namespace BeWo.Service.ServiceImplementations
@@ -18,92 +21,55 @@ namespace BeWo.Service.ServiceImplementations
[ServiceBehavior(InstanceContextMode = InstanceContextMode.PerCall, ConcurrencyMode = ConcurrencyMode.Single)]
public class DownloadBeWoServiceImp : IDownloadBeWoService
{
- public UpdateConfigHelper UpdateConfigHelper { get; set; }
-
public string Tenant => MultitenancyOperationContextExt.Current.Tenant;
-
+
public DownloadPlanerResponseDC Download2(DownloadPlanerRequestDC request)
+ {
+ DownloadPlanerResponseBuilder builder = new DownloadPlanerResponseBuilder(request);
+
+ builder.Calculate(Tenant);
+
+ if (!request.ApplyFolderIsEmpty)
+ if (request.ApplyPackage is object)
+ builder.Substract(request.ApplyPackage.ToPlanerPackageInfo());
+
+ if (!request.DownloadFolderIsEmpty)
+ if (request.DownloadedPackages is object)
+ builder.AnalyseDownload(request.DownloadedPackages.ToDictionary(pair => pair.Key, pair => pair.Value.ToPlanerPackageInfo()));
+
+ return builder.CreateResponse();
+ }
+
+ public DownloadPlanerResponseDC Download2_(DownloadPlanerRequestDC request)
{
try
{
- PlanerRoot root = new PlanerRoot();
- UpdateConfigHelper = new UpdateConfigHelper(UpdatePathHelper.VersionConfigPath(), Tenant);
-
- root.DefaultVersion = UpdateConfigHelper.LoadDefaultVersion();
- root.TenantVersion = UpdateConfigHelper.LoadSpecificVersion();
-
- string version = root.CurrentVersion;
-
- // Setze Basis
- root.InitPlanerFiles(GetVersionDefaultFiles(version));
-
- // Überschreibe mit Version-Tenant Daten
- root.UpdatePlanerFiles(GetVersionTenantFiles(version, Tenant));
-
- // Überschreibe mit Special-Tenant Daten
- root.UpdatePlanerFiles(GetSpecialTenantFiles(Tenant));
-
- if (true || request.VersionXML is null)
- return Install(root);
-
- return Update(root, request.VersionXML);
}
catch (Exception e)
{
throw Core.Utils.CreateBeWoFaultException(e);
}
- }
- private List GetVersionDefaultFiles(string version) => GetPlanerFiles(UpdatePathHelper.VersionDefaultPath(version), PlanerUpdateSource.VersionDefault);
- private List GetVersionTenantFiles(string version, string tenant) => GetPlanerFiles(UpdatePathHelper.VersionTenantPath(version, tenant), PlanerUpdateSource.VersionTenant);
- private List GetSpecialTenantFiles(string tenant) => GetPlanerFiles(UpdatePathHelper.SpecialTenantPath(tenant), PlanerUpdateSource.SpecialTenant);
-
- private List GetPlanerFiles(string path, PlanerUpdateSource source)
- {
- var res = new List();
-
- if (!Directory.Exists(path))
- return res;
-
- // Sollte der Path ohne / enden, wird der unterordner mit angegeben
- // Deshalb manuell hinzufügen, falls nicht vorhanden
- if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
- path += Path.DirectorySeparatorChar;
-
- GetPlanerFilesRecursive(new DirectoryInfo(path), path, source, ref res);
- return res;
- }
- private void GetPlanerFilesRecursive(DirectoryInfo directoryInfo, string relativeTo, PlanerUpdateSource source, ref List files)
- {
- foreach (var item in directoryInfo.GetDirectories())
- {
- GetPlanerFilesRecursive(item, relativeTo, source, ref files);
- }
-
- foreach (var item in directoryInfo.GetFiles())
- {
- var file = new PlanerFile(item, relativeTo, source);
-
- files.Add(file);
- }
- }
-
- private DownloadPlanerResponseDC Install(PlanerRoot root)
- {
- var res = new DownloadPlanerResponseDC();
-
- res.VersionXML = root.GetVersionXml(Tenant);
- res.Data = root.GetData();
-
- return res;
- }
-
- private DownloadPlanerResponseDC Update(PlanerRoot newestVersion, string versionxml)
- {
return null;
}
+
+
+ //private DownloadPlanerResponseDC Install(PlanerPackageInfo root)
+ //{
+ // //PlanerPackageFactory.ConstructResponse(root, Tenant, out DownloadPlanerResponseDC response);
+
+ // //response.DownloadFilesToKeep = response.CurrentApplicationPackageInfo.Files;
+
+ // return response;
+ //}
+
+ //private DownloadPlanerResponseDC Update(PlanerPackageInfo newestVersion, string versionxml)
+ //{
+ // return null;
+ //}
+
//public BeWoProgramPackageDC Update(BeWoProgramPackageDC current)
//{
// try
diff --git a/Service/ServiceUtils/Paths/ServerFilePaths.cs b/Service/ServiceUtils/Paths/ServerFilePaths.cs
new file mode 100644
index 000000000..5794758cd
--- /dev/null
+++ b/Service/ServiceUtils/Paths/ServerFilePaths.cs
@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BeWo.Service.ServiceUtils.Paths
+{
+ public static class ServerFilePaths
+ {
+ // UpdateRootPath
+ // L specialTenant
+ // L tenant#1
+ // L exampleData#1
+ // L version
+ // L 1.0.0.0
+ // L _default
+ // L exampleData#2
+ // L tenant#1
+ // L exampleData#3
+ // L 1.0.0.1
+ // L _default
+ // L exampleData#4
+ // L tenant#1
+ // L exampleData#5
+ // L version.config
+
+ public static string UpdateRootFolderPath
+ => @"d:\Rene\ServerBeWoDataExample";
+ //=> ConfigurationManager.AppSettings.Get("UpdateRootPath");
+
+ public static string GetSpecialTenantFolderPath() => Path.Combine(UpdateRootFolderPath, "overridetenant");
+ public static string GetOverrideTenantFolderPath(string tenant) => Path.Combine(GetSpecialTenantFolderPath(), tenant);
+ public static string GetVersionFolderPath() => Path.Combine(UpdateRootFolderPath, "version");
+
+ public static string GetVersionFolderPath(string version) => Path.Combine(GetVersionFolderPath(), version);
+ public static string GetVersionTenantFolderPath(string version, string tenant) => Path.Combine(GetVersionFolderPath(version), tenant);
+ public static string GetVersionDefaultFolderPath(string version) => GetVersionTenantFolderPath(version, "default");
+
+ public static string GetVersionConfigFilePath() => Path.Combine(UpdateRootFolderPath, "update.config");
+ //ConfigurationManager.AppSettings.Get("UpdateRootPath");
+ }
+}
diff --git a/Service/ServiceUtils/Update/DownloadPlanerResponseBuilder.cs b/Service/ServiceUtils/Update/DownloadPlanerResponseBuilder.cs
new file mode 100644
index 000000000..2504b7fdb
--- /dev/null
+++ b/Service/ServiceUtils/Update/DownloadPlanerResponseBuilder.cs
@@ -0,0 +1,131 @@
+using BeWo.Service.ServiceUtils.Paths;
+using BS.SharedLauncher.DataContract;
+using BS.SharedLauncher.Extensions;
+using BS.SharedLauncher.Logic;
+using BS.SharedLauncher.Update;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BeWo.Service.ServiceUtils.Update
+{
+ public class DownloadPlanerResponseBuilder
+ {
+ private PlanerPackageInfo currentUpdatePackageInfo;
+ private PlanerPackageInfo latestUpdatePackageInfo;
+ private Dictionary> downloadFilesToKeep;
+
+ public DownloadPlanerResponseBuilder(DownloadPlanerRequestDC req)
+ {
+ currentUpdatePackageInfo = null;
+ latestUpdatePackageInfo = null;
+ downloadFilesToKeep = null;
+ }
+
+ public PlanerPackageInfo CurrentUpdatePackageInfo => currentUpdatePackageInfo;
+ public PlanerPackageInfo FullUpdatePackageInfo => latestUpdatePackageInfo;
+
+ public void Calculate(string tenant)
+ {
+ PlanerPackageInfo root = new PlanerPackageInfo();
+ UpdateConfigReader reader = new UpdateConfigReader(ServerFilePaths.GetVersionConfigFilePath(), tenant);
+
+ root.DefaultVersion = reader.GetDefaultVersion();
+ root.TenantVersion = reader.GetSpecificVersion();
+
+ string version = root.Version;
+
+ // Setze Basis
+ root.InitFiles(getVersionDefaultFiles(version));
+
+ // Überschreibe mit Version-Tenant Daten
+ root.OverrideFiles(getVersionTenantFiles(version, tenant));
+
+ // Überschreibe mit Special-Tenant Daten
+ root.OverrideFiles(getSpecialTenantFiles(tenant));
+
+ // Lade Hash Werte
+ root.LoadHash();
+
+ latestUpdatePackageInfo = root;
+ currentUpdatePackageInfo = root.Copy();
+ }
+ public void Substract(PlanerPackageInfo applyPackage)
+ {
+ currentUpdatePackageInfo.SubstractFiles(applyPackage.Files);
+ }
+ public void AnalyseDownload(Dictionary zip2info)
+ {
+ downloadFilesToKeep = new Dictionary>();
+
+ foreach (var z2i in zip2info)
+ {
+ bool found = false;
+
+ for (int i = currentUpdatePackageInfo.Files.Count - 1; i >= 0; i--)
+ //foreach (var file in currentUpdatePackageInfo.Files)
+ {
+ var file = currentUpdatePackageInfo.Files[i];
+
+ if (z2i.Value.ContainsPlanerFile(file.RelativePath, file.Checksum))
+ {
+ if (!found)
+ {
+ found = true;
+ downloadFilesToKeep.Add(z2i.Key, new List());
+ }
+
+ downloadFilesToKeep[z2i.Key].Add(file.RelativePath);
+
+ currentUpdatePackageInfo.RemoveFileAt(i);
+ }
+ }
+ }
+ }
+ public void Compress()
+ {
+ if (!downloadFilesToKeep.Any())
+ downloadFilesToKeep = null;
+
+ if (!currentUpdatePackageInfo.AnyFile())
+ currentUpdatePackageInfo = null;
+ }
+
+ public DownloadPlanerResponseDC CreateResponse()
+ {
+ var res = new DownloadPlanerResponseDC();
+
+ Compress();
+
+ res.LatestApplicationInfo = latestUpdatePackageInfo.ToPlanerPackageInfoDC();
+
+ if (downloadFilesToKeep is object)
+ {
+ res.DownloadFilesToKeep = downloadFilesToKeep;
+ }
+
+ if (currentUpdatePackageInfo is object)
+ {
+ res.NewZipData = ZipArchiveBuilder.CreateZipInMemory(currentUpdatePackageInfo.Files,
+ (file) => file.AbsolutePath, (file) => file.AbsolutePath);
+ res.NewZipInfo = currentUpdatePackageInfo.ToPlanerPackageInfoDC();
+ }
+
+ return res;
+ }
+
+ private List getVersionDefaultFiles(string version) => getPlanerFiles(ServerFilePaths.GetVersionDefaultFolderPath(version));
+ private List getVersionTenantFiles(string version, string tenant) => getPlanerFiles(ServerFilePaths.GetVersionTenantFolderPath(version, tenant));
+ private List getSpecialTenantFiles(string tenant) => getPlanerFiles(ServerFilePaths.GetOverrideTenantFolderPath(tenant));
+
+ private List getPlanerFiles(string path)
+ {
+ var res = FileController.GetPlanerFiles(path);
+
+ //res.ForEach(x => x.Source = source);
+ return res;
+ }
+ }
+}
diff --git a/Service/ServiceUtils/Update/UpdateConfigHelper.cs b/Service/ServiceUtils/Update/UpdateConfigReader.cs
similarity index 71%
rename from Service/ServiceUtils/Update/UpdateConfigHelper.cs
rename to Service/ServiceUtils/Update/UpdateConfigReader.cs
index d983ef5c3..f087451bb 100644
--- a/Service/ServiceUtils/Update/UpdateConfigHelper.cs
+++ b/Service/ServiceUtils/Update/UpdateConfigReader.cs
@@ -8,22 +8,22 @@ using System.Xml;
namespace BeWo.Service.ServiceUtils.Update
{
- public class UpdateConfigHelper
+ public class UpdateConfigReader
{
- public XmlDocument Document{ get; set; }
- public string Tenant { get; set; }
+ private XmlDocument Document{ get; set; }
+ private string Tenant { get; set; }
- public UpdateConfigHelper(string configFile, string tenant)
+ public UpdateConfigReader(string configFilePath, string tenant)
{
Document = new XmlDocument();
- Document.Load(configFile);
+ Document.Load(configFilePath);
Tenant = tenant;
}
//public PlanerUpdateSource Source => GotSpecialVersion ? PlanerUpdateSource.SpecialVersion : PlanerUpdateSource.NewestVersion;
- public string LoadSpecificVersion()
+ public string GetSpecificVersion()
{
try
{
@@ -35,7 +35,7 @@ namespace BeWo.Service.ServiceUtils.Update
}
}
- public string LoadDefaultVersion()
+ public string GetDefaultVersion()
{
return Document.SelectSingleNode("/config/default/version").InnerXml;
}
diff --git a/Service/ServiceUtils/Update/UpdatePathHelper.cs b/Service/ServiceUtils/Update/UpdatePathHelper.cs
deleted file mode 100644
index b82255104..000000000
--- a/Service/ServiceUtils/Update/UpdatePathHelper.cs
+++ /dev/null
@@ -1,45 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Configuration;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace BeWo.Service.ServiceUtils.Update
-{
- public static class UpdatePathHelper
- {
- // UpdateRootPath
- // L specialTenant
- // L tenant#1
- // L exampleData#1
- // L version
- // L 1.0.0.0
- // L _default
- // L exampleData#2
- // L tenant#1
- // L exampleData#3
- // L 1.0.0.1
- // L _default
- // L exampleData#4
- // L tenant#1
- // L exampleData#5
- // L version.config
-
- public static string UpdateRootPath
- => @"d:\ServerBeWoDataExample";
- //=> ConfigurationManager.AppSettings.Get("UpdateRootPath");
-
- public static string SpecialTenantPath() => Path.Combine(UpdateRootPath, "specialtenant");
- public static string SpecialTenantPath(string tenant) => Path.Combine(SpecialTenantPath(), tenant);
- public static string VersionPath() => Path.Combine(UpdateRootPath, "version");
- public static string VersionConfigPath() => Path.Combine(UpdateRootPath, "version.config");
-
- public static string VersionPath(string version) => Path.Combine(VersionPath(), version);
- public static string VersionTenantPath(string version, string tenant) => Path.Combine(VersionPath(version), tenant);
- public static string VersionDefaultPath(string version) => VersionTenantPath(version, "_default");
-
- //ConfigurationManager.AppSettings.Get("UpdateRootPath");
- }
-}
diff --git a/SharedLauncher/DataContract/DownloadPlanerRequestDC.cs b/SharedLauncher/DataContract/DownloadPlanerRequestDC.cs
index 2b895729c..224300699 100644
--- a/SharedLauncher/DataContract/DownloadPlanerRequestDC.cs
+++ b/SharedLauncher/DataContract/DownloadPlanerRequestDC.cs
@@ -14,10 +14,32 @@ namespace BS.SharedLauncher.DataContract
{
public DownloadPlanerRequestDC()
{
-
+ PlanerRootFolderExists = false;
+ DownloadFolderExists = false;
+ DownloadFolderIsEmpty = true;
+ ApplyFolderExists = false;
+ ApplyFolderIsEmpty = true;
}
[DataMember]
- public string VersionXML { get; set; }
+ public bool PlanerRootFolderExists { get; set; }
+
+ [DataMember]
+ public bool DownloadFolderExists { get; set; }
+
+ [DataMember]
+ public bool DownloadFolderIsEmpty { get; set; }
+
+ [DataMember]
+ public bool ApplyFolderExists { get; set; }
+
+ [DataMember]
+ public bool ApplyFolderIsEmpty { get; set; }
+
+ [DataMember]
+ public Dictionary DownloadedPackages { get; set; }
+
+ [DataMember]
+ public PlanerPackageInfoDC ApplyPackage { get; set; }
}
}
diff --git a/SharedLauncher/DataContract/DownloadPlanerResponseDC.cs b/SharedLauncher/DataContract/DownloadPlanerResponseDC.cs
index b572dbcbf..90df81684 100644
--- a/SharedLauncher/DataContract/DownloadPlanerResponseDC.cs
+++ b/SharedLauncher/DataContract/DownloadPlanerResponseDC.cs
@@ -1,25 +1,35 @@
-using System;
+using BS.SharedLauncher.Update;
+using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Threading.Tasks;
+using System.Xml.Serialization;
namespace BS.SharedLauncher.DataContract
{
[DataContract]
public class DownloadPlanerResponseDC
{
-
public DownloadPlanerResponseDC()
{
-
+ DownloadFilesToKeep = null;
}
+
+ [DataMember]
+ public bool HasToRemoveFiles { get; set; }
+
+ [DataMember]
+ public byte[] NewZipData { get; set; }
+
+ [DataMember]
+ public PlanerPackageInfoDC NewZipInfo { get; set; }
+
+ [DataMember]
+ public PlanerPackageInfoDC LatestApplicationInfo { get; set; }
[DataMember]
- public byte[] Data { get; set; }
-
- [DataMember]
- public string VersionXML { get; set; }
+ public Dictionary> DownloadFilesToKeep { get; set; }
}
}
diff --git a/SharedLauncher/DataContract/PlanerFileInfoDC.cs b/SharedLauncher/DataContract/PlanerFileInfoDC.cs
new file mode 100644
index 000000000..f0c5a5fc7
--- /dev/null
+++ b/SharedLauncher/DataContract/PlanerFileInfoDC.cs
@@ -0,0 +1,24 @@
+using BS.SharedLauncher.Enums;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace BS.SharedLauncher.DataContract
+{
+ [DataContract, Serializable()]
+ public class PlanerFileInfoDC
+ {
+ [DataMember, XmlAttribute]
+ public string Name { get; set; }
+
+ [DataMember, XmlAttribute]
+ public string RelativePath { get; set; }
+
+ [DataMember, XmlAttribute]
+ public string Checksum { get; set; }
+ }
+}
diff --git a/SharedLauncher/DataContract/PlanerPackageInfoDC.cs b/SharedLauncher/DataContract/PlanerPackageInfoDC.cs
new file mode 100644
index 000000000..8213d5031
--- /dev/null
+++ b/SharedLauncher/DataContract/PlanerPackageInfoDC.cs
@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace BS.SharedLauncher.DataContract
+{
+ [DataContract, XmlRoot("Package"), Serializable()]
+ public class PlanerPackageInfoDC
+ {
+ [DataMember]
+ public List Files { get; set; }
+
+ [DataMember]
+ public DateTime Created { get; set; }
+
+ [DataMember]
+ public string DefaultVersion { get; set; }
+
+ [DataMember]
+ public string TenantVersion { get; set; }
+
+ public string Version => TenantVersion ?? DefaultVersion;
+ }
+}
diff --git a/SharedLauncher/Exceptions/UpdateException.cs b/SharedLauncher/Exceptions/UpdateException.cs
new file mode 100644
index 000000000..ef2bcc575
--- /dev/null
+++ b/SharedLauncher/Exceptions/UpdateException.cs
@@ -0,0 +1,24 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BS.SharedLauncher.Exceptions
+{
+ [Serializable]
+ public class UpdateException : Exception
+ {
+ public UpdateException()
+ { }
+
+ public UpdateException(string message)
+ : base(message)
+ { }
+
+ public UpdateException(string message, Exception innerException)
+ : base(message, innerException)
+ { }
+
+}
+}
diff --git a/SharedLauncher/Extensions/DownloadPlanerResponseExtension.cs b/SharedLauncher/Extensions/DownloadPlanerResponseExtension.cs
new file mode 100644
index 000000000..313cf4e0c
--- /dev/null
+++ b/SharedLauncher/Extensions/DownloadPlanerResponseExtension.cs
@@ -0,0 +1,27 @@
+using BS.SharedLauncher.DataContract;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BS.SharedLauncher.Extensions
+{
+ public static class DownloadPlanerResponseExtension
+ {
+ public static bool HasToDo(this DownloadPlanerResponseDC response)
+ {
+ return response.HasToDoDownload2Keep() || response.HasToDoNewZip() || response.HasToRemoveFiles;
+ }
+
+ public static bool HasToDoDownload2Keep(this DownloadPlanerResponseDC response)
+ {
+ return response.DownloadFilesToKeep is object;
+ }
+
+ public static bool HasToDoNewZip(this DownloadPlanerResponseDC response)
+ {
+ return response.NewZipInfo is object;
+ }
+ }
+}
diff --git a/SharedLauncher/Extensions/PathExtensions.cs b/SharedLauncher/Extensions/PathExtensions.cs
new file mode 100644
index 000000000..b3999b352
--- /dev/null
+++ b/SharedLauncher/Extensions/PathExtensions.cs
@@ -0,0 +1,80 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using BS.SharedLauncher.Information;
+
+namespace BS.SharedLauncher.Extensions
+{
+ public static class PathExtensions
+ {
+ public static string Combine(this string start, string sub)
+ {
+ return Path.Combine(start, sub);
+ }
+ public static void CreateFolder(this string path)
+ {
+ Directory.CreateDirectory(path);
+ }
+ public static bool Exists(this string path)
+ {
+ try
+ {
+ FileAttributes attr = File.GetAttributes(path);
+
+ if (attr.HasFlag(FileAttributes.Directory))
+ {
+ return Directory.Exists(path);
+ }
+ return File.Exists(path);
+ }
+ catch (FileNotFoundException)
+ {
+
+ }
+ catch (DirectoryNotFoundException)
+ {
+
+ }
+ return false;
+ }
+ public static bool IsFolderEmpty(this string path)
+ {
+ return !Directory.EnumerateFileSystemEntries(path).Any();
+ }
+
+ public static void ClearFolder(this string path) => ClearFolder(new DirectoryInfo(path));
+ public static void ClearFolder(this DirectoryInfo di)
+ {
+ foreach (FileInfo file in di.EnumerateFiles())
+ {
+ file.Delete();
+ }
+ foreach (DirectoryInfo dir in di.EnumerateDirectories())
+ {
+ dir.Delete(true);
+ }
+ }
+
+ public static void Lock(this string path, bool skiplock)
+ {
+ var file = Path.Combine(path, BeWoPathFileConfig.LockFileName);
+
+ if (!skiplock && File.Exists(file))
+ throw new ArgumentException($"Lock ist bereits gesetzt", path);
+
+ using (File.Create(file));
+ }
+ public static void Unlock(this string path)
+ {
+ var file = Path.Combine(path, BeWoPathFileConfig.LockFileName);
+
+ if (!File.Exists(file))
+ throw new ArgumentException($"Unlock nicht möglich, Lock existiert nicht", path);
+
+ File.Delete(file);
+ }
+ }
+}
diff --git a/SharedLauncher/Extensions/PlanerFileExtension.cs b/SharedLauncher/Extensions/PlanerFileExtension.cs
new file mode 100644
index 000000000..16439f5eb
--- /dev/null
+++ b/SharedLauncher/Extensions/PlanerFileExtension.cs
@@ -0,0 +1,48 @@
+using BS.SharedLauncher.DataContract;
+using BS.SharedLauncher.Update;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BS.SharedLauncher.Extensions
+{
+ public static class PlanerFileExtension
+ {
+ public static List ToPlanerFileInfoDCList(this List planerFileInfos) => planerFileInfos.Select(x => new PlanerFileInfoDC()
+ {
+ Checksum = x.Checksum,
+ Name = x.Name,
+ RelativePath = x.RelativePath
+ }).ToList();
+ public static List ToPlanerFileInfoList(this List planerFileInfos) => planerFileInfos.Select(x => new PlanerFileInfo()
+ {
+ Checksum = x.Checksum,
+ Name = x.Name,
+ RelativePath = x.RelativePath
+ }).ToList();
+
+ public static void LoadHash(this PlanerFileInfo planerFileInfo)
+ {
+ //FileData = File.ReadAllBytes(AbsolutePath);
+ using (var md5 = MD5.Create())
+ {
+ using (var stream = File.OpenRead(planerFileInfo.AbsolutePath))
+ {
+ planerFileInfo.Checksum = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLowerInvariant();
+ }
+ }
+ }
+
+ public static void Copy(this PlanerFileInfo info) => new PlanerFileInfo()
+ {
+ Name = info.Name,
+ AbsolutePath = info.AbsolutePath,
+ Checksum = info.Checksum,
+ RelativePath = info.RelativePath
+ };
+ }
+}
diff --git a/SharedLauncher/Extensions/PlanerPackageExtension.cs b/SharedLauncher/Extensions/PlanerPackageExtension.cs
new file mode 100644
index 000000000..5ae44fe11
--- /dev/null
+++ b/SharedLauncher/Extensions/PlanerPackageExtension.cs
@@ -0,0 +1,101 @@
+using BS.SharedLauncher.DataContract;
+using BS.SharedLauncher.Update;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BS.SharedLauncher.Extensions
+{
+ public static class PlanerPackageExtension
+ {
+ public static PlanerPackageInfoDC ToPlanerPackageInfoDC(this PlanerPackageInfo planerFileInfo) => new PlanerPackageInfoDC()
+ {
+ Created = planerFileInfo.Created,
+ DefaultVersion = planerFileInfo.DefaultVersion,
+ Files = planerFileInfo.Files.ToPlanerFileInfoDCList(),
+ TenantVersion = planerFileInfo.TenantVersion
+ };
+ public static PlanerPackageInfo ToPlanerPackageInfo(this PlanerPackageInfoDC planerFileInfo) => new PlanerPackageInfo()
+ {
+ Created = planerFileInfo.Created,
+ DefaultVersion = planerFileInfo.DefaultVersion,
+ Files = planerFileInfo.Files.ToPlanerFileInfoList(),
+ TenantVersion = planerFileInfo.TenantVersion
+ };
+
+ public static bool ContainsPlanerFile(this PlanerPackageInfo planerPackageInfo, string rel, string checksum)
+ {
+ return planerPackageInfo.Files.FirstOrDefault(file => file.RelativePath == rel && file.Checksum == checksum) is object;
+ }
+ public static bool AnyFile(this PlanerPackageInfo planerPackageInfo)
+ {
+ if (planerPackageInfo.Files is null)
+ return false;
+
+ return planerPackageInfo.Files.Any();
+ }
+
+ public static PlanerFileInfo FindPlanerFile(this PlanerPackageInfo planerFileInfo, string relative)
+ {
+ return planerFileInfo.Files.Find(x => x.RelativePath == relative);
+ }
+ public static PlanerFileInfo FirstOrDefaultPlanerFile(this PlanerPackageInfo planerFileInfo, string relative)
+ {
+ return planerFileInfo.Files.FirstOrDefault(x => x.RelativePath == relative);
+ }
+
+ public static void InitFiles(this PlanerPackageInfo planerFileInfo, List files)
+ {
+ planerFileInfo.Files = new List();
+ planerFileInfo.Files.AddRange(files);
+ }
+ private static void OverrideFile(this PlanerPackageInfo planerFileInfo, PlanerFileInfo newFile)
+ {
+ var oldFile = planerFileInfo.FindPlanerFile(newFile.RelativePath);
+
+ oldFile.AbsolutePath = newFile.AbsolutePath;
+ //oldFile.Source = newFile.Source;
+ }
+ public static void OverrideFiles(this PlanerPackageInfo planerFileInfo, List files)
+ {
+ files.ForEach(x => planerFileInfo.OverrideFile(x));
+ }
+ public static void RemoveFile(this PlanerPackageInfo planerFileInfo, string subtrahend)
+ {
+ var minuend = planerFileInfo.FirstOrDefaultPlanerFile(subtrahend);
+
+ if (minuend is PlanerFileInfo)
+ {
+ planerFileInfo.RemoveFile(minuend);
+ }
+ }
+ public static void RemoveFile(this PlanerPackageInfo planerFileInfo, PlanerFileInfo file)
+ {
+ planerFileInfo.Files.Remove(file);
+ }
+ public static void RemoveFileAt(this PlanerPackageInfo planerFileInfo, int index)
+ {
+ planerFileInfo.Files.RemoveAt(index);
+ }
+ public static void SubstractFiles(this PlanerPackageInfo planerPackageInfo, List files)
+ {
+ files.ForEach(f => planerPackageInfo.RemoveFile(f.RelativePath));
+ }
+
+ public static void LoadHash(this PlanerPackageInfo planer) => planer.Files.ForEach(file => file.LoadHash());
+ public static PlanerPackageInfo Copy(this PlanerPackageInfo pp) => new PlanerPackageInfo()
+ {
+ Created = pp.Created,
+ DefaultVersion = pp.DefaultVersion,
+ TenantVersion = pp.TenantVersion,
+ Files = pp.Files.Select(file => file.Copy()).ToList()
+ };
+
+ public static void Apply(this PlanerPackageInfo planer)
+ {
+
+ }
+ }
+}
diff --git a/SharedLauncher/Information/BeWoPathFileConfig.cs b/SharedLauncher/Information/BeWoPathFileConfig.cs
new file mode 100644
index 000000000..e30c6f2a4
--- /dev/null
+++ b/SharedLauncher/Information/BeWoPathFileConfig.cs
@@ -0,0 +1,23 @@
+using BS.SharedLauncher.Extensions;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BS.SharedLauncher.Information
+{
+ public static class BeWoPathFileConfig
+ {
+ private static readonly string lockFileName = "_lock";
+ private static readonly string zipName = "bewo{0}.zip";
+ private static readonly string dotbewoinfo = ".bewoinfo";
+ private static readonly string latestFileName = "latest";
+
+ public static string LockFileName => lockFileName;
+ public static string ZipFormatName => zipName;
+ public static string DotBeWoInfo => dotbewoinfo;
+ public static string LatestBeWoInfo => latestFileName + DotBeWoInfo;
+ }
+}
diff --git a/SharedLauncher/LauncherEnums.cs b/SharedLauncher/LauncherEnums.cs
index 3c2f43a56..99a17e678 100644
--- a/SharedLauncher/LauncherEnums.cs
+++ b/SharedLauncher/LauncherEnums.cs
@@ -39,35 +39,36 @@ namespace BS.SharedLauncher.Enums
AreTheSame
}
- public enum PlanerUpdateSource
- {
- VersionDefault = 1,
- VersionTenant = 2,
- SpecialTenant = 3
+ //public enum PlanerUpdateSource
+ //{
+ // Invalid = 0,
+ // Version = 1,
+ // VersionTenant = 2,
+ // OverrideTenant = 3
- /////
- ///// Aus der neusten Version / Default Case
- /////
- //NewestVersion = 1,
+ // /////
+ // ///// Aus der neusten Version / Default Case
+ // /////
+ // //NewestVersion = 1,
- /////
- ///// Durch spezieller Version in version.config
- /////
- //SpecialVersion = 2,
+ // /////
+ // ///// Durch spezieller Version in version.config
+ // /////
+ // //SpecialVersion = 2,
- /////
- ///// Aus der neusten Version aus dem Version-Kunden-Ordner
- /////
- //NewestVersionTenant = 3,
+ // /////
+ // ///// Aus der neusten Version aus dem Version-Kunden-Ordner
+ // /////
+ // //NewestVersionTenant = 3,
- /////
- ///// Aus der speziellen Version aus dem Version-Kunden-Ordner
- /////
- //SpecialVersionTenant = 4,
+ // /////
+ // ///// Aus der speziellen Version aus dem Version-Kunden-Ordner
+ // /////
+ // //SpecialVersionTenant = 4,
- /////
- ///// Aus dem Kunden-Ordner
- /////
- //SpecialTenant = 5
- }
+ // /////
+ // ///// Aus dem Kunden-Ordner
+ // /////
+ // //SpecialTenant = 5
+ //}
}
diff --git a/SharedLauncher/Logic/FileController.cs b/SharedLauncher/Logic/FileController.cs
new file mode 100644
index 000000000..aee068702
--- /dev/null
+++ b/SharedLauncher/Logic/FileController.cs
@@ -0,0 +1,183 @@
+using BS.SharedLauncher.DataContract;
+using BS.SharedLauncher.Extensions;
+using BS.SharedLauncher.Information;
+using BS.SharedLauncher.Update;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BS.SharedLauncher.Logic
+{
+ public static class FileController
+ {
+ private static string ZipFormatName => BeWoPathFileConfig.ZipFormatName;
+ private static string DotBeWoInfo => BeWoPathFileConfig.DotBeWoInfo;
+
+ public static string GetDZipPath(string root, int number) => Path.Combine(root, string.Format(ZipFormatName, getFileNumberCountString(number)));
+ public static string GetDZipInfoPath(string root, int number) => GetDZipPath(root, number) + DotBeWoInfo;
+
+ public static void ApplyDZip(Dictionary> zip2keepfiles, string destinationfolder)
+ {
+ foreach (var pair in zip2keepfiles)
+ {
+ ApplyDZip(pair.Key, destinationfolder, pair.Value.Contains);
+ }
+ }
+ public static void ApplyDZip(string zipfilepath, string destinationfolder)
+ => ApplyDZip(zipfilepath, destinationfolder, (s) => true);
+ private static void ApplyDZip(string zipfilepath, string destinationfolder, Func isValidFunc)
+ {
+ using (ZipArchive archive = ZipFile.OpenRead(zipfilepath))
+ {
+ foreach (ZipArchiveEntry entry in archive.Entries)
+ {
+ if (isValidFunc(entry.Name))
+ {
+ entry.ExtractToFile(destinationfolder.Combine(entry.Name), true);
+ }
+ }
+ }
+ }
+
+ public static List GetValidDZipPaths(string path)
+ {
+ var res = new List();
+
+ var dir = new DirectoryInfo(path);
+ var files = dir.GetFiles("*.zip");
+
+ foreach (var file in files)
+ {
+ if (file.FullName.IsDZipValid())
+ res.Add(file.FullName);
+ }
+
+ return res;
+ }
+ public static string GetNewZipPath(string root)
+ {
+ int i = 0;
+ string temp = string.Empty;
+
+ do
+ {
+ temp = GetDZipPath(root, i++);
+
+ } while (temp.IsDZipValidAndDeleteIfNot());
+
+ return temp;
+ }
+ public static void SaveDZip(string path, byte[] data)
+ {
+ File.WriteAllBytes(path, data);
+ }
+ public static void SaveInfo(string path, T t)
+ where T : class
+ {
+ File.WriteAllText(path.WithInfoExtension(), XmlConverter.Serialize(t));
+ }
+ public static PlanerPackageInfoDC LoadInfo(string filepath)
+ {
+ filepath = filepath.WithInfoExtension();
+
+ var xml = File.ReadAllText(filepath);
+ var obj = XmlConverter.Deserialize(xml);
+
+ return obj;
+ }
+
+ public static bool TryGetPackageInfo(string filepath, out PlanerPackageInfoDC planerPackageInfoDC)
+ {
+ planerPackageInfoDC = null;
+
+ try
+ {
+ planerPackageInfoDC = LoadInfo(filepath);
+ }
+ catch (Exception)
+ {
+ return false;
+ }
+ return true;
+ }
+ public static Dictionary LoadInfos(string rootfolder)
+ {
+ var allDZips = GetValidDZipPaths(rootfolder);
+
+ if (allDZips is null || !allDZips.Any())
+ return null;
+
+ return allDZips.ToDictionary(dzip => dzip, dzip => LoadInfo(dzip));
+
+ // Detailed Debug Section
+ //var res = new Dictionary();
+
+ //foreach (var dzip in allDZips)
+ //{
+ // res.Add(dzip, GetPackageInfo(dzip));
+ //}
+
+ //return res;
+ }
+ public static List GetPlanerFiles(string path)
+ {
+ var res = new List();
+
+ // Sollte der Path ohne / enden, wird der unterordner mit angegeben
+ // Deshalb manuell hinzufügen, falls nicht vorhanden
+
+ if (!path.EndsWith(Path.DirectorySeparatorChar.ToString()))
+ path += Path.DirectorySeparatorChar;
+
+ getPlanerFilesRecursive(new DirectoryInfo(path), path, ref res);
+ return res;
+ }
+
+ public static bool IsDZipValidAndDeleteIfNot(this string path)
+ {
+ if (path.IsDZipValid())
+ return true;
+
+ new FileInfo(path).Delete();
+ new FileInfo(path + BeWoPathFileConfig.DotBeWoInfo).Delete();
+
+ return false;
+ }
+ public static bool IsDZipValid(this string path)
+ {
+ return path.Exists() && (path + BeWoPathFileConfig.DotBeWoInfo).Exists();
+ }
+ public static string WithInfoExtension(this string path)
+ {
+ if (path.EndsWith(DotBeWoInfo))
+ return path;
+
+ return path + DotBeWoInfo;
+ }
+
+ private static void getPlanerFilesRecursive(DirectoryInfo directoryInfo, string relativeTo, ref List files)
+ {
+ foreach (var item in directoryInfo.GetDirectories())
+ {
+ getPlanerFilesRecursive(item, relativeTo, ref files);
+ }
+
+ foreach (var item in directoryInfo.GetFiles())
+ {
+ var file = new PlanerFileInfo(item, relativeTo);
+
+ files.Add(file);
+ }
+ }
+ private static string getFileNumberCountString(int i)
+ {
+ if (i == 0)
+ return string.Empty;
+ return $"({i})";
+ }
+ }
+}
diff --git a/SharedLauncher/Logic/XmlConverter.cs b/SharedLauncher/Logic/XmlConverter.cs
new file mode 100644
index 000000000..92e29861e
--- /dev/null
+++ b/SharedLauncher/Logic/XmlConverter.cs
@@ -0,0 +1,35 @@
+using BS.SharedLauncher.DataContract;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml.Serialization;
+
+namespace BS.SharedLauncher.Logic
+{
+ public static class XmlConverter
+ {
+ public static string Serialize(T obj)
+ where T : class
+ {
+ XmlSerializer ser = new XmlSerializer(typeof(T));
+
+ using (StringWriter sw = new StringWriter())
+ {
+ ser.Serialize(sw, obj);
+ return sw.ToString();
+ }
+ }
+
+ public static T Deserialize(string input)
+ where T : class
+ {
+ XmlSerializer ser = new XmlSerializer(typeof(T));
+
+ using (StringReader sr = new StringReader(input))
+ return (T)ser.Deserialize(sr);
+ }
+ }
+}
diff --git a/SharedLauncher/Logic/ZipArchiveBuilder.cs b/SharedLauncher/Logic/ZipArchiveBuilder.cs
new file mode 100644
index 000000000..b5c6f0971
--- /dev/null
+++ b/SharedLauncher/Logic/ZipArchiveBuilder.cs
@@ -0,0 +1,35 @@
+using BS.SharedLauncher.Update;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace BS.SharedLauncher.Logic
+{
+ public static class ZipArchiveBuilder
+ {
+ public static byte[] CreateZipInMemory(List files, Func path, Func zipentryname)
+ //(PlanerPackageInfo root)
+ {
+ byte[] res = null;
+
+ using (var memoryStream = new MemoryStream())
+ {
+ using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
+ {
+ foreach (var file in files)
+ {
+ var archiveentry = archive.CreateEntryFromFile(path(file), zipentryname(file));
+ }
+ }
+
+ res = memoryStream.ToArray();
+ }
+
+ return res;
+ }
+ }
+}
diff --git a/SharedLauncher/SharedLauncher.csproj b/SharedLauncher/SharedLauncher.csproj
index 53cda2558..0959f4e00 100644
--- a/SharedLauncher/SharedLauncher.csproj
+++ b/SharedLauncher/SharedLauncher.csproj
@@ -51,10 +51,21 @@
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
diff --git a/SharedLauncher/Update/PlanerFile.cs b/SharedLauncher/Update/PlanerFile.cs
deleted file mode 100644
index 04f7d5f5f..000000000
--- a/SharedLauncher/Update/PlanerFile.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-using BS.SharedLauncher.Utils;
-using BS.SharedLauncher.Enums;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Security.Cryptography;
-using BS.SharedLauncher.Update;
-
-namespace BS.SharedLauncher.Update
-{
- public class PlanerFile
- {
- public string Name { get; set; }
- public string Extension { get; set; }
- public string AbsolutePath { get; set; }
- public string RelativePath { get; set; }
- public PlanerUpdateSource Source { get; set; }
- //public Version FileVersion { get; set; }
-
- //public byte[] FileData { get; set; }
- public string Checksum { get; set; }
-
- public PlanerFile(FileInfo fileInfo, string relativeTo, PlanerUpdateSource source)
- {
- Name = fileInfo.Name;
- Extension = fileInfo.Extension;
- AbsolutePath = fileInfo.FullName;
- RelativePath = PathUtils.MakeRelativePath(relativeTo, fileInfo.FullName);
- Source = source;
- }
-
- //public static PlanerFile Init(FileInfo fileInfo, string relativeTo, PlanerUpdateSource source)
- //{
- // var res = new PlanerFile()
- // {
- // FileSystemName = fileInfo.Name,
- // FileSystemExtension = fileInfo.Extension,
- // FileSystemAbsolutePath = fileInfo.FullName,
- // FileSystemRelativePath = PathUtils.MakeRelativePath(relativeTo, fileInfo.FullName),
- // FileSystemSource = source
- // };
-
- // return res;
- //}
-
- public void Load()
- {
- //FileData = File.ReadAllBytes(AbsolutePath);
- using (var md5 = MD5.Create())
- {
- using (var stream = File.OpenRead(AbsolutePath))
- {
- Checksum = BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLowerInvariant();
- }
- }
- }
- }
-}
diff --git a/SharedLauncher/Update/PlanerFileInfo.cs b/SharedLauncher/Update/PlanerFileInfo.cs
new file mode 100644
index 000000000..15d57d53d
--- /dev/null
+++ b/SharedLauncher/Update/PlanerFileInfo.cs
@@ -0,0 +1,45 @@
+using BS.SharedLauncher.Utils;
+using BS.SharedLauncher.Enums;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Security.Cryptography;
+using BS.SharedLauncher.Update;
+using System.Diagnostics;
+
+namespace BS.SharedLauncher.Update
+{
+ [DebuggerDisplay("{AbsolutePath}")]
+ public class PlanerFileInfo
+ {
+ public string Name { get; set; }
+ public string AbsolutePath { get; set; }
+ public string RelativePath { get; set; }
+ public string Checksum { get; set; }
+
+ public PlanerFileInfo()
+ {
+ }
+
+ public PlanerFileInfo(FileInfo fileInfo, string relativeTo) : this()
+ {
+ Name = fileInfo.Name;
+ AbsolutePath = fileInfo.FullName;
+ RelativePath = PathUtils.MakeRelativePath(relativeTo, fileInfo.FullName);
+ }
+
+ public PlanerFileInfo Copy()
+ {
+ return new PlanerFileInfo()
+ {
+ Name = Name,
+ AbsolutePath = AbsolutePath,
+ RelativePath = RelativePath,
+ Checksum = Checksum
+ };
+ }
+ }
+}
diff --git a/SharedLauncher/Update/PlanerPackageInfo.cs b/SharedLauncher/Update/PlanerPackageInfo.cs
new file mode 100644
index 000000000..64a3ec8ad
--- /dev/null
+++ b/SharedLauncher/Update/PlanerPackageInfo.cs
@@ -0,0 +1,30 @@
+using BS.SharedLauncher.Enums;
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.IO.Compression;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Xml;
+using System.Xml.Linq;
+using System.Xml.Serialization;
+
+namespace BS.SharedLauncher.Update
+{
+ public class PlanerPackageInfo
+ {
+ public List Files { get; set; }
+ public DateTime Created { get; set; }
+ public string DefaultVersion { get; set; }
+ public string TenantVersion { get; set; }
+
+ public PlanerPackageInfo()
+ {
+ DefaultVersion = null;
+ TenantVersion = null;
+ }
+
+ public string Version => TenantVersion ?? DefaultVersion;
+ }
+}
diff --git a/SharedLauncher/Update/PlanerRoot.cs b/SharedLauncher/Update/PlanerRoot.cs
deleted file mode 100644
index 0596c1816..000000000
--- a/SharedLauncher/Update/PlanerRoot.cs
+++ /dev/null
@@ -1,163 +0,0 @@
-using BS.SharedLauncher.Enums;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.IO.Compression;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Xml;
-using System.Xml.Linq;
-
-namespace BS.SharedLauncher.Update
-{
- public class PlanerRoot
- {
- public List Files { get; set; }
- public DateTime Created { get; set; }
-
- public string DefaultVersion { get; set; }
- public string TenantVersion { get; set; }
-
- //public List Directories { get; set; }
- //public List Files { get; set; }
-
- public PlanerRoot()
- {
- Created = DateTime.Now;
- }
-
- public string CurrentVersion => TenantVersion ?? DefaultVersion;
-
- public PlanerFile FindPlanerFile(PlanerFile file)
- {
- return Files.Find(x => x.RelativePath == file.RelativePath);
- }
-
- public void InitPlanerFiles(List files)
- {
- Files = new List();
- Files.AddRange(files);
- }
-
- private void UpdatePlanerFile(PlanerFile newFile)
- {
- var oldFile = FindPlanerFile(newFile);
-
- oldFile.AbsolutePath = newFile.AbsolutePath;
- oldFile.Source = newFile.Source;
- }
- public void UpdatePlanerFiles(List files) => files.ForEach(x => UpdatePlanerFile(x));
-
- public byte[] GetData()
- {
- byte[] res = null;
-
- using (var memoryStream = new MemoryStream())
- {
- using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
- {
- var demoFile = archive.CreateEntry("foo.txt");
-
- using (var entryStream = demoFile.Open())
- using (var streamWriter = new StreamWriter(entryStream))
- {
- streamWriter.Write("Bar!");
- }
- }
-
- res = memoryStream.ToArray();
-
- // memoryStream.Seek(0, SeekOrigin.Begin);
-
-
- //using (var fileStream = new FileStream(@"C:\Temp\test.zip", FileMode.Create))
- //{
- // memoryStream.Seek(0, SeekOrigin.Begin);
- // memoryStream.CopyTo(fileStream);
- //}
- }
-
- return res;
-
- //using (var compressedFileStream = new MemoryStream())
- //{
- // //Create an archive and store the stream in memory.
- // using (var zipArchive = new ZipArchive(compressedFileStream, ZipArchiveMode.Create, false))
- // {
- // foreach (var caseAttachmentModel in caseAttachmentModels)
- // {
- // //Create a zip entry for each attachment
- // var zipEntry = zipArchive.CreateEntry(caseAttachmentModel.Name);
-
- // //Get the stream of the attachment
- // using (var originalFileStream = new MemoryStream(caseAttachmentModel.Body))
- // using (var zipEntryStream = zipEntry.Open())
- // {
- // //Copy the attachment stream to the zip entry stream
- // originalFileStream.CopyTo(zipEntryStream);
- // }
- // }
- // }
-
- // return new FileContentResult(compressedFileStream.ToArray(), "application/zip") { FileDownloadName = "Filename.zip" };
- //}
- }
-
- public string GetVersionXml(string tenant)
- {
- XElement versions = new XElement("example");
-
- XDocument root = new XDocument(
- new XElement("bewopackage",
- GetConfigElement(tenant),
- GetFilesElement()
- )
- );
-
- root.Save("D:\\document.xml");
-
- //XDocument doc = new XDocument(
- // new XElement("body",
- // new XElement("level1",
- // new XElement("level2", "text"),
- // new XElement("level2", "other text"))));
- //doc.Save("D:\\document.xml");
-
- return string.Empty;
- }
-
- private XElement GetConfigElement(string tenant)
- {
- XElement element = new XElement("config");
-
- element.Add(new XElement("tenant", tenant));
- element.Add(new XElement("dversion", DefaultVersion));
- element.Add(new XElement("tversion", TenantVersion));
- element.Add(new XElement("created", Created.ToString()));
-
- return element;
- }
-
- private XElement GetFilesElement()
- {
- XElement element = new XElement("files");
-
- Files.ForEach(x => element.Add(GetFileElement(x)));
-
- return element;
- }
-
- private XElement GetFileElement(PlanerFile planerFile)
- {
- XElement element = new XElement("file");
-
- element.Add(new XElement("name", planerFile.Name));
- element.Add(new XElement("relative", planerFile.RelativePath));
- //element.Add(new XElement("extension", planerFile.Extension));
- element.Add(new XElement("source", planerFile.Source));
-
- return element;
- }
- }
-}
diff --git a/SharedLauncher/Utils/PathUtils.cs b/SharedLauncher/Utils/PathUtils.cs
index fb4937468..8069137f7 100644
--- a/SharedLauncher/Utils/PathUtils.cs
+++ b/SharedLauncher/Utils/PathUtils.cs
@@ -13,21 +13,24 @@ namespace BS.SharedLauncher.Utils
/// Creates a relative path from one file or folder to another.
/// From https://stackoverflow.com/questions/275689/how-to-get-relative-path-from-absolute-path
///
- /// Contains the directory that defines the start of the relative path.
- /// Contains the path that defines the endpoint of the relative path.
+ /// Contains the directory that defines the start of the relative path.
+ /// Contains the path that defines the endpoint of the relative path.
/// The relative path from the start directory to the end path or toPath if the paths are not related.
///
///
///
- public static string MakeRelativePath(string fromPath, string toPath)
+ public static string MakeRelativePath(string beginPath, string fullPath)
{
- if (string.IsNullOrEmpty(fromPath)) throw new ArgumentNullException("fromPath");
- if (string.IsNullOrEmpty(toPath)) throw new ArgumentNullException("toPath");
+ if (string.IsNullOrEmpty(beginPath)) throw new ArgumentNullException("fromPath");
+ if (string.IsNullOrEmpty(fullPath)) throw new ArgumentNullException("toPath");
- Uri fromUri = new Uri(fromPath);
- Uri toUri = new Uri(toPath);
+ if (!beginPath.EndsWith(Path.DirectorySeparatorChar.ToString()))
+ beginPath += Path.DirectorySeparatorChar;
- if (fromUri.Scheme != toUri.Scheme) { return toPath; } // path can't be made relative.
+ Uri fromUri = new Uri(beginPath);
+ Uri toUri = new Uri(fullPath);
+
+ if (fromUri.Scheme != toUri.Scheme) { return fullPath; } // path can't be made relative.
Uri relativeUri = fromUri.MakeRelativeUri(toUri);
string relativePath = Uri.UnescapeDataString(relativeUri.ToString());