Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6a51a58224 | |||
| 9b451c9cbe | |||
| 35ce8facff | |||
| c685f4f91d | |||
| 5eae3da213 |
@@ -258,15 +258,21 @@ jobs:
|
||||
& msbuild @msbuildArgs
|
||||
if ($LASTEXITCODE -ne 0) { throw "msbuild /t:Publish failed with $LASTEXITCODE" }
|
||||
|
||||
# Sanity check: did the VSTO publish target produce a .vsto file?
|
||||
$vsto = Get-ChildItem -Recurse -Filter '*.vsto' -Path publish | Select-Object -First 1
|
||||
if (-not $vsto) { throw "msbuild /t:Publish completed but no .vsto file found under publish/" }
|
||||
# Sanity check + rename to canonical OutlookAddin.vsto so the URL
|
||||
# matches PROVIDER_URL (hardcoded to .../OutlookAddin.vsto). Restrict
|
||||
# to publish/ root -- there's a second .vsto inside Application Files
|
||||
# that must keep its versioned name. Verify the renamed file exists
|
||||
# before continuing; v1.2.11 shipped broken because a silent failure
|
||||
# here left no OutlookAddin.vsto in the tar and 404'd the CDN.
|
||||
$vsto = Get-ChildItem -File -Filter '*.vsto' -Path publish | Select-Object -First 1
|
||||
if (-not $vsto) { throw "msbuild /t:Publish completed but no .vsto file found at publish/ root" }
|
||||
Write-Host " produced $($vsto.FullName)"
|
||||
|
||||
# Rename to canonical OutlookAddin.vsto so the ClickOnce manifest
|
||||
# URL matches PROVIDER_URL (which is hardcoded to .../OutlookAddin.vsto).
|
||||
if ($vsto.Name -ne 'OutlookAddin.vsto') {
|
||||
Rename-Item -LiteralPath $vsto.FullName -NewName 'OutlookAddin.vsto'
|
||||
Rename-Item -LiteralPath $vsto.FullName -NewName 'OutlookAddin.vsto' -ErrorAction Stop
|
||||
Write-Host " renamed -> OutlookAddin.vsto"
|
||||
}
|
||||
if (-not (Test-Path 'publish/OutlookAddin.vsto')) {
|
||||
throw "post-rename: publish/OutlookAddin.vsto does not exist"
|
||||
}
|
||||
|
||||
Write-Host "=== STEP F: stage protocol handler ==="
|
||||
|
||||
@@ -213,13 +213,29 @@ namespace MarcusLaw.OutlookAddin.Core.Services
|
||||
// is sent in the "file" field as a data-URI. The previous extra
|
||||
// "contents" alias was an undocumented legacy that strict tenants
|
||||
// reject with 400.
|
||||
//
|
||||
// We bind the upload to Note.attachments (parentType=Note,
|
||||
// field=attachments). EspoCRM's attachment access checker now
|
||||
// REJECTS a role=Attachment upload that carries neither `field`
|
||||
// nor `parentType` ("No `field` and `parentType`." → 400) — the
|
||||
// earlier "unbound blob" shape no longer passes. Note.attachments
|
||||
// is the documented Attachment-Multiple example and a built-in
|
||||
// field that carries NO "allowed file types" restriction, so every
|
||||
// file type (PDF, JPEG, PNG, …) passes — unlike Document.file,
|
||||
// which Marcus-Law limits to PDF/Word and which rejected images
|
||||
// with 403 "Not allowed file type".
|
||||
//
|
||||
// We never set parentId / create a Note: the attachment stays a
|
||||
// standalone blob whose id we immediately push to the network
|
||||
// share. The (parentType, field) pair only satisfies the access
|
||||
// checker and selects an unrestricted file-type policy.
|
||||
var payload = new Dictionary<string, object?>
|
||||
{
|
||||
["name"] = fileName,
|
||||
["type"] = mime,
|
||||
["role"] = "Attachment",
|
||||
["relatedType"] = "Document",
|
||||
["field"] = "file",
|
||||
["parentType"] = "Note",
|
||||
["field"] = "attachments",
|
||||
["file"] = dataUri
|
||||
};
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:conv="clr-namespace:MarcusLaw.OutlookAddin.UI.Converters"
|
||||
Title="שמור קבצים מצורפים ל-Klear"
|
||||
Height="560" Width="620"
|
||||
MinHeight="420" MinWidth="500"
|
||||
Height="640" Width="620"
|
||||
MinHeight="480" MinWidth="500"
|
||||
FlowDirection="RightToLeft"
|
||||
WindowStartupLocation="CenterOwner"
|
||||
ShowInTaskbar="False"
|
||||
@@ -144,24 +144,38 @@
|
||||
|
||||
<!-- Folder -->
|
||||
<DockPanel Grid.Row="2" Margin="0,10,0,0" LastChildFill="True">
|
||||
<TextBlock DockPanel.Dock="Left" Text="תיקייה:" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0" Foreground="{StaticResource Muted}" FontSize="12" />
|
||||
<TextBlock DockPanel.Dock="Right" Text="טוען…" VerticalAlignment="Center"
|
||||
Margin="8,0,0,0" Foreground="{StaticResource Muted}" FontSize="12"
|
||||
Visibility="{Binding IsLoadingSubfolders, Converter={StaticResource BoolToVis}}" />
|
||||
<ComboBox ItemsSource="{Binding Subfolders}"
|
||||
SelectedItem="{Binding SelectedSubfolder}"
|
||||
Padding="6,4">
|
||||
<ComboBox.Style>
|
||||
<Style TargetType="ComboBox">
|
||||
<Style.Triggers>
|
||||
<DataTrigger Binding="{Binding IsLoadingSubfolders}" Value="True">
|
||||
<Setter Property="IsEnabled" Value="False" />
|
||||
</DataTrigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ComboBox.Style>
|
||||
</ComboBox>
|
||||
<DockPanel DockPanel.Dock="Top" LastChildFill="True" Margin="0,0,0,4">
|
||||
<TextBlock DockPanel.Dock="Left" Text="תיקיית יעד:" VerticalAlignment="Center"
|
||||
Margin="0,0,8,0" Foreground="{StaticResource Muted}" FontSize="12" />
|
||||
<TextBlock DockPanel.Dock="Right" Text="טוען…" VerticalAlignment="Center"
|
||||
Margin="8,0,0,0" Foreground="{StaticResource Muted}" FontSize="12"
|
||||
Visibility="{Binding IsLoadingSubfolders, Converter={StaticResource BoolToVis}}" />
|
||||
<TextBlock Text="בחר/י תיקייה או תת-תיקייה לשמירה (ניתן להרחיב רמות)"
|
||||
VerticalAlignment="Center" Foreground="{StaticResource Muted}" FontSize="11"
|
||||
TextTrimming="CharacterEllipsis" />
|
||||
</DockPanel>
|
||||
<Border Style="{StaticResource Card}" MaxHeight="150">
|
||||
<TreeView x:Name="FolderTreeView"
|
||||
ItemsSource="{Binding FolderTree}"
|
||||
BorderThickness="0"
|
||||
Background="Transparent"
|
||||
SelectedItemChanged="FolderTreeView_SelectedItemChanged">
|
||||
<TreeView.ItemContainerStyle>
|
||||
<Style TargetType="TreeViewItem">
|
||||
<Setter Property="IsExpanded" Value="{Binding IsExpanded, Mode=TwoWay}" />
|
||||
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
|
||||
</Style>
|
||||
</TreeView.ItemContainerStyle>
|
||||
<TreeView.ItemTemplate>
|
||||
<HierarchicalDataTemplate ItemsSource="{Binding Children}">
|
||||
<StackPanel Orientation="Horizontal" Margin="0,1">
|
||||
<TextBlock Text="📁" Margin="0,0,4,0" FontSize="13" VerticalAlignment="Center" />
|
||||
<TextBlock Text="{Binding Name}" VerticalAlignment="Center" FontSize="13" />
|
||||
</StackPanel>
|
||||
</HierarchicalDataTemplate>
|
||||
</TreeView.ItemTemplate>
|
||||
</TreeView>
|
||||
</Border>
|
||||
</DockPanel>
|
||||
|
||||
<!-- Attachments header -->
|
||||
|
||||
@@ -32,5 +32,15 @@ namespace MarcusLaw.OutlookAddin.UI.Dialogs
|
||||
DialogResult = _viewModel?.DialogResult;
|
||||
Close();
|
||||
}
|
||||
|
||||
// WPF's TreeView.SelectedItem is read-only, so we mirror the selection
|
||||
// into the view-model here (the chosen node drives the save target).
|
||||
private void FolderTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
|
||||
{
|
||||
if (_viewModel != null)
|
||||
{
|
||||
_viewModel.SelectedFolder = e.NewValue as FolderNodeViewModel;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,168 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using MarcusLaw.OutlookAddin.Core.Services;
|
||||
using Serilog;
|
||||
|
||||
namespace MarcusLaw.OutlookAddin.UI.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// One node in the network-storage folder tree shown by the
|
||||
/// save-attachments dialog. Children are listed lazily the first time the
|
||||
/// node is expanded, so the user can drill into nested subfolders to any
|
||||
/// depth without us listing the whole tree up front.
|
||||
/// </summary>
|
||||
public sealed partial class FolderNodeViewModel : ObservableObject
|
||||
{
|
||||
private readonly IEspoCrmClient? _client;
|
||||
private readonly ILogger? _logger;
|
||||
private readonly Dispatcher? _dispatcher;
|
||||
private bool _childrenLoaded;
|
||||
private bool _loadingStarted;
|
||||
|
||||
/// <summary>Label shown in the tree.</summary>
|
||||
public string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Path relative to the share root (e.g. "56-ליאור זייני/מסמכים").
|
||||
/// Used to list this folder's children. Empty for placeholders.
|
||||
/// </summary>
|
||||
public string FullPath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Path relative to the case-root folder (e.g. "מסמכים/רפואי"), or
|
||||
/// null for the case-root node itself. This is what the save target
|
||||
/// appends to the resolved case folder.
|
||||
/// </summary>
|
||||
public string? RelativePath { get; }
|
||||
|
||||
/// <summary>True for the transient "loading…" child placeholder.</summary>
|
||||
public bool IsPlaceholder { get; }
|
||||
|
||||
public bool IsRoot => !IsPlaceholder && RelativePath == null;
|
||||
|
||||
public ObservableCollection<FolderNodeViewModel> Children { get; } =
|
||||
new ObservableCollection<FolderNodeViewModel>();
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isExpanded;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isSelected;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool isLoading;
|
||||
|
||||
/// <summary>Real folder node.</summary>
|
||||
public FolderNodeViewModel(
|
||||
IEspoCrmClient client,
|
||||
ILogger logger,
|
||||
Dispatcher dispatcher,
|
||||
string name,
|
||||
string fullPath,
|
||||
string? relativePath)
|
||||
{
|
||||
_client = client ?? throw new ArgumentNullException(nameof(client));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
_dispatcher = dispatcher ?? throw new ArgumentNullException(nameof(dispatcher));
|
||||
Name = name;
|
||||
FullPath = fullPath;
|
||||
RelativePath = relativePath;
|
||||
// A placeholder child makes the expand chevron appear before we've
|
||||
// listed; expanding swaps it for the real children (or, if there
|
||||
// are none, the node becomes a leaf).
|
||||
Children.Add(new FolderNodeViewModel());
|
||||
}
|
||||
|
||||
/// <summary>Placeholder ("loading…") node constructor.</summary>
|
||||
private FolderNodeViewModel()
|
||||
{
|
||||
Name = "טוען…";
|
||||
FullPath = string.Empty;
|
||||
RelativePath = string.Empty;
|
||||
IsPlaceholder = true;
|
||||
_childrenLoaded = true;
|
||||
}
|
||||
|
||||
partial void OnIsExpandedChanged(bool value)
|
||||
{
|
||||
if (value && !_childrenLoaded && !_loadingStarted)
|
||||
{
|
||||
_loadingStarted = true;
|
||||
_ = LoadChildrenAsync();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Lists this folder's subfolders and replaces the placeholder with
|
||||
/// real child nodes. <paramref name="seedNames"/> (used for the root)
|
||||
/// guarantees the default case subfolders show even if the share
|
||||
/// listing lags or omits a not-yet-created folder.
|
||||
/// </summary>
|
||||
public async Task LoadChildrenAsync(IEnumerable<string>? seedNames = null)
|
||||
{
|
||||
if (_client == null) return;
|
||||
IsLoading = true;
|
||||
|
||||
// Build into a local list and swap once at the end. The seeds are
|
||||
// added first so that even if the share listing fails the default
|
||||
// subfolders still show; on failure for a non-seeded node the list
|
||||
// is empty and the node reads as a leaf rather than "loading…".
|
||||
var seen = new HashSet<string>(StringComparer.Ordinal);
|
||||
var loaded = new List<FolderNodeViewModel>();
|
||||
if (seedNames != null)
|
||||
{
|
||||
foreach (var n in seedNames)
|
||||
{
|
||||
if (seen.Add(n)) loaded.Add(MakeChild(n));
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
var items = await _client.ListNetworkStorageFolderAsync(FullPath).ConfigureAwait(true);
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (!item.IsFolder) continue;
|
||||
if (!seen.Add(item.Name)) continue;
|
||||
loaded.Add(MakeChild(item.Name));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger?.Warning(ex, "Listing subfolders under '{Path}' failed", FullPath);
|
||||
}
|
||||
finally
|
||||
{
|
||||
// Marshal onto the Dispatcher: once this node's TreeViewItem
|
||||
// exists, Children is bound and must only be mutated on the UI
|
||||
// thread (the network await above can resume on a thread-pool
|
||||
// thread in this VSTO host).
|
||||
OnUi(() =>
|
||||
{
|
||||
Children.Clear();
|
||||
foreach (var child in loaded) Children.Add(child);
|
||||
});
|
||||
_childrenLoaded = true;
|
||||
IsLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
private FolderNodeViewModel MakeChild(string name)
|
||||
{
|
||||
var fullPath = string.IsNullOrEmpty(FullPath) ? name : FullPath + "/" + name;
|
||||
var relativePath = IsRoot ? name : RelativePath + "/" + name;
|
||||
return new FolderNodeViewModel(_client!, _logger!, _dispatcher!, name, fullPath, relativePath);
|
||||
}
|
||||
|
||||
private void OnUi(Action action)
|
||||
{
|
||||
var d = _dispatcher;
|
||||
if (d == null || d.CheckAccess()) action();
|
||||
else d.Invoke(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Threading;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using MarcusLaw.OutlookAddin.Core.Models;
|
||||
@@ -31,6 +32,7 @@ namespace MarcusLaw.OutlookAddin.UI.ViewModels
|
||||
|
||||
private readonly IEspoCrmClient _client;
|
||||
private readonly ILogger _logger;
|
||||
private readonly Dispatcher _dispatcher;
|
||||
private CancellationTokenSource? _searchCts;
|
||||
|
||||
[ObservableProperty]
|
||||
@@ -40,7 +42,7 @@ namespace MarcusLaw.OutlookAddin.UI.ViewModels
|
||||
private CaseEntity? selectedCase;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? selectedSubfolder;
|
||||
private FolderNodeViewModel? selectedFolder;
|
||||
|
||||
[ObservableProperty]
|
||||
private string? statusMessage;
|
||||
@@ -58,7 +60,12 @@ namespace MarcusLaw.OutlookAddin.UI.ViewModels
|
||||
|
||||
public ObservableCollection<CaseEntity> Cases { get; } = new ObservableCollection<CaseEntity>();
|
||||
|
||||
public ObservableCollection<string> Subfolders { get; } = new ObservableCollection<string>();
|
||||
/// <summary>
|
||||
/// Folder tree for the selected case. Holds a single root node (the
|
||||
/// case folder); its children are the subfolders, loaded lazily so the
|
||||
/// user can drill into any nesting depth.
|
||||
/// </summary>
|
||||
public ObservableCollection<FolderNodeViewModel> FolderTree { get; } = new ObservableCollection<FolderNodeViewModel>();
|
||||
|
||||
public ObservableCollection<AttachmentRowViewModel> Attachments { get; } = new ObservableCollection<AttachmentRowViewModel>();
|
||||
|
||||
@@ -78,14 +85,20 @@ namespace MarcusLaw.OutlookAddin.UI.ViewModels
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subfolder string the user picked, or null to save to the case
|
||||
/// folder root.
|
||||
/// Folder the user picked, as a path relative to the case folder
|
||||
/// (e.g. "מסמכים/רפואי"), or null to save to the case folder root.
|
||||
/// Multi-segment paths are honoured by the save target, which appends
|
||||
/// this to <see cref="ResolvedCaseFolderPath"/>.
|
||||
/// </summary>
|
||||
public string? ChosenSubfolderName =>
|
||||
string.IsNullOrEmpty(SelectedSubfolder) ||
|
||||
string.Equals(SelectedSubfolder, RootSentinel, StringComparison.Ordinal)
|
||||
? null
|
||||
: SelectedSubfolder;
|
||||
public string? ChosenSubfolderName
|
||||
{
|
||||
get
|
||||
{
|
||||
var f = SelectedFolder;
|
||||
if (f == null || f.IsPlaceholder || f.IsRoot) return null;
|
||||
return string.IsNullOrEmpty(f.RelativePath) ? null : f.RelativePath;
|
||||
}
|
||||
}
|
||||
|
||||
public CaseEntity? PickedCase => SelectedCase;
|
||||
|
||||
@@ -98,8 +111,15 @@ namespace MarcusLaw.OutlookAddin.UI.ViewModels
|
||||
{
|
||||
_client = client ?? throw new ArgumentNullException(nameof(client));
|
||||
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||
// Captured on the UI thread (the VM is constructed on the thread
|
||||
// that shows the dialog). Used to marshal ObservableCollection
|
||||
// mutations back onto the Dispatcher — in this VSTO host the WPF
|
||||
// SynchronizationContext is not installed, so ConfigureAwait(true)
|
||||
// resumes on a thread-pool thread and a bound-collection Add throws
|
||||
// "changes ... from a thread different from the Dispatcher thread".
|
||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||
|
||||
ResetSubfolders();
|
||||
ResetFolderTree();
|
||||
|
||||
foreach (var att in attachments)
|
||||
{
|
||||
@@ -107,12 +127,52 @@ namespace MarcusLaw.OutlookAddin.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private void ResetSubfolders()
|
||||
/// <summary>
|
||||
/// Seeds the case list with the cases already resolved for the mail's
|
||||
/// sender (from the sidebar match) so the user doesn't have to search
|
||||
/// for a client we've already identified. When exactly one case is
|
||||
/// known we auto-select it (which kicks the subfolder/folder-path
|
||||
/// resolve); with several we just show them and let the user pick.
|
||||
/// The user can still type in the search box to override — that
|
||||
/// repopulates <see cref="Cases"/> from a fresh server search.
|
||||
/// </summary>
|
||||
public void PreselectCases(IReadOnlyList<CaseEntity> cases)
|
||||
{
|
||||
Subfolders.Clear();
|
||||
Subfolders.Add(RootSentinel);
|
||||
foreach (var f in DefaultCaseSubfolders) Subfolders.Add(f);
|
||||
SelectedSubfolder = Subfolders[0];
|
||||
if (cases == null || cases.Count == 0) return;
|
||||
|
||||
Cases.Clear();
|
||||
foreach (var c in cases)
|
||||
{
|
||||
if (c == null || string.IsNullOrEmpty(c.Id)) continue;
|
||||
Cases.Add(c);
|
||||
}
|
||||
if (Cases.Count == 0) return;
|
||||
|
||||
if (Cases.Count == 1)
|
||||
{
|
||||
SelectedCase = Cases[0];
|
||||
StatusMessage = "התיק זוהה אוטומטית מהשולח";
|
||||
}
|
||||
else
|
||||
{
|
||||
StatusMessage = $"{Cases.Count} תיקים מקושרים לשולח — בחר/י תיק";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Runs <paramref name="action"/> on the UI/Dispatcher thread.</summary>
|
||||
private void OnUi(Action action)
|
||||
{
|
||||
if (_dispatcher.CheckAccess()) action();
|
||||
else _dispatcher.Invoke(action);
|
||||
}
|
||||
|
||||
private void ResetFolderTree()
|
||||
{
|
||||
OnUi(() =>
|
||||
{
|
||||
FolderTree.Clear();
|
||||
SelectedFolder = null;
|
||||
});
|
||||
}
|
||||
|
||||
partial void OnSearchTextChanged(string value)
|
||||
@@ -137,7 +197,7 @@ namespace MarcusLaw.OutlookAddin.UI.ViewModels
|
||||
/// </summary>
|
||||
public async Task RefreshSubfoldersForSelectedCaseAsync()
|
||||
{
|
||||
ResetSubfolders();
|
||||
ResetFolderTree();
|
||||
ResolvedCaseFolderPath = null;
|
||||
|
||||
var c = SelectedCase;
|
||||
@@ -188,21 +248,28 @@ namespace MarcusLaw.OutlookAddin.UI.ViewModels
|
||||
c.Id, c.Number ?? "(none)", primaryContactName ?? "(none)", c.NetworkStorageFolderPath ?? "(none)", folderPath);
|
||||
if (string.IsNullOrEmpty(folderPath)) return;
|
||||
|
||||
// Build the tree rooted at the case folder. The root node is
|
||||
// selected by default (→ save to case root, matching the previous
|
||||
// default), expanded, and seeded with the default subfolders so
|
||||
// they appear even before the share listing returns. Deeper levels
|
||||
// load lazily as the user expands them.
|
||||
var root = new FolderNodeViewModel(_client, _logger, _dispatcher, RootSentinel, folderPath, relativePath: null);
|
||||
OnUi(() =>
|
||||
{
|
||||
FolderTree.Add(root);
|
||||
SelectedFolder = root;
|
||||
root.IsSelected = true;
|
||||
});
|
||||
|
||||
try
|
||||
{
|
||||
var items = await _client.ListNetworkStorageFolderAsync(folderPath).ConfigureAwait(true);
|
||||
foreach (var item in items)
|
||||
{
|
||||
if (!item.IsFolder) continue;
|
||||
if (Subfolders.Contains(item.Name)) continue;
|
||||
if (string.Equals(item.Name, RootSentinel, StringComparison.Ordinal)) continue;
|
||||
Subfolders.Add(item.Name);
|
||||
}
|
||||
await root.LoadChildrenAsync(DefaultCaseSubfolders).ConfigureAwait(true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_logger.Warning(ex, "Listing subfolders for case {CaseId} failed", c.Id);
|
||||
}
|
||||
OnUi(() => root.IsExpanded = true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -257,6 +257,9 @@
|
||||
<EmbeddedResource Include="Ribbon\InspectorRibbon.xml">
|
||||
<LogicalName>OutlookAddin.Ribbon.InspectorRibbon.xml</LogicalName>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Ribbon\ReadMailRibbon.xml">
|
||||
<LogicalName>OutlookAddin.Ribbon.ReadMailRibbon.xml</LogicalName>
|
||||
</EmbeddedResource>
|
||||
<EmbeddedResource Include="Images\klear-file.png">
|
||||
<LogicalName>OutlookAddin.Images.klear-file.png</LogicalName>
|
||||
</EmbeddedResource>
|
||||
|
||||
@@ -33,6 +33,6 @@ using System.Security;
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.2.11.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.11.0")]
|
||||
[assembly: AssemblyVersion("1.2.16.0")]
|
||||
[assembly: AssemblyFileVersion("1.2.16.0")]
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace OutlookAddin.Ribbon
|
||||
{
|
||||
private const string ExplorerResource = "OutlookAddin.Ribbon.ExplorerRibbon.xml";
|
||||
private const string InspectorResource = "OutlookAddin.Ribbon.InspectorRibbon.xml";
|
||||
private const string ReadMailResource = "OutlookAddin.Ribbon.ReadMailRibbon.xml";
|
||||
|
||||
// Every button whose `getEnabled` depends on the current Explorer
|
||||
// selection must be re-evaluated on every SelectionChange — Office
|
||||
@@ -40,6 +41,8 @@ namespace OutlookAddin.Ribbon
|
||||
return LoadResource(ExplorerResource);
|
||||
case "Microsoft.Outlook.Mail.Compose":
|
||||
return LoadResource(InspectorResource);
|
||||
case "Microsoft.Outlook.Mail.Read":
|
||||
return LoadResource(ReadMailResource);
|
||||
default:
|
||||
return string.Empty;
|
||||
}
|
||||
@@ -77,6 +80,51 @@ namespace OutlookAddin.Ribbon
|
||||
_inspectorRibbon = ribbon;
|
||||
}
|
||||
|
||||
// The read-mail inspector ribbon loads fresh for each opened message,
|
||||
// so its getEnabled callback re-runs per window — no cached IRibbonUI
|
||||
// or invalidation is needed here.
|
||||
public void OnReadMailRibbonLoad(IRibbonUI ribbon)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enabled when the message open in this read inspector has at least
|
||||
/// one attachment. Mirrors <see cref="OnGetSaveAttachmentsEnabled"/>
|
||||
/// but reads the item from the Inspector context rather than the
|
||||
/// Explorer selection.
|
||||
/// </summary>
|
||||
public bool OnGetSaveAttachmentsInspectorEnabled(IRibbonControl control)
|
||||
{
|
||||
try
|
||||
{
|
||||
var inspector = control?.Context as Outlook.Inspector;
|
||||
if (inspector?.CurrentItem is not Outlook.MailItem mail) return false;
|
||||
var attachments = mail.Attachments;
|
||||
if (attachments == null) return false;
|
||||
return attachments.Count > 0;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSaveAttachmentsFromInspector(IRibbonControl control)
|
||||
{
|
||||
try
|
||||
{
|
||||
var inspector = control?.Context as Outlook.Inspector;
|
||||
if (inspector?.CurrentItem is Outlook.MailItem mail)
|
||||
{
|
||||
_ = Globals.ThisAddIn.AddInHost.LaunchSaveAttachmentsAsync(mail);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Globals.ThisAddIn.AddInHost.Logger.Warning(ex, "OnSaveAttachmentsFromInspector failed");
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnGetFileToEspoCrmEnabled(IRibbonControl control)
|
||||
{
|
||||
try
|
||||
@@ -206,6 +254,7 @@ namespace OutlookAddin.Ribbon
|
||||
{
|
||||
case "FileToEspoCrm": fileName = "klear-file.png"; break;
|
||||
case "SaveAttachments": fileName = "klear-attach.png"; break;
|
||||
case "SaveAttachmentsRead": fileName = "klear-attach.png"; break;
|
||||
case "ShowSidebar": fileName = "klear-sidebar.png"; break;
|
||||
case "OpenEspoCrmSettings": fileName = "klear-settings.png"; break;
|
||||
case "ComposeFromCase": fileName = "klear-compose.png"; break;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="OnReadMailRibbonLoad">
|
||||
<ribbon>
|
||||
<tabs>
|
||||
<tab idMso="TabReadMessage">
|
||||
<group id="MarcusLawReadGroup" label="Klear">
|
||||
<button id="SaveAttachmentsRead"
|
||||
label="שמור קבצים"
|
||||
screentip="שמור את הקבצים המצורפים בלבד"
|
||||
supertip="מעלה את הקבצים המצורפים של המייל הזה ל-Klear כ-Documents מקושרים לתיק שתבחר, בלי לתייק את המייל עצמו."
|
||||
size="large"
|
||||
getImage="OnGetImage"
|
||||
onAction="OnSaveAttachmentsFromInspector"
|
||||
getEnabled="OnGetSaveAttachmentsInspectorEnabled" />
|
||||
</group>
|
||||
</tab>
|
||||
</tabs>
|
||||
</ribbon>
|
||||
</customUI>
|
||||
@@ -127,6 +127,62 @@ namespace OutlookAddin.Services
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows a message box that is guaranteed to render above Outlook and
|
||||
/// any other window. A bare <see cref="MessageBox.Show(string)"/> has
|
||||
/// no owner — once our WPF dialog closes there is no active window on
|
||||
/// the add-in thread, so the box sinks behind Outlook and the user
|
||||
/// never sees the success/error result. We anchor it to a transient,
|
||||
/// invisible top-most owner window parented to the foreground Outlook
|
||||
/// window so it always surfaces on top. Caption is always "Klear".
|
||||
/// </summary>
|
||||
private MessageBoxResult ShowMessage(
|
||||
string text,
|
||||
MessageBoxButton button = MessageBoxButton.OK,
|
||||
MessageBoxImage icon = MessageBoxImage.None)
|
||||
{
|
||||
Window? owner = null;
|
||||
try
|
||||
{
|
||||
// A 1×1 borderless window at screen centre: imperceptible, but
|
||||
// gives the MessageBox a top-most owner to z-order above. The
|
||||
// box centres on this point → effectively centred on screen.
|
||||
owner = new Window
|
||||
{
|
||||
Width = 1,
|
||||
Height = 1,
|
||||
WindowStyle = WindowStyle.None,
|
||||
ResizeMode = ResizeMode.NoResize,
|
||||
ShowInTaskbar = false,
|
||||
Topmost = true,
|
||||
WindowStartupLocation = WindowStartupLocation.CenterScreen,
|
||||
};
|
||||
|
||||
var hwnd = GetForegroundWindow();
|
||||
if (hwnd == IntPtr.Zero)
|
||||
{
|
||||
hwnd = System.Diagnostics.Process.GetCurrentProcess().MainWindowHandle;
|
||||
}
|
||||
if (hwnd != IntPtr.Zero)
|
||||
{
|
||||
new WindowInteropHelper(owner).Owner = hwnd;
|
||||
}
|
||||
|
||||
owner.Show();
|
||||
owner.Activate();
|
||||
return MessageBox.Show(owner, text, "Klear", button, icon);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warning(ex, "ShowMessage top-most owner failed; falling back to ownerless box");
|
||||
return MessageBox.Show(text, "Klear", button, icon);
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { owner?.Close(); } catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnableModernTls()
|
||||
{
|
||||
try
|
||||
@@ -402,9 +458,8 @@ namespace OutlookAddin.Services
|
||||
if (mail == null) return;
|
||||
if (!IsConfigured)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"התוסף עדיין לא מוגדר. פתח את ההגדרות תחילה.",
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
return;
|
||||
@@ -423,9 +478,8 @@ namespace OutlookAddin.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error(ex, "LaunchComposeFromCaseAsync failed");
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"טעינת התיק נכשלה: " + ex.Message,
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
@@ -444,9 +498,8 @@ namespace OutlookAddin.Services
|
||||
if (mail == null) return;
|
||||
if (!IsConfigured)
|
||||
{
|
||||
var result = MessageBox.Show(
|
||||
var result = ShowMessage(
|
||||
"התוסף עדיין לא מוגדר. לפתוח את חלון ההגדרות עכשיו?",
|
||||
"Klear",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Information);
|
||||
if (result == MessageBoxResult.Yes) LaunchSettings();
|
||||
@@ -463,9 +516,8 @@ namespace OutlookAddin.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error(ex, "LaunchSaveAttachmentsAsync: extract failed");
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"קריאת הקבצים המצורפים נכשלה: " + ex.Message,
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
return;
|
||||
@@ -473,9 +525,8 @@ namespace OutlookAddin.Services
|
||||
|
||||
if (envelope.Attachments.Count == 0)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"אין במייל הזה קבצים מצורפים לשמירה.",
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
return;
|
||||
@@ -485,6 +536,13 @@ namespace OutlookAddin.Services
|
||||
// Subfolders are populated lazily once the user picks a case;
|
||||
// the default static set is already pre-loaded.
|
||||
|
||||
// If the sender already maps to a known client, seed the case
|
||||
// list so the user sees the identified case pre-selected instead
|
||||
// of having to search. Uses the same matching lookup the sidebar
|
||||
// does (cached for 10 min), so this is normally instant. Any
|
||||
// failure here is non-fatal — the dialog still opens empty.
|
||||
await TryPreselectSenderCaseAsync(vm, envelope.From).ConfigureAwait(true);
|
||||
|
||||
var dialog = new SaveAttachmentsDialog(vm);
|
||||
AttachOwnerToOutlook(dialog);
|
||||
var ok = dialog.ShowDialog();
|
||||
@@ -503,9 +561,8 @@ namespace OutlookAddin.Services
|
||||
: SaveAttachmentsViewModel.ResolveCaseFolderPath(picked);
|
||||
if (string.IsNullOrEmpty(caseFolder))
|
||||
{
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"לא ניתן לחשב את נתיב התיקייה של התיק. ייתכן שהתיק עוד לא הוגדר ב-Klear.",
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
return;
|
||||
@@ -533,15 +590,38 @@ namespace OutlookAddin.Services
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error(ex, "LaunchSaveAttachmentsAsync failed");
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"שמירת הקבצים נכשלה: " + ex.Message,
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowAttachmentSummary(AttachmentSaveSummary summary, string caseLabel, string targetPath)
|
||||
/// <summary>
|
||||
/// Looks up the mail sender against the CRM (reusing the sidebar's
|
||||
/// cached match) and, when it resolves to one or more linked cases,
|
||||
/// seeds the save-attachments dialog so the already-identified client
|
||||
/// case shows up pre-selected. Best-effort: swallows any error.
|
||||
/// </summary>
|
||||
private async Task TryPreselectSenderCaseAsync(SaveAttachmentsViewModel vm, string? senderEmail)
|
||||
{
|
||||
if (MatchingService == null || string.IsNullOrWhiteSpace(senderEmail)) return;
|
||||
try
|
||||
{
|
||||
var match = await MatchingService.LookupAsync(senderEmail!).ConfigureAwait(true);
|
||||
// Ambiguous (same email on several contacts) → don't guess; let
|
||||
// the user search. A clean match with linked cases → seed them.
|
||||
if (match == null || match.IsAmbiguous) return;
|
||||
if (match.RecentCases == null || match.RecentCases.Count == 0) return;
|
||||
vm.PreselectCases(match.RecentCases);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Warning(ex, "Sender-case preselect for save-attachments failed (non-fatal)");
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowAttachmentSummary(AttachmentSaveSummary summary, string caseLabel, string targetPath)
|
||||
{
|
||||
string message;
|
||||
MessageBoxImage icon;
|
||||
@@ -558,7 +638,7 @@ namespace OutlookAddin.Services
|
||||
message = parts.Count == 0 ? "לא נשמרו פריטים." : string.Join(" · ", parts);
|
||||
icon = summary.FailedCount > 0 ? MessageBoxImage.Warning : MessageBoxImage.Information;
|
||||
}
|
||||
MessageBox.Show(message, "Klear", MessageBoxButton.OK, icon);
|
||||
ShowMessage(message, MessageBoxButton.OK, icon);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -570,9 +650,8 @@ namespace OutlookAddin.Services
|
||||
{
|
||||
if (!IsConfigured)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"התוסף עדיין לא מוגדר. פתח את ההגדרות תחילה.",
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
return;
|
||||
@@ -589,9 +668,8 @@ namespace OutlookAddin.Services
|
||||
{
|
||||
Logger.Error(ex, "LaunchComposeFromCaseByIdAsync failed for caseId={CaseId}", caseId);
|
||||
if (mail != null) try { Marshal.ReleaseComObject(mail); } catch { }
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"פתיחת המייל מתיק נכשלה: " + ex.Message,
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Error);
|
||||
}
|
||||
@@ -654,9 +732,8 @@ namespace OutlookAddin.Services
|
||||
{
|
||||
if (!IsConfigured)
|
||||
{
|
||||
var result = MessageBox.Show(
|
||||
var result = ShowMessage(
|
||||
"התוסף עדיין לא מוגדר. לפתוח את חלון ההגדרות עכשיו?",
|
||||
"Klear",
|
||||
MessageBoxButton.YesNo,
|
||||
MessageBoxImage.Information);
|
||||
if (result == MessageBoxResult.Yes)
|
||||
@@ -669,9 +746,8 @@ namespace OutlookAddin.Services
|
||||
var mailItems = ReadCurrentSelection();
|
||||
if (mailItems.Count == 0)
|
||||
{
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"לא נבחר מייל לתיוק. סמן מייל אחד או יותר ונסה שוב.",
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Information);
|
||||
return;
|
||||
@@ -712,9 +788,8 @@ namespace OutlookAddin.Services
|
||||
Logger.Warning(
|
||||
"Filing skipped — selected EspoEntityRef has no usable Id/EntityType (id={Id}, name={Name}, type={Type})",
|
||||
vm.SelectedTarget?.Id, vm.SelectedTarget?.Name, vm.SelectedTarget?.EntityType);
|
||||
MessageBox.Show(
|
||||
ShowMessage(
|
||||
"התיק שנבחר לא הוחזר עם סוג ישות (entityType) תקין. ייתכן ש-Klear שלך מחזיר שדה אחר; הלוג מכיל את הפרטים. שלח לאדמין.",
|
||||
"Klear",
|
||||
MessageBoxButton.OK,
|
||||
MessageBoxImage.Warning);
|
||||
return;
|
||||
@@ -886,7 +961,7 @@ namespace OutlookAddin.Services
|
||||
}
|
||||
}
|
||||
|
||||
private static void ShowSummary(FilingBatchSummary summary, FilingTarget target)
|
||||
private void ShowSummary(FilingBatchSummary summary, FilingTarget target)
|
||||
{
|
||||
string message;
|
||||
MessageBoxImage icon;
|
||||
@@ -907,7 +982,7 @@ namespace OutlookAddin.Services
|
||||
icon = summary.FailedCount > 0 ? MessageBoxImage.Warning : MessageBoxImage.Information;
|
||||
}
|
||||
|
||||
MessageBox.Show(message, "Klear", MessageBoxButton.OK, icon);
|
||||
ShowMessage(message, MessageBoxButton.OK, icon);
|
||||
}
|
||||
|
||||
private static string? TryGetSenderName(Outlook.MailItem item)
|
||||
|
||||
Reference in New Issue
Block a user