Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f0bcfdfd30 | |||
| 650d0def51 | |||
| f57518a1d5 | |||
| 1be0a94b51 | |||
| 3c38a1a6cc | |||
| ba0b79de64 | |||
| 60bd3163a9 | |||
| a3a3ac1dcc | |||
| 9d58a1a113 | |||
| bf0be12a5e | |||
| 59d4c094a9 | |||
| 499763d81f | |||
| 9aa6ccb224 | |||
| 235960f450 | |||
| 9298c3c287 | |||
| d0a2ffc9fd | |||
| 7ac5ff24a2 | |||
| cbe1a8f452 | |||
| 6627212032 | |||
| 1aa74ec014 |
+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.2"
|
#define MyAppVersion "0.0.0.12"
|
||||||
#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"
|
||||||
|
|||||||
@@ -0,0 +1,37 @@
|
|||||||
|
using System;
|
||||||
|
using System.IO;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
namespace StarfaceOutlookSync.Models
|
||||||
|
{
|
||||||
|
public class UserSettings
|
||||||
|
{
|
||||||
|
public bool StartMinimized { get; set; } = false;
|
||||||
|
|
||||||
|
private static readonly string SettingsFile = Path.Combine(
|
||||||
|
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
|
||||||
|
"StarfaceOutlookSync", "settings.json");
|
||||||
|
|
||||||
|
public static UserSettings Load()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
if (File.Exists(SettingsFile))
|
||||||
|
return JsonConvert.DeserializeObject<UserSettings>(File.ReadAllText(SettingsFile))
|
||||||
|
?? new UserSettings();
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
return new UserSettings();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Save()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(SettingsFile));
|
||||||
|
File.WriteAllText(SettingsFile, JsonConvert.SerializeObject(this, Formatting.Indented));
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,44 +2,75 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
using StarfaceOutlookSync.Models;
|
using StarfaceOutlookSync.Models;
|
||||||
using Outlook = Microsoft.Office.Interop.Outlook;
|
|
||||||
|
|
||||||
namespace StarfaceOutlookSync.Services
|
namespace StarfaceOutlookSync.Services
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Zugriff auf Outlook-Kontakte per dynamic COM.
|
||||||
|
/// Funktioniert mit jeder Outlook Classic Version (2013-2024)
|
||||||
|
/// ohne Abhaengigkeit von einer bestimmten Interop-DLL.
|
||||||
|
/// </summary>
|
||||||
public class OutlookContactsService : IDisposable
|
public class OutlookContactsService : IDisposable
|
||||||
{
|
{
|
||||||
private Outlook.Application _outlookApp;
|
private dynamic _outlookApp;
|
||||||
private bool _weStartedOutlook;
|
private bool _weStartedOutlook;
|
||||||
|
|
||||||
// Marshal.GetActiveObject existiert nicht in .NET 8, daher P/Invoke
|
// OlDefaultFolders.olFolderContacts = 10
|
||||||
|
private const int OlFolderContacts = 10;
|
||||||
|
// OlItemType.olContactItem = 2
|
||||||
|
private const int OlContactItem = 2;
|
||||||
|
|
||||||
[DllImport("oleaut32.dll", PreserveSig = false)]
|
[DllImport("oleaut32.dll", PreserveSig = false)]
|
||||||
private static extern void GetActiveObject([MarshalAs(UnmanagedType.LPStruct)] Guid rclsid, IntPtr pvReserved, [MarshalAs(UnmanagedType.IUnknown)] out object ppunk);
|
private static extern void GetActiveObject(
|
||||||
|
[MarshalAs(UnmanagedType.LPStruct)] Guid rclsid,
|
||||||
|
IntPtr pvReserved,
|
||||||
|
[MarshalAs(UnmanagedType.IUnknown)] out object ppunk);
|
||||||
|
|
||||||
private static object GetActiveComObject(string progId)
|
private static object GetActiveComObject(string progId)
|
||||||
{
|
{
|
||||||
var clsid = Type.GetTypeFromProgID(progId, true).GUID;
|
var type = Type.GetTypeFromProgID(progId, false);
|
||||||
GetActiveObject(clsid, IntPtr.Zero, out var obj);
|
if (type == null) return null;
|
||||||
|
GetActiveObject(type.GUID, IntPtr.Zero, out var obj);
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Outlook.Application GetOutlookApp()
|
private dynamic GetOutlookApp()
|
||||||
{
|
{
|
||||||
if (_outlookApp != null) return _outlookApp;
|
if (_outlookApp != null) return _outlookApp;
|
||||||
|
|
||||||
|
// Versuch 1: Laufende Outlook-Instanz finden
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Versuche laufende Outlook-Instanz zu finden
|
var obj = GetActiveComObject("Outlook.Application");
|
||||||
_outlookApp = (Outlook.Application)GetActiveComObject("Outlook.Application");
|
if (obj != null)
|
||||||
_weStartedOutlook = false;
|
{
|
||||||
}
|
_outlookApp = obj;
|
||||||
catch
|
_weStartedOutlook = false;
|
||||||
{
|
return _outlookApp;
|
||||||
// Outlook starten falls nicht laufend
|
}
|
||||||
_outlookApp = new Outlook.Application();
|
|
||||||
_weStartedOutlook = true;
|
|
||||||
}
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
return _outlookApp;
|
// Versuch 2: Outlook per COM starten
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var outlookType = Type.GetTypeFromProgID("Outlook.Application", false);
|
||||||
|
if (outlookType != null)
|
||||||
|
{
|
||||||
|
_outlookApp = Activator.CreateInstance(outlookType);
|
||||||
|
_weStartedOutlook = true;
|
||||||
|
return _outlookApp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
|
||||||
|
throw new InvalidOperationException(
|
||||||
|
"Outlook Classic konnte nicht gefunden werden.\n\n" +
|
||||||
|
"Moegliche Ursachen:\n" +
|
||||||
|
"- Outlook Classic ist nicht installiert\n" +
|
||||||
|
"- Outlook Classic ist nicht gestartet\n" +
|
||||||
|
"- Das neue Outlook wird verwendet (wird noch nicht unterstuetzt)\n\n" +
|
||||||
|
"Bitte Outlook Classic starten und erneut versuchen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<string> GetContactFolderPaths()
|
public List<string> GetContactFolderPaths()
|
||||||
@@ -50,128 +81,235 @@ namespace StarfaceOutlookSync.Services
|
|||||||
var app = GetOutlookApp();
|
var app = GetOutlookApp();
|
||||||
var ns = app.GetNamespace("MAPI");
|
var ns = app.GetNamespace("MAPI");
|
||||||
|
|
||||||
// Standard-Kontaktordner
|
// Alle Stores durchgehen
|
||||||
var defaultFolder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
|
var stores = ns.Stores;
|
||||||
folders.Add(defaultFolder.FolderPath);
|
for (int i = 1; i <= (int)stores.Count; i++)
|
||||||
|
|
||||||
// Unterordner
|
|
||||||
AddSubFolders(defaultFolder, folders);
|
|
||||||
|
|
||||||
// Weitere Kontaktordner in anderen Stores
|
|
||||||
foreach (Outlook.Store store in ns.Stores)
|
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
var store = stores[i];
|
||||||
var rootFolder = store.GetRootFolder();
|
var rootFolder = store.GetRootFolder();
|
||||||
FindContactFolders(rootFolder, folders);
|
FindContactFoldersRecursive(rootFolder, folders);
|
||||||
|
Marshal.ReleaseComObject(rootFolder);
|
||||||
|
Marshal.ReleaseComObject(store);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Error scanning store {i}: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Falls nichts gefunden, Standard-Kontaktordner als Fallback
|
||||||
|
if (folders.Count == 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var defaultFolder = ns.GetDefaultFolder(OlFolderContacts);
|
||||||
|
folders.Add((string)defaultFolder.FolderPath);
|
||||||
|
Marshal.ReleaseComObject(defaultFolder);
|
||||||
}
|
}
|
||||||
catch { }
|
catch { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Marshal.ReleaseComObject(stores);
|
||||||
Marshal.ReleaseComObject(ns);
|
Marshal.ReleaseComObject(ns);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
System.Diagnostics.Debug.WriteLine($"Error getting folders: {ex.Message}");
|
System.Diagnostics.Debug.WriteLine($"Error getting folders: {ex.Message}");
|
||||||
|
throw;
|
||||||
}
|
}
|
||||||
|
|
||||||
return folders;
|
return folders;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddSubFolders(Outlook.MAPIFolder folder, List<string> paths)
|
private void FindContactFoldersRecursive(dynamic folder, List<string> paths)
|
||||||
{
|
{
|
||||||
foreach (Outlook.MAPIFolder sub in folder.Folders)
|
try
|
||||||
{
|
{
|
||||||
if (sub.DefaultItemType == Outlook.OlItemType.olContactItem)
|
if ((int)folder.DefaultItemType == OlContactItem)
|
||||||
{
|
{
|
||||||
if (!paths.Contains(sub.FolderPath))
|
string path = folder.FolderPath;
|
||||||
paths.Add(sub.FolderPath);
|
if (!paths.Contains(path))
|
||||||
AddSubFolders(sub, paths);
|
paths.Add(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var subFolders = folder.Folders;
|
||||||
|
for (int i = 1; i <= (int)subFolders.Count; i++)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sub = subFolders[i];
|
||||||
|
FindContactFoldersRecursive(sub, paths);
|
||||||
|
Marshal.ReleaseComObject(sub);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
Marshal.ReleaseComObject(subFolders);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Error scanning folder: {ex.Message}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void FindContactFolders(Outlook.MAPIFolder folder, List<string> paths)
|
private dynamic FindFolderByPath(dynamic folder, string targetPath)
|
||||||
{
|
{
|
||||||
if (folder.DefaultItemType == Outlook.OlItemType.olContactItem)
|
try
|
||||||
{
|
{
|
||||||
if (!paths.Contains(folder.FolderPath))
|
string currentPath = folder.FolderPath;
|
||||||
paths.Add(folder.FolderPath);
|
if (currentPath == targetPath)
|
||||||
}
|
return folder;
|
||||||
|
|
||||||
foreach (Outlook.MAPIFolder sub in folder.Folders)
|
var subs = folder.Folders;
|
||||||
{
|
for (int i = 1; i <= (int)subs.Count; i++)
|
||||||
FindContactFolders(sub, paths);
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var sub = subs[i];
|
||||||
|
var match = FindFolderByPath(sub, targetPath);
|
||||||
|
if (match != null) return match;
|
||||||
|
Marshal.ReleaseComObject(sub);
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
}
|
||||||
|
Marshal.ReleaseComObject(subs);
|
||||||
}
|
}
|
||||||
|
catch { }
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Outlook.MAPIFolder GetFolderByPath(string folderPath)
|
private dynamic GetFolderByPath(string folderPath)
|
||||||
{
|
{
|
||||||
var app = GetOutlookApp();
|
var app = GetOutlookApp();
|
||||||
var ns = app.GetNamespace("MAPI");
|
var ns = app.GetNamespace("MAPI");
|
||||||
|
|
||||||
// Standard-Kontaktordner als Fallback
|
|
||||||
if (string.IsNullOrEmpty(folderPath))
|
if (string.IsNullOrEmpty(folderPath))
|
||||||
return ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
|
return ns.GetDefaultFolder(OlFolderContacts);
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Pfad durchlaufen
|
// Versuch 1: Alle Kontaktordner durchsuchen und per FolderPath matchen
|
||||||
var parts = folderPath.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
|
var stores = ns.Stores;
|
||||||
Outlook.MAPIFolder current = null;
|
for (int i = 1; i <= (int)stores.Count; i++)
|
||||||
|
|
||||||
foreach (Outlook.Store store in ns.Stores)
|
|
||||||
{
|
{
|
||||||
if (store.GetRootFolder().Name == parts[0] ||
|
try
|
||||||
store.GetRootFolder().FolderPath.TrimStart('\\') == parts[0])
|
|
||||||
{
|
{
|
||||||
current = store.GetRootFolder();
|
var store = stores[i];
|
||||||
break;
|
var root = store.GetRootFolder();
|
||||||
}
|
var match = FindFolderByPath(root, folderPath);
|
||||||
}
|
if (match != null)
|
||||||
|
|
||||||
if (current == null)
|
|
||||||
return ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
|
|
||||||
|
|
||||||
for (int i = 1; i < parts.Length; i++)
|
|
||||||
{
|
|
||||||
bool found = false;
|
|
||||||
foreach (Outlook.MAPIFolder sub in current.Folders)
|
|
||||||
{
|
|
||||||
if (sub.Name == parts[i])
|
|
||||||
{
|
{
|
||||||
current = sub;
|
Marshal.ReleaseComObject(stores);
|
||||||
found = true;
|
return match;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
Marshal.ReleaseComObject(root);
|
||||||
|
Marshal.ReleaseComObject(store);
|
||||||
}
|
}
|
||||||
if (!found)
|
catch { }
|
||||||
return ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
|
}
|
||||||
|
Marshal.ReleaseComObject(stores);
|
||||||
|
|
||||||
|
// Versuch 2: Namespace.Folders direkt navigieren
|
||||||
|
var parts = folderPath.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
if (parts.Length >= 1)
|
||||||
|
{
|
||||||
|
var topFolders = ns.Folders;
|
||||||
|
for (int i = 1; i <= (int)topFolders.Count; i++)
|
||||||
|
{
|
||||||
|
var topFolder = topFolders[i];
|
||||||
|
if ((string)topFolder.Name == parts[0])
|
||||||
|
{
|
||||||
|
dynamic current = topFolder;
|
||||||
|
for (int p = 1; p < parts.Length; p++)
|
||||||
|
{
|
||||||
|
bool found = false;
|
||||||
|
var subs = current.Folders;
|
||||||
|
for (int j = 1; j <= (int)subs.Count; j++)
|
||||||
|
{
|
||||||
|
var sub = subs[j];
|
||||||
|
if ((string)sub.Name == parts[p])
|
||||||
|
{
|
||||||
|
current = sub;
|
||||||
|
found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Marshal.ReleaseComObject(sub);
|
||||||
|
}
|
||||||
|
Marshal.ReleaseComObject(subs);
|
||||||
|
if (!found) { current = null; break; }
|
||||||
|
}
|
||||||
|
if (current != null)
|
||||||
|
{
|
||||||
|
Marshal.ReleaseComObject(topFolders);
|
||||||
|
return current;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Marshal.ReleaseComObject(topFolder);
|
||||||
|
}
|
||||||
|
Marshal.ReleaseComObject(topFolders);
|
||||||
}
|
}
|
||||||
|
|
||||||
return current;
|
System.Diagnostics.Debug.WriteLine($"Folder not found by path: {folderPath}, using default");
|
||||||
|
return ns.GetDefaultFolder(OlFolderContacts);
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
return ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
|
return ns.GetDefaultFolder(OlFolderContacts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<UnifiedContact> GetContacts(string folderPath)
|
public List<UnifiedContact> GetContacts(string folderPath)
|
||||||
{
|
{
|
||||||
var contacts = new List<UnifiedContact>();
|
var contacts = new List<UnifiedContact>();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var folder = GetFolderByPath(folderPath);
|
var folder = GetFolderByPath(folderPath);
|
||||||
var items = folder.Items;
|
System.Diagnostics.Debug.WriteLine($"Reading contacts from: {(string)folder.FolderPath}");
|
||||||
|
|
||||||
foreach (var item in items)
|
var items = folder.Items;
|
||||||
|
int count = (int)items.Count;
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Items count: {count}");
|
||||||
|
|
||||||
|
for (int i = 1; i <= count; i++)
|
||||||
{
|
{
|
||||||
if (item is Outlook.ContactItem ci)
|
dynamic item = null;
|
||||||
|
try
|
||||||
{
|
{
|
||||||
contacts.Add(MapFromOutlook(ci));
|
item = items[i];
|
||||||
Marshal.ReleaseComObject(ci);
|
int itemClass = -1;
|
||||||
|
try { itemClass = (int)item.Class; } catch { }
|
||||||
|
|
||||||
|
// olContact = 40, aber manche Kontakte melden Class anders
|
||||||
|
// Versuch einfach die Kontakt-Felder zu lesen
|
||||||
|
if (itemClass == 40)
|
||||||
|
{
|
||||||
|
contacts.Add(MapFromOutlook(item));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Fallback: Pruefen ob es trotzdem ein Kontakt ist
|
||||||
|
try
|
||||||
|
{
|
||||||
|
string eid = item.EntryID;
|
||||||
|
string fn = item.FirstName;
|
||||||
|
string ln = item.LastName;
|
||||||
|
// Hat Kontakt-Felder -> ist ein Kontakt
|
||||||
|
contacts.Add(MapFromOutlook(item));
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
// Kein Kontakt, ueberspringen
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Error reading item {i}: {ex.Message}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
if (item != null) try { Marshal.ReleaseComObject(item); } catch { }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -191,7 +329,8 @@ namespace StarfaceOutlookSync.Services
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
var folder = GetFolderByPath(folderPath);
|
var folder = GetFolderByPath(folderPath);
|
||||||
var ci = (Outlook.ContactItem)folder.Items.Add(Outlook.OlItemType.olContactItem);
|
var items = folder.Items;
|
||||||
|
dynamic ci = items.Add(OlContactItem);
|
||||||
|
|
||||||
MapToOutlook(contact, ci);
|
MapToOutlook(contact, ci);
|
||||||
ci.Save();
|
ci.Save();
|
||||||
@@ -199,6 +338,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
contact.OutlookEntryId = ci.EntryID;
|
contact.OutlookEntryId = ci.EntryID;
|
||||||
|
|
||||||
Marshal.ReleaseComObject(ci);
|
Marshal.ReleaseComObject(ci);
|
||||||
|
Marshal.ReleaseComObject(items);
|
||||||
Marshal.ReleaseComObject(folder);
|
Marshal.ReleaseComObject(folder);
|
||||||
|
|
||||||
return contact;
|
return contact;
|
||||||
@@ -216,7 +356,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
{
|
{
|
||||||
var app = GetOutlookApp();
|
var app = GetOutlookApp();
|
||||||
var ns = app.GetNamespace("MAPI");
|
var ns = app.GetNamespace("MAPI");
|
||||||
var ci = (Outlook.ContactItem)ns.GetItemFromID(entryId);
|
dynamic ci = ns.GetItemFromID(entryId);
|
||||||
|
|
||||||
MapToOutlook(contact, ci);
|
MapToOutlook(contact, ci);
|
||||||
ci.Save();
|
ci.Save();
|
||||||
@@ -239,7 +379,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
{
|
{
|
||||||
var app = GetOutlookApp();
|
var app = GetOutlookApp();
|
||||||
var ns = app.GetNamespace("MAPI");
|
var ns = app.GetNamespace("MAPI");
|
||||||
var ci = (Outlook.ContactItem)ns.GetItemFromID(entryId);
|
dynamic ci = ns.GetItemFromID(entryId);
|
||||||
|
|
||||||
ci.Delete();
|
ci.Delete();
|
||||||
Marshal.ReleaseComObject(ci);
|
Marshal.ReleaseComObject(ci);
|
||||||
@@ -254,36 +394,46 @@ namespace StarfaceOutlookSync.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private UnifiedContact MapFromOutlook(Outlook.ContactItem ci)
|
private UnifiedContact MapFromOutlook(dynamic ci)
|
||||||
{
|
{
|
||||||
return new UnifiedContact
|
return new UnifiedContact
|
||||||
{
|
{
|
||||||
OutlookEntryId = ci.EntryID ?? "",
|
OutlookEntryId = (string)(ci.EntryID ?? ""),
|
||||||
FirstName = ci.FirstName ?? "",
|
FirstName = (string)(ci.FirstName ?? ""),
|
||||||
LastName = ci.LastName ?? "",
|
LastName = (string)(ci.LastName ?? ""),
|
||||||
Company = ci.CompanyName ?? "",
|
Company = (string)(ci.CompanyName ?? ""),
|
||||||
JobTitle = ci.JobTitle ?? "",
|
JobTitle = (string)(ci.JobTitle ?? ""),
|
||||||
Email = ci.Email1Address ?? "",
|
Email = (string)(ci.Email1Address ?? ""),
|
||||||
EmailSecondary = ci.Email2Address ?? "",
|
EmailSecondary = (string)(ci.Email2Address ?? ""),
|
||||||
PhoneWork = ci.BusinessTelephoneNumber ?? "",
|
PhoneWork = (string)(ci.BusinessTelephoneNumber ?? ""),
|
||||||
PhoneMobile = ci.MobileTelephoneNumber ?? "",
|
PhoneMobile = (string)(ci.MobileTelephoneNumber ?? ""),
|
||||||
PhoneHome = ci.HomeTelephoneNumber ?? "",
|
PhoneHome = (string)(ci.HomeTelephoneNumber ?? ""),
|
||||||
Fax = ci.BusinessFaxNumber ?? "",
|
Fax = (string)(ci.BusinessFaxNumber ?? ""),
|
||||||
Street = ci.BusinessAddressStreet ?? "",
|
Street = (string)(ci.BusinessAddressStreet ?? ""),
|
||||||
City = ci.BusinessAddressCity ?? "",
|
City = (string)(ci.BusinessAddressCity ?? ""),
|
||||||
PostalCode = ci.BusinessAddressPostalCode ?? "",
|
PostalCode = (string)(ci.BusinessAddressPostalCode ?? ""),
|
||||||
State = ci.BusinessAddressState ?? "",
|
State = (string)(ci.BusinessAddressState ?? ""),
|
||||||
Country = ci.BusinessAddressCountry ?? "",
|
Country = (string)(ci.BusinessAddressCountry ?? ""),
|
||||||
Website = ci.WebPage ?? "",
|
Website = (string)(ci.WebPage ?? ""),
|
||||||
Notes = ci.Body ?? "",
|
Notes = (string)(ci.Body ?? ""),
|
||||||
Salutation = ci.Title ?? "",
|
Salutation = (string)(ci.Title ?? ""),
|
||||||
Title = ci.Suffix ?? "",
|
Birthday = GetBirthdayString(ci)
|
||||||
Birthday = ci.Birthday != DateTime.MinValue && ci.Birthday.Year > 1900
|
|
||||||
? ci.Birthday.ToString("yyyy-MM-dd") : ""
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private void MapToOutlook(UnifiedContact contact, Outlook.ContactItem ci)
|
private string GetBirthdayString(dynamic ci)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
DateTime bday = ci.Birthday;
|
||||||
|
if (bday.Year > 1900 && bday != DateTime.MinValue)
|
||||||
|
return bday.ToString("yyyy-MM-dd");
|
||||||
|
}
|
||||||
|
catch { }
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void MapToOutlook(UnifiedContact contact, dynamic ci)
|
||||||
{
|
{
|
||||||
ci.FirstName = contact.FirstName;
|
ci.FirstName = contact.FirstName;
|
||||||
ci.LastName = contact.LastName;
|
ci.LastName = contact.LastName;
|
||||||
@@ -320,7 +470,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
{
|
{
|
||||||
try { _outlookApp.Quit(); } catch { }
|
try { _outlookApp.Quit(); } catch { }
|
||||||
}
|
}
|
||||||
Marshal.ReleaseComObject(_outlookApp);
|
try { Marshal.ReleaseComObject(_outlookApp); } catch { }
|
||||||
_outlookApp = null;
|
_outlookApp = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -155,11 +155,14 @@ namespace StarfaceOutlookSync.Services
|
|||||||
return books;
|
return books;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public event Action<string> OnDebug;
|
||||||
|
|
||||||
public async Task<List<UnifiedContact>> GetContactsAsync(StarfaceAddressBook book)
|
public async Task<List<UnifiedContact>> GetContactsAsync(StarfaceAddressBook book)
|
||||||
{
|
{
|
||||||
var contacts = new List<UnifiedContact>();
|
var contacts = new List<UnifiedContact>();
|
||||||
int page = 0;
|
int page = 0;
|
||||||
const int pageSize = 200;
|
const int pageSize = 200;
|
||||||
|
bool firstPage = true;
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
@@ -172,11 +175,68 @@ namespace StarfaceOutlookSync.Services
|
|||||||
var resp = await _http.GetAsync($"{_baseUrl}/contacts?{query}");
|
var resp = await _http.GetAsync($"{_baseUrl}/contacts?{query}");
|
||||||
if (!resp.IsSuccessStatusCode) break;
|
if (!resp.IsSuccessStatusCode) break;
|
||||||
|
|
||||||
var array = JArray.Parse(await resp.Content.ReadAsStringAsync());
|
var body = await resp.Content.ReadAsStringAsync();
|
||||||
|
JArray array;
|
||||||
|
|
||||||
|
// Die API gibt je nach Version ein Array oder ein Objekt mit "items" zurueck
|
||||||
|
var token = JToken.Parse(body);
|
||||||
|
if (token is JArray directArray)
|
||||||
|
{
|
||||||
|
array = directArray;
|
||||||
|
}
|
||||||
|
else if (token is JObject obj)
|
||||||
|
{
|
||||||
|
// Versuche gaengige Felder: items, contacts, data, results
|
||||||
|
array = (obj["items"] ?? obj["contacts"] ?? obj["data"] ?? obj["results"]) as JArray;
|
||||||
|
if (array == null)
|
||||||
|
{
|
||||||
|
// Einzelnes Kontakt-Objekt? Dann in Array wrappen
|
||||||
|
if (obj["id"] != null && obj["blocks"] != null)
|
||||||
|
{
|
||||||
|
array = new JArray { obj };
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.Diagnostics.Debug.WriteLine($"Unerwartete Starface-Antwort: {body.Substring(0, Math.Min(200, body.Length))}");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (array.Count == 0) break;
|
if (array.Count == 0) break;
|
||||||
|
|
||||||
|
OnDebug?.Invoke($"Seite {page}: {array.Count} Kontakte in Liste");
|
||||||
|
|
||||||
|
// Die Listen-API gibt nur Summary zurueck.
|
||||||
|
// Jeden Kontakt einzeln abrufen fuer alle Felder.
|
||||||
foreach (var item in array)
|
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++;
|
||||||
@@ -224,7 +284,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)
|
||||||
{
|
{
|
||||||
@@ -234,79 +297,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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ namespace StarfaceOutlookSync.Services
|
|||||||
Log("Verbinde mit Starface...");
|
Log("Verbinde mit Starface...");
|
||||||
using (var starface = new StarfaceApiClient(profile.StarfaceConnection))
|
using (var starface = new StarfaceApiClient(profile.StarfaceConnection))
|
||||||
{
|
{
|
||||||
|
starface.OnDebug += (msg) => Log(msg);
|
||||||
var loginOk = await starface.LoginAsync();
|
var loginOk = await starface.LoginAsync();
|
||||||
if (!loginOk)
|
if (!loginOk)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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.2</Version>
|
<Version>0.0.0.12</Version>
|
||||||
<AssemblyVersion>0.0.0.2</AssemblyVersion>
|
<AssemblyVersion>0.0.0.12</AssemblyVersion>
|
||||||
<FileVersion>0.0.0.2</FileVersion>
|
<FileVersion>0.0.0.12</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>
|
||||||
@@ -19,7 +19,6 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
<PackageReference Include="Microsoft.Office.Interop.Outlook" Version="15.0.4797.1004" />
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ namespace StarfaceOutlookSync.UI
|
|||||||
|
|
||||||
var lblVersion = new Label
|
var lblVersion = new Label
|
||||||
{
|
{
|
||||||
Text = "Version 0.0.0.2",
|
Text = "Version 0.0.0.12",
|
||||||
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
|
||||||
|
|||||||
@@ -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, _btnInfo;
|
private Button _btnNew, _btnEdit, _btnDelete, _btnSync, _btnSettings, _btnInfo;
|
||||||
private StatusStrip _statusBar;
|
private StatusStrip _statusBar;
|
||||||
private ToolStripStatusLabel _statusLabel;
|
private ToolStripStatusLabel _statusLabel;
|
||||||
private Timer _autoSyncTimer;
|
private Timer _autoSyncTimer;
|
||||||
@@ -29,6 +29,30 @@ namespace StarfaceOutlookSync.UI
|
|||||||
SetupTrayIcon();
|
SetupTrayIcon();
|
||||||
SetupAutoSync();
|
SetupAutoSync();
|
||||||
RefreshProfileList();
|
RefreshProfileList();
|
||||||
|
|
||||||
|
// Minimiert starten falls in Einstellungen aktiviert
|
||||||
|
var settings = UserSettings.Load();
|
||||||
|
if (settings.StartMinimized)
|
||||||
|
{
|
||||||
|
WindowState = FormWindowState.Minimized;
|
||||||
|
ShowInTaskbar = false;
|
||||||
|
Visible = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetVisibleCore(bool value)
|
||||||
|
{
|
||||||
|
// Beim ersten Anzeigen pruefen ob minimiert gestartet werden soll
|
||||||
|
if (!IsHandleCreated)
|
||||||
|
{
|
||||||
|
var settings = UserSettings.Load();
|
||||||
|
if (settings.StartMinimized)
|
||||||
|
{
|
||||||
|
CreateHandle();
|
||||||
|
value = false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
base.SetVisibleCore(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void InitializeComponent()
|
private void InitializeComponent()
|
||||||
@@ -76,10 +100,13 @@ namespace StarfaceOutlookSync.UI
|
|||||||
_btnSync = new Button { Text = "Jetzt synchronisieren", Width = 150, Height = 30 };
|
_btnSync = new Button { Text = "Jetzt synchronisieren", Width = 150, 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 };
|
||||||
|
_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, _btnInfo });
|
buttonPanel.Controls.AddRange(new Control[] { _btnNew, _btnEdit, _btnDelete, _btnSync, _btnSettings, _btnInfo });
|
||||||
|
|
||||||
// Statusbar
|
// Statusbar
|
||||||
_statusBar = new StatusStrip();
|
_statusBar = new StatusStrip();
|
||||||
@@ -283,6 +310,14 @@ namespace StarfaceOutlookSync.UI
|
|||||||
_statusLabel.Text = text;
|
_statusLabel.Text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void ShowSettings()
|
||||||
|
{
|
||||||
|
using (var settings = new SettingsForm())
|
||||||
|
{
|
||||||
|
settings.ShowDialog(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void ShowAbout()
|
private void ShowAbout()
|
||||||
{
|
{
|
||||||
using (var about = new AboutForm())
|
using (var about = new AboutForm())
|
||||||
|
|||||||
@@ -0,0 +1,125 @@
|
|||||||
|
using System;
|
||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace StarfaceOutlookSync.UI
|
||||||
|
{
|
||||||
|
public class OutlookFolderBrowserForm : Form
|
||||||
|
{
|
||||||
|
private TreeView _tree;
|
||||||
|
private Button _btnOk, _btnCancel;
|
||||||
|
public string SelectedFolderPath { get; private set; } = "";
|
||||||
|
public string SelectedFolderName { get; private set; } = "";
|
||||||
|
|
||||||
|
public OutlookFolderBrowserForm(List<string> folderPaths, string currentSelection)
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
BuildTree(folderPaths, currentSelection);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
Text = "Outlook-Ordner waehlen";
|
||||||
|
Size = new Size(400, 450);
|
||||||
|
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||||
|
MaximizeBox = false;
|
||||||
|
MinimizeBox = false;
|
||||||
|
StartPosition = FormStartPosition.CenterParent;
|
||||||
|
Font = new Font("Segoe UI", 9);
|
||||||
|
|
||||||
|
var lblInfo = new Label
|
||||||
|
{
|
||||||
|
Text = "Bitte waehlen Sie den Outlook-Kontaktordner fuer die Synchronisation:",
|
||||||
|
Left = 12, Top = 12, Width = 360, Height = 36
|
||||||
|
};
|
||||||
|
|
||||||
|
_tree = new TreeView
|
||||||
|
{
|
||||||
|
Left = 12, Top = 52, Width = 360, Height = 310,
|
||||||
|
HideSelection = false,
|
||||||
|
ShowLines = true,
|
||||||
|
ShowPlusMinus = true,
|
||||||
|
ShowRootLines = true
|
||||||
|
};
|
||||||
|
_tree.DoubleClick += (s, e) => { if (_tree.SelectedNode?.Tag != null) SelectAndClose(); };
|
||||||
|
|
||||||
|
_btnOk = new Button
|
||||||
|
{
|
||||||
|
Text = "OK", Left = 210, Top = 372, Width = 75, Height = 28,
|
||||||
|
DialogResult = DialogResult.None
|
||||||
|
};
|
||||||
|
_btnOk.Click += (s, e) => SelectAndClose();
|
||||||
|
|
||||||
|
_btnCancel = new Button
|
||||||
|
{
|
||||||
|
Text = "Abbrechen", Left = 292, Top = 372, Width = 80, Height = 28,
|
||||||
|
DialogResult = DialogResult.Cancel
|
||||||
|
};
|
||||||
|
|
||||||
|
Controls.AddRange(new Control[] { lblInfo, _tree, _btnOk, _btnCancel });
|
||||||
|
AcceptButton = _btnOk;
|
||||||
|
CancelButton = _btnCancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BuildTree(List<string> folderPaths, string currentSelection)
|
||||||
|
{
|
||||||
|
_tree.Nodes.Clear();
|
||||||
|
var nodeMap = new Dictionary<string, TreeNode>();
|
||||||
|
|
||||||
|
foreach (var path in folderPaths)
|
||||||
|
{
|
||||||
|
// Pfad: \\Store\Kontakte\Unterordner
|
||||||
|
var parts = path.TrimStart('\\').Split('\\');
|
||||||
|
string runningPath = "";
|
||||||
|
TreeNode parent = null;
|
||||||
|
|
||||||
|
for (int i = 0; i < parts.Length; i++)
|
||||||
|
{
|
||||||
|
runningPath += "\\" + parts[i];
|
||||||
|
|
||||||
|
if (!nodeMap.ContainsKey(runningPath))
|
||||||
|
{
|
||||||
|
var node = new TreeNode(parts[i]);
|
||||||
|
// Nur Blatt-Knoten oder bekannte Pfade sind waehlbar
|
||||||
|
if (i == parts.Length - 1)
|
||||||
|
node.Tag = path; // Vollstaendiger Pfad
|
||||||
|
|
||||||
|
if (parent == null)
|
||||||
|
_tree.Nodes.Add(node);
|
||||||
|
else
|
||||||
|
parent.Nodes.Add(node);
|
||||||
|
|
||||||
|
nodeMap[runningPath] = node;
|
||||||
|
|
||||||
|
// Aktuellen Ordner vorauswaehlen
|
||||||
|
if (path == currentSelection)
|
||||||
|
{
|
||||||
|
_tree.SelectedNode = node;
|
||||||
|
node.EnsureVisible();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parent = nodeMap[runningPath];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_tree.ExpandAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SelectAndClose()
|
||||||
|
{
|
||||||
|
if (_tree.SelectedNode?.Tag == null)
|
||||||
|
{
|
||||||
|
MessageBox.Show("Bitte einen Kontaktordner waehlen.", "Hinweis",
|
||||||
|
MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
SelectedFolderPath = _tree.SelectedNode.Tag.ToString();
|
||||||
|
SelectedFolderName = _tree.SelectedNode.Text;
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,14 +15,18 @@ namespace StarfaceOutlookSync.UI
|
|||||||
private readonly bool _isNew;
|
private readonly bool _isNew;
|
||||||
|
|
||||||
// Controls
|
// Controls
|
||||||
private TextBox _txtName, _txtHost, _txtPort, _txtLoginId, _txtPassword;
|
private TextBox _txtName, _txtHost, _txtPort, _txtLoginId, _txtPassword, _txtOutlookFolder;
|
||||||
private CheckBox _chkSsl, _chkEnabled;
|
private CheckBox _chkSsl, _chkEnabled;
|
||||||
private ComboBox _cmbAddressBook, _cmbOutlookFolder, _cmbDirection;
|
private ComboBox _cmbAddressBook, _cmbDirection;
|
||||||
|
private Button _btnBrowseFolder;
|
||||||
private NumericUpDown _numAutoSync;
|
private NumericUpDown _numAutoSync;
|
||||||
private Button _btnTest, _btnLoadBooks, _btnSave, _btnCancel;
|
private Button _btnTest, _btnLoadBooks, _btnSave, _btnCancel;
|
||||||
private Label _lblTestResult;
|
private Label _lblTestResult;
|
||||||
|
|
||||||
private List<StarfaceAddressBook> _addressBooks = new List<StarfaceAddressBook>();
|
private List<StarfaceAddressBook> _addressBooks = new List<StarfaceAddressBook>();
|
||||||
|
private List<string> _outlookFolderPaths = new List<string>();
|
||||||
|
private string _selectedOutlookPath = "";
|
||||||
|
private string _selectedOutlookName = "";
|
||||||
|
|
||||||
public ProfileEditorForm(SyncProfile profile)
|
public ProfileEditorForm(SyncProfile profile)
|
||||||
{
|
{
|
||||||
@@ -87,8 +91,11 @@ namespace StarfaceOutlookSync.UI
|
|||||||
panel.Controls.Add(MakeSectionLabel("Outlook-Einstellungen", 12, y)); y += 26;
|
panel.Controls.Add(MakeSectionLabel("Outlook-Einstellungen", 12, y)); y += 26;
|
||||||
|
|
||||||
panel.Controls.Add(MakeLabel("Kontakte-Ordner:", 12, y)); y += 22;
|
panel.Controls.Add(MakeLabel("Kontakte-Ordner:", 12, y)); y += 22;
|
||||||
_cmbOutlookFolder = new ComboBox { Left = 12, Top = y, Width = 420, DropDownStyle = ComboBoxStyle.DropDownList };
|
_txtOutlookFolder = new TextBox { Left = 12, Top = y, Width = 330, ReadOnly = true, BackColor = SystemColors.Window };
|
||||||
panel.Controls.Add(_cmbOutlookFolder); y += 32;
|
_btnBrowseFolder = new Button { Text = "Durchsuchen...", Left = 348, Top = y - 1, Width = 84, Height = 24 };
|
||||||
|
_btnBrowseFolder.Click += (s, e) => BrowseOutlookFolder();
|
||||||
|
panel.Controls.Add(_txtOutlookFolder);
|
||||||
|
panel.Controls.Add(_btnBrowseFolder); y += 32;
|
||||||
|
|
||||||
panel.Controls.Add(MakeLabel("Sync-Richtung:", 12, y)); y += 22;
|
panel.Controls.Add(MakeLabel("Sync-Richtung:", 12, y)); y += 22;
|
||||||
_cmbDirection = new ComboBox { Left = 12, Top = y, Width = 250, DropDownStyle = ComboBoxStyle.DropDownList };
|
_cmbDirection = new ComboBox { Left = 12, Top = y, Width = 250, DropDownStyle = ComboBoxStyle.DropDownList };
|
||||||
@@ -132,18 +139,15 @@ namespace StarfaceOutlookSync.UI
|
|||||||
{
|
{
|
||||||
using (var outlook = new OutlookContactsService())
|
using (var outlook = new OutlookContactsService())
|
||||||
{
|
{
|
||||||
var folders = outlook.GetContactFolderPaths();
|
_outlookFolderPaths = outlook.GetContactFolderPaths();
|
||||||
_cmbOutlookFolder.Items.Clear();
|
|
||||||
foreach (var f in folders)
|
|
||||||
_cmbOutlookFolder.Items.Add(f);
|
|
||||||
if (folders.Count > 0)
|
|
||||||
_cmbOutlookFolder.SelectedIndex = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
_cmbOutlookFolder.Items.Add("\\\\Kontakte");
|
MessageBox.Show(
|
||||||
_cmbOutlookFolder.SelectedIndex = 0;
|
$"Outlook-Kontaktordner konnten nicht geladen werden:\n{ex.Message}\n\nIst Outlook gestartet?",
|
||||||
|
"Outlook-Verbindung", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
_outlookFolderPaths = new List<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bestehende Werte laden
|
// Bestehende Werte laden
|
||||||
@@ -160,15 +164,10 @@ namespace StarfaceOutlookSync.UI
|
|||||||
|
|
||||||
_cmbDirection.SelectedIndex = (int)_existingProfile.SyncDirection;
|
_cmbDirection.SelectedIndex = (int)_existingProfile.SyncDirection;
|
||||||
|
|
||||||
// Outlook-Ordner auswaehlen
|
// Outlook-Ordner
|
||||||
for (int i = 0; i < _cmbOutlookFolder.Items.Count; i++)
|
_selectedOutlookPath = _existingProfile.OutlookFolderPath;
|
||||||
{
|
_selectedOutlookName = _existingProfile.OutlookFolderName;
|
||||||
if (_cmbOutlookFolder.Items[i].ToString() == _existingProfile.OutlookFolderPath)
|
_txtOutlookFolder.Text = _selectedOutlookPath;
|
||||||
{
|
|
||||||
_cmbOutlookFolder.SelectedIndex = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Adressbuch
|
// Adressbuch
|
||||||
if (_existingProfile.StarfaceAddressBook != null)
|
if (_existingProfile.StarfaceAddressBook != null)
|
||||||
@@ -178,6 +177,26 @@ namespace StarfaceOutlookSync.UI
|
|||||||
_cmbAddressBook.SelectedIndex = 0;
|
_cmbAddressBook.SelectedIndex = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (_outlookFolderPaths.Count > 0)
|
||||||
|
{
|
||||||
|
// Standard-Ordner vorauswaehlen
|
||||||
|
_selectedOutlookPath = _outlookFolderPaths[0];
|
||||||
|
_selectedOutlookName = _selectedOutlookPath.Substring(_selectedOutlookPath.LastIndexOf('\\') + 1);
|
||||||
|
_txtOutlookFolder.Text = _selectedOutlookPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void BrowseOutlookFolder()
|
||||||
|
{
|
||||||
|
using (var browser = new OutlookFolderBrowserForm(_outlookFolderPaths, _selectedOutlookPath))
|
||||||
|
{
|
||||||
|
if (browser.ShowDialog(this) == DialogResult.OK)
|
||||||
|
{
|
||||||
|
_selectedOutlookPath = browser.SelectedFolderPath;
|
||||||
|
_selectedOutlookName = browser.SelectedFolderName;
|
||||||
|
_txtOutlookFolder.Text = _selectedOutlookPath;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private StarfaceConnection GetConnection()
|
private StarfaceConnection GetConnection()
|
||||||
@@ -292,10 +311,12 @@ namespace StarfaceOutlookSync.UI
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectedFolder = _cmbOutlookFolder.SelectedItem?.ToString() ?? "";
|
if (string.IsNullOrEmpty(_selectedOutlookPath))
|
||||||
var folderName = selectedFolder;
|
{
|
||||||
if (folderName.Contains("\\"))
|
MessageBox.Show("Bitte einen Outlook-Kontaktordner waehlen.",
|
||||||
folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
|
"Fehler", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var profile = new SyncProfile
|
var profile = new SyncProfile
|
||||||
{
|
{
|
||||||
@@ -303,8 +324,8 @@ namespace StarfaceOutlookSync.UI
|
|||||||
Name = _txtName.Text.Trim(),
|
Name = _txtName.Text.Trim(),
|
||||||
StarfaceConnection = GetConnection(),
|
StarfaceConnection = GetConnection(),
|
||||||
StarfaceAddressBook = _addressBooks[_cmbAddressBook.SelectedIndex],
|
StarfaceAddressBook = _addressBooks[_cmbAddressBook.SelectedIndex],
|
||||||
OutlookFolderPath = selectedFolder,
|
OutlookFolderPath = _selectedOutlookPath,
|
||||||
OutlookFolderName = folderName,
|
OutlookFolderName = _selectedOutlookName,
|
||||||
SyncDirection = (SyncDirection)_cmbDirection.SelectedIndex,
|
SyncDirection = (SyncDirection)_cmbDirection.SelectedIndex,
|
||||||
Enabled = _chkEnabled.Checked,
|
Enabled = _chkEnabled.Checked,
|
||||||
AutoSyncIntervalMinutes = (int)_numAutoSync.Value,
|
AutoSyncIntervalMinutes = (int)_numAutoSync.Value,
|
||||||
|
|||||||
@@ -0,0 +1,62 @@
|
|||||||
|
using System.Drawing;
|
||||||
|
using System.Windows.Forms;
|
||||||
|
using StarfaceOutlookSync.Models;
|
||||||
|
|
||||||
|
namespace StarfaceOutlookSync.UI
|
||||||
|
{
|
||||||
|
public class SettingsForm : Form
|
||||||
|
{
|
||||||
|
private CheckBox _chkStartMinimized;
|
||||||
|
private Button _btnSave, _btnCancel;
|
||||||
|
private readonly UserSettings _settings;
|
||||||
|
|
||||||
|
public SettingsForm()
|
||||||
|
{
|
||||||
|
_settings = UserSettings.Load();
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void InitializeComponent()
|
||||||
|
{
|
||||||
|
Text = "Einstellungen";
|
||||||
|
Size = new Size(350, 180);
|
||||||
|
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||||
|
MaximizeBox = false;
|
||||||
|
MinimizeBox = false;
|
||||||
|
StartPosition = FormStartPosition.CenterParent;
|
||||||
|
Font = new Font("Segoe UI", 9);
|
||||||
|
|
||||||
|
_chkStartMinimized = new CheckBox
|
||||||
|
{
|
||||||
|
Text = "Minimiert starten (nur im System Tray)",
|
||||||
|
Left = 20, Top = 24, AutoSize = true,
|
||||||
|
Checked = _settings.StartMinimized
|
||||||
|
};
|
||||||
|
|
||||||
|
_btnSave = new Button
|
||||||
|
{
|
||||||
|
Text = "Speichern", Left = 80, Top = 100, Width = 85, Height = 28,
|
||||||
|
DialogResult = DialogResult.None
|
||||||
|
};
|
||||||
|
_btnSave.Click += (s, e) => Save();
|
||||||
|
|
||||||
|
_btnCancel = new Button
|
||||||
|
{
|
||||||
|
Text = "Abbrechen", Left = 174, Top = 100, Width = 85, Height = 28,
|
||||||
|
DialogResult = DialogResult.Cancel
|
||||||
|
};
|
||||||
|
|
||||||
|
Controls.AddRange(new Control[] { _chkStartMinimized, _btnSave, _btnCancel });
|
||||||
|
AcceptButton = _btnSave;
|
||||||
|
CancelButton = _btnCancel;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Save()
|
||||||
|
{
|
||||||
|
_settings.StartMinimized = _chkStartMinimized.Checked;
|
||||||
|
_settings.Save();
|
||||||
|
DialogResult = DialogResult.OK;
|
||||||
|
Close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user