Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3e22a40e17 | |||
| 36aca2c04d | |||
| 4f56f28ccb | |||
| 2b9ad5bf3c | |||
| 8a316600b5 | |||
| 0f61b4cd31 | |||
| b9f5a26b27 | |||
| 4359d3ad1a | |||
| 39b30f9a80 |
+1
-1
@@ -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.12"
|
#define MyAppVersion "0.0.0.15"
|
||||||
#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"
|
||||||
|
|||||||
@@ -252,11 +252,20 @@ namespace StarfaceOutlookSync.Services
|
|||||||
if (book.Type == "user" && !string.IsNullOrEmpty(book.UserId))
|
if (book.Type == "user" && !string.IsNullOrEmpty(book.UserId))
|
||||||
query = $"?userId={book.UserId}";
|
query = $"?userId={book.UserId}";
|
||||||
|
|
||||||
var content = new StringContent(sfContact.ToString(), Encoding.UTF8, "application/json");
|
var body = sfContact.ToString();
|
||||||
var resp = await _http.PostAsync($"{_baseUrl}/contacts{query}", content);
|
OnDebug?.Invoke($"POST /contacts{query} Body:\n{body}");
|
||||||
if (!resp.IsSuccessStatusCode) return null;
|
|
||||||
|
|
||||||
var created = JObject.Parse(await resp.Content.ReadAsStringAsync());
|
var content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||||
|
var resp = await _http.PostAsync($"{_baseUrl}/contacts{query}", content);
|
||||||
|
var respBody = await resp.Content.ReadAsStringAsync();
|
||||||
|
|
||||||
|
if (!resp.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
OnDebug?.Invoke($"POST /contacts fehlgeschlagen: {(int)resp.StatusCode} {resp.StatusCode}\n{respBody}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var created = JObject.Parse(respBody);
|
||||||
return MapFromStarface(created);
|
return MapFromStarface(created);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,9 +15,15 @@ namespace StarfaceOutlookSync.Services
|
|||||||
|
|
||||||
private void Log(string message) => OnProgress?.Invoke(message);
|
private void Log(string message) => OnProgress?.Invoke(message);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Findet einen passenden Kontakt in der Kandidatenliste.
|
||||||
|
/// Matching-Reihenfolge: E-Mail, dann Vorname+Nachname+Firma, dann Vorname+Nachname.
|
||||||
|
/// </summary>
|
||||||
private static UnifiedContact FindMatch(UnifiedContact contact, List<UnifiedContact> candidates)
|
private static UnifiedContact FindMatch(UnifiedContact contact, List<UnifiedContact> candidates)
|
||||||
{
|
{
|
||||||
// Erst E-Mail-Match
|
if (candidates == null || candidates.Count == 0) return null;
|
||||||
|
|
||||||
|
// 1. Exakte E-Mail
|
||||||
if (!string.IsNullOrEmpty(contact.Email))
|
if (!string.IsNullOrEmpty(contact.Email))
|
||||||
{
|
{
|
||||||
var byEmail = candidates.FirstOrDefault(c =>
|
var byEmail = candidates.FirstOrDefault(c =>
|
||||||
@@ -26,7 +32,18 @@ namespace StarfaceOutlookSync.Services
|
|||||||
if (byEmail != null) return byEmail;
|
if (byEmail != null) return byEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Dann Name-Match
|
// 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))
|
if (!string.IsNullOrEmpty(contact.FirstName) || !string.IsNullOrEmpty(contact.LastName))
|
||||||
{
|
{
|
||||||
var byName = candidates.FirstOrDefault(c =>
|
var byName = candidates.FirstOrDefault(c =>
|
||||||
@@ -36,9 +53,32 @@ namespace StarfaceOutlookSync.Services
|
|||||||
if (byName != null) return byName;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static string NormalizePhone(string phone)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(phone)) return "";
|
||||||
|
// Nur Ziffern und + behalten
|
||||||
|
return new string(phone.Where(c => char.IsDigit(c) || c == '+').ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<SyncResult> SyncProfileAsync(SyncProfile profile)
|
public async Task<SyncResult> SyncProfileAsync(SyncProfile profile)
|
||||||
{
|
{
|
||||||
var result = new SyncResult
|
var result = new SyncResult
|
||||||
@@ -49,7 +89,6 @@ namespace StarfaceOutlookSync.Services
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Starface verbinden
|
|
||||||
Log("Verbinde mit Starface...");
|
Log("Verbinde mit Starface...");
|
||||||
using (var starface = new StarfaceApiClient(profile.StarfaceConnection))
|
using (var starface = new StarfaceApiClient(profile.StarfaceConnection))
|
||||||
{
|
{
|
||||||
@@ -62,10 +101,6 @@ namespace StarfaceOutlookSync.Services
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
var mappings = _profileManager.GetMappings(profile.Id);
|
|
||||||
var mappingByOutlook = mappings.ToDictionary(m => m.OutlookEntryId, m => m);
|
|
||||||
var mappingByStarface = mappings.ToDictionary(m => m.StarfaceId, m => m);
|
|
||||||
|
|
||||||
// Kontakte laden
|
// Kontakte laden
|
||||||
Log("Lade Outlook-Kontakte...");
|
Log("Lade Outlook-Kontakte...");
|
||||||
var outlookContacts = _outlookService.GetContacts(profile.OutlookFolderPath);
|
var outlookContacts = _outlookService.GetContacts(profile.OutlookFolderPath);
|
||||||
@@ -75,54 +110,148 @@ namespace StarfaceOutlookSync.Services
|
|||||||
var starfaceContacts = await starface.GetContactsAsync(profile.StarfaceAddressBook);
|
var starfaceContacts = await starface.GetContactsAsync(profile.StarfaceAddressBook);
|
||||||
Log($"{starfaceContacts.Count} Starface-Kontakte geladen");
|
Log($"{starfaceContacts.Count} Starface-Kontakte geladen");
|
||||||
|
|
||||||
// Outlook -> Starface
|
// Bestehende Mappings laden
|
||||||
if (profile.SyncDirection == SyncDirection.Both ||
|
var mappings = _profileManager.GetMappings(profile.Id);
|
||||||
profile.SyncDirection == SyncDirection.OutlookToStarface)
|
|
||||||
{
|
|
||||||
Log("Synchronisiere Outlook -> Starface...");
|
|
||||||
foreach (var oc in outlookContacts)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
SyncMapping existing = null;
|
|
||||||
if (!string.IsNullOrEmpty(oc.OutlookEntryId))
|
|
||||||
mappingByOutlook.TryGetValue(oc.OutlookEntryId, out existing);
|
|
||||||
|
|
||||||
if (existing != null)
|
// Sets fuer schnellen Lookup
|
||||||
|
var mappingByOutlook = new Dictionary<string, SyncMapping>();
|
||||||
|
var mappingByStarface = new Dictionary<string, SyncMapping>();
|
||||||
|
foreach (var m in mappings)
|
||||||
{
|
{
|
||||||
var hash = oc.GetHash();
|
if (!string.IsNullOrEmpty(m.OutlookEntryId))
|
||||||
if (hash != existing.LastSyncHash)
|
mappingByOutlook[m.OutlookEntryId] = m;
|
||||||
{
|
if (!string.IsNullOrEmpty(m.StarfaceId))
|
||||||
if (await starface.UpdateContactAsync(existing.StarfaceId, oc, profile.StarfaceAddressBook))
|
mappingByStarface[m.StarfaceId] = m;
|
||||||
{
|
|
||||||
existing.LastSyncHash = hash;
|
|
||||||
result.Updated++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Tracking: welche Kontakte wurden bereits verarbeitet
|
||||||
|
var processedStarfaceIds = new HashSet<string>();
|
||||||
|
var processedOutlookIds = new HashSet<string>();
|
||||||
|
var newMappings = new List<SyncMapping>();
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Phase 1: Bestehende Mappings abgleichen
|
||||||
|
// ============================================
|
||||||
|
Log("Gleiche bestehende Zuordnungen ab...");
|
||||||
|
foreach (var mapping in mappings.ToList())
|
||||||
|
{
|
||||||
|
var oc = outlookContacts.FirstOrDefault(c => c.OutlookEntryId == mapping.OutlookEntryId);
|
||||||
|
var sc = starfaceContacts.FirstOrDefault(c => c.StarfaceId == mapping.StarfaceId);
|
||||||
|
|
||||||
|
if (oc != null) processedOutlookIds.Add(oc.OutlookEntryId);
|
||||||
|
if (sc != null) processedStarfaceIds.Add(sc.StarfaceId);
|
||||||
|
|
||||||
|
if (oc == null && sc == null)
|
||||||
|
{
|
||||||
|
// Beide Seiten geloescht -> Mapping entfernen
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oc != null && sc != null)
|
||||||
|
{
|
||||||
|
// Beide vorhanden -> auf Aenderungen pruefen
|
||||||
|
var olHash = oc.GetHash();
|
||||||
|
var sfHash = sc.GetHash();
|
||||||
|
bool olChanged = olHash != mapping.LastSyncHash;
|
||||||
|
bool sfChanged = sfHash != mapping.LastSyncHash;
|
||||||
|
|
||||||
|
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))
|
||||||
|
{
|
||||||
|
mapping.LastSyncHash = olHash;
|
||||||
|
result.Updated++;
|
||||||
|
Log($" Aktualisiert (OL->SF): {oc.DisplayName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (sfChanged && !olChanged && (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.StarfaceToOutlook))
|
||||||
|
{
|
||||||
|
// Starface hat sich geaendert -> Outlook updaten
|
||||||
|
if (_outlookService.UpdateContact(mapping.OutlookEntryId, sc))
|
||||||
|
{
|
||||||
|
mapping.LastSyncHash = sfHash;
|
||||||
|
result.Updated++;
|
||||||
|
Log($" Aktualisiert (SF->OL): {sc.DisplayName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (olChanged && sfChanged)
|
||||||
|
{
|
||||||
|
// Beide geaendert -> Konflikt, neuere gewinnt (Outlook bevorzugt)
|
||||||
|
if (profile.SyncDirection != SyncDirection.StarfaceToOutlook)
|
||||||
|
{
|
||||||
|
if (await starface.UpdateContactAsync(mapping.StarfaceId, oc, profile.StarfaceAddressBook))
|
||||||
|
{
|
||||||
|
mapping.LastSyncHash = olHash;
|
||||||
|
result.Updated++;
|
||||||
|
Log($" Konflikt (OL gewinnt): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var match = FindMatch(oc, starfaceContacts);
|
if (_outlookService.UpdateContact(mapping.OutlookEntryId, sc))
|
||||||
if (match != null && !string.IsNullOrEmpty(match.StarfaceId))
|
|
||||||
{
|
{
|
||||||
|
mapping.LastSyncHash = sfHash;
|
||||||
|
result.Updated++;
|
||||||
|
Log($" Konflikt (SF gewinnt): {sc.DisplayName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Beide unveraendert -> nichts tun
|
||||||
|
}
|
||||||
|
|
||||||
|
newMappings.Add(mapping);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================
|
||||||
|
// Phase 2: Neue Outlook-Kontakte (ohne Mapping)
|
||||||
|
// ============================================
|
||||||
|
if (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.OutlookToStarface)
|
||||||
|
{
|
||||||
|
var unmappedOutlook = outlookContacts
|
||||||
|
.Where(c => !string.IsNullOrEmpty(c.OutlookEntryId) && !processedOutlookIds.Contains(c.OutlookEntryId))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (unmappedOutlook.Count > 0)
|
||||||
|
Log($"Neue Outlook-Kontakte: {unmappedOutlook.Count}");
|
||||||
|
|
||||||
|
// Starface-Kontakte die noch kein Mapping haben (fuer Duplikat-Check)
|
||||||
|
var unmappedStarface = starfaceContacts
|
||||||
|
.Where(c => !string.IsNullOrEmpty(c.StarfaceId) && !processedStarfaceIds.Contains(c.StarfaceId))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var oc in unmappedOutlook)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
// Duplikat-Check: existiert der Kontakt schon in der Starface?
|
||||||
|
var match = FindMatch(oc, unmappedStarface);
|
||||||
|
if (match != null)
|
||||||
|
{
|
||||||
|
// Existiert schon -> verknuepfen und updaten
|
||||||
if (await starface.UpdateContactAsync(match.StarfaceId, oc, profile.StarfaceAddressBook))
|
if (await starface.UpdateContactAsync(match.StarfaceId, oc, profile.StarfaceAddressBook))
|
||||||
{
|
{
|
||||||
_profileManager.AddOrUpdateMapping(new SyncMapping
|
newMappings.Add(new SyncMapping
|
||||||
{
|
{
|
||||||
ProfileId = profile.Id,
|
ProfileId = profile.Id,
|
||||||
OutlookEntryId = oc.OutlookEntryId,
|
OutlookEntryId = oc.OutlookEntryId,
|
||||||
StarfaceId = match.StarfaceId,
|
StarfaceId = match.StarfaceId,
|
||||||
LastSyncHash = oc.GetHash()
|
LastSyncHash = oc.GetHash()
|
||||||
});
|
});
|
||||||
|
processedStarfaceIds.Add(match.StarfaceId);
|
||||||
|
unmappedStarface.Remove(match);
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
|
Log($" Verknuepft (OL->SF): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Neu -> in Starface erstellen
|
||||||
|
Log($" Erstelle in Starface: {oc.DisplayName}");
|
||||||
var created = await starface.CreateContactAsync(oc, profile.StarfaceAddressBook);
|
var created = await starface.CreateContactAsync(oc, profile.StarfaceAddressBook);
|
||||||
if (created != null && !string.IsNullOrEmpty(created.StarfaceId))
|
if (created != null && !string.IsNullOrEmpty(created.StarfaceId))
|
||||||
{
|
{
|
||||||
_profileManager.AddOrUpdateMapping(new SyncMapping
|
newMappings.Add(new SyncMapping
|
||||||
{
|
{
|
||||||
ProfileId = profile.Id,
|
ProfileId = profile.Id,
|
||||||
OutlookEntryId = oc.OutlookEntryId,
|
OutlookEntryId = oc.OutlookEntryId,
|
||||||
@@ -130,66 +259,71 @@ namespace StarfaceOutlookSync.Services
|
|||||||
LastSyncHash = oc.GetHash()
|
LastSyncHash = oc.GetHash()
|
||||||
});
|
});
|
||||||
result.Created++;
|
result.Created++;
|
||||||
|
Log($" Erstellt (OL->SF): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log($" FEHLER: Kontakt konnte nicht erstellt werden: {oc.DisplayName}");
|
||||||
|
result.Errors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
result.Errors++;
|
result.Errors++;
|
||||||
result.ErrorMessages.Add($"{oc.DisplayName}: {ex.Message}");
|
result.ErrorMessages.Add($"OL->SF {oc.DisplayName}: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Starface -> Outlook
|
// ============================================
|
||||||
if (profile.SyncDirection == SyncDirection.Both ||
|
// Phase 3: Neue Starface-Kontakte (ohne Mapping)
|
||||||
profile.SyncDirection == SyncDirection.StarfaceToOutlook)
|
// ============================================
|
||||||
|
if (profile.SyncDirection == SyncDirection.Both || profile.SyncDirection == SyncDirection.StarfaceToOutlook)
|
||||||
{
|
{
|
||||||
Log("Synchronisiere Starface -> Outlook...");
|
var unmappedStarface = starfaceContacts
|
||||||
foreach (var sc in starfaceContacts)
|
.Where(c => !string.IsNullOrEmpty(c.StarfaceId) && !processedStarfaceIds.Contains(c.StarfaceId))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
if (unmappedStarface.Count > 0)
|
||||||
|
Log($"Neue Starface-Kontakte: {unmappedStarface.Count}");
|
||||||
|
|
||||||
|
// Outlook-Kontakte die noch kein Mapping haben (fuer Duplikat-Check)
|
||||||
|
var unmappedOutlook = outlookContacts
|
||||||
|
.Where(c => !string.IsNullOrEmpty(c.OutlookEntryId) && !processedOutlookIds.Contains(c.OutlookEntryId))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
foreach (var sc in unmappedStarface)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SyncMapping existing = null;
|
// Duplikat-Check: existiert der Kontakt schon in Outlook?
|
||||||
if (!string.IsNullOrEmpty(sc.StarfaceId))
|
var match = FindMatch(sc, unmappedOutlook);
|
||||||
mappingByStarface.TryGetValue(sc.StarfaceId, out existing);
|
if (match != null)
|
||||||
|
|
||||||
if (existing != null)
|
|
||||||
{
|
|
||||||
var hash = sc.GetHash();
|
|
||||||
if (hash != existing.LastSyncHash)
|
|
||||||
{
|
|
||||||
if (_outlookService.UpdateContact(existing.OutlookEntryId, sc))
|
|
||||||
{
|
|
||||||
existing.LastSyncHash = hash;
|
|
||||||
result.Updated++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var match = FindMatch(sc, outlookContacts);
|
|
||||||
if (match != null && !string.IsNullOrEmpty(match.OutlookEntryId))
|
|
||||||
{
|
{
|
||||||
|
// Existiert schon -> verknuepfen und updaten
|
||||||
if (_outlookService.UpdateContact(match.OutlookEntryId, sc))
|
if (_outlookService.UpdateContact(match.OutlookEntryId, sc))
|
||||||
{
|
{
|
||||||
_profileManager.AddOrUpdateMapping(new SyncMapping
|
newMappings.Add(new SyncMapping
|
||||||
{
|
{
|
||||||
ProfileId = profile.Id,
|
ProfileId = profile.Id,
|
||||||
OutlookEntryId = match.OutlookEntryId,
|
OutlookEntryId = match.OutlookEntryId,
|
||||||
StarfaceId = sc.StarfaceId,
|
StarfaceId = sc.StarfaceId,
|
||||||
LastSyncHash = sc.GetHash()
|
LastSyncHash = sc.GetHash()
|
||||||
});
|
});
|
||||||
|
processedOutlookIds.Add(match.OutlookEntryId);
|
||||||
|
unmappedOutlook.Remove(match);
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
|
Log($" Verknuepft (SF->OL): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Neu -> in Outlook erstellen
|
||||||
var created = _outlookService.CreateContact(sc, profile.OutlookFolderPath);
|
var created = _outlookService.CreateContact(sc, profile.OutlookFolderPath);
|
||||||
if (created != null && !string.IsNullOrEmpty(created.OutlookEntryId))
|
if (created != null && !string.IsNullOrEmpty(created.OutlookEntryId))
|
||||||
{
|
{
|
||||||
_profileManager.AddOrUpdateMapping(new SyncMapping
|
newMappings.Add(new SyncMapping
|
||||||
{
|
{
|
||||||
ProfileId = profile.Id,
|
ProfileId = profile.Id,
|
||||||
OutlookEntryId = created.OutlookEntryId,
|
OutlookEntryId = created.OutlookEntryId,
|
||||||
@@ -197,22 +331,25 @@ namespace StarfaceOutlookSync.Services
|
|||||||
LastSyncHash = sc.GetHash()
|
LastSyncHash = sc.GetHash()
|
||||||
});
|
});
|
||||||
result.Created++;
|
result.Created++;
|
||||||
}
|
Log($" Erstellt (SF->OL): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
result.Errors++;
|
result.Errors++;
|
||||||
result.ErrorMessages.Add($"{sc.DisplayName}: {ex.Message}");
|
result.ErrorMessages.Add($"SF->OL {sc.DisplayName}: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mappings speichern
|
||||||
|
_profileManager.SaveMappings(profile.Id, newMappings);
|
||||||
_profileManager.UpdateLastSync(profile.Id);
|
_profileManager.UpdateLastSync(profile.Id);
|
||||||
_profileManager.SaveMappings(profile.Id, mappings);
|
|
||||||
await starface.LogoutAsync();
|
await starface.LogoutAsync();
|
||||||
Log("Synchronisation abgeschlossen!");
|
|
||||||
|
Log($"Fertig: {result.Created} erstellt, {result.Updated} aktualisiert, {result.Errors} Fehler");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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.12</Version>
|
<Version>0.0.0.15</Version>
|
||||||
<AssemblyVersion>0.0.0.12</AssemblyVersion>
|
<AssemblyVersion>0.0.0.15</AssemblyVersion>
|
||||||
<FileVersion>0.0.0.12</FileVersion>
|
<FileVersion>0.0.0.15</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.12",
|
Text = "Version 0.0.0.15",
|
||||||
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,108 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Drawing.Drawing2D;
|
||||||
|
|
||||||
|
namespace StarfaceOutlookSync.UI
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Generiert das App-Icon programmatisch (Kontakt-Symbol mit Sync-Pfeilen).
|
||||||
|
/// Kein externes ICO-File noetig.
|
||||||
|
/// </summary>
|
||||||
|
public static class AppIcon
|
||||||
|
{
|
||||||
|
private static Icon _icon;
|
||||||
|
|
||||||
|
public static Icon GetIcon()
|
||||||
|
{
|
||||||
|
if (_icon != null) return _icon;
|
||||||
|
_icon = CreateIcon(32);
|
||||||
|
return _icon;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Icon GetSmallIcon()
|
||||||
|
{
|
||||||
|
return CreateIcon(16);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Icon CreateIcon(int size)
|
||||||
|
{
|
||||||
|
using (var bmp = new Bitmap(size, size))
|
||||||
|
using (var g = Graphics.FromImage(bmp))
|
||||||
|
{
|
||||||
|
g.SmoothingMode = SmoothingMode.AntiAlias;
|
||||||
|
g.Clear(Color.Transparent);
|
||||||
|
|
||||||
|
if (size >= 32)
|
||||||
|
DrawIcon32(g);
|
||||||
|
else
|
||||||
|
DrawIcon16(g);
|
||||||
|
|
||||||
|
return Icon.FromHandle(bmp.GetHicon());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawIcon32(Graphics g)
|
||||||
|
{
|
||||||
|
// Hintergrund: abgerundetes Quadrat
|
||||||
|
using (var bgBrush = new SolidBrush(Color.FromArgb(0, 120, 212)))
|
||||||
|
{
|
||||||
|
FillRoundedRect(g, bgBrush, 0, 0, 31, 31, 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Person (Kopf)
|
||||||
|
using (var whiteBrush = new SolidBrush(Color.White))
|
||||||
|
{
|
||||||
|
g.FillEllipse(whiteBrush, 11, 4, 10, 10);
|
||||||
|
// Person (Koerper)
|
||||||
|
g.FillPie(whiteBrush, 6, 14, 20, 18, 180, 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sync-Pfeile unten rechts
|
||||||
|
using (var arrowPen = new Pen(Color.FromArgb(120, 255, 120), 2f))
|
||||||
|
{
|
||||||
|
arrowPen.StartCap = LineCap.Round;
|
||||||
|
arrowPen.EndCap = LineCap.ArrowAnchor;
|
||||||
|
// Pfeil rechts
|
||||||
|
g.DrawArc(arrowPen, 20, 22, 10, 8, 200, 140);
|
||||||
|
arrowPen.Color = Color.FromArgb(255, 200, 80);
|
||||||
|
// Pfeil links
|
||||||
|
g.DrawArc(arrowPen, 20, 22, 10, 8, 20, 140);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void DrawIcon16(Graphics g)
|
||||||
|
{
|
||||||
|
// Hintergrund
|
||||||
|
using (var bgBrush = new SolidBrush(Color.FromArgb(0, 120, 212)))
|
||||||
|
{
|
||||||
|
FillRoundedRect(g, bgBrush, 0, 0, 15, 15, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Person (vereinfacht)
|
||||||
|
using (var whiteBrush = new SolidBrush(Color.White))
|
||||||
|
{
|
||||||
|
g.FillEllipse(whiteBrush, 4, 1, 7, 7);
|
||||||
|
g.FillPie(whiteBrush, 2, 8, 12, 10, 180, 180);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kleiner Sync-Indikator
|
||||||
|
using (var dotBrush = new SolidBrush(Color.FromArgb(120, 255, 120)))
|
||||||
|
{
|
||||||
|
g.FillEllipse(dotBrush, 11, 11, 4, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void FillRoundedRect(Graphics g, Brush brush, int x, int y, int w, int h, int r)
|
||||||
|
{
|
||||||
|
using (var path = new GraphicsPath())
|
||||||
|
{
|
||||||
|
path.AddArc(x, y, r * 2, r * 2, 180, 90);
|
||||||
|
path.AddArc(x + w - r * 2, y, r * 2, r * 2, 270, 90);
|
||||||
|
path.AddArc(x + w - r * 2, y + h - r * 2, r * 2, r * 2, 0, 90);
|
||||||
|
path.AddArc(x, y + h - r * 2, r * 2, r * 2, 90, 90);
|
||||||
|
path.CloseFigure();
|
||||||
|
g.FillPath(brush, path);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -18,7 +18,7 @@ namespace StarfaceOutlookSync.UI
|
|||||||
private NotifyIcon _trayIcon;
|
private NotifyIcon _trayIcon;
|
||||||
private ContextMenuStrip _trayMenu;
|
private ContextMenuStrip _trayMenu;
|
||||||
private ListView _profileList;
|
private ListView _profileList;
|
||||||
private Button _btnNew, _btnEdit, _btnDelete, _btnSync, _btnSettings, _btnInfo;
|
private Button _btnNew, _btnEdit, _btnDelete, _btnSync, _btnReset, _btnSettings, _btnInfo;
|
||||||
private StatusStrip _statusBar;
|
private StatusStrip _statusBar;
|
||||||
private ToolStripStatusLabel _statusLabel;
|
private ToolStripStatusLabel _statusLabel;
|
||||||
private Timer _autoSyncTimer;
|
private Timer _autoSyncTimer;
|
||||||
@@ -62,6 +62,7 @@ namespace StarfaceOutlookSync.UI
|
|||||||
MinimumSize = new Size(500, 350);
|
MinimumSize = new Size(500, 350);
|
||||||
StartPosition = FormStartPosition.CenterScreen;
|
StartPosition = FormStartPosition.CenterScreen;
|
||||||
Font = new Font("Segoe UI", 9);
|
Font = new Font("Segoe UI", 9);
|
||||||
|
Icon = AppIcon.GetIcon();
|
||||||
|
|
||||||
// Profil-Liste
|
// Profil-Liste
|
||||||
_profileList = new ListView
|
_profileList = new ListView
|
||||||
@@ -97,16 +98,19 @@ namespace StarfaceOutlookSync.UI
|
|||||||
_btnDelete = new Button { Text = "Loeschen", Width = 80, Height = 30 };
|
_btnDelete = new Button { Text = "Loeschen", Width = 80, Height = 30 };
|
||||||
_btnDelete.Click += (s, e) => DeleteProfile();
|
_btnDelete.Click += (s, e) => DeleteProfile();
|
||||||
|
|
||||||
_btnSync = new Button { Text = "Jetzt synchronisieren", Width = 150, Height = 30 };
|
_btnSync = new Button { Text = "Synchronisieren", Width = 110, Height = 30 };
|
||||||
_btnSync.Click += async (s, e) => await SyncSelectedProfile();
|
_btnSync.Click += async (s, e) => await SyncSelectedProfile();
|
||||||
|
|
||||||
_btnSettings = new Button { Text = "Einstellungen", Width = 100, Height = 30 };
|
_btnReset = new Button { Text = "Sync Reset", Width = 80, Height = 30 };
|
||||||
|
_btnReset.Click += (s, e) => ResetSync();
|
||||||
|
|
||||||
|
_btnSettings = new Button { Text = "Einstellungen", Width = 95, Height = 30 };
|
||||||
_btnSettings.Click += (s, e) => ShowSettings();
|
_btnSettings.Click += (s, e) => ShowSettings();
|
||||||
|
|
||||||
_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, _btnSettings, _btnInfo });
|
buttonPanel.Controls.AddRange(new Control[] { _btnNew, _btnEdit, _btnDelete, _btnSync, _btnReset, _btnSettings, _btnInfo });
|
||||||
|
|
||||||
// Statusbar
|
// Statusbar
|
||||||
_statusBar = new StatusStrip();
|
_statusBar = new StatusStrip();
|
||||||
@@ -121,10 +125,26 @@ namespace StarfaceOutlookSync.UI
|
|||||||
private void SetupTrayIcon()
|
private void SetupTrayIcon()
|
||||||
{
|
{
|
||||||
_trayMenu = new ContextMenuStrip();
|
_trayMenu = new ContextMenuStrip();
|
||||||
|
|
||||||
|
_trayIcon = new NotifyIcon
|
||||||
|
{
|
||||||
|
Text = "Starface Kontakt-Sync",
|
||||||
|
Icon = AppIcon.GetSmallIcon(),
|
||||||
|
ContextMenuStrip = _trayMenu,
|
||||||
|
Visible = true
|
||||||
|
};
|
||||||
|
|
||||||
|
_trayIcon.DoubleClick += (s, e) => ShowMainWindow();
|
||||||
|
|
||||||
|
UpdateTrayMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateTrayMenu()
|
||||||
|
{
|
||||||
|
_trayMenu.Items.Clear();
|
||||||
_trayMenu.Items.Add("Oeffnen", null, (s, e) => ShowMainWindow());
|
_trayMenu.Items.Add("Oeffnen", null, (s, e) => ShowMainWindow());
|
||||||
_trayMenu.Items.Add("-");
|
_trayMenu.Items.Add("-");
|
||||||
|
|
||||||
// Schnell-Sync fuer jedes Profil
|
|
||||||
var profiles = _profileManager.GetProfiles();
|
var profiles = _profileManager.GetProfiles();
|
||||||
foreach (var p in profiles.Where(p => p.Enabled))
|
foreach (var p in profiles.Where(p => p.Enabled))
|
||||||
{
|
{
|
||||||
@@ -139,16 +159,6 @@ namespace StarfaceOutlookSync.UI
|
|||||||
_trayMenu.Items.Add("-");
|
_trayMenu.Items.Add("-");
|
||||||
|
|
||||||
_trayMenu.Items.Add("Beenden", null, (s, e) => ExitApplication());
|
_trayMenu.Items.Add("Beenden", null, (s, e) => ExitApplication());
|
||||||
|
|
||||||
_trayIcon = new NotifyIcon
|
|
||||||
{
|
|
||||||
Text = "Starface Kontakt-Sync",
|
|
||||||
Icon = SystemIcons.Application, // Placeholder, wird durch eigenes Icon ersetzt
|
|
||||||
ContextMenuStrip = _trayMenu,
|
|
||||||
Visible = true
|
|
||||||
};
|
|
||||||
|
|
||||||
_trayIcon.DoubleClick += (s, e) => ShowMainWindow();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetupAutoSync()
|
private void SetupAutoSync()
|
||||||
@@ -216,7 +226,7 @@ namespace StarfaceOutlookSync.UI
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Tray-Menu aktualisieren
|
// Tray-Menu aktualisieren
|
||||||
SetupTrayIcon();
|
UpdateTrayMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NewProfile()
|
private void NewProfile()
|
||||||
@@ -255,6 +265,36 @@ namespace StarfaceOutlookSync.UI
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ResetSync()
|
||||||
|
{
|
||||||
|
if (_profileList.SelectedItems.Count == 0)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Bitte ein Profil auswaehlen.", "Sync Reset",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var profile = _profileList.SelectedItems[0].Tag as SyncProfile;
|
||||||
|
if (profile == null) return;
|
||||||
|
|
||||||
|
var msg = $"Sync-Zuordnungen fuer '{profile.Name}' zuruecksetzen?\n\n" +
|
||||||
|
"Alle Kontakt-Verknuepfungen werden geloescht.\n" +
|
||||||
|
"Beim naechsten Sync werden die Kontakte neu abgeglichen.\n" +
|
||||||
|
"Es werden keine Kontakte geloescht.";
|
||||||
|
|
||||||
|
if (MessageBox.Show(msg, "Sync Reset",
|
||||||
|
MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
||||||
|
{
|
||||||
|
_profileManager.SaveMappings(profile.Id, new List<SyncMapping>());
|
||||||
|
// LastSync auch zuruecksetzen
|
||||||
|
profile.LastSync = "";
|
||||||
|
_profileManager.UpdateProfile(profile);
|
||||||
|
RefreshProfileList();
|
||||||
|
MessageBox.Show("Sync-Zuordnungen wurden zurueckgesetzt.",
|
||||||
|
"Sync Reset", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private Task SyncSelectedProfile()
|
private Task SyncSelectedProfile()
|
||||||
{
|
{
|
||||||
if (_profileList.SelectedItems.Count == 0)
|
if (_profileList.SelectedItems.Count == 0)
|
||||||
|
|||||||
@@ -41,7 +41,8 @@ namespace StarfaceOutlookSync.UI
|
|||||||
_progressBar = new ProgressBar
|
_progressBar = new ProgressBar
|
||||||
{
|
{
|
||||||
Left = 12, Top = 38, Width = 460, Height = 22,
|
Left = 12, Top = 38, Width = 460, Height = 22,
|
||||||
Style = ProgressBarStyle.Marquee
|
Style = ProgressBarStyle.Blocks,
|
||||||
|
Value = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
_txtLog = new TextBox
|
_txtLog = new TextBox
|
||||||
|
|||||||
Reference in New Issue
Block a user