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

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

    1: using Dart.Telnet;
    2: using System;
    3: using System.Collections.Generic;
    4: using System.Diagnostics;
    5: using System.Security.Cryptography.X509Certificates;
    6:  
    7: namespace Ia.Ftn.Cl.Models.Client.Huawei
    8: {
    9:     ////////////////////////////////////////////////////////////////////////////
   10:  
   11:     /// <summary publish="true">
   12:     /// Fixed Telecommunications Network's Operations Support System Management Intranet (FTN OSS) client support class for Huawei's Fixed Telecommunications Network (FTN) EMS client model.
   13:     /// </summary>
   14:     /// 
   15:     /// <remarks> 
   16:     /// Copyright © 2017-2025 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 Ems
   29:     {
   30:         private string receiveString;
   31:  
   32:         private byte[] buffer = new byte[1024];
   33:         private TelnetModel telnetModel;
   34:         private Dart.Telnet.Telnet telnet;
   35:         private X509CertificateCollection clientCertificates = new X509CertificateCollection();
   36:         private System.ComponentModel.IContainer components;
   37:  
   38:         /// <summary/>
   39:         public static int WaitAfterSendInMillisecond { get { return 4000; } }
   40:  
   41:         public static int WaitAfterSendForCfgCommandInMillisecond { get { return 10000; } }
   42:  
   43:         public string LastSentCommand { get; private set; }
   44:  
   45:         public Queue<string> ReceiveQueue { get; set; }
   46:  
   47:         public Queue<string> SendQueue { get; set; }
   48:  
   49:         public Queue<string> SystemIsBusyResendQueue { get; set; }
   50:  
   51:         public Queue<string> OntLoadingCommandIsBeingExecutedNowResendQueue { get; set; }
   52:  
   53:         public Dictionary<string, DateTime> OntSipInfoCommandAgainAfterNSecondsToDateTimeDictionary { get; set; }
   54:  
   55:         public Queue<string> OntSipInfoCommandAgainAfterNSecondsResendQueue { get; set; }
   56:  
   57:         /// <summary/>
   58:         public bool IsLoggedIn { get; set; }
   59:  
   60:         ////////////////////////////////////////////////////////////////////////////
   61:  
   62:         /// <summary>
   63:         /// 
   64:         /// </summary>
   65:         public enum ResultCode : long
   66:         {
   67:             // I'm basically using the almost exact document phrasing of error codes
   68:             /// <summary/>
   69:             Unknown = -1,
   70:  
   71:             /// <summary/>
   72:             Succeeded = 0,
   73:  
   74:             /// <summary/>
   75:             DeviceDoesNotExist1 = 2686058531,
   76:  
   77:             /// <summary/>
   78:             DeviceDoesNotExist2 = 15658136501,
   79:  
   80:             /// <summary/>
   81:             ResourceDoesNotExist = 2686058552,
   82:  
   83:             /// <summary/>
   84:             OntIsNotOnline = 2689012370,
   85:  
   86:             /// <summary/>
   87:             CommunicatingWithDmFailed = 2686058603,
   88:  
   89:             /// <summary/>
   90:             OntIsOffline = 2689014724,
   91:  
   92:             /// <summary/>
   93:             OntLoadingCommandIsBeingExecutedNow = 2689014933,
   94:  
   95:             /// <summary/>
   96:             SystemIsBusy1 = 2686058516,
   97:  
   98:             /// <summary/>
   99:             SystemIsBusy2 = 2689017157,
  100:  
  101:             /// <summary/>
  102:             AttempetingTimeout = 2686058596,
  103:  
  104:             /// <summary/>
  105:             CommandSyntaxError = 2686058497,
  106:  
  107:             /// <summary/>
  108:             UnknownCommand = 2686058499,
  109:  
  110:             /// <summary/>
  111:             TaskTimeout = 2686058508,
  112:  
  113:             /// <summary/>
  114:             ValueOfParameterIsWrong = 2686058500,
  115:  
  116:             /// <summary/>
  117:             DbaProfileDoesNotExist1 = 102690820,
  118:  
  119:             /// <summary/>
  120:             DbaProfileDoesNotExist2 = 2689014791,
  121:  
  122:             /// <summary/>
  123:             NodeParameterSetFailed = 1615069195,
  124:  
  125:             /// <summary/>
  126:             VersionDoesNotMatchOrCommunicationWithDeviceFailed = 1615462437,
  127:  
  128:             /// <summary/>
  129:             FailedToCommunicateWithDevice1 = 1610614842,
  130:  
  131:             /// <summary/>
  132:             FailedToCommunicateWithDevice2 = 1616445483,
  133:  
  134:             /// <summary/>
  135:             FailedToCommunicateWithDevice3 = 1616445484,
  136:  
  137:             /// <summary/>
  138:             FailedToCommunicateWithDevice4 = 1616445485,
  139:  
  140:             /// <summary/>
  141:             LoginAddressIsNotInUserAcl = 76546022,
  142:  
  143:             /// <summary/>
  144:             LoginAddressIsNotInSystemAcl = 76546023,
  145:  
  146:             /// <summary/>
  147:             DeviceOfflineError = 1610612765,
  148:  
  149:             /// <summary/>
  150:             OperationIsNotSupported = 2689008176,
  151:  
  152:             /// <summary/>
  153:             ParametersConflictWithVasProfile = 1615069206,
  154:  
  155:             /// <summary/>
  156:             ProfileAlreadyExists = 2689023090,
  157:  
  158:             /// <summary/>
  159:             TrafficProfileDoesNotExist = 2689020327,
  160:  
  161:             /// <summary/>
  162:             MgParameterIsConflicting = 2688880284,
  163:  
  164:             /// <summary/>
  165:             NoOnuTypeIsSetInGeneralProfile = 1618280538,
  166:  
  167:             /// <summary/>
  168:             OntIsUsedByOthers = 1618214927,
  169:  
  170:             /// <summary/>
  171:             UserDoesNotLogIn = 2686058521,
  172:  
  173:             /// <summary/>
  174:             PortDoesNotExist = 2689015666,
  175:  
  176:             /// <summary/>
  177:             TelephoneNumberAlreadyExists = 2689015764,
  178:  
  179:             /// <summary/>
  180:             ThePasswordHasExpiredOrNeedsToBeChangedOnNextLogin = 1618280766,
  181:  
  182:             /// <summary/>
  183:             TheUserAccountIsLocked = 76546024,
  184:  
  185:             /// <summary/>
  186:             TheOntDoesNotSuppportConfigeringValueAddedServiceWithoutBindingGeneralVasProfile = 1615069214,
  187:  
  188:             /// <summary/>
  189:             NoMatchingPortPleaseCheckTheDataSetting = 2686059269,
  190:  
  191:             /// <summary/>
  192:             AnInstanceUnknownToTheAgentIsDesignated = 2689007637,
  193:  
  194:             /// <summary/>
  195:             ThePortIsNotConfiguredMgUserData = 2689015732,
  196:  
  197:             /// <summary/>
  198:             PortHasBeenConfiguredWithUserData = 2689015744,
  199:  
  200:             /// <summary/>
  201:             TheCpeIsNotExistent = 161503642,
  202:  
  203:             /// <summary/>
  204:             TheVersionIsNotConfigurable = 1615069190,
  205:         }
  206:  
  207:         ////////////////////////////////////////////////////////////////////////////
  208:  
  209:         /// <summary>
  210:         ///
  211:         /// </summary>
  212:         public static string ResultCodeString(long _resultCode)
  213:         {
  214:             // see: ColoredResultCodeString()
  215:             string resultCodeString;
  216:             Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode resultCode;
  217:  
  218:             resultCode = (Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode)_resultCode;
  219:  
  220:             resultCodeString = resultCode.ToString();
  221:             resultCodeString = Ia.Cl.Models.Default.CamelToProperCase(resultCodeString);
  222:             resultCodeString = Ia.Cl.Models.Default.ToTitleCase(resultCodeString);
  223:             resultCodeString = resultCodeString.Replace("Ont", "ONT");
  224:  
  225:             return resultCodeString;
  226:         }
  227:  
  228:         ////////////////////////////////////////////////////////////////////////////
  229:  
  230:         /// <summary>
  231:         ///
  232:         /// </summary>
  233:         public static string ColoredResultCodeString(long _resultCode)
  234:         {
  235:             // see: ResultCodeString()
  236:             string resultCodeString, coloredResultCodeString;
  237:             Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode resultCode;
  238:  
  239:             resultCode = (Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode)_resultCode;
  240:  
  241:             resultCodeString = resultCode.ToString();
  242:             resultCodeString = Ia.Cl.Models.Default.CamelToProperCase(resultCodeString);
  243:             resultCodeString = Ia.Cl.Models.Default.ToTitleCase(resultCodeString);
  244:             resultCodeString = resultCodeString.Replace("Ont", "ONT");
  245:  
  246:             switch (resultCode)
  247:             {
  248:                 case Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.Succeeded: coloredResultCodeString = "<span style=\"color:Green\">" + resultCodeString + "</span>"; break;
  249:                 case Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.SystemIsBusy2: coloredResultCodeString = "<span style=\"color:MediumPurple\">" + resultCodeString + "</span>"; break;
  250:                 case Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.OntIsOffline: coloredResultCodeString = "<span style=\"color:OrangeRed\">" + resultCodeString + "</span>"; break;
  251:                 case Ia.Ftn.Cl.Models.Client.Huawei.Ems.ResultCode.DeviceOfflineError: coloredResultCodeString = "<span style=\"color:Red\">" + resultCodeString + "</span>"; break;
  252:                 default: coloredResultCodeString = "<span style=\"color:Blue\">" + resultCodeString + "</span>"; break;
  253:             }
  254:  
  255:             return coloredResultCodeString;
  256:         }
  257:  
  258:         ////////////////////////////////////////////////////////////////////////////
  259:  
  260:         /// <summary>
  261:         ///
  262:         /// </summary>
  263:         public Ems()
  264:         {
  265:             components = new System.ComponentModel.Container();
  266:  
  267:             Dart.Telnet.Option option1 = new Dart.Telnet.Option();
  268:             Dart.Telnet.Option option2 = new Dart.Telnet.Option();
  269:             Dart.Telnet.Option option3 = new Dart.Telnet.Option();
  270:             Dart.Telnet.Option option4 = new Dart.Telnet.Option();
  271:             Dart.Telnet.Option option5 = new Dart.Telnet.Option();
  272:  
  273:             telnet = new Dart.Telnet.Telnet(components);
  274:  
  275:             option1.Code = Dart.Telnet.OptionCode.SuppressGoAheads;
  276:             option2.Code = Dart.Telnet.OptionCode.WindowSize;
  277:             option2.SubOption = new byte[] { 0, 80, 0, 24 };
  278:             option3.Code = Dart.Telnet.OptionCode.TerminalType;
  279:             option3.SubOption = new byte[] { 0, 116, 116, 121 };
  280:             telnet.ClientOptions.AddRange(new Dart.Telnet.Option[] { option1, option2, option3 });
  281:  
  282:             option4.Code = Dart.Telnet.OptionCode.SuppressGoAheads;
  283:             option5.Code = Dart.Telnet.OptionCode.Echo;
  284:             telnet.ServerOptions.AddRange(new Dart.Telnet.Option[] { option4, option5 });
  285:  
  286:             telnet.SocketOption.ReceiveTimeout = 1000;
  287:             telnet.SynchronizingObject = null;
  288:             telnet.ClientOptionChanged += Telnet_ClientOptionChanged;
  289:             telnet.ServerOptionChanged += Telnet_ServerOptionChanged;
  290:             telnet.Data += Telnet_Data;
  291:             telnet.StateChanged += Telnet_StateChanged;
  292:             telnet.Log += Telnet_Log;
  293:             telnet.Error += Telnet_Error;
  294:  
  295:             telnetModel = new TelnetModel();
  296:  
  297:             // set non-serializable Telnet component
  298:             telnetModel.Telnet = telnet;
  299:             telnetModel.ReceiveLoopRequired = true;
  300:  
  301:             // subscribe to certificate events
  302:             telnetModel.CertificateRequested += new EventHandler<LocalCertificateEventArgs>(TelnetModel_CertificateRequested);
  303:             telnetModel.CertificatePresented += new EventHandler<RemoteCertificateEventArgs>(TelnetModel_CertificatePresented);
  304:  
  305:             /*
  306:             this.telnet = new Dart.Telnet.Telnet(); // this.components);
  307: 
  308:             this.telnet.ClientOptions.AddRange(new Dart.Telnet.Option[] {
  309:             new Dart.Telnet.Option(Dart.Telnet.OptionCode.SuppressGoAheads, null, Dart.Telnet.OptionState.RequestOn),
  310:             new Dart.Telnet.Option(Dart.Telnet.OptionCode.WindowSize, new byte[] {((byte)(0)),((byte)(80)),((byte)(0)),((byte)(24))}, Dart.Telnet.OptionState.RequestOn),
  311:             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)});
  312: 
  313:             this.telnet.ServerOptions.AddRange(new Dart.Telnet.Option[] {
  314:             new Dart.Telnet.Option(Dart.Telnet.OptionCode.SuppressGoAheads, null, Dart.Telnet.OptionState.RequestOn),
  315:             new Dart.Telnet.Option(Dart.Telnet.OptionCode.Echo, null, Dart.Telnet.OptionState.RequestOn)});
  316:             */
  317:  
  318:             //this.telnet.SynchronizingObject = this;
  319:             //this.telnet.TerminalType = "xterm";
  320:             //this.telnet.WindowSize = new System.Drawing.Size(80, 24);
  321:             ////this.telnet.EndReceive += new Dart.Telnet.SegmentEventHandler(this.Telnet_EndReceive);
  322:             ////this.telnet.ConnectedChangedEx += new Dart.Telnet.EventHandlerEx(this.Telnet_ConnectedChangedEx);
  323:  
  324:             receiveString = string.Empty;
  325:  
  326:             ReceiveQueue = new Queue<string>();
  327:             SendQueue = new Queue<string>();
  328:             SystemIsBusyResendQueue = new Queue<string>();
  329:             OntLoadingCommandIsBeingExecutedNowResendQueue = new Queue<string>();
  330:  
  331:             OntSipInfoCommandAgainAfterNSecondsToDateTimeDictionary = new Dictionary<string, DateTime>();
  332:             OntSipInfoCommandAgainAfterNSecondsResendQueue = new Queue<string>();
  333:  
  334:             IsLoggedIn = false;
  335:         }
  336:  
  337:         ////////////////////////////////////////////////////////////////////////////
  338:  
  339:         /// <summary>
  340:         ///
  341:         /// </summary>
  342:         ~Ems()
  343:         {
  344:             Dispose(true);
  345:         }
  346:  
  347:         ////////////////////////////////////////////////////////////////////////////
  348:  
  349:         /// <summary>
  350:         ///
  351:         /// </summary>
  352:         public Ia.Cl.Models.Result Connect()
  353:         {
  354:             var result = new Ia.Cl.Models.Result();
  355:  
  356:             // if a model with a matching server exists, remove it, then add it so that it is first in the list
  357:             telnetModel.Session.RemoteEndPoint = new IPEndPoint(Ia.Ftn.Cl.Models.Business.Huawei.Ems.Host, Ia.Ftn.Cl.Models.Business.Huawei.Ems.Port);
  358:             telnetModel.Credentials.Username = string.Empty; // txtUsername.Text;
  359:             telnetModel.Credentials.Password = string.Empty; // txtPassword.Text;
  360:             telnetModel.Credentials.CommandPrompt = string.Empty; // txtCommandPrompt.Text;
  361:             telnetModel.Credentials.UsernamePrompt = string.Empty; // txtLoginPrompt.Text;
  362:             telnetModel.Credentials.PasswordPrompt = string.Empty; // txtPasswordPrompt.Text;
  363:             telnetModel.SecurityType = SecurityType.None; // (SecurityType)cboSecurity.SelectedIndex;
  364:             telnetModel.SaveSession();
  365:  
  366:             if (telnetModel.Session.RemoteEndPoint.Port == 23)
  367:             {
  368:                 telnetModel.Telnet.ClientOptions.Add(new Option(OptionCode.SuppressGoAheads, null, OptionState.RequestOn));
  369:                 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));
  370:                 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));
  371:  
  372:                 telnetModel.Telnet.ServerOptions.Add(new Option(OptionCode.SuppressGoAheads, null, OptionState.RequestOn));
  373:                 telnetModel.Telnet.ServerOptions.Add(new Option(OptionCode.Echo, null, OptionState.RequestOn));
  374:                 telnetModel.Telnet.ServerOptions.Add(new Option(OptionCode.OutputPageSize, null, OptionState.RequestOn));
  375:             }
  376:             else
  377:             {
  378:                 telnetModel.Telnet.ClientOptions.Clear();
  379:                 telnetModel.Telnet.ServerOptions.Clear();
  380:             }
  381:  
  382:             // connect and receive data on a separate thread
  383:             telnet.Start(telnetModel.Connect, null);
  384:  
  385:             result.AddSuccess("Connected");
  386:  
  387:             /*
  388:             try
  389:             {
  390:                 telnet.ClientOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.SuppressGoAheads, null, Dart.Telnet.OptionState.RequestOn));
  391:                 telnet.ClientOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.TerminalType, new System.Byte[] { ((System.Byte)(0)), ((System.Byte)(116)), ((System.Byte)(116)), ((System.Byte)(121)) }, Dart.Telnet.OptionState.RequestOn));
  392:                 telnet.ServerOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.SuppressGoAheads, null, Dart.Telnet.OptionState.RequestOn));
  393:                 telnet.ServerOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.Echo, null, Dart.Telnet.OptionState.RequestOn));
  394:                 telnet.ServerOptions.Add(new Dart.Telnet.Option(Dart.Telnet.OptionCode.OutputPageSize, null, Dart.Telnet.OptionState.RequestOn));
  395: 
  396:                 ////telnet.Connect(Ia.Ftn.Cl.Models.Business.Huawei.Ems.Host, Ia.Ftn.Cl.Models.Business.Huawei.Ems.Port.ToString());
  397: 
  398:                 // receive using asynchronous technique
  399:                 ////telnet.ReceiveTimeout = 0;
  400:                 ////telnet.BeginReceive(buffer);
  401: 
  402:                 result.AddSuccess("Connected");
  403:             }
  404:             catch (Exception ex)
  405:             {
  406:                 result.AddError("Exception: " + ex.Message);
  407: 
  408:                 telnet.Close();
  409:             }
  410:             */
  411:  
  412:             return result;
  413:         }
  414:  
  415:         ////////////////////////////////////////////////////////////////////////////
  416:  
  417:         /// <summary>
  418:         ///
  419:         /// </summary>
  420:         public Ia.Cl.Models.Result Disconnect()
  421:         {
  422:             var result = new Ia.Cl.Models.Result();
  423:  
  424:             try
  425:             {
  426:                 telnetModel.Telnet.Close();
  427:  
  428:                 result.AddSuccess("Disconnected");
  429:             }
  430:             catch (Exception ex)
  431:             {
  432:                 result.AddError(ex.Message);
  433:             }
  434:  
  435:             return result;
  436:         }
  437:  
  438:         ////////////////////////////////////////////////////////////////////////////
  439:  
  440:         /// <summary>
  441:         ///
  442:         /// </summary>
  443:         public bool IsConnected
  444:         {
  445:             get
  446:             {
  447:                 return telnetModel.IsConnected;
  448:             }
  449:         }
  450:  
  451:         ////////////////////////////////////////////////////////////////////////////
  452:  
  453:         /// <summary>
  454:         ///
  455:         /// </summary>
  456:         public /*override*/ void Dispose(bool disposing)
  457:         {
  458:             if (disposing)
  459:             {
  460:                 if (components != null)
  461:                 {
  462:                     components.Dispose();
  463:                 }
  464:             }
  465:  
  466:             //base.Dispose(disposing);
  467:         }
  468:  
  469:         ////////////////////////////////////////////////////////////////////////////
  470:  
  471:         /// <summary>
  472:         ///
  473:         /// </summary>
  474:         public void Login()
  475:         {
  476:             // sendQueue.Enqueue(Ia.Ftn.Cl.Model.Business.Huawei.Ems.Semicolon); did not make any different
  477:  
  478:             // below: I need this because NCE somehow needs to be triggered before I send login information
  479:             SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Huawei.Ems.EmsKeepAliveCommand);
  480:             SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Huawei.Ems.EmsKeepAliveCommand);
  481:  
  482:             SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Huawei.Ems.LoginUser);
  483:         }
  484:  
  485:         ////////////////////////////////////////////////////////////////////////////
  486:  
  487:         /// <summary>
  488:         ///
  489:         /// </summary>
  490:         public void Logout()
  491:         {
  492:             SendQueue.Enqueue(Ia.Ftn.Cl.Models.Business.Huawei.Ems.LogoutUser);
  493:         }
  494:  
  495:         ////////////////////////////////////////////////////////////////////////////
  496:  
  497:         /// <summary>
  498:         ///
  499:         /// </summary>
  500:         public Ia.Cl.Models.Result Send(string text, bool skipSleep)
  501:         {
  502:             var result = new Ia.Cl.Models.Result();
  503:  
  504:             try
  505:             {
  506:                 if (telnetModel.IsConnected)
  507:                 {
  508:                     if (!string.IsNullOrEmpty(text))
  509:                     {
  510:                         LastSentCommand = text;
  511:  
  512:                         //this.textBox.AppendText("\r\n/* Sending: " + text + " */\r\n");
  513:  
  514:                         telnetModel.WriteData(text + "\r\n"); // I added "\r\n", not sure if it will work with read server
  515:  
  516:                         result.AddSuccess("Sent: [" + text + "]");
  517:                     }
  518:                     else
  519:                     {
  520:                         result.AddError("No text to send.");
  521:                     }
  522:                 }
  523:                 else
  524:                 {
  525:                     result.AddError("No established telnet connection.");
  526:                     //if(processRunning) waitToConnectionCounter = waitToConnectionCounterSeconds;
  527:                 }
  528:             }
  529:             catch (Exception ex)
  530:             {
  531:                 //if(processRunning) waitToConnectionCounter = waitToConnectionCounterSeconds;
  532:  
  533:                 result.AddError(ex.Message);
  534:             }
  535:  
  536:             if (!skipSleep)
  537:             {
  538:                 // this is meant to give the Telnet_EndReceive() time to receive and process data from session
  539:                 // we will wait according to the type of commands send
  540:  
  541:                 if (Ia.Ftn.Cl.Models.Business.Huawei.Ems.IsACfgCommand(LastSentCommand))
  542:                 {
  543:                     System.Threading.Thread.Sleep(Ia.Ftn.Cl.Models.Client.Huawei.Ems.WaitAfterSendForCfgCommandInMillisecond);
  544:                 }
  545:                 else
  546:                 {
  547:                     System.Threading.Thread.Sleep(Ia.Ftn.Cl.Models.Client.Huawei.Ems.WaitAfterSendInMillisecond);
  548:                 }
  549:             }
  550:  
  551:             return result;
  552:         }
  553:  
  554:         ////////////////////////////////////////////////////////////////////////////
  555:  
  556:         /// <summary>
  557:         ///
  558:         /// </summary>
  559:         private void Telnet_Data(object sender, DataEventArgs e)
  560:         {
  561:             string message, entry;
  562:             string[] receiveStringSplit;
  563:  
  564:             Debug.WriteLine(" ");
  565:             Debug.WriteLine("============================================");
  566:  
  567:             receiveString += e.Data.ToString();
  568:  
  569:             Debug.WriteLine("Telnet_EndReceive(): e.Segment: [" + e.Data.ToString() + "], receiveString: [" + receiveString + "]");
  570:  
  571:             if (!string.IsNullOrEmpty(receiveString))
  572:             {
  573:                 receiveStringSplit = receiveString.Split(new string[] { "\r\n;" }, StringSplitOptions.None);
  574:  
  575:                 if (receiveStringSplit.Length > 0)
  576:                 {
  577:                     for (int i = 0; i < receiveStringSplit.Length; i++)
  578:                     {
  579:                         entry = receiveStringSplit[i];
  580:  
  581:                         if (!string.IsNullOrEmpty(entry) && !string.IsNullOrWhiteSpace(entry))
  582:                         {
  583:                             // will not enqueue an empty entry
  584:  
  585:                             if (i == receiveStringSplit.Length - 1)
  586:                             {
  587:                                 // if there is a non empty last entry that means its incomplete and we will assign it to receiveString
  588:  
  589:                                 receiveString = entry;
  590:                             }
  591:                             else
  592:                             {
  593:                                 message = entry + "\r\n;"; // important
  594:  
  595:                                 if (!ReceiveQueue.Contains(message))
  596:                                 {
  597:                                     // will not enqueue duplicate
  598:  
  599:                                     ReceiveQueue.Enqueue(message);
  600:  
  601:                                     Debug.WriteLine("Telnet_EndReceive(): ReceiveQueue.Enqueue(message): [" + message + "]");
  602:                                 }
  603:  
  604:                                 receiveString = string.Empty;
  605:                             }
  606:                         }
  607:                     }
  608:                 }
  609:  
  610:                 Debug.WriteLine("Telnet_EndReceive(): receiveString: [" + receiveString + "]");
  611:             }
  612:             else
  613:             {
  614:  
  615:             }
  616:  
  617:             ////if (telnet.Connected) telnet.BeginReceive(buffer);
  618:  
  619:             Debug.WriteLine("============================================");
  620:             Debug.WriteLine(" ");
  621:         }
  622:  
  623:         ////////////////////////////////////////////////////////////////////////////
  624:  
  625:         /// <summary>
  626:         ///
  627:         /// </summary>
  628:         private void Telnet_StateChanged(object sender, EventArgs e)
  629:         {
  630:             // always raised when connection is established or closed (state property changes)
  631:             switch (telnetModel.Telnet.State)
  632:             {
  633:                 case ConnectionState.Connected:
  634:                 case ConnectionState.ConnectedAndSecure: break;
  635:                 case ConnectionState.Closed: break;
  636:             }
  637:         }
  638:  
  639:         ////////////////////////////////////////////////////////////////////////////
  640:  
  641:         /// <summary>
  642:         ///
  643:         /// </summary>
  644:         private void Telnet_ClientOptionChanged(object sender, OptionEventArgs e)
  645:         {
  646:         }
  647:  
  648:         ////////////////////////////////////////////////////////////////////////////
  649:  
  650:         /// <summary>
  651:         ///
  652:         /// </summary>
  653:         private void Telnet_ServerOptionChanged(object sender, OptionEventArgs e)
  654:         {
  655:         }
  656:  
  657:         ////////////////////////////////////////////////////////////////////////////
  658:  
  659:         /// <summary>
  660:         ///
  661:         /// </summary>
  662:         private void Telnet_Error(object sender, Dart.Telnet.ErrorEventArgs e)
  663:         {
  664:         }
  665:  
  666:         ////////////////////////////////////////////////////////////////////////////
  667:  
  668:         /// <summary>
  669:         ///
  670:         /// </summary>
  671:         private void Telnet_Log(object sender, DataEventArgs e)
  672:         {
  673:             // e.Data;
  674:         }
  675:  
  676:         ////////////////////////////////////////////////////////////////////////////
  677:  
  678:         /// <summary>
  679:         ///
  680:         /// </summary>
  681:         void TelnetModel_CertificateRequested(object sender, LocalCertificateEventArgs e)
  682:         {
  683:         }
  684:  
  685:         ////////////////////////////////////////////////////////////////////////////
  686:  
  687:         /// <summary>
  688:         ///
  689:         /// </summary>
  690:         void TelnetModel_CertificatePresented(object sender, RemoteCertificateEventArgs e)
  691:         {
  692:         }
  693:  
  694:         ////////////////////////////////////////////////////////////////////////////
  695:  
  696:         /// <summary>
  697:         ///
  698:         /// </summary>
  699:         public Ia.Cl.Models.Result Update(string rowData, ref Ia.Ftn.Cl.Models.Client.Huawei.Ems ems, out string systemIsBusyResponseCommand, out string ontLoadingCommandIsBeingExecutedNowResponseCommand)
  700:         {
  701:             return Ia.Ftn.Cl.Models.Business.Huawei.Ems.UpdateDatabaseWithEmsCommandOutput(rowData, ref ems, out systemIsBusyResponseCommand, out ontLoadingCommandIsBeingExecutedNowResponseCommand);
  702:         }
  703:  
  704:         ////////////////////////////////////////////////////////////////////////////
  705:         ////////////////////////////////////////////////////////////////////////////
  706:     }
  707:  
  708:     ////////////////////////////////////////////////////////////////////////////
  709:     ////////////////////////////////////////////////////////////////////////////
  710: }