Rewrite as standalone C# WinForms app
Replace the Office Web Add-in with a native Windows application. The web add-in required Exchange/M365 for registration which is not available in all customer environments (standalone Office, POP/IMAP only). The new app: - Uses COM Interop to access Outlook contacts directly - Communicates with Starface REST API (accepts self-signed certs) - Runs as System Tray app with optional auto-sync - Profile-based config stored in %AppData% - No webserver, no certificates, no Exchange, no M365 needed - Inno Setup installer for clean MSI-style deployment - Works with any Outlook version (Classic and New) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,323 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using StarfaceOutlookSync.Models;
|
||||
using StarfaceOutlookSync.Services;
|
||||
|
||||
namespace StarfaceOutlookSync.UI
|
||||
{
|
||||
public class ProfileEditorForm : Form
|
||||
{
|
||||
private readonly ProfileManager _pm = new ProfileManager();
|
||||
private readonly SyncProfile _existingProfile;
|
||||
private readonly bool _isNew;
|
||||
|
||||
// Controls
|
||||
private TextBox _txtName, _txtHost, _txtPort, _txtLoginId, _txtPassword;
|
||||
private CheckBox _chkSsl, _chkEnabled;
|
||||
private ComboBox _cmbAddressBook, _cmbOutlookFolder, _cmbDirection;
|
||||
private NumericUpDown _numAutoSync;
|
||||
private Button _btnTest, _btnLoadBooks, _btnSave, _btnCancel;
|
||||
private Label _lblTestResult;
|
||||
|
||||
private List<StarfaceAddressBook> _addressBooks = new List<StarfaceAddressBook>();
|
||||
|
||||
public ProfileEditorForm(SyncProfile profile)
|
||||
{
|
||||
_existingProfile = profile;
|
||||
_isNew = profile == null;
|
||||
InitializeComponent();
|
||||
LoadData();
|
||||
}
|
||||
|
||||
private void InitializeComponent()
|
||||
{
|
||||
Text = _isNew ? "Neues Sync-Profil" : "Profil bearbeiten";
|
||||
Size = new Size(480, 620);
|
||||
FormBorderStyle = FormBorderStyle.FixedDialog;
|
||||
MaximizeBox = false;
|
||||
MinimizeBox = false;
|
||||
StartPosition = FormStartPosition.CenterParent;
|
||||
Font = new Font("Segoe UI", 9);
|
||||
|
||||
var panel = new Panel { Dock = DockStyle.Fill, AutoScroll = true, Padding = new Padding(16) };
|
||||
int y = 8;
|
||||
|
||||
// Profilname
|
||||
panel.Controls.Add(MakeLabel("Profilname:", 12, y)); y += 22;
|
||||
_txtName = new TextBox { Left = 12, Top = y, Width = 420 }; panel.Controls.Add(_txtName); y += 32;
|
||||
|
||||
// === Starface ===
|
||||
panel.Controls.Add(MakeSectionLabel("Starface-Verbindung", 12, y)); y += 26;
|
||||
|
||||
panel.Controls.Add(MakeLabel("Host / IP-Adresse:", 12, y)); y += 22;
|
||||
_txtHost = new TextBox { Left = 12, Top = y, Width = 320 };
|
||||
_txtPort = new TextBox { Left = 340, Top = y, Width = 60, Text = "443" };
|
||||
panel.Controls.Add(_txtHost);
|
||||
panel.Controls.Add(MakeLabel("Port:", 340, y - 22));
|
||||
panel.Controls.Add(_txtPort); y += 32;
|
||||
|
||||
_chkSsl = new CheckBox { Text = "HTTPS verwenden", Left = 12, Top = y, Checked = true, AutoSize = true };
|
||||
panel.Controls.Add(_chkSsl); y += 28;
|
||||
|
||||
panel.Controls.Add(MakeLabel("Login-ID:", 12, y)); y += 22;
|
||||
_txtLoginId = new TextBox { Left = 12, Top = y, Width = 200 }; panel.Controls.Add(_txtLoginId); y += 32;
|
||||
|
||||
panel.Controls.Add(MakeLabel("Kennwort:", 12, y)); y += 22;
|
||||
_txtPassword = new TextBox { Left = 12, Top = y, Width = 200, UseSystemPasswordChar = true };
|
||||
panel.Controls.Add(_txtPassword); y += 32;
|
||||
|
||||
_btnTest = new Button { Text = "Verbindung testen", Left = 12, Top = y, Width = 130, Height = 28 };
|
||||
_btnTest.Click += async (s, e) => await TestConnection();
|
||||
_btnLoadBooks = new Button { Text = "Adressbuecher laden", Left = 150, Top = y, Width = 140, Height = 28 };
|
||||
_btnLoadBooks.Click += async (s, e) => await LoadAddressBooks();
|
||||
panel.Controls.Add(_btnTest);
|
||||
panel.Controls.Add(_btnLoadBooks); y += 32;
|
||||
|
||||
_lblTestResult = new Label { Left = 12, Top = y, Width = 420, Height = 20, ForeColor = Color.Gray };
|
||||
panel.Controls.Add(_lblTestResult); y += 26;
|
||||
|
||||
panel.Controls.Add(MakeLabel("Starface-Adressbuch:", 12, y)); y += 22;
|
||||
_cmbAddressBook = new ComboBox { Left = 12, Top = y, Width = 420, DropDownStyle = ComboBoxStyle.DropDownList };
|
||||
panel.Controls.Add(_cmbAddressBook); y += 32;
|
||||
|
||||
// === Outlook ===
|
||||
panel.Controls.Add(MakeSectionLabel("Outlook-Einstellungen", 12, y)); y += 26;
|
||||
|
||||
panel.Controls.Add(MakeLabel("Kontakte-Ordner:", 12, y)); y += 22;
|
||||
_cmbOutlookFolder = new ComboBox { Left = 12, Top = y, Width = 420, DropDownStyle = ComboBoxStyle.DropDownList };
|
||||
panel.Controls.Add(_cmbOutlookFolder); y += 32;
|
||||
|
||||
panel.Controls.Add(MakeLabel("Sync-Richtung:", 12, y)); y += 22;
|
||||
_cmbDirection = new ComboBox { Left = 12, Top = y, Width = 250, DropDownStyle = ComboBoxStyle.DropDownList };
|
||||
_cmbDirection.Items.AddRange(new object[] { "Bidirektional", "Outlook -> Starface", "Starface -> Outlook" });
|
||||
_cmbDirection.SelectedIndex = 0;
|
||||
panel.Controls.Add(_cmbDirection); y += 32;
|
||||
|
||||
panel.Controls.Add(MakeLabel("Auto-Sync Intervall (Minuten, 0 = manuell):", 12, y)); y += 22;
|
||||
_numAutoSync = new NumericUpDown { Left = 12, Top = y, Width = 80, Minimum = 0, Maximum = 1440, Value = 0 };
|
||||
panel.Controls.Add(_numAutoSync); y += 32;
|
||||
|
||||
_chkEnabled = new CheckBox { Text = "Profil aktiviert", Left = 12, Top = y, Checked = true, AutoSize = true };
|
||||
panel.Controls.Add(_chkEnabled); y += 36;
|
||||
|
||||
// Buttons
|
||||
_btnSave = new Button { Text = "Speichern", Left = 12, Top = y, Width = 100, Height = 30, DialogResult = DialogResult.None };
|
||||
_btnSave.Click += (s, e) => SaveProfile();
|
||||
_btnCancel = new Button { Text = "Abbrechen", Left = 120, Top = y, Width = 100, Height = 30, DialogResult = DialogResult.Cancel };
|
||||
panel.Controls.Add(_btnSave);
|
||||
panel.Controls.Add(_btnCancel);
|
||||
|
||||
Controls.Add(panel);
|
||||
AcceptButton = _btnSave;
|
||||
CancelButton = _btnCancel;
|
||||
}
|
||||
|
||||
private Label MakeLabel(string text, int x, int y)
|
||||
{
|
||||
return new Label { Text = text, Left = x, Top = y, AutoSize = true };
|
||||
}
|
||||
|
||||
private Label MakeSectionLabel(string text, int x, int y)
|
||||
{
|
||||
return new Label { Text = text, Left = x, Top = y, AutoSize = true, Font = new Font("Segoe UI", 10, FontStyle.Bold) };
|
||||
}
|
||||
|
||||
private void LoadData()
|
||||
{
|
||||
// Outlook-Ordner laden
|
||||
try
|
||||
{
|
||||
using (var outlook = new OutlookContactsService())
|
||||
{
|
||||
var folders = outlook.GetContactFolderPaths();
|
||||
_cmbOutlookFolder.Items.Clear();
|
||||
foreach (var f in folders)
|
||||
_cmbOutlookFolder.Items.Add(f);
|
||||
if (folders.Count > 0)
|
||||
_cmbOutlookFolder.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
_cmbOutlookFolder.Items.Add("\\\\Kontakte");
|
||||
_cmbOutlookFolder.SelectedIndex = 0;
|
||||
}
|
||||
|
||||
// Bestehende Werte laden
|
||||
if (_existingProfile != null)
|
||||
{
|
||||
_txtName.Text = _existingProfile.Name;
|
||||
_txtHost.Text = _existingProfile.StarfaceConnection.Host;
|
||||
_txtPort.Text = _existingProfile.StarfaceConnection.Port.ToString();
|
||||
_chkSsl.Checked = _existingProfile.StarfaceConnection.UseSsl;
|
||||
_txtLoginId.Text = _existingProfile.StarfaceConnection.LoginId;
|
||||
_txtPassword.Text = _existingProfile.StarfaceConnection.Password;
|
||||
_chkEnabled.Checked = _existingProfile.Enabled;
|
||||
_numAutoSync.Value = _existingProfile.AutoSyncIntervalMinutes;
|
||||
|
||||
_cmbDirection.SelectedIndex = (int)_existingProfile.SyncDirection;
|
||||
|
||||
// Outlook-Ordner auswaehlen
|
||||
for (int i = 0; i < _cmbOutlookFolder.Items.Count; i++)
|
||||
{
|
||||
if (_cmbOutlookFolder.Items[i].ToString() == _existingProfile.OutlookFolderPath)
|
||||
{
|
||||
_cmbOutlookFolder.SelectedIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Adressbuch
|
||||
if (_existingProfile.StarfaceAddressBook != null)
|
||||
{
|
||||
_addressBooks.Add(_existingProfile.StarfaceAddressBook);
|
||||
_cmbAddressBook.Items.Add(_existingProfile.StarfaceAddressBook.Name);
|
||||
_cmbAddressBook.SelectedIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private StarfaceConnection GetConnection()
|
||||
{
|
||||
return new StarfaceConnection
|
||||
{
|
||||
Host = _txtHost.Text.Trim(),
|
||||
Port = int.TryParse(_txtPort.Text, out var p) ? p : 443,
|
||||
UseSsl = _chkSsl.Checked,
|
||||
LoginId = _txtLoginId.Text.Trim(),
|
||||
Password = _txtPassword.Text
|
||||
};
|
||||
}
|
||||
|
||||
private async Task TestConnection()
|
||||
{
|
||||
_lblTestResult.Text = "Teste Verbindung...";
|
||||
_lblTestResult.ForeColor = Color.Gray;
|
||||
_btnTest.Enabled = false;
|
||||
|
||||
try
|
||||
{
|
||||
using (var client = new StarfaceApiClient(GetConnection()))
|
||||
{
|
||||
var ok = await client.LoginAsync();
|
||||
if (ok)
|
||||
{
|
||||
_lblTestResult.Text = "Verbindung erfolgreich!";
|
||||
_lblTestResult.ForeColor = Color.Green;
|
||||
await client.LogoutAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
_lblTestResult.Text = "Login fehlgeschlagen. Zugangsdaten pruefen.";
|
||||
_lblTestResult.ForeColor = Color.Red;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_lblTestResult.Text = $"Fehler: {ex.Message}";
|
||||
_lblTestResult.ForeColor = Color.Red;
|
||||
}
|
||||
|
||||
_btnTest.Enabled = true;
|
||||
}
|
||||
|
||||
private async Task LoadAddressBooks()
|
||||
{
|
||||
_lblTestResult.Text = "Lade Adressbuecher...";
|
||||
_lblTestResult.ForeColor = Color.Gray;
|
||||
_btnLoadBooks.Enabled = false;
|
||||
|
||||
try
|
||||
{
|
||||
using (var client = new StarfaceApiClient(GetConnection()))
|
||||
{
|
||||
var ok = await client.LoginAsync();
|
||||
if (!ok)
|
||||
{
|
||||
_lblTestResult.Text = "Login fehlgeschlagen.";
|
||||
_lblTestResult.ForeColor = Color.Red;
|
||||
_btnLoadBooks.Enabled = true;
|
||||
return;
|
||||
}
|
||||
|
||||
_addressBooks = await client.GetAddressBooksAsync();
|
||||
await client.LogoutAsync();
|
||||
|
||||
_cmbAddressBook.Items.Clear();
|
||||
foreach (var book in _addressBooks)
|
||||
_cmbAddressBook.Items.Add(book.Name);
|
||||
|
||||
if (_addressBooks.Count > 0)
|
||||
{
|
||||
_cmbAddressBook.SelectedIndex = 0;
|
||||
_lblTestResult.Text = $"{_addressBooks.Count} Adressbuch/buecher gefunden.";
|
||||
_lblTestResult.ForeColor = Color.Green;
|
||||
}
|
||||
else
|
||||
{
|
||||
_lblTestResult.Text = "Keine Adressbuecher gefunden.";
|
||||
_lblTestResult.ForeColor = Color.Orange;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_lblTestResult.Text = $"Fehler: {ex.Message}";
|
||||
_lblTestResult.ForeColor = Color.Red;
|
||||
}
|
||||
|
||||
_btnLoadBooks.Enabled = true;
|
||||
}
|
||||
|
||||
private void SaveProfile()
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(_txtName.Text))
|
||||
{
|
||||
MessageBox.Show("Bitte Profilnamen eingeben.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(_txtHost.Text))
|
||||
{
|
||||
MessageBox.Show("Bitte Starface-Host eingeben.", "Fehler", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
if (_cmbAddressBook.SelectedIndex < 0 || _addressBooks.Count == 0)
|
||||
{
|
||||
MessageBox.Show("Bitte ein Starface-Adressbuch auswaehlen.\nZuerst 'Adressbuecher laden' klicken.",
|
||||
"Fehler", MessageBoxButtons.OK, MessageBoxIcon.Warning);
|
||||
return;
|
||||
}
|
||||
|
||||
var selectedFolder = _cmbOutlookFolder.SelectedItem?.ToString() ?? "";
|
||||
var folderName = selectedFolder;
|
||||
if (folderName.Contains("\\"))
|
||||
folderName = folderName.Substring(folderName.LastIndexOf('\\') + 1);
|
||||
|
||||
var profile = new SyncProfile
|
||||
{
|
||||
Id = _existingProfile?.Id ?? _pm.GenerateId(),
|
||||
Name = _txtName.Text.Trim(),
|
||||
StarfaceConnection = GetConnection(),
|
||||
StarfaceAddressBook = _addressBooks[_cmbAddressBook.SelectedIndex],
|
||||
OutlookFolderPath = selectedFolder,
|
||||
OutlookFolderName = folderName,
|
||||
SyncDirection = (SyncDirection)_cmbDirection.SelectedIndex,
|
||||
Enabled = _chkEnabled.Checked,
|
||||
AutoSyncIntervalMinutes = (int)_numAutoSync.Value,
|
||||
LastSync = _existingProfile?.LastSync ?? ""
|
||||
};
|
||||
|
||||
if (_isNew)
|
||||
_pm.AddProfile(profile);
|
||||
else
|
||||
_pm.UpdateProfile(profile);
|
||||
|
||||
DialogResult = DialogResult.OK;
|
||||
Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user