Update 20260109

This commit is contained in:
Stefan Hutter
2026-01-09 08:37:07 +01:00
parent e377f08ccd
commit 49155d898f
229 changed files with 28984 additions and 39486 deletions

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Runtime.InteropServices;
using System.Security.AccessControl;
using System.Text;
using System.Threading;
@@ -10,13 +11,72 @@ using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using Database;
using Microsoft.Office.Interop.Word;
using OnDoc.UICintrols;
using Syncfusion.Olap.MDXQueryParser;
using Syncfusion.Windows.Forms.Tools;
using Syncfusion.WinForms.Input.Enums;
using static Syncfusion.Windows.Forms.Tools.ColorDlgAdv;
using Word = Microsoft.Office.Interop.Word;
namespace OnDoc.Klassen
{
public static class clsProcessWatch
{
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
private static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll")]
private static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);
// Delegate to filter which windows to include
public delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
/// <summary> Get the text for the window pointed to by hWnd </summary>
public static string GetWindowText(IntPtr hWnd)
{
int size = GetWindowTextLength(hWnd);
if (size > 0)
{
var builder = new StringBuilder(size + 1);
GetWindowText(hWnd, builder, builder.Capacity);
return builder.ToString();
}
return String.Empty;
}
public static IEnumerable<IntPtr> FindWindows(EnumWindowsProc filter)
{
IntPtr found = IntPtr.Zero;
List<IntPtr> windows = new List<IntPtr>();
EnumWindows(delegate (IntPtr wnd, IntPtr param)
{
if (filter(wnd, param))
{
// only add the windows that pass the filter
windows.Add(wnd);
}
// but return true here so that we iterate all windows
return true;
}, IntPtr.Zero);
return windows;
}
public static IEnumerable<IntPtr> FindWindowsWithText(string titleText)
{
return FindWindows(delegate (IntPtr wnd, IntPtr param)
{
return GetWindowText(wnd).Contains(titleText);
});
}
public static System.Timers.Timer watchtimer = new System.Timers.Timer(Convert.ToInt32(Properties.Settings.Default.OfficeWatchTimerIntervall));
@@ -72,7 +132,7 @@ namespace OnDoc.Klassen
return "NO OWNER";
}
private static void WatchProcesses(object source, ElapsedEventArgs e)
private static void WatchProcesses1(object source, ElapsedEventArgs e)
{
bool word = false;
bool excel = false;
@@ -80,13 +140,14 @@ namespace OnDoc.Klassen
bool found = false;
watchtimer.Enabled = false;
found = false;
Logging.Logging.Debug("Start Watch_Process:"+ DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch","" );
Logging.Logging.Debug("Start Watch_Process:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", "");
try
{
foreach (FileToCheck fc in FilestoCheck)
{
if (fc.filedatetime < DateTime.Now.AddSeconds(-3))
{
found = false;
word = false;
excel = false;
@@ -101,12 +162,18 @@ namespace OnDoc.Klassen
{
Thread.Sleep(200);
Process[] localByName = Process.GetProcessesByName("WINWORD");
Logging.Logging.Debug("Get Processe", "", "");
foreach (Process p in localByName)
{
Logging.Logging.Debug(localByName.Count().ToString(), "", "");
string owner = GetProcessOwner(p.Id);
owner = owner.ToUpper();
Logging.Logging.Debug(AppParams.systemtgnummer + "/" + AppParams.currenttgnummer + "/" + owner + "/" + fc.dokumentid + "/" + p.MainWindowTitle, "", "");
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1 ||
(p.MainWindowTitle.Trim() == "" && owner.Contains(AppParams.systemtgnummer.ToUpper())))
{
@@ -194,9 +261,71 @@ namespace OnDoc.Klassen
}
finally
{
watchtimer.Enabled = true ;
watchtimer.Enabled = true;
}
}
private static void WatchProcesses(object source, ElapsedEventArgs e)
{
bool word = false;
bool excel = false;
bool pdf = false;
bool found = false;
watchtimer.Enabled = false;
found = false;
Logging.Logging.Debug("Start Watch_Process:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", "");
try
{
foreach (FileToCheck fc in FilestoCheck)
{
if (fc.filedatetime < DateTime.Now.AddSeconds(-3))
{
found = false;
var windows = FindWindowsWithText(fc.dokumentid);
if (windows.Count() > 0)
{
found = true;
save_to_db(fc);
}
windows = null;
if (!found)
{
Logging.Logging.Debug("Not Found " + fc.filename + " / " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", fc.dokumentid);
if (Check_Modified(fc) == true)
{
Save_File(fc.dokumentid, fc.filename);
Logging.DocLog.Info("Dokument gespeichert und geschlossen", "Processwatch", fc.dokumentid, "", fc.filename);
RemoveFromList(fc.dokumentid);
Remove_Dok_in_Bearbeitung(fc.dokumentid);
Remove_Dokumentbearbeitung_Zwingend(fc.dokumentid);
Remove_Approvals(fc.dokumentid);
return;
}
else
{
Logging.DocLog.Info("Dokument ohne speichern geschlossen", "Processwatch", fc.dokumentid, "", fc.filename);
RemoveFromList(fc.dokumentid);
Remove_Dok_in_Bearbeitung(fc.dokumentid);
return;
};
}
}
}
watchtimer.Enabled = true;
}
catch (Exception ex)
{
Logging.Logging.Debug("Error Processwatch", "OnDoc", ex.Message);
}
finally
{
watchtimer.Enabled = true;
}
}
private static void Remove_Dok_in_Bearbeitung(string dokumentid)
{
DB db = new DB(AppParams.connectionstring);