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 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuechermarktClient", "BuechermarktClient\BuechermarktClient.csproj", "{4DE1DCAB-3872-42C8-8E47-A1ED6A7A56E7}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuechermarktClient", "BuechermarktClient\BuechermarktClient.csproj", "{4DE1DCAB-3872-42C8-8E47-A1ED6A7A56E7}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BuechermarktServer", "BuechermarktServer\BuechermarktServer.csproj", "{BA959A9C-FF68-4440-9983-8FB434230FCB}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU 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}.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.ActiveCfg = Release|Any CPU
{4DE1DCAB-3872-42C8-8E47-A1ED6A7A56E7}.Release|Any CPU.Build.0 = 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 EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@ -14,54 +14,15 @@ namespace BuechermarktClient
public class Backup public class Backup
{ {
public static void MakeBackup() { 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 ts = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
var json = JsonConvert.SerializeObject(bt); var process = new Process();
StringToFile(tbackupfolder + "\\BookTypes.json", json); process.StartInfo.FileName = "mongodump.exe";
process.StartInfo.Arguments = "--host " + MainWindow.MongoHost + " --db " + MainWindow.DatabaseName + " --gzip --out .\\backups\\" + ts;
var b = MainWindow.BookCollection.Find(e => true).ToList(); process.StartInfo.RedirectStandardOutput = true;
json = JsonConvert.SerializeObject(b); process.StartInfo.UseShellExecute = false;
StringToFile(tbackupfolder + "\\Book.json", json); process.StartInfo.CreateNoWindow = true;
process.Start();
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);
} }
} }
} }

View File

@ -64,7 +64,7 @@ namespace BuechermarktClient
OnPropertyChanged("Student"); OnPropertyChanged("Student");
} else if(value == null) } 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("Im Lager", BookState.InStock),
new ComboS("Verkauft", BookState.Selled), 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) new ComboS("Zurück an den Schüler", BookState.BackToStudent)
}; };
DataContext = this; DataContext = this;

View File

@ -82,6 +82,10 @@
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
</Page> </Page>
<Page Include="GetConnection.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Students.xaml"> <Page Include="Students.xaml">
<SubType>Designer</SubType> <SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator> <Generator>MSBuild:Compile</Generator>
@ -112,6 +116,9 @@
<Compile Include="BookTypes.xaml.cs"> <Compile Include="BookTypes.xaml.cs">
<DependentUpon>BookTypes.xaml</DependentUpon> <DependentUpon>BookTypes.xaml</DependentUpon>
</Compile> </Compile>
<Compile Include="GetConnection.xaml.cs">
<DependentUpon>GetConnection.xaml</DependentUpon>
</Compile>
<Compile Include="SigningService.cs" /> <Compile Include="SigningService.cs" />
<Compile Include="Students.xaml.cs"> <Compile Include="Students.xaml.cs">
<DependentUpon>Students.xaml</DependentUpon> <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 MongoDB.Driver;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
@ -28,6 +29,7 @@ namespace BuechermarktClient
public static IMongoCollection<BookType> BookTypeCollection; public static IMongoCollection<BookType> BookTypeCollection;
public static IMongoCollection<Book> BookCollection; public static IMongoCollection<Book> BookCollection;
public static IMongoCollection<Student> StudentCollection; public static IMongoCollection<Student> StudentCollection;
public const string DatabaseName = "buechermarkt";
public static string MongoHost = "localhost"; public static string MongoHost = "localhost";
public BookTypes BookTypesWindow = null; public BookTypes BookTypesWindow = null;
@ -36,16 +38,17 @@ namespace BuechermarktClient
public MainWindow() public MainWindow()
{ {
var s = new GetConnection();
s.ShowDialog();
InitializeComponent(); InitializeComponent();
OnConnectionEstablised("localhost"); OnConnectionEstablised();
//ToDo get server informations //ToDo get server informations
} }
public void OnConnectionEstablised(string hostname) public void OnConnectionEstablised()
{ {
MongoHost = hostname;
Mongo = new MongoClient("mongodb://" + MongoHost + ":27017"); Mongo = new MongoClient("mongodb://" + MongoHost + ":27017");
Database = Mongo.GetDatabase("buechermarkt"); Database = Mongo.GetDatabase(DatabaseName);
BookTypeCollection = Database.GetCollection<BookType>("booktypes"); BookTypeCollection = Database.GetCollection<BookType>("booktypes");
BookCollection = Database.GetCollection<Book>("books"); BookCollection = Database.GetCollection<Book>("books");
StudentCollection = Database.GetCollection<Student>("students"); StudentCollection = Database.GetCollection<Student>("students");

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