)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Temp (Ia.Cl.Models.Db)

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

Temporary Storage support class.

    1: using System.Collections.Generic;
    2: using System.Text.Json;
    3: using System.Text.Json.Serialization;
    4:  
    5: namespace Ia.Cl.Models.Db
    6: {
    7:     ////////////////////////////////////////////////////////////////////////////
    8:  
    9:     /// <summary publish="true">
   10:     /// Temporary Storage support class.
   11:     /// </summary>
   12:     /// <remarks> 
   13:     /// Copyright © 2015-2021 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   14:     ///
   15:     /// 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
   16:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   17:     ///
   18:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   19:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   20:     /// 
   21:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   22:     /// 
   23:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   24:     /// </remarks> 
   25:     public static class Temp
   26:     {
   27:         ////////////////////////////////////////////////////////////////////////////
   28:  
   29:         /// <summary>
   30:         ///
   31:         /// </summary>
   32:         public static class Dictionary
   33:         {
   34:             private static Dictionary<string, Dictionary<string, string>> dictionaryDictionary = new Dictionary<string, Dictionary<string, string>>();
   35:  
   36:             ////////////////////////////////////////////////////////////////////////////
   37:  
   38:             /// <summary>
   39:             ///
   40:             /// </summary>
   41:             public static void Add(string name, string key, string value)
   42:             {
   43:                 if (!string.IsNullOrEmpty(name))
   44:                 {
   45:                     if (!dictionaryDictionary.ContainsKey(name))
   46:                     {
   47:                         var dictionary = new Dictionary<string, string>();
   48:  
   49:                         dictionaryDictionary[name] = dictionary;
   50:                     }
   51:  
   52:                     dictionaryDictionary[name][key] = value;
   53:                 }
   54:             }
   55:  
   56:             ////////////////////////////////////////////////////////////////////////////
   57:  
   58:             /// <summary>
   59:             ///
   60:             /// </summary>
   61:             public static Dictionary<string, string> Get(string name)
   62:             {
   63:                 var dictionary = new Dictionary<string, string>();
   64:  
   65:                 if (!string.IsNullOrEmpty(name))
   66:                 {
   67:                     if (dictionaryDictionary.ContainsKey(name))
   68:                     {
   69:                         dictionary = dictionaryDictionary[name];
   70:                     }
   71:                 }
   72:  
   73:                 return dictionary;
   74:             }
   75:  
   76:             ////////////////////////////////////////////////////////////////////////////
   77:  
   78:             /// <summary>
   79:             ///
   80:             /// </summary>
   81:             public static int Count(string name)
   82:             {
   83:                 var c = 0;
   84:  
   85:                 if (!string.IsNullOrEmpty(name))
   86:                 {
   87:                     if (dictionaryDictionary.ContainsKey(name))
   88:                     {
   89:                         c = dictionaryDictionary[name].Count;
   90:                     }
   91:                 }
   92:  
   93:                 return c;
   94:             }
   95:  
   96:             ////////////////////////////////////////////////////////////////////////////
   97:         }
   98:  
   99:         ////////////////////////////////////////////////////////////////////////////
  100:  
  101:         /// <summary>
  102:         ///
  103:         /// </summary>
  104:         public static class List
  105:         {
  106:             private static Dictionary<string, List<string>> listDictionary = new Dictionary<string, List<string>>();
  107:  
  108:             ////////////////////////////////////////////////////////////////////////////
  109:  
  110:             /// <summary>
  111:             ///
  112:             /// </summary>
  113:             public static void Add(string name, string value)
  114:             {
  115:                 if (!string.IsNullOrEmpty(name))
  116:                 {
  117:                     if (!listDictionary.ContainsKey(name))
  118:                     {
  119:                         var list = new List<string>();
  120:  
  121:                         listDictionary[name] = list;
  122:                     }
  123:  
  124:                     listDictionary[name].Add(value);
  125:                 }
  126:             }
  127:  
  128:             ////////////////////////////////////////////////////////////////////////////
  129:  
  130:             /// <summary>
  131:             ///
  132:             /// </summary>
  133:             public static List<string> Get(string name)
  134:             {
  135:                 var list = new List<string>();
  136:  
  137:                 if (!string.IsNullOrEmpty(name))
  138:                 {
  139:                     if (listDictionary.ContainsKey(name))
  140:                     {
  141:                         list = listDictionary[name];
  142:                     }
  143:                 }
  144:  
  145:                 return list;
  146:             }
  147:  
  148:             ////////////////////////////////////////////////////////////////////////////
  149:  
  150:             /// <summary>
  151:             ///
  152:             /// </summary>
  153:             public static int Count(string name)
  154:             {
  155:                 var c = 0;
  156:  
  157:                 if (!string.IsNullOrEmpty(name))
  158:                 {
  159:                     if (listDictionary.ContainsKey(name))
  160:                     {
  161:                         c = listDictionary[name].Count;
  162:                     }
  163:                 }
  164:  
  165:                 return c;
  166:             }
  167:  
  168:             ////////////////////////////////////////////////////////////////////////////
  169:         }
  170:  
  171:         ////////////////////////////////////////////////////////////////////////////
  172:         ////////////////////////////////////////////////////////////////////////////
  173:  
  174:         /// <summary>
  175:         ///
  176:         /// </summary>
  177:         public static class Queue
  178:         {
  179:             private static Dictionary<string, Queue<string>> queueDictionary = new Dictionary<string, Queue<string>>();
  180:  
  181:             ////////////////////////////////////////////////////////////////////////////
  182:  
  183:             /// <summary>
  184:             ///
  185:             /// </summary>
  186:             public static void Enqueue(string name, string value)
  187:             {
  188:                 if (!string.IsNullOrEmpty(name))
  189:                 {
  190:                     if (!queueDictionary.ContainsKey(name))
  191:                     {
  192:                         var queue = new Queue<string>();
  193:  
  194:                         queueDictionary[name] = queue;
  195:                     }
  196:  
  197:                     queueDictionary[name].Enqueue(value);
  198:                 }
  199:             }
  200:  
  201:             ////////////////////////////////////////////////////////////////////////////
  202:  
  203:             /// <summary>
  204:             ///
  205:             /// </summary>
  206:             public static string Dequeue(string name)
  207:             {
  208:                 var value = string.Empty;
  209:  
  210:                 if (!string.IsNullOrEmpty(name))
  211:                 {
  212:                     if (queueDictionary.ContainsKey(name))
  213:                     {
  214:                         value = queueDictionary[name].Dequeue();
  215:                     }
  216:                 }
  217:  
  218:                 return value;
  219:             }
  220:  
  221:             ////////////////////////////////////////////////////////////////////////////
  222:  
  223:             /// <summary>
  224:             ///
  225:             /// </summary>
  226:             public static int Count(string name)
  227:             {
  228:                 var c = 0;
  229:  
  230:                 if (!string.IsNullOrEmpty(name))
  231:                 {
  232:                     if (queueDictionary.ContainsKey(name))
  233:                     {
  234:                         c = queueDictionary[name].Count;
  235:                     }
  236:                 }
  237:  
  238:                 return c;
  239:             }
  240:  
  241:             ////////////////////////////////////////////////////////////////////////////
  242:             ////////////////////////////////////////////////////////////////////////////
  243:         }
  244:  
  245:         ////////////////////////////////////////////////////////////////////////////
  246:         ////////////////////////////////////////////////////////////////////////////
  247:  
  248:         /// <summary>
  249:         ///
  250:         /// </summary>
  251:         public static class Object
  252:         {
  253:             private static Dictionary<string, string> jsonDictionary = new Dictionary<string, string>();
  254:  
  255:             ////////////////////////////////////////////////////////////////////////////
  256:  
  257:             /// <summary>
  258:             ///
  259:             /// </summary>
  260:             private static T Deserialize<T>(string json)
  261:             {
  262:                 T t;
  263:  
  264:                 if (!string.IsNullOrEmpty(json))
  265:                 {
  266:                     t = JsonSerializer.Deserialize<T>(json);
  267:                 }
  268:                 else t = default;
  269:  
  270:                 return t;
  271:             }
  272:  
  273:             ////////////////////////////////////////////////////////////////////////////
  274:  
  275:             /// <summary>
  276:             ///
  277:             /// </summary>
  278:             public static void Write<T>(string name, T t)
  279:             {
  280:                 var jsonSerializerOptions = new JsonSerializerOptions
  281:                 {
  282:                     WriteIndented = true
  283:                 };
  284:  
  285:                 var json = JsonSerializer.Serialize<T>(t, jsonSerializerOptions);
  286:  
  287:                 jsonDictionary[name] = json;
  288:             }
  289:  
  290:             ////////////////////////////////////////////////////////////////////////////
  291:  
  292:             /// <summary>
  293:             ///
  294:             /// </summary>
  295:             public static T Read<T>(string name)
  296:             {
  297:                 T t;
  298:  
  299:                 if (jsonDictionary.ContainsKey(name))
  300:                 {
  301:                     var json = jsonDictionary[name];
  302:  
  303:                     t = Deserialize<T>(json);
  304:                 }
  305:                 else t = default;
  306:  
  307:                 return t;
  308:             }
  309:  
  310:             ////////////////////////////////////////////////////////////////////////////
  311:             ////////////////////////////////////////////////////////////////////////////
  312:         }
  313:  
  314:         ////////////////////////////////////////////////////////////////////////////
  315:         ////////////////////////////////////////////////////////////////////////////
  316:     }
  317: }
  318: