-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCallbackEnumerator.cs
195 lines (172 loc) · 6.74 KB
/
CallbackEnumerator.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//
// Copyright 2010 Thaddeus L Ryker
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Dynamics Nav is a registered trademark of the Microsoft Corporation
//
using System;
using System.Collections.Generic;
using System.Text.RegularExpressions;
using Org.Edgerunner.Dynamics.Nav.CSide.Interfaces;
namespace Org.Edgerunner.Dynamics.Nav.CSide
{
/// <summary>
/// A CallbackEnumerator for enumerating tables, records, fields, field values, and filters in a Dynamics Nav client instance
/// </summary>
internal class CallbackEnumerator : INSCallbackEnum
{
#region Non-Public Fields (6)
private Dictionary<Int32, Field> _Fields;
private Dictionary<Int32, FieldValue> _FieldValues;
private Dictionary<Int32, Filter> _Filters;
private object _Manager;
private List<Record> _Records;
private Dictionary<Int32, Table> _Tables;
#endregion Non-Public Fields
#region Properties (5)
/// <summary>
/// Gets the enumerated fields.
/// </summary>
/// <value>The fields.</value>
public Dictionary<Int32, Field> Fields
{
get { return _Fields; }
}
/// <summary>
/// Gets the enumerated field values.
/// </summary>
/// <value>The field values.</value>
public Dictionary<Int32, FieldValue> FieldValues
{
get { return _FieldValues; }
}
/// <summary>
/// Gets the enumerated filters.
/// </summary>
/// <value>The filters.</value>
public Dictionary<Int32, Filter> Filters
{
get { return _Filters; }
}
/// <summary>
/// Gets the enumerated records.
/// </summary>
/// <value>The records.</value>
public List<Record> Records
{
get { return _Records; }
}
/// <summary>
/// Gets the enumerated tables.
/// </summary>
/// <value>The tables.</value>
public Dictionary<Int32, Table> Tables
{
get { return _Tables; }
}
#endregion Properties
#region Constructors/Deconstructors (1)
/// <summary>
/// Initializes a new instance of the CallbackEnumerator class.
/// </summary>
/// <param name="manager"></param>
public CallbackEnumerator(object manager)
{
_Manager = manager;
_Fields = new Dictionary<int, Field>();
_FieldValues = new Dictionary<int, FieldValue>();
_Tables = new Dictionary<int, Table>();
_Filters = new Dictionary<int, Filter>();
_Records = new List<Record>();
}
#endregion Constructors/Deconstructors
private string CleanTimeValue(string value)
{
Regex regex = new Regex("(\\d{1,2}:\\d{1,2}:\\d{1,2})([.]\\d+)?(\\w*)",
RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
return regex.Replace(value, "$1$3");
}
#region INSCallbackEnum Members
/// <summary>
/// Receives the next record.
/// </summary>
/// <param name="record">The record.</param>
/// <returns>An <see cref="System.Int32"/> representing an error code</returns>
public int NextRecord(INSRec record)
{
// Do not pass in the record variable to our CSide.Record constructor because its lifetime expires at the end of this method
// Instead lazy loading will reconstitute a longer lifetime version later as is needed
Record rec = new Record(null, _Manager as Table);
CallbackEnumerator cbEnum = new CallbackEnumerator(rec);
record.EnumFieldValues(cbEnum);
rec._Fields = cbEnum.FieldValues;
_Records.Add(rec);
return 0;
}
/// <summary>
/// Receives the next field value.
/// </summary>
/// <param name="fieldNo">The field no.</param>
/// <param name="fieldValue">The field value.</param>
/// <param name="dataType">Type of the data.</param>
/// <returns>An <see cref="System.Int32"/> representing an error code</returns>
public int NextFieldValue(int fieldNo, string fieldValue, string dataType)
{
if (dataType == "Time")
fieldValue = CleanTimeValue(fieldValue);
_FieldValues.Add(fieldNo, new FieldValue(fieldNo, fieldValue, dataType, _Manager as Record));
return 0;
}
/// <summary>
/// Receives the next filter value.
/// </summary>
/// <param name="fieldNo">The field no.</param>
/// <param name="filterValue">The filter value.</param>
/// <returns>An <see cref="System.Int32"/> representing an error code</returns>
public int NextFilterValue(int fieldNo, string filterValue)
{
_Filters.Add(fieldNo, new Filter(fieldNo, filterValue, _Manager as Table));
return 0;
}
/// <summary>
/// Receives information about the next table.
/// </summary>
/// <param name="tableID">The table ID.</param>
/// <param name="tableName">Name of the table.</param>
/// <returns>An <see cref="System.Int32"/> representing an error code</returns>
public int NextTable(int tableID, string tableName)
{
_Tables.Add(tableID, new Table(tableID, tableName, _Manager as Client));
return 0;
}
/// <summary>
/// Receives the next field definition.
/// </summary>
/// <param name="fieldNo">The field no.</param>
/// <param name="fieldName">Name of the field.</param>
/// <param name="fieldCaption">The field caption.</param>
/// <param name="dataType">Type of the data.</param>
/// <param name="dataLength">Length of the data.</param>
/// <param name="flag">Unknown flag.</param>
/// <returns>An <see cref="System.Int32"/> representing an error code</returns>
public int NextFieldDef(int fieldNo, string fieldName, string fieldCaption, string dataType, int dataLength, int flag)
{
_Fields.Add(fieldNo, new Field(_Manager as Table, fieldNo, fieldName, fieldCaption, dataType, dataLength, flag));
return 0;
}
#endregion
}
}