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

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

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

    1: using System;
    2: using System.Collections.Generic;
    3: using System.Linq;
    4: using System.Text.RegularExpressions;
    5: using Microsoft.EntityFrameworkCore;
    6:  
    7: namespace Ia.Cl.Model.Business.Nfc
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// TAG NFC Near-Field Communication (NFC) Support Business functions
   13:     /// </summary>
   14:     /// <value>
   15:     /// https://msdn.microsoft.com/en-us/library/z1hkazw7(v=vs.100).aspx
   16:     /// </value>
   17:     /// <remarks> 
   18:     /// Copyright © 2020-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   19:     ///
   20:     /// 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
   21:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   22:     ///
   23:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   24:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   25:     /// 
   26:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   27:     /// 
   28:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   29:     /// </remarks> 
   30:     public partial class Tag
   31:     {
   32:         /*
   33:          * Don't remove items that are obsolete, just mark them with obsolete="true"
   34:          * Insertable is true if not explicitly specified
   35:          */
   36:  
   37:         ////////////////////////////////////////////////////////////////////////////
   38:  
   39:         /// <summary>
   40:         ///
   41:         /// </summary>
   42:         public class Type
   43:         {
   44:             /// <summary/>
   45:             public int Id { get; set; }
   46:  
   47:             /// <summary/>
   48:             public string Name { get; set; }
   49:         }
   50:  
   51:         ////////////////////////////////////////////////////////////////////////////
   52:  
   53:         /// <summary>
   54:         ///
   55:         /// </summary>
   56:         public static List<Type> TypeList
   57:         {
   58:             get
   59:             {
   60:                 List<Type> list;
   61:  
   62:                 list = new List<Type>();
   63:  
   64:                 list.Add(new Type { Id = 0, Name = "NTAG 213" });
   65:  
   66:                 if (list.Select(u => u.Id).Distinct().Count() != list.Count())
   67:                 {
   68:                     throw new Exception("Duplicate Id in Ia.Cl.Model.Business.Nfc.Default.NfcTypeList.");
   69:                 }
   70:  
   71:                 return list;
   72:             }
   73:         }
   74:  
   75:         ////////////////////////////////////////////////////////////////////////////
   76:  
   77:         /// <summary>
   78:         ///
   79:         /// </summary>
   80:         public static string TypeNameById(int id)
   81:         {
   82:             string name;
   83:  
   84:             var type = (from t in Ia.Cl.Model.Business.Nfc.Tag.TypeList where t.Id == id select t).SingleOrDefault();
   85:  
   86:             name = type != null ? type.Name : string.Empty;
   87:  
   88:             return name;
   89:         }
   90:  
   91:         ////////////////////////////////////////////////////////////////////////////
   92:  
   93:         /// <summary>
   94:         ///
   95:         /// </summary>
   96:         public Tag() { }
   97:  
   98:         ////////////////////////////////////////////////////////////////////////////
   99:  
  100:         /// <summary>
  101:         ///
  102:         /// </summary>
  103:         public static Ia.Cl.Model.Db.Default.PersistentStorageState CreateOrUpdate(int projectId, string uId, int counter, string payload)
  104:         {
  105:             var dateTime = DateTime.UtcNow.AddHours(3);
  106:  
  107:             var id = Ia.Cl.Model.Business.Nfc.Default.Id(projectId, uId);
  108:  
  109:             var tagTypeId = 0;
  110:  
  111:             var tag = new Ia.Cl.Model.Nfc.Tag
  112:             {
  113:                 Id = id,
  114:                 UId = uId,
  115:                 TypeId = tagTypeId,
  116:                 ProjectId = projectId,
  117:                 Counter = counter,
  118:                 Payload = payload,
  119:                 UserId = Guid.Empty,
  120:                 Created = dateTime,
  121:                 Updated = dateTime,
  122:                 Interacted = dateTime
  123:             };
  124:  
  125:             var persistentStorageState = Ia.Cl.Model.Data.Nfc.Tag.CreateOrUpdate(tag);
  126:  
  127:             return persistentStorageState;
  128:         }
  129:  
  130:         ////////////////////////////////////////////////////////////////////////////
  131:  
  132:         /// <summary>
  133:         ///
  134:         /// </summary>
  135:         public static void ParseTagUIdAndCounter(string line, out string uId, out int counter)
  136:         {
  137:             var matchCollection = Regex.Matches(line, @"^(.+)x(.+)$");
  138:  
  139:             if (matchCollection.Count > 0)
  140:             {
  141:                 uId = matchCollection[0].Groups[1].Value;
  142:  
  143:                 var hex = matchCollection[0].Groups[2].Value;
  144:  
  145:                 counter = Ia.Cl.Model.Default.HexToDec(hex);
  146:             }
  147:             else
  148:             {
  149:                 uId = line;
  150:                 counter = -1;
  151:             }
  152:         }
  153:  
  154:         ////////////////////////////////////////////////////////////////////////////
  155:         ////////////////////////////////////////////////////////////////////////////
  156:     }
  157:  
  158:     ////////////////////////////////////////////////////////////////////////////
  159:     ////////////////////////////////////////////////////////////////////////////
  160: }