133 lines
4.3 KiB
C#
133 lines
4.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xaml;
|
|
using System.IO.Compression;
|
|
using System.Diagnostics;
|
|
using ICSharpCode.SharpZipLib.Zip;
|
|
using ICSharpCode.SharpZipLib.Core;
|
|
using KlassenBIB;
|
|
using SanShared.Exceptions;
|
|
|
|
namespace Database
|
|
{
|
|
public class Datenbank
|
|
{
|
|
public const string pfad = "./";
|
|
public string projekt;
|
|
public static readonly Datenbank instance = new Datenbank();
|
|
public static Datenbank Instance
|
|
{
|
|
get
|
|
{
|
|
return instance;
|
|
}
|
|
}
|
|
|
|
public KlassenBIB.Projekt loadedProjekt = null;
|
|
public KlassenBIB.MainDataBase MainDatenbank = null;
|
|
public KlassenBIB.DB TeufelDB = null;
|
|
|
|
public Datenbank()
|
|
{
|
|
TeufelDB = new KlassenBIB.DB();
|
|
string filepath = "";
|
|
filepath = Path.Combine("./projekte", "TeufelDB.xaml");
|
|
if(File.Exists(filepath))
|
|
TeufelDB = XamlServices.Load("./projekte/TeufelDB.xaml") as KlassenBIB.DB;
|
|
|
|
//Debugger.Break();
|
|
filepath = Path.Combine("./projekte","MainDatenbank.xaml");
|
|
if(File.Exists(filepath))
|
|
{
|
|
MainDatenbank = XamlServices.Load(filepath) as KlassenBIB.MainDataBase;
|
|
}
|
|
else
|
|
{
|
|
MainDatenbank = new MainDataBase();
|
|
}
|
|
}
|
|
|
|
private string projektpfad = string.Empty;
|
|
public bool LoadProjekt(string projekt)
|
|
{
|
|
this.projekt = projekt;
|
|
loadedProjekt = Datenbank.Instance.TeufelDB.Projekte.Find(x => x.Nummer != null && x.Nummer.Equals(projekt));
|
|
//Debugger.Break();
|
|
//UnPackProject("18-850","willyteufelchen");
|
|
//PackSystem("./projekte/18-850.zip", "./projekte/18-850","willyteufelchen");
|
|
|
|
/*
|
|
string filepath = Path.Combine(projektpfad, string.Format("{0}.xaml", projekt));
|
|
this.projektpfad = filepath;
|
|
if (File.Exists(filepath))
|
|
{
|
|
File.Copy(filepath, string.Format("{0}_{1}_{2}.bak", filepath,DateTime.Now.ToShortDateString(),DateTime.Now.Ticks));
|
|
try
|
|
{
|
|
loadedProjekt = XamlServices.Load(filepath) as KlassenBIB.Projekt;
|
|
}
|
|
catch(XamlObjectWriterException ex)
|
|
{
|
|
if (ex.HResult.Equals(-2146233088))
|
|
throw new DataBaseVersionMismatchException(ex.Message);
|
|
|
|
}
|
|
}
|
|
else
|
|
loadedProjekt = new KlassenBIB.Projekt();
|
|
|
|
*/
|
|
if (!File.Exists("./projekte/TeufelDB.xaml"))
|
|
{
|
|
UpdateDatabase.UpdateNewGuids();
|
|
UpdateDatabase.TransferSanierteObjekte();
|
|
UpdateDatabase.TransferAuftraggeber();
|
|
UpdateDatabase.MakeNewDatabaseSystem();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool InitProjekt(Projekt projekt,string projektpfad)
|
|
{
|
|
this.projektpfad = Path.Combine(projektpfad,string.Format("{0}.xaml",projekt.Nummer));
|
|
loadedProjekt = projekt;
|
|
SaveProjekt();
|
|
return true;
|
|
}
|
|
|
|
|
|
public void Test()
|
|
{
|
|
|
|
|
|
using (MemoryStream memoryStream = new MemoryStream())
|
|
{
|
|
using (var fileStream = new FileStream("./test.zip", FileMode.Open))
|
|
{
|
|
fileStream.Seek(0, SeekOrigin.Begin);
|
|
fileStream.CopyTo(memoryStream);
|
|
}
|
|
using (ZipArchive archive = new ZipArchive(memoryStream, ZipArchiveMode.Update, true))
|
|
{
|
|
ZipArchiveEntry test = archive.CreateEntry("./datas/test.txt");
|
|
Debugger.Break();
|
|
}
|
|
|
|
Debugger.Break();
|
|
}
|
|
}
|
|
|
|
public void SaveProjekt()
|
|
{
|
|
//XamlServices.Save("./projekte/MainDatenbank.xaml", MainDatenbank);
|
|
//XamlServices.Save(projektpfad, loadedProjekt);
|
|
XamlServices.Save("./projekte/TeufelDB.xaml", TeufelDB);
|
|
}
|
|
}
|
|
}
|