Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 88635c04f8 | |||
| 6b025a24f0 | |||
| 641267081a | |||
| 0336530742 | |||
| 75c0c1126e |
@@ -38,6 +38,26 @@ Versionsschema ist `x.x.x.x` (siehe `release.sh`).
|
||||
|
||||
### 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
|
||||
@@ -70,6 +90,13 @@ Versionsschema ist `x.x.x.x` (siehe `release.sh`).
|
||||
|
||||
### 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
|
||||
Syncs (manuell + Auto-Sync-Timer) ist jetzt atomar (`Interlocked`) statt eines
|
||||
nicht-atomaren `volatile bool`, bei dem beide in einem Zeitfenster
|
||||
|
||||
+2
-2
@@ -2,7 +2,7 @@
|
||||
; Erfordert Inno Setup 6.x (https://jrsoftware.org/isinfo.php)
|
||||
|
||||
#define MyAppName "Starface Outlook Sync"
|
||||
#define MyAppVersion "0.0.0.29"
|
||||
#define MyAppVersion "0.0.0.30"
|
||||
#define MyAppPublisher "HackerSoft - Hacker-Net Telekommunikation"
|
||||
#define MyAppURL "https://www.hacker-net.de"
|
||||
#define MyAppExeName "StarfaceOutlookSync.exe"
|
||||
@@ -32,7 +32,7 @@ Name: "german"; MessagesFile: "compiler:Languages\German.isl"
|
||||
|
||||
[Tasks]
|
||||
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]
|
||||
; Hauptanwendung - Pfad anpassen nach Build
|
||||
|
||||
@@ -73,6 +73,10 @@ namespace StarfaceOutlookSync.Models
|
||||
public int Errors { get; set; }
|
||||
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
|
||||
// ueber die Vorrang-Regel aufgeloest wurden. Fuer Benutzer-Hinweise.
|
||||
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 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
|
||||
// Sync-Sperre. Leer = keine Sperre (nur lokaler Schutz). Verhindert, dass
|
||||
// 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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
@@ -63,6 +65,48 @@ namespace StarfaceOutlookSync.Services
|
||||
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
|
||||
|
||||
@@ -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);
|
||||
|
||||
/// <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>
|
||||
/// Setzt die Baseline eines Mappings auf den uebergebenen Stand beider
|
||||
/// Seiten (Snapshot + Hash). Der Snapshot wird fuer das Feld-Merge bei
|
||||
@@ -184,7 +191,7 @@ namespace StarfaceOutlookSync.Services
|
||||
if (await starface.DeleteContactAsync(mapping.StarfaceId))
|
||||
{
|
||||
result.Updated++;
|
||||
Log($" Geloescht (OL->SF): {sc.DisplayName}");
|
||||
Action(result, $"Geloescht (OL->SF): {sc.DisplayName}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -202,7 +209,7 @@ namespace StarfaceOutlookSync.Services
|
||||
if (await starface.DeleteContactAsync(mapping.StarfaceId))
|
||||
{
|
||||
result.Updated++;
|
||||
Log($" Geloescht (OL->SF): {sc.DisplayName}");
|
||||
Action(result, $"Geloescht (OL->SF): {sc.DisplayName}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -245,7 +252,7 @@ namespace StarfaceOutlookSync.Services
|
||||
if (_outlookService.DeleteContact(oc.OutlookEntryId))
|
||||
{
|
||||
result.Updated++;
|
||||
Log($" Geloescht (SF->OL): {oc.DisplayName}");
|
||||
Action(result, $"Geloescht (SF->OL): {oc.DisplayName}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -263,7 +270,7 @@ namespace StarfaceOutlookSync.Services
|
||||
if (_outlookService.DeleteContact(oc.OutlookEntryId))
|
||||
{
|
||||
result.Updated++;
|
||||
Log($" Geloescht (SF->OL): {oc.DisplayName}");
|
||||
Action(result, $"Geloescht (SF->OL): {oc.DisplayName}");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -322,7 +329,7 @@ namespace StarfaceOutlookSync.Services
|
||||
{
|
||||
SetBaseline(mapping, oc, 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))
|
||||
@@ -333,7 +340,7 @@ namespace StarfaceOutlookSync.Services
|
||||
{
|
||||
SetBaseline(mapping, updated, sc);
|
||||
result.Updated++;
|
||||
Log($" Aktualisiert (SF->OL): {sc.DisplayName}");
|
||||
Action(result, $"Aktualisiert (SF->OL): {sc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else if (olChanged && sfChanged)
|
||||
@@ -366,9 +373,9 @@ namespace StarfaceOutlookSync.Services
|
||||
mapping.LastSyncHash = "";
|
||||
result.Updated++;
|
||||
foreach (var cf in conflicts) result.Conflicts.Add(cf);
|
||||
Log(conflicts.Count > 0
|
||||
? $" Beidseitig geaendert, zusammengefuehrt ({conflicts.Count} Feld-Konflikt(e), Outlook gewinnt): {oc.DisplayName}"
|
||||
: $" Beidseitig geaendert, zusammengefuehrt: {oc.DisplayName}");
|
||||
Action(result, conflicts.Count > 0
|
||||
? $"Beidseitig geaendert, zusammengefuehrt ({conflicts.Count} Feld-Konflikt(e), Outlook gewinnt): {oc.DisplayName}"
|
||||
: $"Beidseitig geaendert, zusammengefuehrt: {oc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else if (profile.SyncDirection != SyncDirection.StarfaceToOutlook)
|
||||
@@ -380,7 +387,7 @@ namespace StarfaceOutlookSync.Services
|
||||
{
|
||||
SetBaseline(mapping, oc, updated);
|
||||
result.Updated++;
|
||||
Log($" Konflikt (OL gewinnt): {oc.DisplayName}");
|
||||
Action(result, $"Konflikt (OL gewinnt): {oc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -390,7 +397,7 @@ namespace StarfaceOutlookSync.Services
|
||||
{
|
||||
SetBaseline(mapping, updated, sc);
|
||||
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);
|
||||
unmappedStarface.Remove(match);
|
||||
result.Updated++;
|
||||
Log($" Verknuepft (OL->SF): {oc.DisplayName}");
|
||||
Action(result, $"Verknuepft (OL->SF): {oc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -462,7 +469,7 @@ namespace StarfaceOutlookSync.Services
|
||||
LastStarfaceHash = created.GetHash()
|
||||
});
|
||||
result.Created++;
|
||||
Log($" Erstellt (OL->SF): {oc.DisplayName}");
|
||||
Action(result, $"Erstellt (OL->SF): {oc.DisplayName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -521,7 +528,7 @@ namespace StarfaceOutlookSync.Services
|
||||
processedOutlookIds.Add(match.OutlookEntryId);
|
||||
unmappedOutlook.Remove(match);
|
||||
result.Updated++;
|
||||
Log($" Verknuepft (SF->OL): {sc.DisplayName}");
|
||||
Action(result, $"Verknuepft (SF->OL): {sc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -541,7 +548,7 @@ namespace StarfaceOutlookSync.Services
|
||||
LastOutlookHash = created.GetHash()
|
||||
});
|
||||
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))
|
||||
{
|
||||
result.Updated++;
|
||||
Log($" Geloescht (nur in Starface): {sc.DisplayName}");
|
||||
Action(result, $"Geloescht (nur in Starface): {sc.DisplayName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -612,7 +619,7 @@ namespace StarfaceOutlookSync.Services
|
||||
if (_outlookService.DeleteContact(oc.OutlookEntryId))
|
||||
{
|
||||
result.Updated++;
|
||||
Log($" Geloescht (nur in Outlook): {oc.DisplayName}");
|
||||
Action(result, $"Geloescht (nur in Outlook): {oc.DisplayName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
<AssemblyTitle>Starface Outlook Sync</AssemblyTitle>
|
||||
<Company>HackerSoft - Hacker-Net Telekommunikation</Company>
|
||||
<Product>Starface Outlook Sync</Product>
|
||||
<Version>0.0.0.29</Version>
|
||||
<AssemblyVersion>0.0.0.29</AssemblyVersion>
|
||||
<FileVersion>0.0.0.29</FileVersion>
|
||||
<Version>0.0.0.30</Version>
|
||||
<AssemblyVersion>0.0.0.30</AssemblyVersion>
|
||||
<FileVersion>0.0.0.30</FileVersion>
|
||||
<Description>Synchronisiert Outlook-Kontakte mit Starface Telefonanlage</Description>
|
||||
<Copyright>Stefan Hacker - HackerSoft</Copyright>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace StarfaceOutlookSync.UI
|
||||
|
||||
var lblVersion = new Label
|
||||
{
|
||||
Text = "Version 0.0.0.29",
|
||||
Text = "Version 0.0.0.30",
|
||||
Left = 0, Top = 56, Width = 340, Height = 20,
|
||||
TextAlign = ContentAlignment.MiddleCenter,
|
||||
ForeColor = Color.Gray
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using StarfaceOutlookSync.Models;
|
||||
using StarfaceOutlookSync.Services;
|
||||
|
||||
namespace StarfaceOutlookSync.UI
|
||||
@@ -72,6 +73,7 @@ namespace StarfaceOutlookSync.UI
|
||||
|
||||
private void LoadLog()
|
||||
{
|
||||
Logger.PruneOlderThan(UserSettings.Load().LogRetentionDays);
|
||||
_txt.Text = Logger.ReadAll();
|
||||
_txt.SelectionStart = _txt.TextLength;
|
||||
_txt.ScrollToCaret();
|
||||
|
||||
@@ -2,7 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Timers;
|
||||
using System.Windows.Forms;
|
||||
@@ -16,7 +15,7 @@ namespace StarfaceOutlookSync.UI
|
||||
{
|
||||
private readonly ProfileManager _profileManager = new ProfileManager();
|
||||
private readonly SyncEngine _syncEngine = new SyncEngine();
|
||||
private readonly ConflictNotifier _conflictNotifier = new ConflictNotifier();
|
||||
private readonly SyncCoordinator _coordinator = new SyncCoordinator();
|
||||
private NotifyIcon _trayIcon;
|
||||
private ContextMenuStrip _trayMenu;
|
||||
private ListView _profileList;
|
||||
@@ -24,9 +23,10 @@ namespace StarfaceOutlookSync.UI
|
||||
private StatusStrip _statusBar;
|
||||
private ToolStripStatusLabel _statusLabel;
|
||||
private Timer _autoSyncTimer;
|
||||
// 0 = frei, 1 = Sync laeuft. Per Interlocked atomar geschaltet, damit
|
||||
// ein manueller Sync und der Auto-Sync-Timer nicht gleichzeitig starten.
|
||||
private int _syncRunning = 0;
|
||||
|
||||
// Aktive Benachrichtigungs-Einstellung (pro Sync-Lauf gesetzt).
|
||||
private bool _notifyGeneral = true;
|
||||
private bool _notifyWarn = true;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
@@ -39,6 +39,9 @@ namespace StarfaceOutlookSync.UI
|
||||
var settings = UserSettings.Load();
|
||||
settings.ApplyOutlookSecuritySetting();
|
||||
|
||||
// Protokoll bei Bedarf auf das eingestellte Alter eindampfen.
|
||||
Logger.PruneOlderThan(settings.LogRetentionDays);
|
||||
|
||||
if (settings.StartMinimized)
|
||||
{
|
||||
WindowState = FormWindowState.Minimized;
|
||||
@@ -344,166 +347,83 @@ namespace StarfaceOutlookSync.UI
|
||||
|
||||
private async Task RunSync(SyncProfile profile)
|
||||
{
|
||||
// Atomar pruefen-und-setzen: verhindert, dass manueller Sync und
|
||||
// Auto-Sync-Timer gleichzeitig denselben/einen Sync starten.
|
||||
if (Interlocked.CompareExchange(ref _syncRunning, 1, 0) != 0)
|
||||
{
|
||||
SetStatus("Sync laeuft bereits, bitte warten...");
|
||||
return;
|
||||
}
|
||||
var settings = UserSettings.Load();
|
||||
_notifyGeneral = settings.NotificationsEnabled;
|
||||
_notifyWarn = settings.NotifyWarningsErrors;
|
||||
|
||||
SyncLock crossLock = null;
|
||||
var sharedDir = UserSettings.Load().SharedDirectory;
|
||||
try
|
||||
{
|
||||
// Clientuebergreifende Sperre (falls gemeinsames Verzeichnis konfiguriert).
|
||||
crossLock = await AcquireCrossClientLock(sharedDir);
|
||||
if (crossLock == null)
|
||||
// Lokaler Guard, Lock-Datei, Konflikt-Notizen und Protokoll laufen
|
||||
// zentral im Coordinator (gemeinsam mit dem manuellen Sync-Pfad).
|
||||
var outcome = await _coordinator.RunAsync(
|
||||
profile,
|
||||
runEngine: () => _syncEngine.SyncProfileAsync(profile),
|
||||
status: SetStatus);
|
||||
|
||||
if (outcome.Skipped)
|
||||
{
|
||||
SetStatus("Anderer Arbeitsplatz synchronisiert gerade - uebersprungen.");
|
||||
Logger.Log($"Sync '{profile.Name}' uebersprungen: anderer Arbeitsplatz synct gerade.");
|
||||
SetStatus(outcome.SkipReason);
|
||||
return;
|
||||
}
|
||||
|
||||
Logger.Log($"Sync gestartet: '{profile.Name}' (Richtung: {profile.SyncDirection})");
|
||||
// Konflikt-Hinweise anderer Arbeitsplaetze als Tray-Meldung (falls aktiv).
|
||||
ShowRemoteNoticesTray(outcome.RemoteNotices);
|
||||
|
||||
// Konflikt-Hinweise von ANDEREN Arbeitsplaetzen anzeigen, BEVOR der
|
||||
// Sync den eigenen Stand auf den Gewinner-Wert aktualisiert (sonst
|
||||
// koennte man nicht mehr erkennen, ob man betroffen war).
|
||||
ShowRemoteConflictNotices(sharedDir);
|
||||
|
||||
SetStatus($"Synchronisiere '{profile.Name}'...");
|
||||
_trayIcon.ShowBalloonTip(2000, "Starface Sync",
|
||||
$"Synchronisiere '{profile.Name}'...", ToolTipIcon.Info);
|
||||
|
||||
var result = await _syncEngine.SyncProfileAsync(profile);
|
||||
if (outcome.Error != null)
|
||||
{
|
||||
Balloon(3000, "Starface Sync Fehler", outcome.Error.Message, ToolTipIcon.Error, warn: true);
|
||||
SetStatus($"Fehler: {outcome.Error.Message}");
|
||||
return;
|
||||
}
|
||||
|
||||
var result = outcome.Result;
|
||||
var msg = $"{profile.Name}: {result.Created} erstellt, {result.Updated} aktualisiert";
|
||||
if (result.Errors > 0) msg += $", {result.Errors} Fehler";
|
||||
if (result.Conflicts.Count > 0) msg += $", {result.Conflicts.Count} Konflikt(e)";
|
||||
|
||||
_trayIcon.ShowBalloonTip(3000, "Starface Sync", msg,
|
||||
result.Errors > 0 ? ToolTipIcon.Warning : ToolTipIcon.Info);
|
||||
// Zusammenfassung als Warnung werten, wenn Fehler/Konflikte auftraten.
|
||||
bool noteworthy = result.Errors > 0 || result.Conflicts.Count > 0;
|
||||
Balloon(3000, "Starface Sync", msg,
|
||||
result.Errors > 0 ? ToolTipIcon.Warning : ToolTipIcon.Info, warn: noteworthy);
|
||||
|
||||
Logger.Log($"Sync fertig: {msg}");
|
||||
foreach (var em in result.ErrorMessages)
|
||||
Logger.Log($" Fehler: {em}");
|
||||
|
||||
// Echte Feld-Konflikte gesondert melden, damit der Benutzer weiss,
|
||||
// dass ein Wert ueberschrieben wurde.
|
||||
// Echte Feld-Konflikte gesondert melden (eigener Wert wurde ueberschrieben).
|
||||
if (result.Conflicts.Count > 0)
|
||||
{
|
||||
var detail = string.Join("\n", result.Conflicts.Take(5).Select(c => c.ToString()));
|
||||
if (result.Conflicts.Count > 5)
|
||||
detail += $"\n... und {result.Conflicts.Count - 5} weitere";
|
||||
_trayIcon.ShowBalloonTip(10000,
|
||||
$"Konflikt bei {result.Conflicts.Count} Kontakt(en)", detail, ToolTipIcon.Warning);
|
||||
|
||||
foreach (var c in result.Conflicts)
|
||||
Logger.Log($" KONFLIKT: {c}");
|
||||
|
||||
// Andere Arbeitsplaetze ueber das gemeinsame Verzeichnis informieren.
|
||||
_conflictNotifier.Write(sharedDir, result.Conflicts);
|
||||
Balloon(10000, $"Konflikt bei {result.Conflicts.Count} Kontakt(en)", detail, ToolTipIcon.Warning, warn: true);
|
||||
}
|
||||
|
||||
SetStatus(msg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_trayIcon.ShowBalloonTip(3000, "Starface Sync Fehler",
|
||||
ex.Message, ToolTipIcon.Error);
|
||||
Balloon(3000, "Starface Sync Fehler", ex.Message, ToolTipIcon.Error, warn: true);
|
||||
SetStatus($"Fehler: {ex.Message}");
|
||||
Logger.Log($"Sync FEHLER '{profile.Name}': {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
crossLock?.Dispose();
|
||||
Interlocked.Exchange(ref _syncRunning, 0);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Zeigt Konflikt-Hinweise anderer Arbeitsplaetze als Tray-Meldung.</summary>
|
||||
private void ShowRemoteNoticesTray(System.Collections.Generic.List<ConflictNotice> notices)
|
||||
{
|
||||
if (notices == null || notices.Count == 0) return;
|
||||
var detail = string.Join("\n", notices.Take(5).Select(p => p.ToString()));
|
||||
if (notices.Count > 5)
|
||||
detail += $"\n... und {notices.Count - 5} weitere";
|
||||
Balloon(10000, $"Konflikt an anderem Arbeitsplatz ({notices.Count})", detail, ToolTipIcon.Warning, warn: true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Holt die clientuebergreifende Lock-Datei aus dem konfigurierten
|
||||
/// 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).
|
||||
/// Zeigt eine Tray-Meldung - aber nur, wenn die passende Benachrichtigungs-
|
||||
/// Einstellung aktiv ist. warn=true -> Warnungen/Fehler (Konflikte, Fehler),
|
||||
/// warn=false -> allgemeine Info-Meldungen.
|
||||
/// </summary>
|
||||
private async Task<SyncLock> AcquireCrossClientLock(string dir)
|
||||
private void Balloon(int ms, string title, string text, ToolTipIcon icon, bool warn)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(dir))
|
||||
return SyncLock.NoOp();
|
||||
|
||||
try
|
||||
{
|
||||
// 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>
|
||||
/// Zeigt Konflikt-Hinweise an, die andere Arbeitsplaetze ueber das
|
||||
/// gemeinsame Verzeichnis hinterlassen haben und Kontakte betreffen, die
|
||||
/// auch dieser Client gemappt hat.
|
||||
/// </summary>
|
||||
private void ShowRemoteConflictNotices(string sharedDir)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(sharedDir)) return;
|
||||
try
|
||||
{
|
||||
var pending = _conflictNotifier.GetPending(sharedDir, MyContactsByStarfaceId());
|
||||
if (pending.Count == 0) return;
|
||||
|
||||
foreach (var p in pending)
|
||||
Logger.Log($" KONFLIKT (anderer Arbeitsplatz): {p}");
|
||||
|
||||
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;
|
||||
bool allow = warn ? _notifyWarn : _notifyGeneral;
|
||||
if (allow) _trayIcon.ShowBalloonTip(ms, title, text, icon);
|
||||
}
|
||||
|
||||
private void SetStatus(string text)
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
using StarfaceOutlookSync.Models;
|
||||
using StarfaceOutlookSync.Services;
|
||||
|
||||
namespace StarfaceOutlookSync.UI
|
||||
{
|
||||
public class SettingsForm : Form
|
||||
{
|
||||
private CheckBox _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook;
|
||||
private CheckBox _chkNotifGeneral, _chkNotifWarn;
|
||||
private CheckBox _chkAutostartUser, _chkAutostartAll;
|
||||
private NumericUpDown _numLogRetention;
|
||||
private TextBox _txtSharedDir;
|
||||
private Button _btnBrowseShared;
|
||||
private Button _btnSave, _btnCancel;
|
||||
@@ -61,21 +65,47 @@ namespace StarfaceOutlookSync.UI
|
||||
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
|
||||
{
|
||||
Text = "Gemeinsames Verzeichnis fuer Sync-Sperre (Mehrplatz, optional):",
|
||||
Left = 20, Top = 150, AutoSize = true
|
||||
Left = 20, Top = 240, AutoSize = true
|
||||
};
|
||||
|
||||
_txtSharedDir = new TextBox
|
||||
{
|
||||
Left = 20, Top = 172, Width = 250,
|
||||
Left = 20, Top = 262, Width = 250,
|
||||
Text = _settings.SharedDirectory
|
||||
};
|
||||
|
||||
_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();
|
||||
|
||||
@@ -83,26 +113,52 @@ namespace StarfaceOutlookSync.UI
|
||||
{
|
||||
Text = "Netzlaufwerk/UNC, das alle Arbeitsplaetze erreichen. Leer = keine\n" +
|
||||
"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)
|
||||
};
|
||||
|
||||
// === 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
|
||||
{
|
||||
Text = "Speichern", Left = 95, Top = 240, Width = 85, Height = 28,
|
||||
Text = "Speichern", Left = 95, Top = 422, Width = 85, Height = 28,
|
||||
DialogResult = DialogResult.None
|
||||
};
|
||||
_btnSave.Click += (s, e) => Save();
|
||||
|
||||
_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
|
||||
};
|
||||
|
||||
Size = new Size(380, 330);
|
||||
Size = new Size(380, 512);
|
||||
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;
|
||||
CancelButton = _btnCancel;
|
||||
}
|
||||
@@ -126,8 +182,25 @@ namespace StarfaceOutlookSync.UI
|
||||
_settings.StartMinimized = _chkStartMinimized.Checked;
|
||||
_settings.SyncOnStart = _chkSyncOnStart.Checked;
|
||||
_settings.AutoAcceptOutlookPrompt = _chkAutoAcceptOutlook.Checked;
|
||||
_settings.NotificationsEnabled = _chkNotifGeneral.Checked;
|
||||
_settings.NotifyWarningsErrors = _chkNotifWarn.Checked;
|
||||
_settings.LogRetentionDays = (int)_numLogRetention.Value;
|
||||
_settings.SharedDirectory = _txtSharedDir.Text.Trim();
|
||||
_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;
|
||||
Close();
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace StarfaceOutlookSync.UI
|
||||
{
|
||||
private readonly SyncProfile _profile;
|
||||
private readonly SyncEngine _engine = new SyncEngine();
|
||||
private readonly SyncCoordinator _coordinator = new SyncCoordinator();
|
||||
private TextBox _txtLog;
|
||||
private ProgressBar _progressBar;
|
||||
private Button _btnClose, _btnStart;
|
||||
@@ -92,19 +93,46 @@ namespace StarfaceOutlookSync.UI
|
||||
_progressBar.Style = ProgressBarStyle.Marquee;
|
||||
_lblResult.Text = "";
|
||||
|
||||
_engine.OnProgress += AppendLog;
|
||||
|
||||
try
|
||||
// Engine-Aufruf inkl. Live-Log: laeuft im Hintergrund, damit das
|
||||
// Fenster reagiert. Guard/Lock/Notizen/Protokoll uebernimmt der
|
||||
// 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;
|
||||
_progressBar.Value = 100;
|
||||
var outcome = await _coordinator.RunAsync(_profile, runEngine, status: AppendLog);
|
||||
|
||||
var resultText = $"Erstellt: {result.Created} | Aktualisiert: {result.Updated} | Fehler: {result.Errors}";
|
||||
_lblResult.Text = resultText;
|
||||
_progressBar.Style = ProgressBarStyle.Blocks;
|
||||
_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;
|
||||
|
||||
// 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)
|
||||
{
|
||||
AppendLog("--- Fehler ---");
|
||||
@@ -112,14 +140,7 @@ namespace StarfaceOutlookSync.UI
|
||||
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.Text = "Erneut synchronisieren";
|
||||
_btnClose.Enabled = true;
|
||||
|
||||
Reference in New Issue
Block a user