Пример #1
0
        public string[] GetRunningConfig()
        {
            string[] l_strLines = { "" };

            //
            //Read Running-Config from Router
            //
            // shell.cmd_remove_mode(1);
            if (DeviceType.Equals("H3C"))
            {
                l_strLines = this.SendCmd("display current-configuration");
            }
            else
            {
                l_strLines = this.SendCmd("show running-config");
            }
            if (_Debug > 0)
            {
                Console.WriteLine("Running-Config:");
                if ((l_strLines != null) && (l_strLines.Length > 0))
                {
                    foreach (string strLine in l_strLines)
                    {
                        Console.WriteLine(strLine);
                    }
                }
            }

            return(l_strLines);
        }
Пример #2
0
        public string[] GetIntoConfigMode()
        {
            string strOutput = "";

            string[] strLines = { "" };

            //Change to Config-Mode of Router
            if (DeviceType.Equals("H3C"))
            {
                strOutput = shell.cmd("system-view", DevicePromptConfig);
            }
            else
            {
                strOutput = shell.cmd("configure terminal", DevicePromptConfig);
            }

            bConfigMode = true;
            if (_Debug > 0)
            {
                Console.WriteLine("Entered-Configmode:");
                if (strOutput != null)
                {
                    Console.WriteLine(strOutput);
                }
            }
            if (strOutput != null)
            {
                strLines = strOutput.Split(new char[] { '\n' });
            }

            return(strLines);
        }
Пример #3
0
        public string[] GetShowVersion()
        {
            string[] l_strLines = { "" };
            //string strOutput = "";
            //
            //Read Show-Version from Device
            //
            if (DeviceType.Equals("H3C"))
            {
                l_strLines = this.SendCmd("display version");
            }
            else
            {
                l_strLines = this.SendCmd("show version"); // strOutput = shell.cmd("show version", DevicePrompt);
            }
            if (_Debug > 0)
            {
                Console.WriteLine("Show-Version:");
                if (l_strLines != null) //strOutput
                {
                    Console.WriteLine(String.Join("\n", l_strLines));
                }
            }

            //if( strOutput != null )
            //    l_strLines = strOutput.Split(new char[] { '\n' });

            return(l_strLines);
        }
Пример #4
0
        public bool Equals(TopUpRequestBody other)
        {
            if (other == null)
            {
                return(false);
            }

            return(AuthenticationData.Equals(other.AuthenticationData) &&
                   DeviceType.Equals(other.DeviceType) &&
                   Amount == other.Amount &&
                   String.Equals(ExternalTransactionReference, other.ExternalTransactionReference) &&
                   String.Equals(MNO, other.MNO) &&
                   String.Equals(Recipient, other.Recipient));
        }
 /// <summary>
 /// Updates the database table <see cref="Device"/> by setting to
 /// null the push tokens of each device matching the specified push
 /// token and the specified type.
 /// </summary>
 /// <param name="deviceType"></param>
 /// <param name="pushToken"></param>
 private static void NullifyDevicePushToken(DeviceType deviceType, string pushToken)
 {
     using (var db = new IbaCmsDbContext())
     {
         var devices = db.Devices
                       .Where(device => deviceType.Equals(device.DeviceType))
                       .Where(device => pushToken.Equals(device.PushToken));
         foreach (var device in devices)
         {
             device.PushToken = null;
             device.UpdatedOn = DateTime.UtcNow;
         }
         db.SaveChanges();
     }
 }
Пример #6
0
        public string[] ExitConfigMode()
        {
            string strOutput = "";

            string[] strLines = { "" };

            //Exit from Config-Mode
            if (DeviceType.Equals("H3C"))
            {
                strOutput = shell.cmd("return", DevicePrompt);
            }
            else if (DeviceType.Equals("Cisco-IOS-XR"))
            {
                string _tmpPrompt = DevicePrompt + @"|[\[(](?:[Yy](?:es)?|[Nn]o?)[\\/|](?:[Yy](?:es)?|[Nn]o?)(?:[\\/|](?:[Cc]?(?:ancel)?|[Aa]?(?:ll)?))*[)\]]\s*[?:]?\s*(?:\[[a-zA-Z]+\])?\s*[?:]?\s*$";
                strOutput = shell.cmd("end", _tmpPrompt);
                if (!HelperClass.RegExCompare(strOutput, DevicePrompt, RegexOptions.IgnoreCase))
                {
                    strOutput = shell.cmd("n", DevicePrompt);
                }
            }
            else
            {
                strOutput = shell.cmd("end", DevicePrompt);
            }

            bConfigMode = false;
            if (_Debug > 0)
            {
                Console.WriteLine("Exited-Configmode:");
                if (strOutput != null)
                {
                    Console.WriteLine(strOutput);
                }
            }

            if (strOutput != null)
            {
                strLines = strOutput.Split(new char[] { '\n' });
            }

            return(strLines);
        }
Пример #7
0
        /// <summary>
        /// Returns true if LightingZone instances are equal
        /// </summary>
        /// <param name="other">Instance of LightingZone to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(LightingZone other)
        {
            if (ReferenceEquals(null, other))
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Id == other.Id ||
                     Id != null &&
                     Id.Equals(other.Id)
                     ) &&
                 (
                     Name == other.Name ||
                     Name != null &&
                     Name.Equals(other.Name)
                 ) &&
                 (
                     DeviceId == other.DeviceId ||
                     DeviceId != null &&
                     DeviceId.Equals(other.DeviceId)
                 ) &&
                 (
                     DeviceType == other.DeviceType ||
                     DeviceType != null &&
                     DeviceType.Equals(other.DeviceType)
                 ) &&
                 (
                     Zone == other.Zone ||
                     Zone != null &&
                     Zone.Equals(other.Zone)
                 ));
        }
Пример #8
0
        private LoginStatus Enable()
        {
            LoginStatus pwdResult = LoginStatus.InProgress;
            string      strTemp   = "";

            shell.buffer_empty();
            shell.print("\nenable");
            string match = "";

            string[] LoginPrompt = { "Username:"******"Login:"******"Password:"******"username:"******"login:"******"(>|#)", DevicePromptString + "#");
                    if (pwdResult == LoginStatus.UserMode)
                    {
                        shell.buffer_empty();
                        shell.print("\nenable");
                    }
                    PWDCounter++;
                }
                if (pwdResult > LoginStatus.Success)
                {
                    return(LoginStatus.InProgress);
                }
            }
            else if (match.ToLower().Contains("password:"******"", DevicePromptString + "#");

            string[] strLines = strOutput.Split(new char[] { '\n' });
            foreach (string strLine in strLines)
            {
                strTemp = strLine.Replace("\n", "");
                strTemp = strTemp.Replace("\r", "");
                strTemp = strTemp.Trim(); // strTemp.Replace(" ", "");
                if (strTemp.Length > 0)
                {
                    LastPromptChar = strTemp.Substring(strTemp.Length - 1, 1).ToCharArray()[0];
                    strTemp        = strTemp.Substring(0, strTemp.Length - 1); //Remove Last Char
                    DevicePrompt   = HelperClass.quotemeta(strTemp);
                }
            }
            DevicePromptString = DevicePrompt;
            DevicePromptConfig = DevicePrompt;
            if (DevicePromptConfig.Length > 10)
            {
                DevicePromptConfig = DevicePromptConfig.Substring(0, 10);
            }
            if (DeviceType.Equals("HP"))
            {
                DevicePromptConfig = DevicePromptConfig + @".*\(.*\)" + LastPromptChar;
            }
            else
            {
                DevicePromptConfig = DevicePromptConfig + @".*\(config.*\)" + LastPromptChar;
            }
            DevicePromptConfig = DevicePromptConfig + "[ \\r\\n]*$";
            DevicePrompt       = DevicePrompt + LastPromptChar + "[ \\r\\n]*$";
            if (Debug > 0)
            {
                Console.WriteLine("\nDebug-Info:");
                Console.WriteLine("new Prompt: " + DevicePrompt);
                Console.WriteLine("Config-Prompt: " + DevicePromptConfig);
            }

            return(LoginStatus.Success);
        }
Пример #9
0
        public LoginStatus doLogin(string Device, string ConnectOptions)
        {
            string strOutput = "";

            PWDCounter         = 0;
            DevicePromptString = "";
            DevicePrompt       = "";
            DevicePromptConfig = "";
            EnableMode         = false;
            bConfigMode        = false;
            DeviceType         = "";
            LoginStatus bResult = LoginStatus.InProgress;

            while ((bResult == LoginStatus.InProgress) && (PWDCounter < UserArray.Count))
            {
                bResult = Login(Device, ConnectOptions);

                if ((bConnected > 0) && (bResult == LoginStatus.InProgress))
                {
                    bConnected--;
                }
            }
            if (Debug > 0)
            {
                Console.WriteLine("Login-Result: " + bResult);
            }

            if (DevicePrompt.Length == 0)
            {
                if (Debug > 0)
                {
                    Console.WriteLine("\nExit by me !");
                }
                if (bConnected > 0)
                {
                    bConnected--;
                }
                return(LoginStatus.Failed);
            }

            //Check if we are in Enable-Mode or not
            if (EnableMode)
            {
                if (Debug > 0)
                {
                    Console.WriteLine("\nWe are in Enable-Mode.");
                }
            }
            else
            {
                //DevicePromptString =~ s/^[\r\n]*[a-zA-Z0-9\-][>]\s*\r?\n?$/$1/;  # s/^(.*)[>]$/$1/
                DevicePrompt = "";
                bResult      = Enable();
                if (Debug > 0)
                {
                    Console.WriteLine("Enable-Result: " + bResult.ToString());
                }
                if (DevicePrompt.Length == 0)
                {
                    if (Debug > 0)
                    {
                        Console.WriteLine("\nExit by me !");
                    }
                    return(LoginStatus.UserMode);
                }
            }

            if (DeviceType.Equals("HP"))
            {
                strOutput = shell.cmd("terminal length 1000", DevicePrompt);
            }
            else if (DeviceType.Equals("Cisco") || (DeviceType.Length == 0))
            {
                strOutput = shell.cmd("terminal length 0", DevicePrompt);
            }
            strOutput = shell.cmd("terminal width 0", DevicePrompt);

            if (DeviceType.Length == 0)
            {
                Specify();
            }
            return(bResult);
        }
Пример #10
0
        private LoginStatus Login(string host, string ConnectOptions)
        {
            string      match = "", strOutput = "";
            string      l_ConStr       = "";
            string      strTemp        = "";
            char        LastPromptChar = '\0';
            LoginStatus bResult        = LoginStatus.InProgress;

            if (bConnected == 0)
            {
                if (shell != null)  //if ((shell != null) && shell.Connected)
                {
                    shell.close();
                }
                shell = null;
                shell = new TerminalSessions.TelnetSSHLogin();
                if (Debug > 0)
                {
                    shell.DebugFlag = Debug;
                    Console.WriteLine("Debug-Info:\nConnect to " + host);
                }
                //shell.cmd_remove_mode = "1";
                if (!shell.open("", "", host, 0, "telnet", "", "", ""))
                {
                    return(LoginStatus.Failed);
                }
                else
                {
                    bConnected = 1;
                }
            }
            else
            {
                shell.buffer_empty();
                if (Debug > 0)
                {
                    Console.WriteLine("Debug-Info:\nConnect to " + host);
                }
                // shell.print("telnet " + host + " /vrf " + VRF);
                l_ConStr = host;
                if (ConnectOptions.Trim().Length != 0)
                {
                    l_ConStr = l_ConStr + " " + ConnectOptions;
                }
                Console.WriteLine("Will connect to: " + l_ConStr);
                shell.print("telnet " + l_ConStr);
                bConnected++;
            }
            // sleep 1sec.
            string[] LoginPrompt = { "Username:"******"Login:"******"Login Name:", "Password:"******"Press any key to continue" };
            if (DeviceCounter > 0)  //Add Prompt from source-Device
            {
                LoginPrompt = (string.Join(",", LoginPrompt) + "," + DeviceHistory[DeviceCounter - 1].DevicePrompt).Split(new char[] { ',' });
            }
            match = shell.WaitFor(LoginPrompt, false, Timeout);
            if (Debug > 0)
            {
                Console.WriteLine("Debug-Info:\nConnected, start Login.");
            }

            if ((match == null) || (match.Length == 0))
            {
                if (Debug > 0)
                {
                    Console.WriteLine("Connection failed, found no Loginprompt.");
                }
                return(LoginStatus.Unknown);
            }

            strTemp = shell.ShowScreen();
            if (strTemp.ToUpper().Contains("HEWLETT"))
            {
                DeviceType = "HP";      // HEWLETT-PACKARD
            }
            strTemp = "";
            if (match.ToLower().Contains("press any key to continue"))
            {
                match = "";
                shell.buffer_empty();
                string[] LoginPrompt2 = { "Username:"******"Login:"******"Login Name:", "Password:"******" ");
                match = shell.WaitFor(LoginPrompt2, false, Timeout);
                if ((match == null) || (match.Length == 0))
                {
                    if (Debug > 0)
                    {
                        Console.WriteLine("Connection failed, found no Loginprompt.");
                    }
                    return(LoginStatus.Unknown);
                }
            }

            if ((match.ToLower().Contains("username:"******"login:"******"login name:")))
            {
                //$PWDCounter = 0;
                bResult = LoginStatus.Continue;
                while ((PWDCounter <= UserArray.Count) && (bResult > LoginStatus.InProgress) && (bResult < LoginStatus.Unknown))
                {
                    bResult = TryUserLogin(unknownPrompt, unknownPrompt);
                    PWDCounter++;
                }
                if (bResult > LoginStatus.Success)
                {
                    return(bResult);
                }
            }
            else if (match.ToLower().Contains("password:"******"Test-" + PWDCounter.ToString() + ":" + bResult.ToString());
                    }
                    PWDCounter++;
                }
                if (bResult > 0)
                {
                    return(bResult);
                }
            }
            if (Debug > 0)
            {
                Console.WriteLine("\nDebug-Info:     Login success.");
            }

            //Get full Prompt
            DevicePrompt = "";
            strOutput    = shell.cmd("", unknownPrompt);
            if ((strOutput == null) || (strOutput.Length == 0))
            {
                //Found no Prompt Exit...
                return(LoginStatus.Unknown);
            }
            string[] strLines = strOutput.Split(new char[] { '\n' });
            foreach (string strLine in strLines)
            {
                strTemp = strLine.Replace("\n", "");
                strTemp = strTemp.Replace("\r", "");
                strTemp = strTemp.Trim(); // strTemp.Replace(" ", "");
                if (strTemp.Length > 0)
                {
                    LastPromptChar = strTemp.ToCharArray(strTemp.Length - 1, 1)[0];
                    strTemp        = strTemp.Substring(0, strTemp.Length - 1); // Remove Last Char
                    DevicePrompt   = HelperClass.quotemeta(strTemp);
                }
            }
            DevicePromptString = DevicePrompt;
            if (LastPromptChar == '#')
            {
                EnableMode = true;

                DevicePromptConfig = DevicePrompt.Substring(0, 10);
                if (DevicePromptConfig.EndsWith("\\"))
                {
                    DevicePromptConfig = DevicePromptConfig.Substring(0, DevicePromptConfig.Length - 1);
                }

                DevicePromptConfig = DevicePromptConfig + LastPromptChar;
                //DevicePromptConfig =~ s/(.*)(.)$/$1.*\\(config.*\\)$2/;	# s/(.*)([^\s])\s?$/$1.*\\(config.*\\)$2/;
                if (DeviceType.Equals("HP"))
                {
                    DevicePromptConfig = DevicePromptConfig.Substring(0, DevicePromptConfig.Length - 1) + ".*\\(.*\\)" + "#";
                }
                else
                {
                    DevicePromptConfig = DevicePromptConfig.Trim();
                    DevicePromptConfig = DevicePromptConfig.Substring(0, DevicePromptConfig.Length - 1) + ".*\\(config.*\\)" + "#";
                }
                DevicePromptConfig = DevicePromptConfig + "[ \\r\\n]*$";
            }
            else
            {
                DevicePromptConfig = "";
            }

            DevicePrompt = DevicePrompt + LastPromptChar + "[ \\r\\n]*$";
            if (Debug > 0)
            {
                Console.WriteLine("\nDebug-Info:");
                Console.WriteLine("new Prompt: " + DevicePrompt);
                Console.WriteLine("Config-Prompt: " + DevicePromptConfig);
            }

            return(LoginStatus.Success);
        }
Пример #11
0
        public void On_Connection_Message(object MsgObj)
        {
            try
            {
                string Msg = (string)MsgObj;
                //if (Vendor.ToUpper().Equals("ACDT"))
                //{
                //    byte[] byteAry = Encoding.ASCII.GetBytes(Msg);


                //    logger.Debug(DeviceName + " Recieve:" + BitConverter.ToString(byteAry));
                //}
                //else
                //{

                //}
                //Node Target = null;

                List <CommandReturnMessage> ReturnMsgList = _Decoder.GetMessage(Msg);
                foreach (CommandReturnMessage ReturnMsg in ReturnMsgList)
                {
                    //logger.Info(DeviceName + " Recieve:" + ReturnMsg.OrgMsg);
                    if (!this.Vendor.ToUpper().Equals("MITSUBISHI_PLC"))
                    {
                        _ReportTarget.On_Message_Log("CMD", DeviceName + " Recieve:" + ReturnMsg.OrgMsg);
                    }
                    try
                    {
                        Transaction Txn  = null;
                        Node        Node = null;
                        if (ReturnMsg != null)
                        {
                            lock (TransactionList)
                            {
                                if (ReturnMsg.Command != null)
                                {
                                    if (ReturnMsg.Command.Equals("PAUSE"))
                                    {
                                        foreach (Transaction t in TransactionList.Values)
                                        {
                                            t.SetTimeOutMonitor(false);
                                        }
                                    }
                                    if (ReturnMsg.Command.Equals("CONT_"))
                                    {
                                        foreach (Transaction t in TransactionList.Values)
                                        {
                                            t.SetTimeOutMonitor(true);
                                        }
                                    }
                                }


                                string key = "";
                                if (Vendor.ToUpper().Equals("KAWASAKI"))
                                {
                                    key = ReturnMsg.Seq;
                                }
                                else if (Vendor.ToUpper().Equals("HST") || Vendor.ToUpper().Equals("COGNEX"))
                                {
                                    key = "1" + ReturnMsg.Command;
                                }

                                else if (Vendor.ToUpper().Equals("SANWA") || Vendor.ToUpper().Equals("ATEL_NEW"))
                                {
                                    key = ReturnMsg.NodeAdr + ReturnMsg.Command;
                                    for (int seq = 0; seq <= 99; seq++)
                                    {
                                        string tmpKey = key + seq.ToString("00");

                                        if (TransactionList.ContainsKey(tmpKey))
                                        {
                                            key = tmpKey;
                                            break;
                                        }
                                        if (seq == 99)
                                        {
                                            logger.Error("seq is run out!");
                                        }
                                    }
                                }
                                else if (Vendor.ToUpper().Equals("SANWA_MC"))
                                {
                                    //if (ReturnMsg.Command.Equals("MCR__"))
                                    //{
                                    if (ReturnMsg.Command.Equals("RESET"))
                                    {
                                        key = "0";
                                    }
                                    else
                                    {
                                        key = ReturnMsg.NodeAdr;
                                    }
                                    //}
                                    //else
                                    //{
                                    //    key = "0" + ReturnMsg.Command;
                                    //}
                                }
                                else if (DeviceType.Equals("SMARTTAG"))
                                {
                                    key = "00";
                                }
                                else
                                {
                                    key = (ReturnMsg.NodeAdr + ReturnMsg.Command).Equals("") ? "0" : ReturnMsg.NodeAdr + ReturnMsg.Command;
                                }

                                if (Vendor.ToUpper().Equals("KAWASAKI"))
                                {
                                    if (TransactionList.TryGetValue(key, out Txn))
                                    {
                                        Node = NodeManagement.Get(Txn.NodeName);

                                        if (!Txn.CommandType.Equals("CMD"))
                                        {
                                            if (ReturnMsg.Type.Equals(CommandReturnMessage.ReturnType.Excuted))
                                            {
                                                continue;
                                            }
                                            else if (ReturnMsg.Type.Equals(CommandReturnMessage.ReturnType.Finished))
                                            {
                                                ReturnMsg.Type = CommandReturnMessage.ReturnType.Excuted;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        logger.Debug("Transaction not exist:key=" + key);
                                        return;
                                    }
                                }
                                else if (Vendor.ToUpper().Equals("TDK"))
                                {
                                    if (TransactionList.TryGetValue(key, out Txn))
                                    {
                                        Node = NodeManagement.Get(Txn.NodeName);
                                        if (Txn.CommandType.Equals("SET") && ReturnMsg.Type.Equals(CommandReturnMessage.ReturnType.Excuted))
                                        {
                                            //continue;
                                        }
                                    }
                                    else
                                    {
                                        Node = NodeManagement.GetByController(DeviceName, ReturnMsg.NodeAdr);
                                    }
                                }
                                else
                                {
                                    //if (ReturnMsg.NodeAdr.Equals("") || ReturnMsg.Command.Equals("RESET") || ReturnMsg.Command.Equals("SP___") || ReturnMsg.Command.Equals("PAUSE") || ReturnMsg.Command.Equals("CONT_") || ReturnMsg.Command.Equals("STOP_") || ReturnMsg.Command.Equals("TGEVT"))
                                    //{
                                    //    Node = NodeManagement.GetFirstByController(DeviceName);
                                    //}
                                    //else
                                    //{
                                    //    Node = NodeManagement.GetByController(DeviceName, ReturnMsg.NodeAdr);
                                    //}
                                    Node = NodeManagement.GetByController(DeviceName, ReturnMsg.NodeAdr.Equals("") ? "0" : ReturnMsg.NodeAdr);
                                    if (Node == null)
                                    {
                                        Node = NodeManagement.GetOCRByController(DeviceName);
                                    }
                                    if (Node == null)
                                    {
                                        Node = NodeManagement.GetFirstByController(DeviceName);
                                    }
                                }
                                //lock (TransactionList)
                                //{
                                //lock (Node)
                                //{
                                //Target = Node;
                                if (Node.Vendor.ToUpper().Equals("COGNEX"))
                                {
                                    if (ReturnMsg.Type == CommandReturnMessage.ReturnType.UserName)
                                    {
                                        //conn.Send("admin\r\n");
                                        continue;
                                    }
                                    if (ReturnMsg.Type == CommandReturnMessage.ReturnType.Password)
                                    {
                                        //conn.Send("\r\n");
                                        continue;
                                    }
                                }
                                if (ReturnMsg.Type == CommandReturnMessage.ReturnType.Event)
                                {
                                    //_ReportTarget.On_Event_Trigger(Node, ReturnMsg);
                                }
                                else if ((ReturnMsg.Type == CommandReturnMessage.ReturnType.Information && Node.Vendor.ToUpper().Equals("TDK") && !TransactionList.ContainsKey(key)))
                                {
                                    if (ReturnMsg.Type.Equals(CommandReturnMessage.ReturnType.Information))
                                    {
                                        //ThreadPool.QueueUserWorkItem(new WaitCallback(conn.Send), ReturnMsg.FinCommand);
                                        //conn.Send(ReturnMsg.FinCommand);
                                        //isWaiting = false;
                                        logger.Debug(DeviceName + " Send:" + ReturnMsg.FinCommand);
                                    }
                                }
                                else if (TransactionList.TryRemove(key, out Txn))
                                {
                                    // Node.InitialComplete = false;
                                    Node = NodeManagement.Get(Txn.NodeName);
                                    switch (ReturnMsg.Type)
                                    {
                                    case CommandReturnMessage.ReturnType.Excuted:
                                        if (!Txn.CommandType.Equals("CMD") && !Txn.CommandType.Equals("MOV") && !Txn.CommandType.Equals("HCS"))
                                        {
                                            logger.Debug("Txn timmer stoped.");
                                            Txn.SetTimeOutMonitor(false);
                                            lock (Node.ExcuteLock)
                                            {
                                                Node.IsExcuting = false;
                                            }
                                        }
                                        else
                                        {
                                            //if (Txn.Method.Equals(Transaction.Command.LoadPortType.Reset))
                                            //{
                                            //    logger.Debug("Txn timmer stoped.");
                                            //    Txn.SetTimeOutMonitor(false);

                                            //}
                                            //else if (Txn.Method.Equals(Transaction.Command.RobotType.OrginSearch))
                                            //{
                                            //    logger.Debug("Txn timmer stoped.");
                                            //    Txn.SetTimeOutMonitor(false);
                                            //    //Node.IsExcuting = false;
                                            //    TransactionList.TryAdd(key, Txn);
                                            //}
                                            //else
                                            //{
                                            Txn.SetTimeOutMonitor(false);
                                            Txn.SetTimeOut(Txn.MotionTimeOut);
                                            Txn.SetTimeOutMonitor(true);
                                            TransactionList.TryAdd(key, Txn);

                                            //}
                                        }
                                        //_ReportTarget.On_Command_Excuted(Node, Txn, ReturnMsg);
                                        break;

                                    case CommandReturnMessage.ReturnType.Finished:
                                        logger.Debug("Txn timmer stoped.");
                                        Txn.SetTimeOutMonitor(false);
                                        lock (Node.ExcuteLock)
                                        {
                                            Node.IsExcuting = false;
                                        }
                                        //_ReportTarget.On_Command_Finished(Node, Txn, ReturnMsg);
                                        break;

                                    case CommandReturnMessage.ReturnType.Error:
                                        logger.Debug("Txn timmer stoped.");
                                        Txn.SetTimeOutMonitor(false);
                                        lock (Node.ExcuteLock)
                                        {
                                            Node.IsExcuting = false;
                                        }
                                        //_ReportTarget.On_Command_Error(Node, Txn, ReturnMsg);
                                        if (Vendor.ToUpper().Equals("TDK") || DeviceType.ToUpper().Equals("SMARTTAG"))
                                        {
                                            //conn.Send(ReturnMsg.FinCommand);
                                            logger.Debug(DeviceName + " Send:" + ReturnMsg.FinCommand);
                                        }
                                        break;

                                    case CommandReturnMessage.ReturnType.Information:
                                        logger.Debug("Txn timmer stoped.");
                                        Txn.SetTimeOutMonitor(false);
                                        lock (Node.ExcuteLock)
                                        {
                                            Node.IsExcuting = false;
                                        }
                                        if (Vendor.ToUpper().Equals("TDK") && Txn.CommandType.Equals("SET"))
                                        {
                                            ReturnMsg.Type = CommandReturnMessage.ReturnType.Excuted;
                                        }
                                        else
                                        {
                                            ReturnMsg.Type = CommandReturnMessage.ReturnType.Finished;
                                            //Node.IsExcuting = false;
                                        }
                                        SpinWait.SpinUntil(() => false, 50);
                                        //ThreadPool.QueueUserWorkItem(new WaitCallback(conn.Send), ReturnMsg.FinCommand);
                                        //conn.Send(ReturnMsg.FinCommand);

                                        logger.Debug(DeviceName + " Send:" + ReturnMsg.FinCommand);

                                        break;
                                    }
                                }
                                else
                                {
                                    if (ReturnMsg.Type != null)
                                    {
                                        if (ReturnMsg.Type.Equals(CommandReturnMessage.ReturnType.Information))
                                        {
                                            //ThreadPool.QueueUserWorkItem(new WaitCallback(conn.Send), ReturnMsg.FinCommand);
                                            //conn.Send(ReturnMsg.FinCommand);

                                            logger.Debug(DeviceName + " Send:" + ReturnMsg.FinCommand);
                                        }
                                        else
                                        {
                                            if (ReturnMsg.Type == CommandReturnMessage.ReturnType.Error)
                                            {
                                                Txn = TransactionList.First().Value;

                                                logger.Debug("Txn timmer stoped.");
                                                Txn.SetTimeOutMonitor(false);
                                                lock (Node.ExcuteLock)
                                                {
                                                    Node.IsExcuting = false;
                                                }
                                                //_ReportTarget.On_Command_Error(Node, Txn, ReturnMsg);
                                                if (Vendor.ToUpper().Equals("TDK") || DeviceType.ToUpper().Equals("SMARTTAG"))
                                                {
                                                    //conn.Send(ReturnMsg.FinCommand);
                                                    logger.Debug(DeviceName + " Send:" + ReturnMsg.FinCommand);
                                                }

                                                TransactionList.TryRemove(TransactionList.First().Key, out Txn);
                                            }
                                            else
                                            {
                                                logger.Debug(DeviceName + "(On_Connection_Message Txn is not found. msg:" + Msg);
                                                continue;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        logger.Debug(DeviceName + "(On_Connection_Message Return type is null. msg:" + Msg);
                                        continue;
                                    }
                                }
                                //}
                            }
                            switch (ReturnMsg.Type)
                            {
                            case CommandReturnMessage.ReturnType.Information:
                            case CommandReturnMessage.ReturnType.Event:
                                Transaction t = new Transaction();
                                t.NodeName         = Node.Name;
                                t.NodeType         = Node.Type;
                                t.Value            = ReturnMsg.Value;
                                t.CommandEncodeStr = ReturnMsg.OrgMsg;
                                t.Method           = ReturnMsg.Command;

                                //TransactionRecord.AddDetail(TransactionRecord.GetUUID(), Node.Name,Node.Type,ReturnMsg.Type,ReturnMsg.Value);
                                _ReportTarget.On_Event_Trigger(Node, ReturnMsg);
                                break;

                            case CommandReturnMessage.ReturnType.Excuted:

                                _ReportTarget.On_Command_Excuted(Node, Txn, ReturnMsg);
                                if (Txn.CommandType.Equals("CMD") && !Node.Type.Equals("LOADPORT"))
                                {
                                    _ReportTarget.On_Node_State_Changed(Node, "Busy");
                                }
                                break;

                            case CommandReturnMessage.ReturnType.Finished:

                                //if (Node.Type.Equals("LOADPORT"))
                                //{
                                //    Node.InterLock = false;
                                //}

                                _ReportTarget.On_Command_Finished(Node, Txn, ReturnMsg);
                                if (!Node.Type.Equals("LOADPORT"))
                                {
                                    _ReportTarget.On_Node_State_Changed(Node, "StandBy");
                                }


                                break;

                            case CommandReturnMessage.ReturnType.Error:

                                //if (Node.Type.Equals("LOADPORT"))
                                //{
                                //    Node.InterLock = false;
                                //}
                                _ReportTarget.On_Command_Error(Node, Txn, ReturnMsg);

                                break;
                            }
                        }
                        else
                        {
                            logger.Debug(DeviceName + "(On_Connection_Message Message decode fail:" + Msg);
                        }
                    }
                    catch (Exception e)
                    {
                        logger.Error(DeviceName + "(On_Connection_Message " + IPAdress + ":" + Port.ToString() + ")" + e.Message + "\n" + e.StackTrace);
                    }
                }
            }
            catch (Exception e)
            {
                logger.Error(DeviceName + "(On_Connection_Message " + IPAdress + ":" + Port.ToString() + ")" + e.Message + "\n" + e.StackTrace);
            }
        }
Пример #12
0
 private static bool applicationIsDeskop()
 {
     return(deviceType.Equals(DeviceType.Desktop));
 }
Пример #13
0
        public DevicePrompts detectPrompt(string unknownPrompt)
        {
            string        strTemp = "", strOutput = "";
            char          LastPromptChar = '\0';
            DevicePrompts prompts        = new DevicePrompts();

            //Get full Prompt
            strOutput = shell.cmd("", unknownPrompt);
            if ((strOutput == null) || (strOutput.Length == 0))
            {
                //Found no Prompt Exit...
                prompts = null;
                return(null);
            }
            string[] strLines = strOutput.Split(new char[] { '\n' });
            foreach (string strLine in strLines)
            {
                strTemp = strLine.Replace("\n", "");
                strTemp = strTemp.Replace("\r", "");
                strTemp = strTemp.Trim(); // strTemp.Replace(" ", "");
                if (strTemp.Length > 0)
                {
                    LastPromptChar       = strTemp.ToCharArray(strTemp.Length - 1, 1)[0];
                    strTemp              = strTemp.Substring(0, strTemp.Length - 1); // Remove Last Char
                    prompts.DevicePrompt = HelperClass.quotemeta(strTemp);
                }
            }
            prompts.DevicePromptString = prompts.DevicePrompt;
            if ((LastPromptChar == '#') || (DeviceType.Equals("H3C")) || (DeviceType.Equals("HP") && (LastPromptChar == ']')))
            {
                //EnableMode = true;

                if (prompts.DevicePrompt.Length < 10)
                {
                    prompts.DevicePromptConfig = prompts.DevicePrompt.Substring(0, prompts.DevicePrompt.Length);
                }
                else
                {
                    prompts.DevicePromptConfig = prompts.DevicePrompt.Substring(0, 10);
                }
                if (prompts.DevicePromptConfig.EndsWith("\\"))
                {
                    prompts.DevicePromptConfig = prompts.DevicePromptConfig.Substring(0, prompts.DevicePromptConfig.Length - 1);
                }

                prompts.DevicePromptConfig = prompts.DevicePromptConfig + LastPromptChar;
                //DevicePromptConfig =~ s/(.*)(.)$/$1.*\\(config.*\\)$2/;	# s/(.*)([^\s])\s?$/$1.*\\(config.*\\)$2/;
                if ((DeviceType.Equals("HP") && (LastPromptChar == ']')) || DeviceType.Equals("H3C"))
                {
                    prompts.DevicePromptConfig = prompts.DevicePromptConfig.Substring(0, prompts.DevicePromptConfig.Length - 1) + ".*-.*" + LastPromptChar;
                    //DeviceType = "H3C";
                }
                else if (DeviceType.Equals("HP"))
                {
                    prompts.DevicePromptConfig = prompts.DevicePromptConfig.Substring(0, prompts.DevicePromptConfig.Length - 1) + ".*\\(.*\\)" + LastPromptChar;
                }
                else
                {
                    prompts.DevicePromptConfig = prompts.DevicePromptConfig.Trim();
                    //DevicePromptConfig = DevicePromptConfig.Substring(0, DevicePromptConfig.Length-1) + ".*\\(config.*\\)" + "#";
                    prompts.DevicePromptConfig = prompts.DevicePromptConfig.Substring(0, prompts.DevicePromptConfig.Length - 1) + ".*\\((?:c.*|.*-config)\\)" + LastPromptChar;
                }
                prompts.DevicePromptConfig = prompts.DevicePromptConfig + "[ \\r\\n]*$";
            }
            else
            {
                prompts.DevicePromptConfig = "";
            }

            prompts.DevicePrompt   = prompts.DevicePrompt + LastPromptChar + "[ \\r\\n]*$";
            prompts.LastPromptChar = LastPromptChar;
            if (_Debug > 0)
            {
                Console.WriteLine("\nDebug-Info:");
                Console.WriteLine("new Prompt: " + prompts.DevicePrompt);
                Console.WriteLine("Config-Prompt: " + prompts.DevicePromptConfig);
            }
            return(prompts);
        }
Пример #14
0
        protected string Specify()
        {
            int HPMatches = 0;

            string[] l_Lines = GetShowVersion();

            foreach (string strLine in l_Lines)
            {
                if (HelperClass.RegExCompare(strLine, @"s*[A-Z]+\.\d+\.\d+\s*|\s*Boot Image:.*", RegexOptions.IgnoreCase))
                {   //HP-Procurve
                    HPMatches++;
                    if (HPMatches > 1)
                    {
                        DeviceType = "HP";
                        break;
                    }
                }
                else if (strLine.ToLower().Contains("cisco ios xr ")) //Cisco IOS XR Software or iosxr-
                {
                    DeviceType = "Cisco-IOS-XR";
                    break;
                }
                else if (strLine.ToLower().Contains("cisco adaptive security appliance"))
                {
                    DeviceType = "Cisco-ASA";
                    break;
                }
                else if (strLine.ToLower().Contains("cisco"))
                {
                    DeviceType = "Cisco";
                    break;
                }
            }

            if (DeviceType.Length == 0)
            {
                string[] strOutp = this.SendCmd("show inventory");
                if (strOutp != null)
                {
                    foreach (string strLine in strOutp)
                    {
                        if (HelperClass.RegExCompare(strLine, @"cisco .*wireless .*controller", RegexOptions.IgnoreCase))
                        {
                            DeviceType = "Cisco WLC";
                            break;
                        }
                    }
                }
            }
            if ((DeviceType.Length == 0) || (DeviceType.Equals("HP")))
            {
                string[] strOutp = this.SendCmd("display version");
                if (strOutp != null)
                {
                    foreach (string strLine in strOutp)
                    {
                        if (strLine.ToLower().Contains("comware software"))
                        {
                            DeviceType = "H3C"; //H3C, HP A-Series
                            break;
                        }
                    }
                }
            }

            if (DeviceType.Length == 0)
            {
                l_Lines = GetRunningConfig();
                foreach (string strLine in l_Lines)
                {
                    if (HelperClass.RegExCompare(strLine, @"\s*;.* Configuration Editor; Created on release", RegexOptions.IgnoreCase))
                    {
                        DeviceType = "HP";
                        break;
                    }
                }
            }

            if (_Debug > 0)
            {
                Console.WriteLine("Device-Type: " + DeviceType);
            }

            return(DeviceType);
        }