5 Commits

Author SHA1 Message Date
f867ef6222 Exports werden in einem Export ordner abgelegt 2023-08-06 19:37:42 +02:00
778b4a9a64 Letzte Projekt wird beigehalten 2023-08-06 19:19:44 +02:00
ba3e10fd2d code cleanup 2023-08-06 16:25:26 +02:00
e54b875f1a Haltungsbezeichnung
beim auswahlen des Obere Schachtes wird automatisch die
Haltungsbezeichnung angepasst
2023-08-06 16:25:15 +02:00
16ac432831 Dongle abfrage hinzugefügt 2023-08-06 16:24:27 +02:00
16 changed files with 289 additions and 23 deletions

View File

@@ -12,4 +12,8 @@
<None Remove="Services\**" /> <None Remove="Services\**" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<PackageReference Include="Wibu.CodeMeter.WibuCmNET" Version="7.60.5615.502" />
</ItemGroup>
</Project> </Project>

View File

@@ -0,0 +1,203 @@
using CodeMeter;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SewerStammGen.Shared
{
public class DongleNotFoundException : Exception
{
}
public class WWRuntime : IDisposable
{
uint FirmCode;
uint ProductCode;
Api cmApi;
CmCredential cmCred;
CmAccess2 cmAcc;
HCMSysEntry hcmse;
CmBoxInfo cmBoxInfo;
CmBoxEntry2? BoxContent;
uint ExportCount;
public WWRuntime(uint ProductCode)
{
this.ProductCode = ProductCode;
FirmCode = 103086;
cmApi = new Api();
cmCred = new CmCredential();
cmAcc = new CmAccess2();
cmAcc.Credential = cmCred;
cmAcc.Ctrl |= CmAccess.Option.UserLimit;
cmAcc.FirmCode = FirmCode;
cmAcc.ProductCode = ProductCode;
hcmse = cmApi.CmAccess2(CmAccessOption.Local, cmAcc);
if(hcmse == null)
{
ErrorCodes2 code = cmApi.CmGetLastErrorCode2();
throw new DongleNotFoundException();
}
cmBoxInfo = new CmBoxInfo();
CmGetBoxContentsOption boxOptions = new CmGetBoxContentsOption();
boxOptions = CmGetBoxContentsOption.AllEntries;
CmBoxEntry2[] tmpBoxContent;
tmpBoxContent = cmApi.CmGetBoxContents2(hcmse, boxOptions, this.FirmCode, cmBoxInfo);
CmEntryData[] pCmBoxEntry = (CmEntryData[])cmApi.CmGetInfo(hcmse, CmGetInfoOption.EntryData);
for (int i = 0; i < pCmBoxEntry.Length; i++)
{
switch (pCmBoxEntry[i].Ctrl & 0x0ffff)
{
case (uint)CodeMeter.GlobalEntryOption.UserData:
{
ExportCount = BitConverter.ToUInt32(pCmBoxEntry[i].Data);
}
break;
case (uint)CodeMeter.GlobalEntryOption.ProtectedData:
// Transfer to transformed byte
uint length = pCmBoxEntry[i].DataLen;
byte[] datas = new byte[length];
for (uint f = 0; f < length; f++)
{
datas[f] = pCmBoxEntry[i].Data[f];
}
//SyncfusionKey = Encoding.ASCII.GetString(datas);
break;
}
}
foreach (CmBoxEntry2 boxes in tmpBoxContent)
{
if (boxes.ProductCode == this.ProductCode)
{
this.BoxContent = boxes;
}
}
}
public bool IsLicensed(byte neededMask)
{
uint DongleFeature = GetFeatureMap();
byte DongleFeatureB = (byte)DongleFeature;
if ((DongleFeatureB & neededMask) == neededMask)
return true;
return false;
}
private uint GetFeatureMap()
{
if (BoxContent == null) return 0;
return BoxContent.FeatureMap;
}
string GetDongleSerial()
{
CmBoxInfo res = (CmBoxInfo)cmApi.CmGetInfo(hcmse, CmGetInfoOption.BoxInfo);
if (null != res)
{
return res.SerialNumber.ToString();
}
else
{
throw new Exception("Fehler beim aufrufen der Seriennummer");
}
}
int GetExportCount()
{
return 0;
}
public void IncrementExportCounter()
{
ExportCount++;
writeExportCount(ExportCount);
}
public bool CheckDongleVorhanden()
{
return hcmse != null;
}
public void CleanDongle()
{
cmApi.CmRelease(hcmse);
}
private void writeExportCount(uint count)
{
CmCreatePioUserData cmCreatePioUserData = new CmCreatePioUserData();
CmProgramUpdateProductItem pcmUpdateProductItem = new CmProgramUpdateProductItem();
CmCreateItem hcmCreateItem = new CmCreateItem();
object pvPio = new object();
CmInternalEntryInfo[] cmInternalEntryData;
cmInternalEntryData = (CmInternalEntryInfo[])cmApi.CmGetInfo(hcmse, CmGetInfoOption.InternalEntryInfo);
byte[] newCount = BitConverter.GetBytes(count);
newCount.CopyTo(cmCreatePioUserData.Data, 0);
cmCreatePioUserData.DataLen = (ushort)newCount.Length;
pvPio = cmCreatePioUserData;
CmCreatePioProductCode cmPC = new CmCreatePioProductCode();
cmPC.TvbCtrl = (CmCreatePioProductCode.Option)0;
cmPC.ProductCode = ProductCode;
cmPC.FirmItemReference = cmInternalEntryData[0].FirmItemReference;
cmPC.ProductItemReference = cmInternalEntryData[0].ProductItemReference;
string? error;
bool res = cmApi.CmCreateProductItemOption(hcmse, CmCreateProductItemOptionOption.Update | CmCreateProductItemOptionOption.ProductCode, cmPC);
if(!res)
{
error = cmApi.CmGetLastErrorText();
return;
}
res = cmApi.CmCreateProductItemOption(hcmse, CmCreateProductItemOptionOption.UserData | CmCreateProductItemOptionOption.Terminate, pvPio);
if(!res)
{
error = cmApi.CmGetLastErrorText();
return;
}
hcmCreateItem.FirmCode = 103086;
hcmCreateItem.ProductCode = ProductCode;
byte[] sequence = cmApi.CmCreateSequence(hcmse, GlobalProgrammingOption.UpdateProductItem, ref hcmCreateItem, pcmUpdateProductItem);
res = cmApi.CmProgram(hcmse, GlobalProgrammingOption.UpdateProductItem, sequence);
if (!res)
{
error = cmApi.CmGetLastErrorText();
return;
}
}
public void Dispose()
{
CleanDongle();
}
}
}

View File

@@ -9,6 +9,9 @@ using System.Data;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using CodeMeter;
using SewerStammGen.Shared;
using System.Threading;
namespace StammGenerator namespace StammGenerator
{ {
@@ -20,7 +23,27 @@ namespace StammGenerator
private readonly IHost _host; private readonly IHost _host;
public App() public App()
{ {
_host = CreateHostBuilder().Build(); new Mutex(initiallyOwned: true, "Stammdatengenerator", out bool result);
if(!result)
{
MessageBox.Show("Bitte nur 1 Instanz der Software Starten!","Fehler", MessageBoxButton.OK, MessageBoxImage.Error);
Environment.Exit(0);
}
using (WWRuntime wWRuntime = new WWRuntime(21))
{
if(wWRuntime.CheckDongleVorhanden())
{
wWRuntime.CleanDongle();
_host = CreateHostBuilder().Build();
}
else
{
MessageBox.Show("Kein Dongle gefunden");
Environment.Exit(0);
}
}
} }
static IHostBuilder CreateHostBuilder(string[]? args = null) static IHostBuilder CreateHostBuilder(string[]? args = null)
@@ -34,10 +57,9 @@ namespace StammGenerator
protected override void OnStartup(StartupEventArgs e) protected override void OnStartup(StartupEventArgs e)
{ {
if (_host == null) return;
_host.Start(); _host.Start();
MainWindow? window = new MainWindow() { DataContext = _host.Services.GetRequiredService<MainWindowViewModel>() }; MainWindow? window = new MainWindow() { DataContext = _host.Services.GetRequiredService<MainWindowViewModel>() };
window.Show(); window.Show();

View File

@@ -1,4 +1,5 @@
using SewerStammGen.Shared.Contracts; using SewerStammGen.Shared;
using SewerStammGen.Shared.Contracts;
using SewerStammGen.Shared.Domain; using SewerStammGen.Shared.Domain;
using Shared.Contracts; using Shared.Contracts;
using StammGenerator.Commands; using StammGenerator.Commands;
@@ -6,6 +7,7 @@ using StammGenerator.ViewModel;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
@@ -39,13 +41,21 @@ namespace StammGenerator.Commands
IExport export = ExporterFactory.Export(_selectedProjekt.ExportType); IExport export = ExporterFactory.Export(_selectedProjekt.ExportType);
IEnumerable<Kanal> haltungen = await _haltungDataService.GetAllByProjekt(_selectedProjekt); IEnumerable<Kanal> haltungen = await _haltungDataService.GetAllByProjekt(_selectedProjekt);
IEnumerable<Schacht> schaechte = await _schachtDataService.GetAllByProjekt(_selectedProjekt); IEnumerable<Schacht> schaechte = await _schachtDataService.GetAllByProjekt(_selectedProjekt);
if(!Directory.Exists("./export/"))
{
Directory.CreateDirectory("./export/");
}
await export.Export(_selectedProjekt.Id.ToString(), _selectedProjekt.Kodierungssystem, haltungen.ToList(), schaechte.ToList(), wwLog); await export.Export("./export/"+_selectedProjekt.Id.ToString(), _selectedProjekt.Kodierungssystem, haltungen.ToList(), schaechte.ToList(), wwLog);
} }
catch(NotImplementedException) catch(NotImplementedException)
{ {
MessageBoxResult result = MessageBox.Show(string.Format("Schnittstelle Export format: {0} ist nicht Implementiert", _selectedProjekt.ExportType), "Fehlende Implementation", MessageBoxButton.OK, MessageBoxImage.Exclamation); MessageBoxResult result = MessageBox.Show(string.Format("Schnittstelle Export format: {0} ist nicht Implementiert", _selectedProjekt.ExportType), "Fehlende Implementation", MessageBoxButton.OK, MessageBoxImage.Exclamation);
} }
catch(DongleNotFoundException)
{
MessageBoxResult result = MessageBox.Show("Dongle nicht vorhanden");
}
} }
} }
} }

View File

@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:StammGenerator" xmlns:local="clr-namespace:StammGenerator"
mc:Ignorable="d" mc:Ignorable="d"
WindowState="Maximized"
xmlns:view="clr-namespace:StammGenerator.Views" xmlns:view="clr-namespace:StammGenerator.Views"
xmlns:viewmodel="clr-namespace:StammGenerator.ViewModel" xmlns:viewmodel="clr-namespace:StammGenerator.ViewModel"

View File

@@ -10,6 +10,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" /> <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" /> <PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="7.0.0" />
<PackageReference Include="Wibu.CodeMeter.WibuCmNET" Version="7.60.5615.502" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@@ -15,7 +15,7 @@ namespace StammGenerator.ViewModel
private readonly IActualState _actualState; private readonly IActualState _actualState;
private readonly IHaltungDataService _haltungDataService; private readonly IHaltungDataService _haltungDataService;
private readonly ISchachtDataService _schachtDataService; private readonly ISchachtDataService _schachtDataService;
private List<Schacht> avaibleSchaechte; private List<Schacht> avaibleSchaechte = new List<Schacht>();
private int _selectedObenIndex; private int _selectedObenIndex;
private int _selectedUntenIndex; private int _selectedUntenIndex;
private Kanal _model; private Kanal _model;
@@ -52,6 +52,7 @@ namespace StammGenerator.ViewModel
_selectedObenIndex = value; _selectedObenIndex = value;
_model.StartSchacht = avaibleSchaechte[value]; _model.StartSchacht = avaibleSchaechte[value];
RecalculateLength(); RecalculateLength();
Haltungsbezeichnung = _model.StartSchacht.Objektbezeichnung;
OnPropertyChanged(); OnPropertyChanged();
} }
} }

View File

@@ -42,18 +42,12 @@ namespace StammGenerator.ViewModel
UpdateCurrentViewModelCommand.Execute(EMainWindowViewType.Home); UpdateCurrentViewModelCommand.Execute(EMainWindowViewType.Home);
_actualState = actualState; _actualState = actualState;
_actualState.ProjektChanged += ActualState_ProjektChanged; _actualState.ProjektChanged += ActualState_ProjektChanged;
_actualState.LoadLastProjekt();
Navigator.StateChanged += Navigator_StateChanged; Navigator.StateChanged += Navigator_StateChanged;
#if DEBUG
_actualState.SetProjekt(new Projekt() { Id = 5 });
#endif
} }
private void ActualState_ProjektChanged(object? sender, EventArgs e) private void ActualState_ProjektChanged(object? sender, EventArgs e)

View File

@@ -1,4 +1,5 @@
using SewerStammGen.Shared.Domain; using Microsoft.Win32;
using SewerStammGen.Shared.Domain;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@@ -9,6 +10,10 @@ namespace StammGenerator.ViewModel
{ {
internal class ActualState : IActualState internal class ActualState : IActualState
{ {
const string userroot = "HKEY_CURRENT_USER\\Software";
const string firmkey = "WWTech";
const string subkey = "StammGenerator";
// TODO: set auf private set setzen // TODO: set auf private set setzen
public int ProjektID { get; set; } public int ProjektID { get; set; }
@@ -25,6 +30,9 @@ namespace StammGenerator.ViewModel
{ {
OnProjektChanged(); OnProjektChanged();
} }
string keyName = userroot + "\\" + firmkey + "\\" + subkey;
Registry.SetValue(keyName, "LastProjekt", ProjektID);
} }
public void SetSchacht(Schacht schacht, bool notification = true) public void SetSchacht(Schacht schacht, bool notification = true)
{ {
@@ -61,6 +69,17 @@ namespace StammGenerator.ViewModel
{ {
HaltungChanged?.Invoke(this, new EventArgs()); HaltungChanged?.Invoke(this, new EventArgs());
} }
public void LoadLastProjekt()
{
string keyName = userroot + "\\" + firmkey + "\\" + subkey;
if(Registry.GetValue(keyName,"LastProjekt","")!= null)
{
ProjektID = Convert.ToInt32(Registry.GetValue(keyName, "LastProjekt", ""));
OnProjektChanged();
}
}
} }
} }

View File

@@ -20,5 +20,7 @@ namespace StammGenerator.ViewModel
void SetProjekt(Projekt projekt, bool notification = true); void SetProjekt(Projekt projekt, bool notification = true);
void SetSchacht(Schacht schacht, bool notification = true); void SetSchacht(Schacht schacht, bool notification = true);
void SetHaltung(Kanal haltung, bool notification = true); void SetHaltung(Kanal haltung, bool notification = true);
void LoadLastProjekt();
} }
} }

View File

@@ -7,6 +7,6 @@
mc:Ignorable="d" mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<Grid> <Grid>
<TextBlock Text="Willkommen dieses Programm generiert Stammdaten für die TV Inspektion" /> <TextBlock Text="Version Test - 0.1" />
</Grid> </Grid>
</UserControl> </UserControl>

View File

@@ -1,4 +1,5 @@
using SewerStammGen.Shared.Domain; using SewerStammGen.Shared;
using SewerStammGen.Shared.Domain;
using SewerStammGen.Shared.Enum; using SewerStammGen.Shared.Enum;
using Shared.Contracts; using Shared.Contracts;
using System; using System;
@@ -16,6 +17,15 @@ namespace WWTech_KanalSchnittstelle.Exporter
{ {
public static IExport Export(EExportType exportType) public static IExport Export(EExportType exportType)
{ {
using(WWRuntime wWRuntime = new WWRuntime(21))
{
if(!wWRuntime.CheckDongleVorhanden())
{
throw new DongleNotFoundException();
}
wWRuntime.IncrementExportCounter();
wWRuntime.CleanDongle();
}
switch(exportType) switch(exportType)
{ {
case EExportType.KANDIS6: return new KANDIS60(); case EExportType.KANDIS6: return new KANDIS60();

View File

@@ -50,7 +50,7 @@ namespace WWTech_KanalSchnittstelle.Exporter.XML
DoAdmindata(xmlElement); DoAdmindata(xmlElement);
DoCollectives(xmlElement); DoCollectives(xmlElement);
_file.Save("test.xml"); _file.Save(projektname+".xml");
return true; return true;
} }

View File

@@ -50,7 +50,7 @@ namespace WWTech_KanalSchnittstelle.Exporter.XML
DoAdmindata(xmlElement); DoAdmindata(xmlElement);
DoCollectives(xmlElement); DoCollectives(xmlElement);
_file.Save("test.xml"); _file.Save(projektname + ".xml");
return true; return true;
} }

View File

@@ -50,7 +50,7 @@ namespace WWTech_KanalSchnittstelle.Exporter.XML
DoAdmindata(xmlElement); DoAdmindata(xmlElement);
DoCollectives(xmlElement); DoCollectives(xmlElement);
_file.Save("test.xml"); _file.Save(projektname + ".xml");
return true; return true;
} }

View File

@@ -100,7 +100,7 @@ namespace WWTech_KanalSchnittstelle.Importer
schacht.SohlHoehe = parseKoordinate(parsed[3]); schacht.SohlHoehe = parseKoordinate(parsed[3]);
} }
if (parsed.Length >= 4) if (parsed.Length > 4)
{ {
schacht.Entwaesserung = entwaesserungKennung[parsed[4]]; schacht.Entwaesserung = entwaesserungKennung[parsed[4]];
schacht.SchachtType = schachtKennung[parsed[4]]; schacht.SchachtType = schachtKennung[parsed[4]];