Dongle abfrage hinzugefügt
This commit is contained in:
@@ -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>
|
||||||
|
|||||||
203
SewerStammGen.Shared/WWRuntime.cs
Normal file
203
SewerStammGen.Shared/WWRuntime.cs
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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,8 +23,28 @@ namespace StammGenerator
|
|||||||
private readonly IHost _host;
|
private readonly IHost _host;
|
||||||
public App()
|
public App()
|
||||||
{
|
{
|
||||||
|
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();
|
_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();
|
||||||
|
|
||||||
|
|||||||
@@ -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;
|
||||||
@@ -46,6 +47,10 @@ namespace StammGenerator.Commands
|
|||||||
{
|
{
|
||||||
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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>
|
||||||
|
|||||||
@@ -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();
|
||||||
|
|||||||
@@ -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]];
|
||||||
|
|||||||
Reference in New Issue
Block a user