예제 #1
0
        public int WaitTillSystemIsUp(string SystemIP, int WaitTimeOutInMins)
        {
            Generic        GenericObj  = new Generic();
            Logger         NewLogObj   = new Logger();
            FileOperations FileObj     = new FileOperations();
            string         LogFilePath = NewLogObj.GetLogFilePath();
            string         PingCmd     = "ping " + SystemIP;

            NewLogObj.WriteLogFile(LogFilePath, "ping cmd : " + PingCmd, "info");

            String CmdResult  = GenericObj.StartCmdExecutionAndWaitForCompletion(PingCmd);
            Regex  RegPattern = new Regex("\r\n");

            //Replace the newlines
            //CmdResult = RegPattern.Replace(CmdResult, " ");
            string [] TempList = RegPattern.Split(CmdResult);
            CmdResult = TempList[8];
            //foreach (string temp in TempList)
            //{
            //    CmdResult = CmdResult + temp + " ";
            //}
            string SystemLocale        = GenericObj.GetSystemLocale();
            string TranslatedCmdResult = null;

            NewLogObj.WriteLogFile(LogFilePath, "Ping Result: " + CmdResult, "info");

            if (!Regex.IsMatch(SystemLocale, "en-US"))
            {
                //BingTranslator MyBingObj = new BingTranslator();
                BingTranslator MyBingObj = new BingTranslator();
                //string BingLanguage = MyBingObj.DecideLanguageBasedOnLocale(SystemLocale);
                //TranslatedCmdResult = MyBingObj.TranslateString(CmdResult, "english");
                string Locale = MyBingObj.DecideLanguageBasedOnLocale(SystemLocale);
                //Antwort von 10.105.74.7: Bytes=32 Zeit<1ms TTL=63
                TranslatedCmdResult = MyBingObj.GenerateAccessTokenAndStartTranslation(CmdResult, Locale, "en");
            }
            else
            {
                TranslatedCmdResult = CmdResult;
            }
            TranslatedCmdResult = TranslatedCmdResult.ToLower();
            TranslatedCmdResult = Regex.Replace(TranslatedCmdResult, "\\s", "");
            //int PingStats = FileObj.CheckStringForPattern(TranslatedCmdResult, "Packets: Sent = 4, Received = 4, Lost = 0", null);
            // int PingStats = FileObj.CheckStringForPattern(TranslatedCmdResult, "packets:sent=4,received=4,lost=0", null);
            int PingStats = FileObj.CheckStringForPattern(TranslatedCmdResult, "packets:sent=4,received=4", null);

            //int PingStats = FileObj.CheckStringForPattern(CmdResult, TranslatedCmdResult, null);
            //int PingStats = FileObj.CheckUnicodeStringForPattern(CmdResult, TranslatedCmdResult, null);
            if (PingStats == 1)
            {
                NewLogObj.WriteLogFile(LogFilePath, "System " + SystemIP + " is up", "info");
                return(1);
            }
            int Timer = 0;
            int WaitTimeOutInMilliSecs = WaitTimeOutInMins * 60 * 1000;

            while (PingStats == -1 && Timer < WaitTimeOutInMilliSecs)
            {
                CmdResult = GenericObj.StartCmdExecutionAndWaitForCompletion(PingCmd);

                TempList  = RegPattern.Split(CmdResult);
                CmdResult = TempList[8];
                if (!Regex.IsMatch(SystemLocale, "en-US"))
                {
                    BingTranslator MyBingObj = new BingTranslator();
                    //string BingLanguage = MyBingObj.DecideLanguageBasedOnLocale(SystemLocale);
                    //TranslatedCmdResult = MyBingObj.TranslateString(CmdResult, "english");
                    string Locale = MyBingObj.DecideLanguageBasedOnLocale(SystemLocale);
                    TranslatedCmdResult = MyBingObj.GenerateAccessTokenAndStartTranslation(CmdResult, Locale, "en");
                }
                else
                {
                    TranslatedCmdResult = CmdResult;
                }
                //PingStats = FileObj.CheckStringForPattern(CmdResult, "Packets: Sent = 4, Received = 4, Lost = 0", null);
                //PingStats = FileObj.CheckStringForPattern(CmdResult, TranslatedCmdResult, null);
                TranslatedCmdResult = TranslatedCmdResult.ToLower();
                TranslatedCmdResult = Regex.Replace(TranslatedCmdResult, "\\s", "");
                //PingStats = FileObj.CheckStringForPattern(TranslatedCmdResult, "Packets: Sent = 4, Received = 4, Lost = 0", null);
                //PingStats = FileObj.CheckStringForPattern(TranslatedCmdResult, "packets:sent=4,received=4,lost=0", null);
                PingStats = FileObj.CheckStringForPattern(TranslatedCmdResult, "packets:sent=4,received=4", null);
                if (PingStats == 1)
                {
                    NewLogObj.WriteLogFile(LogFilePath, "System " + SystemIP + " is up", "info");
                    return(1);
                }
                Thread.Sleep(10000);
                Timer = Timer + 10000;
            }
            if (PingStats == -1 && Timer >= WaitTimeOutInMilliSecs)
            {
                NewLogObj.WriteLogFile(LogFilePath, "Timeout waiting for System " + SystemIP + " to be up", "info");
                return(-1);
            }
            return(-1);
        }