Compare commits
25 Commits
3e22a40e17
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| ad323c9d0f | |||
| 849a996b9a | |||
| b07a3b3a87 | |||
| f620e96d23 | |||
| e8731a87d4 | |||
| 53ca4611d1 | |||
| df13ddf6b1 | |||
| c08a625348 | |||
| 4484f19d14 | |||
| ca17e5d433 | |||
| d89e36b962 | |||
| 3092150d3a | |||
| 163dc17b49 | |||
| b7cc335184 | |||
| a19a39b7d2 | |||
| 6349424007 | |||
| 7ffaddc77f | |||
| 9007e2a9b5 | |||
| 0eadb2274e | |||
| a676e064c4 | |||
| 39ec176b16 | |||
| 39be854a4a | |||
| 724beba34a | |||
| 65d3e911d0 | |||
| ab9c16c69a |
@@ -0,0 +1,65 @@
|
||||
# Changelog
|
||||
|
||||
Alle nennenswerten Aenderungen an Starface Outlook Sync werden hier dokumentiert.
|
||||
|
||||
Format orientiert sich an [Keep a Changelog](https://keepachangelog.com/de/),
|
||||
Versionsschema ist `x.x.x.x` (siehe `release.sh`).
|
||||
|
||||
## [Unreleased]
|
||||
|
||||
### Behoben
|
||||
|
||||
- **Dubletten auf beiden Seiten beim Synchronisieren.** Mehrere zusammenhaengende
|
||||
Ursachen wurden beseitigt:
|
||||
- Eine unvollstaendig geladene Starface-Kontaktliste (z.B. durch einen
|
||||
Lade-Fehler oder Timeout) liess die Engine Kontakte faelschlich als
|
||||
"geloescht" ansehen, ihr Mapping verwerfen und sie beim naechsten Lauf neu
|
||||
anlegen. Der Kontakt-Abruf bricht jetzt mit Fehlermeldung ab (inkl.
|
||||
Wiederholversuch), statt still mit einer Teil-Liste weiterzuarbeiten.
|
||||
- Ist ein Starface-Kontakt nicht in der geladenen Liste (z.B. anderes
|
||||
Adressbuch), wird das Mapping jetzt **behalten** statt verworfen und neu
|
||||
angelegt.
|
||||
- Das Wiederzuordnen bestehender Kontakte war zu streng: eine von Starface
|
||||
umformatierte Telefonnummer konnte einen eindeutigen E-Mail- oder
|
||||
Namens-Treffer ueberstimmen und so eine Neuanlage statt Verknuepfung
|
||||
ausloesen. Ein gleicher E-Mail- oder voller Namens-Treffer reicht jetzt.
|
||||
|
||||
- **Synchronisation extrem langsam / schrieb bei jedem Lauf alle Kontakte neu.**
|
||||
Die Aenderungserkennung verglich einen einzigen Hash gegen beide Seiten.
|
||||
Outlook und Starface stellen denselben Kontakt aber unterschiedlich dar
|
||||
(nicht uebertragene Felder, abweichendes Telefonformat), wodurch der Hash nie
|
||||
uebereinstimmte und praktisch jeder Kontakt bei jedem Sync neu geschrieben
|
||||
wurde. Jede Seite hat jetzt eine eigene Baseline (`LastOutlookHash` /
|
||||
`LastStarfaceHash`); nur tatsaechlich geaenderte Kontakte werden geschrieben.
|
||||
|
||||
### Geaendert
|
||||
|
||||
- Starface-Kontaktdetails werden beim Laden parallel abgerufen (8 gleichzeitig)
|
||||
statt einzeln nacheinander – deutlich schneller bei grossen Adressbuechern.
|
||||
- `UpdateContact` (Outlook) und `UpdateContactAsync` (Starface) geben jetzt den
|
||||
frisch eingelesenen Stand zurueck, damit die Baseline nach dem Schreiben
|
||||
korrekt gesetzt wird und der Sync sauber konvergiert.
|
||||
|
||||
### Migration
|
||||
|
||||
- Bestehende Mapping-Dateien werden beim ersten Sync automatisch uebernommen
|
||||
(ein ruhiger Durchlauf ohne Massen-Update).
|
||||
- **Bereits vorhandene Dubletten werden nicht automatisch entfernt** – die Fixes
|
||||
verhindern nur neue. Vorhandene Doppel-Kontakte einmalig manuell bereinigen.
|
||||
|
||||
## [0.0.0.23]
|
||||
|
||||
### Behoben
|
||||
|
||||
- Kritischer Loesch-Fehler: Kontakte wurden bei einer geaenderten Outlook-EntryID
|
||||
nicht mehr massenhaft geloescht.
|
||||
|
||||
### Geaendert
|
||||
|
||||
- Outlook-Sicherheitsschluessel werden fuer Domaenenumgebungen zusaetzlich nach
|
||||
HKLM geschrieben (unterdrueckt die Outlook-Sicherheitsabfrage).
|
||||
|
||||
## Aeltere Versionen
|
||||
|
||||
Aeltere Releases (v0.0.0.1 – v0.0.0.22) sind ueber die Git-Historie und die
|
||||
Git-Tags nachvollziehbar.
|
||||
@@ -42,6 +42,32 @@ Windows-Anwendung zur bidirektionalen Synchronisation von Kontakten zwischen Mic
|
||||
5. Starface-Adressbuch und Outlook-Kontaktordner waehlen
|
||||
6. Speichern und "Jetzt synchronisieren"
|
||||
|
||||
### Outlook-Sicherheitsabfrage unterdruecken
|
||||
|
||||
Beim Zugriff auf Outlook-Kontakte zeigt Outlook standardmaessig einen
|
||||
Sicherheitsdialog ("Ein Programm versucht auf Ihre E-Mail-Adressinformationen
|
||||
zuzugreifen"). Dieser kann in den Einstellungen der App deaktiviert werden:
|
||||
|
||||
1. In der App auf "Einstellungen" klicken
|
||||
2. "Outlook-Sicherheitsabfrage automatisch erlauben" aktivieren
|
||||
3. Speichern
|
||||
|
||||
**Auf Domaenen-PCs / Terminal Servern:**
|
||||
|
||||
Die Outlook-Sicherheitseinstellungen werden dort per Gruppenrichtlinie (GPO)
|
||||
gesteuert und sind im Trust Center ausgegraut. In diesem Fall muss die App
|
||||
**einmalig als Administrator** gestartet werden, damit die Registry-Keys
|
||||
unter HKLM geschrieben werden koennen:
|
||||
|
||||
1. Rechtsklick auf die App -> "Als Administrator ausfuehren"
|
||||
2. Einstellungen -> "Outlook-Sicherheitsabfrage automatisch erlauben" aktivieren
|
||||
3. Speichern und App schliessen
|
||||
4. Outlook neu starten
|
||||
5. App kann danach wieder normal (ohne Admin) gestartet werden
|
||||
|
||||
Die Einstellung bleibt dauerhaft bestehen und gilt fuer alle Benutzer
|
||||
auf dem Rechner.
|
||||
|
||||
### Deinstallation
|
||||
|
||||
Ueber Windows Einstellungen -> Apps oder die Systemsteuerung.
|
||||
|
||||
+1
-1
@@ -2,7 +2,7 @@
|
||||
; Erfordert Inno Setup 6.x (https://jrsoftware.org/isinfo.php)
|
||||
|
||||
#define MyAppName "Starface Outlook Sync"
|
||||
#define MyAppVersion "0.0.0.15"
|
||||
#define MyAppVersion "0.0.0.24"
|
||||
#define MyAppPublisher "HackerSoft - Hacker-Net Telekommunikation"
|
||||
#define MyAppURL "https://www.hacker-net.de"
|
||||
#define MyAppExeName "StarfaceOutlookSync.exe"
|
||||
|
||||
@@ -45,6 +45,15 @@ namespace StarfaceOutlookSync.Models
|
||||
public string ProfileId { get; set; } = "";
|
||||
public string OutlookEntryId { get; set; } = "";
|
||||
public string StarfaceId { get; set; } = "";
|
||||
|
||||
// Getrennte Baselines pro Seite. Outlook und Starface stellen denselben
|
||||
// Kontakt unterschiedlich dar (Felder, Telefonformat), daher MUSS jede
|
||||
// Seite gegen ihre eigene zuletzt-gesehene Repraesentation verglichen
|
||||
// werden - sonst gilt jeder Kontakt bei jedem Sync als geaendert.
|
||||
public string LastOutlookHash { get; set; } = "";
|
||||
public string LastStarfaceHash { get; set; } = "";
|
||||
|
||||
// Alt-Feld (vor v0.0.0.24). Nur noch fuer Migration bestehender Mappings.
|
||||
public string LastSyncHash { get; set; } = "";
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Microsoft.Win32;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace StarfaceOutlookSync.Models
|
||||
@@ -7,6 +8,8 @@ namespace StarfaceOutlookSync.Models
|
||||
public class UserSettings
|
||||
{
|
||||
public bool StartMinimized { get; set; } = false;
|
||||
public bool SyncOnStart { get; set; } = false;
|
||||
public bool AutoAcceptOutlookPrompt { get; set; } = false;
|
||||
|
||||
private static readonly string SettingsFile = Path.Combine(
|
||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||
@@ -32,6 +35,86 @@ namespace StarfaceOutlookSync.Models
|
||||
File.WriteAllText(SettingsFile, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||
}
|
||||
catch { }
|
||||
|
||||
ApplyOutlookSecuritySetting();
|
||||
}
|
||||
|
||||
public void ApplyOutlookSecuritySetting()
|
||||
{
|
||||
var versions = new[] { "16.0", "15.0" };
|
||||
|
||||
var securityValues = new (string name, int value)[]
|
||||
{
|
||||
("ObjectModelGuard", 2),
|
||||
("PromptOOMAddressBookAccess", 2),
|
||||
("PromptOOMAddressInformationAccess", 2),
|
||||
("PromptOOMSend", 2),
|
||||
("PromptOOMSaveAs", 2),
|
||||
("PromptOOMFormulaAccess", 2),
|
||||
("PromptOOMCustomAction", 2),
|
||||
("PromptSimpleMAPISend", 2),
|
||||
("PromptSimpleMAPINameResolve", 2),
|
||||
("PromptSimpleMAPIOpenMessage", 2),
|
||||
("AdminSecurityMode", 3),
|
||||
};
|
||||
|
||||
// In alle moeglichen Pfade schreiben (HKCU + HKLM, Policies + direkt)
|
||||
var roots = new[] { Registry.CurrentUser, Registry.LocalMachine };
|
||||
var prefixes = new[]
|
||||
{
|
||||
@"Software\Policies\Microsoft\Office",
|
||||
@"Software\Microsoft\Office"
|
||||
};
|
||||
|
||||
foreach (var ver in versions)
|
||||
{
|
||||
foreach (var root in roots)
|
||||
{
|
||||
foreach (var prefix in prefixes)
|
||||
{
|
||||
var regPath = $@"{prefix}\{ver}\Outlook\Security";
|
||||
try
|
||||
{
|
||||
if (AutoAcceptOutlookPrompt)
|
||||
{
|
||||
var key = root.CreateSubKey(regPath);
|
||||
if (key != null)
|
||||
{
|
||||
foreach (var (name, value) in securityValues)
|
||||
key.SetValue(name, value, RegistryValueKind.DWord);
|
||||
key.Close();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
try { root.DeleteSubKey(regPath, false); } catch { }
|
||||
}
|
||||
}
|
||||
catch { } // Kein Fehler wenn Rechte fehlen - naechsten Pfad versuchen
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Prueft ob die Outlook-Sicherheitseinstellung per GPO blockiert wird.
|
||||
/// </summary>
|
||||
public static bool IsOutlookSecurityLockedByPolicy()
|
||||
{
|
||||
try
|
||||
{
|
||||
// Wenn HKLM Policies gesetzt sind und wir dort nicht schreiben koennen
|
||||
var key = Registry.LocalMachine.OpenSubKey(
|
||||
@"Software\Policies\Microsoft\Office\16.0\Outlook\Security", false);
|
||||
if (key != null)
|
||||
{
|
||||
var val = key.GetValue("AdminSecurityMode");
|
||||
key.Close();
|
||||
if (val != null) return true;
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -350,7 +350,13 @@ namespace StarfaceOutlookSync.Services
|
||||
}
|
||||
}
|
||||
|
||||
public bool UpdateContact(string entryId, UnifiedContact contact)
|
||||
/// <summary>
|
||||
/// Aktualisiert den Outlook-Kontakt und gibt den frisch eingelesenen
|
||||
/// Stand zurueck (null bei Fehler). Der zurueckgegebene Kontakt liefert
|
||||
/// den massgeblichen Hash NACH dem Schreiben - noetig damit die naechste
|
||||
/// Synchronisation den Kontakt nicht erneut als geaendert erkennt.
|
||||
/// </summary>
|
||||
public UnifiedContact UpdateContact(string entryId, UnifiedContact contact)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -361,15 +367,17 @@ namespace StarfaceOutlookSync.Services
|
||||
MapToOutlook(contact, ci);
|
||||
ci.Save();
|
||||
|
||||
var updated = MapFromOutlook(ci);
|
||||
|
||||
Marshal.ReleaseComObject(ci);
|
||||
Marshal.ReleaseComObject(ns);
|
||||
|
||||
return true;
|
||||
return updated;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Error updating contact: {ex.Message}");
|
||||
return false;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -394,29 +402,40 @@ namespace StarfaceOutlookSync.Services
|
||||
}
|
||||
}
|
||||
|
||||
private static string SafeGet(dynamic ci, string property)
|
||||
{
|
||||
try
|
||||
{
|
||||
object val = ci.GetType().InvokeMember(property,
|
||||
System.Reflection.BindingFlags.GetProperty, null, ci, null);
|
||||
return val?.ToString() ?? "";
|
||||
}
|
||||
catch { return ""; }
|
||||
}
|
||||
|
||||
private UnifiedContact MapFromOutlook(dynamic ci)
|
||||
{
|
||||
return new UnifiedContact
|
||||
{
|
||||
OutlookEntryId = (string)(ci.EntryID ?? ""),
|
||||
FirstName = (string)(ci.FirstName ?? ""),
|
||||
LastName = (string)(ci.LastName ?? ""),
|
||||
Company = (string)(ci.CompanyName ?? ""),
|
||||
JobTitle = (string)(ci.JobTitle ?? ""),
|
||||
Email = (string)(ci.Email1Address ?? ""),
|
||||
EmailSecondary = (string)(ci.Email2Address ?? ""),
|
||||
PhoneWork = (string)(ci.BusinessTelephoneNumber ?? ""),
|
||||
PhoneMobile = (string)(ci.MobileTelephoneNumber ?? ""),
|
||||
PhoneHome = (string)(ci.HomeTelephoneNumber ?? ""),
|
||||
Fax = (string)(ci.BusinessFaxNumber ?? ""),
|
||||
Street = (string)(ci.BusinessAddressStreet ?? ""),
|
||||
City = (string)(ci.BusinessAddressCity ?? ""),
|
||||
PostalCode = (string)(ci.BusinessAddressPostalCode ?? ""),
|
||||
State = (string)(ci.BusinessAddressState ?? ""),
|
||||
Country = (string)(ci.BusinessAddressCountry ?? ""),
|
||||
Website = (string)(ci.WebPage ?? ""),
|
||||
Notes = (string)(ci.Body ?? ""),
|
||||
Salutation = (string)(ci.Title ?? ""),
|
||||
OutlookEntryId = SafeGet(ci, "EntryID"),
|
||||
FirstName = SafeGet(ci, "FirstName"),
|
||||
LastName = SafeGet(ci, "LastName"),
|
||||
Company = SafeGet(ci, "CompanyName"),
|
||||
JobTitle = SafeGet(ci, "JobTitle"),
|
||||
Email = SafeGet(ci, "Email1Address"),
|
||||
EmailSecondary = SafeGet(ci, "Email2Address"),
|
||||
PhoneWork = SafeGet(ci, "BusinessTelephoneNumber"),
|
||||
PhoneMobile = SafeGet(ci, "MobileTelephoneNumber"),
|
||||
PhoneHome = SafeGet(ci, "HomeTelephoneNumber"),
|
||||
Fax = SafeGet(ci, "BusinessFaxNumber"),
|
||||
Street = SafeGet(ci, "BusinessAddressStreet"),
|
||||
City = SafeGet(ci, "BusinessAddressCity"),
|
||||
PostalCode = SafeGet(ci, "BusinessAddressPostalCode"),
|
||||
State = SafeGet(ci, "BusinessAddressState"),
|
||||
Country = SafeGet(ci, "BusinessAddressCountry"),
|
||||
Website = SafeGet(ci, "WebPage"),
|
||||
Notes = SafeGet(ci, "Body"),
|
||||
Salutation = SafeGet(ci, "Title"),
|
||||
Birthday = GetBirthdayString(ci)
|
||||
};
|
||||
}
|
||||
@@ -425,8 +444,9 @@ namespace StarfaceOutlookSync.Services
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime bday = ci.Birthday;
|
||||
if (bday.Year > 1900 && bday != DateTime.MinValue)
|
||||
object val = ci.GetType().InvokeMember("Birthday",
|
||||
System.Reflection.BindingFlags.GetProperty, null, ci, null);
|
||||
if (val is DateTime bday && bday.Year > 1900 && bday != DateTime.MinValue)
|
||||
return bday.ToString("yyyy-MM-dd");
|
||||
}
|
||||
catch { }
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Security.Cryptography;
|
||||
@@ -115,42 +116,62 @@ namespace StarfaceOutlookSync.Services
|
||||
{
|
||||
var books = new List<StarfaceAddressBook>();
|
||||
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "central",
|
||||
Name = "Zentrales Adressbuch"
|
||||
});
|
||||
|
||||
var userId = await GetCurrentUserIdAsync();
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "user",
|
||||
UserId = userId,
|
||||
Name = "Persoenliches Adressbuch"
|
||||
});
|
||||
}
|
||||
|
||||
// Tags als virtuelle Adressbuecher
|
||||
// Alle Tags laden - die Starface nutzt Tags als Adressbuch-Zuordnung
|
||||
var allTags = new JArray();
|
||||
try
|
||||
{
|
||||
var resp = await _http.GetAsync($"{_baseUrl}/contacts/tags");
|
||||
if (resp.IsSuccessStatusCode)
|
||||
{
|
||||
var tags = JArray.Parse(await resp.Content.ReadAsStringAsync());
|
||||
foreach (var tag in tags)
|
||||
allTags = JArray.Parse(await resp.Content.ReadAsStringAsync());
|
||||
OnDebug?.Invoke($"Gefundene Tags: {allTags.Count}");
|
||||
foreach (var t in allTags)
|
||||
OnDebug?.Invoke($" Tag: {t["name"]} (id: {t["id"]}, alias: {t["alias"]}, owner: {t["owner"]})");
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
// Zentrales Adressbuch (folder/all)
|
||||
var allTag = allTags.FirstOrDefault(t => t["name"]?.ToString() == "folder/all"
|
||||
|| t["alias"]?.ToString()?.Contains("folder.all") == true);
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "central",
|
||||
TagId = allTag?["id"]?.ToString() ?? "",
|
||||
Name = "Zentrales Adressbuch"
|
||||
});
|
||||
|
||||
// Persoenliches Adressbuch (folder/private mit owner = userId)
|
||||
var userId = await GetCurrentUserIdAsync();
|
||||
if (!string.IsNullOrEmpty(userId))
|
||||
{
|
||||
var privateTag = allTags.FirstOrDefault(t =>
|
||||
(t["name"]?.ToString() == "folder/private" || t["alias"]?.ToString()?.Contains("folder.private") == true)
|
||||
&& t["owner"]?.ToString() == userId);
|
||||
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "user",
|
||||
UserId = userId,
|
||||
TagId = privateTag?["id"]?.ToString() ?? "",
|
||||
Name = "Persoenliches Adressbuch"
|
||||
});
|
||||
}
|
||||
|
||||
// Alle weiteren Tags als Adressbuecher anbieten
|
||||
foreach (var tag in allTags)
|
||||
{
|
||||
var tagName = tag["name"]?.ToString() ?? "";
|
||||
// folder/all und folder/private bereits oben erfasst
|
||||
if (tagName == "folder/all" || tagName == "folder/private") continue;
|
||||
|
||||
books.Add(new StarfaceAddressBook
|
||||
{
|
||||
Type = "tag",
|
||||
TagId = tag["id"]?.ToString() ?? "",
|
||||
Name = $"Tag: {tag["name"]}"
|
||||
Name = tagName
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return books;
|
||||
}
|
||||
@@ -173,7 +194,16 @@ namespace StarfaceOutlookSync.Services
|
||||
query += $"&tags={book.TagId}";
|
||||
|
||||
var resp = await _http.GetAsync($"{_baseUrl}/contacts?{query}");
|
||||
if (!resp.IsSuccessStatusCode) break;
|
||||
if (!resp.IsSuccessStatusCode)
|
||||
{
|
||||
// WICHTIG: nicht still abbrechen. Eine unvollstaendige Liste
|
||||
// laesst die Sync-Engine Kontakte faelschlich als geloescht
|
||||
// ansehen -> Mappings werden verworfen -> Dubletten.
|
||||
throw new Exception(
|
||||
$"Starface-Kontaktliste konnte nicht vollstaendig geladen werden " +
|
||||
$"(Seite {page}: HTTP {(int)resp.StatusCode}). Synchronisation abgebrochen, " +
|
||||
$"um Dubletten zu vermeiden.");
|
||||
}
|
||||
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
JArray array;
|
||||
@@ -211,31 +241,40 @@ namespace StarfaceOutlookSync.Services
|
||||
|
||||
OnDebug?.Invoke($"Seite {page}: {array.Count} Kontakte in Liste");
|
||||
|
||||
// Die Listen-API gibt nur Summary zurueck.
|
||||
// Jeden Kontakt einzeln abrufen fuer alle Felder.
|
||||
foreach (var item in array)
|
||||
{
|
||||
var id = item["id"]?.ToString();
|
||||
if (string.IsNullOrEmpty(id)) continue;
|
||||
|
||||
try
|
||||
{
|
||||
var detailResp = await _http.GetAsync($"{_baseUrl}/contacts/{id}");
|
||||
if (detailResp.IsSuccessStatusCode)
|
||||
{
|
||||
var detailBody = await detailResp.Content.ReadAsStringAsync();
|
||||
var detailObj = JObject.Parse(detailBody);
|
||||
|
||||
if (firstPage)
|
||||
{
|
||||
OnDebug?.Invoke($"Starface Kontakt-Detail (1. Kontakt):\n{detailObj.ToString(Formatting.Indented)}");
|
||||
var firstId = array[0]?["id"]?.ToString();
|
||||
if (!string.IsNullOrEmpty(firstId))
|
||||
{
|
||||
var sample = await FetchDetailAsync(firstId);
|
||||
if (sample != null)
|
||||
OnDebug?.Invoke($"Starface Kontakt-Detail (1. Kontakt):\n{sample.ToString(Formatting.Indented)}");
|
||||
}
|
||||
firstPage = false;
|
||||
}
|
||||
|
||||
contacts.Add(MapFromStarface(detailObj));
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
// Die Listen-API liefert nur eine Zusammenfassung; jeder Kontakt
|
||||
// muss einzeln geladen werden. Das parallelisieren (begrenzt),
|
||||
// sonst dauert es bei vielen Kontakten extrem lange.
|
||||
var ids = array
|
||||
.Select(it => it["id"]?.ToString())
|
||||
.Where(id => !string.IsNullOrEmpty(id))
|
||||
.ToList();
|
||||
|
||||
const int maxParallel = 8;
|
||||
for (int i = 0; i < ids.Count; i += maxParallel)
|
||||
{
|
||||
var batch = ids.Skip(i).Take(maxParallel)
|
||||
.Select(async id =>
|
||||
{
|
||||
var detail = await FetchDetailAsync(id);
|
||||
// null = 404 (zwischenzeitlich geloescht) -> ueberspringen.
|
||||
return detail == null ? null : MapFromStarface(detail);
|
||||
})
|
||||
.ToList();
|
||||
|
||||
var mapped = await Task.WhenAll(batch);
|
||||
contacts.AddRange(mapped.Where(c => c != null));
|
||||
}
|
||||
|
||||
if (array.Count < pageSize) break;
|
||||
@@ -245,9 +284,49 @@ namespace StarfaceOutlookSync.Services
|
||||
return contacts;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Laedt das Detail-JSON eines Kontakts mit kleiner Wiederholung.
|
||||
/// Gibt null zurueck, wenn der Kontakt zwischen Listen- und Detail-Abruf
|
||||
/// wirklich geloescht wurde (404 - harmlos, wird uebersprungen).
|
||||
/// Wirft bei transienten Fehlern, damit der Aufrufer NICHT mit einer
|
||||
/// unvollstaendigen Liste weiterarbeitet (sonst entstehen Dubletten).
|
||||
/// </summary>
|
||||
private async Task<JObject> FetchDetailAsync(string id)
|
||||
{
|
||||
for (int attempt = 0; attempt < 3; attempt++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var resp = await _http.GetAsync($"{_baseUrl}/contacts/{id}");
|
||||
if (resp.IsSuccessStatusCode)
|
||||
return JObject.Parse(await resp.Content.ReadAsStringAsync());
|
||||
|
||||
// 404 = zwischenzeitlich geloescht; nicht erneut versuchen.
|
||||
if (resp.StatusCode == HttpStatusCode.NotFound) return null;
|
||||
}
|
||||
catch { }
|
||||
|
||||
await Task.Delay(250 * (attempt + 1));
|
||||
}
|
||||
|
||||
throw new Exception(
|
||||
$"Starface-Kontakt {id} konnte nach mehreren Versuchen nicht geladen werden. " +
|
||||
$"Synchronisation abgebrochen, um Dubletten zu vermeiden.");
|
||||
}
|
||||
|
||||
public async Task<UnifiedContact> CreateContactAsync(UnifiedContact contact, StarfaceAddressBook book)
|
||||
{
|
||||
var sfContact = MapToStarface(contact);
|
||||
|
||||
// Tag zuweisen - die Starface verlangt dass jeder Kontakt einem Tag zugeordnet ist
|
||||
if (!string.IsNullOrEmpty(book.TagId))
|
||||
{
|
||||
sfContact["tags"] = new JArray
|
||||
{
|
||||
new JObject { ["id"] = book.TagId }
|
||||
};
|
||||
}
|
||||
|
||||
var query = "";
|
||||
if (book.Type == "user" && !string.IsNullOrEmpty(book.UserId))
|
||||
query = $"?userId={book.UserId}";
|
||||
@@ -269,17 +348,66 @@ namespace StarfaceOutlookSync.Services
|
||||
return MapFromStarface(created);
|
||||
}
|
||||
|
||||
public async Task<bool> UpdateContactAsync(string contactId, UnifiedContact contact, StarfaceAddressBook book)
|
||||
/// <summary>
|
||||
/// Aktualisiert den Starface-Kontakt und gibt den massgeblichen Stand
|
||||
/// NACH dem Schreiben zurueck (null bei Fehler). Wird fuer die getrennte
|
||||
/// Hash-Baseline benoetigt, damit der Kontakt beim naechsten Sync nicht
|
||||
/// erneut faelschlich als geaendert gilt.
|
||||
/// </summary>
|
||||
public async Task<UnifiedContact> UpdateContactAsync(string contactId, UnifiedContact contact, StarfaceAddressBook book)
|
||||
{
|
||||
var sfContact = MapToStarface(contact);
|
||||
sfContact["id"] = contactId;
|
||||
|
||||
// Tag beibehalten
|
||||
if (!string.IsNullOrEmpty(book.TagId))
|
||||
{
|
||||
sfContact["tags"] = new JArray { new JObject { ["id"] = book.TagId } };
|
||||
}
|
||||
|
||||
var query = "";
|
||||
if (book.Type == "user" && !string.IsNullOrEmpty(book.UserId))
|
||||
query = $"?userId={book.UserId}";
|
||||
|
||||
var content = new StringContent(sfContact.ToString(), Encoding.UTF8, "application/json");
|
||||
var body = sfContact.ToString();
|
||||
var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||
var resp = await _http.PutAsync($"{_baseUrl}/contacts/{contactId}{query}", content);
|
||||
return resp.IsSuccessStatusCode;
|
||||
|
||||
if (!resp.IsSuccessStatusCode)
|
||||
{
|
||||
var respBody = await resp.Content.ReadAsStringAsync();
|
||||
OnDebug?.Invoke($"PUT /contacts/{contactId} fehlgeschlagen: {(int)resp.StatusCode}\n{respBody}");
|
||||
return null;
|
||||
}
|
||||
|
||||
// Frischen Stand zurueckgeben. Manche Versionen liefern den Kontakt
|
||||
// direkt in der PUT-Antwort, sonst per GET nachladen.
|
||||
try
|
||||
{
|
||||
var respBody = await resp.Content.ReadAsStringAsync();
|
||||
if (!string.IsNullOrWhiteSpace(respBody))
|
||||
{
|
||||
var obj = JObject.Parse(respBody);
|
||||
if (obj["blocks"] != null)
|
||||
return MapFromStarface(obj);
|
||||
}
|
||||
}
|
||||
catch { }
|
||||
|
||||
return await GetContactAsync(contactId) ?? contact;
|
||||
}
|
||||
|
||||
/// <summary>Laedt einen einzelnen Kontakt mit allen Feldern.</summary>
|
||||
public async Task<UnifiedContact> GetContactAsync(string contactId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var resp = await _http.GetAsync($"{_baseUrl}/contacts/{contactId}");
|
||||
if (!resp.IsSuccessStatusCode) return null;
|
||||
var obj = JObject.Parse(await resp.Content.ReadAsStringAsync());
|
||||
return MapFromStarface(obj);
|
||||
}
|
||||
catch { return null; }
|
||||
}
|
||||
|
||||
public async Task<bool> DeleteContactAsync(string contactId)
|
||||
|
||||
@@ -17,61 +17,60 @@ namespace StarfaceOutlookSync.Services
|
||||
|
||||
/// <summary>
|
||||
/// Findet einen passenden Kontakt in der Kandidatenliste.
|
||||
/// Matching-Reihenfolge: E-Mail, dann Vorname+Nachname+Firma, dann Vorname+Nachname.
|
||||
/// Strenges Matching: Felder die auf einer Seite gefuellt sind muessen
|
||||
/// auf der anderen auch gefuellt (und gleich) sein.
|
||||
/// Ein leeres Feld auf einer Seite und ein gefuelltes auf der anderen
|
||||
/// bedeutet: verschiedene Kontakte.
|
||||
/// </summary>
|
||||
private static UnifiedContact FindMatch(UnifiedContact contact, List<UnifiedContact> candidates)
|
||||
{
|
||||
if (candidates == null || candidates.Count == 0) return null;
|
||||
|
||||
// 1. Exakte E-Mail
|
||||
if (!string.IsNullOrEmpty(contact.Email))
|
||||
foreach (var c in candidates)
|
||||
{
|
||||
var byEmail = candidates.FirstOrDefault(c =>
|
||||
!string.IsNullOrEmpty(c.Email) &&
|
||||
c.Email.Equals(contact.Email, StringComparison.OrdinalIgnoreCase));
|
||||
if (byEmail != null) return byEmail;
|
||||
}
|
||||
|
||||
// 2. Vorname + Nachname + Firma (staerkstes Match ohne E-Mail)
|
||||
if ((!string.IsNullOrEmpty(contact.FirstName) || !string.IsNullOrEmpty(contact.LastName))
|
||||
&& !string.IsNullOrEmpty(contact.Company))
|
||||
{
|
||||
var byNameCompany = candidates.FirstOrDefault(c =>
|
||||
c.FirstName.Equals(contact.FirstName, StringComparison.OrdinalIgnoreCase) &&
|
||||
c.LastName.Equals(contact.LastName, StringComparison.OrdinalIgnoreCase) &&
|
||||
c.Company.Equals(contact.Company, StringComparison.OrdinalIgnoreCase));
|
||||
if (byNameCompany != null) return byNameCompany;
|
||||
}
|
||||
|
||||
// 3. Vorname + Nachname (ohne Firma)
|
||||
if (!string.IsNullOrEmpty(contact.FirstName) || !string.IsNullOrEmpty(contact.LastName))
|
||||
{
|
||||
var byName = candidates.FirstOrDefault(c =>
|
||||
c.FirstName.Equals(contact.FirstName, StringComparison.OrdinalIgnoreCase) &&
|
||||
c.LastName.Equals(contact.LastName, StringComparison.OrdinalIgnoreCase) &&
|
||||
(!string.IsNullOrEmpty(c.FirstName) || !string.IsNullOrEmpty(c.LastName)));
|
||||
if (byName != null) return byName;
|
||||
}
|
||||
|
||||
// 4. Telefonnummer (Buero oder Mobil)
|
||||
if (!string.IsNullOrEmpty(contact.PhoneWork))
|
||||
{
|
||||
var byPhone = candidates.FirstOrDefault(c =>
|
||||
!string.IsNullOrEmpty(c.PhoneWork) &&
|
||||
NormalizePhone(c.PhoneWork) == NormalizePhone(contact.PhoneWork));
|
||||
if (byPhone != null) return byPhone;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(contact.PhoneMobile))
|
||||
{
|
||||
var byMobile = candidates.FirstOrDefault(c =>
|
||||
!string.IsNullOrEmpty(c.PhoneMobile) &&
|
||||
NormalizePhone(c.PhoneMobile) == NormalizePhone(contact.PhoneMobile));
|
||||
if (byMobile != null) return byMobile;
|
||||
if (IsMatch(contact, c))
|
||||
return c;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool IsMatch(UnifiedContact a, UnifiedContact b)
|
||||
{
|
||||
bool hasName = (!string.IsNullOrEmpty(a.FirstName) || !string.IsNullOrEmpty(a.LastName))
|
||||
&& (!string.IsNullOrEmpty(b.FirstName) || !string.IsNullOrEmpty(b.LastName));
|
||||
|
||||
// Starke Identifikatoren
|
||||
bool emailMatch = !string.IsNullOrEmpty(a.Email) && !string.IsNullOrEmpty(b.Email)
|
||||
&& a.Email.Equals(b.Email, StringComparison.OrdinalIgnoreCase);
|
||||
bool nameMatch = hasName
|
||||
&& (a.FirstName ?? "").Equals(b.FirstName ?? "", StringComparison.OrdinalIgnoreCase)
|
||||
&& (a.LastName ?? "").Equals(b.LastName ?? "", StringComparison.OrdinalIgnoreCase);
|
||||
bool phoneMatch = (!string.IsNullOrEmpty(a.PhoneWork) && !string.IsNullOrEmpty(b.PhoneWork)
|
||||
&& NormalizePhone(a.PhoneWork) == NormalizePhone(b.PhoneWork))
|
||||
|| (!string.IsNullOrEmpty(a.PhoneMobile) && !string.IsNullOrEmpty(b.PhoneMobile)
|
||||
&& NormalizePhone(a.PhoneMobile) == NormalizePhone(b.PhoneMobile))
|
||||
|| (!string.IsNullOrEmpty(a.Fax) && !string.IsNullOrEmpty(b.Fax)
|
||||
&& NormalizePhone(a.Fax) == NormalizePhone(b.Fax));
|
||||
bool companyMatch = !string.IsNullOrEmpty(a.Company) && !string.IsNullOrEmpty(b.Company)
|
||||
&& a.Company.Equals(b.Company, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
// Widerspruch: beide haben eine E-Mail, aber unterschiedlich -> verschiedene Personen.
|
||||
bool emailContradiction = !string.IsNullOrEmpty(a.Email) && !string.IsNullOrEmpty(b.Email) && !emailMatch;
|
||||
|
||||
// Gleiche E-Mail ist der staerkste Identifikator und reicht allein.
|
||||
if (emailMatch) return true;
|
||||
|
||||
// Gleicher voller Name reicht, solange keine widerspruechliche E-Mail vorliegt.
|
||||
// (Telefon-Umformatierung durch Starface darf einen Namens-Treffer NICHT verhindern.)
|
||||
if (nameMatch && !emailContradiction) return true;
|
||||
|
||||
// Schwacher Pfad: Telefon/Fax nur zusammen mit gleicher Firma und ohne E-Mail-Widerspruch.
|
||||
if (phoneMatch && companyMatch && !emailContradiction) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static string NormalizePhone(string phone)
|
||||
{
|
||||
if (string.IsNullOrEmpty(phone)) return "";
|
||||
@@ -144,23 +143,88 @@ namespace StarfaceOutlookSync.Services
|
||||
if (oc == null && sc == null)
|
||||
{
|
||||
// Beide Seiten geloescht -> Mapping entfernen
|
||||
Log($" Mapping verwaist (beide geloescht), entferne");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (oc == null && sc != null)
|
||||
{
|
||||
// Outlook-Kontakt nicht gefunden.
|
||||
// Erst pruefen ob er vielleicht nur eine neue EntryID hat
|
||||
var reMatch = FindMatch(sc, outlookContacts.Where(c =>
|
||||
!processedOutlookIds.Contains(c.OutlookEntryId)).ToList());
|
||||
if (reMatch != null)
|
||||
{
|
||||
// Kontakt existiert noch in Outlook, nur EntryID geaendert
|
||||
Log($" EntryID geaendert, verknuepfe neu: {sc.DisplayName}");
|
||||
mapping.OutlookEntryId = reMatch.OutlookEntryId;
|
||||
processedOutlookIds.Add(reMatch.OutlookEntryId);
|
||||
newMappings.Add(mapping);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Wirklich geloescht -> in Starface auch loeschen
|
||||
if (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.OutlookToStarface)
|
||||
{
|
||||
if (await starface.DeleteContactAsync(mapping.StarfaceId))
|
||||
{
|
||||
result.Updated++;
|
||||
Log($" Geloescht (OL->SF): {sc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newMappings.Add(mapping);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (oc != null && sc == null)
|
||||
{
|
||||
// Starface-Kontakt nicht in der geladenen Liste.
|
||||
// Da unvollstaendige Ladevorgaenge inzwischen abgebrochen
|
||||
// werden (siehe StarfaceApiClient), liegt das hoechstens an
|
||||
// einem anderen Adressbuch. NICHT loeschen und NICHT neu
|
||||
// anlegen - sonst entstehen Dubletten. Mapping behalten,
|
||||
// beim naechsten Sync wird es erneut abgeglichen.
|
||||
Log($" Starface-Kontakt nicht in Liste (anderes Adressbuch?), behalte Mapping: {oc.DisplayName}");
|
||||
newMappings.Add(mapping);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (oc != null && sc != null)
|
||||
{
|
||||
// Beide vorhanden -> auf Aenderungen pruefen
|
||||
// Beide vorhanden -> auf Aenderungen pruefen.
|
||||
// WICHTIG: jede Seite gegen ihre EIGENE Baseline pruefen.
|
||||
// Outlook und Starface stellen denselben Kontakt
|
||||
// unterschiedlich dar, ein gemeinsamer Hash schlaegt nie an.
|
||||
var olHash = oc.GetHash();
|
||||
var sfHash = sc.GetHash();
|
||||
bool olChanged = olHash != mapping.LastSyncHash;
|
||||
bool sfChanged = sfHash != mapping.LastSyncHash;
|
||||
|
||||
// Migration alter Mappings (nur LastSyncHash vorhanden):
|
||||
// aktuellen Stand als Baseline uebernehmen und als synchron
|
||||
// annehmen, damit kein Massen-Update ausgeloest wird.
|
||||
if (string.IsNullOrEmpty(mapping.LastOutlookHash) &&
|
||||
string.IsNullOrEmpty(mapping.LastStarfaceHash))
|
||||
{
|
||||
mapping.LastOutlookHash = olHash;
|
||||
mapping.LastStarfaceHash = sfHash;
|
||||
mapping.LastSyncHash = "";
|
||||
newMappings.Add(mapping);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool olChanged = olHash != mapping.LastOutlookHash;
|
||||
bool sfChanged = sfHash != mapping.LastStarfaceHash;
|
||||
|
||||
if (olChanged && !sfChanged && (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.OutlookToStarface))
|
||||
{
|
||||
// Outlook hat sich geaendert -> Starface updaten
|
||||
if (await starface.UpdateContactAsync(mapping.StarfaceId, oc, profile.StarfaceAddressBook))
|
||||
var updated = await starface.UpdateContactAsync(mapping.StarfaceId, oc, profile.StarfaceAddressBook);
|
||||
if (updated != null)
|
||||
{
|
||||
mapping.LastSyncHash = olHash;
|
||||
mapping.LastOutlookHash = olHash;
|
||||
mapping.LastStarfaceHash = updated.GetHash();
|
||||
result.Updated++;
|
||||
Log($" Aktualisiert (OL->SF): {oc.DisplayName}");
|
||||
}
|
||||
@@ -168,30 +232,36 @@ namespace StarfaceOutlookSync.Services
|
||||
else if (sfChanged && !olChanged && (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.StarfaceToOutlook))
|
||||
{
|
||||
// Starface hat sich geaendert -> Outlook updaten
|
||||
if (_outlookService.UpdateContact(mapping.OutlookEntryId, sc))
|
||||
var updated = _outlookService.UpdateContact(mapping.OutlookEntryId, sc);
|
||||
if (updated != null)
|
||||
{
|
||||
mapping.LastSyncHash = sfHash;
|
||||
mapping.LastStarfaceHash = sfHash;
|
||||
mapping.LastOutlookHash = updated.GetHash();
|
||||
result.Updated++;
|
||||
Log($" Aktualisiert (SF->OL): {sc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else if (olChanged && sfChanged)
|
||||
{
|
||||
// Beide geaendert -> Konflikt, neuere gewinnt (Outlook bevorzugt)
|
||||
// Beide geaendert -> Konflikt, Outlook bevorzugt
|
||||
if (profile.SyncDirection != SyncDirection.StarfaceToOutlook)
|
||||
{
|
||||
if (await starface.UpdateContactAsync(mapping.StarfaceId, oc, profile.StarfaceAddressBook))
|
||||
var updated = await starface.UpdateContactAsync(mapping.StarfaceId, oc, profile.StarfaceAddressBook);
|
||||
if (updated != null)
|
||||
{
|
||||
mapping.LastSyncHash = olHash;
|
||||
mapping.LastOutlookHash = olHash;
|
||||
mapping.LastStarfaceHash = updated.GetHash();
|
||||
result.Updated++;
|
||||
Log($" Konflikt (OL gewinnt): {oc.DisplayName}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_outlookService.UpdateContact(mapping.OutlookEntryId, sc))
|
||||
var updated = _outlookService.UpdateContact(mapping.OutlookEntryId, sc);
|
||||
if (updated != null)
|
||||
{
|
||||
mapping.LastSyncHash = sfHash;
|
||||
mapping.LastStarfaceHash = sfHash;
|
||||
mapping.LastOutlookHash = updated.GetHash();
|
||||
result.Updated++;
|
||||
Log($" Konflikt (SF gewinnt): {sc.DisplayName}");
|
||||
}
|
||||
@@ -229,14 +299,16 @@ namespace StarfaceOutlookSync.Services
|
||||
if (match != null)
|
||||
{
|
||||
// Existiert schon -> verknuepfen und updaten
|
||||
if (await starface.UpdateContactAsync(match.StarfaceId, oc, profile.StarfaceAddressBook))
|
||||
var updated = await starface.UpdateContactAsync(match.StarfaceId, oc, profile.StarfaceAddressBook);
|
||||
if (updated != null)
|
||||
{
|
||||
newMappings.Add(new SyncMapping
|
||||
{
|
||||
ProfileId = profile.Id,
|
||||
OutlookEntryId = oc.OutlookEntryId,
|
||||
StarfaceId = match.StarfaceId,
|
||||
LastSyncHash = oc.GetHash()
|
||||
LastOutlookHash = oc.GetHash(),
|
||||
LastStarfaceHash = updated.GetHash()
|
||||
});
|
||||
processedStarfaceIds.Add(match.StarfaceId);
|
||||
unmappedStarface.Remove(match);
|
||||
@@ -256,7 +328,8 @@ namespace StarfaceOutlookSync.Services
|
||||
ProfileId = profile.Id,
|
||||
OutlookEntryId = oc.OutlookEntryId,
|
||||
StarfaceId = created.StarfaceId,
|
||||
LastSyncHash = oc.GetHash()
|
||||
LastOutlookHash = oc.GetHash(),
|
||||
LastStarfaceHash = created.GetHash()
|
||||
});
|
||||
result.Created++;
|
||||
Log($" Erstellt (OL->SF): {oc.DisplayName}");
|
||||
@@ -302,14 +375,16 @@ namespace StarfaceOutlookSync.Services
|
||||
if (match != null)
|
||||
{
|
||||
// Existiert schon -> verknuepfen und updaten
|
||||
if (_outlookService.UpdateContact(match.OutlookEntryId, sc))
|
||||
var updated = _outlookService.UpdateContact(match.OutlookEntryId, sc);
|
||||
if (updated != null)
|
||||
{
|
||||
newMappings.Add(new SyncMapping
|
||||
{
|
||||
ProfileId = profile.Id,
|
||||
OutlookEntryId = match.OutlookEntryId,
|
||||
StarfaceId = sc.StarfaceId,
|
||||
LastSyncHash = sc.GetHash()
|
||||
LastStarfaceHash = sc.GetHash(),
|
||||
LastOutlookHash = updated.GetHash()
|
||||
});
|
||||
processedOutlookIds.Add(match.OutlookEntryId);
|
||||
unmappedOutlook.Remove(match);
|
||||
@@ -328,7 +403,8 @@ namespace StarfaceOutlookSync.Services
|
||||
ProfileId = profile.Id,
|
||||
OutlookEntryId = created.OutlookEntryId,
|
||||
StarfaceId = sc.StarfaceId,
|
||||
LastSyncHash = sc.GetHash()
|
||||
LastStarfaceHash = sc.GetHash(),
|
||||
LastOutlookHash = created.GetHash()
|
||||
});
|
||||
result.Created++;
|
||||
Log($" Erstellt (SF->OL): {sc.DisplayName}");
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
<AssemblyTitle>Starface Outlook Sync</AssemblyTitle>
|
||||
<Company>HackerSoft - Hacker-Net Telekommunikation</Company>
|
||||
<Product>Starface Outlook Sync</Product>
|
||||
<Version>0.0.0.15</Version>
|
||||
<AssemblyVersion>0.0.0.15</AssemblyVersion>
|
||||
<FileVersion>0.0.0.15</FileVersion>
|
||||
<Version>0.0.0.24</Version>
|
||||
<AssemblyVersion>0.0.0.24</AssemblyVersion>
|
||||
<FileVersion>0.0.0.24</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.15",
|
||||
Text = "Version 0.0.0.24",
|
||||
Left = 0, Top = 56, Width = 340, Height = 20,
|
||||
TextAlign = ContentAlignment.MiddleCenter,
|
||||
ForeColor = Color.Gray
|
||||
|
||||
@@ -22,6 +22,7 @@ namespace StarfaceOutlookSync.UI
|
||||
private StatusStrip _statusBar;
|
||||
private ToolStripStatusLabel _statusLabel;
|
||||
private Timer _autoSyncTimer;
|
||||
private volatile bool _syncRunning = false;
|
||||
|
||||
public MainForm()
|
||||
{
|
||||
@@ -30,14 +31,31 @@ namespace StarfaceOutlookSync.UI
|
||||
SetupAutoSync();
|
||||
RefreshProfileList();
|
||||
|
||||
// Minimiert starten falls in Einstellungen aktiviert
|
||||
// Einstellungen laden und anwenden
|
||||
var settings = UserSettings.Load();
|
||||
settings.ApplyOutlookSecuritySetting();
|
||||
|
||||
if (settings.StartMinimized)
|
||||
{
|
||||
WindowState = FormWindowState.Minimized;
|
||||
ShowInTaskbar = false;
|
||||
Visible = false;
|
||||
}
|
||||
|
||||
// Beim Start automatisch synchronisieren
|
||||
if (settings.SyncOnStart)
|
||||
{
|
||||
_ = SyncAllProfiles();
|
||||
}
|
||||
}
|
||||
|
||||
private async Task SyncAllProfiles()
|
||||
{
|
||||
var profiles = _profileManager.GetProfiles().Where(p => p.Enabled).ToList();
|
||||
foreach (var profile in profiles)
|
||||
{
|
||||
await RunSync(profile);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetVisibleCore(bool value)
|
||||
@@ -58,8 +76,8 @@ namespace StarfaceOutlookSync.UI
|
||||
private void InitializeComponent()
|
||||
{
|
||||
Text = "Starface Kontakt-Sync";
|
||||
Size = new Size(620, 450);
|
||||
MinimumSize = new Size(500, 350);
|
||||
Size = new Size(830, 450);
|
||||
MinimumSize = new Size(830, 350);
|
||||
StartPosition = FormStartPosition.CenterScreen;
|
||||
Font = new Font("Segoe UI", 9);
|
||||
Icon = AppIcon.GetIcon();
|
||||
@@ -158,6 +176,7 @@ namespace StarfaceOutlookSync.UI
|
||||
if (profiles.Any(p => p.Enabled))
|
||||
_trayMenu.Items.Add("-");
|
||||
|
||||
_trayMenu.Items.Add("Ueber", null, (s, e) => ShowAbout());
|
||||
_trayMenu.Items.Add("Beenden", null, (s, e) => ExitApplication());
|
||||
}
|
||||
|
||||
@@ -318,6 +337,13 @@ namespace StarfaceOutlookSync.UI
|
||||
|
||||
private async Task RunSync(SyncProfile profile)
|
||||
{
|
||||
if (_syncRunning)
|
||||
{
|
||||
SetStatus("Sync laeuft bereits, bitte warten...");
|
||||
return;
|
||||
}
|
||||
|
||||
_syncRunning = true;
|
||||
try
|
||||
{
|
||||
SetStatus($"Synchronisiere '{profile.Name}'...");
|
||||
@@ -340,6 +366,10 @@ namespace StarfaceOutlookSync.UI
|
||||
ex.Message, ToolTipIcon.Error);
|
||||
SetStatus($"Fehler: {ex.Message}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
_syncRunning = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetStatus(string text)
|
||||
|
||||
@@ -333,9 +333,23 @@ namespace StarfaceOutlookSync.UI
|
||||
};
|
||||
|
||||
if (_isNew)
|
||||
{
|
||||
_pm.AddProfile(profile);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Wenn Adressbuch gewechselt wurde, Mappings zuruecksetzen
|
||||
if (_existingProfile.StarfaceAddressBook?.TagId != profile.StarfaceAddressBook?.TagId
|
||||
|| _existingProfile.StarfaceAddressBook?.Type != profile.StarfaceAddressBook?.Type)
|
||||
{
|
||||
_pm.SaveMappings(profile.Id, new List<SyncMapping>());
|
||||
profile.LastSync = "";
|
||||
MessageBox.Show(
|
||||
"Adressbuch wurde geaendert.\nSync-Zuordnungen wurden automatisch zurueckgesetzt.",
|
||||
"Adressbuch geaendert", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
_pm.UpdateProfile(profile);
|
||||
}
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
||||
@@ -6,7 +6,7 @@ namespace StarfaceOutlookSync.UI
|
||||
{
|
||||
public class SettingsForm : Form
|
||||
{
|
||||
private CheckBox _chkStartMinimized;
|
||||
private CheckBox _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook;
|
||||
private Button _btnSave, _btnCancel;
|
||||
private readonly UserSettings _settings;
|
||||
|
||||
@@ -19,7 +19,7 @@ namespace StarfaceOutlookSync.UI
|
||||
private void InitializeComponent()
|
||||
{
|
||||
Text = "Einstellungen";
|
||||
Size = new Size(350, 180);
|
||||
Size = new Size(380, 250);
|
||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
MaximizeBox = false;
|
||||
MinimizeBox = false;
|
||||
@@ -33,20 +33,47 @@ namespace StarfaceOutlookSync.UI
|
||||
Checked = _settings.StartMinimized
|
||||
};
|
||||
|
||||
_chkSyncOnStart = new CheckBox
|
||||
{
|
||||
Text = "Beim Start automatisch synchronisieren",
|
||||
Left = 20, Top = 52, AutoSize = true,
|
||||
Checked = _settings.SyncOnStart
|
||||
};
|
||||
|
||||
_chkAutoAcceptOutlook = new CheckBox
|
||||
{
|
||||
Text = "Outlook-Sicherheitsabfrage automatisch erlauben",
|
||||
Left = 20, Top = 80, AutoSize = true,
|
||||
Checked = _settings.AutoAcceptOutlookPrompt
|
||||
};
|
||||
|
||||
var hintText = "Hinweis: Outlook muss nach Aenderung neu gestartet werden.";
|
||||
if (UserSettings.IsOutlookSecurityLockedByPolicy())
|
||||
hintText += "\nAuf Domaenen-PCs: App einmalig als Admin starten!";
|
||||
|
||||
var lblHint = new Label
|
||||
{
|
||||
Text = hintText,
|
||||
Left = 38, Top = 102, Width = 310, Height = 36,
|
||||
ForeColor = UserSettings.IsOutlookSecurityLockedByPolicy() ? Color.OrangeRed : Color.Gray,
|
||||
Font = new Font("Segoe UI", 8)
|
||||
};
|
||||
|
||||
_btnSave = new Button
|
||||
{
|
||||
Text = "Speichern", Left = 80, Top = 100, Width = 85, Height = 28,
|
||||
Text = "Speichern", Left = 95, Top = 170, Width = 85, Height = 28,
|
||||
DialogResult = DialogResult.None
|
||||
};
|
||||
_btnSave.Click += (s, e) => Save();
|
||||
|
||||
_btnCancel = new Button
|
||||
{
|
||||
Text = "Abbrechen", Left = 174, Top = 100, Width = 85, Height = 28,
|
||||
Text = "Abbrechen", Left = 189, Top = 170, Width = 85, Height = 28,
|
||||
DialogResult = DialogResult.Cancel
|
||||
};
|
||||
|
||||
Controls.AddRange(new Control[] { _chkStartMinimized, _btnSave, _btnCancel });
|
||||
Size = new Size(380, 260);
|
||||
Controls.AddRange(new Control[] { _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook, lblHint, _btnSave, _btnCancel });
|
||||
AcceptButton = _btnSave;
|
||||
CancelButton = _btnCancel;
|
||||
}
|
||||
@@ -54,6 +81,8 @@ namespace StarfaceOutlookSync.UI
|
||||
private void Save()
|
||||
{
|
||||
_settings.StartMinimized = _chkStartMinimized.Checked;
|
||||
_settings.SyncOnStart = _chkSyncOnStart.Checked;
|
||||
_settings.AutoAcceptOutlookPrompt = _chkAutoAcceptOutlook.Checked;
|
||||
_settings.Save();
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
|
||||
Reference in New Issue
Block a user