EBS_POC/EBS POC/Controls/Deploy_Page.xaml.cs

71 lines
2.1 KiB
C#

using EBS_POC.Models;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace EBS_POC.Controls
{
/// <summary>
/// Interaction logic for Deploy_Page.xaml
/// </summary>
public partial class Deploy_Page : UserControl
{
public Deploy_Page()
{
InitializeComponent();
}
private async void buttonDeploy_Click(object sender, RoutedEventArgs e)
{
if (File.Exists(textBox.Text.Replace("\"", "")))
{
MessageBox.Show("File already exists.");
return;
}
try
{
var masterFile = new Master_File();
masterFile.HostName = Environment.MachineName;
var filePath = textBox.Text.Replace("\"", "");
Main_Model.Current.EBSFilePath = filePath;
await FilePlus.WriteAllText(filePath, JsonHelper.Encode(masterFile));
Main_Model.Current.LockFS = File.Create(filePath + ".lock");
Main_Model.Current.IsHost = true;
Sockets.ConnectAsHost();
}
catch (DirectoryNotFoundException)
{
MessageBox.Show("Couldn't find the directory.");
}
catch (FileNotFoundException)
{
MessageBox.Show("Couldn't find the file.");
}
catch (UnauthorizedAccessException)
{
MessageBox.Show("Couldn't create file. Check your rights.");
}
catch (PathTooLongException)
{
MessageBox.Show("Path is too long. Pick another location.");
}
catch
{
MessageBox.Show("Something went wrong.");
}
}
}
}