-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfooTester.cs
More file actions
103 lines (89 loc) · 2.6 KB
/
fooTester.cs
File metadata and controls
103 lines (89 loc) · 2.6 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
using Genetec.Sdk;
using Genetec.Sdk.Entities;
using Genetec.Sdk.Enumerations;
using Genetec.Sdk.Queries;
using Genetec.Sdk.Scripting;
using Genetec.Sdk.Scripting.Interfaces.Attributes;
using System;
using System.Data;
using System.Linq;
using System.Xml;
using System.Collections.Generic;
using System.IO;
[MacroParameters()]
public sealed class footester : UserMacro
{
public string foo { get; set; }
/// <summary>
/// wrote this test Genetec Macro to figure out how to set input paramter value.
/// I needed the capability to clear input in another macro ran so input wasn't doubly applied if the macro was run again.
/// </summary>
Macro _footester = null;
public override void Execute()
{
string logFile = @"C:\genetec\footest.log";
StreamWriter file = System.IO.File.CreateText(logFile);
try
{
file.WriteLine("---------- Macro started ---------- ");
List<Guid> macros = GetAllEntity(EntityType.Macro);
file.WriteLine(" found " + macros.Count + " macros.");
foreach (Guid macroguid in macros)
{
Macro macro = Sdk.GetEntity(macroguid) as Macro;
if (macro == null)
continue;
if (macro.Name.Contains("footester"))
{
file.WriteLine(" macro found is namedd " + macro.Name);
Macro.ReadOnlyMacroParameterCollection macroParams = (macro.DefaultParameters);
// 1. Create the input parameter collection
file.WriteLine("got a ref to parameters.");
foreach (var paramDef in macroParams)
{
file.WriteLine($" Param Name: {paramDef.Name}, Type: {paramDef.Type}, Value:{paramDef.Value}");
macroParams["foo"].Value = "whoopi";
macro.SetDefaultParameters(macroParams);
}
}
}
}
catch (Exception ex)
{
file.WriteLine(ex.ToString());
}
finally
{
file.WriteLine("*** End of batch ***");
file.WriteLine("---------- Macro stopped ---------- ");
file.Close();
file.Dispose();
}
}
/// <summary>
/// Called when the macro needs to clean up.
/// </summary>
protected override void CleanUp()
{
// Release objects created by the Execute method, unhook events, and so on.
}
private List<Guid> GetAllEntity(EntityType entityType)
{
List<Guid> entityGuids = new List<Guid>();
EntityConfigurationQuery query = Sdk.ReportManager.CreateReportQuery(ReportType.EntityConfiguration) as EntityConfigurationQuery;
query.EntityTypes.Add(entityType);
QueryCompletedEventArgs args = query.Query();
if (args.Success)
{
foreach (DataRow row in args.Data.Rows)
{
entityGuids.Add((Guid)row["GUID"]);
}
}
else
{
throw new Exception(entityType.ToString() + " query failed.");
}
return entityGuids;
}
}