예제 #1
0
        public override void Run(bool runChildren)
        {
            RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink urlListCreate");
            urlList = new System.Collections.Concurrent.ConcurrentBag<string>();
            RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink  autoNextLink.Run");

            autoNextLink.Run();
            RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink  autoNextLink.Run End");

            var page = this.GetUpperRawler<Page>();
            if (page != null)
            {
                if (maxCount > count)
                {
                    var url = page.GetCurrentUrl();
                    Uri url_uri = new Uri(url);
                    if (urlList.Any())
                    {
                        var test = urlList.Distinct().Where(n => new Uri(n).Host == url_uri.Host && urlHash.Contains(n) == false).ToList();
                        var nextUrl = urlList.Distinct().Where(n => new Uri(n).Host == url_uri.Host && urlHash.Contains(n) == false)
                            .Select(n => new { url = n, Distance = Rawler.NPL.LevenshteinDistance.Compute(url, n) })
                            .OrderBy(n => n.Distance);
                        if (nextUrl.Any())
                        {
                            page.PushUrl(nextUrl.First().url);
                            urlHash.Add(nextUrl.First().url);
                            count++;
                        }
                        urlHash.Add(url);

                    }
                    else
                    {
                        ReportManage.ErrReport(this, "NextLinkの取得がありません");
                    }
                }
            }
            RawlerLib.Timer.StopWatch.Write("RawlerAutoNextLink  End");

            base.Run(runChildren);
        }
예제 #2
0
        public void Test(ITestContext context)
        {
            var failedChecks = new System.Collections.Concurrent.ConcurrentBag<SqlDeployResult>();
            var databasesCount = this.sqlDeploy.Settings.Databases.Count();
            var processedCount = 0;
            var databases = this.sqlDeploy.Settings.Databases.ToList();
            context.UpdateProgress(0, processedCount, databasesCount);
            Parallel.ForEach(
                databases,
                database =>
                {
                    var csBuilder = new SqlConnectionStringBuilder(database.ConnectionString);
                    var dbName = csBuilder.InitialCatalog;
                    var upToDate = database.Status.IsUpToDate;
                    try
                    {
                        var reconcileResult = this.sqlDeploy.ReconcileDatabase(database.DatabaseName);
                        if (upToDate && reconcileResult.IsSuccessful)
                        {
                            context.WriteLine(EventType.Success, Titles.DbIsUpToDate, dbName);
                        }
                        else
                        {
                            if (!upToDate)
                            {
                                context.WriteLine(
                                    EventType.Error,
                                    Titles.DbCheckFailed,
                                    dbName,
                                    Titles.SchemaNotUpToDate);
                                var result = new SqlDeployResult
                                                 {
                                                     IsSuccessful = false,
                                                     DatabaseName = dbName,
                                                     Exceptions =
                                                         new List<Exception>
                                                             {
                                                                 new Exception(
                                                                     Titles
                                                                     .SchemaNotUpToDate)
                                                             }
                                                 };
                                failedChecks.Add(result);
                            }
                            else
                            {
                                context.WriteLine(EventType.Error, Titles.DbCheckFailed, dbName, Titles.SchemaChanged);
                                failedChecks.Add(reconcileResult);
                            }
                        }
                    }
                    catch (SqlException ex)
                    {
                        context.WriteLine(
                                    EventType.Error,
                                    Titles.DbCheckFailed,
                                    dbName,
                                    ex.Message);
                                var result = new SqlDeployResult
                                                 {
                                                     IsSuccessful = false,
                                                     DatabaseName = dbName,
                                                     Exceptions =
                                                         new List<Exception>
                                                             {
                                                                 new Exception(ex.Message)
                                                             }
                                                 };
                                failedChecks.Add(result);
                    }

                    processedCount++;
                    context.UpdateProgress(0, processedCount, databasesCount);
                });
            
            if (failedChecks.Any())
            {
                var msg = string.Format(Titles.DbsNotUpToDate, string.Join(", ", failedChecks.Select(x => x.DatabaseName).ToArray()));
                Assert.Fails(msg);
            }
        }