)>}]
شركة التطبيقات المتكاملة لتصميم وبرمجة البرمجيات الخاصة ش.ش.و.
Integrated Applications Programming Company
Home » Code Library » Transction (Ia.Ftn.Cl.Model.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.Model.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:     ///
   12:     /// 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
   13:     /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
   14:     ///
   15:     /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
   16:     /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
   17:     /// 
   18:     /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
   19:     /// 
   20:     /// Copyright notice: This notice may not be removed or altered from any source distribution.
   21:     /// </remarks> 
   22:     public class Transction
   23:     {
   24:         /*
   25:         private static int currentItemId;
   26:         private static StringBuilder log = new StringBuilder(100000);
   27: 
   28:         /// <summary/>
   29:         public enum ProcessState
   30:         {
   31:             Initiated = 1, NoPendingTransaction = 2
   32:         }
   33: 
   34:         ////////////////////////////////////////////////////////////////////////////
   35: 
   36:         /// <summary>
   37:         ///
   38:         /// </summary>
   39:         public static int Inbox(Transaction.Recipient recipientId, Transaction.Priority priorityId, string message)
   40:         {
   41:             bool b;
   42:             int itemId;
   43:             Transaction newItem;
   44: 
   45:             newItem = new Transaction();
   46: 
   47:             newItem.Message = message;
   48:             newItem.RecipientId = (int)recipientId;
   49:             newItem.PriorityId = (int)priorityId;
   50:             newItem.RecipientId = (int)recipientId;
   51:             newItem.RecipientId = (int)recipientId;
   52: 
   53:             newItem.Created = newItem.Updated = DateTime.UtcNow.AddHours(3);
   54: 
   55:             b = Transaction.Create(newItem, out itemId);
   56: 
   57:             currentItemId = itemId;
   58: 
   59:             return itemId;
   60:         }
   61: 
   62:         ////////////////////////////////////////////////////////////////////////////
   63: 
   64:         /// <summary>
   65:         ///
   66:         /// </summary>
   67:         public static string Outbox(int itemId) 
   68:         {
   69:             string response;
   70:             Transaction transaction;
   71: 
   72:             response = null;
   73: 
   74:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
   75:             {
   76:                 // below:
   77:                 transaction = (from q in db.Transactions where q.Id == itemId select q).FirstOrDefault();
   78: 
   79:                 if (transaction != null)
   80:                 {
   81:                     // below:
   82:                     response = transaction.Response;
   83:                 }
   84:                 else
   85:                 {
   86:                 }
   87: 
   88:                 db.SaveChanges();
   89:             }
   90: 
   91:             return response;
   92:         }
   93: 
   94:         ////////////////////////////////////////////////////////////////////////////
   95: 
   96:         /// <summary>
   97:         ///
   98:         /// </summary>
   99:         public static ProcessState Process(ref Dart.PowerTCP.Telnet.Telnet telnet, Ia.Ftn.Cl.Model.Transaction.Recipient recepientId)
  100:         {
  101:             bool messageSent;
  102:             ProcessState processState;
  103:             string s;
  104: 
  105:             // below:
  106: 
  107:             processState = ProcessState.Initiated;
  108: 
  109:             messageSent = false;
  110:             List<Transaction> itemList;
  111: 
  112:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  113:             {
  114:                 // below:
  115:                 itemList = (from q in db.Transactions where q.RecipientId == (int)recepientId && q.Closed == false && q.NumberOfTimesMessageSent == 0 select q).ToList();
  116: 
  117:                 if (itemList.Count > 0)
  118:                 {
  119:                     foreach (Transaction transaction in itemList)
  120:                     {
  121:                         // below: DEBUG
  122:                         if (/*true ||* / telnet.Connected)
  123:                         {
  124:                             try
  125:                             {
  126:                                 foreach (char c in transaction.Message.ToCharArray())
  127:                                 {
  128:                                     s = c.ToString();
  129: 
  130:                                     // below: DEBUG
  131:                                     telnet.Send(s);
  132: 
  133:                                     // below: log
  134:                                     log.Append(s);
  135: 
  136:                                     Thread.Sleep(20); // 20 milliseconds for bytes
  137:                                 }
  138: 
  139:                                 messageSent = true;
  140:                             }
  141:                             catch (Exception)
  142:                             {
  143:                                 messageSent = false;
  144:                             }
  145:                             
  146:                             if (messageSent)
  147:                             {
  148:                                 // below:
  149:                                 transaction.NumberOfTimesMessageSent++;
  150:                                 transaction.MessageSent = transaction.Updated = DateTime.UtcNow.AddHours(3);
  151:                             }
  152:                             else
  153:                             {
  154:                                 transaction.MessageSent = null;
  155:                             }
  156:                         }
  157:                         else
  158:                         {
  159:                             // below: no connection
  160:                             transaction.StateId = (int)Ia.Ftn.Cl.Model.Transaction.State.NoConnection;
  161:                             transaction.Updated = DateTime.UtcNow.AddHours(3);
  162:                         }
  163:                     }
  164:                 }
  165:                 else
  166:                 {
  167:                     processState = ProcessState.NoPendingTransaction;
  168:                 }
  169: 
  170:                 db.SaveChanges();
  171:             }
  172: 
  173:             return processState;
  174:         }
  175: 
  176:         ////////////////////////////////////////////////////////////////////////////
  177: 
  178:         /// <summary>
  179:         ///
  180:         /// </summary>
  181:         public static void ProcessReceive(string receivedData)
  182:         {
  183:             Transaction transaction;
  184: 
  185:             using (var db = new Ia.Ftn.Cl.Model.Ftn())
  186:             {
  187:                 // below:
  188:                 transaction = (from q in db.Transactions where q.Id == currentItemId && q.Closed == false select q).FirstOrDefault();
  189: 
  190:                 if (transaction != null)
  191:                 {
  192:                     // below:
  193:                     transaction.Response = Ia.Cl.Models.Telnet.FormatAndCleanData(receivedData);
  194:                     transaction.ResponseReceived = transaction.Updated = DateTime.UtcNow.AddHours(3);
  195:                     transaction.StateId = (int)Transaction.State.Closed;
  196:                     transaction.Closed = true;
  197: 
  198:                     db.SaveChanges();
  199:                 }
  200:                 else
  201:                 {
  202:                 }
  203:             }
  204:         }
  205: 
  206:         ////////////////////////////////////////////////////////////////////////////
  207: 
  208:         /// <summary>
  209:         ///
  210:         /// </summary>
  211:         public static StringBuilder Log
  212:         {
  213:             get
  214:             {
  215:                 return log;
  216:             }
  217:         }
  218: 
  219:         ////////////////////////////////////////////////////////////////////////////
  220: 
  221:         /// <summary>
  222:         ///
  223:         /// </summary>
  224:         public static void Second() 
  225:         { 
  226:         }
  227:          */
  228:  
  229:         ////////////////////////////////////////////////////////////////////////////    
  230:         ////////////////////////////////////////////////////////////////////////////    
  231:     }
  232:  
  233:     ////////////////////////////////////////////////////////////////////////////
  234:     ////////////////////////////////////////////////////////////////////////////   
  235: }