update 20250219
This commit is contained in:
@@ -9,6 +9,7 @@ using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using Database;
|
||||
using Syncfusion.Windows.Forms.Tools;
|
||||
using Syncfusion.WinForms.Input.Enums;
|
||||
|
||||
namespace OnDoc.Klassen
|
||||
{
|
||||
@@ -54,54 +55,61 @@ namespace OnDoc.Klassen
|
||||
bool excel = false;
|
||||
bool pdf = false;
|
||||
bool found = false;
|
||||
|
||||
watchtimer.Enabled = false;
|
||||
found= false;
|
||||
foreach (FileToCheck fc in FilestoCheck)
|
||||
{
|
||||
Logging.Logging.Debug("FileChek "+fc.filename+" / " + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", fc.dokumentid);
|
||||
if (fc.application == "Word") { word = true; }
|
||||
if (fc.application == "Excel") { excel = true; }
|
||||
if (fc.application == "PDF") { pdf = true; }
|
||||
if (fc.filedatetime < DateTime.Now.AddSeconds(-5))
|
||||
{
|
||||
found = false;
|
||||
Logging.Logging.Debug(fc.application + " / FileChek " + fc.filename + " / " + fc.filedatetime.ToString("yyyy-MM-dd hh:mm:ss") + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", fc.dokumentid);
|
||||
if (fc.application == "Word") { word = true; }
|
||||
if (fc.application == "Excel") { excel = true; }
|
||||
if (fc.application == "PDF") { pdf = true; }
|
||||
|
||||
if (word)
|
||||
{
|
||||
Process[] localByName = Process.GetProcessesByName("WINWORD");
|
||||
foreach (Process p in localByName)
|
||||
if (word)
|
||||
{
|
||||
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1) { found = true; }
|
||||
Process[] localByName = Process.GetProcessesByName("WINWORD");
|
||||
foreach (Process p in localByName)
|
||||
{
|
||||
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1) { found = true; }
|
||||
save_to_db(fc);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (excel)
|
||||
{
|
||||
Process[] localByName = Process.GetProcessesByName("EXCEL");
|
||||
foreach (Process p in localByName)
|
||||
if (excel)
|
||||
{
|
||||
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > 0) { found = true; }
|
||||
Process[] localByName = Process.GetProcessesByName("EXCEL");
|
||||
foreach (Process p in localByName)
|
||||
{
|
||||
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > 0) { found = true; }
|
||||
save_to_db(fc);
|
||||
}
|
||||
}
|
||||
}
|
||||
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)
|
||||
if (!found)
|
||||
{
|
||||
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;
|
||||
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;
|
||||
};
|
||||
}
|
||||
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;
|
||||
|
||||
}
|
||||
private static void Remove_Dok_in_Bearbeitung(string dokumentid)
|
||||
@@ -124,6 +132,28 @@ namespace OnDoc.Klassen
|
||||
db = null;
|
||||
|
||||
}
|
||||
|
||||
private static void save_to_db(FileToCheck fc)
|
||||
{
|
||||
if (Check_Modified(fc))
|
||||
{
|
||||
try
|
||||
{
|
||||
System.IO.File.Copy(fc.filename, fc.filename + ".tmp");
|
||||
Save_File(fc.dokumentid, fc.filename + ".tmp");
|
||||
fc.filedatetime = DateTime.Now;
|
||||
System.IO.File.Delete(fc.filename + ".tmp");
|
||||
Logging.Logging.Debug(fc.application + " / save_to_db " + fc.filename + " / " + fc.filedatetime.ToString("yyyy-MM-dd hh:mm:ss") + "/"+DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", fc.dokumentid);
|
||||
|
||||
}
|
||||
catch
|
||||
{
|
||||
Logging.Logging.Debug(fc.application + " / save_to_db faild " + fc.filename + " / " + fc.filedatetime.ToString("yyyy-MM-dd hh:mm:ss") +"/"+ DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss"), "OnDoc.Processwatch", fc.dokumentid);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
private static void Save_File(string dokumentid, string filename)
|
||||
{
|
||||
DB db = new DB(AppParams.connectionstring);
|
||||
@@ -139,8 +169,11 @@ namespace OnDoc.Klassen
|
||||
private static bool Check_Modified(FileToCheck fc)
|
||||
{
|
||||
DateTime lwt = System.IO.File.GetLastWriteTime(fc.filename);
|
||||
Logging.DocLog.Debug("Prozesswatch - Check Modified: " + lwt.ToString() + "," + fc.filedatetime.ToString(), "Processwatch", fc.dokumentid, "", fc.filename);
|
||||
if ((lwt- fc.filedatetime).Seconds > 2)
|
||||
int secdiff = (int)((lwt - fc.filedatetime).TotalSeconds);
|
||||
Logging.Logging.Debug("Prozesswatch - Check Modified: " + lwt.ToString() + "," + fc.filedatetime.ToString(), "OnDoc", fc.dokumentid);
|
||||
//Logging.DocLog.Debug("Prozesswatch - Check Modified: " + lwt.ToString() + "," + fc.filedatetime.ToString(), "Processwatch", fc.dokumentid, "", fc.filename);
|
||||
//if ((lwt- fc.filedatetime).Seconds > 2)
|
||||
if (secdiff > 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -150,6 +183,11 @@ namespace OnDoc.Klassen
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static int check_open_files()
|
||||
{
|
||||
return FilestoCheck.Count;
|
||||
}
|
||||
}
|
||||
public class FileToCheck
|
||||
{
|
||||
@@ -165,7 +203,8 @@ namespace OnDoc.Klassen
|
||||
this.filename = filename;
|
||||
this.application = application;
|
||||
this.filedatetime = DateTime.Now;
|
||||
Logging.DocLog.Debug("Add Processwatch: " + DateTime.Now.ToString(), "New FileToCheck", dokumentid, "", "Add Processwatch");
|
||||
//Logging.DocLog.Debug("Add Processwatch: " + DateTime.Now.ToString(), "New FileToCheck", dokumentid, "", "Add Processwatch");
|
||||
Logging.Logging.Debug("Add Processwatch: " + DateTime.Now.ToString(),"OnDoc",this.dokumentid);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user