Zwischenstand 22.08.30
This commit is contained in:
@@ -32,11 +32,12 @@
|
||||
</behaviors>
|
||||
</system.serviceModel>
|
||||
<appSettings>
|
||||
<add key="AutoLogin" value="false" />
|
||||
<add key="AutoLogin" value="true" />
|
||||
<add key="ShowUpdateDelay" value="true" />
|
||||
<add key="ForceUpdate" value="true" />
|
||||
<add key="UseUpdater" value="true"/>
|
||||
<add key="ClientSettingsProvider.ServiceUri" value="" />
|
||||
<add key="SkipLock" value="true"/>
|
||||
</appSettings>
|
||||
<system.web>
|
||||
<membership defaultProvider="ClientAuthenticationMembershipProvider">
|
||||
|
||||
@@ -73,6 +73,8 @@
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.IO.Compression" />
|
||||
<Reference Include="System.IO.Compression.FileSystem" />
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Web.Extensions" />
|
||||
@@ -127,7 +129,11 @@
|
||||
<Compile Include="Converter\StringLengthVisibilityConverter.cs" />
|
||||
<Compile Include="Converter\StringLengthVisibilityMultiConverter.cs" />
|
||||
<Compile Include="Converter\ValueEqualsParamVisibilityConverter.cs" />
|
||||
<Compile Include="UpdateFileManager.cs" />
|
||||
<Compile Include="Logic\ProcessController.cs" />
|
||||
<Compile Include="Logic\ViewController.cs" />
|
||||
<Compile Include="Utils\BeWoHelper.cs" />
|
||||
<Compile Include="Utils\BeWoPaths.cs" />
|
||||
<Compile Include="Utils\Update\UpdateFileManager.cs" />
|
||||
<Compile Include="Components\PasswortAenderungsView.xaml.cs">
|
||||
<DependentUpon>PasswortAenderungsView.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -135,8 +141,6 @@
|
||||
<Compile Include="PageImp\02 UpdatePage.xaml.cs">
|
||||
<DependentUpon>02 UpdatePage.xaml</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="Extensions\FileExtension.cs" />
|
||||
<Compile Include="UpdatePathManager.cs" />
|
||||
<Compile Include="WindowImp\PopUpWindow.xaml.cs">
|
||||
<DependentUpon>PopUpWindow.xaml</DependentUpon>
|
||||
</Compile>
|
||||
@@ -406,5 +410,8 @@
|
||||
<Private>True</Private>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<WCFMetadata Include="Connected Services\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
@@ -43,62 +43,20 @@
|
||||
<RowDefinition Height="Auto" />
|
||||
<RowDefinition Height="Auto" />
|
||||
</Grid.RowDefinitions>
|
||||
<Label Content="Profilname:" Margin="0,3,0,0" />
|
||||
<TextBox x:Name="profileNameTextBox" Grid.Column="1" Margin="0,3,0,0" />
|
||||
|
||||
<Label Content="Kundennummer:" Margin="0,3,0,0" Grid.Row="1" />
|
||||
<TextBox x:Name="profileTenantBox" Grid.Row="1" Grid.Column="1" Margin="0,3,0,0" />
|
||||
|
||||
<Label Content="Server:" Grid.Row="2" Margin="0,3,0,0" />
|
||||
<TextBox x:Name="profileServerTextBox" Grid.Column="1" Grid.Row="2" Margin="0,3,0,0" />
|
||||
|
||||
<DockPanel Margin="0" Grid.Column="1" Grid.Row="3" Grid.ColumnSpan="1">
|
||||
<Button Margin="0,0,0,0" HorizontalAlignment="Left" Content="Ausgew. Profil löschen" Click="ProfileDeleteClick" />
|
||||
<Button Margin="0,0,0,0" HorizontalAlignment="Right" Content="Neues Profil hinzufügen" Click="ProfileAddClick" />
|
||||
<Button Margin="0,0,0,0" HorizontalAlignment="Right" Click="ProfileDeleteClick" Width="25" >-</Button>
|
||||
<Button Margin="0,0,0,0" HorizontalAlignment="Right" Click="ProfileAddClick" Width="25" >+</Button>
|
||||
</DockPanel>
|
||||
</Grid>
|
||||
<DataGrid x:Name="profileControl" Grid.Row="1" Margin="5"
|
||||
SelectionMode="Single" AutoGenerateColumns="False" >
|
||||
<DataGrid x:Name="profileControl" Grid.Row="1" Margin="5"
|
||||
SelectionMode="Single" AutoGenerateColumns="False" CanUserResizeRows="False" CanUserSortColumns="False" CellEditEnding="ProfileControl_CellEditEnding" >
|
||||
<DataGrid.Columns>
|
||||
<!-- <DataGridTemplateColumn>
|
||||
<DataGridTemplateColumn.CellEditingTemplate>
|
||||
<DataTemplate>
|
||||
<Button Click="DeleteRowButtonClick">X</Button>
|
||||
</DataTemplate>
|
||||
</DataGridTemplateColumn.CellEditingTemplate>
|
||||
</DataGridTemplateColumn> -->
|
||||
<DataGridTextColumn Header="Profilname" Binding="{Binding Name}" Width="70"/>
|
||||
<DataGridTextColumn Header="Kundennummer" Binding="{Binding Tenant}" Width="100"/>
|
||||
<DataGridTextColumn Header="Server" Binding="{Binding Server}" Width="*"/>
|
||||
</DataGrid.Columns>
|
||||
</DataGrid>
|
||||
<!-- <Grid Grid.Row="1">
|
||||
<ListView x:Name="listView" Margin="10">
|
||||
<ListView.View>
|
||||
<GridView>
|
||||
<GridViewColumn Header="Profilname" Width="120" DisplayMemberBinding="{Binding Name}"/>
|
||||
<GridViewColumn Header="Kundennummer" Width="120" DisplayMemberBinding="{Binding Tenant}"/>
|
||||
<GridViewColumn Header="Server" Width="120" DisplayMemberBinding="{Binding Server}"/>
|
||||
</GridView>
|
||||
</ListView.View>
|
||||
</ListView>
|
||||
</Grid> -->
|
||||
<!-- <dxg:GridControl Grid.Row="1" Margin="5" ItemsSource="{Binding Profiles}" x:Name="profileGridControl" >
|
||||
<dxg:GridControl.Columns>
|
||||
<dxg:GridColumn FieldName="Notice" Header="" FixedWidth="True" Width="24" ReadOnly="True">
|
||||
<dxg:GridColumn.CellTemplate>
|
||||
<DataTemplate>
|
||||
<Button Content="r" FontFamily="Webdings" Tag="{Binding}" Click="btn_deleteProfileClick" Width="18" Height="18" VerticalAlignment="Center" />
|
||||
</DataTemplate>
|
||||
</dxg:GridColumn.CellTemplate>
|
||||
</dxg:GridColumn>
|
||||
<dxg:GridColumn FieldName="Name" Header="Profilname" Width="70"/>
|
||||
<dxg:GridColumn FieldName="Tenant" Header="Kundennummer" Width="50" />
|
||||
<dxg:GridColumn FieldName="Server" Header="Server" Width="100" />
|
||||
</dxg:GridControl.Columns>
|
||||
<dxg:GridControl.View>
|
||||
<dxg:TableView AutoWidth="true" ShowGroupPanel="False" ShowGroupedColumns="false" ShowTotalSummary="False" NavigationStyle="Cell" />
|
||||
</dxg:GridControl.View>
|
||||
</dxg:GridControl> -->
|
||||
<Border Grid.Row="2" Grid.ColumnSpan="3" Height="40" Margin="0,10,0,0" VerticalAlignment="Stretch" Background="#FF000000">
|
||||
<Border.OpacityMask>
|
||||
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
|
||||
|
||||
@@ -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("<Neuer Eintrag>", 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
122
BeWoLauncher/Logic/ProcessController.cs
Normal file
122
BeWoLauncher/Logic/ProcessController.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
124
BeWoLauncher/Logic/ViewController.cs
Normal file
124
BeWoLauncher/Logic/ViewController.cs
Normal file
@@ -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);
|
||||
//}
|
||||
}
|
||||
}
|
||||
@@ -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<ConnectionProfile> 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());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<FileEventArgs> DownloadFileEventHandler;
|
||||
public static event EventHandler<FileEventArgs> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
BeWoLauncher/Utils/BeWoHelper.cs
Normal file
14
BeWoLauncher/Utils/BeWoHelper.cs
Normal file
@@ -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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// Holt den Install Ort aus den Properties Settings.
|
||||
@@ -31,19 +35,11 @@ namespace BeWoLauncher
|
||||
|
||||
return installLocation;
|
||||
}
|
||||
/// <summary>
|
||||
/// Speichert den aktuellen Update Path
|
||||
/// </summary>
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
157
BeWoLauncher/Utils/Update/UpdateFileManager.cs
Normal file
157
BeWoLauncher/Utils/Update/UpdateFileManager.cs
Normal file
@@ -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
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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<Control>();
|
||||
|
||||
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()
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
</StartCmdLineArguments>
|
||||
<StartWorkingDirectory>
|
||||
</StartWorkingDirectory>
|
||||
<EnableENC>True</EnableENC>
|
||||
<EnableENC>False</EnableENC>
|
||||
<AlwaysStartWebServerOnDebug>True</AlwaysStartWebServerOnDebug>
|
||||
</WebProjectProperties>
|
||||
</FlavorProperties>
|
||||
|
||||
@@ -476,8 +476,9 @@
|
||||
<Compile Include="ServiceImplementations\UserServiceImp.cs" />
|
||||
<Compile Include="ServiceImplementations\ValueListServiceImp.cs" />
|
||||
<Compile Include="Configuration\AppSettings.cs" />
|
||||
<Compile Include="ServiceUtils\Update\UpdatePathHelper.cs" />
|
||||
<Compile Include="ServiceUtils\Update\UpdateConfigHelper.cs" />
|
||||
<Compile Include="ServiceUtils\Paths\ServerFilePaths.cs" />
|
||||
<Compile Include="ServiceUtils\Update\UpdateConfigReader.cs" />
|
||||
<Compile Include="ServiceUtils\Update\DownloadPlanerResponseBuilder.cs" />
|
||||
<Compile Include="UnitOfWork\HibernateSessionEndpointBehavior.cs" />
|
||||
<Compile Include="UnitOfWork\HibernateSessionBehaviorExtension.cs" />
|
||||
<Compile Include="UnitOfWork\HibernateSessionContextInitializer.cs" />
|
||||
@@ -516,6 +517,7 @@
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="ServiceUtils\Generell\" />
|
||||
<Folder Include="Utils\" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -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<PlanerFile> GetVersionDefaultFiles(string version) => GetPlanerFiles(UpdatePathHelper.VersionDefaultPath(version), PlanerUpdateSource.VersionDefault);
|
||||
private List<PlanerFile> GetVersionTenantFiles(string version, string tenant) => GetPlanerFiles(UpdatePathHelper.VersionTenantPath(version, tenant), PlanerUpdateSource.VersionTenant);
|
||||
private List<PlanerFile> GetSpecialTenantFiles(string tenant) => GetPlanerFiles(UpdatePathHelper.SpecialTenantPath(tenant), PlanerUpdateSource.SpecialTenant);
|
||||
|
||||
private List<PlanerFile> GetPlanerFiles(string path, PlanerUpdateSource source)
|
||||
{
|
||||
var res = new List<PlanerFile>();
|
||||
|
||||
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<PlanerFile> 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
|
||||
|
||||
44
Service/ServiceUtils/Paths/ServerFilePaths.cs
Normal file
44
Service/ServiceUtils/Paths/ServerFilePaths.cs
Normal file
@@ -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");
|
||||
}
|
||||
}
|
||||
131
Service/ServiceUtils/Update/DownloadPlanerResponseBuilder.cs
Normal file
131
Service/ServiceUtils/Update/DownloadPlanerResponseBuilder.cs
Normal file
@@ -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<string, List<string>> 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<string, PlanerPackageInfo> zip2info)
|
||||
{
|
||||
downloadFilesToKeep = new Dictionary<string, List<string>>();
|
||||
|
||||
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<string>());
|
||||
}
|
||||
|
||||
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<PlanerFileInfo> getVersionDefaultFiles(string version) => getPlanerFiles(ServerFilePaths.GetVersionDefaultFolderPath(version));
|
||||
private List<PlanerFileInfo> getVersionTenantFiles(string version, string tenant) => getPlanerFiles(ServerFilePaths.GetVersionTenantFolderPath(version, tenant));
|
||||
private List<PlanerFileInfo> getSpecialTenantFiles(string tenant) => getPlanerFiles(ServerFilePaths.GetOverrideTenantFolderPath(tenant));
|
||||
|
||||
private List<PlanerFileInfo> getPlanerFiles(string path)
|
||||
{
|
||||
var res = FileController.GetPlanerFiles(path);
|
||||
|
||||
//res.ForEach(x => x.Source = source);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
@@ -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<string, PlanerPackageInfoDC> DownloadedPackages { get; set; }
|
||||
|
||||
[DataMember]
|
||||
public PlanerPackageInfoDC ApplyPackage { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<string, List<string>> DownloadFilesToKeep { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
24
SharedLauncher/DataContract/PlanerFileInfoDC.cs
Normal file
24
SharedLauncher/DataContract/PlanerFileInfoDC.cs
Normal file
@@ -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; }
|
||||
}
|
||||
}
|
||||
28
SharedLauncher/DataContract/PlanerPackageInfoDC.cs
Normal file
28
SharedLauncher/DataContract/PlanerPackageInfoDC.cs
Normal file
@@ -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<PlanerFileInfoDC> 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;
|
||||
}
|
||||
}
|
||||
24
SharedLauncher/Exceptions/UpdateException.cs
Normal file
24
SharedLauncher/Exceptions/UpdateException.cs
Normal file
@@ -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)
|
||||
{ }
|
||||
|
||||
}
|
||||
}
|
||||
27
SharedLauncher/Extensions/DownloadPlanerResponseExtension.cs
Normal file
27
SharedLauncher/Extensions/DownloadPlanerResponseExtension.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
80
SharedLauncher/Extensions/PathExtensions.cs
Normal file
80
SharedLauncher/Extensions/PathExtensions.cs
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
48
SharedLauncher/Extensions/PlanerFileExtension.cs
Normal file
48
SharedLauncher/Extensions/PlanerFileExtension.cs
Normal file
@@ -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<PlanerFileInfoDC> ToPlanerFileInfoDCList(this List<PlanerFileInfo> planerFileInfos) => planerFileInfos.Select(x => new PlanerFileInfoDC()
|
||||
{
|
||||
Checksum = x.Checksum,
|
||||
Name = x.Name,
|
||||
RelativePath = x.RelativePath
|
||||
}).ToList();
|
||||
public static List<PlanerFileInfo> ToPlanerFileInfoList(this List<PlanerFileInfoDC> 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
|
||||
};
|
||||
}
|
||||
}
|
||||
101
SharedLauncher/Extensions/PlanerPackageExtension.cs
Normal file
101
SharedLauncher/Extensions/PlanerPackageExtension.cs
Normal file
@@ -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<PlanerFileInfo> files)
|
||||
{
|
||||
planerFileInfo.Files = new List<PlanerFileInfo>();
|
||||
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<PlanerFileInfo> 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<PlanerFileInfo> 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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
23
SharedLauncher/Information/BeWoPathFileConfig.cs
Normal file
23
SharedLauncher/Information/BeWoPathFileConfig.cs
Normal file
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
///// <summary>
|
||||
///// Aus der neusten Version / Default Case
|
||||
///// </summary>
|
||||
//NewestVersion = 1,
|
||||
// ///// <summary>
|
||||
// ///// Aus der neusten Version / Default Case
|
||||
// ///// </summary>
|
||||
// //NewestVersion = 1,
|
||||
|
||||
///// <summary>
|
||||
///// Durch spezieller Version in version.config
|
||||
///// </summary>
|
||||
//SpecialVersion = 2,
|
||||
// ///// <summary>
|
||||
// ///// Durch spezieller Version in version.config
|
||||
// ///// </summary>
|
||||
// //SpecialVersion = 2,
|
||||
|
||||
///// <summary>
|
||||
///// Aus der neusten Version aus dem Version-Kunden-Ordner
|
||||
///// </summary>
|
||||
//NewestVersionTenant = 3,
|
||||
// ///// <summary>
|
||||
// ///// Aus der neusten Version aus dem Version-Kunden-Ordner
|
||||
// ///// </summary>
|
||||
// //NewestVersionTenant = 3,
|
||||
|
||||
///// <summary>
|
||||
///// Aus der speziellen Version aus dem Version-Kunden-Ordner
|
||||
///// </summary>
|
||||
//SpecialVersionTenant = 4,
|
||||
// ///// <summary>
|
||||
// ///// Aus der speziellen Version aus dem Version-Kunden-Ordner
|
||||
// ///// </summary>
|
||||
// //SpecialVersionTenant = 4,
|
||||
|
||||
///// <summary>
|
||||
///// Aus dem Kunden-Ordner
|
||||
///// </summary>
|
||||
//SpecialTenant = 5
|
||||
}
|
||||
// ///// <summary>
|
||||
// ///// Aus dem Kunden-Ordner
|
||||
// ///// </summary>
|
||||
// //SpecialTenant = 5
|
||||
//}
|
||||
}
|
||||
|
||||
183
SharedLauncher/Logic/FileController.cs
Normal file
183
SharedLauncher/Logic/FileController.cs
Normal file
@@ -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<string, List<string>> 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<string, bool> 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<string> GetValidDZipPaths(string path)
|
||||
{
|
||||
var res = new List<string>();
|
||||
|
||||
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<T>(string path, T t)
|
||||
where T : class
|
||||
{
|
||||
File.WriteAllText(path.WithInfoExtension(), XmlConverter.Serialize<T>(t));
|
||||
}
|
||||
public static PlanerPackageInfoDC LoadInfo(string filepath)
|
||||
{
|
||||
filepath = filepath.WithInfoExtension();
|
||||
|
||||
var xml = File.ReadAllText(filepath);
|
||||
var obj = XmlConverter.Deserialize<PlanerPackageInfoDC>(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<string, PlanerPackageInfoDC> 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<string, PlanerPackageInfoDC>();
|
||||
|
||||
//foreach (var dzip in allDZips)
|
||||
//{
|
||||
// res.Add(dzip, GetPackageInfo(dzip));
|
||||
//}
|
||||
|
||||
//return res;
|
||||
}
|
||||
public static List<PlanerFileInfo> GetPlanerFiles(string path)
|
||||
{
|
||||
var res = new List<PlanerFileInfo>();
|
||||
|
||||
// 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<PlanerFileInfo> 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})";
|
||||
}
|
||||
}
|
||||
}
|
||||
35
SharedLauncher/Logic/XmlConverter.cs
Normal file
35
SharedLauncher/Logic/XmlConverter.cs
Normal file
@@ -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>(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<T>(string input)
|
||||
where T : class
|
||||
{
|
||||
XmlSerializer ser = new XmlSerializer(typeof(T));
|
||||
|
||||
using (StringReader sr = new StringReader(input))
|
||||
return (T)ser.Deserialize(sr);
|
||||
}
|
||||
}
|
||||
}
|
||||
35
SharedLauncher/Logic/ZipArchiveBuilder.cs
Normal file
35
SharedLauncher/Logic/ZipArchiveBuilder.cs
Normal file
@@ -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<T>(List<T> files, Func<T, string> path, Func<T, string> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -51,10 +51,21 @@
|
||||
<ItemGroup>
|
||||
<Compile Include="DataContract\DownloadPlanerResponseDC.cs" />
|
||||
<Compile Include="DataContract\DownloadPlanerRequestDC.cs" />
|
||||
<Compile Include="DataContract\PlanerFileInfoDC.cs" />
|
||||
<Compile Include="DataContract\PlanerPackageInfoDC.cs" />
|
||||
<Compile Include="Exceptions\UpdateException.cs" />
|
||||
<Compile Include="Extensions\DownloadPlanerResponseExtension.cs" />
|
||||
<Compile Include="Extensions\PathExtensions.cs" />
|
||||
<Compile Include="Extensions\PlanerFileExtension.cs" />
|
||||
<Compile Include="Extensions\PlanerPackageExtension.cs" />
|
||||
<Compile Include="Information\BeWoPathFileConfig.cs" />
|
||||
<Compile Include="LauncherEnums.cs" />
|
||||
<Compile Include="Information\ConnectionInformation.cs" />
|
||||
<Compile Include="Update\PlanerFile.cs" />
|
||||
<Compile Include="Update\PlanerRoot.cs" />
|
||||
<Compile Include="Logic\FileController.cs" />
|
||||
<Compile Include="Logic\XmlConverter.cs" />
|
||||
<Compile Include="Logic\ZipArchiveBuilder.cs" />
|
||||
<Compile Include="Update\PlanerFileInfo.cs" />
|
||||
<Compile Include="Update\PlanerPackageInfo.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="StringCompressor.cs" />
|
||||
<Compile Include="Utils\NonspecificTools.cs" />
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
45
SharedLauncher/Update/PlanerFileInfo.cs
Normal file
45
SharedLauncher/Update/PlanerFileInfo.cs
Normal file
@@ -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
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
30
SharedLauncher/Update/PlanerPackageInfo.cs
Normal file
30
SharedLauncher/Update/PlanerPackageInfo.cs
Normal file
@@ -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<PlanerFileInfo> 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;
|
||||
}
|
||||
}
|
||||
@@ -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<PlanerFile> Files { get; set; }
|
||||
public DateTime Created { get; set; }
|
||||
|
||||
public string DefaultVersion { get; set; }
|
||||
public string TenantVersion { get; set; }
|
||||
|
||||
//public List<PlanerDirectory> Directories { get; set; }
|
||||
//public List<PlanerFile> 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<PlanerFile> files)
|
||||
{
|
||||
Files = new List<PlanerFile>();
|
||||
Files.AddRange(files);
|
||||
}
|
||||
|
||||
private void UpdatePlanerFile(PlanerFile newFile)
|
||||
{
|
||||
var oldFile = FindPlanerFile(newFile);
|
||||
|
||||
oldFile.AbsolutePath = newFile.AbsolutePath;
|
||||
oldFile.Source = newFile.Source;
|
||||
}
|
||||
public void UpdatePlanerFiles(List<PlanerFile> 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
/// </summary>
|
||||
/// <param name="fromPath">Contains the directory that defines the start of the relative path.</param>
|
||||
/// <param name="toPath">Contains the path that defines the endpoint of the relative path.</param>
|
||||
/// <param name="beginPath">Contains the directory that defines the start of the relative path.</param>
|
||||
/// <param name="fullPath">Contains the path that defines the endpoint of the relative path.</param>
|
||||
/// <returns>The relative path from the start directory to the end path or <c>toPath</c> if the paths are not related.</returns>
|
||||
/// <exception cref="ArgumentNullException"></exception>
|
||||
/// <exception cref="UriFormatException"></exception>
|
||||
/// <exception cref="InvalidOperationException"></exception>
|
||||
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());
|
||||
|
||||
Reference in New Issue
Block a user