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