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

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

Transction support class of Fixed Telecommunications Network (FTN) business model.

    1: namespace Ia.Ftn.Cl.Models.Business
    2: {
    3:     ////////////////////////////////////////////////////////////////////////////
    4:  
    5:     /// <summary publish="true">
    6:     /// Transction support class of Fixed Telecommunications Network (FTN) business model.
    7:     /// </summary>
    8:     /// 
    9:     /// <remarks> 
   10:     /// Copyright © 2006-2017 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   11:     /// </remarks> 
   12:     public class Transction
   13:     {
   14:         /*
   15:         private static int currentItemId;
   16:         private static StringBuilder log = new StringBuilder(100000);
   17: 
   18:         /// <summary/>
   19:         public enum ProcessState
   20:         {
   21:             Initiated = 1, NoPendingTransaction = 2
   22:         }
   23: 
   24:         ////////////////////////////////////////////////////////////////////////////
   25: 
   26:         /// <summary>
   27:         ///
   28:         /// </summary>
   29:         public static int Inbox(Transaction.Recipient recipientId, Transaction.Priority priorityId, string message)
   30:         {
   31:             bool b;
   32:             int itemId;
   33:             Transaction newItem;
   34: 
   35:             newItem = new Transaction();
   36: 
   37:             newItem.Message = message;
   38:             newItem.RecipientId = (int)recipientId;
   39:             newItem.PriorityId = (int)priorityId;
   40:             newItem.RecipientId = (int)recipientId;
   41:             newItem.RecipientId = (int)recipientId;
   42: 
   43:             newItem.Created = newItem.Updated = DateTime.UtcNow.AddHours(3);
   44: 
   45:             b = Transaction.Create(newItem, out itemId);
   46: 
   47:             currentItemId = itemId;
   48: 
   49:             return itemId;
   50:         }
   51: 
   52:         ////////////////////////////////////////////////////////////////////////////
   53: 
   54:         /// <summary>
   55:         ///
   56:         /// </summary>
   57:         public static string Outbox(int itemId) 
   58:         {
   59:             string response;
   60:             Transaction transaction;
   61: 
   62:             response = null;
   63: 
   64:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
   65:             {
   66:                 // below:
   67:                 transaction = (from q in db.Transactions where q.Id == itemId select q).FirstOrDefault();
   68: 
   69:                 if (transaction != null)
   70:                 {
   71:                     // below:
   72:                     response = transaction.Response;
   73:                 }
   74:                 else
   75:                 {
   76:                 }
   77: 
   78:                 db.SaveChanges();
   79:             }
   80: 
   81:             return response;
   82:         }
   83: 
   84:         ////////////////////////////////////////////////////////////////////////////
   85: 
   86:         /// <summary>
   87:         ///
   88:         /// </summary>
   89:         public static ProcessState Process(ref Dart.Telnet.Telnet telnet, Ia.Ftn.Cl.Model.Transaction.Recipient recepientId)
   90:         {
   91:             bool messageSent;
   92:             ProcessState processState;
   93:             string s;
   94: 
   95:             // below:
   96: 
   97:             processState = ProcessState.Initiated;
   98: 
   99:             messageSent = false;
  100:             List<Transaction> itemList;
  101: 
  102:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  103:             {
  104:                 // below:
  105:                 itemList = (from q in db.Transactions where q.RecipientId == (int)recepientId && q.Closed == false && q.NumberOfTimesMessageSent == 0 select q).ToList();
  106: 
  107:                 if (itemList.Count > 0)
  108:                 {
  109:                     foreach (Transaction transaction in itemList)
  110:                     {
  111:                         // below: DEBUG
  112:                         if (/*true ||* / telnet.Connected)
  113:                         {
  114:                             try
  115:                             {
  116:                                 foreach (char c in transaction.Message.ToCharArray())
  117:                                 {
  118:                                     s = c.ToString();
  119: 
  120:                                     // below: DEBUG
  121:                                     telnet.Send(s);
  122: 
  123:                                     // below: log
  124:                                     log.Append(s);
  125: 
  126:                                     Thread.Sleep(20); // 20 milliseconds for bytes
  127:                                 }
  128: 
  129:                                 messageSent = true;
  130:                             }
  131:                             catch (Exception)
  132:                             {
  133:                                 messageSent = false;
  134:                             }
  135:                             
  136:                             if (messageSent)
  137:                             {
  138:                                 // below:
  139:                                 transaction.NumberOfTimesMessageSent++;
  140:                                 transaction.MessageSent = transaction.Updated = DateTime.UtcNow.AddHours(3);
  141:                             }
  142:                             else
  143:                             {
  144:                                 transaction.MessageSent = null;
  145:                             }
  146:                         }
  147:                         else
  148:                         {
  149:                             // below: no connection
  150:                             transaction.StateId = (int)Ia.Ftn.Cl.Model.Transaction.State.NoConnection;
  151:                             transaction.Updated = DateTime.UtcNow.AddHours(3);
  152:                         }
  153:                     }
  154:                 }
  155:                 else
  156:                 {
  157:                     processState = ProcessState.NoPendingTransaction;
  158:                 }
  159: 
  160:                 db.SaveChanges();
  161:             }
  162: 
  163:             return processState;
  164:         }
  165: 
  166:         ////////////////////////////////////////////////////////////////////////////
  167: 
  168:         /// <summary>
  169:         ///
  170:         /// </summary>
  171:         public static void ProcessReceive(string receivedData)
  172:         {
  173:             Transaction transaction;
  174: 
  175:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  176:             {
  177:                 // below:
  178:                 transaction = (from q in db.Transactions where q.Id == currentItemId && q.Closed == false select q).FirstOrDefault();
  179: 
  180:                 if (transaction != null)
  181:                 {
  182:                     // below:
  183:                     transaction.Response = Ia.Cl.Models.Telnet.FormatAndCleanData(receivedData);
  184:                     transaction.ResponseReceived = transaction.Updated = DateTime.UtcNow.AddHours(3);
  185:                     transaction.StateId = (int)Transaction.State.Closed;
  186:                     transaction.Closed = true;
  187: 
  188:                     db.SaveChanges();
  189:                 }
  190:                 else
  191:                 {
  192:                 }
  193:             }
  194:         }
  195: 
  196:         ////////////////////////////////////////////////////////////////////////////
  197: 
  198:         /// <summary>
  199:         ///
  200:         /// </summary>
  201:         public static StringBuilder Log
  202:         {
  203:             get
  204:             {
  205:                 return log;
  206:             }
  207:         }
  208: 
  209:         ////////////////////////////////////////////////////////////////////////////
  210: 
  211:         /// <summary>
  212:         ///
  213:         /// </summary>
  214:         public static void Second() 
  215:         { 
  216:         }
  217:          */
  218:  
  219:         ////////////////////////////////////////////////////////////////////////////    
  220:         ////////////////////////////////////////////////////////////////////////////    
  221:     }
  222:  
  223:     ////////////////////////////////////////////////////////////////////////////
  224:     ////////////////////////////////////////////////////////////////////////////   
  225: }