1 |
using System; |
2 |
using System.Collections.Generic; |
3 |
using System.Text; |
4 |
|
5 |
using gr2lib.core.typedefs; |
6 |
using gr2lib.core.exceptions; |
7 |
|
8 |
namespace gr2lib.core.apiversion |
9 |
{ |
10 |
#region public class VersionType |
11 |
public interface Iversiontype |
12 |
{ |
13 |
granny_int32x major { get; } |
14 |
granny_int32x minor { get; } |
15 |
granny_int32x customization { get; } |
16 |
granny_int32x build { get; } |
17 |
string version { get; } |
18 |
} |
19 |
|
20 |
public class versiontype : Iversiontype |
21 |
{ |
22 |
/// <summary> |
23 |
/// default versiontype construction: 0.0.0.0 |
24 |
/// </summary> |
25 |
public versiontype() |
26 |
{ |
27 |
this.major = 0; |
28 |
this.minor = 0; |
29 |
this.customization = 0; |
30 |
this.build = 0; |
31 |
} |
32 |
/// <summary> |
33 |
/// versiontype construction: major.minor.customization.build |
34 |
/// </summary> |
35 |
public versiontype(granny_int32x major, granny_int32x minor, granny_int32x customization, granny_int32x build) |
36 |
{ |
37 |
this.major = major; |
38 |
this.minor = minor; |
39 |
this.customization = customization; |
40 |
this.build = build; |
41 |
} |
42 |
/// <summary> |
43 |
/// versiontype construction: major.minor.customization.build (via string: "0.0.0.0") |
44 |
/// </summary> |
45 |
public versiontype(string version) |
46 |
{ |
47 |
string[] _version = version.Split('.'); |
48 |
|
49 |
this.major = _version[0]; |
50 |
this.minor = _version[1]; |
51 |
this.customization = _version[2]; |
52 |
this.build = _version[3]; |
53 |
} |
54 |
/// <summary> |
55 |
/// Gets this version in format: major.minor.customization.build |
56 |
/// </summary> |
57 |
/// <returns></returns> |
58 |
public override string ToString() |
59 |
{ |
60 |
return this.version; |
61 |
} |
62 |
|
63 |
#region IVersionType Members |
64 |
/// <summary> |
65 |
/// Returns a string representation of the Granny2 API Version in format (major.minor.customization.build) |
66 |
/// </summary> |
67 |
public string version { get { return string.Format("{0}.{1}.{2}.{3}", major, minor, customization, build); } } |
68 |
private granny_int32x _major; |
69 |
/// <summary> |
70 |
/// Returns the Major of the Granny2 API Version (X.0.0.0) |
71 |
/// </summary> |
72 |
public granny_int32x major { get { return _major; } private set { _major = value; } } |
73 |
|
74 |
private granny_int32x _minor; |
75 |
/// <summary> |
76 |
/// Returns the Minor of the Granny2 API Version (0.X.0.0) |
77 |
/// </summary> |
78 |
public granny_int32x minor { get { return _minor; } private set { _minor = value; } } |
79 |
|
80 |
private granny_int32x _customization; |
81 |
/// <summary> |
82 |
/// Returns the Customization of the Granny2 API Version - Customization (0.0.X.0) |
83 |
/// </summary> |
84 |
public granny_int32x customization { get { return _customization; } private set { _customization = value; } } |
85 |
|
86 |
private granny_int32x _build; |
87 |
/// <summary> |
88 |
/// Returns the Build of the Granny2 API Version (0.0.0.X) |
89 |
/// </summary> |
90 |
public granny_int32x build { get { return _build; } private set { _build = value; } } |
91 |
#endregion |
92 |
} |
93 |
#endregion |
94 |
|
95 |
#region public class Granny2APIVersion |
96 |
public interface igranny2apiversion |
97 |
{ |
98 |
bool apiversionsmatch { get; } |
99 |
versiontype apiversion { get; } |
100 |
versiontype expectedapiversion { get; } |
101 |
} |
102 |
/// <summary> |
103 |
/// Handle's the checking of the Loaded Granny2 API Version |
104 |
/// </summary> |
105 |
public class granny2apiversion : igranny2apiversion |
106 |
{ |
107 |
/// <summary> |
108 |
/// Default granny2apiversion Constructor: Expect Granny2 API -> 2.7.0.30 |
109 |
/// </summary> |
110 |
public granny2apiversion() |
111 |
{ |
112 |
this._expectedapiversion = new versiontype( |
113 |
apiversiontype.GrannyProductMajorVersion, |
114 |
apiversiontype.GrannyProductMinorVersion, |
115 |
apiversiontype.GrannyProductCustomization, |
116 |
apiversiontype.GrannyProductBuildNumber); |
117 |
|
118 |
granny2apiloader _loader = new granny2apiloader(); |
119 |
this._apiversion = new versiontype(); |
120 |
this._apiversionsmatch = this.GrannyVersionsMatch(); |
121 |
this.GetGrannyVersion(); |
122 |
|
123 |
} |
124 |
/// <summary> |
125 |
/// granny2apiversion Constructor: set Granny2 API -> major.minor.customization.build |
126 |
/// </summary> |
127 |
public granny2apiversion(granny_int32x ExpectedMajorVersion, granny_int32x ExpectedMinorVersion, granny_int32x ExpectedCustomization, granny_int32x ExpectedBuildNumber) |
128 |
{ |
129 |
this._expectedapiversion = new versiontype( |
130 |
ExpectedMajorVersion, |
131 |
ExpectedMinorVersion, |
132 |
ExpectedCustomization, |
133 |
ExpectedBuildNumber); |
134 |
|
135 |
granny2apiloader _loader = new granny2apiloader(); |
136 |
this._apiversion = new versiontype(); |
137 |
this._apiversionsmatch = this.GrannyVersionsMatch(); |
138 |
this.GetGrannyVersion(); |
139 |
} |
140 |
/// <summary> |
141 |
/// granny2apiversion Constructor: set Granny2 API -> major.minor.customization.build (via string: "0.0.0.0") |
142 |
/// </summary> |
143 |
public granny2apiversion(string ExceptedVersion) |
144 |
{ |
145 |
this._expectedapiversion = new versiontype(ExceptedVersion); |
146 |
|
147 |
granny2apiloader _loader = new granny2apiloader(); |
148 |
this._apiversion = new versiontype(); |
149 |
this._apiversionsmatch = this.GrannyVersionsMatch(); |
150 |
this.GetGrannyVersion(); |
151 |
} |
152 |
|
153 |
#region APIVersion Support |
154 |
private class apiversiontype |
155 |
{ |
156 |
public static string GrannyProductVersion = "2.7.0.30"; |
157 |
public static granny_int32x GrannyProductMajorVersion = 2; |
158 |
public static granny_int32x GrannyProductMinorVersion = 7; |
159 |
public static granny_int32x GrannyProductCustomization = 0; |
160 |
public static granny_int32x GrannyProductBuildNumber = 30; |
161 |
public static string GrannyProductReleaseName = "release"; |
162 |
}; |
163 |
|
164 |
private bool GrannyVersionsMatch() |
165 |
{ |
166 |
return gr2lib.core.coreapi.GrannyVersionsMatch( |
167 |
this._expectedapiversion.major, |
168 |
this._expectedapiversion.minor, |
169 |
this._expectedapiversion.customization, |
170 |
this._expectedapiversion.build); |
171 |
} |
172 |
private void GetGrannyVersion() |
173 |
{ |
174 |
granny_int32x major = 0; |
175 |
granny_int32x minor = 0; |
176 |
granny_int32x customization = 0; |
177 |
granny_int32x build = 0; |
178 |
|
179 |
gr2lib.core.coreapi.GrannyGetVersion( |
180 |
ref major, |
181 |
ref minor, |
182 |
ref customization, |
183 |
ref build); |
184 |
|
185 |
this._apiversion = new versiontype(major, minor, customization, build); |
186 |
|
187 |
} |
188 |
private string GrannyGetVersionString() |
189 |
{ |
190 |
return gr2lib.core.coreapi.GrannyGetVersionString(); |
191 |
} |
192 |
#endregion |
193 |
|
194 |
#region IGranny2APIVersion Members |
195 |
private bool _apiversionsmatch = false; |
196 |
/// <summary> |
197 |
/// Indicates that the Loaded Granny2 API Version matches the version that the core library was built against |
198 |
/// </summary> |
199 |
public bool apiversionsmatch { get { return _apiversionsmatch; } } |
200 |
private versiontype _apiversion; |
201 |
/// <summary> |
202 |
/// Gets the Loaded Granny2 API Version |
203 |
/// </summary> |
204 |
public versiontype apiversion { get { return _apiversion; } } |
205 |
private versiontype _expectedapiversion; |
206 |
/// <summary> |
207 |
/// Gets the Expected Granny2 API Version |
208 |
/// </summary> |
209 |
public versiontype expectedapiversion { get { return _expectedapiversion; } } |
210 |
#endregion |
211 |
} |
212 |
#endregion |
213 |
} |