You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
160 lines
5.9 KiB
160 lines
5.9 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using System.Security.AccessControl;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Timers;
|
|
using Database;
|
|
using Syncfusion.Windows.Forms.Tools;
|
|
|
|
namespace OnDoc.Klassen
|
|
{
|
|
public static class clsProcessWatch
|
|
{
|
|
|
|
public static System.Timers.Timer watchtimer = new System.Timers.Timer(Convert.ToInt32(Properties.Settings.Default.OfficeWatchTimerIntervall));
|
|
|
|
static List<FileToCheck> FilestoCheck = new List<FileToCheck>();
|
|
|
|
public static void AddToList(string dokumentid, string filename, string application)
|
|
{
|
|
FilestoCheck.Add(new FileToCheck(dokumentid, filename, application));
|
|
watchtimer.Elapsed += WatchProcesses;
|
|
if (watchtimer.Enabled == false) { watchtimer.Enabled = true; }
|
|
|
|
}
|
|
|
|
public static void RemoveFromList(string dokumentid)
|
|
{
|
|
foreach (FileToCheck fc in FilestoCheck)
|
|
{
|
|
if (fc.dokumentid == dokumentid)
|
|
{
|
|
FilestoCheck.Remove(fc);
|
|
break;
|
|
}
|
|
}
|
|
if (FilestoCheck.Count == 0)
|
|
{
|
|
watchtimer.Enabled = false;
|
|
}
|
|
}
|
|
|
|
private static void WatchProcesses(object source, ElapsedEventArgs e)
|
|
{
|
|
bool word = false;
|
|
bool excel = false;
|
|
bool pdf = false;
|
|
bool found = 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 (word)
|
|
{
|
|
Process[] localByName = Process.GetProcessesByName("WINWORD");
|
|
foreach (Process p in localByName)
|
|
{
|
|
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > -1) { found = true; }
|
|
}
|
|
}
|
|
if (excel)
|
|
{
|
|
Process[] localByName = Process.GetProcessesByName("EXCEL");
|
|
foreach (Process p in localByName)
|
|
{
|
|
if (p.MainWindowTitle.IndexOf(fc.dokumentid) > 0) { found = true; }
|
|
}
|
|
}
|
|
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);
|
|
return;
|
|
}
|
|
else
|
|
{
|
|
Logging.DocLog.Info("Dokument ohne speichern geschlossen", "Processwatch", fc.dokumentid, "", fc.filename);
|
|
RemoveFromList(fc.dokumentid);
|
|
Remove_Dok_in_Bearbeitung(fc.dokumentid);
|
|
return;
|
|
};
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
private static void Remove_Dok_in_Bearbeitung(string dokumentid)
|
|
{
|
|
DB db = new DB(AppParams.connectionstring);
|
|
db.Dok_in_Bearbeietung(2, dokumentid, AppParams.CurrentMitarbieter);
|
|
db = null;
|
|
}
|
|
private static void Remove_Dokumentbearbeitung_Zwingend(string dokumentid)
|
|
{
|
|
DB db = new DB(AppParams.connectionstring);
|
|
db.Exec_SQL("Update dokument set bearbeitung_zwingend=0 where dokumentid='" + dokumentid + "'");
|
|
db = null;
|
|
}
|
|
private static void Save_File(string dokumentid, string filename)
|
|
{
|
|
DB db = new DB(AppParams.connectionstring);
|
|
db.Get_Tabledata("Select * from dokument where dokumentid='" + dokumentid + "'", false, true);
|
|
|
|
db.Save_To_DB(dokumentid, filename);
|
|
db.set_approvalstate(dokumentid, false);
|
|
Logging.DocLog.Info("Dokument gespeichert", "Processwatch", dokumentid, "", filename);
|
|
db = null;
|
|
}
|
|
|
|
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)
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
|
|
}
|
|
}
|
|
public class FileToCheck
|
|
{
|
|
public string dokumentid { get; set; }
|
|
public string filename { get; set; }
|
|
public string application { get; set; }
|
|
|
|
public DateTime filedatetime { get; set; }
|
|
|
|
public FileToCheck(string dokumentid, string filename, string application)
|
|
{
|
|
this.dokumentid = dokumentid;
|
|
this.filename = filename;
|
|
this.application = application;
|
|
this.filedatetime = DateTime.Now;
|
|
Logging.DocLog.Debug("Add Processwatch: " + DateTime.Now.ToString(), "New FileToCheck", dokumentid, "", "Add Processwatch");
|
|
|
|
}
|
|
}
|
|
}
|
|
|