public static void AddDiv4FinalMessage(this ControlCollection controls, TestXmlFile testXmlFile, int errorCount, Stopwatch sw)
 {
     controls.AddDiv("<br/>&nbsp;&nbsp;&nbsp;&nbsp;(Всего: " + testXmlFile.TestRules.Sum(_ => _.TestSents.Count) + " штук, &nbsp;" +
                     ((errorCount == 0) ? "Ошибок НЕТ" : "Ошибок: " + errorCount + " штук") + ", &nbsp;Время: " +
                     sw.Elapsed);
 }
        protected void runTestButton_Click(object sender, EventArgs e)
        {
            #region [.set controls state.]
            runTestButton.Visible         = false;
            testFileUpload1.Visible       = false;
            testFileUpload2.Visible       = false;
            showOnlyErrorCheckBox.Visible = false;
            againHyperLink1.Visible       = true;
            againHyperLink2.Visible       = true;
            backHyperLink2.Visible        = true;
            //repeatLinkButton1    .Visible = true;
            //repeatLinkButton2    .Visible = true;
            #endregion

            #region [.read text-file.]
            var testXmlFile = new TestXmlFile(TestFileContent);
            #endregion

            #region [.test.]
            var sw = Stopwatch.StartNew();

            #region [.parallel.]
            var errorCount = 0;
            var wasCommunicationException = 0;
            Parallel.ForEach(testXmlFile.TestRules, rule =>
            {
                if (wasCommunicationException.IsTrue())
                {
                    return;
                }

                foreach (var sent in rule.TestSents)
                {
                    try
                    {
                        var result = GetTonalityOutputResult(sent);

                        var xdoc = result.OutputXml.ToXDocument();

                        #region [check OT.]
                        if (sent.OTs != null && sent.OTs.Any())
                        {
                            var inquiryinitialNodes = xdoc.XPathSelectElements("//*[ @INQUIRYINITIAL ]").ToArray();
                            if (sent.OTs.Count != inquiryinitialNodes.Length /*result.AuthorTonalityMarkingTuple.Objects.Count*/)
                            {
                                throw (new TestException("Число выделенных объектов не равно числу объектов в атрибуте-@OT в тестовом файле."));
                            }

                            for (var i = 0; i < sent.OTs.Count; i++)
                            {
                                var ot1     = sent.OTs[i];
                                var inquiry = inquiryinitialNodes[i];
                                var ot2     = inquiry.GetVALUETHEMEorVALUE();

                                var isi = ot1.ToInquiriesSynonymsInfo();
                                var xot = Algorithms.GetObjectBySynonyms(inquiry, isi);
                                if (xot == null)
                                {
                                    var subsent     = inquiry.GetAncestorSubsent();
                                    var subsentText = (subsent != null) ? subsent.Value : "???";

                                    throw (new TestException("В подпредложении " + subsentText.ToHtmlBold().InSingleQuotes() +
                                                             " определился объект " + ot2.ToHtmlBold().InSingleQuotes() +
                                                             ", должен определиться " + ot1.ToHtmlBold().InSingleQuotes()));
                                }
                            }
                        }
                        #endregion

                        #region [check SNTFINAL.]
                        var subsentNodes = xdoc.XPathSelectElements("//SUB_SENT").ToArray();       // || "TEXT/SENT/SUB_SENT"
                        if (sent.SNTFINALs.Count != subsentNodes.Length)
                        {
                            throw (new TestException("Число подпредложений в строке не равно числу атрибутов-@SNTFINAL в тестовом файле."));
                        }
                        for (var i = 0; i < sent.SNTFINALs.Count; i++)
                        {
                            var snt1 = subsentNodes[i].GetAttributeSNTFINAL();
                            var snt2 = sent.SNTFINALs[i];
                            if (snt1 != snt2)
                            {
                                throw (new TestException("Подпредложение " + subsentNodes[i].Value.ToHtmlBold().InSingleQuotes() +
                                                         " получило @SNTFINAL=" + snt1.ToString().ToHtmlBold().InSingleQuotes() +
                                                         ", должно быть @SNTFINAL=" + snt2.ToString().ToHtmlBold().InSingleQuotes()));
                            }
                        }
                        #endregion

                        #region [.check operate-rule-order.]
                        if (result.OperateRulesNames != null)
                        {
                            var indexofStartSearch = 0;
                            foreach (var id in rule.Ids)
                            {
                                var name = result.OperateRulesNames
                                           .Skip(indexofStartSearch)
                                           .FirstOrDefault(n => n.StartsWith(id, StringComparison.InvariantCultureIgnoreCase));
                                if (name != null)
                                {
                                    var indexofStartSearchNew = indexofStartSearch +
                                                                result.OperateRulesNames.Skip(indexofStartSearch).ToList().IndexOf(name);
                                    //result.OperateRulesNames.IndexOf( name );

                                    for (int i = indexofStartSearch; i < indexofStartSearchNew; i++)
                                    {
                                        var value = result.OperateRulesNames[i];
                                        if (3 <= value.Length &&
                                            100 <= value.Substring(0, 3).TryConvert2Int().GetValueOrDefault())
                                        {
                                            //found who's don't shoul be found!!!!!
                                            throw (new TestException("Сработало правило " + value.InSingleQuotes().ToHtmlBold() + ", которое не должно было сработать: " + result.OperateRulesNames.ToHtml()));
                                        }
                                    }

                                    indexofStartSearch = indexofStartSearchNew + 1;
                                }
                                else
                                {
                                    //not found!!!!!!!
                                    throw (new TestException("Правило " + id.InSingleQuotes().ToHtmlBold() + " не найдено среди сработавших правил: " + result.OperateRulesNames.ToHtml()));
                                }
                            }
                        }
                        #endregion

                        if (showOnlyErrorCheckBox.Checked)
                        {
                            continue;
                        }

                        rule.HtmlControls.Add(Extensions4Test.CreateDiv4OkMessage(rule, sent));
                    }
                    catch (Exception ex)
                    {
                        #region
                        Interlocked.Increment(ref errorCount);

                        rule.HtmlControls.Add(Extensions4Test.CreateDiv4ExceptionMessage(ex, rule, sent));

                        if (ex is CommunicationException)       //EndpointNotFoundException)
                        {
                            Interlocked.CompareExchange(ref wasCommunicationException, 1, 0);
                            return;
                        }
                        #endregion
                    }
                }
            }
                             );

            //output result to html
            foreach (var rule in testXmlFile.TestRules)
            {
                foreach (var control in rule.HtmlControls)
                {
                    resultDiv.Controls.Add(control);
                    resultDiv.Controls.AddHr();
                }
            }
            if (wasCommunicationException.IsTrue())
            {
                resultDiv.Controls.AddDiv("....выполниение теста прервано => [CommunicationException]....");
                resultDiv.Controls.AddHr();
            }
            #endregion

            #region [.consecutively.]

            /*
             * var errorCount = 0;
             * foreach ( var rule in testXmlFile.TestRules )
             * {
             *  foreach ( var sent in rule.TestSents )
             *  {
             *      try
             *      {
             *          var result = GetTonalityOutputResult( sent, lptm );
             *
             #region [check SNTFINAL.]
             *          var subsentNodes = result.OutputXml.ToXDocument().XPathSelectElements( "//SUB_SENT" ).ToArray(); // || "TEXT/SENT/SUB_SENT"
             *          if ( sent.SNTFINALs.Count != subsentNodes.Length )
             *          {
             *              throw (new TestException("Число подпредложений в строке не равно числу атрибутов-@SNTFINAL в тестовом файле."));
             *          }
             *          for ( var i = 0; i < sent.SNTFINALs.Count; i++ )
             *          {
             *              var snt1 = subsentNodes[ i ].GetAttributeSNTFINAL();
             *              var snt2 = sent.SNTFINALs[ i ];
             *              if ( snt1 != snt2 )
             *              {
             *                  throw (new TestException("Подпредложение "          + subsentNodes[ i ].Value.ToHtmlBold().InSingleQuotes() +
             *                                           " получило @SNTFINAL="     + snt1.ToString()        .ToHtmlBold().InSingleQuotes() +
             *                                           ", должно быть @SNTFINAL=" + snt2.ToString()        .ToHtmlBold().InSingleQuotes() ));
             *              }
             *          }
             #endregion
             *
             #region [.check operate-rule-order.]
             *          if ( result.OperateRulesNames != null )
             *          {
             *              var indexofStartSearch = 0;
             *              foreach ( var id in rule.Ids )
             *              {
             *                  var name = result.OperateRulesNames
             *                                   .Skip( indexofStartSearch )
             *                                   .FirstOrDefault( n => n.StartsWith( id, StringComparison.InvariantCultureIgnoreCase ) );
             *                  if ( name != null )
             *                  {
             *                      var indexofStartSearchNew = indexofStartSearch +
             *                                                  result.OperateRulesNames.Skip( indexofStartSearch ).ToList().IndexOf( name );
             *                          //result.OperateRulesNames.IndexOf( name );
             *
             *                      for ( int i = indexofStartSearch; i < indexofStartSearchNew; i++ )
             *                      {
             *                          var value = result.OperateRulesNames[ i ];
             *                          if ( 3 <= value.Length &&
             *                               100 <= value.Substring( 0, 3 ).TryConvert2Int().GetValueOrDefault() )
             *                          {
             *                              //found who's don't shoul be found!!!!!
             *                              throw (new TestException("Сработало правило " + value.InSingleQuotes().ToHtmlBold() + ", которое не должно было сработать: " + result.OperateRulesNames.ToHtml() ));
             *                          }
             *                      }
             *
             *                      indexofStartSearch = indexofStartSearchNew + 1;
             *                  }
             *                  else
             *                  {
             *                      //not found!!!!!!!
             *                      throw (new TestException("Правило " + id.InSingleQuotes().ToHtmlBold() + " не найдено среди сработавших правил: " + result.OperateRulesNames.ToHtml() ));
             *                  }
             *              }
             *          }
             #endregion
             *
             *          if ( showOnlyErrorCheckBox.Checked )
             *              continue;
             *
             *          resultDiv.Controls.AddDiv4OkMessage( rule, sent );
             *      }
             *      catch ( Exception ex )
             *      {
             #region
             *          errorCount++;
             *
             *          resultDiv.Controls.AddDiv4ExceptionMessage( ex, rule, sent );
             *
             *          if ( ex is CommunicationException ) //EndpointNotFoundException)
             *          {
             *              resultDiv.Controls.AddDiv( "....выполниение теста прервано...." );
             *              return;
             *          }
             #endregion
             *      }
             *      resultDiv.Controls.AddHr();
             *  }
             * }
             * //*/
            #endregion

            sw.Stop();
            resultDiv.Controls.AddDiv4FinalMessage(testXmlFile, errorCount, sw);
            #endregion
        }