Skip to content

Commit

Permalink
Create Master/Slave sample (and test)
Browse files Browse the repository at this point in the history
  • Loading branch information
govert committed Feb 21, 2016
1 parent 8f85c2e commit b9fba7b
Show file tree
Hide file tree
Showing 15 changed files with 529 additions and 2 deletions.
20 changes: 20 additions & 0 deletions MasterSlave/Master/Master-AddIn.dna
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<DnaLibrary Name="Master Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="Master.dll" LoadFromBytes="true" Pack="true" />

<!--
The RuntimeVersion attribute above allows two settings:
* RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5
* RuntimeVersion="v4.0" - for .NET 4 and 4.5

Additional referenced assemblies can be specified by adding 'Reference' tags.
These libraries will not be examined and registered with Excel as add-in libraries,
but will be packed into the -packed.xll file and loaded at runtime as needed.
For example:

<Reference Path="Another.Library.dll" Pack="true" />

Excel-DNA also allows the xml for ribbon UI extensions to be specified in the .dna file.
See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
-->

</DnaLibrary>
71 changes: 71 additions & 0 deletions MasterSlave/Master/Master.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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>{255EA622-10F7-4A1F-8CC4-053DEC4E0AA0}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MasterSlave</RootNamespace>
<AssemblyName>Master</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ExcelDna.Integration, Version=0.33.5730.40390, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelDna.Integration.0.33.9\lib\ExcelDna.Integration.dll</HintPath>
<Private>False</Private>
</Reference>
<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="Ribbon.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Master-AddIn.dna">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna.xll" "$(TargetDir)Master-AddIn.xll*" /C /Y
xcopy "$(TargetDir)Master-AddIn.dna*" "$(TargetDir)Master-AddIn64.dna*" /C /Y
xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna64.xll" "$(TargetDir)Master-AddIn64.xll*" /C /Y
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)Master-AddIn.dna" /Y
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)Master-AddIn64.dna" /Y</PostBuildEvent>
</PropertyGroup>
<!-- 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>
36 changes: 36 additions & 0 deletions MasterSlave/Master/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("Master")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Master")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("255ea622-10f7-4a1f-8cc4-053dec4e0aa0")]

// 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")]
44 changes: 44 additions & 0 deletions MasterSlave/Master/Ribbon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using ExcelDna.Integration;
using ExcelDna.Integration.CustomUI;

namespace MasterSlave
{
[ComVisible(true)]
public class Ribbon : ExcelRibbon
{
public Ribbon()
{
}

public override string GetCustomUI(string RibbonID)
{
XlCall.Excel(XlCall.xlcMessage, "BANG!!!!");
Console.Beep();
Console.Beep();
Console.Beep();
return
@"
<customUI xmlns = 'http://schemas.microsoft.com/office/2006/01/customui' >
<ribbon>
<tabs>
<tab id = 'CustomTab' label = 'My Tab' >
<group id = 'SampleGroup' label = 'My Sample Group' >
<button id = 'Button1' label = 'My Button Label' size = 'large' onAction = 'RunTagMacro' tag = 'ShowHelloMessage' />
<button id = 'Button2' label = 'My Second Button' size = 'normal' onAction = 'OnButtonPressed' />
</group>
</tab>
</tabs>
</ribbon>
</customUI>
";
}
}

}
43 changes: 43 additions & 0 deletions MasterSlave/MasterSlave.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.24720.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Master", "Master\Master.csproj", "{255EA622-10F7-4A1F-8CC4-053DEC4E0AA0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Slave", "Slave\Slave.csproj", "{9245231C-6B34-40B4-A1EA-29A987B042FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestController", "TestController\TestController.csproj", "{A7D2C0D4-DC96-4A3B-92EA-0A9BA1DFF681}"
ProjectSection(ProjectDependencies) = postProject
{9245231C-6B34-40B4-A1EA-29A987B042FA} = {9245231C-6B34-40B4-A1EA-29A987B042FA}
{255EA622-10F7-4A1F-8CC4-053DEC4E0AA0} = {255EA622-10F7-4A1F-8CC4-053DEC4E0AA0}
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{CD534D4E-2D58-4998-B569-604D8FCC0F9A}"
ProjectSection(SolutionItems) = preProject
Readme.md = Readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{255EA622-10F7-4A1F-8CC4-053DEC4E0AA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{255EA622-10F7-4A1F-8CC4-053DEC4E0AA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{255EA622-10F7-4A1F-8CC4-053DEC4E0AA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{255EA622-10F7-4A1F-8CC4-053DEC4E0AA0}.Release|Any CPU.Build.0 = Release|Any CPU
{9245231C-6B34-40B4-A1EA-29A987B042FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9245231C-6B34-40B4-A1EA-29A987B042FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9245231C-6B34-40B4-A1EA-29A987B042FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9245231C-6B34-40B4-A1EA-29A987B042FA}.Release|Any CPU.Build.0 = Release|Any CPU
{A7D2C0D4-DC96-4A3B-92EA-0A9BA1DFF681}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A7D2C0D4-DC96-4A3B-92EA-0A9BA1DFF681}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A7D2C0D4-DC96-4A3B-92EA-0A9BA1DFF681}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A7D2C0D4-DC96-4A3B-92EA-0A9BA1DFF681}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions MasterSlave/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
The MasterSlave sample shows how an add-in host can control loading and unloading of other add-ins.

The Master add-in displays a ribbon with two buttons, to load and unload the Slave add-in.

In addition, there is TestController application (a console application) which loads and controls the Master add-in, and attempts to detect whether the Excel process exits with an error. This is to test for a reported error on closing Excel when an add-in has been unregistered.

12 changes: 12 additions & 0 deletions MasterSlave/Slave/AddIn.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Slave
{
public class Class1
{
}
}
36 changes: 36 additions & 0 deletions MasterSlave/Slave/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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("Slave")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Slave")]
[assembly: AssemblyCopyright("Copyright © 2016")]
[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("9245231c-6b34-40b4-a1ea-29a987b042fa")]

// 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")]
20 changes: 20 additions & 0 deletions MasterSlave/Slave/Slave-AddIn.dna
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<DnaLibrary Name="Slave Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="Slave.dll" LoadFromBytes="true" Pack="true" />

<!--
The RuntimeVersion attribute above allows two settings:
* RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5
* RuntimeVersion="v4.0" - for .NET 4 and 4.5

Additional referenced assemblies can be specified by adding 'Reference' tags.
These libraries will not be examined and registered with Excel as add-in libraries,
but will be packed into the -packed.xll file and loaded at runtime as needed.
For example:

<Reference Path="Another.Library.dll" Pack="true" />

Excel-DNA also allows the xml for ribbon UI extensions to be specified in the .dna file.
See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
-->

</DnaLibrary>
71 changes: 71 additions & 0 deletions MasterSlave/Slave/Slave.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?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>{9245231C-6B34-40B4-A1EA-29A987B042FA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>MasterSlave</RootNamespace>
<AssemblyName>Slave</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="ExcelDna.Integration, Version=0.33.5730.40390, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\ExcelDna.Integration.0.33.9\lib\ExcelDna.Integration.dll</HintPath>
<Private>False</Private>
</Reference>
<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="AddIn.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="Slave-AddIn.dna">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna.xll" "$(TargetDir)Slave-AddIn.xll*" /C /Y
xcopy "$(TargetDir)Slave-AddIn.dna*" "$(TargetDir)Slave-AddIn64.dna*" /C /Y
xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna64.xll" "$(TargetDir)Slave-AddIn64.xll*" /C /Y
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)Slave-AddIn.dna" /Y
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)Slave-AddIn64.dna" /Y</PostBuildEvent>
</PropertyGroup>
<!-- 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>
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ExcelDna.AddIn" version="0.33.9.65" targetFramework="net4" />
<package id="ExcelDna.Integration" version="0.33.9" targetFramework="net4" />
<package id="ExcelDna.AddIn" version="0.33.9" targetFramework="net45" />
<package id="ExcelDna.Integration" version="0.33.9" targetFramework="net45" />
</packages>
Loading

0 comments on commit b9fba7b

Please sign in to comment.