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