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

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

Fixed Telecommunications Network's Operations Support System Management Intranet (FTN OSS) client support class for Nokia's Fixed Telecommunications Network (FTN) AMS client model.

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