Add project files.

This commit is contained in:
Admin
2024-09-02 10:03:23 +07:00
parent 42def0d4aa
commit 6219298497
361 changed files with 58423 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Management;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
namespace SafeBagDE70.Services
{
public static class HardwareInforManager
{
public static string GetHardwareId()
{
string cpuId = GetCpuId();
string biosId = GetBiosId();
string motherboardId = GetMotherboardId();
// Combine the strings and create a hash
string combined = cpuId + biosId + motherboardId;
string hardwareId = CreateMD5Hash(combined);
return hardwareId;
}
public static string GetCpuId()
{
return GetHardwareInfo("Win32_Processor", "ProcessorId");
}
public static string GetBiosId()
{
return GetHardwareInfo("Win32_BIOS", "SerialNumber");
}
public static string GetMotherboardId()
{
return GetHardwareInfo("Win32_BaseBoard", "SerialNumber");
}
private static string GetHardwareInfo(string wmiClass, string wmiProperty)
{
try
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher($"select {wmiProperty} from {wmiClass}");
foreach (ManagementObject obj in searcher.Get())
{
return obj[wmiProperty]?.ToString() ?? string.Empty;
}
}
catch (Exception ex)
{
throw new Exception($"Failed to retrieve {wmiClass} {wmiProperty}: " + ex.Message);
}
return string.Empty;
}
private static string CreateMD5Hash(string input)
{
using (MD5 md5 = MD5.Create())
{
byte[] inputBytes = Encoding.ASCII.GetBytes(input);
byte[] hashBytes = md5.ComputeHash(inputBytes);
return string.Join("", hashBytes.Select(b => b.ToString("X2")));
}
}
}
}
+71
View File
@@ -0,0 +1,71 @@
using Custom.CuCustomWndAPI;
using HandyControl.Data;
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace SafeBagDE70.Services
{
public class PrinterManager
{
CuCustomWndDevice? dev = null;
CuCustomWndAPIWrap? customWndAPIWrap =null;
PrinterStatus? status = null;
public PrinterManager()
{
try
{
customWndAPIWrap = new CuCustomWndAPIWrap(CuCustomWndAPIWrap.CcwLogVerbosity.CCW_LOG_FATAL, null);
customWndAPIWrap.InitLibrary();
USBDevice[] usbArray = customWndAPIWrap.EnumUSBDevices();
dev = customWndAPIWrap.OpenPrinterUSB(usbArray[0]);
Log.Information("[PRINTER] Init Printer Successfully");
}
catch (Exception ex)
{
// System.Windows.MessageBox.Show(ex.ToString());
}
}
public PrinterStatus? GetStatus()
{
var status = dev.GetPrinterFullStatus();
return status;
}
public bool IsNearPaperOut()
{
try
{
var status = dev.GetPrinterFullStatus();
return status.StsNEARENDPAP;
}
catch(Exception ex)
{
return true;
}
}
public bool IsPaperOut()
{
try
{
var status = dev.GetPrinterFullStatus();
return status.StsNOPAPER;
}
catch (Exception ex)
{
return true;
}
}
public void Release()
{
if (dev != null)
dev.Terminate();
}
}
}
+69
View File
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace SafeBagDE70.Services
{
public static class SoundManager
{
private static MediaPlayer _mediaPlayer = new MediaPlayer();
private static Uri _audioFileUri;
private static bool _isWarningActive = false;
private static MediaPlayer _pressPlayer = new MediaPlayer();
private static Uri _audioPressFileUri;
static SoundManager()
{
var audioFilePath = "assets/audio/alarm.mp3";
_audioFileUri = new Uri(audioFilePath, UriKind.RelativeOrAbsolute);
_mediaPlayer.MediaEnded += MediaPlayer_MediaEnded;
var audioPressPath = "assets/audio/buttonpress.mp3";
_audioPressFileUri = new Uri(audioPressPath, UriKind.RelativeOrAbsolute);
//_pressPlayer.MediaEnded += _pressPlayer_MediaEnded; ;
}
private static void _pressPlayer_MediaEnded(object? sender, EventArgs e)
{
}
public static void StartButtonPressSound()
{
_pressPlayer.Open(_audioPressFileUri);
_pressPlayer.Play();
}
// Starts the continuous playback
public static void StartWarningSound()
{
if (!_isWarningActive)
{
_isWarningActive = true;
_mediaPlayer.Open(_audioFileUri);
_mediaPlayer.Play();
}
}
// Stops the playback
public static void StopWarningSound()
{
_mediaPlayer.Stop();
_isWarningActive= false;
}
// Handles the MediaEnded event to replay the audio
private static void MediaPlayer_MediaEnded(object sender, EventArgs e)
{
if (_isWarningActive)
{
_mediaPlayer.Position = TimeSpan.Zero;
_mediaPlayer.Play();
}
}
}
}
+40
View File
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace SafeBagDE70.Services
{
internal class WarningSoundManager2
{
private static bool _isWarningActive = false;
private static Thread _warningSoundThread;
public static void StartWarningSound()
{
if (!_isWarningActive)
{
_isWarningActive = true;
_warningSoundThread = new Thread(PlayWarningSound);
_warningSoundThread.IsBackground = true; // Ensure the thread stops when the application exits
_warningSoundThread.Start();
}
}
public static void StopWarningSound()
{
_isWarningActive = false;
}
private static void PlayWarningSound()
{
while (_isWarningActive)
{
Console.Beep(1200, 500); // Frequency: 1200 Hz, Duration: 500 ms
Thread.Sleep(500); // Pause for 500 ms before repeating for 100ms
}
}
}
}