1: using System;
2: using System.Collections.Generic;
3: using System.Configuration;
4: using System.Linq;
5:
6: namespace Ia.Cl.Model.Business.Nfc
7: {
8: ////////////////////////////////////////////////////////////////////////////
9:
10: /// <summary publish="true">
11: /// Default NFC Near-Field Communication (NFC) Support Business functions
12: /// </summary>
13: ///
14: /// <remarks>
15: /// Copyright © 2020-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
16: ///
17: /// This library is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by
18: /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
19: ///
20: /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
21: /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
22: ///
23: /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
24: ///
25: /// Copyright notice: This notice may not be removed or altered from any source distribution.
26: /// </remarks>
27: public class Default
28: {
29: // private const int fixedLengthOfId = 18;
30:
31: //public static int FixedLengthOfId { get { return fixedLengthOfId; } }
32:
33: /// <summary/>
34: public enum ProjectType
35: {
36: /// <summary/>
37: Inventory,
38:
39: /// <summary/>
40: UrlRedirection
41: }
42:
43: ////////////////////////////////////////////////////////////////////////////
44:
45: /// <summary>
46: ///
47: /// </summary>
48: public class NfcProject
49: {
50: /// <summary/>
51: public int Id { get; set; }
52:
53: /// <summary/>
54: public Guid Guid { get; set; }
55:
56: /// <summary/>
57: public string Name { get; set; }
58:
59: /// <summary/>
60: public ProjectType ProjectType { get; set; }
61:
62: /// <summary/>
63: public string CardType { get; set; }
64:
65: /// <summary/>
66: public string Url { get; set; }
67:
68: /// <summary/>
69: public string ApiKeyName { get; set; }
70:
71: /// <summary/>
72: public string ApiKeyValue { get; set; }
73:
74: /// <summary/>
75: public List<Ia.Cl.Model.Business.Nfc.Inventory.Type> InventoryItemTypeList { get; set; }
76:
77: /// <summary/>
78: public List<Ia.Cl.Model.Business.Nfc.Inventory.State> InventoryItemStateList { get; set; }
79: }
80:
81: ////////////////////////////////////////////////////////////////////////////
82:
83: /// <summary>
84: ///
85: /// </summary>
86: public static List<NfcProject> NfcProjectList
87: {
88: get
89: {
90: var list = new List<NfcProject>();
91:
92: ////////////////////////////////////////////////////////////////////////////
93:
94: list.Add(new NfcProject
95: {
96: Id = 0,
97: Name = "Scrap/NFC Inventory System Project",
98: Guid = Guid.Parse("69c7df71-ca57-4627-8fc4-42fa4caec9a4"),
99: ProjectType = ProjectType.Inventory,
100: CardType = "NTAG 213",
101: Url = "https://nfc.ia.com.kw/p",
102: ApiKeyName = "nfcApiKey",
103: ApiKeyValue = ConfigurationManager.AppSettings["nfcApiKey"],
104: InventoryItemTypeList = Ia.Cl.Model.Business.Nfc.Inventory.TypeList(0),
105: InventoryItemStateList = Ia.Cl.Model.Business.Nfc.Inventory.StateList(0),
106: });
107:
108: ////////////////////////////////////////////////////////////////////////////
109:
110: list.Add(new NfcProject
111: {
112: Id = 1,
113: Name = "Boutiqaat",
114: Guid = Guid.Parse("3e540d34-2e8a-4fc5-bcda-03d11dc044f0"),
115: ProjectType = ProjectType.UrlRedirection,
116: CardType = "NTAG 213",
117: Url = "https://nfc.ia.com.kw/p",
118: ApiKeyName = "nfcApiKey",
119: ApiKeyValue = ConfigurationManager.AppSettings["nfcApiKey"],
120: });
121:
122: ////////////////////////////////////////////////////////////////////////////
123:
124: if (list.Select(u => u.Id).Distinct().Count() != list.Count())
125: {
126: throw new Exception("Duplicate Id in Ia.Cl.Model.Business.Nfc.Default.NfcProjectList.");
127: }
128:
129: return list;
130: }
131: }
132:
133: /*
134: ////////////////////////////////////////////////////////////////////////////
135:
136: /// <summary>
137: ///
138: /// </summary>
139: public static NfcProject CurrentNfcProject
140: {
141: get
142: {
143: var projectId = ConfigurationManager.AppSettings["projectId"];
144: Ia.Cl.Model.Business.Nfc.Default.NfcProject nfcProject;
145:
146: if (!string.IsNullOrEmpty(projectId) && int.TryParse(projectId, out int id))
147: {
148: nfcProject = (from n in Ia.Cl.Model.Business.Nfc.Default.NfcProjectList where n.Id == id select n).SingleOrDefault();
149:
150: if (nfcProject == null)
151: {
152: throw new Exception("CurrentNfcProject is not defined in Ia.Cl.Model.Business.Nfc.Default.CurrentNfcProject.");
153: }
154: }
155: else
156: {
157: nfcProject = null;
158:
159: throw new Exception("CurrentNfcProject is not defined in Ia.Cl.Model.Business.Nfc.Default.CurrentNfcProject.");
160: }
161:
162: return nfcProject;
163: }
164: }
165: */
166:
167: ////////////////////////////////////////////////////////////////////////////
168:
169: /// <summary>
170: ///
171: /// </summary>
172: public static NfcProject NfcProjectById(int id)
173: {
174: var nfcProject = (from n in Ia.Cl.Model.Business.Nfc.Default.NfcProjectList where n.Id == id select n).SingleOrDefault();
175:
176: return nfcProject;
177: }
178:
179: ////////////////////////////////////////////////////////////////////////////
180:
181: /// <summary>
182: ///
183: /// </summary>
184: public static string NfcProjectNameById(int id)
185: {
186: string name;
187:
188: var nfcProject = (from n in Ia.Cl.Model.Business.Nfc.Default.NfcProjectList where n.Id == id select n).SingleOrDefault();
189:
190: name = nfcProject != null ? nfcProject.Name : string.Empty;
191:
192: return name;
193: }
194:
195: ////////////////////////////////////////////////////////////////////////////
196:
197: /// <summary>
198: ///
199: /// </summary>
200: public static NfcProject NfcProjectByApiKeyValue(string apiKeyValue)
201: {
202: NfcProject nfcProject;
203:
204: if (Guid.TryParse(apiKeyValue, out Guid guid))
205: {
206: nfcProject = (from n in Ia.Cl.Model.Business.Nfc.Default.NfcProjectList where n.ApiKeyValue == guid.ToString() select n).SingleOrDefault();
207: }
208: else nfcProject = null;
209:
210: return nfcProject;
211: }
212:
213: ////////////////////////////////////////////////////////////////////////////
214: ////////////////////////////////////////////////////////////////////////////
215:
216: /// <summary>
217: ///
218: /// </summary>
219: public class UIdUrl
220: {
221: /// <summary/>
222: public string UId { get; set; }
223:
224: /// <summary/>
225: public string Url { get; set; }
226: }
227:
228: ////////////////////////////////////////////////////////////////////////////
229: ////////////////////////////////////////////////////////////////////////////
230:
231: /// <summary>
232: ///
233: /// </summary>
234: public class NfcProjectIdUIdUrlListItem
235: {
236: /// <summary/>
237: public int ProjectId { get; set; }
238:
239: /// <summary/>
240: public string Url { get; set; }
241:
242: /// <summary/>
243: public List<Ia.Cl.Model.Business.Nfc.Default.UIdUrl> uIdUrlList { get; set; }
244: }
245:
246: ////////////////////////////////////////////////////////////////////////////
247:
248: /// <summary>
249: ///
250: /// </summary>
251: public Default()
252: {
253: }
254:
255: ////////////////////////////////////////////////////////////////////////////
256:
257: /// <summary>
258: ///
259: /// </summary>
260: public static string Id(int projectId, string uId)
261: {
262: string id;
263:
264: id = projectId.ToString().PadLeft(4, '0') + uId.PadLeft(14, '0');
265:
266: /*
267: if (id.Length != fixedLengthOfId)
268: {
269: throw new ArgumentOutOfRangeException(@"Id(): Id length is not " + fixedLengthOfId);
270: }
271: */
272:
273: return id;
274: }
275:
276: ////////////////////////////////////////////////////////////////////////////
277: ////////////////////////////////////////////////////////////////////////////
278: }
279:
280: ////////////////////////////////////////////////////////////////////////////
281: ////////////////////////////////////////////////////////////////////////////
282: }