Skip to content

Commit

Permalink
Add RtdClocks example with various ways to do RTD functions
Browse files Browse the repository at this point in the history
  • Loading branch information
govert committed Mar 25, 2016
1 parent 75d5e71 commit f1cafd5
Show file tree
Hide file tree
Showing 35 changed files with 1,049 additions and 2 deletions.
4 changes: 2 additions & 2 deletions MasterSlave/Slave/packages.config
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" targetFramework="net45" />
<package id="ExcelDna.Integration" version="0.33.9" targetFramework="net45" />
<package id="ExcelDna.AddIn" version="0.34.0-dev38" targetFramework="net45" />
<package id="ExcelDna.Integration" version="0.34.0-dev38" targetFramework="net45" />
</packages>
16 changes: 16 additions & 0 deletions RtdClocks/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
The RtdClocks sample shows a number of ways to implement RTD functions with Excel-DNA.

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.

## RtdClock-ExcelRtdServer
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.
Internally, Excel-DNA uses an ExcelRtdServer for all the other RTD-based features, including RxExcel / IObservable support.

## RtdClock-IExcelObservable
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>.

## RtdClock-Rx
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.

## RtdClock-Rx-Registration
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.
36 changes: 36 additions & 0 deletions RtdClocks/RtdClock-ExcelRtdServer/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("RtdClock-ExcelRtdServer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RtdClock-ExcelRtdServer")]
[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("95e29cf7-b6a0-44c8-a07f-0261d630d310")]

// 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")]
6 changes: 6 additions & 0 deletions RtdClocks/RtdClock-ExcelRtdServer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
This project has the following NuGet package installed:
* ExcelDna.AddIn

The add-in defines:
* an RTD server based on the ExcelRtdServer base class,
* a UDF that called `dnaRtdClock`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<DnaLibrary Name="RtdClock-ExcelRtdServer Add-In" RuntimeVersion="v4.0">
<ExternalLibrary Path="RtdClock-ExcelRtdServer.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>
73 changes: 73 additions & 0 deletions RtdClocks/RtdClock-ExcelRtdServer/RtdClock-ExcelRtdServer.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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>{95E29CF7-B6A0-44C8-A07F-0261D630D310}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>RtdClock_ExcelRtdServer</RootNamespace>
<AssemblyName>RtdClock-ExcelRtdServer</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="RtdClock.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RtdClockServer.cs" />
</ItemGroup>
<ItemGroup>
<Content Include="RtdClock-ExcelRtdServer-AddIn.dna">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<None Include="packages.config" />
<None Include="README.md" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna.xll" "$(TargetDir)RtdClock-ExcelRtdServer-AddIn.xll*" /C /Y
xcopy "$(TargetDir)RtdClock-ExcelRtdServer-AddIn.dna*" "$(TargetDir)RtdClock-ExcelRtdServer-AddIn64.dna*" /C /Y
xcopy "$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDna64.xll" "$(TargetDir)RtdClock-ExcelRtdServer-AddIn64.xll*" /C /Y
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)RtdClock-ExcelRtdServer-AddIn.dna" /Y
"$(SolutionDir)\packages\ExcelDna.AddIn.0.33.9\tools\ExcelDnaPack.exe" "$(TargetDir)RtdClock-ExcelRtdServer-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>
15 changes: 15 additions & 0 deletions RtdClocks/RtdClock-ExcelRtdServer/RtdClock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using ExcelDna.Integration;

namespace RtdClock_ExcelRtdServer
{
public static class RtdClock
{
[ExcelFunction(Description = "Provides a ticking clock")]
public static object dnaRtdClock_ExcelRtdServer()
{
// Call the Excel-DNA RTD wrapper, which does dynamic registration of the RTD server
// Note that the topic information needs at least one string - it's not used in this sample
return XlCall.RTD(RtdClockServer.ServerProgId, null, "");
}
}
}
50 changes: 50 additions & 0 deletions RtdClocks/RtdClock-ExcelRtdServer/RtdClockServer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Runtime.InteropServices;
using System.Threading;
using ExcelDna.Integration.Rtd;

namespace RtdClock_ExcelRtdServer
{
[ComVisible(true)] // Required since the default template puts [assembly:ComVisible(false)] in the AssemblyInfo.cs
[ProgId(RtdClockServer.ServerProgId)] // If ProgId is not specified, change the XlCall.RTD call in the wrapper to use namespace + type name (the default ProgId)
public class RtdClockServer : ExcelRtdServer
{
public const string ServerProgId = "RtdClock.ClockServer";

// Using a System.Threading.Time which invokes the callback on a ThreadPool thread
// (normally that would be dangeours for an RTD server, but ExcelRtdServer is thrad-safe)
Timer _timer;
List<Topic> _topics;

protected override bool ServerStart()
{
_timer = new Timer(timer_tick, null, 0, 1000);
_topics = new List<Topic>();
return true;
}

protected override void ServerTerminate()
{
_timer.Dispose();
}

protected override object ConnectData(Topic topic, IList<string> topicInfo, ref bool newValues)
{
_topics.Add(topic);
return DateTime.Now.ToString("HH:mm:ss") + " (ConnectData)";
}

protected override void DisconnectData(Topic topic)
{
_topics.Remove(topic);
}

void timer_tick(object _unused_state_)
{
string now = DateTime.Now.ToString("HH:mm:ss");
foreach (var topic in _topics)
topic.UpdateValue(now);
}
}
}
5 changes: 5 additions & 0 deletions RtdClocks/RtdClock-ExcelRtdServer/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ExcelDna.AddIn" version="0.33.9" targetFramework="net45" />
<package id="ExcelDna.Integration" version="0.33.9" targetFramework="net45" />
</packages>
41 changes: 41 additions & 0 deletions RtdClocks/RtdClock-FSharp/AssemblyInfo.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
namespace RtdClock_FSharp.AssemblyInfo

open System.Reflection
open System.Runtime.CompilerServices
open 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("RtdClock-FSharp")>]
[<assembly: AssemblyDescription("")>]
[<assembly: AssemblyConfiguration("")>]
[<assembly: AssemblyCompany("")>]
[<assembly: AssemblyProduct("RtdClock-FSharp")>]
[<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("fb526881-a282-4a04-aaa8-00b6d51b658c")>]

// 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")>]

do
()
4 changes: 4 additions & 0 deletions RtdClocks/RtdClock-FSharp/Library1.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
namespace RtdClock_FSharp

type Class1() =
member this.X = "F#"
73 changes: 73 additions & 0 deletions RtdClocks/RtdClock-FSharp/RtdClock-FSharp.fsproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>fb526881-a282-4a04-aaa8-00b6d51b658c</ProjectGuid>
<OutputType>Library</OutputType>
<RootNamespace>RtdClock_FSharp</RootNamespace>
<AssemblyName>RtdClock_FSharp</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<TargetFSharpCoreVersion>4.4.0.0</TargetFSharpCoreVersion>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Name>RtdClock-FSharp</Name>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<Tailcalls>false</Tailcalls>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Debug\RtdClock_FSharp.XML</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<Tailcalls>true</Tailcalls>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<WarningLevel>3</WarningLevel>
<DocumentationFile>bin\Release\RtdClock_FSharp.XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="mscorlib" />
<Reference Include="FSharp.Core, Version=$(TargetFSharpCoreVersion), Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.fs" />
<Compile Include="Library1.fs" />
<None Include="Script.fsx" />
</ItemGroup>
<PropertyGroup>
<MinimumVisualStudioVersion Condition="'$(MinimumVisualStudioVersion)' == ''">11</MinimumVisualStudioVersion>
</PropertyGroup>
<Choose>
<When Condition="'$(VisualStudioVersion)' == '11.0'">
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\..\Microsoft SDKs\F#\3.0\Framework\v4.0\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</When>
<Otherwise>
<PropertyGroup Condition="Exists('$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets')">
<FSharpTargetsPath>$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\FSharp\Microsoft.FSharp.Targets</FSharpTargetsPath>
</PropertyGroup>
</Otherwise>
</Choose>
<Import Project="$(FSharpTargetsPath)" />
<!-- 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>
8 changes: 8 additions & 0 deletions RtdClocks/RtdClock-FSharp/Script.fsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Learn more about F# at http://fsharp.org. See the 'F# Tutorial' project
// for more guidance on F# programming.

#load "Library1.fs"
open RtdClock_FSharp

// Define your library scripting code here

Loading

0 comments on commit f1cafd5

Please sign in to comment.