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