WIP daten als zip speichern

This commit is contained in:
Husky
2018-06-30 19:49:37 +02:00
parent 5a7dfc6189
commit f8a85bdc68
9 changed files with 220 additions and 19 deletions

View File

@@ -33,6 +33,10 @@ namespace Language
labels.Add("error_messages", "Fehlermeldungsarten"); labels.Add("error_messages", "Fehlermeldungsarten");
labels.Add("error_projwrong", "Projektnummer nicht vergeben"); labels.Add("error_projwrong", "Projektnummer nicht vergeben");
labels.Add("error_groundData", "Grunddaten sind nicht richtig vergeben"); labels.Add("error_groundData", "Grunddaten sind nicht richtig vergeben");
labels.Add("mainmenu_projekt", "&Projekt");
labels.Add("mainmenu_projekt_new", "&Neu");
labels.Add("mainmenu_projekt_open", "Ö&ffnen");
} }
} }

View File

@@ -30,8 +30,12 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="ICSharpCode.SharpZipLib, Version=0.86.0.518, Culture=neutral, PublicKeyToken=1b03e6acf1164f73, processorArchitecture=MSIL">
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.Xaml" /> <Reference Include="System.Xaml" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" /> <Reference Include="System.Data.DataSetExtensions" />
@@ -50,5 +54,8 @@
<Name>KlassenBIB</Name> <Name>KlassenBIB</Name>
</ProjectReference> </ProjectReference>
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project> </Project>

View File

@@ -5,11 +5,16 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Xaml; using System.Xaml;
using System.IO.Compression;
using System.Diagnostics;
using ICSharpCode.SharpZipLib.Zip;
using ICSharpCode.SharpZipLib.Core;
namespace Database namespace Database
{ {
public class Datenbank public class Datenbank
{ {
public const string pfad = "./";
public static readonly Datenbank instance = new Datenbank(); public static readonly Datenbank instance = new Datenbank();
public static Datenbank Instance public static Datenbank Instance
{ {
@@ -24,6 +29,8 @@ namespace Database
private string projektpfad = string.Empty; private string projektpfad = string.Empty;
public bool LoadProjekt(string filepath) public bool LoadProjekt(string filepath)
{ {
UnPackProject("18-850","willyteufelchen");
//PackSystem("./projekte/18-850.zip", "./projekte/18-850","willyteufelchen");
projektpfad = filepath; projektpfad = filepath;
if (File.Exists(filepath)) if (File.Exists(filepath))
loadedProjekt = XamlServices.Load(filepath) as KlassenBIB.Projekt; loadedProjekt = XamlServices.Load(filepath) as KlassenBIB.Projekt;
@@ -32,6 +39,130 @@ namespace Database
return true; return true;
} }
private void UnPackProject(string projekt, string password = "")
{
if (!Directory.Exists("./temp")) Directory.CreateDirectory("./temp");
ZipFile zf = null;
try
{
FileStream fs = File.OpenRead(Path.Combine("projekte", string.Format("{0}.zip", projekt)));
zf = new ZipFile(fs);
if (!password.Equals("")) zf.Password = password;
foreach(ZipEntry zipEntry in zf)
{
if (!zipEntry.IsFile) continue;
string entryFileName = zipEntry.Name;
byte[] buffer = new byte[4096];
Stream zipStream = zf.GetInputStream(zipEntry);
string fullZipToPath = Path.Combine("./temp/", entryFileName);
string directoryName = Path.GetDirectoryName(fullZipToPath);
if (directoryName.Length > 0) Directory.CreateDirectory(directoryName);
using (FileStream streamWriter = File.Create(fullZipToPath))
{
StreamUtils.Copy(zipStream, streamWriter, buffer);
}
}
}
finally
{
if(zf != null)
{
zf.IsStreamOwner = true;
zf.Close();
}
}
}
public bool CreateProjekt(string projektnummer)
{
string filepath = Path.Combine(pfad, projektnummer);
if (File.Exists(filepath)) return false;
using (MemoryStream memoryStream = new MemoryStream())
{
using (ZipArchive archive = new ZipArchive(memoryStream, ZipArchiveMode.Create, true))
{
var demoFile = archive.CreateEntry("daten/foo.txt");
using (var entryStream = demoFile.Open())
{
XamlServices.Save(entryStream, loadedProjekt);
}
}
using (var fileStream = new FileStream("./test.zip", FileMode.Create))
{
memoryStream.Seek(0, SeekOrigin.Begin);
memoryStream.CopyTo(fileStream);
}
}
return true;
}
private void PackSystem(string outPathName, string folderName, string password = "")
{
FileStream fsOut = File.Create(outPathName);
ZipOutputStream zipStream = new ZipOutputStream(fsOut);
zipStream.SetLevel(3);
if (!password.Equals("")) zipStream.Password = password;
int folderOffset = folderName.Length +(folderName.EndsWith("\\") ? 0 : 1);
CompressFolder(folderName, zipStream, folderOffset);
zipStream.IsStreamOwner = true;
zipStream.Close();
}
private void CompressFolder(string path, ZipOutputStream zipStream, int folderOffset)
{
string[] files = Directory.GetFiles(path);
foreach(string filename in files)
{
FileInfo fi = new FileInfo(filename);
string entryName = filename.Substring(folderOffset);
entryName = ZipEntry.CleanName(entryName);
ZipEntry newEntry = new ZipEntry(entryName);
newEntry.DateTime = fi.LastWriteTime;
newEntry.Size = fi.Length;
zipStream.PutNextEntry(newEntry);
byte[] buffer = new byte[4096];
using (FileStream streamReader = File.OpenRead(filename))
{
StreamUtils.Copy(streamReader, zipStream, buffer);
}
zipStream.CloseEntry();
}
string[] folders = Directory.GetDirectories(path);
foreach(string folder in folders)
{
CompressFolder(folder, zipStream, folderOffset);
}
}
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() public void SaveProjekt()
{ {
XamlServices.Save(projektpfad, loadedProjekt); XamlServices.Save(projektpfad, loadedProjekt);

4
Database/packages.config Normal file
View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="SharpZipLib" version="0.86.0" targetFramework="net461" />
</packages>

View File

@@ -32,6 +32,9 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Ionic.Zip, Version=1.9.1.8, Culture=neutral, PublicKeyToken=edbe51ad942a3f5c, processorArchitecture=MSIL">
<HintPath>..\packages\Ionic.Zip.1.9.1.8\lib\Ionic.Zip.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@@ -93,6 +96,7 @@
<AutoGen>True</AutoGen> <AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon> <DependentUpon>Resources.resx</DependentUpon>
</Compile> </Compile>
<None Include="packages.config" />
<None Include="Properties\DataSources\KlassenBIB.Strasse.datasource" /> <None Include="Properties\DataSources\KlassenBIB.Strasse.datasource" />
<None Include="Properties\Settings.settings"> <None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator> <Generator>SettingsSingleFileGenerator</Generator>

View File

@@ -28,23 +28,71 @@
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
this.mainmenu = new System.Windows.Forms.MenuStrip();
this.projektToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.neuToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.öffnenToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.mainmenu.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
// frm_main // mainmenu
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 16F); this.mainmenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.projektToolStripMenuItem});
this.mainmenu.Location = new System.Drawing.Point(0, 0);
this.mainmenu.Name = "mainmenu";
this.mainmenu.Size = new System.Drawing.Size(596, 24);
this.mainmenu.TabIndex = 1;
this.mainmenu.Text = "menuStrip1";
//
// projektToolStripMenuItem
//
this.projektToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.neuToolStripMenuItem,
this.öffnenToolStripMenuItem});
this.projektToolStripMenuItem.Name = "projektToolStripMenuItem";
this.projektToolStripMenuItem.Size = new System.Drawing.Size(56, 20);
this.projektToolStripMenuItem.Text = "Projekt";
//
// neuToolStripMenuItem
//
this.neuToolStripMenuItem.Name = "neuToolStripMenuItem";
this.neuToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.neuToolStripMenuItem.Text = "Neu";
this.neuToolStripMenuItem.Click += new System.EventHandler(this.neuToolStripMenuItem_Click);
//
// öffnenToolStripMenuItem
//
this.öffnenToolStripMenuItem.Name = "öffnenToolStripMenuItem";
this.öffnenToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.öffnenToolStripMenuItem.Text = "Öffnen";
//
// frmMain
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(795, 459); this.ClientSize = new System.Drawing.Size(596, 373);
this.Controls.Add(this.mainmenu);
this.IsMdiContainer = true; this.IsMdiContainer = true;
this.Name = "frm_main"; this.MainMenuStrip = this.mainmenu;
this.Margin = new System.Windows.Forms.Padding(2, 2, 2, 2);
this.Name = "frmMain";
this.Text = "Kanalsanierungsverwaltung"; this.Text = "Kanalsanierungsverwaltung";
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frm_main_FormClosing); this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.frm_main_FormClosing);
this.Load += new System.EventHandler(this.frm_main_Load); this.Load += new System.EventHandler(this.frm_main_Load);
this.mainmenu.ResumeLayout(false);
this.mainmenu.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout();
} }
#endregion #endregion
private System.Windows.Forms.MenuStrip mainmenu;
private System.Windows.Forms.ToolStripMenuItem projektToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem neuToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem öffnenToolStripMenuItem;
} }
} }

View File

@@ -18,28 +18,19 @@ namespace SanSystem
{ {
InitializeComponent(); InitializeComponent();
Datenbank.Instance.LoadProjekt("projekt1.xaml"); Datenbank.Instance.LoadProjekt("projekt1.xaml");
Datenbank.Instance.CreateProjekt("");
this.Width = Screen.PrimaryScreen.WorkingArea.Width; this.Width = Screen.PrimaryScreen.WorkingArea.Width;
this.Height = Screen.PrimaryScreen.WorkingArea.Height; this.Height = Screen.PrimaryScreen.WorkingArea.Height;
this.WindowState = FormWindowState.Maximized; this.WindowState = FormWindowState.Maximized;
this.StartPosition = FormStartPosition.Manual; this.StartPosition = FormStartPosition.Manual;
this.Location = new Point(0, 0); this.Location = new Point(0, 0);
projektToolStripMenuItem.Text = Global.Instance.language.Labels["mainmenu_projekt"];
neuToolStripMenuItem.Text = Global.Instance.language.Labels["mainmenu_projekt_new"];
öffnenToolStripMenuItem.Text = Global.Instance.language.Labels["mainmenu_projekt_open"];
} }
private void button1_Click(object sender, EventArgs e)
{
Projekt projekt = Datenbank.Instance.loadedProjekt;
//dresseCollection adressen = projekt.Adressen;
/*
adressen[0].Objekte.Add(new Inspektionsobjekt()
{
Objektbezeichnung = "SW01"
});
*/
Datenbank.Instance.SaveProjekt();
}
private void frm_main_Load(object sender, EventArgs e) private void frm_main_Load(object sender, EventArgs e)
{ {
@@ -56,5 +47,10 @@ namespace SanSystem
{ {
Datenbank.Instance.SaveProjekt(); Datenbank.Instance.SaveProjekt();
} }
private void neuToolStripMenuItem_Click(object sender, EventArgs e)
{
}
} }
} }

View File

@@ -117,4 +117,7 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="mainmenu.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root> </root>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Ionic.Zip" version="1.9.1.8" targetFramework="net461" />
</packages>