Professional Applications Programmers/Consultants برمجة واستشارات تطبيقات الإنترنت
Skip Navigation LinksHome » Code Library » Transction

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

Transction support class of Next Generation Network'a (NGN's) business model.

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