forked from Excel-DNA/Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ExcelFunctions.cs
81 lines (73 loc) · 2.74 KB
/
ExcelFunctions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExcelDna.Integration;
namespace ObjectHandles
{
public static class ExcelFunctions
{
static DataService _dataService = new DataService();
static ObjectHandler _objectHandler = new ObjectHandler(_dataService);
public static object TestHandleSample()
{
return "Hello form ObjectHandles!";
}
public static object CreateDataObject1(string code)
{
return _objectHandler.GetHandle("DataObject1", new object[] { code },
(objectType, parameters) => _dataService.ProcessRequest(objectType, parameters));
}
public static string GetCode(string handle)
{
object value;
// TODO: We might be able to strongly type the GetObject...
if (_objectHandler.TryGetObject(handle, out value))
{
DataObject1 data = (DataObject1)value;
return data.Code;
}
// No object for the handle ...
return "!!! INVALID HANDLE";
}
public static object GetDateTime(string handle)
{
object value;
// TODO: We might be able to strongly type the GetObject...
if (_objectHandler.TryGetObject(handle, out value))
{
DataObject1 data = (DataObject1)value;
return data.DateTime;
}
// No object for the handle ...
return "!!! INVALID HANDLE";
}
public static object GetValue(string handle)
{
object value;
// TODO: We might be able to strongly type the GetObject...
if (_objectHandler.TryGetObject(handle, out value))
{
DataObject1 data = (DataObject1)value;
return data.Value;
}
// No object for the handle ...
return "!!! INVALID HANDLE";
}
// Forces a refresh of all the objects in the handler
// All objects will be recreated and return a new handle, invalidating all dependencies.
[ExcelCommand(MenuName="Object Handler", MenuText="Refresh All")]
public static void RefreshAll()
{
_objectHandler.RefreshAll();
}
// Does an update of all objects in the handler
// This is done by a query to the back end, passing in the current rowversions.
// When the query is done, only the objects with updated rowversions will be refreshed with a new handle.
[ExcelCommand(MenuName = "Object Handler", MenuText = "Update All")]
public static void UpdateAll()
{
_objectHandler.UpdateAll();
}
}
}