Beta version

This commit is contained in:
Fabian Stamm 2017-05-21 16:23:59 +02:00
parent 129e0679cd
commit 81dd00b5bd
173 changed files with 650 additions and 64 deletions

View File

@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.26403.3
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuechermarktClient", "BuechermarktClient\BuechermarktClient.csproj", "{4DE1DCAB-3872-42C8-8E47-A1ED6A7A56E7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuechermarktServer", "BuechermarktServer\BuechermarktServer.csproj", "{BA959A9C-FF68-4440-9983-8FB434230FCB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -15,6 +17,10 @@ Global
{4DE1DCAB-3872-42C8-8E47-A1ED6A7A56E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4DE1DCAB-3872-42C8-8E47-A1ED6A7A56E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4DE1DCAB-3872-42C8-8E47-A1ED6A7A56E7}.Release|Any CPU.Build.0 = Release|Any CPU
{BA959A9C-FF68-4440-9983-8FB434230FCB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BA959A9C-FF68-4440-9983-8FB434230FCB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BA959A9C-FF68-4440-9983-8FB434230FCB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BA959A9C-FF68-4440-9983-8FB434230FCB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

View File

@ -14,54 +14,15 @@ namespace BuechermarktClient
public class Backup
{
public static void MakeBackup() {
string folder = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName);
string backupfolder = folder + "\\backups";
if (!Directory.Exists(backupfolder)){
Directory.CreateDirectory(backupfolder);
}
string tbackupfoldername = "" + (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
string tbackupfolder = backupfolder + "\\" + tbackupfoldername;
Directory.CreateDirectory(tbackupfolder);
var bt = MainWindow.BookTypeCollection.Find(e => true).ToList();
var json = JsonConvert.SerializeObject(bt);
StringToFile(tbackupfolder + "\\BookTypes.json", json);
var b = MainWindow.BookCollection.Find(e => true).ToList();
json = JsonConvert.SerializeObject(b);
StringToFile(tbackupfolder + "\\Book.json", json);
var s = MainWindow.StudentCollection.Find(e => true).ToList();
json = JsonConvert.SerializeObject(s);
StringToFile(tbackupfolder + "\\Students.json", json);
ZipFile.CreateFromDirectory(tbackupfolder, tbackupfolder + ".zip");
DeleteDirectory(tbackupfolder);
}
private static void StringToFile(string filepath, string json)
{
//File.Create(filepath);
File.WriteAllText(filepath, json);
}
public static void DeleteDirectory(string target_dir)
{
string[] files = Directory.GetFiles(target_dir);
string[] dirs = Directory.GetDirectories(target_dir);
foreach (string file in files)
{
File.SetAttributes(file, FileAttributes.Normal);
File.Delete(file);
}
foreach (string dir in dirs)
{
DeleteDirectory(dir);
}
Directory.Delete(target_dir, false);
var ts = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
var process = new Process();
process.StartInfo.FileName = "mongodump.exe";
process.StartInfo.Arguments = "--host " + MainWindow.MongoHost + " --db " + MainWindow.DatabaseName + " --gzip --out .\\backups\\" + ts;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start();
}
}
}

View File

@ -64,7 +64,7 @@ namespace BuechermarktClient
OnPropertyChanged("Student");
} else if(value == null)
{
Book.Student = new MongoDB.Bson.ObjectId("0");
Book.Student = new MongoDB.Bson.ObjectId(string.Empty);
}
}
}
@ -181,7 +181,7 @@ namespace BuechermarktClient
{
new ComboS("Im Lager", BookState.InStock),
new ComboS("Verkauft", BookState.Selled),
new ComboS("Verlohren", BookState.Missing),
new ComboS("Verloren", BookState.Missing),
new ComboS("Zurück an den Schüler", BookState.BackToStudent)
};
DataContext = this;

View File

@ -82,6 +82,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="GetConnection.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Students.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@ -112,6 +116,9 @@
<Compile Include="BookTypes.xaml.cs">
<DependentUpon>BookTypes.xaml</DependentUpon>
</Compile>
<Compile Include="GetConnection.xaml.cs">
<DependentUpon>GetConnection.xaml</DependentUpon>
</Compile>
<Compile Include="SigningService.cs" />
<Compile Include="Students.xaml.cs">
<DependentUpon>Students.xaml</DependentUpon>

View File

@ -0,0 +1,12 @@
<Window x:Class="BuechermarktClient.GetConnection"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:BuechermarktClient"
mc:Ignorable="d"
Title="GetConnection" Height="150" Width="600">
<Grid>
<Label Margin="5,5,0,0" Content="Waiting for Server" VerticalContentAlignment="Center" HorizontalContentAlignment="Center" FontSize="72"/>
</Grid>
</Window>

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Net;
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.Shapes;
namespace BuechermarktClient
{
/// <summary>
/// Interaktionslogik für GetConnection.xaml
/// </summary>
public partial class GetConnection : Window
{
public const string ServerIdentifier = "BUECHERMARKTCLIENT00018946";
public GetConnection()
{
InitializeComponent();
Loaded += (sender, e) =>
{
ListenForServer();
};
}
private UdpClient UdpClient;
public void ListenForServer()
{
UdpClient = new UdpClient(15000);
UdpClient.BeginReceive(Recevie, new object());
}
public void Recevie(IAsyncResult ar)
{
var ip = new IPEndPoint(IPAddress.Any, 15000);
var bytes = UdpClient.EndReceive(ar, ref ip);
string message = Encoding.ASCII.GetString(bytes);
if(message == ServerIdentifier)
{
MainWindow.MongoHost = ip.Address.ToString();
Dispatcher.BeginInvoke(new Action(delegate () {
Close();
}));
//Success
} else
{
//Retry
ListenForServer();
}
}
}
}

View File

@ -2,6 +2,7 @@
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading;
@ -28,6 +29,7 @@ namespace BuechermarktClient
public static IMongoCollection<BookType> BookTypeCollection;
public static IMongoCollection<Book> BookCollection;
public static IMongoCollection<Student> StudentCollection;
public const string DatabaseName = "buechermarkt";
public static string MongoHost = "localhost";
public BookTypes BookTypesWindow = null;
@ -36,16 +38,17 @@ namespace BuechermarktClient
public MainWindow()
{
var s = new GetConnection();
s.ShowDialog();
InitializeComponent();
OnConnectionEstablised("localhost");
OnConnectionEstablised();
//ToDo get server informations
}
public void OnConnectionEstablised(string hostname)
public void OnConnectionEstablised()
{
MongoHost = hostname;
Mongo = new MongoClient("mongodb://" + MongoHost + ":27017");
Database = Mongo.GetDatabase("buechermarkt");
Database = Mongo.GetDatabase(DatabaseName);
BookTypeCollection = Database.GetCollection<BookType>("booktypes");
BookCollection = Database.GetCollection<Book>("books");
StudentCollection = Database.GetCollection<Student>("students");

Some files were not shown because too many files have changed in this diff Show More