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

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 Fixed Telecommunications Network (FTN) client model.

    1: using Dart.Telnet;
    2: using Ia.Cl.Models;
    3: using System;
    4: using System.Collections.Generic;
    5: using System.Security.Cryptography.X509Certificates;
    6:  
    7: namespace Ia.Ftn.Cl.Models.Client.Ericsson
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Ericsson's AXE support class for Ericsson's PSTN Exchange Migration to Fixed Telecommunications Network (FTN) client model.
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright © 2018-2020 Jasem Y. Al-Shamlan (info@ia.com.kw), Integrated Applications - Kuwait. All Rights Reserved.
   17:     /// </remarks> 
   18:     public class Axe
   19:     {
   20:         private byte[] buffer = new byte[1024];
   21:         private TelnetModel telnetModel;
   22:         private Dart.Telnet.Telnet telnet;
   23:         private X509CertificateCollection clientCertificates = new X509CertificateCollection();
   24:         private System.ComponentModel.IContainer components;
   25:  
   26:         /// <summary/>
   27:         public Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn Pstn { get; private set; }
   28:  
   29:         /// <summary/>
   30:         public string LastSentCommand { get; private set; }
   31:  
   32:         /// <summary/>
   33:         public Queue<string> ReceiveQueue { get; set; }
   34:  
   35:         /// <summary/>
   36:         public Queue<string> SendQueue { get; set; }
   37:  
   38:         /// <summary/>
   39:         public bool IsLoggedIn { get; set; }
   40:  
   41:         ////////////////////////////////////////////////////////////////////////////
   42:  
   43:         /// <summary>
   44:         ///
   45:         /// </summary>
   46:         public enum ResultCode
   47:         {
   48:             /// <summary/>
   49:             Successful = 0,
   50:  
   51:             /// <summary/>
   52:             NotAcceptedUnreasonableValue = 1,
   53:  
   54:             /// <summary/>
   55:             NotAcceptedCommandUnknown = 2,
   56:  
   57:             /// <summary/>
   58:             SubscriberNotConnected = 41,
   59:  
   60:             /// <summary/>
   61:             UnknownError = 100,
   62:  
   63:             /// <summary/>
   64:             Failed = 101,
   65:  
   66:             /// <summary/>
   67:             TimeOut = 102,
   68:         }
   69:  
   70:         ////////////////////////////////////////////////////////////////////////////
   71:  
   72:         /// <summary>
   73:         ///
   74:         /// </summary>
   75:         public Axe(Ia.Ftn.Cl.Models.Business.NetworkDesignDocument.Pstn pstn)
   76:         {
   77:             Pstn = pstn;
   78:  
   79:             components = new System.ComponentModel.Container();
   80:  
   81:             Dart.Telnet.Option option1 = new Dart.Telnet.Option();
   82:             Dart.Telnet.Option option2 = new Dart.Telnet.Option();
   83:             Dart.Telnet.Option option3 = new Dart.Telnet.Option();
   84:             Dart.Telnet.Option option4 = new Dart.Telnet.Option();
   85:             Dart.Telnet.Option option5 = new Dart.Telnet.Option();
   86:  
   87:             telnet = new Dart.Telnet.Telnet(components);
   88:  
   89:             option1.Code = Dart.Telnet.OptionCode.SuppressGoAheads;
   90:             option2.Code = Dart.Telnet.OptionCode.WindowSize;
   91:             option2.SubOption = new byte[] { 0, 80, 0, 24 };
   92:             option3.Code = Dart.Telnet.OptionCode.TerminalType;
   93:             option3.SubOption = new byte[] { 0, 116, 116, 121 };
   94:             telnet.ClientOptions.AddRange(new Dart.Telnet.Option[] { option1, option2, option3 });
   95:  
   96:             option4.Code = Dart.Telnet.OptionCode.SuppressGoAheads;
   97:             option5.Code = Dart.Telnet.OptionCode.Echo;
   98:             telnet.ServerOptions.AddRange(new Dart.Telnet.Option[] { option4, option5 });
   99:  
  100:             telnet.SocketOption.ReceiveTimeout = 1000;
  101:             telnet.SynchronizingObject = null;
  102:             telnet.ClientOptionChanged += Telnet_ClientOptionChanged;
  103:             telnet.ServerOptionChanged += Telnet_ServerOptionChanged;
  104:             telnet.Data += Telnet_Data;
  105:             telnet.StateChanged += Telnet_StateChanged;
  106:             telnet.Log += Telnet_Log;
  107:             telnet.Error += Telnet_Error;
  108:  
  109:             telnetModel = new TelnetModel();
  110:  
  111:             // set non-serializable Telnet component
  112:             telnetModel.Telnet = telnet;
  113:             telnetModel.ReceiveLoopRequired = true;
  114:  
  115:             // subscribe to certificate events
  116:             telnetModel.CertificateRequested += new EventHandler<LocalCertificateEventArgs>(TelnetModel_CertificateRequested);
  117:             telnetModel.CertificatePresented += new EventHandler<RemoteCertificateEventArgs>(TelnetModel_CertificatePresented);
  118:  
  119:             /*
  120:             telnet = new Dart.Telnet.Telnet();
  121: 
  122:             telnet.ClientOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.SuppressGoAheads, null, Dart.Telnet.OptionState.RequestOn));
  123:             telnet.ClientOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.SuppressLocalEcho, null, Dart.Telnet.OptionState.RequestOn));
  124: 
  125:             telnet.ServerOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.SuppressGoAheads, null, Dart.Telnet.OptionState.RequestOn));
  126:             telnet.ServerOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.SuppressLocalEcho, null, Dart.Telnet.OptionState.RequestOn));
  127:             telnet.ServerOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.OutputPageSize, null, Dart.Telnet.OptionState.RequestOn));
  128:             */
  129:  
  130:             //telnet.TerminalType = "tty";
  131:             //telnet.TerminalType = "xterm";
  132:  
  133:             ReceiveQueue = new Queue<string>(100);
  134:             SendQueue = new Queue<string>(100);
  135:  
  136:             IsLoggedIn = false;
  137:         }
  138:  
  139:         ////////////////////////////////////////////////////////////////////////////
  140:  
  141:         /// <summary>
  142:         ///
  143:         /// </summary>
  144:         ~Axe()
  145:         {
  146:             Dispose(true);
  147:         }
  148:  
  149:         ////////////////////////////////////////////////////////////////////////////
  150:  
  151:         /// <summary>
  152:         ///
  153:         /// </summary>
  154:         public Ia.Cl.Models.Result Connect()
  155:         {
  156:             var result = new Ia.Cl.Models.Result();
  157:  
  158:             SendQueue.Clear();
  159:  
  160:             // if a model with a matching server exists, remove it, then add it so that it is first in the list
  161:             telnetModel.Session.RemoteEndPoint = new IPEndPoint(Ia.Ftn.Cl.Models.Business.Ericsson.Axe.Host(Pstn), Ia.Ftn.Cl.Models.Business.Ericsson.Axe.Port);
  162:             telnetModel.Credentials.Username = string.Empty; // txtUsername.Text;
  163:             telnetModel.Credentials.Password = string.Empty; // txtPassword.Text;
  164:             telnetModel.Credentials.CommandPrompt = string.Empty; // txtCommandPrompt.Text;
  165:             telnetModel.Credentials.UsernamePrompt = string.Empty; // txtLoginPrompt.Text;
  166:             telnetModel.Credentials.PasswordPrompt = string.Empty; // txtPasswordPrompt.Text;
  167:             telnetModel.SecurityType = SecurityType.None; // (SecurityType)cboSecurity.SelectedIndex;
  168:             telnetModel.SaveSession();
  169:  
  170:             if (telnetModel.Session.RemoteEndPoint.Port == 23)
  171:             {
  172:                 telnetModel.Telnet.ClientOptions.Add(new Option(OptionCode.SuppressGoAheads, null, OptionState.RequestOn));
  173:                 telnetModel.Telnet.ClientOptions.Add(new Option(OptionCode.WindowSize, new System.Byte[] { ((System.Byte)(0)), ((System.Byte)(80)), ((System.Byte)(0)), ((System.Byte)(24)) }, OptionState.RequestOn));
  174:                 telnetModel.Telnet.ClientOptions.Add(new Option(OptionCode.TerminalType, new System.Byte[] { ((System.Byte)(0)), ((System.Byte)(116)), ((System.Byte)(116)), ((System.Byte)(121)) }, OptionState.RequestOn));
  175:  
  176:                 telnetModel.Telnet.ServerOptions.Add(new Option(OptionCode.SuppressGoAheads, null, OptionState.RequestOn));
  177:                 telnetModel.Telnet.ServerOptions.Add(new Option(OptionCode.Echo, null, OptionState.RequestOn));
  178:                 telnetModel.Telnet.ServerOptions.Add(new Option(OptionCode.OutputPageSize, null, OptionState.RequestOn));
  179:             }
  180:             else
  181:             {
  182:                 telnetModel.Telnet.ClientOptions.Clear();
  183:                 telnetModel.Telnet.ServerOptions.Clear();
  184:             }
  185:  
  186:             // connect and receive data on a separate thread
  187:             telnet.Start(telnetModel.Connect, null);
  188:  
  189:             result.AddSuccess("Connected");
  190:  
  191:             return result;
  192:         }
  193:  
  194:         ////////////////////////////////////////////////////////////////////////////
  195:  
  196:         /// <summary>
  197:         ///
  198:         /// </summary>
  199:         public Ia.Cl.Models.Result Disconnect()
  200:         {
  201:             var result = new Ia.Cl.Models.Result();
  202:  
  203:             try
  204:             {
  205:                 telnetModel.Telnet.Close();
  206:  
  207:                 SendQueue.Clear();
  208:  
  209:                 result.AddSuccess("Disconnected");
  210:             }
  211:             catch (Exception ex)
  212:             {
  213:                 result.AddError(ex.Message);
  214:             }
  215:  
  216:             return result;
  217:         }
  218:  
  219:         ////////////////////////////////////////////////////////////////////////////
  220:  
  221:         /// <summary>
  222:         ///
  223:         /// </summary>
  224:         public bool IsConnected
  225:         {
  226:             get
  227:             {
  228:                 return telnetModel.IsConnected;
  229:             }
  230:         }
  231:  
  232:         ////////////////////////////////////////////////////////////////////////////
  233:  
  234:         /// <summary>
  235:         ///
  236:         /// </summary>
  237:         protected /*override*/ void Dispose(bool disposing)
  238:         {
  239:             if (disposing)
  240:             {
  241:                 if (components != null)
  242:                 {
  243:                     components.Dispose();
  244:                 }
  245:             }
  246:  
  247:             //base.Dispose(disposing);
  248:         }
  249:  
  250:         ////////////////////////////////////////////////////////////////////////////
  251:  
  252:         /// <summary>
  253:         ///
  254:         /// </summary>
  255:         public void SendQueueUserName()
  256:         {
  257:             SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Ericsson.Axe.UserName(Pstn));
  258:         }
  259:  
  260:         ////////////////////////////////////////////////////////////////////////////
  261:  
  262:         /// <summary>
  263:         ///
  264:         /// </summary>
  265:         public void SendQueuePassword()
  266:         {
  267:             SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Ericsson.Axe.Password(Pstn));
  268:         }
  269:  
  270:         ////////////////////////////////////////////////////////////////////////////
  271:  
  272:         /// <summary>
  273:         ///
  274:         /// </summary>
  275:         public void SendQueueLogoutCommand()
  276:         {
  277:             SendQueue.Clear();
  278:  
  279:             SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Ericsson.Axe.LogoutCommand);
  280:         }
  281:  
  282:         ////////////////////////////////////////////////////////////////////////////
  283:  
  284:         /// <summary>
  285:         ///
  286:         /// </summary>
  287:         public Ia.Cl.Models.Result Send(string text)
  288:         {
  289:             var result = new Ia.Cl.Models.Result();
  290:  
  291:             try
  292:             {
  293:                 if (telnetModel.IsConnected)
  294:                 {
  295:                     if (!string.IsNullOrEmpty(text))
  296:                     {
  297:                         LastSentCommand = text;
  298:  
  299:                         telnetModel.WriteData(text + "\r\n");
  300:  
  301:                         result.AddSuccess(Pstn.Name + ": Sent: " + text);
  302:                     }
  303:                     else result.AddError(Pstn.Name + ": No text to send.");
  304:                 }
  305:                 else
  306:                 {
  307:                     result.AddError(Pstn.Name + ": No established telnet connection.");
  308:                     //if(processRunning) waitToConnectionCounter = waitToConnectionCounterSeconds;
  309:                 }
  310:             }
  311:             catch (Exception ex)
  312:             {
  313:                 result.AddError(ex.Message);
  314:             }
  315:  
  316:             return result;
  317:         }
  318:  
  319:         ////////////////////////////////////////////////////////////////////////////
  320:  
  321:         /// <summary>
  322:         ///
  323:         /// </summary>
  324:         private void Telnet_Data(object sender, DataEventArgs e)
  325:         {
  326:             string rowString, filteredString;
  327:  
  328:             rowString = e.Data.ToString();
  329:  
  330:             filteredString = rowString.Replace("\u0003", "").Replace("<", "").Trim();
  331:  
  332:             if (!string.IsNullOrEmpty(filteredString) && !string.IsNullOrWhiteSpace(filteredString))
  333:             {
  334:                 if (filteredString != LastSentCommand) // to ignore echoed command
  335:                 {
  336:                     ReceiveQueue.Enqueue(filteredString);
  337:                 }
  338:             }
  339:             else
  340:             {
  341:  
  342:             }
  343:  
  344:             ////if (telnet.Connected) telnet.BeginReceive(buffer);
  345:         }
  346:  
  347:         ////////////////////////////////////////////////////////////////////////////
  348:  
  349:         /// <summary>
  350:         ///
  351:         /// </summary>
  352:         private void Telnet_StateChanged(object sender, EventArgs e)
  353:         {
  354:             // always raised when connection is established or closed (state property changes)
  355:             switch (telnetModel.Telnet.State)
  356:             {
  357:                 case ConnectionState.Connected:
  358:                 case ConnectionState.ConnectedAndSecure: break;
  359:                 case ConnectionState.Closed: break;
  360:             }
  361:         }
  362:  
  363:         ////////////////////////////////////////////////////////////////////////////
  364:  
  365:         /// <summary>
  366:         ///
  367:         /// </summary>
  368:         private void Telnet_ClientOptionChanged(object sender, OptionEventArgs e)
  369:         {
  370:         }
  371:  
  372:         ////////////////////////////////////////////////////////////////////////////
  373:  
  374:         /// <summary>
  375:         ///
  376:         /// </summary>
  377:         private void Telnet_ServerOptionChanged(object sender, OptionEventArgs e)
  378:         {
  379:         }
  380:  
  381:         ////////////////////////////////////////////////////////////////////////////
  382:  
  383:         /// <summary>
  384:         ///
  385:         /// </summary>
  386:         private void Telnet_Error(object sender, Dart.Telnet.ErrorEventArgs e)
  387:         {
  388:         }
  389:  
  390:         ////////////////////////////////////////////////////////////////////////////
  391:  
  392:         /// <summary>
  393:         ///
  394:         /// </summary>
  395:         private void Telnet_Log(object sender, DataEventArgs e)
  396:         {
  397:             // e.Data;
  398:         }
  399:  
  400:         ////////////////////////////////////////////////////////////////////////////
  401:  
  402:         /// <summary>
  403:         ///
  404:         /// </summary>
  405:         void TelnetModel_CertificateRequested(object sender, LocalCertificateEventArgs e)
  406:         {
  407:         }
  408:  
  409:         ////////////////////////////////////////////////////////////////////////////
  410:  
  411:         /// <summary>
  412:         ///
  413:         /// </summary>
  414:         void TelnetModel_CertificatePresented(object sender, RemoteCertificateEventArgs e)
  415:         {
  416:         }
  417:  
  418:         ////////////////////////////////////////////////////////////////////////////
  419:  
  420:         /// <summary>
  421:         ///
  422:         /// </summary>
  423:         public Ia.Cl.Models.Result Update(string formattedString, ref Ia.Ftn.Cl.Models.Client.Ericsson.Axe axe)
  424:         {
  425:             Ia.Cl.Models.Result result;
  426:  
  427:             Ia.Ftn.Cl.Models.Data.Ericsson.Axe.UpdateDatabaseWithAxeCommandOutput(formattedString, ref axe, out result);
  428:  
  429:             return result;
  430:         }
  431:  
  432:         ////////////////////////////////////////////////////////////////////////////
  433:         ////////////////////////////////////////////////////////////////////////////
  434:     }
  435:  
  436:     ////////////////////////////////////////////////////////////////////////////
  437:     ////////////////////////////////////////////////////////////////////////////
  438: }