2017-09-12 14:32:34 +02:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
2020-06-17 19:36:52 +02:00
|
|
|
|
using System.ComponentModel;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
using System.IO;
|
2017-10-06 12:08:05 +02:00
|
|
|
|
using System.Reflection;
|
2020-06-17 19:36:52 +02:00
|
|
|
|
using System.Runtime.CompilerServices;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Windows;
|
2020-06-17 19:36:52 +02:00
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
|
using System.Windows.Threading;
|
|
|
|
|
|
using ChatController.Annotations;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
using ChatController.HauptKlassen;
|
2019-04-04 13:00:10 +02:00
|
|
|
|
using ChatController.LoginKlassen;
|
2020-06-17 19:36:52 +02:00
|
|
|
|
using ChatController.Utilities;
|
|
|
|
|
|
using ChatController.Utilities.Extensions;
|
2017-10-20 07:34:26 +02:00
|
|
|
|
using Cursors = System.Windows.Input.Cursors;
|
|
|
|
|
|
using MessageBox = System.Windows.MessageBox;
|
2017-10-06 12:08:05 +02:00
|
|
|
|
using Path = System.IO.Path;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
|
|
|
|
|
namespace ChatController
|
|
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
public partial class LoginControl : INotifyPropertyChanged
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
private ChatControlWaitLayer _WaitLayer;
|
|
|
|
|
|
|
|
|
|
|
|
public string UserName
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _Benutzername;
|
|
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!Equals(_Benutzername, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_Benutzername = value;
|
|
|
|
|
|
OnPropertyChanged(nameof(UserName));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string Password
|
|
|
|
|
|
{
|
|
|
|
|
|
get => PasswordBox.Password;
|
|
|
|
|
|
|
|
|
|
|
|
set => PasswordBox.Password = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string ChatCode
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _ChatCode;
|
|
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!Equals(_ChatCode, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_ChatCode = value;
|
|
|
|
|
|
OnPropertyChanged(nameof(ChatCode));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public string Tenant
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _Kundennummer;
|
|
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if(!Equals(_Kundennummer, value))
|
|
|
|
|
|
{
|
|
|
|
|
|
_Kundennummer = value;
|
|
|
|
|
|
OnPropertyChanged(nameof(Tenant));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-12 14:32:34 +02:00
|
|
|
|
public delegate void LoginDelegate(ChatDatenUebergabe cdu);
|
|
|
|
|
|
|
|
|
|
|
|
public event LoginDelegate OnLogin;
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
private string _Benutzername = string.Empty;
|
|
|
|
|
|
private string _ChatCode = string.Empty;
|
|
|
|
|
|
private string _Kundennummer = string.Empty;
|
2020-09-28 11:29:02 +02:00
|
|
|
|
private readonly string _Version = "1.4";
|
2020-06-17 19:36:52 +02:00
|
|
|
|
|
|
|
|
|
|
public string Version => $"Version: {_Version}";
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
|
|
|
|
|
public LoginControl()
|
|
|
|
|
|
{
|
|
|
|
|
|
InitializeComponent();
|
2017-10-06 12:08:05 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
DataContext = this;
|
2017-11-13 17:09:21 +01:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
LeseDateiFallsVorhanden();
|
2020-08-06 16:05:23 +02:00
|
|
|
|
|
|
|
|
|
|
#if DEBUG
|
|
|
|
|
|
_Kundennummer = "4368658436";
|
|
|
|
|
|
_ChatCode = "ZMCKb-BckTt";
|
|
|
|
|
|
_Benutzername = "muellerp";
|
|
|
|
|
|
Password = "F5aTk9Co47JFJCWB2Z7Y";
|
|
|
|
|
|
#endif
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void AnmeldenButton_OnClick(object sender, RoutedEventArgs e)
|
2017-10-20 07:34:26 +02:00
|
|
|
|
{
|
|
|
|
|
|
Anmelden();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
private void StartWaiting()
|
|
|
|
|
|
{
|
|
|
|
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) StartWaitingImmediately);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void StartWaitingImmediately()
|
2017-10-20 07:34:26 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
if (_WaitLayer == null)
|
2017-10-20 07:34:26 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
_WaitLayer = new ChatControlWaitLayer();
|
|
|
|
|
|
Panel.SetZIndex(_WaitLayer, int.MaxValue);
|
|
|
|
|
|
RootGrid.Children.Add(_WaitLayer);
|
|
|
|
|
|
_WaitLayer.RefreshUI();
|
2017-10-20 07:34:26 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-06-17 19:36:52 +02:00
|
|
|
|
|
|
|
|
|
|
private void EndWaiting()
|
|
|
|
|
|
{
|
|
|
|
|
|
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action) delegate
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_WaitLayer != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
RootGrid.Children.Remove(_WaitLayer);
|
|
|
|
|
|
_WaitLayer = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-20 07:34:26 +02:00
|
|
|
|
private void Anmelden()
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2017-09-15 16:39:07 +02:00
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
if (!string.IsNullOrWhiteSpace(_Kundennummer) && !string.IsNullOrWhiteSpace(_ChatCode) && !string.IsNullOrWhiteSpace(_Benutzername) && Password.Length > 0)
|
2017-10-20 07:34:26 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
StartWaiting();
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
var login = new Login(_Kundennummer, _ChatCode, _Benutzername, PasswordBox.Password);
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
login.DoLoginAsync(chatDatenUebergabe =>
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
this.Dispatch(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
EndWaiting();
|
2019-04-04 13:00:10 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
if(chatDatenUebergabe != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
AutosetDaten();
|
|
|
|
|
|
|
|
|
|
|
|
OnLogin?.Invoke(chatDatenUebergabe);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
},
|
|
|
|
|
|
errorMessage =>
|
|
|
|
|
|
{
|
|
|
|
|
|
this.Dispatch(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
EndWaiting();
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
MessageBox.Show(errorMessage, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-10-06 12:08:05 +02:00
|
|
|
|
MessageBox.Show("Bitte alle Felder ausfüllen!", "Info", MessageBoxButton.OK);
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
2017-09-15 16:39:07 +02:00
|
|
|
|
}
|
|
|
|
|
|
catch (Exception exception)
|
|
|
|
|
|
{
|
2017-10-24 12:22:05 +02:00
|
|
|
|
MessageBox.Show("Fehler: " + exception.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
2020-06-17 19:36:52 +02:00
|
|
|
|
EndWaiting();
|
2017-09-20 11:46:00 +02:00
|
|
|
|
Cursor = Cursors.Arrow;
|
2017-09-15 16:39:07 +02:00
|
|
|
|
}
|
2017-10-06 12:08:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
private void LoadTenantAndChatCodeFromFile()
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
if(File.Exists(Path.Combine(GetAndCreateUserAppDataPath(), Constants.TenantAndChatCodeFileName)))
|
2017-09-20 11:46:00 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
var lines = new List<string>();
|
|
|
|
|
|
using(var streamReader = new StreamReader(Path.Combine(GetAndCreateUserAppDataPath(), Constants.TenantAndChatCodeFileName), true))
|
2017-09-20 11:46:00 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
string line;
|
2017-09-20 11:46:00 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
while((line = streamReader.ReadLine()) != null)
|
2017-09-20 11:46:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
var encodedTextBytes = Convert.FromBase64String(line);
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
var plainText = Encoding.UTF8.GetString(encodedTextBytes);
|
2017-09-20 11:46:00 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
lines.Add(plainText);
|
2017-09-20 11:46:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
if(lines.Count == 2)
|
2017-09-20 11:46:00 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
_Kundennummer = lines[0];
|
|
|
|
|
|
_ChatCode = lines[1];
|
2017-09-20 11:46:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
2020-06-17 19:36:52 +02:00
|
|
|
|
catch(Exception e)
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
MessageBox.Show("Fehler: \n" + e.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
private void LeseDateiFallsVorhanden()
|
|
|
|
|
|
{
|
|
|
|
|
|
LoadTenantAndChatCodeFromFile();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-09-20 11:46:00 +02:00
|
|
|
|
private void AutosetDaten()
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
|
|
|
|
|
try
|
2017-09-15 09:49:32 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
if(File.Exists(Path.Combine(GetAndCreateUserAppDataPath(), Constants.TenantAndChatCodeFileName)))
|
2017-09-20 11:46:00 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
File.SetAttributes(Path.Combine(GetAndCreateUserAppDataPath(), Constants.TenantAndChatCodeFileName), FileAttributes.Normal);
|
|
|
|
|
|
File.Delete(Path.Combine(GetAndCreateUserAppDataPath(), Constants.TenantAndChatCodeFileName));
|
2017-10-06 12:08:05 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
using(var streamWriter = new StreamWriter(Path.Combine(GetAndCreateUserAppDataPath(), Constants.TenantAndChatCodeFileName)))
|
|
|
|
|
|
{
|
|
|
|
|
|
Encoding utf8Encoding = new UTF8Encoding();
|
|
|
|
|
|
var tenantBytes = utf8Encoding.GetBytes(_Kundennummer);
|
|
|
|
|
|
var encodedTenant = Convert.ToBase64String(tenantBytes);
|
2017-10-06 12:08:05 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
var chatCodeBytes = utf8Encoding.GetBytes(_ChatCode);
|
|
|
|
|
|
var encodedChatCode = Convert.ToBase64String(chatCodeBytes);
|
2017-10-06 12:08:05 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
streamWriter.WriteLine(encodedTenant);
|
|
|
|
|
|
streamWriter.WriteLine(encodedChatCode);
|
2017-10-06 12:08:05 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
File.SetAttributes(Path.Combine(GetAndCreateUserAppDataPath(), Constants.TenantAndChatCodeFileName), FileAttributes.ReadOnly);
|
2017-09-20 11:46:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
MessageBox.Show("Fehler: \n" + e.Message, "Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
|
2017-09-20 11:46:00 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-10-20 07:34:26 +02:00
|
|
|
|
private static string GetAndCreateUserAppDataPath()
|
2017-09-20 11:46:00 +02:00
|
|
|
|
{
|
|
|
|
|
|
try
|
|
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
var localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
|
|
|
|
|
|
var companyFilePath = Path.Combine(localAppData, "beyondSoft");
|
2017-09-20 11:46:00 +02:00
|
|
|
|
|
2017-10-06 12:08:05 +02:00
|
|
|
|
if (!Directory.Exists(companyFilePath))
|
2020-06-17 19:36:52 +02:00
|
|
|
|
{
|
2017-10-06 12:08:05 +02:00
|
|
|
|
Directory.CreateDirectory(companyFilePath);
|
2020-06-17 19:36:52 +02:00
|
|
|
|
}
|
2017-09-20 11:46:00 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
var bewoFilePath = Path.Combine(companyFilePath, "OwnChat");
|
2017-09-14 12:36:48 +02:00
|
|
|
|
|
2017-10-06 12:08:05 +02:00
|
|
|
|
if (!Directory.Exists(bewoFilePath))
|
2020-06-17 19:36:52 +02:00
|
|
|
|
{
|
2017-10-06 12:08:05 +02:00
|
|
|
|
Directory.CreateDirectory(bewoFilePath);
|
2020-06-17 19:36:52 +02:00
|
|
|
|
}
|
2017-09-14 12:36:48 +02:00
|
|
|
|
|
2017-10-06 12:08:05 +02:00
|
|
|
|
return bewoFilePath;
|
|
|
|
|
|
}
|
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
|
{
|
|
|
|
|
|
MessageBox.Show(
|
|
|
|
|
|
"Fehler beim Anlegen des Anwendungsordners. Sie besitzen nicht die erforderlichen Rechte, bitte wenden Sie sich an Ihren Systemadministrator.\n" +
|
|
|
|
|
|
ex.Message, "BeWoPlaner", MessageBoxButton.OK, MessageBoxImage.Exclamation);
|
|
|
|
|
|
}
|
|
|
|
|
|
return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
|
|
|
|
|
}
|
2017-09-14 12:36:48 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
public void Login()
|
2017-09-12 14:32:34 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
Anmelden();
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
2017-09-12 14:32:34 +02:00
|
|
|
|
|
2020-06-17 19:36:52 +02:00
|
|
|
|
[NotifyPropertyChangedInvocator]
|
|
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
|
2019-05-14 13:37:20 +02:00
|
|
|
|
{
|
2020-06-17 19:36:52 +02:00
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
2019-05-14 13:37:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-09-12 14:32:34 +02:00
|
|
|
|
}
|