Compare commits
36 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
b07a3b3a87 | |
|
|
f620e96d23 | |
|
|
e8731a87d4 | |
|
|
53ca4611d1 | |
|
|
df13ddf6b1 | |
|
|
c08a625348 | |
|
|
4484f19d14 | |
|
|
ca17e5d433 | |
|
|
d89e36b962 | |
|
|
3092150d3a | |
|
|
163dc17b49 | |
|
|
b7cc335184 | |
|
|
a19a39b7d2 | |
|
|
6349424007 | |
|
|
7ffaddc77f | |
|
|
9007e2a9b5 | |
|
|
0eadb2274e | |
|
|
a676e064c4 | |
|
|
39ec176b16 | |
|
|
39be854a4a | |
|
|
724beba34a | |
|
|
65d3e911d0 | |
|
|
ab9c16c69a | |
|
|
3e22a40e17 | |
|
|
36aca2c04d | |
|
|
4f56f28ccb | |
|
|
2b9ad5bf3c | |
|
|
8a316600b5 | |
|
|
0f61b4cd31 | |
|
|
b9f5a26b27 | |
|
|
4359d3ad1a | |
|
|
39b30f9a80 | |
|
|
f0bcfdfd30 | |
|
|
650d0def51 | |
|
|
f57518a1d5 | |
|
|
1be0a94b51 |
26
README.md
26
README.md
|
|
@ -42,6 +42,32 @@ Windows-Anwendung zur bidirektionalen Synchronisation von Kontakten zwischen Mic
|
||||||
5. Starface-Adressbuch und Outlook-Kontaktordner waehlen
|
5. Starface-Adressbuch und Outlook-Kontaktordner waehlen
|
||||||
6. Speichern und "Jetzt synchronisieren"
|
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
|
### Deinstallation
|
||||||
|
|
||||||
Ueber Windows Einstellungen -> Apps oder die Systemsteuerung.
|
Ueber Windows Einstellungen -> Apps oder die Systemsteuerung.
|
||||||
|
|
|
||||||
|
|
@ -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.10"
|
#define MyAppVersion "0.0.0.23"
|
||||||
#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"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Microsoft.Win32;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace StarfaceOutlookSync.Models
|
namespace StarfaceOutlookSync.Models
|
||||||
|
|
@ -7,6 +8,8 @@ namespace StarfaceOutlookSync.Models
|
||||||
public class UserSettings
|
public class UserSettings
|
||||||
{
|
{
|
||||||
public bool StartMinimized { get; set; } = false;
|
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(
|
private static readonly string SettingsFile = Path.Combine(
|
||||||
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
|
@ -32,6 +35,86 @@ namespace StarfaceOutlookSync.Models
|
||||||
File.WriteAllText(SettingsFile, JsonConvert.SerializeObject(this, Formatting.Indented));
|
File.WriteAllText(SettingsFile, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||||
}
|
}
|
||||||
catch { }
|
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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -394,29 +394,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)
|
private UnifiedContact MapFromOutlook(dynamic ci)
|
||||||
{
|
{
|
||||||
return new UnifiedContact
|
return new UnifiedContact
|
||||||
{
|
{
|
||||||
OutlookEntryId = (string)(ci.EntryID ?? ""),
|
OutlookEntryId = SafeGet(ci, "EntryID"),
|
||||||
FirstName = (string)(ci.FirstName ?? ""),
|
FirstName = SafeGet(ci, "FirstName"),
|
||||||
LastName = (string)(ci.LastName ?? ""),
|
LastName = SafeGet(ci, "LastName"),
|
||||||
Company = (string)(ci.CompanyName ?? ""),
|
Company = SafeGet(ci, "CompanyName"),
|
||||||
JobTitle = (string)(ci.JobTitle ?? ""),
|
JobTitle = SafeGet(ci, "JobTitle"),
|
||||||
Email = (string)(ci.Email1Address ?? ""),
|
Email = SafeGet(ci, "Email1Address"),
|
||||||
EmailSecondary = (string)(ci.Email2Address ?? ""),
|
EmailSecondary = SafeGet(ci, "Email2Address"),
|
||||||
PhoneWork = (string)(ci.BusinessTelephoneNumber ?? ""),
|
PhoneWork = SafeGet(ci, "BusinessTelephoneNumber"),
|
||||||
PhoneMobile = (string)(ci.MobileTelephoneNumber ?? ""),
|
PhoneMobile = SafeGet(ci, "MobileTelephoneNumber"),
|
||||||
PhoneHome = (string)(ci.HomeTelephoneNumber ?? ""),
|
PhoneHome = SafeGet(ci, "HomeTelephoneNumber"),
|
||||||
Fax = (string)(ci.BusinessFaxNumber ?? ""),
|
Fax = SafeGet(ci, "BusinessFaxNumber"),
|
||||||
Street = (string)(ci.BusinessAddressStreet ?? ""),
|
Street = SafeGet(ci, "BusinessAddressStreet"),
|
||||||
City = (string)(ci.BusinessAddressCity ?? ""),
|
City = SafeGet(ci, "BusinessAddressCity"),
|
||||||
PostalCode = (string)(ci.BusinessAddressPostalCode ?? ""),
|
PostalCode = SafeGet(ci, "BusinessAddressPostalCode"),
|
||||||
State = (string)(ci.BusinessAddressState ?? ""),
|
State = SafeGet(ci, "BusinessAddressState"),
|
||||||
Country = (string)(ci.BusinessAddressCountry ?? ""),
|
Country = SafeGet(ci, "BusinessAddressCountry"),
|
||||||
Website = (string)(ci.WebPage ?? ""),
|
Website = SafeGet(ci, "WebPage"),
|
||||||
Notes = (string)(ci.Body ?? ""),
|
Notes = SafeGet(ci, "Body"),
|
||||||
Salutation = (string)(ci.Title ?? ""),
|
Salutation = SafeGet(ci, "Title"),
|
||||||
Birthday = GetBirthdayString(ci)
|
Birthday = GetBirthdayString(ci)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -425,8 +436,9 @@ namespace StarfaceOutlookSync.Services
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DateTime bday = ci.Birthday;
|
object val = ci.GetType().InvokeMember("Birthday",
|
||||||
if (bday.Year > 1900 && bday != DateTime.MinValue)
|
System.Reflection.BindingFlags.GetProperty, null, ci, null);
|
||||||
|
if (val is DateTime bday && bday.Year > 1900 && bday != DateTime.MinValue)
|
||||||
return bday.ToString("yyyy-MM-dd");
|
return bday.ToString("yyyy-MM-dd");
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
@ -115,43 +116,63 @@ namespace StarfaceOutlookSync.Services
|
||||||
{
|
{
|
||||||
var books = new List<StarfaceAddressBook>();
|
var books = new List<StarfaceAddressBook>();
|
||||||
|
|
||||||
books.Add(new StarfaceAddressBook
|
// Alle Tags laden - die Starface nutzt Tags als Adressbuch-Zuordnung
|
||||||
{
|
var allTags = new JArray();
|
||||||
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
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var resp = await _http.GetAsync($"{_baseUrl}/contacts/tags");
|
var resp = await _http.GetAsync($"{_baseUrl}/contacts/tags");
|
||||||
if (resp.IsSuccessStatusCode)
|
if (resp.IsSuccessStatusCode)
|
||||||
{
|
{
|
||||||
var tags = JArray.Parse(await resp.Content.ReadAsStringAsync());
|
allTags = JArray.Parse(await resp.Content.ReadAsStringAsync());
|
||||||
foreach (var tag in tags)
|
OnDebug?.Invoke($"Gefundene Tags: {allTags.Count}");
|
||||||
{
|
foreach (var t in allTags)
|
||||||
books.Add(new StarfaceAddressBook
|
OnDebug?.Invoke($" Tag: {t["name"]} (id: {t["id"]}, alias: {t["alias"]}, owner: {t["owner"]})");
|
||||||
{
|
|
||||||
Type = "tag",
|
|
||||||
TagId = tag["id"]?.ToString() ?? "",
|
|
||||||
Name = $"Tag: {tag["name"]}"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch { }
|
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 = tagName
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return books;
|
return books;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -209,15 +230,34 @@ namespace StarfaceOutlookSync.Services
|
||||||
|
|
||||||
if (array.Count == 0) break;
|
if (array.Count == 0) break;
|
||||||
|
|
||||||
// Ersten Kontakt als Debug-Info loggen
|
OnDebug?.Invoke($"Seite {page}: {array.Count} Kontakte in Liste");
|
||||||
if (firstPage && array.Count > 0)
|
|
||||||
{
|
|
||||||
OnDebug?.Invoke($"Starface API Rohdaten (1. Kontakt):\n{array[0].ToString(Formatting.Indented)}");
|
|
||||||
firstPage = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Die Listen-API gibt nur Summary zurueck.
|
||||||
|
// Jeden Kontakt einzeln abrufen fuer alle Felder.
|
||||||
foreach (var item in array)
|
foreach (var item in array)
|
||||||
contacts.Add(MapFromStarface(item));
|
{
|
||||||
|
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)}");
|
||||||
|
firstPage = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
contacts.Add(MapFromStarface(detailObj));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
|
||||||
if (array.Count < pageSize) break;
|
if (array.Count < pageSize) break;
|
||||||
page++;
|
page++;
|
||||||
|
|
@ -229,15 +269,34 @@ namespace StarfaceOutlookSync.Services
|
||||||
public async Task<UnifiedContact> CreateContactAsync(UnifiedContact contact, StarfaceAddressBook book)
|
public async Task<UnifiedContact> CreateContactAsync(UnifiedContact contact, StarfaceAddressBook book)
|
||||||
{
|
{
|
||||||
var sfContact = MapToStarface(contact);
|
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 = "";
|
var query = "";
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -245,12 +304,27 @@ namespace StarfaceOutlookSync.Services
|
||||||
{
|
{
|
||||||
var sfContact = MapToStarface(contact);
|
var sfContact = MapToStarface(contact);
|
||||||
sfContact["id"] = contactId;
|
sfContact["id"] = contactId;
|
||||||
|
|
||||||
|
// Tag beibehalten
|
||||||
|
if (!string.IsNullOrEmpty(book.TagId))
|
||||||
|
{
|
||||||
|
sfContact["tags"] = new JArray { new JObject { ["id"] = book.TagId } };
|
||||||
|
}
|
||||||
|
|
||||||
var query = "";
|
var query = "";
|
||||||
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 content = new StringContent(body, Encoding.UTF8, "application/json");
|
||||||
var resp = await _http.PutAsync($"{_baseUrl}/contacts/{contactId}{query}", content);
|
var resp = await _http.PutAsync($"{_baseUrl}/contacts/{contactId}{query}", content);
|
||||||
|
|
||||||
|
if (!resp.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
var respBody = await resp.Content.ReadAsStringAsync();
|
||||||
|
OnDebug?.Invoke($"PUT /contacts/{contactId} fehlgeschlagen: {(int)resp.StatusCode}\n{respBody}");
|
||||||
|
}
|
||||||
|
|
||||||
return resp.IsSuccessStatusCode;
|
return resp.IsSuccessStatusCode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -265,7 +339,10 @@ namespace StarfaceOutlookSync.Services
|
||||||
var contact = new UnifiedContact();
|
var contact = new UnifiedContact();
|
||||||
contact.StarfaceId = item["id"]?.ToString() ?? "";
|
contact.StarfaceId = item["id"]?.ToString() ?? "";
|
||||||
|
|
||||||
var attrs = new Dictionary<string, string>();
|
// Attribute per "name"-Feld mappen (zuverlaessiger als displayKey,
|
||||||
|
// weil viele Felder USER_DEFINED als displayKey haben)
|
||||||
|
var byName = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
|
var byDisplayKey = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
||||||
var blocks = item["blocks"] as JArray;
|
var blocks = item["blocks"] as JArray;
|
||||||
if (blocks != null)
|
if (blocks != null)
|
||||||
{
|
{
|
||||||
|
|
@ -275,79 +352,123 @@ namespace StarfaceOutlookSync.Services
|
||||||
if (blockAttrs == null) continue;
|
if (blockAttrs == null) continue;
|
||||||
foreach (var attr in blockAttrs)
|
foreach (var attr in blockAttrs)
|
||||||
{
|
{
|
||||||
var key = attr["displayKey"]?.ToString() ?? "";
|
var name = attr["name"]?.ToString() ?? "";
|
||||||
|
var displayKey = attr["displayKey"]?.ToString() ?? "";
|
||||||
var val = attr["value"]?.ToString() ?? "";
|
var val = attr["value"]?.ToString() ?? "";
|
||||||
if (!string.IsNullOrEmpty(val))
|
if (!string.IsNullOrEmpty(val))
|
||||||
attrs[key] = val;
|
{
|
||||||
|
if (!string.IsNullOrEmpty(name))
|
||||||
|
byName[name] = val;
|
||||||
|
// displayKey nur als Fallback (viele sind USER_DEFINED)
|
||||||
|
if (!string.IsNullOrEmpty(displayKey) && displayKey != "USER_DEFINED")
|
||||||
|
byDisplayKey[displayKey] = val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
contact.FirstName = attrs.GetValueOrDefault("NAME", "");
|
// Primaer nach name-Feld mappen, Fallback auf displayKey
|
||||||
contact.LastName = attrs.GetValueOrDefault("SURNAME", "");
|
string Get(string name, string displayKey = null)
|
||||||
contact.Company = attrs.GetValueOrDefault("COMPANY", "");
|
{
|
||||||
contact.JobTitle = attrs.GetValueOrDefault("JOB_TITLE", "");
|
if (byName.TryGetValue(name, out var v)) return v;
|
||||||
contact.Email = attrs.GetValueOrDefault("EMAIL", "");
|
if (displayKey != null && byDisplayKey.TryGetValue(displayKey, out v)) return v;
|
||||||
contact.PhoneWork = attrs.GetValueOrDefault("OFFICE_PHONE_NUMBER", "");
|
return "";
|
||||||
contact.PhoneMobile = attrs.GetValueOrDefault("MOBILE_PHONE_NUMBER", "");
|
}
|
||||||
contact.PhoneHome = attrs.GetValueOrDefault("PRIVATE_PHONE_NUMBER", "");
|
|
||||||
contact.Fax = attrs.GetValueOrDefault("FAX_NUMBER", "");
|
contact.FirstName = Get("firstname", "NAME");
|
||||||
contact.Street = attrs.GetValueOrDefault("STREET", "");
|
contact.LastName = Get("familyname", "SURNAME");
|
||||||
contact.City = attrs.GetValueOrDefault("CITY", "");
|
contact.Company = Get("company", "COMPANY");
|
||||||
contact.PostalCode = attrs.GetValueOrDefault("POSTAL_CODE", "");
|
contact.JobTitle = Get("jobtitle", "JOB_TITLE");
|
||||||
contact.State = attrs.GetValueOrDefault("STATE", "");
|
contact.Email = Get("e-mail", "EMAIL");
|
||||||
contact.Country = attrs.GetValueOrDefault("COUNTRY", "");
|
contact.PhoneWork = Get("phone", "PHONE_NUMBER");
|
||||||
contact.Website = attrs.GetValueOrDefault("URL", "");
|
contact.PhoneMobile = Get("mobile", "MOBILE_PHONE_NUMBER");
|
||||||
contact.Notes = attrs.GetValueOrDefault("NOTE", "");
|
contact.PhoneHome = Get("homephone", "PRIVATE_PHONE_NUMBER");
|
||||||
contact.Salutation = attrs.GetValueOrDefault("SALUTATION", "");
|
contact.Fax = Get("fax", "FAX_NUMBER");
|
||||||
contact.Title = attrs.GetValueOrDefault("TITLE", "");
|
contact.Street = Get("street", "STREET");
|
||||||
contact.Birthday = attrs.GetValueOrDefault("BIRTHDAY", "");
|
contact.City = Get("city", "CITY");
|
||||||
|
contact.PostalCode = Get("postcode", "POSTAL_CODE");
|
||||||
|
contact.State = Get("state", "STATE");
|
||||||
|
contact.Country = Get("country", "COUNTRY");
|
||||||
|
contact.Website = Get("url", "URL");
|
||||||
|
contact.Notes = Get("comment", "NOTE");
|
||||||
|
contact.Salutation = Get("salutation", "SALUTATION");
|
||||||
|
contact.Title = Get("title", "TITLE");
|
||||||
|
contact.Birthday = Get("birthday", "BIRTHDAY");
|
||||||
|
|
||||||
return contact;
|
return contact;
|
||||||
}
|
}
|
||||||
|
|
||||||
private JObject MapToStarface(UnifiedContact contact)
|
private JObject MapToStarface(UnifiedContact contact)
|
||||||
{
|
{
|
||||||
var attrs = new JArray();
|
JArray MakeAttrs(params (string displayKey, string name, string value)[] fields)
|
||||||
|
|
||||||
void AddAttr(string displayKey, string name, string value)
|
|
||||||
{
|
{
|
||||||
if (!string.IsNullOrEmpty(value))
|
var arr = new JArray();
|
||||||
attrs.Add(new JObject { ["displayKey"] = displayKey, ["name"] = name, ["value"] = value });
|
foreach (var (dk, n, v) in fields)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(v))
|
||||||
|
arr.Add(new JObject { ["displayKey"] = dk, ["name"] = n, ["value"] = v });
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
AddAttr("NAME", "firstName", contact.FirstName);
|
// Block-Struktur wie von der Starface erwartet
|
||||||
AddAttr("SURNAME", "lastName", contact.LastName);
|
var contactBlock = MakeAttrs(
|
||||||
AddAttr("COMPANY", "company", contact.Company);
|
("NAME", "firstname", contact.FirstName),
|
||||||
AddAttr("JOB_TITLE", "jobTitle", contact.JobTitle);
|
("SURNAME", "familyname", contact.LastName),
|
||||||
AddAttr("EMAIL", "email", contact.Email);
|
("COMPANY", "company", contact.Company)
|
||||||
AddAttr("OFFICE_PHONE_NUMBER", "businessPhone", contact.PhoneWork);
|
);
|
||||||
AddAttr("MOBILE_PHONE_NUMBER", "mobilePhone", contact.PhoneMobile);
|
|
||||||
AddAttr("PRIVATE_PHONE_NUMBER", "homePhone", contact.PhoneHome);
|
var addressBlock = MakeAttrs(
|
||||||
AddAttr("FAX_NUMBER", "fax", contact.Fax);
|
("USER_DEFINED", "street", contact.Street),
|
||||||
AddAttr("STREET", "street", contact.Street);
|
("POSTAL_CODE", "postcode", contact.PostalCode),
|
||||||
AddAttr("CITY", "city", contact.City);
|
("USER_DEFINED", "city", contact.City),
|
||||||
AddAttr("POSTAL_CODE", "postalCode", contact.PostalCode);
|
("USER_DEFINED", "state", contact.State),
|
||||||
AddAttr("STATE", "state", contact.State);
|
("USER_DEFINED", "country", contact.Country)
|
||||||
AddAttr("COUNTRY", "country", contact.Country);
|
);
|
||||||
AddAttr("URL", "website", contact.Website);
|
|
||||||
AddAttr("NOTE", "notes", contact.Notes);
|
var phoneBlock = MakeAttrs(
|
||||||
AddAttr("SALUTATION", "salutation", contact.Salutation);
|
("PHONE_NUMBER", "phone", contact.PhoneWork),
|
||||||
AddAttr("TITLE", "title", contact.Title);
|
("PRIVATE_PHONE_NUMBER", "homephone", contact.PhoneHome),
|
||||||
AddAttr("BIRTHDAY", "birthday", contact.Birthday);
|
("MOBILE_PHONE_NUMBER", "mobile", contact.PhoneMobile),
|
||||||
|
("FAX_NUMBER", "fax", contact.Fax)
|
||||||
|
);
|
||||||
|
|
||||||
|
var emailBlock = MakeAttrs(
|
||||||
|
("EMAIL", "e-mail", contact.Email),
|
||||||
|
("URL", "url", contact.Website),
|
||||||
|
("USER_DEFINED", "comment", contact.Notes)
|
||||||
|
);
|
||||||
|
|
||||||
|
var blocks = new JArray();
|
||||||
|
blocks.Add(new JObject
|
||||||
|
{
|
||||||
|
["name"] = "contact",
|
||||||
|
["resourceKey"] = "de.vertico.starface.addressbook.block.label_contact",
|
||||||
|
["attributes"] = contactBlock
|
||||||
|
});
|
||||||
|
blocks.Add(new JObject
|
||||||
|
{
|
||||||
|
["name"] = "address",
|
||||||
|
["resourceKey"] = "de.vertico.starface.addressbook.block.label_address",
|
||||||
|
["attributes"] = addressBlock
|
||||||
|
});
|
||||||
|
blocks.Add(new JObject
|
||||||
|
{
|
||||||
|
["name"] = "telephone",
|
||||||
|
["resourceKey"] = "de.vertico.starface.addressbook.block.label_telephone",
|
||||||
|
["attributes"] = phoneBlock
|
||||||
|
});
|
||||||
|
blocks.Add(new JObject
|
||||||
|
{
|
||||||
|
["name"] = "email",
|
||||||
|
["resourceKey"] = "de.vertico.starface.addressbook.block.label_email",
|
||||||
|
["attributes"] = emailBlock
|
||||||
|
});
|
||||||
|
|
||||||
return new JObject
|
return new JObject
|
||||||
{
|
{
|
||||||
["id"] = contact.StarfaceId ?? "",
|
["id"] = contact.StarfaceId ?? "",
|
||||||
["blocks"] = new JArray
|
["blocks"] = blocks
|
||||||
{
|
|
||||||
new JObject
|
|
||||||
{
|
|
||||||
["name"] = "contact",
|
|
||||||
["resourceKey"] = "contact",
|
|
||||||
["attributes"] = attrs
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,30 +15,103 @@ 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.
|
||||||
|
/// 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)
|
private static UnifiedContact FindMatch(UnifiedContact contact, List<UnifiedContact> candidates)
|
||||||
{
|
{
|
||||||
// Erst E-Mail-Match
|
if (candidates == null || candidates.Count == 0) return null;
|
||||||
if (!string.IsNullOrEmpty(contact.Email))
|
|
||||||
{
|
|
||||||
var byEmail = candidates.FirstOrDefault(c =>
|
|
||||||
!string.IsNullOrEmpty(c.Email) &&
|
|
||||||
c.Email.Equals(contact.Email, StringComparison.OrdinalIgnoreCase));
|
|
||||||
if (byEmail != null) return byEmail;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dann Name-Match
|
foreach (var c in candidates)
|
||||||
if (!string.IsNullOrEmpty(contact.FirstName) || !string.IsNullOrEmpty(contact.LastName))
|
|
||||||
{
|
{
|
||||||
var byName = candidates.FirstOrDefault(c =>
|
if (IsMatch(contact, c))
|
||||||
c.FirstName.Equals(contact.FirstName, StringComparison.OrdinalIgnoreCase) &&
|
return c;
|
||||||
c.LastName.Equals(contact.LastName, StringComparison.OrdinalIgnoreCase) &&
|
|
||||||
(!string.IsNullOrEmpty(c.FirstName) || !string.IsNullOrEmpty(c.LastName)));
|
|
||||||
if (byName != null) return byName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsMatch(UnifiedContact a, UnifiedContact b)
|
||||||
|
{
|
||||||
|
// Mindestens ein identifizierendes Feld muss vorhanden sein
|
||||||
|
bool hasName = !string.IsNullOrEmpty(a.FirstName) || !string.IsNullOrEmpty(a.LastName);
|
||||||
|
bool hasEmail = !string.IsNullOrEmpty(a.Email);
|
||||||
|
bool hasPhone = !string.IsNullOrEmpty(a.PhoneWork) || !string.IsNullOrEmpty(a.PhoneMobile);
|
||||||
|
|
||||||
|
if (!hasName && !hasEmail && !hasPhone) return false;
|
||||||
|
|
||||||
|
// E-Mail: wenn auf beiden Seiten vorhanden, muss sie gleich sein
|
||||||
|
// Wenn nur auf einer Seite vorhanden -> kein Match
|
||||||
|
if (!FieldsCompatible(a.Email, b.Email)) return false;
|
||||||
|
|
||||||
|
// Name: wenn auf einer Seite vorhanden, muss er gleich sein
|
||||||
|
if (!FieldsCompatible(a.FirstName, b.FirstName)) return false;
|
||||||
|
if (!FieldsCompatible(a.LastName, b.LastName)) return false;
|
||||||
|
|
||||||
|
// Firma: wenn auf einer Seite vorhanden, muss sie gleich sein
|
||||||
|
// Leere Firma vs. gefuellte Firma = verschiedene Kontakte
|
||||||
|
if (!FieldsCompatible(a.Company, b.Company)) return false;
|
||||||
|
|
||||||
|
// Telefon/Fax: wenn auf einer Seite vorhanden, muss es gleich sein
|
||||||
|
if (!PhoneFieldsCompatible(a.PhoneWork, b.PhoneWork)) return false;
|
||||||
|
if (!PhoneFieldsCompatible(a.PhoneMobile, b.PhoneMobile)) return false;
|
||||||
|
if (!PhoneFieldsCompatible(a.PhoneHome, b.PhoneHome)) return false;
|
||||||
|
if (!PhoneFieldsCompatible(a.Fax, b.Fax)) return false;
|
||||||
|
|
||||||
|
// Mindestens ein starkes Match muss vorhanden sein
|
||||||
|
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)
|
||||||
|
&& (!string.IsNullOrEmpty(a.FirstName) || !string.IsNullOrEmpty(a.LastName));
|
||||||
|
bool phoneMatch = (!string.IsNullOrEmpty(a.PhoneWork) && !string.IsNullOrEmpty(b.PhoneWork)
|
||||||
|
&& NormalizePhone(a.PhoneWork) == NormalizePhone(b.PhoneWork))
|
||||||
|
|| (!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);
|
||||||
|
|
||||||
|
// Email oder Name reicht. Telefon/Fax nur mit Firma zusammen.
|
||||||
|
return emailMatch || nameMatch || (phoneMatch && companyMatch) || (companyMatch && phoneMatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Prueft ob zwei Felder kompatibel sind.
|
||||||
|
/// Beide leer = kompatibel. Beide gleich = kompatibel.
|
||||||
|
/// Eins leer, eins gefuellt = NICHT kompatibel (verschiedene Kontakte).
|
||||||
|
/// </summary>
|
||||||
|
private static bool FieldsCompatible(string a, string b)
|
||||||
|
{
|
||||||
|
bool aEmpty = string.IsNullOrEmpty(a);
|
||||||
|
bool bEmpty = string.IsNullOrEmpty(b);
|
||||||
|
|
||||||
|
if (aEmpty && bEmpty) return true;
|
||||||
|
if (aEmpty != bEmpty) return false; // Einer leer, anderer nicht
|
||||||
|
return a.Equals(b, StringComparison.OrdinalIgnoreCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool PhoneFieldsCompatible(string a, string b)
|
||||||
|
{
|
||||||
|
bool aEmpty = string.IsNullOrEmpty(a);
|
||||||
|
bool bEmpty = string.IsNullOrEmpty(b);
|
||||||
|
|
||||||
|
if (aEmpty && bEmpty) return true;
|
||||||
|
if (aEmpty != bEmpty) return false;
|
||||||
|
return NormalizePhone(a) == NormalizePhone(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
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 +122,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 +134,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,144 +143,290 @@ 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)
|
||||||
|
{
|
||||||
|
if (!string.IsNullOrEmpty(m.OutlookEntryId))
|
||||||
|
mappingByOutlook[m.OutlookEntryId] = m;
|
||||||
|
if (!string.IsNullOrEmpty(m.StarfaceId))
|
||||||
|
mappingByStarface[m.StarfaceId] = m;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
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))
|
||||||
{
|
{
|
||||||
var hash = oc.GetHash();
|
result.Updated++;
|
||||||
if (hash != existing.LastSyncHash)
|
Log($" Geloescht (OL->SF): {sc.DisplayName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
newMappings.Add(mapping);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (oc != null && sc == null)
|
||||||
|
{
|
||||||
|
// Starface-Kontakt nicht gefunden.
|
||||||
|
// Kann passieren wenn der Kontakt einem anderen Adressbuch gehoert.
|
||||||
|
// NICHT loeschen, nur Mapping entfernen - wird in Phase 2/3 neu verknuepft
|
||||||
|
Log($" Starface-Kontakt nicht in Liste (anderes Adressbuch?): {oc.DisplayName}");
|
||||||
|
// Mapping verwerfen, Outlook-Kontakt als unverarbeitet belassen
|
||||||
|
// damit er in Phase 2 neu zugeordnet oder erstellt werden kann
|
||||||
|
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))
|
||||||
{
|
{
|
||||||
if (await starface.UpdateContactAsync(existing.StarfaceId, oc, profile.StarfaceAddressBook))
|
mapping.LastSyncHash = olHash;
|
||||||
{
|
result.Updated++;
|
||||||
existing.LastSyncHash = hash;
|
Log($" Konflikt (OL gewinnt): {oc.DisplayName}");
|
||||||
result.Updated++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var match = FindMatch(oc, starfaceContacts);
|
if (_outlookService.UpdateContact(mapping.OutlookEntryId, sc))
|
||||||
if (match != null && !string.IsNullOrEmpty(match.StarfaceId))
|
|
||||||
{
|
{
|
||||||
if (await starface.UpdateContactAsync(match.StarfaceId, oc, profile.StarfaceAddressBook))
|
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))
|
||||||
|
{
|
||||||
|
newMappings.Add(new SyncMapping
|
||||||
{
|
{
|
||||||
_profileManager.AddOrUpdateMapping(new SyncMapping
|
ProfileId = profile.Id,
|
||||||
{
|
OutlookEntryId = oc.OutlookEntryId,
|
||||||
ProfileId = profile.Id,
|
StarfaceId = match.StarfaceId,
|
||||||
OutlookEntryId = oc.OutlookEntryId,
|
LastSyncHash = oc.GetHash()
|
||||||
StarfaceId = match.StarfaceId,
|
});
|
||||||
LastSyncHash = oc.GetHash()
|
processedStarfaceIds.Add(match.StarfaceId);
|
||||||
});
|
unmappedStarface.Remove(match);
|
||||||
result.Updated++;
|
result.Updated++;
|
||||||
}
|
Log($" Verknuepft (OL->SF): {oc.DisplayName}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Neu -> in Starface erstellen
|
||||||
|
Log($" Erstelle in Starface: {oc.DisplayName}");
|
||||||
|
var created = await starface.CreateContactAsync(oc, profile.StarfaceAddressBook);
|
||||||
|
if (created != null && !string.IsNullOrEmpty(created.StarfaceId))
|
||||||
|
{
|
||||||
|
newMappings.Add(new SyncMapping
|
||||||
|
{
|
||||||
|
ProfileId = profile.Id,
|
||||||
|
OutlookEntryId = oc.OutlookEntryId,
|
||||||
|
StarfaceId = created.StarfaceId,
|
||||||
|
LastSyncHash = oc.GetHash()
|
||||||
|
});
|
||||||
|
result.Created++;
|
||||||
|
Log($" Erstellt (OL->SF): {oc.DisplayName}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var created = await starface.CreateContactAsync(oc, profile.StarfaceAddressBook);
|
Log($" FEHLER: Kontakt konnte nicht erstellt werden: {oc.DisplayName}");
|
||||||
if (created != null && !string.IsNullOrEmpty(created.StarfaceId))
|
result.Errors++;
|
||||||
{
|
|
||||||
_profileManager.AddOrUpdateMapping(new SyncMapping
|
|
||||||
{
|
|
||||||
ProfileId = profile.Id,
|
|
||||||
OutlookEntryId = oc.OutlookEntryId,
|
|
||||||
StarfaceId = created.StarfaceId,
|
|
||||||
LastSyncHash = oc.GetHash()
|
|
||||||
});
|
|
||||||
result.Created++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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();
|
// Existiert schon -> verknuepfen und updaten
|
||||||
if (hash != existing.LastSyncHash)
|
if (_outlookService.UpdateContact(match.OutlookEntryId, sc))
|
||||||
{
|
{
|
||||||
if (_outlookService.UpdateContact(existing.OutlookEntryId, sc))
|
newMappings.Add(new SyncMapping
|
||||||
{
|
{
|
||||||
existing.LastSyncHash = hash;
|
ProfileId = profile.Id,
|
||||||
result.Updated++;
|
OutlookEntryId = match.OutlookEntryId,
|
||||||
}
|
StarfaceId = sc.StarfaceId,
|
||||||
|
LastSyncHash = sc.GetHash()
|
||||||
|
});
|
||||||
|
processedOutlookIds.Add(match.OutlookEntryId);
|
||||||
|
unmappedOutlook.Remove(match);
|
||||||
|
result.Updated++;
|
||||||
|
Log($" Verknuepft (SF->OL): {sc.DisplayName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var match = FindMatch(sc, outlookContacts);
|
// Neu -> in Outlook erstellen
|
||||||
if (match != null && !string.IsNullOrEmpty(match.OutlookEntryId))
|
var created = _outlookService.CreateContact(sc, profile.OutlookFolderPath);
|
||||||
|
if (created != null && !string.IsNullOrEmpty(created.OutlookEntryId))
|
||||||
{
|
{
|
||||||
if (_outlookService.UpdateContact(match.OutlookEntryId, sc))
|
newMappings.Add(new SyncMapping
|
||||||
{
|
{
|
||||||
_profileManager.AddOrUpdateMapping(new SyncMapping
|
ProfileId = profile.Id,
|
||||||
{
|
OutlookEntryId = created.OutlookEntryId,
|
||||||
ProfileId = profile.Id,
|
StarfaceId = sc.StarfaceId,
|
||||||
OutlookEntryId = match.OutlookEntryId,
|
LastSyncHash = sc.GetHash()
|
||||||
StarfaceId = sc.StarfaceId,
|
});
|
||||||
LastSyncHash = sc.GetHash()
|
result.Created++;
|
||||||
});
|
Log($" Erstellt (SF->OL): {sc.DisplayName}");
|
||||||
result.Updated++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var created = _outlookService.CreateContact(sc, profile.OutlookFolderPath);
|
|
||||||
if (created != null && !string.IsNullOrEmpty(created.OutlookEntryId))
|
|
||||||
{
|
|
||||||
_profileManager.AddOrUpdateMapping(new SyncMapping
|
|
||||||
{
|
|
||||||
ProfileId = profile.Id,
|
|
||||||
OutlookEntryId = created.OutlookEntryId,
|
|
||||||
StarfaceId = sc.StarfaceId,
|
|
||||||
LastSyncHash = sc.GetHash()
|
|
||||||
});
|
|
||||||
result.Created++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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.10</Version>
|
<Version>0.0.0.23</Version>
|
||||||
<AssemblyVersion>0.0.0.10</AssemblyVersion>
|
<AssemblyVersion>0.0.0.23</AssemblyVersion>
|
||||||
<FileVersion>0.0.0.10</FileVersion>
|
<FileVersion>0.0.0.23</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.10",
|
Text = "Version 0.0.0.23",
|
||||||
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,10 +18,11 @@ 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;
|
||||||
|
private volatile bool _syncRunning = false;
|
||||||
|
|
||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
|
|
@ -30,14 +31,31 @@ namespace StarfaceOutlookSync.UI
|
||||||
SetupAutoSync();
|
SetupAutoSync();
|
||||||
RefreshProfileList();
|
RefreshProfileList();
|
||||||
|
|
||||||
// Minimiert starten falls in Einstellungen aktiviert
|
// Einstellungen laden und anwenden
|
||||||
var settings = UserSettings.Load();
|
var settings = UserSettings.Load();
|
||||||
|
settings.ApplyOutlookSecuritySetting();
|
||||||
|
|
||||||
if (settings.StartMinimized)
|
if (settings.StartMinimized)
|
||||||
{
|
{
|
||||||
WindowState = FormWindowState.Minimized;
|
WindowState = FormWindowState.Minimized;
|
||||||
ShowInTaskbar = false;
|
ShowInTaskbar = false;
|
||||||
Visible = 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)
|
protected override void SetVisibleCore(bool value)
|
||||||
|
|
@ -58,10 +76,11 @@ namespace StarfaceOutlookSync.UI
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
Text = "Starface Kontakt-Sync";
|
Text = "Starface Kontakt-Sync";
|
||||||
Size = new Size(620, 450);
|
Size = new Size(830, 450);
|
||||||
MinimumSize = new Size(500, 350);
|
MinimumSize = new Size(830, 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 +116,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 +143,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))
|
||||||
{
|
{
|
||||||
|
|
@ -138,17 +176,8 @@ namespace StarfaceOutlookSync.UI
|
||||||
if (profiles.Any(p => p.Enabled))
|
if (profiles.Any(p => p.Enabled))
|
||||||
_trayMenu.Items.Add("-");
|
_trayMenu.Items.Add("-");
|
||||||
|
|
||||||
|
_trayMenu.Items.Add("Ueber", null, (s, e) => ShowAbout());
|
||||||
_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 +245,7 @@ namespace StarfaceOutlookSync.UI
|
||||||
}
|
}
|
||||||
|
|
||||||
// Tray-Menu aktualisieren
|
// Tray-Menu aktualisieren
|
||||||
SetupTrayIcon();
|
UpdateTrayMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void NewProfile()
|
private void NewProfile()
|
||||||
|
|
@ -255,6 +284,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)
|
||||||
|
|
@ -278,6 +337,13 @@ namespace StarfaceOutlookSync.UI
|
||||||
|
|
||||||
private async Task RunSync(SyncProfile profile)
|
private async Task RunSync(SyncProfile profile)
|
||||||
{
|
{
|
||||||
|
if (_syncRunning)
|
||||||
|
{
|
||||||
|
SetStatus("Sync laeuft bereits, bitte warten...");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_syncRunning = true;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
SetStatus($"Synchronisiere '{profile.Name}'...");
|
SetStatus($"Synchronisiere '{profile.Name}'...");
|
||||||
|
|
@ -300,6 +366,10 @@ namespace StarfaceOutlookSync.UI
|
||||||
ex.Message, ToolTipIcon.Error);
|
ex.Message, ToolTipIcon.Error);
|
||||||
SetStatus($"Fehler: {ex.Message}");
|
SetStatus($"Fehler: {ex.Message}");
|
||||||
}
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
_syncRunning = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetStatus(string text)
|
private void SetStatus(string text)
|
||||||
|
|
|
||||||
|
|
@ -333,9 +333,23 @@ namespace StarfaceOutlookSync.UI
|
||||||
};
|
};
|
||||||
|
|
||||||
if (_isNew)
|
if (_isNew)
|
||||||
|
{
|
||||||
_pm.AddProfile(profile);
|
_pm.AddProfile(profile);
|
||||||
|
}
|
||||||
else
|
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);
|
_pm.UpdateProfile(profile);
|
||||||
|
}
|
||||||
|
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
Close();
|
Close();
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ namespace StarfaceOutlookSync.UI
|
||||||
{
|
{
|
||||||
public class SettingsForm : Form
|
public class SettingsForm : Form
|
||||||
{
|
{
|
||||||
private CheckBox _chkStartMinimized;
|
private CheckBox _chkStartMinimized, _chkSyncOnStart, _chkAutoAcceptOutlook;
|
||||||
private Button _btnSave, _btnCancel;
|
private Button _btnSave, _btnCancel;
|
||||||
private readonly UserSettings _settings;
|
private readonly UserSettings _settings;
|
||||||
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace StarfaceOutlookSync.UI
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
{
|
{
|
||||||
Text = "Einstellungen";
|
Text = "Einstellungen";
|
||||||
Size = new Size(350, 180);
|
Size = new Size(380, 250);
|
||||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||||
MaximizeBox = false;
|
MaximizeBox = false;
|
||||||
MinimizeBox = false;
|
MinimizeBox = false;
|
||||||
|
|
@ -33,20 +33,47 @@ namespace StarfaceOutlookSync.UI
|
||||||
Checked = _settings.StartMinimized
|
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
|
_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
|
DialogResult = DialogResult.None
|
||||||
};
|
};
|
||||||
_btnSave.Click += (s, e) => Save();
|
_btnSave.Click += (s, e) => Save();
|
||||||
|
|
||||||
_btnCancel = new Button
|
_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
|
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;
|
AcceptButton = _btnSave;
|
||||||
CancelButton = _btnCancel;
|
CancelButton = _btnCancel;
|
||||||
}
|
}
|
||||||
|
|
@ -54,6 +81,8 @@ namespace StarfaceOutlookSync.UI
|
||||||
private void Save()
|
private void Save()
|
||||||
{
|
{
|
||||||
_settings.StartMinimized = _chkStartMinimized.Checked;
|
_settings.StartMinimized = _chkStartMinimized.Checked;
|
||||||
|
_settings.SyncOnStart = _chkSyncOnStart.Checked;
|
||||||
|
_settings.AutoAcceptOutlookPrompt = _chkAutoAcceptOutlook.Checked;
|
||||||
_settings.Save();
|
_settings.Save();
|
||||||
DialogResult = DialogResult.OK;
|
DialogResult = DialogResult.OK;
|
||||||
Close();
|
Close();
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue