initial
This commit is contained in:
102
libs/ConvertHelper.cs
Normal file
102
libs/ConvertHelper.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
using C4IT_CustomerPanel.Properties;
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
|
||||
public static class ConverterHelper
|
||||
{
|
||||
|
||||
|
||||
public static System.Windows.Controls.Image ConvertImageToWpfImage(System.Drawing.Image image)
|
||||
{
|
||||
if (image == null)
|
||||
throw new ArgumentNullException(nameof(image), Resources.Converter_ConvertImageToWpfImage_Image_darf_nicht_null_sein_);
|
||||
|
||||
using (System.Drawing.Bitmap dImg = new System.Drawing.Bitmap(image))
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
|
||||
|
||||
System.Windows.Media.Imaging.BitmapImage bImg = new System.Windows.Media.Imaging.BitmapImage();
|
||||
|
||||
bImg.BeginInit();
|
||||
bImg.StreamSource = new MemoryStream(ms.ToArray());
|
||||
bImg.EndInit();
|
||||
|
||||
System.Windows.Controls.Image img = new System.Windows.Controls.Image { Source = bImg };
|
||||
|
||||
return img;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static System.Drawing.Image ConvertWpfImageToImage(System.Windows.Controls.Image image)
|
||||
{
|
||||
if (image == null)
|
||||
throw new ArgumentNullException(nameof(image), Resources.Converter_ConvertImageToWpfImage_Image_darf_nicht_null_sein_);
|
||||
|
||||
System.Windows.Media.Imaging.BmpBitmapEncoder encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
|
||||
MemoryStream ms = new MemoryStream();
|
||||
encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create((System.Windows.Media.Imaging.BitmapSource)image.Source));
|
||||
encoder.Save(ms);
|
||||
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static bool ObjectToBoolConverter(object source)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (source == null)
|
||||
return false;
|
||||
|
||||
if (source.Equals("1"))
|
||||
{
|
||||
source = 1;
|
||||
}
|
||||
return Convert.ToBoolean(source);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static int ObjectToIntConverter(object source)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Convert.ToInt32(source);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
public static string ObjectToStringConverter(this object value)
|
||||
{
|
||||
return (value ?? string.Empty).ToString();
|
||||
}
|
||||
|
||||
public static Color ColorConvertFromString(string color)
|
||||
{
|
||||
var convertFromString = ColorConverter.ConvertFromString(color);
|
||||
if (convertFromString != null)
|
||||
{
|
||||
return (Color)convertFromString;
|
||||
}
|
||||
return Colors.White;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
19
libs/Disposer.cs
Normal file
19
libs/Disposer.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
static class Disposer
|
||||
{
|
||||
public static void DisposeAll(this Object clx)
|
||||
{
|
||||
IDisposable disposeable = clx as IDisposable;
|
||||
if (disposeable != null)
|
||||
disposeable.Dispose();
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
47
libs/UserInfo.cs
Normal file
47
libs/UserInfo.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using C4IT.Security;
|
||||
using C4IT.API.Contracts;
|
||||
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
public class UserInfo
|
||||
{
|
||||
public static UserInfo UserInfoInstance = null;
|
||||
|
||||
public string Id { get; set; }
|
||||
public string Email { get; set; }
|
||||
public string EncryptedApiToken { get; set; }
|
||||
public DateTime LoginDate { get; set; }
|
||||
public DateTime ExpirationDate { get; set; }
|
||||
|
||||
public UserInfo()
|
||||
{
|
||||
UserInfoInstance = this;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
// Nur die ersten X Zeichen des Tokens anzeigen
|
||||
const int tokenVisibleLength = 10;
|
||||
string maskedToken;
|
||||
|
||||
if (string.IsNullOrEmpty(EncryptedApiToken))
|
||||
{
|
||||
maskedToken = "(null or empty)";
|
||||
}
|
||||
else
|
||||
{
|
||||
var displayLength = Math.Min(tokenVisibleLength, EncryptedApiToken.Length);
|
||||
maskedToken = EncryptedApiToken.Substring(0, displayLength)
|
||||
+ new string('*', Math.Max(0, EncryptedApiToken.Length - displayLength));
|
||||
}
|
||||
|
||||
return $"UserInfo => Id: {Id}, " +
|
||||
$"Email: {Email}, " +
|
||||
$"Token: {maskedToken}, " +
|
||||
$"LoginDate: {LoginDate:u}, " +
|
||||
$"ExpirationDate: {ExpirationDate:u}";
|
||||
}
|
||||
}
|
||||
}
|
||||
1806
libs/configHelper.cs
Normal file
1806
libs/configHelper.cs
Normal file
File diff suppressed because it is too large
Load Diff
105
libs/converter.cs
Normal file
105
libs/converter.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Markup;
|
||||
using C4IT_CustomerPanel.Properties;
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
|
||||
public class Converter
|
||||
{
|
||||
|
||||
|
||||
public static System.Windows.Controls.Image ConvertImageToWpfImage(System.Drawing.Image image)
|
||||
{
|
||||
if (image == null)
|
||||
throw new ArgumentNullException(nameof(image), Resources.Converter_ConvertImageToWpfImage_Image_darf_nicht_null_sein_);
|
||||
|
||||
using (System.Drawing.Bitmap dImg = new System.Drawing.Bitmap(image))
|
||||
{
|
||||
using (MemoryStream ms = new MemoryStream())
|
||||
{
|
||||
dImg.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);
|
||||
|
||||
System.Windows.Media.Imaging.BitmapImage bImg = new System.Windows.Media.Imaging.BitmapImage();
|
||||
|
||||
bImg.BeginInit();
|
||||
bImg.StreamSource = new MemoryStream(ms.ToArray());
|
||||
bImg.EndInit();
|
||||
|
||||
System.Windows.Controls.Image img = new System.Windows.Controls.Image {Source = bImg};
|
||||
|
||||
return img;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static System.Drawing.Image ConvertWpfImageToImage(System.Windows.Controls.Image image)
|
||||
{
|
||||
if (image == null)
|
||||
throw new ArgumentNullException(nameof(image), Resources.Converter_ConvertImageToWpfImage_Image_darf_nicht_null_sein_);
|
||||
|
||||
System.Windows.Media.Imaging.BmpBitmapEncoder encoder = new System.Windows.Media.Imaging.BmpBitmapEncoder();
|
||||
MemoryStream ms = new MemoryStream();
|
||||
encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create((System.Windows.Media.Imaging.BitmapSource)image.Source));
|
||||
encoder.Save(ms);
|
||||
System.Drawing.Image img = System.Drawing.Image.FromStream(ms);
|
||||
return img;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Remove HTML from string with Regex.
|
||||
/// </summary>
|
||||
public static string StripTagsRegex(string source)
|
||||
{
|
||||
string test = source.Replace(" ", " ");
|
||||
return Regex.Replace(test, "<.*?>", string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Compiled regular expression for performance.
|
||||
/// </summary>
|
||||
readonly Regex _htmlRegex = new Regex("<.*?>", RegexOptions.Compiled);
|
||||
|
||||
/// <summary>
|
||||
/// Remove HTML from string with compiled Regex.
|
||||
/// </summary>
|
||||
public string StripTagsRegexCompiled(string source)
|
||||
{
|
||||
return _htmlRegex.Replace(source, string.Empty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove HTML tags from string using char array.
|
||||
/// </summary>
|
||||
public string StripTagsCharArray(string source)
|
||||
{
|
||||
char[] array = new char[source.Length];
|
||||
int arrayIndex = 0;
|
||||
bool inside = false;
|
||||
|
||||
foreach (char @let in source)
|
||||
{
|
||||
if (@let == '<')
|
||||
{
|
||||
inside = true;
|
||||
continue;
|
||||
}
|
||||
if (@let == '>')
|
||||
{
|
||||
inside = false;
|
||||
continue;
|
||||
}
|
||||
if (!inside)
|
||||
{
|
||||
array[arrayIndex] = @let;
|
||||
arrayIndex++;
|
||||
}
|
||||
}
|
||||
return new string(array, 0, arrayIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
libs/enumsCP.cs
Normal file
20
libs/enumsCP.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
public enum SlideInMethode { Diagonal, Leftright, Bottomtop };
|
||||
|
||||
public enum TaskBarLocation { Top, Bottom, Left, Right };
|
||||
|
||||
public enum MenuItems { Announcement = 0, Information, Ssp, Incident, CustomLink, M42Authentication, Config, Close, Report, langDE, langUS, langOS, pmodeOS, pmodeOff, pmodeOn};
|
||||
|
||||
public enum apiModul
|
||||
{
|
||||
Announcement = 0,
|
||||
Incident,
|
||||
ServerSetup,
|
||||
None
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
234
libs/formHelper.cs
Normal file
234
libs/formHelper.cs
Normal file
@@ -0,0 +1,234 @@
|
||||
using System;
|
||||
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media.Effects;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Reflection;
|
||||
|
||||
|
||||
using C4IT.Logging;
|
||||
using C4IT.Graphics;
|
||||
using static C4IT.Logging.cLogManager;
|
||||
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
|
||||
class FormHelper
|
||||
{
|
||||
|
||||
public static TaskBarLocation GetTaskBarLocation()
|
||||
{
|
||||
var Screens = System.Windows.Forms.Screen.AllScreens;
|
||||
if (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Left > 0)
|
||||
return TaskBarLocation.Left;
|
||||
if (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Top > 0)
|
||||
return TaskBarLocation.Top;
|
||||
if (System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Left == 0
|
||||
&& System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Width < System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width)
|
||||
return TaskBarLocation.Right;
|
||||
return TaskBarLocation.Bottom;
|
||||
}
|
||||
|
||||
|
||||
public static Point CenterOfScreen()
|
||||
{
|
||||
|
||||
System.Drawing.Rectangle screenRect = System.Windows.Forms.Screen.PrimaryScreen.Bounds;
|
||||
// get the Screen Boundy
|
||||
Size clientSize = new Size(screenRect.Width / 2, screenRect.Height / 2); // set the size of the form
|
||||
Point location = new Point(screenRect.Width / 2 - clientSize.Width / 2, screenRect.Height / 2 - clientSize.Height / 2);
|
||||
return location;
|
||||
}
|
||||
|
||||
public static System.Windows.Point GetLocation(int formWidth, int formHeight, double scaleDPI)
|
||||
{
|
||||
var CM = MethodBase.GetCurrentMethod();
|
||||
LogMethodBegin(CM);
|
||||
try
|
||||
{
|
||||
TaskBarLocation taskBarloc = GetTaskBarLocation();
|
||||
System.Windows.Point p = new System.Windows.Point((int)(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right / scaleDPI) - formWidth,
|
||||
(int)(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom / scaleDPI) - formHeight);
|
||||
switch (taskBarloc)
|
||||
{
|
||||
case TaskBarLocation.Bottom:
|
||||
p.X = (int)(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right) - formWidth;
|
||||
p.Y = (int)(System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom) - formHeight;
|
||||
break;
|
||||
case TaskBarLocation.Top:
|
||||
p.X = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - formWidth;
|
||||
p.Y = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Top;
|
||||
break;
|
||||
case TaskBarLocation.Left:
|
||||
p.X = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Left;
|
||||
p.Y = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom - formHeight;
|
||||
|
||||
break;
|
||||
case TaskBarLocation.Right:
|
||||
p.X = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right - formWidth;
|
||||
p.Y = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom - formHeight;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
var lstLogs = new List<string>()
|
||||
{
|
||||
"Window position determination:",
|
||||
" logical coordinates:",
|
||||
string.Format(" Working area: ({0},{1})-({2},{3})", System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Left, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Top, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom),
|
||||
string.Format(" Window size: {0},{1}", formWidth, formHeight),
|
||||
string.Format(" Resuling taskbar location: {0}", taskBarloc.ToString()),
|
||||
string.Format(" Resulting Window Position: {0},{1}", p.X, p.Y),
|
||||
" physical dimensions:",
|
||||
};
|
||||
|
||||
foreach (var scr in System.Windows.Forms.Screen.AllScreens)
|
||||
{
|
||||
var Scaling = NotifyerSupport.GetScaling(scr);
|
||||
var DPI = NotifyerSupport.GetDPI(scr);
|
||||
lstLogs.Add(String.Format(" {0}: ({1},{2})-({3},{4}), {5} DPI = x{6}", scr.DeviceName, scr.Bounds.Left, scr.Bounds.Top, scr.Bounds.Right, scr.Bounds.Bottom, DPI, Scaling));
|
||||
}
|
||||
|
||||
cLogManager.DefaultLogger.LogList(LogLevels.Debug, lstLogs);
|
||||
|
||||
|
||||
return p;
|
||||
}
|
||||
catch (Exception E)
|
||||
{
|
||||
LogException(E);
|
||||
throw;
|
||||
}
|
||||
finally
|
||||
{
|
||||
LogMethodEnd(CM);
|
||||
}
|
||||
}
|
||||
|
||||
public static DropShadowEffect GetDropShadow()
|
||||
{
|
||||
DropShadowEffect myDropShadowEffect = new DropShadowEffect();
|
||||
//DropShadowBitmapEffect myDropShadowEffect = new DropShadowBitmapEffect();
|
||||
|
||||
// Set the color of the shadow to Black.
|
||||
Color myShadowColor = new Color
|
||||
{
|
||||
ScA = 1,
|
||||
ScB = 0,
|
||||
ScG = 0,
|
||||
ScR = 0
|
||||
};
|
||||
// Note that the alpha value is ignored by Color property. The Opacity property is used to control the alpha.
|
||||
myDropShadowEffect.Color = myShadowColor;
|
||||
|
||||
// Set the direction of where the shadow is cast to 320 degrees.
|
||||
myDropShadowEffect.Direction = 320;
|
||||
|
||||
// Set the depth of the shadow being cast.
|
||||
myDropShadowEffect.ShadowDepth = 5;
|
||||
|
||||
// Set the shadow opacity to half opaque or in other words - half transparent.
|
||||
// The range is 0-1.
|
||||
myDropShadowEffect.Opacity = 0.5;
|
||||
return myDropShadowEffect;
|
||||
}
|
||||
|
||||
|
||||
public static System.Drawing.Icon GetNewsIcon(System.Drawing.Icon originalIcon)
|
||||
{
|
||||
|
||||
System.Drawing.Graphics canvas;
|
||||
System.Drawing.Bitmap iconBitmap = new System.Drawing.Bitmap(32, 32);
|
||||
canvas = System.Drawing.Graphics.FromImage(iconBitmap);
|
||||
|
||||
canvas.DrawIcon(originalIcon, 0, 0);
|
||||
|
||||
System.Drawing.SolidBrush redBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Green);
|
||||
|
||||
// Create location and size of ellipse.
|
||||
int x = 16;
|
||||
int y = 16;
|
||||
int width = 16;
|
||||
int height = 16;
|
||||
|
||||
// Fill ellipse on screen.
|
||||
canvas.FillEllipse(redBrush, x, y, width, height);
|
||||
canvas.Dispose();
|
||||
return System.Drawing.Icon.FromHandle(iconBitmap.GetHicon());
|
||||
}
|
||||
|
||||
public static System.Drawing.Icon GetErrorIcon(System.Drawing.Icon originalIcon)
|
||||
{
|
||||
|
||||
System.Drawing.Graphics canvas;
|
||||
System.Drawing.Bitmap iconBitmap = new System.Drawing.Bitmap(32, 32);
|
||||
System.Drawing.Bitmap errBitmap = new System.Drawing.Bitmap(32, 32);
|
||||
canvas = System.Drawing.Graphics.FromImage(iconBitmap);
|
||||
|
||||
canvas.DrawIcon(originalIcon, 0, 0);
|
||||
|
||||
System.Drawing.SolidBrush orangeBrush = new System.Drawing.SolidBrush(System.Drawing.Color.Red);
|
||||
|
||||
// Create location and size of ellipse.
|
||||
int x = 16;
|
||||
int y = 16;
|
||||
int width = 16;
|
||||
int height = 16;
|
||||
|
||||
|
||||
// Fill ellipse on screen.
|
||||
canvas.FillEllipse(orangeBrush, x, y, width, height);
|
||||
|
||||
canvas.Dispose();
|
||||
return System.Drawing.Icon.FromHandle(iconBitmap.GetHicon());
|
||||
}
|
||||
|
||||
public static bool GetIsFlickering(UIElement element)
|
||||
{
|
||||
return (bool)element.GetValue(IsFlickeringProperty);
|
||||
}
|
||||
|
||||
public static void FlickeringDisconnectImage(UIElement element, bool value)
|
||||
{
|
||||
element.Visibility = value ? Visibility.Visible : Visibility.Hidden;
|
||||
element.SetValue(IsFlickeringProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsFlickeringProperty =
|
||||
DependencyProperty.RegisterAttached("IsFlickering", typeof(bool), typeof(FormHelper), new UIPropertyMetadata(false, FlickeringDisconnectImageChanged));
|
||||
|
||||
static void FlickeringDisconnectImageChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if ((bool)e.NewValue)
|
||||
StartAnimation(d as UIElement);
|
||||
else
|
||||
StopAnimation(d as UIElement);
|
||||
}
|
||||
|
||||
private static void StartAnimation(UIElement element)
|
||||
{
|
||||
DoubleAnimation da = new DoubleAnimation
|
||||
{
|
||||
From = 1,
|
||||
To = 0,
|
||||
Duration = new Duration(TimeSpan.FromSeconds(2)),
|
||||
AutoReverse = true,
|
||||
RepeatBehavior = RepeatBehavior.Forever
|
||||
};
|
||||
element.BeginAnimation(UIElement.OpacityProperty, da);
|
||||
}
|
||||
|
||||
private static void StopAnimation(UIElement element)
|
||||
{
|
||||
element.BeginAnimation(UIElement.OpacityProperty, null);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
151
libs/informationHelper.cs
Normal file
151
libs/informationHelper.cs
Normal file
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Data;
|
||||
using System.IO;
|
||||
using System.Management;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
public class InformationHelper
|
||||
|
||||
{
|
||||
private enum QUERY_USER_NOTIFICATION_STATE
|
||||
{
|
||||
QUNS_NOT_PRESENT = 1,
|
||||
QUNS_BUSY = 2,
|
||||
QUNS_RUNNING_D3D_FULL_SCREEN = 3,
|
||||
QUNS_PRESENTATION_MODE = 4,
|
||||
QUNS_ACCEPTS_NOTIFICATIONS = 5,
|
||||
QUNS_QUIET_TIME = 6
|
||||
};
|
||||
|
||||
public static DateTime GetLastReboot()
|
||||
{
|
||||
SelectQuery query =
|
||||
|
||||
new SelectQuery("SELECT LastBootUpTime FROM Win32_OperatingSystem WHERE Primary = 'true'");
|
||||
|
||||
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
|
||||
DateTime dtBootTime = DateTime.Now;
|
||||
foreach (var o in searcher.Get())
|
||||
|
||||
{
|
||||
var mo = (ManagementObject)o;
|
||||
|
||||
dtBootTime = ManagementDateTimeConverter.ToDateTime(mo.Properties["LastBootUpTime"].Value.ToString());
|
||||
}
|
||||
return dtBootTime;
|
||||
|
||||
}
|
||||
|
||||
public static decimal getCPUTemp()
|
||||
{
|
||||
|
||||
SelectQuery query =
|
||||
|
||||
new SelectQuery("SELECT CurrentTemperature FROM Win32_TemperatureProbe");
|
||||
|
||||
|
||||
ManagementObjectSearcher searcher = new ManagementObjectSearcher(query);
|
||||
|
||||
|
||||
|
||||
foreach (var o in searcher.Get())
|
||||
{
|
||||
|
||||
var mo = (ManagementBaseObject)o;
|
||||
return (decimal.Parse(mo["CurrentTemperature"].ToString()) / 10 - 273.15m);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static string GetLanguageString(int language)
|
||||
{
|
||||
string lang;
|
||||
switch (language)
|
||||
{
|
||||
case 1031:
|
||||
lang = "de";
|
||||
break;
|
||||
default:
|
||||
lang = "en";
|
||||
break;
|
||||
}
|
||||
return lang;
|
||||
}
|
||||
|
||||
public static string GetIp4Address(bool ShowOnlyInCorporateNetwork)
|
||||
{
|
||||
var ipInfo = new C4IT.HardwareInfo.cPrimaryIpInfo();
|
||||
ipInfo.GetInfo();
|
||||
if (!string.IsNullOrEmpty(ipInfo.BestLocalIP) || ShowOnlyInCorporateNetwork)
|
||||
return ipInfo.BestLocalIP;
|
||||
|
||||
|
||||
string ip4Address = String.Empty;
|
||||
foreach (IPAddress ipa in Dns.GetHostAddresses(Dns.GetHostName()))
|
||||
{
|
||||
if (ipa.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
ip4Address = ipa.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ip4Address;
|
||||
}
|
||||
|
||||
public static DriveInfo[] GetDrives()
|
||||
{
|
||||
return DriveInfo.GetDrives();
|
||||
}
|
||||
|
||||
public static string FormatBytes(long bytes, bool withSuffix)
|
||||
{
|
||||
string[] suffix = { "B", "KB", "MB", "GB", "TB" };
|
||||
int i;
|
||||
double dblSByte = bytes;
|
||||
for (i = 0; i < suffix.Length && bytes >= 1024; i++, bytes /= 1024)
|
||||
{
|
||||
dblSByte = bytes / 1024.0;
|
||||
}
|
||||
if (withSuffix)
|
||||
{
|
||||
return String.Format("{0:0.##} {1}", dblSByte, suffix[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
return String.Format("{0:0.##}", dblSByte);
|
||||
}
|
||||
}
|
||||
|
||||
[DllImport("shell32.dll")]
|
||||
private static extern int SHQueryUserNotificationState(
|
||||
out QUERY_USER_NOTIFICATION_STATE pquns);
|
||||
|
||||
|
||||
public static bool IsOsInPresentationMode()
|
||||
{
|
||||
var hRes = SHQueryUserNotificationState(out var state);
|
||||
|
||||
if (hRes != 0)
|
||||
return false;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case QUERY_USER_NOTIFICATION_STATE.QUNS_ACCEPTS_NOTIFICATIONS:
|
||||
case QUERY_USER_NOTIFICATION_STATE.QUNS_QUIET_TIME:
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
20
libs/journalAction.cs
Normal file
20
libs/journalAction.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
public class journalAction
|
||||
{
|
||||
public Boolean visible;
|
||||
public string JournalText;
|
||||
|
||||
public journalAction(string inJournalText, Boolean inVisible=true)
|
||||
{
|
||||
this.visible = inVisible;
|
||||
this.JournalText = inJournalText;
|
||||
}
|
||||
}
|
||||
}
|
||||
30
libs/staticContracts.cs
Normal file
30
libs/staticContracts.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
public class staticLibs
|
||||
{
|
||||
|
||||
public static Dictionary<int, journalAction> JournalActivityAction = new Dictionary<int, journalAction>() {
|
||||
{0, new journalAction(Properties.Resources.ticketNewComment) },
|
||||
{1,new journalAction(Properties.Resources.ticketCreatedByAgent) },
|
||||
{2, new journalAction(Properties.Resources.ticketForwardedToUser) },
|
||||
{3,new journalAction(Properties.Resources.ticketForwardedToRole)},
|
||||
|
||||
{4,new journalAction(Properties.Resources.ticketTakeover)},
|
||||
{5,new journalAction(Properties.Resources.ticketPaused) },
|
||||
{7,new journalAction(Properties.Resources.ticketAccepted) },
|
||||
{8,new journalAction(Properties.Resources.ticketClosed) },
|
||||
|
||||
{9,new journalAction(Properties.Resources.ticketMerged) },
|
||||
{11,new journalAction(Properties.Resources.ticketMailSend) },
|
||||
{12,new journalAction(Properties.Resources.ticketPostedback) },
|
||||
{14,new journalAction(Properties.Resources.ticketMailAnswer) },
|
||||
{18,new journalAction(Properties.Resources.ticketCreatedByMail) },
|
||||
{19,new journalAction(Properties.Resources.ticketCreatedBySSP) }
|
||||
|
||||
};
|
||||
}
|
||||
}
|
||||
87
libs/versionHelper.cs
Normal file
87
libs/versionHelper.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
public class VersionHelper
|
||||
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// OS is at least Windows Vista
|
||||
|
||||
/// </summary>
|
||||
|
||||
public static bool IsAtLeastVista
|
||||
|
||||
{
|
||||
|
||||
get
|
||||
|
||||
{
|
||||
|
||||
if (Environment.OSVersion.Version.Major < 6)
|
||||
|
||||
{
|
||||
|
||||
Debug.WriteLine("How about trying this on Vista?");
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// OS is Windows 7 or higher
|
||||
|
||||
/// </summary>
|
||||
|
||||
public static bool IsWindows7orHigher
|
||||
|
||||
{
|
||||
|
||||
get
|
||||
|
||||
{
|
||||
|
||||
if (Environment.OSVersion.Version.Major == 6 &&
|
||||
|
||||
Environment.OSVersion.Version.Minor >= 1)
|
||||
|
||||
{
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
else if (Environment.OSVersion.Version.Major > 6)
|
||||
|
||||
{
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
else
|
||||
|
||||
{
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
94
libs/visualHelper.cs
Normal file
94
libs/visualHelper.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Windows;
|
||||
|
||||
|
||||
namespace C4IT_CustomerPanel.libs
|
||||
{
|
||||
class visualHelper
|
||||
{
|
||||
|
||||
public static List<T> GetLogicalChildCollection<T>(object parent) where T : DependencyObject
|
||||
{
|
||||
List<T> logicalCollection = new List<T>();
|
||||
GetLogicalChildCollection(parent as DependencyObject, logicalCollection);
|
||||
return logicalCollection;
|
||||
}
|
||||
private static void GetLogicalChildCollection<T>(DependencyObject parent, List<T> logicalCollection) where T : DependencyObject
|
||||
{
|
||||
System.Collections.IEnumerable children = LogicalTreeHelper.GetChildren(parent);
|
||||
foreach (object child in children)
|
||||
{
|
||||
if (child is DependencyObject)
|
||||
{
|
||||
DependencyObject depChild = child as DependencyObject;
|
||||
if (child is T)
|
||||
{
|
||||
logicalCollection.Add(child as T);
|
||||
}
|
||||
GetLogicalChildCollection(depChild, logicalCollection);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static T FindVisualChild<T>(DependencyObject parent, string Tag = null) where T : DependencyObject
|
||||
|
||||
{
|
||||
try
|
||||
{
|
||||
var Cnt = System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent);
|
||||
for (int i = 0; i < Cnt ; i++)
|
||||
{
|
||||
DependencyObject child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);
|
||||
string _Tag = (child as FrameworkElement)?.Tag as string;
|
||||
|
||||
if (child is T visualChild && (Tag == null || _Tag == Tag))
|
||||
{
|
||||
return visualChild;
|
||||
}
|
||||
else
|
||||
{
|
||||
T childOfChild = FindVisualChild<T>(child, Tag);
|
||||
|
||||
if (childOfChild != null)
|
||||
|
||||
return childOfChild;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Window GetMainWindow()
|
||||
{
|
||||
return Application.Current.MainWindow;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static Window GetUserControlOwnerWindow(System.Windows.Forms.Control usercontrol)
|
||||
{
|
||||
return GetUserControlOwnerWindow(usercontrol.Parent);
|
||||
}
|
||||
|
||||
// ******************************************************************
|
||||
public static Window GetUserControlOwnerWindow(DependencyObject parent)
|
||||
{
|
||||
while (parent != null && !(parent is Window))
|
||||
{
|
||||
parent = LogicalTreeHelper.GetParent(parent);
|
||||
}
|
||||
|
||||
return parent as Window;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user