mirror of
https://github.com/Kopano-dev/kopano-ol-extension.git
synced 2023-10-10 13:37:40 +02:00
[KOE-14] Added restart dialog to secondary contacts folder sync.
This commit is contained in:
parent
495386dea9
commit
9ba795d7aa
@ -1,12 +1,14 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 14
|
||||
VisualStudioVersion = 14.0.25123.0
|
||||
VisualStudioVersion = 14.0.25420.1
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AcaciaZPushPlugin", "AcaciaZPushPlugin\AcaciaZPushPlugin.csproj", "{1A7427A5-F814-4B07-98B2-C67D758B65D6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PluginDebugger", "PluginDebugger\PluginDebugger.csproj", "{9258AD17-0A25-4669-A95C-93EC70882551}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OutlookRestarter", "OutlookRestarter\OutlookRestarter.csproj", "{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@ -41,6 +43,18 @@ Global
|
||||
{9258AD17-0A25-4669-A95C-93EC70882551}.Release|x64.Build.0 = Release|Any CPU
|
||||
{9258AD17-0A25-4669-A95C-93EC70882551}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{9258AD17-0A25-4669-A95C-93EC70882551}.Release|x86.Build.0 = Release|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|x64.ActiveCfg = Debug|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|x64.Build.0 = Debug|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|x86.ActiveCfg = Debug|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Debug|x86.Build.0 = Debug|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|x64.ActiveCfg = Release|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|x64.Build.0 = Release|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|x86.ActiveCfg = Release|Any CPU
|
||||
{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}.Release|x86.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -26,6 +26,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using static Acacia.DebugOptions;
|
||||
|
||||
namespace Acacia.Features.SecondaryContacts
|
||||
@ -57,6 +58,10 @@ namespace Acacia.Features.SecondaryContacts
|
||||
}
|
||||
}
|
||||
|
||||
// Contains the ids of folders for which we've shown a warning. This is both to prevent
|
||||
// warning multiple times and to detect the case when the app has been restarted.
|
||||
private readonly HashSet<string> _warnedFolders = new HashSet<string>();
|
||||
|
||||
public FeatureSecondaryContacts()
|
||||
{
|
||||
|
||||
@ -68,27 +73,67 @@ namespace Acacia.Features.SecondaryContacts
|
||||
OnUnpatchedFolderDiscovered);
|
||||
}
|
||||
|
||||
|
||||
private void OnUnpatchedFolderDiscovered(IFolder folder)
|
||||
{
|
||||
string strippedName = folder.Name.StripSuffix(SUFFIX_CONTACTS);
|
||||
Logger.Instance.Debug(this, "Patching secondary contacts folder: {0}", strippedName);
|
||||
|
||||
// Note that somehow it fails if these are updated in one go, so do the steps individually
|
||||
// To patch we need to do the following
|
||||
// 1) Update the sync type from 18 to 14
|
||||
// 2) Update the container class from Note to Contact
|
||||
// 3) Patch the name
|
||||
// Note that the above steps need to be done in this order and individually for this to work.
|
||||
//
|
||||
// At some point after 2 we also need to restart Outlook to make it appear in the list of contact folders.
|
||||
// So, when the folder is detected, we make it invisible and perform steps 1 and 2. We issue a warning
|
||||
// that Outlook must be restarted. When the folder is detected again and is invisible, that means we've restarted
|
||||
// At this point the name is patched and the folder is made visible.
|
||||
|
||||
// Sync type
|
||||
Logger.Instance.Trace(this, "Setting sync type");
|
||||
folder.SetProperty(OutlookConstants.PR_EAS_SYNCTYPE, (int)OutlookConstants.SyncType.UserContact);
|
||||
if (!folder.AttrHidden)
|
||||
{
|
||||
// Stage 1
|
||||
|
||||
// Container type
|
||||
Logger.Instance.Trace(this, "Setting container class");
|
||||
folder.SetProperty(OutlookConstants.PR_CONTAINER_CLASS, "IPF.Contact");
|
||||
// Sync type
|
||||
Logger.Instance.Trace(this, "Setting sync type");
|
||||
folder.SetProperty(OutlookConstants.PR_EAS_SYNCTYPE, (int)OutlookConstants.SyncType.UserContact);
|
||||
|
||||
// And the name
|
||||
Logger.Instance.Trace(this, "Patching name");
|
||||
folder.Name = strippedName;
|
||||
// Container type
|
||||
Logger.Instance.Trace(this, "Setting container class");
|
||||
folder.SetProperty(OutlookConstants.PR_CONTAINER_CLASS, "IPF.Contact");
|
||||
|
||||
Logger.Instance.Debug(this, "Patched secondary contacts folder: {0}", strippedName);
|
||||
// Make it invisible.
|
||||
folder.AttrHidden = true;
|
||||
|
||||
Logger.Instance.Debug(this, "Patched secondary contacts folder: {0}", strippedName);
|
||||
// Register and show a warning, if not already done.
|
||||
// Note that patching may be done multiple times.
|
||||
if (!_warnedFolders.Contains(folder.EntryId))
|
||||
{
|
||||
_warnedFolders.Add(folder.EntryId);
|
||||
|
||||
if (MessageBox.Show(StringUtil.GetResourceString("SecondaryContactsPatched_Body", strippedName),
|
||||
StringUtil.GetResourceString("SecondaryContactsPatched_Title"),
|
||||
MessageBoxButtons.YesNo,
|
||||
MessageBoxIcon.Warning
|
||||
) == DialogResult.Yes)
|
||||
{
|
||||
ThisAddIn.Instance.Restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
// If _warnedFolders does not contain the folder (and it's hidden), this means Outlook was restarted.
|
||||
else if (!_warnedFolders.Contains(folder.EntryId))
|
||||
{
|
||||
// Stage 2
|
||||
|
||||
// Patch the name
|
||||
Logger.Instance.Trace(this, "Patching name");
|
||||
folder.Name = strippedName;
|
||||
|
||||
// Show it
|
||||
folder.AttrHidden = false;
|
||||
Logger.Instance.Debug(this, "Shown secondary contacts folder: {0}", strippedName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -785,6 +785,24 @@ namespace Acacia.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to To synchronise the contacts folder '{0}', Outlook must be restarted. Click 'Yes' to restart Outlook now, or 'No' if you plan to restart Outlook later..
|
||||
/// </summary>
|
||||
internal static string SecondaryContactsPatched_Body {
|
||||
get {
|
||||
return ResourceManager.GetString("SecondaryContactsPatched_Body", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Contacts folder.
|
||||
/// </summary>
|
||||
internal static string SecondaryContactsPatched_Title {
|
||||
get {
|
||||
return ResourceManager.GetString("SecondaryContactsPatched_Title", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unable to open the shared folder. Please ensure you have permission to open the shared folder..
|
||||
/// </summary>
|
||||
|
@ -431,4 +431,12 @@
|
||||
<data name="Ribbon_About_Supertip" xml:space="preserve">
|
||||
<value>Shows the about dialog, which contains licensing and version information.</value>
|
||||
</data>
|
||||
<data name="SecondaryContactsPatched_Body" xml:space="preserve">
|
||||
<value>To synchronise the contacts folder '{0}', Outlook must be restarted. Click 'Yes' to restart Outlook now, or 'No' if you plan to restart Outlook later.</value>
|
||||
<comment>Shown when a secondary contact folder is detected, to inform the user that a restart is required</comment>
|
||||
</data>
|
||||
<data name="SecondaryContactsPatched_Title" xml:space="preserve">
|
||||
<value>Contacts folder</value>
|
||||
<comment>Shown when a secondary contact folder is detected, to inform the user that a restart is required</comment>
|
||||
</data>
|
||||
</root>
|
@ -112,7 +112,14 @@ namespace Acacia.Stubs.OutlookWrappers
|
||||
{
|
||||
get
|
||||
{
|
||||
return Props.GetProperty(OutlookConstants.PR_ATTR_HIDDEN);
|
||||
try
|
||||
{
|
||||
return Props.GetProperty(OutlookConstants.PR_ATTR_HIDDEN);
|
||||
}
|
||||
catch(System.Exception)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
set
|
||||
{
|
||||
|
@ -29,6 +29,9 @@ using Acacia.UI;
|
||||
using Acacia.ZPush;
|
||||
using System.Globalization;
|
||||
using Acacia.UI.Outlook;
|
||||
using System.Diagnostics;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Acacia
|
||||
{
|
||||
@ -188,6 +191,35 @@ namespace Acacia
|
||||
|
||||
#endregion
|
||||
|
||||
#region Misc helpers
|
||||
|
||||
public void SendReceive()
|
||||
{
|
||||
Outlook.NameSpace session = Application.Session;
|
||||
session.SendAndReceive(false);
|
||||
ComRelease.Release(session);
|
||||
}
|
||||
|
||||
public void Restart()
|
||||
{
|
||||
// Can not use the assembly location, as that is in the GAC
|
||||
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
|
||||
UriBuilder uri = new UriBuilder(codeBase);
|
||||
string path = Uri.UnescapeDataString(uri.Path);
|
||||
// Create the path to the restarter
|
||||
path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "OutlookRestarter.exe");
|
||||
|
||||
// Run that
|
||||
Process process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo(path, Environment.CommandLine);
|
||||
process.Start();
|
||||
|
||||
// And close us
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Ribbons
|
||||
|
||||
private OutlookUI _outlookUI;
|
||||
|
@ -72,7 +72,7 @@ namespace Acacia.ZPush
|
||||
/// </summary>
|
||||
public void SendReceive()
|
||||
{
|
||||
ThisAddIn.Instance.Application.Session.SendAndReceive(false);
|
||||
ThisAddIn.Instance.SendReceive();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
6
src/AcaciaZPushPlugin/OutlookRestarter/App.config
Normal file
6
src/AcaciaZPushPlugin/OutlookRestarter/App.config
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<configuration>
|
||||
<startup>
|
||||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
|
||||
</startup>
|
||||
</configuration>
|
BIN
src/AcaciaZPushPlugin/OutlookRestarter/Kopano.ico
Normal file
BIN
src/AcaciaZPushPlugin/OutlookRestarter/Kopano.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 361 KiB |
@ -0,0 +1,69 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{222C4DA5-FA31-471A-B127-5E0C6AD2CB3C}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>OutlookRestarter</RootNamespace>
|
||||
<AssemblyName>OutlookRestarter</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\Build\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\Build\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<ApplicationIcon>Kopano.ico</ApplicationIcon>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="Kopano.ico" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
20
src/AcaciaZPushPlugin/OutlookRestarter/Program.cs
Normal file
20
src/AcaciaZPushPlugin/OutlookRestarter/Program.cs
Normal file
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace OutlookRestarter
|
||||
{
|
||||
class Program
|
||||
{
|
||||
[STAThread]
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Process process = new Process();
|
||||
process.StartInfo = new ProcessStartInfo(args[0], string.Join(" ", args.Skip(1)));
|
||||
process.Start();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("OutlookRestarter")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("OutlookRestarter")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2017")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("222c4da5-fa31-471a-b127-5e0c6ad2cb3c")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// 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.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
Loading…
Reference in New Issue
Block a user