شركة التطبيقات المتكاملة لتصميم النظم البرمجية الخاصة

Integrated Applications Programming Company

Skip Navigation Links

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

Ericsson's AXE support class for Ericsson's PSTN Exchange Migration to Next Generation Network (NGN) client model.

   1:  using System;
   2:  using System.Collections.Generic;
   3:  using System.Diagnostics;
   4:  using Dart.PowerTCP.Telnet;
   5:   
   6:  namespace Ia.Ngn.Cl.Model.Client.Ericsson
   7:  {
   8:      ////////////////////////////////////////////////////////////////////////////
   9:   
  10:      /// <summary publish="true">
  11:      /// Ericsson's AXE support class for Ericsson's PSTN Exchange Migration to Next Generation Network (NGN) client model.
  12:      /// </summary>
  13:      /// 
  14:      /// <remarks> 
  15:      /// Copyright © 2018-2019 Jasem Y. Al-Shamlan (info@ia.com.kw), Internet Applications - Kuwait. All Rights Reserved.
  16:      ///
  17:      /// 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
  18:      /// the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  19:      ///
  20:      /// This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  21:      /// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  22:      /// 
  23:      /// You should have received a copy of the GNU General Public License along with this library. If not, see http://www.gnu.org/licenses.
  24:      /// 
  25:      /// Copyright notice: This notice may not be removed or altered from any source distribution.
  26:      /// </remarks> 
  27:      public class Axe
  28:      {
  29:          private byte[] buffer = new byte[1024];
  30:          internal Telnet telnet;
  31:   
  32:          /// <summary/>
  33:          public string LastSentCommand { get; private set; }
  34:   
  35:          /// <summary/>
  36:          public Queue<string> ReceiveQueue { get; set; }
  37:   
  38:          /// <summary/>
  39:          public Queue<string> SendQueue { get; set; }
  40:   
  41:          ////////////////////////////////////////////////////////////////////////////
  42:   
  43:          /// <summary>
  44:          ///
  45:          /// </summary>
  46:          public enum ResultCode
  47:          {
  48:              OperationIsSuccessful = 0,
  49:              NotAcceptedUnreasonableValue = 1,
  50:              NotConnected = 2,
  51:              OperationFailed = 999,
  52:          }
  53:   
  54:          ////////////////////////////////////////////////////////////////////////////
  55:   
  56:          /// <summary>
  57:          ///
  58:          /// </summary>
  59:          public Axe()
  60:          {
  61:              telnet = new Dart.PowerTCP.Telnet.Telnet();
  62:   
  63:              telnet.ClientOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.SuppressGoAheads, null, Dart.PowerTCP.Telnet.OptionState.RequestOn));
  64:              telnet.ClientOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.SuppressLocalEcho, null, Dart.PowerTCP.Telnet.OptionState.RequestOn));
  65:   
  66:              telnet.ServerOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.SuppressGoAheads, null, Dart.PowerTCP.Telnet.OptionState.RequestOn));
  67:              telnet.ServerOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.SuppressLocalEcho, null, Dart.PowerTCP.Telnet.OptionState.RequestOn));
  68:              telnet.ServerOptions.Add(new Dart.PowerTCP.Telnet.Option(Dart.PowerTCP.Telnet.OptionCode.OutputPageSize, null, Dart.PowerTCP.Telnet.OptionState.RequestOn));
  69:   
  70:              telnet.TerminalType = "tty";
  71:   
  72:              telnet.EndReceive += new Dart.PowerTCP.Telnet.SegmentEventHandler(this.Telnet_EndReceive);
  73:              telnet.ConnectedChangedEx += new Dart.PowerTCP.Telnet.EventHandlerEx(this.Telnet_ConnectedChangedEx);
  74:   
  75:              ReceiveQueue = new Queue<string>(100);
  76:              SendQueue = new Queue<string>(100);
  77:   
  78:              IsLoggedIn = false;
  79:          }
  80:   
  81:          ////////////////////////////////////////////////////////////////////////////
  82:   
  83:          /// <summary>
  84:          ///
  85:          /// </summary>
  86:          ~Axe()
  87:          {
  88:              Dispose();
  89:          }
  90:   
  91:          ////////////////////////////////////////////////////////////////////////////
  92:   
  93:          /// <summary>
  94:          ///
  95:          /// </summary>
  96:          public void Connect(out Ia.Cl.Model.Result result)
  97:          {
  98:              result = new Ia.Cl.Model.Result();
  99:   
 100:              try
 101:              {
 102:                  telnet.Connect(Ia.Ngn.Cl.Model.Business.Ericsson.Axe.Host, Ia.Ngn.Cl.Model.Business.Ericsson.Axe.Port.ToString());
 103:   
 104:                  // receive using asynchronous technique
 105:                  telnet.ReceiveTimeout = 0;
 106:                  telnet.BeginReceive(buffer);
 107:   
 108:                  result.AddSuccess("Connected. ");
 109:              }
 110:              catch (Exception ex)
 111:              {
 112:                  result.AddError("Exception: " + ex.Message);
 113:   
 114:                  telnet.Close();
 115:              }
 116:          }
 117:   
 118:          ////////////////////////////////////////////////////////////////////////////
 119:   
 120:          /// <summary>
 121:          ///
 122:          /// </summary>
 123:          public void Disconnect(out Ia.Cl.Model.Result result)
 124:          {
 125:              result = new Ia.Cl.Model.Result();
 126:   
 127:              try
 128:              {
 129:                  telnet.Close();
 130:   
 131:                  result.AddSuccess("Disconnected. ");
 132:              }
 133:              catch (Exception ex)
 134:              {
 135:                  result.AddError(ex.Message);
 136:              }
 137:          }
 138:   
 139:          ////////////////////////////////////////////////////////////////////////////
 140:   
 141:          /// <summary>
 142:          ///
 143:          /// </summary>
 144:          public bool IsConnected
 145:          {
 146:              get
 147:              {
 148:                  return telnet.Connected;
 149:              }
 150:          }
 151:   
 152:          ////////////////////////////////////////////////////////////////////////////
 153:   
 154:          /// <summary>
 155:          ///
 156:          /// </summary>
 157:          public bool IsLoggedIn { get; set; }
 158:   
 159:          ////////////////////////////////////////////////////////////////////////////
 160:   
 161:          /// <summary>
 162:          ///
 163:          /// </summary>
 164:          public void Dispose()
 165:          {
 166:              telnet.Dispose();
 167:          }
 168:   
 169:          ////////////////////////////////////////////////////////////////////////////
 170:   
 171:          /// <summary>
 172:          ///
 173:          /// </summary>
 174:          public void SendQueueUserName()
 175:          {
 176:              SendQueue.Enqueue(Ia.Ngn.Cl.Model.Business.Ericsson.Axe.UserName);
 177:          }
 178:   
 179:          ////////////////////////////////////////////////////////////////////////////
 180:   
 181:          /// <summary>
 182:          ///
 183:          /// </summary>
 184:          public void SendQueuePassword()
 185:          {
 186:              SendQueue.Enqueue(Ia.Ngn.Cl.Model.Business.Ericsson.Axe.Password);
 187:          }
 188:   
 189:          ////////////////////////////////////////////////////////////////////////////
 190:   
 191:          /// <summary>
 192:          ///
 193:          /// </summary>
 194:          public void SendQueueLogoutCommand()
 195:          {
 196:              SendQueue.Enqueue(Ia.Ngn.Cl.Model.Business.Ericsson.Axe.LogoutCommand);
 197:          }
 198:   
 199:          ////////////////////////////////////////////////////////////////////////////
 200:   
 201:          /// <summary>
 202:          ///
 203:          /// </summary>
 204:          public void Send(string text, out Ia.Cl.Model.Result result)
 205:          {
 206:              result = new Ia.Cl.Model.Result();
 207:   
 208:              try
 209:              {
 210:                  if (telnet.Connected)
 211:                  {
 212:                      if (text != null)
 213:                      {
 214:                          LastSentCommand = text;
 215:   
 216:                          telnet.Send(text + "\r\n");
 217:   
 218:                          result.AddSuccess("Sent: " + text);
 219:                      }
 220:                      else
 221:                      {
 222:                          result.AddError("No text to send. ");
 223:                      }
 224:                  }
 225:                  else
 226:                  {
 227:                      result.AddError("No established telnet connection. ");
 228:                      //if(processRunning) waitToConnectionCounter = waitToConnectionCounterSeconds;
 229:                  }
 230:              }
 231:              catch (Exception ex)
 232:              {
 233:                  result.AddError(ex.Message);
 234:              }
 235:          }
 236:   
 237:          ////////////////////////////////////////////////////////////////////////////
 238:   
 239:          /// <summary>
 240:          ///
 241:          /// </summary>
 242:          private void Telnet_EndReceive(object sender, Dart.PowerTCP.Telnet.SegmentEventArgs e)
 243:          {
 244:              string rowString, filteredString;
 245:   
 246:              Debug.WriteLine(" ");
 247:              Debug.WriteLine("============================================");
 248:   
 249:              try
 250:              {
 251:                  if (e.Exception == null)
 252:                  {
 253:                      rowString = e.Segment.ToString();
 254:   
 255:                      filteredString = rowString.Replace("\u0003", "").Replace("<", "").Trim();
 256:   
 257:                      Debug.WriteLine("Telnet_EndReceive(): e.Segment: [" + rowString + "]; filteredString: [" + filteredString + "]");
 258:   
 259:                      if (!string.IsNullOrEmpty(filteredString))
 260:                      {
 261:                          if (filteredString != LastSentCommand) // to ignore echoed command
 262:                          {
 263:                              Debug.WriteLine("Telnet_EndReceive(): ReceiveQueue.Enqueue(filteredString); filteredString: [" + filteredString + "]");
 264:   
 265:                              ReceiveQueue.Enqueue(filteredString);
 266:                          }
 267:                      }
 268:                      else
 269:                      {
 270:   
 271:                      }
 272:   
 273:                      telnet.BeginReceive(buffer);
 274:                  }
 275:                  else
 276:                  {
 277:                      throw new Exception("Telnet_EndReceive(): " + e.Exception.Message);
 278:                  }
 279:              }
 280:              catch (System.Net.Sockets.SocketException se)
 281:              {
 282:                  Debug.WriteLine("Telnet_EndReceive(): System.Net.Sockets.SocketException: " + se.ToString());
 283:              }
 284:   
 285:              Debug.WriteLine("============================================");
 286:              Debug.WriteLine(" ");
 287:          }
 288:   
 289:          ////////////////////////////////////////////////////////////////////////////
 290:   
 291:          /// <summary>
 292:          ///
 293:          /// </summary>
 294:          private void Telnet_ConnectedChangedEx(object sender, System.EventArgs e)
 295:          {
 296:   
 297:          }
 298:   
 299:          ////////////////////////////////////////////////////////////////////////////
 300:   
 301:          /// <summary>
 302:          ///
 303:          /// </summary>
 304:          public void Update(string formattedString, ref Ia.Ngn.Cl.Model.Client.Ericsson.Axe axe, out Ia.Cl.Model.Result result)
 305:          {
 306:              Ia.Ngn.Cl.Model.Data.Ericsson.Axe.UpdateDatabaseWithAxeCommandOutput(formattedString, ref axe, out result);
 307:          }
 308:   
 309:          ////////////////////////////////////////////////////////////////////////////
 310:          ////////////////////////////////////////////////////////////////////////////
 311:      }
 312:   
 313:      ////////////////////////////////////////////////////////////////////////////
 314:      ////////////////////////////////////////////////////////////////////////////
 315:  }