)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Skip Navigation Links

Public general use code classes and xml files that we've compiled and used over the years:

Default NFC Near-Field Communication (NFC) Support Business functions

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Configuration;
   4:  using System.Linq;
   5:   
   6:  namespace Ia.TentPlay.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:          ////////////////////////////////////////////////////////////////////////////
  32:   
  33:          /// <summary>
  34:          ///
  35:          /// </summary>
  36:          //public static int FixedLengthOfId { get { return fixedLengthOfId; } }
  37:   
  38:          ////////////////////////////////////////////////////////////////////////////
  39:   
  40:          /// <summary>
  41:          ///
  42:          /// </summary>
  43:          public class NfcProject
  44:          {
  45:              public int Id { get; set; }
  46:              public string Name { get; set; }
  47:              public string CardType { get; set; }
  48:              public string Url { get; set; }
  49:              public string ApiKeyName { get; set; }
  50:              public string ApiKeyValue { get; set; }
  51:              public List<Ia.TentPlay.Cl.Model.Business.Nfc.Inventory.Type> InventoryItemTypeList { get; set; }
  52:              public List<Ia.TentPlay.Cl.Model.Business.Nfc.Inventory.State> InventoryItemStateList { get; set; }
  53:          }
  54:   
  55:          ////////////////////////////////////////////////////////////////////////////
  56:   
  57:          /// <summary>
  58:          ///
  59:          /// </summary>
  60:          public static List<NfcProject> NfcProjectList
  61:          {
  62:              get
  63:              {
  64:                  var list = new List<NfcProject>();
  65:   
  66:                  ////////////////////////////////////////////////////////////////////////////
  67:   
  68:                  var nfcProject = new NfcProject
  69:                  {
  70:                      Id = 0,
  71:                      Name = "Scrap/NFC Inventory System Project",
  72:                      CardType = "NTAG 213",
  73:                      Url = "https://nfc.tentplay.com/p",
  74:                      ApiKeyName = "nfcTentPlayApiKey",
  75:                      ApiKeyValue = ConfigurationManager.AppSettings["nfcTentPlayApiKey"],
  76:                      InventoryItemTypeList = Ia.TentPlay.Cl.Model.Business.Nfc.Inventory.TypeList(0),
  77:                      InventoryItemStateList = Ia.TentPlay.Cl.Model.Business.Nfc.Inventory.StateList(0),
  78:                  };
  79:   
  80:                  ////////////////////////////////////////////////////////////////////////////
  81:   
  82:                  list.Add(nfcProject);
  83:   
  84:                  if (list.Select(u => u.Id).Distinct().Count() != list.Count())
  85:                  {
  86:                      throw new Exception("Duplicate Id in Ia.TentPlay.Cl.Model.Business.Nfc.Default.NfcProjectList.");
  87:                  }
  88:   
  89:                  return list;
  90:              }
  91:          }
  92:   
  93:          ////////////////////////////////////////////////////////////////////////////
  94:   
  95:          /// <summary>
  96:          ///
  97:          /// </summary>
  98:          public static NfcProject CurrentNfcProject
  99:          {
 100:              get
 101:              {
 102:                  var projectId = ConfigurationManager.AppSettings["projectId"];
 103:                  Ia.TentPlay.Cl.Model.Business.Nfc.Default.NfcProject nfcProject;
 104:   
 105:                  if (!string.IsNullOrEmpty(projectId) && int.TryParse(projectId, out int id))
 106:                  {
 107:                      nfcProject = (from n in Ia.TentPlay.Cl.Model.Business.Nfc.Default.NfcProjectList where n.Id == id select n).SingleOrDefault();
 108:   
 109:                      if (nfcProject == null)
 110:                      {
 111:                          throw new Exception("CurrentNfcProject is not defined in Ia.TentPlay.Cl.Model.Business.Nfc.Default.CurrentNfcProject.");
 112:                      }
 113:                  }
 114:                  else
 115:                  {
 116:                      nfcProject = null;
 117:   
 118:                      throw new Exception("CurrentNfcProject is not defined in Ia.TentPlay.Cl.Model.Business.Nfc.Default.CurrentNfcProject.");
 119:                  }
 120:   
 121:                  return nfcProject;
 122:              }
 123:          }
 124:   
 125:          ////////////////////////////////////////////////////////////////////////////
 126:   
 127:          /// <summary>
 128:          ///
 129:          /// </summary>
 130:          public static NfcProject NfcProjectById(int id)
 131:          {
 132:              var nfcProject = (from n in Ia.TentPlay.Cl.Model.Business.Nfc.Default.NfcProjectList where n.Id == id select n).SingleOrDefault();
 133:   
 134:              return nfcProject;
 135:          }
 136:   
 137:          ////////////////////////////////////////////////////////////////////////////
 138:   
 139:          /// <summary>
 140:          ///
 141:          /// </summary>
 142:          public static string NfcProjectNameById(int id)
 143:          {
 144:              string name;
 145:   
 146:              var nfcProject = (from n in Ia.TentPlay.Cl.Model.Business.Nfc.Default.NfcProjectList where n.Id == id select n).SingleOrDefault();
 147:   
 148:              name = nfcProject != null ? nfcProject.Name : string.Empty;
 149:   
 150:              return name;
 151:          }
 152:   
 153:          ////////////////////////////////////////////////////////////////////////////
 154:   
 155:          /// <summary>
 156:          ///
 157:          /// </summary>
 158:          public static NfcProject NfcProjectByApiKeyValue(string apiKeyValue)
 159:          {
 160:              NfcProject nfcProject;
 161:   
 162:              if (Guid.TryParse(apiKeyValue, out Guid guid))
 163:              {
 164:                  nfcProject = (from n in Ia.TentPlay.Cl.Model.Business.Nfc.Default.NfcProjectList where n.ApiKeyValue == guid.ToString() select n).SingleOrDefault();
 165:              }
 166:              else nfcProject = null;
 167:   
 168:              return nfcProject;
 169:          }
 170:   
 171:          ////////////////////////////////////////////////////////////////////////////
 172:   
 173:          /// <summary>
 174:          ///
 175:          /// </summary>
 176:          public Default()
 177:          {
 178:          }
 179:   
 180:          ////////////////////////////////////////////////////////////////////////////
 181:   
 182:          /// <summary>
 183:          ///
 184:          /// </summary>
 185:          public static string Id(int projectId, string uId)
 186:          {
 187:              string id;
 188:   
 189:              id = projectId.ToString().PadLeft(4, '0') + uId.PadLeft(14, '0');
 190:   
 191:              /*
 192:              if (id.Length != fixedLengthOfId)
 193:              {
 194:                  throw new ArgumentOutOfRangeException(@"Id(): Id length is not " + fixedLengthOfId);
 195:              }
 196:              */
 197:   
 198:              return id;
 199:          }
 200:   
 201:          ////////////////////////////////////////////////////////////////////////////
 202:          ////////////////////////////////////////////////////////////////////////////
 203:      }
 204:   
 205:      ////////////////////////////////////////////////////////////////////////////
 206:      ////////////////////////////////////////////////////////////////////////////
 207:  }