Skip to content

Commit ec7d312

Browse files
committed
Create RtdArrayTest sample
1 parent 8d082a6 commit ec7d312

File tree

9 files changed

+271
-0
lines changed

9 files changed

+271
-0
lines changed

RtdArrayTest/Code

1.45 MB
Binary file not shown.
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("RtdArrayTest")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("RtdArrayTest")]
13+
[assembly: AssemblyCopyright("Copyright © 2015")]
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("6630cf2e-1eca-4343-b04b-159b07ec00ff")]
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")]

RtdArrayTest/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Simple RTD server with array function wrapper
2+
3+
This sample was created to provide a simple RTD server to check the behaviour of RTD functions when called from array formulas.
4+
5+
The wrapper function has signature
6+
```c#
7+
public static object RtdArrayTest(string prefix)
8+
```
9+
and returns a 2x1 array.
10+
11+
The function can be called from Excel as an array formula (with Ctrl+Shift+Enter) using another reference as the "prefix".
12+
```
13+
{=RtdArrayTest(A1)}
14+
```
15+
16+
The implementation of the RTD server is based on the Excel-DNA base class `ExcelRtdServer`, and just uses a Timer to update the topics.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<DnaLibrary Name="RtdArrayTest Add-In" RuntimeVersion="v4.0">
2+
<ExternalLibrary Path="RtdArrayTest.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>

RtdArrayTest/RtdArrayTest.csproj

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="12.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>{42E4844E-00E2-47DD-B97E-E94AC94A7E96}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>RtdArrayTest</RootNamespace>
11+
<AssemblyName>RtdArrayTest</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</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">
34+
<HintPath>packages\Excel-DNA.Lib.0.32.0\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.Xml" />
44+
</ItemGroup>
45+
<ItemGroup>
46+
<Compile Include="TestFunctions.cs" />
47+
<Compile Include="TestRtdServer.cs" />
48+
<Compile Include="Properties\AssemblyInfo.cs" />
49+
</ItemGroup>
50+
<ItemGroup>
51+
<Content Include="RtdArrayTest-AddIn.dna">
52+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
53+
</Content>
54+
<None Include="packages.config" />
55+
</ItemGroup>
56+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
57+
<PropertyGroup>
58+
<PostBuildEvent>xcopy "$(ProjectDir)packages\Excel-DNA.0.32.0\tools\ExcelDna.xll" "$(TargetDir)RtdArrayTest-AddIn.xll*" /C /Y
59+
xcopy "$(TargetDir)RtdArrayTest-AddIn.dna*" "$(TargetDir)RtdArrayTest-AddIn64.dna*" /C /Y
60+
xcopy "$(ProjectDir)packages\Excel-DNA.0.32.0\tools\ExcelDna64.xll" "$(TargetDir)RtdArrayTest-AddIn64.xll*" /C /Y
61+
"$(ProjectDir)packages\Excel-DNA.0.32.0\tools\ExcelDnaPack.exe" "$(TargetDir)RtdArrayTest-AddIn.dna" /Y
62+
"$(ProjectDir)packages\Excel-DNA.0.32.0\tools\ExcelDnaPack.exe" "$(TargetDir)RtdArrayTest-AddIn64.dna" /Y</PostBuildEvent>
63+
</PropertyGroup>
64+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
65+
Other similar extension points exist, see Microsoft.Common.targets.
66+
<Target Name="BeforeBuild">
67+
</Target>
68+
<Target Name="AfterBuild">
69+
</Target>
70+
-->
71+
</Project>

RtdArrayTest/RtdArrayTest.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 2013
4+
VisualStudioVersion = 12.0.30602.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RtdArrayTest", "RtdArrayTest.csproj", "{42E4844E-00E2-47DD-B97E-E94AC94A7E96}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{42E4844E-00E2-47DD-B97E-E94AC94A7E96}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{42E4844E-00E2-47DD-B97E-E94AC94A7E96}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{42E4844E-00E2-47DD-B97E-E94AC94A7E96}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{42E4844E-00E2-47DD-B97E-E94AC94A7E96}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

RtdArrayTest/TestFunctions.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using ExcelDna.Integration;
7+
8+
namespace RtdArrayTest
9+
{
10+
public static class TestFunctions
11+
{
12+
public static object RtdArrayTest(string prefix)
13+
{
14+
object rtdValue = XlCall.RTD("RtdArrayTest.TestRtdServer", null, prefix);
15+
16+
var resultString = rtdValue as string;
17+
if (resultString == null)
18+
return rtdValue;
19+
20+
// We have a string value, parse and return as an 2x1 array
21+
var parts = resultString.Split(';');
22+
Debug.Assert(parts.Length == 2);
23+
var result = new object[2, 1];
24+
result[0, 0] = parts[0];
25+
result[1, 0] = parts[1];
26+
return result;
27+
}
28+
}
29+
}

RtdArrayTest/TestRtdServer.cs

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Runtime.InteropServices;
6+
using System.Text;
7+
using System.Threading;
8+
using ExcelDna.Integration;
9+
using ExcelDna.Integration.Rtd;
10+
11+
namespace RtdArrayTest
12+
{
13+
class TestArrayTopic : ExcelRtdServer.Topic
14+
{
15+
public string Prefix;
16+
17+
public TestArrayTopic(ExcelRtdServer server, int topicId) :
18+
base(server, topicId)
19+
{
20+
}
21+
}
22+
23+
[ComVisible(true)]
24+
public class TestRtdServer : ExcelRtdServer
25+
{
26+
Random _random = new Random();
27+
Timer _timer;
28+
List<TestArrayTopic> _topics;
29+
30+
protected override bool ServerStart()
31+
{
32+
_timer = new Timer(UpdateTopics, null, TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1));
33+
_topics = new List<TestArrayTopic>();
34+
return true;
35+
}
36+
37+
protected override void ServerTerminate()
38+
{
39+
_timer.Dispose();
40+
_timer = null;
41+
}
42+
43+
protected override Topic CreateTopic(int topicId, IList<string> topicInfo)
44+
{
45+
return new TestArrayTopic(this, topicId) { Prefix = topicInfo[0] };
46+
}
47+
48+
protected override object ConnectData(Topic topic, IList<string> topicInfo, ref bool newValues)
49+
{
50+
TestArrayTopic testArrayTopic = (TestArrayTopic)topic;
51+
_topics.Add(testArrayTopic);
52+
Debug.Print("ConnectData - Prefix {0}", testArrayTopic.Prefix);
53+
return ExcelErrorUtil.ToComError(ExcelError.ExcelErrorNA);
54+
}
55+
56+
protected override void DisconnectData(Topic topic)
57+
{
58+
TestArrayTopic testArrayTopic = (TestArrayTopic)topic;
59+
_topics.Remove(testArrayTopic);
60+
Debug.Print("DisconnectData - Prefix {0}", testArrayTopic.Prefix);
61+
}
62+
63+
void UpdateTopics(object _unused_)
64+
{
65+
foreach (TestArrayTopic topic in _topics)
66+
{
67+
var value = topic.Prefix + ":" + DateTime.Now.ToString("HH:mm:ss.fff") + ";" + _random.NextDouble().ToString("F5");
68+
topic.UpdateValue(value);
69+
}
70+
}
71+
}
72+
}

RtdArrayTest/packages.config

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="Excel-DNA" version="0.32.0" targetFramework="net40" />
4+
<package id="Excel-DNA.Lib" version="0.32.0" targetFramework="net40" />
5+
</packages>

0 commit comments

Comments
 (0)