Skip to content

Commit f1cafd5

Browse files
committed
Add RtdClocks example with various ways to do RTD functions
1 parent 75d5e71 commit f1cafd5

35 files changed

+1049
-2
lines changed

MasterSlave/Slave/packages.config

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
3-
<package id="ExcelDna.AddIn" version="0.33.9" targetFramework="net45" />
4-
<package id="ExcelDna.Integration" version="0.33.9" targetFramework="net45" />
3+
<package id="ExcelDna.AddIn" version="0.34.0-dev38" targetFramework="net45" />
4+
<package id="ExcelDna.Integration" version="0.34.0-dev38" targetFramework="net45" />
55
</packages>

RtdClocks/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
The RtdClocks sample shows a number of ways to implement RTD functions with Excel-DNA.
2+
3+
The RtdClocks solution has a number of projects - each project is a stand-alone add-in that shows one approach to implementing an RTD function.
4+
5+
## RtdClock-ExcelRtdServer
6+
This project implements an RTD server using the Excel-DNA base class `ExcelRtdServer`. Any RTD server implemented in an Excel-DNA add-in should use the base class, rather than implementing the IRtdServer interface directly. The base class provides full access to all RTD features, and exposes a thread-safe and update notification that can be called at any time, at high frequency, from any thread.
7+
Internally, Excel-DNA uses an ExcelRtdServer for all the other RTD-based features, including RxExcel / IObservable support.
8+
9+
## RtdClock-IExcelObservable
10+
This project uses the higher-level abstraction of an IObservable / IObserver interface to implement the RTD function. In order to allow compatibility with .NET 2.0, the interfaces IExcelObservable / IExcelObserver are used by Excel-DNA, but the semantics is the same as the .NET 4.0 interfaces IObservable<object> / IObserver<object>.
11+
12+
## RtdClock-Rx
13+
We show how to use the Reactive Extensions (Rx) library to define a simple timer. The Rx Observable is exposed as a UDF through the add-in using some helper utilities that are defined here.
14+
15+
## RtdClock-Rx-Registration
16+
The Excel-DNA Registration extension library allows for custom registration extensions, including autoomatic registration of async and IObservable functions. This project shows how the registration of Rx / IObservable functions can be automatically done, exhibiting the cleanest minimal implementation of an RTD function.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("RtdClock-ExcelRtdServer")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("RtdClock-ExcelRtdServer")]
13+
[assembly: AssemblyCopyright("Copyright © 2016")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("95e29cf7-b6a0-44c8-a07f-0261d630d310")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
This project has the following NuGet package installed:
2+
* ExcelDna.AddIn
3+
4+
The add-in defines:
5+
* an RTD server based on the ExcelRtdServer base class,
6+
* a UDF that called `dnaRtdClock`.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<DnaLibrary Name="RtdClock-ExcelRtdServer Add-In" RuntimeVersion="v4.0">
2+
<ExternalLibrary Path="RtdClock-ExcelRtdServer.dll" LoadFromBytes="true" Pack="true" />
3+
4+
<!--
5+
The RuntimeVersion attribute above allows two settings:
6+
* RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5
7+
* RuntimeVersion="v4.0" - for .NET 4 and 4.5
8+
9+
Additional referenced assemblies can be specified by adding 'Reference' tags.
10+
These libraries will not be examined and registered with Excel as add-in libraries,
11+
but will be packed into the -packed.xll file and loaded at runtime as needed.
12+
For example:
13+
14+
<Reference Path="Another.Library.dll" Pack="true" />
15+
16+
Excel-DNA also allows the xml for ribbon UI extensions to be specified in the .dna file.
17+
See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
18+
-->
19+
20+
</DnaLibrary>
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{95E29CF7-B6A0-44C8-A07F-0261D630D310}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>RtdClock_ExcelRtdServer</RootNamespace>
11+
<AssemblyName>RtdClock-ExcelRtdServer</AssemblyName>
12+
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="ExcelDna.Integration, Version=0.33.5730.40390, Culture=neutral, processorArchitecture=MSIL">
34+
<HintPath>..\packages\ExcelDna.Integration.0.33.9\lib\ExcelDna.Integration.dll</HintPath>
35+
<Private>False</Private>
36+
</Reference>
37+
<Reference Include="System" />
38+
<Reference Include="System.Core" />
39+
<Reference Include="System.Xml.Linq" />
40+
<Reference Include="System.Data.DataSetExtensions" />
41+
<Reference Include="Microsoft.CSharp" />
42+
<Reference Include="System.Data" />
43+
<Reference Include="System.Net.Http" />
44+
<Reference Include="System.Xml" />
45+
</ItemGroup>
46+
<ItemGroup>
47+
<Compile Include="RtdClock.cs" />
48+
<Compile Include="Properties\AssemblyInfo.cs" />
49+
<Compile Include="RtdClockServer.cs" />
50+
</ItemGroup>
51+
<ItemGroup>
52+
<Content Include="RtdClock-ExcelRtdServer-AddIn.dna">
53+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
54+
</Content>
55+
<None Include="packages.config" />
56+
<None Include="README.md" />
57+
</ItemGroup>
58+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
59+
<PropertyGroup>
60+
<PostBuildEvent>xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna.xll" "$(TargetDir)RtdClock-ExcelRtdServer-AddIn.xll*" /C /Y
61+
xcopy "$(TargetDir)RtdClock-ExcelRtdServer-AddIn.dna*" "$(TargetDir)RtdClock-ExcelRtdServer-AddIn64.dna*" /C /Y
62+
xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna64.xll" "$(TargetDir)RtdClock-ExcelRtdServer-AddIn64.xll*" /C /Y
63+
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)RtdClock-ExcelRtdServer-AddIn.dna" /Y
64+
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)RtdClock-ExcelRtdServer-AddIn64.dna" /Y</PostBuildEvent>
65+
</PropertyGroup>
66+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
67+
Other similar extension points exist, see Microsoft.Common.targets.
68+
<Target Name="BeforeBuild">
69+
</Target>
70+
<Target Name="AfterBuild">
71+
</Target>
72+
-->
73+
</Project>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using ExcelDna.Integration;
2+
3+
namespace RtdClock_ExcelRtdServer
4+
{
5+
public static class RtdClock
6+
{
7+
[ExcelFunction(Description = "Provides a ticking clock")]
8+
public static object dnaRtdClock_ExcelRtdServer()
9+
{
10+
// Call the Excel-DNA RTD wrapper, which does dynamic registration of the RTD server
11+
// Note that the topic information needs at least one string - it's not used in this sample
12+
return XlCall.RTD(RtdClockServer.ServerProgId, null, "");
13+
}
14+
}
15+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.InteropServices;
4+
using System.Threading;
5+
using ExcelDna.Integration.Rtd;
6+
7+
namespace RtdClock_ExcelRtdServer
8+
{
9+
[ComVisible(true)] // Required since the default template puts [assembly:ComVisible(false)] in the AssemblyInfo.cs
10+
[ProgId(RtdClockServer.ServerProgId)] // If ProgId is not specified, change the XlCall.RTD call in the wrapper to use namespace + type name (the default ProgId)
11+
public class RtdClockServer : ExcelRtdServer
12+
{
13+
public const string ServerProgId = "RtdClock.ClockServer";
14+
15+
// Using a System.Threading.Time which invokes the callback on a ThreadPool thread
16+
// (normally that would be dangeours for an RTD server, but ExcelRtdServer is thrad-safe)
17+
Timer _timer;
18+
List<Topic> _topics;
19+
20+
protected override bool ServerStart()
21+
{
22+
_timer = new Timer(timer_tick, null, 0, 1000);
23+
_topics = new List<Topic>();
24+
return true;
25+
}
26+
27+
protected override void ServerTerminate()
28+
{
29+
_timer.Dispose();
30+
}
31+
32+
protected override object ConnectData(Topic topic, IList<string> topicInfo, ref bool newValues)
33+
{
34+
_topics.Add(topic);
35+
return DateTime.Now.ToString("HH:mm:ss") + " (ConnectData)";
36+
}
37+
38+
protected override void DisconnectData(Topic topic)
39+
{
40+
_topics.Remove(topic);
41+
}
42+
43+
void timer_tick(object _unused_state_)
44+
{
45+
string now = DateTime.Now.ToString("HH:mm:ss");
46+
foreach (var topic in _topics)
47+
topic.UpdateValue(now);
48+
}
49+
}
50+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="ExcelDna.AddIn" version="0.33.9" targetFramework="net45" />
4+
<package id="ExcelDna.Integration" version="0.33.9" targetFramework="net45" />
5+
</packages>
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
namespace RtdClock_FSharp.AssemblyInfo
2+
3+
open System.Reflection
4+
open System.Runtime.CompilerServices
5+
open System.Runtime.InteropServices
6+
7+
// General Information about an assembly is controlled through the following
8+
// set of attributes. Change these attribute values to modify the information
9+
// associated with an assembly.
10+
[<assembly: AssemblyTitle("RtdClock-FSharp")>]
11+
[<assembly: AssemblyDescription("")>]
12+
[<assembly: AssemblyConfiguration("")>]
13+
[<assembly: AssemblyCompany("")>]
14+
[<assembly: AssemblyProduct("RtdClock-FSharp")>]
15+
[<assembly: AssemblyCopyright("Copyright © 2016")>]
16+
[<assembly: AssemblyTrademark("")>]
17+
[<assembly: AssemblyCulture("")>]
18+
19+
// Setting ComVisible to false makes the types in this assembly not visible
20+
// to COM components. If you need to access a type in this assembly from
21+
// COM, set the ComVisible attribute to true on that type.
22+
[<assembly: ComVisible(false)>]
23+
24+
// The following GUID is for the ID of the typelib if this project is exposed to COM
25+
[<assembly: Guid("fb526881-a282-4a04-aaa8-00b6d51b658c")>]
26+
27+
// Version information for an assembly consists of the following four values:
28+
//
29+
// Major Version
30+
// Minor Version
31+
// Build Number
32+
// Revision
33+
//
34+
// You can specify all the values or you can default the Build and Revision Numbers
35+
// by using the '*' as shown below:
36+
// [<assembly: AssemblyVersion("1.0.*")>]
37+
[<assembly: AssemblyVersion("1.0.0.0")>]
38+
[<assembly: AssemblyFileVersion("1.0.0.0")>]
39+
40+
do
41+
()

0 commit comments

Comments
 (0)