Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 88635c04f8 | |||
| 6b025a24f0 | |||
| 641267081a | |||
| 0336530742 | |||
| 75c0c1126e | |||
| 96c34e542f | |||
| 23223fe0be |
@@ -38,6 +38,32 @@ Versionsschema ist `x.x.x.x` (siehe `release.sh`).
|
|||||||
|
|
||||||
### Hinzugefuegt
|
### Hinzugefuegt
|
||||||
|
|
||||||
|
- **Autostart-Verwaltung in den Einstellungen.** Neuer Abschnitt "Autostart" mit
|
||||||
|
zwei Optionen: "Nur fuer diesen Benutzer" (HKCU) und "Fuer alle Benutzer"
|
||||||
|
(HKLM). Die Option fuer alle Benutzer ist nur mit Admin-Rechten aenderbar -
|
||||||
|
darueber laesst sich auch der vom Setup gesetzte Autostart fuer alle wieder
|
||||||
|
entfernen. Das Setup setzt den Autostart weiterhin fuer alle Benutzer (HKLM),
|
||||||
|
der Hinweis im Installer wurde entsprechend klargestellt.
|
||||||
|
- **Protokoll automatisch leeren (Einstellung).** Neuer Wert "Protokoll
|
||||||
|
auto-leeren - Eintraege aelter als (Tage)". Bei 0 (Standard) bleibt alles
|
||||||
|
erhalten; bei >0 werden aeltere Eintraege automatisch entfernt (beim Start,
|
||||||
|
vor jedem Sync, beim Oeffnen des Protokolls und beim Speichern der
|
||||||
|
Einstellungen).
|
||||||
|
- **Protokoll zeigt jetzt, WAS geaendert wurde.** Pro Sync werden die einzelnen
|
||||||
|
Aktionen (erstellt / aktualisiert / geloescht / verknuepft / zusammengefuehrt je
|
||||||
|
Kontakt) ins Protokoll geschrieben - sowohl beim manuellen Sync (Fenster) als
|
||||||
|
auch bei Auto-/Tray-Sync.
|
||||||
|
- **Benachrichtigungen schaltbar (Einstellungen).** Zwei unabhaengige Haken:
|
||||||
|
"Tray-Benachrichtigungen (allgemein)" fuer Info-Meldungen (Sync laeuft/fertig)
|
||||||
|
und "Benachrichtigungen bei Warnungen/Fehlern" fuer Konflikte und Fehler. So
|
||||||
|
kann man z.B. nur noch bei Konflikten/Fehlern benachrichtigt werden - oder gar
|
||||||
|
nicht. Das Protokoll wird unabhaengig davon immer geschrieben.
|
||||||
|
- **Protokoll (Logdatei) + "Protokoll"-Button.** Syncs, Ergebnisse, Konflikte
|
||||||
|
(lokal und von anderen Arbeitsplaetzen) und Fehler werden dauerhaft in
|
||||||
|
`%AppData%\StarfaceOutlookSync\sync.log` festgehalten - so ist auch nach dem
|
||||||
|
Verschwinden einer Tray-Meldung nachvollziehbar, wer/was/wann. Im Hauptfenster
|
||||||
|
oeffnet der Button "Protokoll" einen Betrachter (Aktualisieren/Leeren/Ordner
|
||||||
|
oeffnen). Die Datei rotiert bei 2 MB.
|
||||||
- **Clientuebergreifende Konflikt-Hinweise (Mehrplatz).** Wird ein echter
|
- **Clientuebergreifende Konflikt-Hinweise (Mehrplatz).** Wird ein echter
|
||||||
Feld-Konflikt aufgeloest, legt der Client eine Notiz im gemeinsamen Verzeichnis
|
Feld-Konflikt aufgeloest, legt der Client eine Notiz im gemeinsamen Verzeichnis
|
||||||
(`conflicts/`) ab - zugeordnet nach Kontakt (StarfaceId). Ein anderer
|
(`conflicts/`) ab - zugeordnet nach Kontakt (StarfaceId). Ein anderer
|
||||||
@@ -64,6 +90,13 @@ Versionsschema ist `x.x.x.x` (siehe `release.sh`).
|
|||||||
|
|
||||||
### Geaendert
|
### Geaendert
|
||||||
|
|
||||||
|
- **Manueller und automatischer Sync vereinheitlicht.** Beide Pfade laufen jetzt
|
||||||
|
ueber einen gemeinsamen `SyncCoordinator` und nutzen damit dieselben Schutz-
|
||||||
|
und Komfortfunktionen: lokaler Re-Entrancy-Schutz (prozessweit - auch manuell
|
||||||
|
vs. automatisch koennen nicht mehr gleichzeitig laufen), clientuebergreifende
|
||||||
|
Lock-Datei, Konflikt-Notizen anderer Arbeitsplaetze und vollstaendiges
|
||||||
|
Protokoll. Vorher umging der manuelle "Synchronisieren"-Button (Fenster) die
|
||||||
|
Lock-Datei und einen Teil des Protokolls.
|
||||||
- **Doppelte Syncs verhindert (lokal).** Der Schutz gegen gleichzeitig laufende
|
- **Doppelte Syncs verhindert (lokal).** Der Schutz gegen gleichzeitig laufende
|
||||||
Syncs (manuell + Auto-Sync-Timer) ist jetzt atomar (`Interlocked`) statt eines
|
Syncs (manuell + Auto-Sync-Timer) ist jetzt atomar (`Interlocked`) statt eines
|
||||||
nicht-atomaren `volatile bool`, bei dem beide in einem Zeitfenster
|
nicht-atomaren `volatile bool`, bei dem beide in einem Zeitfenster
|
||||||
|
|||||||
@@ -260,6 +260,8 @@ StarfaceOutlookSync.exe
|
|||||||
Alle Daten werden lokal pro Benutzer gespeichert:
|
Alle Daten werden lokal pro Benutzer gespeichert:
|
||||||
- `%AppData%\StarfaceOutlookSync\profiles.json` - Sync-Profile mit Zugangsdaten
|
- `%AppData%\StarfaceOutlookSync\profiles.json` - Sync-Profile mit Zugangsdaten
|
||||||
- `%AppData%\StarfaceOutlookSync\mappings\` - Kontakt-Zuordnungen pro Profil
|
- `%AppData%\StarfaceOutlookSync\mappings\` - Kontakt-Zuordnungen pro Profil
|
||||||
|
- `%AppData%\StarfaceOutlookSync\sync.log` - Protokoll (Syncs, Konflikte, Fehler);
|
||||||
|
im Hauptfenster ueber den Button **Protokoll** einsehbar
|
||||||
|
|
||||||
### SSL-Zertifikate
|
### SSL-Zertifikate
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
; Erfordert Inno Setup 6.x (https://jrsoftware.org/isinfo.php)
|
; Erfordert Inno Setup 6.x (https://jrsoftware.org/isinfo.php)
|
||||||
|
|
||||||
#define MyAppName "Starface Outlook Sync"
|
#define MyAppName "Starface Outlook Sync"
|
||||||
#define MyAppVersion "0.0.0.28"
|
#define MyAppVersion "0.0.0.30"
|
||||||
#define MyAppPublisher "HackerSoft - Hacker-Net Telekommunikation"
|
#define MyAppPublisher "HackerSoft - Hacker-Net Telekommunikation"
|
||||||
#define MyAppURL "https://www.hacker-net.de"
|
#define MyAppURL "https://www.hacker-net.de"
|
||||||
#define MyAppExeName "StarfaceOutlookSync.exe"
|
#define MyAppExeName "StarfaceOutlookSync.exe"
|
||||||
@@ -32,7 +32,7 @@ Name: "german"; MessagesFile: "compiler:Languages\German.isl"
|
|||||||
|
|
||||||
[Tasks]
|
[Tasks]
|
||||||
Name: "desktopicon"; Description: "Desktop-Verknuepfung erstellen"; GroupDescription: "Zusaetzliche Optionen:"
|
Name: "desktopicon"; Description: "Desktop-Verknuepfung erstellen"; GroupDescription: "Zusaetzliche Optionen:"
|
||||||
Name: "autostart"; Description: "Bei Windows-Anmeldung automatisch starten"; GroupDescription: "Zusaetzliche Optionen:"; Flags: checkedonce
|
Name: "autostart"; Description: "Bei Windows-Anmeldung automatisch starten (fuer ALLE Benutzer; einzelne Benutzer spaeter in den Einstellungen)"; GroupDescription: "Zusaetzliche Optionen:"; Flags: checkedonce
|
||||||
|
|
||||||
[Files]
|
[Files]
|
||||||
; Hauptanwendung - Pfad anpassen nach Build
|
; Hauptanwendung - Pfad anpassen nach Build
|
||||||
|
|||||||
@@ -73,6 +73,10 @@ namespace StarfaceOutlookSync.Models
|
|||||||
public int Errors { get; set; }
|
public int Errors { get; set; }
|
||||||
public System.Collections.Generic.List<string> ErrorMessages { get; set; } = new System.Collections.Generic.List<string>();
|
public System.Collections.Generic.List<string> ErrorMessages { get; set; } = new System.Collections.Generic.List<string>();
|
||||||
|
|
||||||
|
// Was konkret veraendert wurde (erstellt/aktualisiert/geloescht je Kontakt),
|
||||||
|
// fuer das Protokoll.
|
||||||
|
public System.Collections.Generic.List<string> Changes { get; set; } = new System.Collections.Generic.List<string>();
|
||||||
|
|
||||||
// Echte Feld-Konflikte (dasselbe Feld auf beiden Seiten geaendert), die
|
// Echte Feld-Konflikte (dasselbe Feld auf beiden Seiten geaendert), die
|
||||||
// ueber die Vorrang-Regel aufgeloest wurden. Fuer Benutzer-Hinweise.
|
// ueber die Vorrang-Regel aufgeloest wurden. Fuer Benutzer-Hinweise.
|
||||||
public System.Collections.Generic.List<FieldConflict> Conflicts { get; set; } = new System.Collections.Generic.List<FieldConflict>();
|
public System.Collections.Generic.List<FieldConflict> Conflicts { get; set; } = new System.Collections.Generic.List<FieldConflict>();
|
||||||
|
|||||||
@@ -11,6 +11,15 @@ namespace StarfaceOutlookSync.Models
|
|||||||
public bool SyncOnStart { get; set; } = false;
|
public bool SyncOnStart { get; set; } = false;
|
||||||
public bool AutoAcceptOutlookPrompt { get; set; } = false;
|
public bool AutoAcceptOutlookPrompt { get; set; } = false;
|
||||||
|
|
||||||
|
// Tray-Benachrichtigungen. Allgemein = Info-Meldungen (Sync laeuft/fertig).
|
||||||
|
// WarnungenFehler = nur Konflikte und Fehler. Beide unabhaengig schaltbar.
|
||||||
|
public bool NotificationsEnabled { get; set; } = true;
|
||||||
|
public bool NotifyWarningsErrors { get; set; } = true;
|
||||||
|
|
||||||
|
// Protokoll-Eintraege aelter als X Tage automatisch entfernen. 0 = aus
|
||||||
|
// (alle Eintraege bleiben erhalten).
|
||||||
|
public int LogRetentionDays { get; set; } = 0;
|
||||||
|
|
||||||
// Gemeinsames Verzeichnis (Netzlaufwerk/UNC) fuer die clientuebergreifende
|
// Gemeinsames Verzeichnis (Netzlaufwerk/UNC) fuer die clientuebergreifende
|
||||||
// Sync-Sperre. Leer = keine Sperre (nur lokaler Schutz). Verhindert, dass
|
// Sync-Sperre. Leer = keine Sperre (nur lokaler Schutz). Verhindert, dass
|
||||||
// mehrere Arbeitsplaetze gleichzeitig dasselbe Adressbuch synchronisieren.
|
// mehrere Arbeitsplaetze gleichzeitig dasselbe Adressbuch synchronisieren.
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Security.Principal;
|
||||||
|
using Microsoft.Win32;
|
||||||
|
|
||||||
|
namespace StarfaceOutlookSync.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Verwaltet den Windows-Autostart ueber die Run-Schluessel:
|
||||||
|
/// - pro Benutzer -> HKCU\...\Run
|
||||||
|
/// - alle Benutzer -> HKLM\...\Run (nur mit Admin-Rechten aenderbar)
|
||||||
|
/// Das Setup setzt den Autostart fuer alle Benutzer (HKLM); hierueber laesst
|
||||||
|
/// er sich nachtraeglich umstellen oder entfernen.
|
||||||
|
/// </summary>
|
||||||
|
public static class AutostartManager
|
||||||
|
{
|
||||||
|
private const string RunKey = @"Software\Microsoft\Windows\CurrentVersion\Run";
|
||||||
|
private const string ValueName = "StarfaceOutlookSync";
|
||||||
|
|
||||||
|
private static string ExePath()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var p = Process.GetCurrentProcess().MainModule?.FileName;
|
||||||
|
if (!string.IsNullOrEmpty(p)) return p;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
return System.Reflection.Assembly.GetEntryAssembly()?.Location ?? "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsAdmin()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var id = WindowsIdentity.GetCurrent())
|
||||||
|
return new WindowsPrincipal(id).IsInRole(WindowsBuiltInRole.Administrator);
|
||||||
|
}
|
||||||
|
catch { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool GetUserAutostart() => HasValue(Registry.CurrentUser);
|
||||||
|
public static bool GetMachineAutostart() => HasValue(Registry.LocalMachine);
|
||||||
|
|
||||||
|
public static void SetUserAutostart(bool enabled) => SetValue(Registry.CurrentUser, enabled);
|
||||||
|
|
||||||
|
/// <summary>Setzt/entfernt den Autostart fuer alle Benutzer. Braucht Admin-Rechte. Gibt Erfolg zurueck.</summary>
|
||||||
|
public static bool SetMachineAutostart(bool enabled) => SetValue(Registry.LocalMachine, enabled);
|
||||||
|
|
||||||
|
private static bool HasValue(RegistryKey root)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var k = root.OpenSubKey(RunKey, false))
|
||||||
|
return k?.GetValue(ValueName) != null;
|
||||||
|
}
|
||||||
|
catch { return false; }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool SetValue(RegistryKey root, bool enabled)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var k = root.CreateSubKey(RunKey))
|
||||||
|
{
|
||||||
|
if (k == null) return false;
|
||||||
|
if (enabled)
|
||||||
|
k.SetValue(ValueName, "\"" + ExePath() + "\"", RegistryValueKind.String);
|
||||||
|
else if (k.GetValue(ValueName) != null)
|
||||||
|
k.DeleteValue(ValueName, false);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch { return false; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.IO;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace StarfaceOutlookSync.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Einfaches, threadsicheres Datei-Protokoll. Haelt fest, was bei Syncs
|
||||||
|
/// passiert (Ergebnisse, Konflikte, Fehler) - dauerhaft nachlesbar, auch
|
||||||
|
/// nachdem eine Tray-Meldung verschwunden ist.
|
||||||
|
/// </summary>
|
||||||
|
public static class Logger
|
||||||
|
{
|
||||||
|
private static readonly object _lock = new object();
|
||||||
|
private const long MaxBytes = 2 * 1024 * 1024; // 2 MB, dann Rotation
|
||||||
|
|
||||||
|
public static string LogFilePath { get; } = Path.Combine(
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"StarfaceOutlookSync", "sync.log");
|
||||||
|
|
||||||
|
public static void Log(string message)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(LogFilePath));
|
||||||
|
Rotate();
|
||||||
|
var line = $"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] {message}{Environment.NewLine}";
|
||||||
|
File.AppendAllText(LogFilePath, line, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void Rotate()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var fi = new FileInfo(LogFilePath);
|
||||||
|
if (fi.Exists && fi.Length > MaxBytes)
|
||||||
|
{
|
||||||
|
var bak = LogFilePath + ".1";
|
||||||
|
if (File.Exists(bak)) File.Delete(bak);
|
||||||
|
File.Move(LogFilePath, bak);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ReadAll()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
if (!File.Exists(LogFilePath)) return "";
|
||||||
|
using (var fs = new FileStream(LogFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
|
||||||
|
using (var sr = new StreamReader(fs, Encoding.UTF8))
|
||||||
|
return sr.ReadToEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { return ""; }
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Entfernt Protokoll-Eintraege, die aelter als <paramref name="days"/>
|
||||||
|
/// Tage sind. days <= 0 -> nichts tun (alle Eintraege bleiben).
|
||||||
|
/// </summary>
|
||||||
|
public static void PruneOlderThan(int days)
|
||||||
|
{
|
||||||
|
if (days <= 0) return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
if (!File.Exists(LogFilePath)) return;
|
||||||
|
var cutoff = DateTime.Now.AddDays(-days);
|
||||||
|
var lines = File.ReadAllLines(LogFilePath, Encoding.UTF8);
|
||||||
|
var kept = new List<string>(lines.Length);
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
// Eintraege ohne erkennbaren Zeitstempel (z.B. Fortsetzungs-
|
||||||
|
// zeilen) bleiben erhalten; nur datierte Alt-Eintraege fliegen raus.
|
||||||
|
if (TryParseLineDate(line, out var dt) && dt < cutoff)
|
||||||
|
continue;
|
||||||
|
kept.Add(line);
|
||||||
|
}
|
||||||
|
if (kept.Count != lines.Length)
|
||||||
|
File.WriteAllLines(LogFilePath, kept, Encoding.UTF8);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TryParseLineDate(string line, out DateTime dt)
|
||||||
|
{
|
||||||
|
dt = default;
|
||||||
|
// Format: "[yyyy-MM-dd HH:mm:ss] ..."
|
||||||
|
if (line != null && line.Length >= 21 && line[0] == '[' && line[20] == ']')
|
||||||
|
{
|
||||||
|
return DateTime.TryParseExact(line.Substring(1, 19), "yyyy-MM-dd HH:mm:ss",
|
||||||
|
CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Clear()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
lock (_lock)
|
||||||
|
{
|
||||||
|
if (File.Exists(LogFilePath)) File.Delete(LogFilePath);
|
||||||
|
var bak = LogFilePath + ".1";
|
||||||
|
if (File.Exists(bak)) File.Delete(bak);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,163 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using StarfaceOutlookSync.Models;
|
||||||
|
|
||||||
|
namespace StarfaceOutlookSync.Services
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Gemeinsame Orchestrierung fuer JEDEN Sync-Lauf - egal ob automatisch
|
||||||
|
/// (Tray/Timer) oder manuell (Fortschrittsfenster). Sorgt einheitlich fuer:
|
||||||
|
/// - lokalen Re-Entrancy-Schutz (prozessweit, statisch),
|
||||||
|
/// - clientuebergreifende Lock-Datei,
|
||||||
|
/// - Anzeige/Logging von Konflikt-Notizen anderer Arbeitsplaetze,
|
||||||
|
/// - Protokollierung (Start, Ergebnis, Aenderungen, Konflikte, Fehler),
|
||||||
|
/// - Verteilen eigener Konflikt-Notizen.
|
||||||
|
/// Die eigentliche UI (Tray-Meldung vs. Fenster) bleibt beim Aufrufer.
|
||||||
|
/// </summary>
|
||||||
|
public class SyncCoordinator
|
||||||
|
{
|
||||||
|
// Prozessweit: nie zwei Syncs gleichzeitig - auch nicht manuell + automatisch.
|
||||||
|
private static int _running = 0;
|
||||||
|
|
||||||
|
private readonly ProfileManager _profileManager = new ProfileManager();
|
||||||
|
private readonly ConflictNotifier _notifier = new ConflictNotifier();
|
||||||
|
|
||||||
|
public class SyncOutcome
|
||||||
|
{
|
||||||
|
public bool Skipped;
|
||||||
|
public string SkipReason = "";
|
||||||
|
public SyncResult Result;
|
||||||
|
public Exception Error;
|
||||||
|
public List<ConflictNotice> RemoteNotices = new List<ConflictNotice>();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Fuehrt einen Sync koordiniert aus. runEngine kapselt den eigentlichen
|
||||||
|
/// Engine-Aufruf (inkl. ggf. Task.Run/Progress-Anbindung des Aufrufers),
|
||||||
|
/// damit das Threading-Verhalten pro Pfad erhalten bleibt. status erhaelt
|
||||||
|
/// Fortschrittstexte (Warten auf Sperre, Synchronisiere ...).
|
||||||
|
/// </summary>
|
||||||
|
public async Task<SyncOutcome> RunAsync(SyncProfile profile,
|
||||||
|
Func<Task<SyncResult>> runEngine, Action<string> status)
|
||||||
|
{
|
||||||
|
var outcome = new SyncOutcome();
|
||||||
|
|
||||||
|
if (Interlocked.CompareExchange(ref _running, 1, 0) != 0)
|
||||||
|
{
|
||||||
|
outcome.Skipped = true;
|
||||||
|
outcome.SkipReason = "Sync laeuft bereits, bitte warten...";
|
||||||
|
return outcome;
|
||||||
|
}
|
||||||
|
|
||||||
|
SyncLock crossLock = null;
|
||||||
|
var settings = UserSettings.Load();
|
||||||
|
Logger.PruneOlderThan(settings.LogRetentionDays);
|
||||||
|
var sharedDir = settings.SharedDirectory;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
crossLock = await AcquireCrossClientLock(sharedDir, status);
|
||||||
|
if (crossLock == null)
|
||||||
|
{
|
||||||
|
outcome.Skipped = true;
|
||||||
|
outcome.SkipReason = "Anderer Arbeitsplatz synchronisiert gerade - uebersprungen.";
|
||||||
|
Logger.Log($"Sync '{profile.Name}' uebersprungen: anderer Arbeitsplatz synct gerade.");
|
||||||
|
return outcome;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Konflikt-Hinweise anderer Arbeitsplaetze ermitteln, BEVOR der Sync
|
||||||
|
// den eigenen Stand auf den Gewinner-Wert angleicht.
|
||||||
|
try
|
||||||
|
{
|
||||||
|
outcome.RemoteNotices = _notifier.GetPending(sharedDir, MyContactsByStarfaceId());
|
||||||
|
foreach (var n in outcome.RemoteNotices)
|
||||||
|
Logger.Log($" KONFLIKT (anderer Arbeitsplatz): {n}");
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
Logger.Log($"Sync gestartet: '{profile.Name}' (Richtung: {profile.SyncDirection})");
|
||||||
|
status?.Invoke($"Synchronisiere '{profile.Name}'...");
|
||||||
|
|
||||||
|
SyncResult result;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
result = await runEngine();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
outcome.Error = ex;
|
||||||
|
Logger.Log($"Sync FEHLER '{profile.Name}': {ex.Message}");
|
||||||
|
return outcome;
|
||||||
|
}
|
||||||
|
outcome.Result = result;
|
||||||
|
|
||||||
|
var msg = $"{profile.Name}: {result.Created} erstellt, {result.Updated} aktualisiert"
|
||||||
|
+ (result.Errors > 0 ? $", {result.Errors} Fehler" : "")
|
||||||
|
+ (result.Conflicts.Count > 0 ? $", {result.Conflicts.Count} Konflikt(e)" : "");
|
||||||
|
|
||||||
|
Logger.Log($"Sync fertig: {msg}");
|
||||||
|
foreach (var ch in result.Changes) Logger.Log($" {ch}");
|
||||||
|
foreach (var em in result.ErrorMessages) Logger.Log($" Fehler: {em}");
|
||||||
|
foreach (var c in result.Conflicts) Logger.Log($" KONFLIKT: {c}");
|
||||||
|
|
||||||
|
// Andere Arbeitsplaetze ueber eigene Konflikte informieren.
|
||||||
|
if (result.Conflicts.Count > 0)
|
||||||
|
_notifier.Write(sharedDir, result.Conflicts);
|
||||||
|
|
||||||
|
return outcome;
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
crossLock?.Dispose();
|
||||||
|
Interlocked.Exchange(ref _running, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task<SyncLock> AcquireCrossClientLock(string dir, Action<string> status)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(dir))
|
||||||
|
return SyncLock.NoOp();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Legt das Verzeichnis bei Bedarf an (idempotent). Funktioniert mit
|
||||||
|
// UNC-Pfaden (\\server\freigabe\...) - kein Netzlaufwerk noetig.
|
||||||
|
Directory.CreateDirectory(dir);
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
status?.Invoke("Gemeinsames Verzeichnis nicht erreichbar - synce ohne Sperre.");
|
||||||
|
return SyncLock.NoOp();
|
||||||
|
}
|
||||||
|
|
||||||
|
var deadline = DateTime.UtcNow.AddMinutes(2);
|
||||||
|
int attempt = 0;
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
var l = SyncLock.TryAcquire(dir, out var heldBy);
|
||||||
|
if (l != null) return l;
|
||||||
|
if (DateTime.UtcNow >= deadline) return null;
|
||||||
|
|
||||||
|
attempt++;
|
||||||
|
status?.Invoke($"Warte auf anderen Arbeitsplatz ({heldBy ?? "unbekannt"})... ({attempt})");
|
||||||
|
await Task.Delay(3000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<string, UnifiedContact> MyContactsByStarfaceId()
|
||||||
|
{
|
||||||
|
var map = new Dictionary<string, UnifiedContact>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
foreach (var p in _profileManager.GetProfiles())
|
||||||
|
foreach (var m in _profileManager.GetMappings(p.Id))
|
||||||
|
if (!string.IsNullOrEmpty(m.StarfaceId) && !map.ContainsKey(m.StarfaceId))
|
||||||
|
map[m.StarfaceId] = m.LastOutlook;
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,6 +15,13 @@ namespace StarfaceOutlookSync.Services
|
|||||||
|
|
||||||
private void Log(string message) => OnProgress?.Invoke(message);
|
private void Log(string message) => OnProgress?.Invoke(message);
|
||||||
|
|
||||||
|
/// <summary>Protokolliert eine tatsaechliche Aenderung (fuer Live-Log UND SyncResult.Changes).</summary>
|
||||||
|
private void Action(SyncResult result, string message)
|
||||||
|
{
|
||||||
|
Log(" " + message);
|
||||||
|
result?.Changes.Add(message);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Setzt die Baseline eines Mappings auf den uebergebenen Stand beider
|
/// Setzt die Baseline eines Mappings auf den uebergebenen Stand beider
|
||||||
/// Seiten (Snapshot + Hash). Der Snapshot wird fuer das Feld-Merge bei
|
/// Seiten (Snapshot + Hash). Der Snapshot wird fuer das Feld-Merge bei
|
||||||
@@ -184,7 +191,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
if (await starface.DeleteContactAsync(mapping.StarfaceId))
|
if (await starface.DeleteContactAsync(mapping.StarfaceId))
|
||||||
{
|
{
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Geloescht (OL->SF): {sc.DisplayName}");
|
Action(result, $"Geloescht (OL->SF): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -202,7 +209,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
if (await starface.DeleteContactAsync(mapping.StarfaceId))
|
if (await starface.DeleteContactAsync(mapping.StarfaceId))
|
||||||
{
|
{
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Geloescht (OL->SF): {sc.DisplayName}");
|
Action(result, $"Geloescht (OL->SF): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -245,7 +252,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
if (_outlookService.DeleteContact(oc.OutlookEntryId))
|
if (_outlookService.DeleteContact(oc.OutlookEntryId))
|
||||||
{
|
{
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Geloescht (SF->OL): {oc.DisplayName}");
|
Action(result, $"Geloescht (SF->OL): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -263,7 +270,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
if (_outlookService.DeleteContact(oc.OutlookEntryId))
|
if (_outlookService.DeleteContact(oc.OutlookEntryId))
|
||||||
{
|
{
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Geloescht (SF->OL): {oc.DisplayName}");
|
Action(result, $"Geloescht (SF->OL): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -322,7 +329,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
{
|
{
|
||||||
SetBaseline(mapping, oc, updated);
|
SetBaseline(mapping, oc, updated);
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Aktualisiert (OL->SF): {oc.DisplayName}");
|
Action(result, $"Aktualisiert (OL->SF): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (sfChanged && !olChanged && (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.StarfaceToOutlook))
|
else if (sfChanged && !olChanged && (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.StarfaceToOutlook))
|
||||||
@@ -333,7 +340,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
{
|
{
|
||||||
SetBaseline(mapping, updated, sc);
|
SetBaseline(mapping, updated, sc);
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Aktualisiert (SF->OL): {sc.DisplayName}");
|
Action(result, $"Aktualisiert (SF->OL): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (olChanged && sfChanged)
|
else if (olChanged && sfChanged)
|
||||||
@@ -366,9 +373,9 @@ namespace StarfaceOutlookSync.Services
|
|||||||
mapping.LastSyncHash = "";
|
mapping.LastSyncHash = "";
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
foreach (var cf in conflicts) result.Conflicts.Add(cf);
|
foreach (var cf in conflicts) result.Conflicts.Add(cf);
|
||||||
Log(conflicts.Count > 0
|
Action(result, conflicts.Count > 0
|
||||||
? $" Beidseitig geaendert, zusammengefuehrt ({conflicts.Count} Feld-Konflikt(e), Outlook gewinnt): {oc.DisplayName}"
|
? $"Beidseitig geaendert, zusammengefuehrt ({conflicts.Count} Feld-Konflikt(e), Outlook gewinnt): {oc.DisplayName}"
|
||||||
: $" Beidseitig geaendert, zusammengefuehrt: {oc.DisplayName}");
|
: $"Beidseitig geaendert, zusammengefuehrt: {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (profile.SyncDirection != SyncDirection.StarfaceToOutlook)
|
else if (profile.SyncDirection != SyncDirection.StarfaceToOutlook)
|
||||||
@@ -380,7 +387,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
{
|
{
|
||||||
SetBaseline(mapping, oc, updated);
|
SetBaseline(mapping, oc, updated);
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Konflikt (OL gewinnt): {oc.DisplayName}");
|
Action(result, $"Konflikt (OL gewinnt): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -390,7 +397,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
{
|
{
|
||||||
SetBaseline(mapping, updated, sc);
|
SetBaseline(mapping, updated, sc);
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Konflikt (SF gewinnt): {sc.DisplayName}");
|
Action(result, $"Konflikt (SF gewinnt): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -441,7 +448,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
processedStarfaceIds.Add(match.StarfaceId);
|
processedStarfaceIds.Add(match.StarfaceId);
|
||||||
unmappedStarface.Remove(match);
|
unmappedStarface.Remove(match);
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Verknuepft (OL->SF): {oc.DisplayName}");
|
Action(result, $"Verknuepft (OL->SF): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -462,7 +469,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
LastStarfaceHash = created.GetHash()
|
LastStarfaceHash = created.GetHash()
|
||||||
});
|
});
|
||||||
result.Created++;
|
result.Created++;
|
||||||
Log($" Erstellt (OL->SF): {oc.DisplayName}");
|
Action(result, $"Erstellt (OL->SF): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -521,7 +528,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
processedOutlookIds.Add(match.OutlookEntryId);
|
processedOutlookIds.Add(match.OutlookEntryId);
|
||||||
unmappedOutlook.Remove(match);
|
unmappedOutlook.Remove(match);
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Verknuepft (SF->OL): {sc.DisplayName}");
|
Action(result, $"Verknuepft (SF->OL): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -541,7 +548,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
LastOutlookHash = created.GetHash()
|
LastOutlookHash = created.GetHash()
|
||||||
});
|
});
|
||||||
result.Created++;
|
result.Created++;
|
||||||
Log($" Erstellt (SF->OL): {sc.DisplayName}");
|
Action(result, $"Erstellt (SF->OL): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -581,7 +588,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
if (await starface.DeleteContactAsync(sc.StarfaceId))
|
if (await starface.DeleteContactAsync(sc.StarfaceId))
|
||||||
{
|
{
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Geloescht (nur in Starface): {sc.DisplayName}");
|
Action(result, $"Geloescht (nur in Starface): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -612,7 +619,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
if (_outlookService.DeleteContact(oc.OutlookEntryId))
|
if (_outlookService.DeleteContact(oc.OutlookEntryId))
|
||||||
{
|
{
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
Log($" Geloescht (nur in Outlook): {oc.DisplayName}");
|
Action(result, $"Geloescht (nur in Outlook): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -7,9 +7,9 @@
|
|||||||
<AssemblyTitle>Starface Outlook Sync</AssemblyTitle>
|
<AssemblyTitle>Starface Outlook Sync</AssemblyTitle>
|
||||||
<Company>HackerSoft - Hacker-Net Telekommunikation</Company>
|
<Company>HackerSoft - Hacker-Net Telekommunikation</Company>
|
||||||
<Product>Starface Outlook Sync</Product>
|
<Product>Starface Outlook Sync</Product>
|
||||||
<Version>0.0.0.28</Version>
|
<Version>0.0.0.30</Version>
|
||||||
<AssemblyVersion>0.0.0.28</AssemblyVersion>
|
<AssemblyVersion>0.0.0.30</AssemblyVersion>
|
||||||
<FileVersion>0.0.0.28</FileVersion>
|
<FileVersion>0.0.0.30</FileVersion>
|
||||||
<Description>Synchronisiert Outlook-Kontakte mit Starface Telefonanlage</Description>
|
<Description>Synchronisiert Outlook-Kontakte mit Starface Telefonanlage</Description>
|
||||||
<Copyright>Stefan Hacker - HackerSoft</Copyright>
|
<Copyright>Stefan Hacker - HackerSoft</Copyright>
|
||||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace StarfaceOutlookSync.UI
|
|||||||
|
|
||||||
var lblVersion = new Label
|
var lblVersion = new Label
|
||||||
{
|
{
|
||||||
Text = "Version 0.0.0.28",
|
Text = "Version 0.0.0.30",
|
||||||
Left = 0, Top = 56, Width = 340, Height = 20,
|
Left = 0, Top = 56, Width = 340, Height = 20,
|
||||||
TextAlign = ContentAlignment.MiddleCenter,
|
TextAlign = ContentAlignment.MiddleCenter,
|
||||||
ForeColor = Color.Gray
|
ForeColor = Color.Gray
|
||||||
|
|||||||
@@ -0,0 +1,92 @@
|
|||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.IO;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using StarfaceOutlookSync.Models;
|
||||||
|
using StarfaceOutlookSync.Services;
|
||||||
|
|
||||||
|
namespace StarfaceOutlookSync.UI
|
||||||
|
{
|
||||||
|
/// <summary>Zeigt das Sync-Protokoll an (read-only) mit Aktualisieren/Leeren.</summary>
|
||||||
|
public class LogViewerForm : Form
|
||||||
|
{
|
||||||
|
private TextBox _txt;
|
||||||
|
private Button _btnClose;
|
||||||
|
private Panel _panel;
|
||||||
|
|
||||||
|
public LogViewerForm()
|
||||||
|
{
|
||||||
|
Text = "Protokoll";
|
||||||
|
Size = new Size(720, 500);
|
||||||
|
StartPosition = FormStartPosition.CenterParent;
|
||||||
|
Font = new Font("Segoe UI", 9);
|
||||||
|
|
||||||
|
_txt = new TextBox
|
||||||
|
{
|
||||||
|
Multiline = true,
|
||||||
|
ReadOnly = true,
|
||||||
|
ScrollBars = ScrollBars.Both,
|
||||||
|
WordWrap = false,
|
||||||
|
Dock = DockStyle.Fill,
|
||||||
|
BackColor = Color.White,
|
||||||
|
Font = new Font("Consolas", 9)
|
||||||
|
};
|
||||||
|
|
||||||
|
_panel = new Panel { Dock = DockStyle.Bottom, Height = 44 };
|
||||||
|
|
||||||
|
var btnRefresh = new Button { Text = "Aktualisieren", Left = 10, Top = 8, Width = 100, Height = 28 };
|
||||||
|
btnRefresh.Click += (s, e) => LoadLog();
|
||||||
|
|
||||||
|
var btnClear = new Button { Text = "Leeren", Left = 118, Top = 8, Width = 80, Height = 28 };
|
||||||
|
btnClear.Click += (s, e) =>
|
||||||
|
{
|
||||||
|
if (MessageBox.Show("Protokoll wirklich leeren?", "Protokoll",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
Logger.Clear();
|
||||||
|
LoadLog();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var btnFolder = new Button { Text = "Ordner oeffnen", Left = 206, Top = 8, Width = 120, Height = 28 };
|
||||||
|
btnFolder.Click += (s, e) => OpenFolder();
|
||||||
|
|
||||||
|
_btnClose = new Button
|
||||||
|
{
|
||||||
|
Text = "Schliessen", Top = 8, Width = 100, Height = 28,
|
||||||
|
Anchor = AnchorStyles.Top | AnchorStyles.Right
|
||||||
|
};
|
||||||
|
_btnClose.Click += (s, e) => Close();
|
||||||
|
|
||||||
|
_panel.Controls.AddRange(new Control[] { btnRefresh, btnClear, btnFolder, _btnClose });
|
||||||
|
|
||||||
|
Controls.Add(_txt);
|
||||||
|
Controls.Add(_panel);
|
||||||
|
|
||||||
|
Load += (s, e) =>
|
||||||
|
{
|
||||||
|
_btnClose.Left = _panel.ClientSize.Width - _btnClose.Width - 10;
|
||||||
|
LoadLog();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LoadLog()
|
||||||
|
{
|
||||||
|
Logger.PruneOlderThan(UserSettings.Load().LogRetentionDays);
|
||||||
|
_txt.Text = Logger.ReadAll();
|
||||||
|
_txt.SelectionStart = _txt.TextLength;
|
||||||
|
_txt.ScrollToCaret();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OpenFolder()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var dir = Path.GetDirectoryName(Logger.LogFilePath);
|
||||||
|
Process.Start(new ProcessStartInfo { FileName = dir, UseShellExecute = true });
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,6 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
@@ -16,17 +15,18 @@ namespace StarfaceOutlookSync.UI
|
|||||||
{
|
{
|
||||||
private readonly ProfileManager _profileManager = new ProfileManager();
|
private readonly ProfileManager _profileManager = new ProfileManager();
|
||||||
private readonly SyncEngine _syncEngine = new SyncEngine();
|
private readonly SyncEngine _syncEngine = new SyncEngine();
|
||||||
private readonly ConflictNotifier _conflictNotifier = new ConflictNotifier();
|
private readonly SyncCoordinator _coordinator = new SyncCoordinator();
|
||||||
private NotifyIcon _trayIcon;
|
private NotifyIcon _trayIcon;
|
||||||
private ContextMenuStrip _trayMenu;
|
private ContextMenuStrip _trayMenu;
|
||||||
private ListView _profileList;
|
private ListView _profileList;
|
||||||
private Button _btnNew, _btnEdit, _btnDelete, _btnSync, _btnReset, _btnSettings, _btnInfo;
|
private Button _btnNew, _btnEdit, _btnDelete, _btnSync, _btnReset, _btnSettings, _btnLog, _btnInfo;
|
||||||
private StatusStrip _statusBar;
|
private StatusStrip _statusBar;
|
||||||
private ToolStripStatusLabel _statusLabel;
|
private ToolStripStatusLabel _statusLabel;
|
||||||
private Timer _autoSyncTimer;
|
private Timer _autoSyncTimer;
|
||||||
// 0 = frei, 1 = Sync laeuft. Per Interlocked atomar geschaltet, damit
|
|
||||||
// ein manueller Sync und der Auto-Sync-Timer nicht gleichzeitig starten.
|
// Aktive Benachrichtigungs-Einstellung (pro Sync-Lauf gesetzt).
|
||||||
private int _syncRunning = 0;
|
private bool _notifyGeneral = true;
|
||||||
|
private bool _notifyWarn = true;
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
@@ -39,6 +39,9 @@ namespace StarfaceOutlookSync.UI
|
|||||||
var settings = UserSettings.Load();
|
var settings = UserSettings.Load();
|
||||||
settings.ApplyOutlookSecuritySetting();
|
settings.ApplyOutlookSecuritySetting();
|
||||||
|
|
||||||
|
// Protokoll bei Bedarf auf das eingestellte Alter eindampfen.
|
||||||
|
Logger.PruneOlderThan(settings.LogRetentionDays);
|
||||||
|
|
||||||
if (settings.StartMinimized)
|
if (settings.StartMinimized)
|
||||||
{
|
{
|
||||||
WindowState = FormWindowState.Minimized;
|
WindowState = FormWindowState.Minimized;
|
||||||
@@ -129,10 +132,13 @@ namespace StarfaceOutlookSync.UI
|
|||||||
_btnSettings = new Button { Text = "Einstellungen", Width = 95, Height = 30 };
|
_btnSettings = new Button { Text = "Einstellungen", Width = 95, Height = 30 };
|
||||||
_btnSettings.Click += (s, e) => ShowSettings();
|
_btnSettings.Click += (s, e) => ShowSettings();
|
||||||
|
|
||||||
|
_btnLog = new Button { Text = "Protokoll", Width = 80, Height = 30 };
|
||||||
|
_btnLog.Click += (s, e) => ShowLog();
|
||||||
|
|
||||||
_btnInfo = new Button { Text = "Info", Width = 50, Height = 30 };
|
_btnInfo = new Button { Text = "Info", Width = 50, Height = 30 };
|
||||||
_btnInfo.Click += (s, e) => ShowAbout();
|
_btnInfo.Click += (s, e) => ShowAbout();
|
||||||
|
|
||||||
buttonPanel.Controls.AddRange(new Control[] { _btnNew, _btnEdit, _btnDelete, _btnSync, _btnReset, _btnSettings, _btnInfo });
|
buttonPanel.Controls.AddRange(new Control[] { _btnNew, _btnEdit, _btnDelete, _btnSync, _btnReset, _btnSettings, _btnLog, _btnInfo });
|
||||||
|
|
||||||
// Statusbar
|
// Statusbar
|
||||||
_statusBar = new StatusStrip();
|
_statusBar = new StatusStrip();
|
||||||
@@ -341,152 +347,83 @@ namespace StarfaceOutlookSync.UI
|
|||||||
|
|
||||||
private async Task RunSync(SyncProfile profile)
|
private async Task RunSync(SyncProfile profile)
|
||||||
{
|
{
|
||||||
// Atomar pruefen-und-setzen: verhindert, dass manueller Sync und
|
var settings = UserSettings.Load();
|
||||||
// Auto-Sync-Timer gleichzeitig denselben/einen Sync starten.
|
_notifyGeneral = settings.NotificationsEnabled;
|
||||||
if (Interlocked.CompareExchange(ref _syncRunning, 1, 0) != 0)
|
_notifyWarn = settings.NotifyWarningsErrors;
|
||||||
{
|
|
||||||
SetStatus("Sync laeuft bereits, bitte warten...");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SyncLock crossLock = null;
|
|
||||||
var sharedDir = UserSettings.Load().SharedDirectory;
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Clientuebergreifende Sperre (falls gemeinsames Verzeichnis konfiguriert).
|
// Lokaler Guard, Lock-Datei, Konflikt-Notizen und Protokoll laufen
|
||||||
crossLock = await AcquireCrossClientLock(sharedDir);
|
// zentral im Coordinator (gemeinsam mit dem manuellen Sync-Pfad).
|
||||||
if (crossLock == null)
|
var outcome = await _coordinator.RunAsync(
|
||||||
|
profile,
|
||||||
|
runEngine: () => _syncEngine.SyncProfileAsync(profile),
|
||||||
|
status: SetStatus);
|
||||||
|
|
||||||
|
if (outcome.Skipped)
|
||||||
{
|
{
|
||||||
SetStatus("Anderer Arbeitsplatz synchronisiert gerade - uebersprungen.");
|
SetStatus(outcome.SkipReason);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Konflikt-Hinweise von ANDEREN Arbeitsplaetzen anzeigen, BEVOR der
|
// Konflikt-Hinweise anderer Arbeitsplaetze als Tray-Meldung (falls aktiv).
|
||||||
// Sync den eigenen Stand auf den Gewinner-Wert aktualisiert (sonst
|
ShowRemoteNoticesTray(outcome.RemoteNotices);
|
||||||
// koennte man nicht mehr erkennen, ob man betroffen war).
|
|
||||||
ShowRemoteConflictNotices(sharedDir);
|
|
||||||
|
|
||||||
SetStatus($"Synchronisiere '{profile.Name}'...");
|
if (outcome.Error != null)
|
||||||
_trayIcon.ShowBalloonTip(2000, "Starface Sync",
|
{
|
||||||
$"Synchronisiere '{profile.Name}'...", ToolTipIcon.Info);
|
Balloon(3000, "Starface Sync Fehler", outcome.Error.Message, ToolTipIcon.Error, warn: true);
|
||||||
|
SetStatus($"Fehler: {outcome.Error.Message}");
|
||||||
var result = await _syncEngine.SyncProfileAsync(profile);
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var result = outcome.Result;
|
||||||
var msg = $"{profile.Name}: {result.Created} erstellt, {result.Updated} aktualisiert";
|
var msg = $"{profile.Name}: {result.Created} erstellt, {result.Updated} aktualisiert";
|
||||||
if (result.Errors > 0) msg += $", {result.Errors} Fehler";
|
if (result.Errors > 0) msg += $", {result.Errors} Fehler";
|
||||||
if (result.Conflicts.Count > 0) msg += $", {result.Conflicts.Count} Konflikt(e)";
|
if (result.Conflicts.Count > 0) msg += $", {result.Conflicts.Count} Konflikt(e)";
|
||||||
|
|
||||||
_trayIcon.ShowBalloonTip(3000, "Starface Sync", msg,
|
// Zusammenfassung als Warnung werten, wenn Fehler/Konflikte auftraten.
|
||||||
result.Errors > 0 ? ToolTipIcon.Warning : ToolTipIcon.Info);
|
bool noteworthy = result.Errors > 0 || result.Conflicts.Count > 0;
|
||||||
|
Balloon(3000, "Starface Sync", msg,
|
||||||
|
result.Errors > 0 ? ToolTipIcon.Warning : ToolTipIcon.Info, warn: noteworthy);
|
||||||
|
|
||||||
// Echte Feld-Konflikte gesondert melden, damit der Benutzer weiss,
|
// Echte Feld-Konflikte gesondert melden (eigener Wert wurde ueberschrieben).
|
||||||
// dass ein Wert ueberschrieben wurde.
|
|
||||||
if (result.Conflicts.Count > 0)
|
if (result.Conflicts.Count > 0)
|
||||||
{
|
{
|
||||||
var detail = string.Join("\n", result.Conflicts.Take(5).Select(c => c.ToString()));
|
var detail = string.Join("\n", result.Conflicts.Take(5).Select(c => c.ToString()));
|
||||||
if (result.Conflicts.Count > 5)
|
if (result.Conflicts.Count > 5)
|
||||||
detail += $"\n... und {result.Conflicts.Count - 5} weitere";
|
detail += $"\n... und {result.Conflicts.Count - 5} weitere";
|
||||||
_trayIcon.ShowBalloonTip(10000,
|
Balloon(10000, $"Konflikt bei {result.Conflicts.Count} Kontakt(en)", detail, ToolTipIcon.Warning, warn: true);
|
||||||
$"Konflikt bei {result.Conflicts.Count} Kontakt(en)", detail, ToolTipIcon.Warning);
|
|
||||||
|
|
||||||
// Andere Arbeitsplaetze ueber das gemeinsame Verzeichnis informieren.
|
|
||||||
_conflictNotifier.Write(sharedDir, result.Conflicts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetStatus(msg);
|
SetStatus(msg);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_trayIcon.ShowBalloonTip(3000, "Starface Sync Fehler",
|
Balloon(3000, "Starface Sync Fehler", ex.Message, ToolTipIcon.Error, warn: true);
|
||||||
ex.Message, ToolTipIcon.Error);
|
|
||||||
SetStatus($"Fehler: {ex.Message}");
|
SetStatus($"Fehler: {ex.Message}");
|
||||||
}
|
Logger.Log($"Sync FEHLER '{profile.Name}': {ex.Message}");
|
||||||
finally
|
|
||||||
{
|
|
||||||
crossLock?.Dispose();
|
|
||||||
Interlocked.Exchange(ref _syncRunning, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>Zeigt Konflikt-Hinweise anderer Arbeitsplaetze als Tray-Meldung.</summary>
|
||||||
/// Holt die clientuebergreifende Lock-Datei aus dem konfigurierten
|
private void ShowRemoteNoticesTray(System.Collections.Generic.List<ConflictNotice> notices)
|
||||||
/// gemeinsamen Verzeichnis. Wartet bis zu 2 Minuten, falls ein anderer
|
|
||||||
/// Arbeitsplatz gerade synct. Gibt null zurueck, wenn die Sperre nicht
|
|
||||||
/// erlangt werden konnte (-> diesen Lauf ueberspringen).
|
|
||||||
/// Ist kein Verzeichnis konfiguriert oder es ist nicht erreichbar, wird
|
|
||||||
/// ohne clientuebergreifende Sperre fortgefahren (lokaler Schutz bleibt).
|
|
||||||
/// </summary>
|
|
||||||
private async Task<SyncLock> AcquireCrossClientLock(string dir)
|
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(dir))
|
if (notices == null || notices.Count == 0) return;
|
||||||
return SyncLock.NoOp();
|
var detail = string.Join("\n", notices.Take(5).Select(p => p.ToString()));
|
||||||
|
if (notices.Count > 5)
|
||||||
try
|
detail += $"\n... und {notices.Count - 5} weitere";
|
||||||
{
|
Balloon(10000, $"Konflikt an anderem Arbeitsplatz ({notices.Count})", detail, ToolTipIcon.Warning, warn: true);
|
||||||
// Legt das Verzeichnis bei Bedarf an (idempotent). Funktioniert mit
|
|
||||||
// UNC-Pfaden (\\server\freigabe\...) - kein Netzlaufwerk noetig.
|
|
||||||
System.IO.Directory.CreateDirectory(dir);
|
|
||||||
}
|
|
||||||
catch
|
|
||||||
{
|
|
||||||
SetStatus("Gemeinsames Verzeichnis nicht erreichbar - synce ohne Sperre.");
|
|
||||||
return SyncLock.NoOp();
|
|
||||||
}
|
|
||||||
|
|
||||||
var deadline = DateTime.UtcNow.AddMinutes(2);
|
|
||||||
int attempt = 0;
|
|
||||||
while (true)
|
|
||||||
{
|
|
||||||
var l = SyncLock.TryAcquire(dir, out var heldBy);
|
|
||||||
if (l != null) return l;
|
|
||||||
|
|
||||||
if (DateTime.UtcNow >= deadline) return null;
|
|
||||||
|
|
||||||
attempt++;
|
|
||||||
SetStatus($"Warte auf anderen Arbeitsplatz ({heldBy ?? "unbekannt"})... ({attempt})");
|
|
||||||
await Task.Delay(3000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Zeigt Konflikt-Hinweise an, die andere Arbeitsplaetze ueber das
|
/// Zeigt eine Tray-Meldung - aber nur, wenn die passende Benachrichtigungs-
|
||||||
/// gemeinsame Verzeichnis hinterlassen haben und Kontakte betreffen, die
|
/// Einstellung aktiv ist. warn=true -> Warnungen/Fehler (Konflikte, Fehler),
|
||||||
/// auch dieser Client gemappt hat.
|
/// warn=false -> allgemeine Info-Meldungen.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
private void ShowRemoteConflictNotices(string sharedDir)
|
private void Balloon(int ms, string title, string text, ToolTipIcon icon, bool warn)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrWhiteSpace(sharedDir)) return;
|
bool allow = warn ? _notifyWarn : _notifyGeneral;
|
||||||
try
|
if (allow) _trayIcon.ShowBalloonTip(ms, title, text, icon);
|
||||||
{
|
|
||||||
var pending = _conflictNotifier.GetPending(sharedDir, MyContactsByStarfaceId());
|
|
||||||
if (pending.Count == 0) return;
|
|
||||||
|
|
||||||
var detail = string.Join("\n", pending.Take(5).Select(p => p.ToString()));
|
|
||||||
if (pending.Count > 5)
|
|
||||||
detail += $"\n... und {pending.Count - 5} weitere";
|
|
||||||
_trayIcon.ShowBalloonTip(10000,
|
|
||||||
$"Konflikt an anderem Arbeitsplatz ({pending.Count})", detail, ToolTipIcon.Warning);
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Eigener Kontaktstand je StarfaceId (ueber alle Profile), aus den
|
|
||||||
/// Mapping-Snapshots. Dient dazu, bei Konflikt-Notizen zu pruefen, ob der
|
|
||||||
/// eigene Feldwert ueberhaupt vom uebernommenen Wert abweicht.
|
|
||||||
/// </summary>
|
|
||||||
private Dictionary<string, UnifiedContact> MyContactsByStarfaceId()
|
|
||||||
{
|
|
||||||
var map = new Dictionary<string, UnifiedContact>(StringComparer.OrdinalIgnoreCase);
|
|
||||||
try
|
|
||||||
{
|
|
||||||
foreach (var p in _profileManager.GetProfiles())
|
|
||||||
foreach (var m in _profileManager.GetMappings(p.Id))
|
|
||||||
if (!string.IsNullOrEmpty(m.StarfaceId) && !map.ContainsKey(m.StarfaceId))
|
|
||||||
map[m.StarfaceId] = m.LastOutlook;
|
|
||||||
}
|
|
||||||
catch { }
|
|
||||||
return map;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetStatus(string text)
|
private void SetStatus(string text)
|
||||||
@@ -513,6 +450,14 @@ namespace StarfaceOutlookSync.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ShowLog()
|
||||||
|
{
|
||||||
|
using (var log = new LogViewerForm())
|
||||||
|
{
|
||||||
|
log.ShowDialog(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ExitApplication()
|
private void ExitApplication()
|
||||||
{
|
{
|
||||||
_autoSyncTimer?.Stop();
|
_autoSyncTimer?.Stop();
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Windows.Forms;
|
using System.Windows.Forms;
|
||||||
using StarfaceOutlookSync.Models;
|
using StarfaceOutlookSync.Models;
|
||||||
|
using StarfaceOutlookSync.Services;
|
||||||
|
|
||||||
namespace StarfaceOutlookSync.UI
|
namespace StarfaceOutlookSync.UI
|
||||||
{
|
{
|
||||||
public class SettingsForm : Form
|
public class SettingsForm : Form
|
||||||
{
|
{
|
||||||
private CheckBox _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook;
|
private CheckBox _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook;
|
||||||
|
private CheckBox _chkNotifGeneral, _chkNotifWarn;
|
||||||
|
private CheckBox _chkAutostartUser, _chkAutostartAll;
|
||||||
|
private NumericUpDown _numLogRetention;
|
||||||
private TextBox _txtSharedDir;
|
private TextBox _txtSharedDir;
|
||||||
private Button _btnBrowseShared;
|
private Button _btnBrowseShared;
|
||||||
private Button _btnSave, _btnCancel;
|
private Button _btnSave, _btnCancel;
|
||||||
@@ -61,21 +65,47 @@ namespace StarfaceOutlookSync.UI
|
|||||||
Font = new Font("Segoe UI", 8)
|
Font = new Font("Segoe UI", 8)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
_chkNotifGeneral = new CheckBox
|
||||||
|
{
|
||||||
|
Text = "Tray-Benachrichtigungen (allgemein)",
|
||||||
|
Left = 20, Top = 144, AutoSize = true,
|
||||||
|
Checked = _settings.NotificationsEnabled
|
||||||
|
};
|
||||||
|
|
||||||
|
_chkNotifWarn = new CheckBox
|
||||||
|
{
|
||||||
|
Text = "Benachrichtigungen bei Warnungen/Fehlern (Konflikte, Fehler)",
|
||||||
|
Left = 20, Top = 170, AutoSize = true,
|
||||||
|
Checked = _settings.NotifyWarningsErrors
|
||||||
|
};
|
||||||
|
|
||||||
|
var lblLogRetention = new Label
|
||||||
|
{
|
||||||
|
Text = "Protokoll auto-leeren - Eintraege aelter als (Tage, 0 = aus):",
|
||||||
|
Left = 20, Top = 204, AutoSize = true
|
||||||
|
};
|
||||||
|
|
||||||
|
_numLogRetention = new NumericUpDown
|
||||||
|
{
|
||||||
|
Left = 305, Top = 200, Width = 55, Minimum = 0, Maximum = 3650,
|
||||||
|
Value = System.Math.Max(0, System.Math.Min(3650, _settings.LogRetentionDays))
|
||||||
|
};
|
||||||
|
|
||||||
var lblShared = new Label
|
var lblShared = new Label
|
||||||
{
|
{
|
||||||
Text = "Gemeinsames Verzeichnis fuer Sync-Sperre (Mehrplatz, optional):",
|
Text = "Gemeinsames Verzeichnis fuer Sync-Sperre (Mehrplatz, optional):",
|
||||||
Left = 20, Top = 150, AutoSize = true
|
Left = 20, Top = 240, AutoSize = true
|
||||||
};
|
};
|
||||||
|
|
||||||
_txtSharedDir = new TextBox
|
_txtSharedDir = new TextBox
|
||||||
{
|
{
|
||||||
Left = 20, Top = 172, Width = 250,
|
Left = 20, Top = 262, Width = 250,
|
||||||
Text = _settings.SharedDirectory
|
Text = _settings.SharedDirectory
|
||||||
};
|
};
|
||||||
|
|
||||||
_btnBrowseShared = new Button
|
_btnBrowseShared = new Button
|
||||||
{
|
{
|
||||||
Text = "...", Left = 274, Top = 171, Width = 36, Height = 24
|
Text = "...", Left = 274, Top = 261, Width = 36, Height = 24
|
||||||
};
|
};
|
||||||
_btnBrowseShared.Click += (s, e) => BrowseSharedDir();
|
_btnBrowseShared.Click += (s, e) => BrowseSharedDir();
|
||||||
|
|
||||||
@@ -83,26 +113,52 @@ namespace StarfaceOutlookSync.UI
|
|||||||
{
|
{
|
||||||
Text = "Netzlaufwerk/UNC, das alle Arbeitsplaetze erreichen. Leer = keine\n" +
|
Text = "Netzlaufwerk/UNC, das alle Arbeitsplaetze erreichen. Leer = keine\n" +
|
||||||
"clientuebergreifende Sperre (nur Schutz auf diesem PC).",
|
"clientuebergreifende Sperre (nur Schutz auf diesem PC).",
|
||||||
Left = 20, Top = 198, Width = 330, Height = 32,
|
Left = 20, Top = 288, Width = 330, Height = 32,
|
||||||
ForeColor = Color.Gray, Font = new Font("Segoe UI", 8)
|
ForeColor = Color.Gray, Font = new Font("Segoe UI", 8)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// === Autostart ===
|
||||||
|
bool isAdmin = AutostartManager.IsAdmin();
|
||||||
|
|
||||||
|
var lblAutostart = new Label
|
||||||
|
{
|
||||||
|
Text = "Autostart (bei Windows-Anmeldung starten)",
|
||||||
|
Left = 12, Top = 332, AutoSize = true, Font = new Font("Segoe UI", 10, FontStyle.Bold)
|
||||||
|
};
|
||||||
|
|
||||||
|
_chkAutostartUser = new CheckBox
|
||||||
|
{
|
||||||
|
Text = "Nur fuer diesen Benutzer",
|
||||||
|
Left = 20, Top = 360, AutoSize = true,
|
||||||
|
Checked = AutostartManager.GetUserAutostart()
|
||||||
|
};
|
||||||
|
|
||||||
|
_chkAutostartAll = new CheckBox
|
||||||
|
{
|
||||||
|
Text = "Fuer alle Benutzer" + (isAdmin ? "" : " (nur mit Admin-Rechten aenderbar)"),
|
||||||
|
Left = 20, Top = 386, AutoSize = true,
|
||||||
|
Checked = AutostartManager.GetMachineAutostart(),
|
||||||
|
Enabled = isAdmin
|
||||||
|
};
|
||||||
|
|
||||||
_btnSave = new Button
|
_btnSave = new Button
|
||||||
{
|
{
|
||||||
Text = "Speichern", Left = 95, Top = 240, Width = 85, Height = 28,
|
Text = "Speichern", Left = 95, Top = 422, Width = 85, Height = 28,
|
||||||
DialogResult = DialogResult.None
|
DialogResult = DialogResult.None
|
||||||
};
|
};
|
||||||
_btnSave.Click += (s, e) => Save();
|
_btnSave.Click += (s, e) => Save();
|
||||||
|
|
||||||
_btnCancel = new Button
|
_btnCancel = new Button
|
||||||
{
|
{
|
||||||
Text = "Abbrechen", Left = 189, Top = 240, Width = 85, Height = 28,
|
Text = "Abbrechen", Left = 189, Top = 422, Width = 85, Height = 28,
|
||||||
DialogResult = DialogResult.Cancel
|
DialogResult = DialogResult.Cancel
|
||||||
};
|
};
|
||||||
|
|
||||||
Size = new Size(380, 330);
|
Size = new Size(380, 512);
|
||||||
Controls.AddRange(new Control[] { _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook, lblHint,
|
Controls.AddRange(new Control[] { _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook, lblHint,
|
||||||
lblShared, _txtSharedDir, _btnBrowseShared, lblSharedHint, _btnSave, _btnCancel });
|
_chkNotifGeneral, _chkNotifWarn, lblLogRetention, _numLogRetention,
|
||||||
|
lblShared, _txtSharedDir, _btnBrowseShared, lblSharedHint,
|
||||||
|
lblAutostart, _chkAutostartUser, _chkAutostartAll, _btnSave, _btnCancel });
|
||||||
AcceptButton = _btnSave;
|
AcceptButton = _btnSave;
|
||||||
CancelButton = _btnCancel;
|
CancelButton = _btnCancel;
|
||||||
}
|
}
|
||||||
@@ -126,8 +182,25 @@ namespace StarfaceOutlookSync.UI
|
|||||||
_settings.StartMinimized = _chkStartMinimized.Checked;
|
_settings.StartMinimized = _chkStartMinimized.Checked;
|
||||||
_settings.SyncOnStart = _chkSyncOnStart.Checked;
|
_settings.SyncOnStart = _chkSyncOnStart.Checked;
|
||||||
_settings.AutoAcceptOutlookPrompt = _chkAutoAcceptOutlook.Checked;
|
_settings.AutoAcceptOutlookPrompt = _chkAutoAcceptOutlook.Checked;
|
||||||
|
_settings.NotificationsEnabled = _chkNotifGeneral.Checked;
|
||||||
|
_settings.NotifyWarningsErrors = _chkNotifWarn.Checked;
|
||||||
|
_settings.LogRetentionDays = (int)_numLogRetention.Value;
|
||||||
_settings.SharedDirectory = _txtSharedDir.Text.Trim();
|
_settings.SharedDirectory = _txtSharedDir.Text.Trim();
|
||||||
_settings.Save();
|
_settings.Save();
|
||||||
|
|
||||||
|
// Sofort anwenden, damit der Effekt direkt sichtbar ist.
|
||||||
|
Logger.PruneOlderThan(_settings.LogRetentionDays);
|
||||||
|
|
||||||
|
// Autostart (Registry). Pro Benutzer immer; alle Benutzer nur mit Admin.
|
||||||
|
AutostartManager.SetUserAutostart(_chkAutostartUser.Checked);
|
||||||
|
if (AutostartManager.IsAdmin())
|
||||||
|
{
|
||||||
|
if (!AutostartManager.SetMachineAutostart(_chkAutostartAll.Checked))
|
||||||
|
MessageBox.Show(this,
|
||||||
|
"Autostart fuer alle Benutzer konnte nicht geaendert werden (Rechte?).",
|
||||||
|
"Autostart", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
}
|
||||||
|
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
Close();
|
Close();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ namespace StarfaceOutlookSync.UI
|
|||||||
{
|
{
|
||||||
private readonly SyncProfile _profile;
|
private readonly SyncProfile _profile;
|
||||||
private readonly SyncEngine _engine = new SyncEngine();
|
private readonly SyncEngine _engine = new SyncEngine();
|
||||||
|
private readonly SyncCoordinator _coordinator = new SyncCoordinator();
|
||||||
private TextBox _txtLog;
|
private TextBox _txtLog;
|
||||||
private ProgressBar _progressBar;
|
private ProgressBar _progressBar;
|
||||||
private Button _btnClose, _btnStart;
|
private Button _btnClose, _btnStart;
|
||||||
@@ -92,19 +93,46 @@ namespace StarfaceOutlookSync.UI
|
|||||||
_progressBar.Style = ProgressBarStyle.Marquee;
|
_progressBar.Style = ProgressBarStyle.Marquee;
|
||||||
_lblResult.Text = "";
|
_lblResult.Text = "";
|
||||||
|
|
||||||
_engine.OnProgress += AppendLog;
|
// Engine-Aufruf inkl. Live-Log: laeuft im Hintergrund, damit das
|
||||||
|
// Fenster reagiert. Guard/Lock/Notizen/Protokoll uebernimmt der
|
||||||
try
|
// Coordinator (gemeinsam mit dem Auto-/Tray-Sync).
|
||||||
|
Func<Task<SyncResult>> runEngine = async () =>
|
||||||
{
|
{
|
||||||
var result = await Task.Run(() => _engine.SyncProfileAsync(_profile));
|
_engine.OnProgress += AppendLog;
|
||||||
|
try { return await Task.Run(() => _engine.SyncProfileAsync(_profile)); }
|
||||||
|
finally { _engine.OnProgress -= AppendLog; }
|
||||||
|
};
|
||||||
|
|
||||||
_progressBar.Style = ProgressBarStyle.Blocks;
|
var outcome = await _coordinator.RunAsync(_profile, runEngine, status: AppendLog);
|
||||||
_progressBar.Value = 100;
|
|
||||||
|
|
||||||
var resultText = $"Erstellt: {result.Created} | Aktualisiert: {result.Updated} | Fehler: {result.Errors}";
|
_progressBar.Style = ProgressBarStyle.Blocks;
|
||||||
_lblResult.Text = resultText;
|
_progressBar.Value = 100;
|
||||||
|
|
||||||
|
if (outcome.Skipped)
|
||||||
|
{
|
||||||
|
_lblResult.Text = outcome.SkipReason;
|
||||||
|
_lblResult.ForeColor = Color.OrangeRed;
|
||||||
|
AppendLog(outcome.SkipReason);
|
||||||
|
}
|
||||||
|
else if (outcome.Error != null)
|
||||||
|
{
|
||||||
|
_lblResult.Text = $"Fehler: {outcome.Error.Message}";
|
||||||
|
_lblResult.ForeColor = Color.Red;
|
||||||
|
AppendLog($"FEHLER: {outcome.Error.Message}");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var result = outcome.Result;
|
||||||
|
_lblResult.Text = $"Erstellt: {result.Created} | Aktualisiert: {result.Updated} | Fehler: {result.Errors}";
|
||||||
_lblResult.ForeColor = result.Errors > 0 ? Color.OrangeRed : Color.Green;
|
_lblResult.ForeColor = result.Errors > 0 ? Color.OrangeRed : Color.Green;
|
||||||
|
|
||||||
|
// Konflikt-Hinweise anderer Arbeitsplaetze im Fenster zeigen.
|
||||||
|
foreach (var n in outcome.RemoteNotices)
|
||||||
|
AppendLog($"Konflikt an anderem Arbeitsplatz: {n}");
|
||||||
|
|
||||||
|
foreach (var c in result.Conflicts)
|
||||||
|
AppendLog($"KONFLIKT: {c}");
|
||||||
|
|
||||||
if (result.ErrorMessages.Count > 0)
|
if (result.ErrorMessages.Count > 0)
|
||||||
{
|
{
|
||||||
AppendLog("--- Fehler ---");
|
AppendLog("--- Fehler ---");
|
||||||
@@ -112,14 +140,7 @@ namespace StarfaceOutlookSync.UI
|
|||||||
AppendLog(err);
|
AppendLog(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
_lblResult.Text = $"Fehler: {ex.Message}";
|
|
||||||
_lblResult.ForeColor = Color.Red;
|
|
||||||
AppendLog($"FEHLER: {ex.Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
_engine.OnProgress -= AppendLog;
|
|
||||||
_btnStart.Enabled = true;
|
_btnStart.Enabled = true;
|
||||||
_btnStart.Text = "Erneut synchronisieren";
|
_btnStart.Text = "Erneut synchronisieren";
|
||||||
_btnClose.Enabled = true;
|
_btnClose.Enabled = true;
|
||||||
|
|||||||
Reference in New Issue
Block a user