Example #1
0
        public void Add_WithUrlElement_IncreasesCountByOne()
        {
            var urlCollection = new UrlCollection();

            urlCollection.Add(new UrlElement(new Uri("http://someurl.com"), DateTime.Today, ChangeFrequency.Daily, 1));
            Assert.AreEqual(1, urlCollection.Count);
        }
Example #2
0
        public void ListUrls()
        {
            Init();
            UrlCollection all = Url.Where(c => c.Id != null);

            foreach (Url u in all)
            {
                OutLine(u.ToString());
            }
        }
Example #3
0
        private Program()
        {
            _startTime = DateTime.Now;

            string startingUrl = String.Concat(ConfigurationManager.AppSettings["startingUrl"], ConfigurationManager.AppSettings["path"]);

            _urls = new UrlCollection();
            _urls.Enqueue(new SpiderUrl(startingUrl, startingUrl));

            _visitedUrls = new List <string>();

            Logger.InitializeLogFile("Id, Start Time, Message, Target, Referrer, Title, Time");
        }
Example #4
0
 public ActionResult Save(Bam.Net.Analytics.Url[] values)
 {
     try
     {
         UrlCollection saver = new UrlCollection();
         saver.AddRange(values);
         saver.Save();
         return(Json(new { Success = true, Message = "", Dao = "" }));
     }
     catch (Exception ex)
     {
         return(GetErrorResult(ex));
     }
 }
Example #5
0
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/xml";

        var urlCollection = new UrlCollection();

        // Let's add home page
        var homePage = new Url(new Uri(Config.HomeUrl), DateTime.Today, ChangeFrequency.Daily, 0.7M);

        urlCollection.Add(homePage);
        if (!homePage.Location.StartsWith("http://") && !homePage.Location.StartsWith("https://") && !homePage.Location.StartsWith("feed://"))
        {
            throw new Exception("Sitemap URLs must include protocol (e.g. http://). Refer to http://sitemaps.org for details");
        }
        var forumPage = new Url(new Uri(Config.ForumUrl), DateTime.Today, ChangeFrequency.Daily, 0.7M);

        urlCollection.Add(forumPage);

        #region Write out the topics

        foreach (TopicInfo topic in Topics.GetTopicsForSiteMap(100))
        {
            int topicId = topic.Id;

            var thisUrl = new Url(new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/Content/Forums/topic.aspx?TOPIC_ID={1}", forumPage.Location.TrimEnd('/'), topicId)), topic.LastPostDate.Value, ChangeFrequency.Daily, 0.5M);
            if (thisUrl.Location.Length >= 2048)
            {
                throw new Exception("Sitemap URLs cannot have more than 2048 characters. Refer to http://sitemaps.org for details");
            }
            urlCollection.Add(thisUrl);
        }

        #endregion


        //urlCollection.Add(new Url(new Uri(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}policy.aspx", config.forumUrl)), DateTime.Today, ChangeFrequency.Never, 0.0M));
        urlCollection.Add(new Url(new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/Content/Faq/faq.aspx", Config.ForumUrl.TrimEnd('/'))), DateTime.Today, ChangeFrequency.Never, 0.0M));
        urlCollection.Add(new Url(new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/Content/Forums/active.aspx", Config.ForumUrl.TrimEnd('/'))), DateTime.Today, ChangeFrequency.Always, 1.0M));
        if (urlCollection.Count > 5000)
        {
            throw new Exception("Sitemap file cannot contain more than 5,000 URLs. Refer to http://sitemaps.org for details");
        }
        var serializer    = new XmlSerializer(typeof(UrlCollection));
        var xmlTextWriter = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8);
        serializer.Serialize(xmlTextWriter, urlCollection);
    }
Example #6
0
    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/xml";

        var urlCollection = new UrlCollection();

        // Let's add home page
        var homePage = new Url(new Uri(Config.HomeUrl), DateTime.Today, ChangeFrequency.Daily, 0.7M);
        urlCollection.Add(homePage);
        if (!homePage.Location.StartsWith("http://") && !homePage.Location.StartsWith("https://") && !homePage.Location.StartsWith("feed://"))
        {
            throw new Exception("Sitemap URLs must include protocol (e.g. http://). Refer to http://sitemaps.org for details");
        }
        var forumPage = new Url(new Uri(Config.ForumUrl), DateTime.Today, ChangeFrequency.Daily, 0.7M);
        urlCollection.Add(forumPage);

        #region Write out the topics

        foreach (TopicInfo topic in Topics.GetTopicsForSiteMap(100))
        {
            int topicId = topic.Id;

            var thisUrl = new Url(new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/Content/Forums/topic.aspx?TOPIC_ID={1}", forumPage.Location.TrimEnd('/'), topicId)), topic.LastPostDate.Value, ChangeFrequency.Daily, 0.5M);
            if (thisUrl.Location.Length >= 2048)
            {
                throw new Exception("Sitemap URLs cannot have more than 2048 characters. Refer to http://sitemaps.org for details");
            }
            urlCollection.Add(thisUrl);
        }

        #endregion

        //urlCollection.Add(new Url(new Uri(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}policy.aspx", config.forumUrl)), DateTime.Today, ChangeFrequency.Never, 0.0M));
        urlCollection.Add(new Url(new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/Content/Faq/faq.aspx", Config.ForumUrl.TrimEnd('/'))), DateTime.Today, ChangeFrequency.Never, 0.0M));
        urlCollection.Add(new Url(new Uri(string.Format(CultureInfo.InvariantCulture, "{0}/Content/Forums/active.aspx", Config.ForumUrl.TrimEnd('/'))), DateTime.Today, ChangeFrequency.Always, 1.0M));
        if (urlCollection.Count > 5000)
        {
            throw new Exception("Sitemap file cannot contain more than 5,000 URLs. Refer to http://sitemaps.org for details");
        }
        var serializer = new XmlSerializer(typeof(UrlCollection));
        var xmlTextWriter = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8);
        serializer.Serialize(xmlTextWriter, urlCollection);
    }
Example #7
0
        private Program()
        {
            CheckConfiguration();
            InitializeMimeTypesToIgnore();
            InitializeContentTypesToInclude();
            IntializeLinkHrefPatternsToIgnore();

            _startTime = DateTime.Now;

            string startingUrl = String.Concat(ConfigurationManager.AppSettings["startingUrl"], ConfigurationManager.AppSettings["path"]);

            _urls = new UrlCollection();
            _urls.Enqueue(new SpiderUrl(startingUrl, startingUrl));

            _visitedUrls       = new List <string>();
            _onlyFollowUniques = bool.Parse(ConfigurationManager.AppSettings["onlyFollowUniques"]);
            _website           = new Regex(String.Format("^(http|https){{1}}://({0}){{1}}", ConfigurationManager.AppSettings["website"]), RegexOptions.Compiled | RegexOptions.CultureInvariant);

            Logger.InitializeLogFile("\"Id\",\"Checked\",\"Start Time\",\"Message\",\"Target\",\"Referrer\",\"Title\",\"Time\",\"Size\",\"Content Type\",\"MIME Type\"");
        }
        public override void ProcessRequest()
        {
            HttpContextBase context = SubtextContext.HttpContext;

            context.Response.ContentType = "text/xml";

            var urlCollection = new UrlCollection();

            // Let's add home page
            var homePage = new UrlElement(Url.BlogUrl().ToFullyQualifiedUrl(Blog), DateTime.UtcNow, ChangeFrequency.Daily, 1.0M);

            urlCollection.Add(homePage);

            // then all the entries

            ICollection <Entry> posts = Repository.GetEntries(0, PostType.BlogPost, PostConfig.IsActive, false
                                                              /* includeCategories */);

            if (posts != null)
            {
                foreach (Entry post in posts)
                {
                    ChangeFrequency frequency = CalculateFrequency(post);
                    urlCollection.Add(
                        new UrlElement(Url.EntryUrl(post).ToFullyQualifiedUrl(Blog), post.DateModifiedUtc,
                                       frequency, 0.8M));
                }
            }

            // all articles
            ICollection <Entry> stories = Repository.GetEntries(0, PostType.Story, PostConfig.IsActive, false
                                                                /* includeCategories */);

            if (stories != null)
            {
                foreach (Entry story in stories)
                {
                    ChangeFrequency frequency = CalculateFrequency(story);
                    urlCollection.Add(
                        new UrlElement(Url.EntryUrl(story).ToFullyQualifiedUrl(Blog),
                                       story.DateModifiedUtc,
                                       frequency, 0.8M));
                }
            }

            // categories
            ICollection <LinkCategory> links = Repository.GetCategories(CategoryType.PostCollection, true
                                                                        /* activeOnly */);
            LinkCategory categories = Transformer.MergeLinkCategoriesIntoSingleLinkCategory(string.Empty /* title */,
                                                                                            CategoryType.PostCollection,
                                                                                            links, Url, Blog);

            if (categories != null)
            {
                foreach (Link category in categories.Links)
                {
                    urlCollection.Add(
                        new UrlElement(new Uri(Url.BlogUrl().ToFullyQualifiedUrl(Blog) + category.Url),
                                       DateTime.Today,
                                       ChangeFrequency.Weekly, 0.6M));
                }
            }

            // archives
            // categories
            ICollection <ArchiveCount> archiveCounts = Repository.GetPostCountsByMonth();
            LinkCategory archives = archiveCounts.MergeIntoLinkCategory(string.Empty, Url, Blog);

            if (archives != null)
            {
                foreach (Link archive in archives.Links)
                {
                    urlCollection.Add(
                        new UrlElement(
                            new Uri(Url.BlogUrl().ToFullyQualifiedUrl(Blog) + archive.Url), DateTime.Today,
                            ChangeFrequency.Weekly, 0.6M));
                }
            }

            // don't index contact form
            urlCollection.Add(new UrlElement(Url.ContactFormUrl().ToFullyQualifiedUrl(Blog), DateTime.Today,
                                             ChangeFrequency.Never, 0.0M));
            var serializer    = new XmlSerializer(typeof(UrlCollection));
            var xmlTextWriter = new XmlTextWriter(context.Response.Output);

            serializer.Serialize(xmlTextWriter, urlCollection);
        }
Example #9
0
 public void UrlCollectionAcceptsEntries()
 {
     UrlCollection urlCollection = new UrlCollection();
     urlCollection.Add(new Url(new Uri("http://someurl.com"), DateTime.Today, ChangeFrequency.Daily, 1));
     Assert.AreEqual(1, urlCollection.Count);
 }
        public override void ProcessRequest()
        {
            HttpContextBase context = SubtextContext.HttpContext;
            context.Response.ContentType = "text/xml";

            var urlCollection = new UrlCollection();

            // Let's add home page
            var homePage = new UrlElement(Url.BlogUrl().ToFullyQualifiedUrl(Blog), DateTime.UtcNow, ChangeFrequency.Daily, 1.0M);
            urlCollection.Add(homePage);

            // then all the entries

            ICollection<Entry> posts = Repository.GetEntries(0, PostType.BlogPost, PostConfig.IsActive, false
                /* includeCategories */);
            if (posts != null)
            {
                foreach (Entry post in posts)
                {
                    ChangeFrequency frequency = CalculateFrequency(post);
                    urlCollection.Add(
                        new UrlElement(Url.EntryUrl(post).ToFullyQualifiedUrl(Blog), post.DateModifiedUtc,
                                       frequency, 0.8M));
                }
            }

            // all articles
            ICollection<Entry> stories = Repository.GetEntries(0, PostType.Story, PostConfig.IsActive, false
                /* includeCategories */);
            if (stories != null)
            {
                foreach (Entry story in stories)
                {
                    ChangeFrequency frequency = CalculateFrequency(story);
                    urlCollection.Add(
                        new UrlElement(Url.EntryUrl(story).ToFullyQualifiedUrl(Blog),
                                       story.DateModifiedUtc,
                                       frequency, 0.8M));
                }
            }

            // categories
            ICollection<LinkCategory> links = Repository.GetCategories(CategoryType.PostCollection, true
                /* activeOnly */);
            LinkCategory categories = Transformer.MergeLinkCategoriesIntoSingleLinkCategory(string.Empty /* title */,
                                                                                            CategoryType.PostCollection,
                                                                                            links, Url, Blog);
            if (categories != null)
            {
                foreach (Link category in categories.Links)
                {
                    urlCollection.Add(
                        new UrlElement(new Uri(Url.BlogUrl().ToFullyQualifiedUrl(Blog) + category.Url),
                                       DateTime.Today,
                                       ChangeFrequency.Weekly, 0.6M));
                }
            }

            // archives
            // categories
            ICollection<ArchiveCount> archiveCounts = Repository.GetPostCountsByMonth();
            LinkCategory archives = archiveCounts.MergeIntoLinkCategory(string.Empty, Url, Blog);
            if (archives != null)
            {
                foreach (Link archive in archives.Links)
                {
                    urlCollection.Add(
                        new UrlElement(
                            new Uri(Url.BlogUrl().ToFullyQualifiedUrl(Blog) + archive.Url), DateTime.Today,
                            ChangeFrequency.Weekly, 0.6M));
                }
            }

            // don't index contact form
            urlCollection.Add(new UrlElement(Url.ContactFormUrl().ToFullyQualifiedUrl(Blog), DateTime.Today,
                                             ChangeFrequency.Never, 0.0M));
            var serializer = new XmlSerializer(typeof(UrlCollection));
            var xmlTextWriter = new XmlTextWriter(context.Response.Output);
            serializer.Serialize(xmlTextWriter, urlCollection);
        }
Example #11
0
        public void Initialize()
        {
            InitializeError = string.Empty;
            if (Export2CsvCommand == null)
            {
                Export2CsvCommand = new RelayCommand(() => Export2Csv());
            }
            if (Export2DbCommand == null)
            {
                Export2DbCommand = new RelayCommand(Export2Db);
            }
            if (UpdateErrorsCommand == null)
            {
                UpdateErrorsCommand = new RelayCommand(UpdateErrors);
            }
            if (UpdateSelectedErrorCommand == null)
            {
                UpdateSelectedErrorCommand = new RelayCommand(UpdateSelectedError);
            }
            if (UpdateSelectedWarningCommand == null)
            {
                UpdateSelectedWarningCommand = new RelayCommand(UpdateSelectedWarning);
            }

            loadWorker = new BackgroundWorker()
            {
                WorkerReportsProgress = true, WorkerSupportsCancellation = true
            };
            loadWorker.DoWork += (s, prm) =>
            {
                var Disp = prm.Argument as System.Windows.Threading.Dispatcher;

                ObservableCollection <OutputRow> rowsToExport = new ObservableCollection <OutputRow>();
                Guid logSession = Helpers.Old.Log.SessionStart("ExportViewModel.Initialize()");
                try
                {
                    Log.Add(string.Format("total sheets count: '{0}'", App.Locator.Import.Document.DocumentSheets.Count));
                    var addErr  = new List <Error>();
                    var addGErr = new List <GlobalError>();

                    var progress = new PercentageProgress();

                    foreach (var item in App.Locator.Import
                             .ExportRules
                             .Where(r => r.Rule != App.Locator.Import.NullRule)
                             .Select(r => new { Rule = r, Progress = progress.GetChild() })
                             .ToArray()
                             )
                    {
                        if (((BackgroundWorker)s).CancellationPending || s != loadWorker)
                        {
                            break;
                        }

                        var mappingRule = item.Rule.Rule;
                        var ds          = item.Rule.Sheet;

                        if (mappingRule == null || ds == null)
                        {
                            if (!string.IsNullOrWhiteSpace(item.Rule.Status))
                            {
                                addGErr.Add(new GlobalError()
                                {
                                    Description = item.Rule.Status
                                });
                            }
                            item.Progress.Value = 100;
                            continue;
                        }
                        else
                        {
                            if (ds.MainHeader == null)
                            {
                                Log.Add(string.Format("should update main header row..."));

                                ds.UpdateMainHeaderRow(mappingRule.MainHeaderSearchTags
                                                       .Select(h => h.Tag)
                                                       .Union(SettingsProvider.CurrentSettings.HeaderSearchTags.Split(new char[] { ',' }))
                                                       .Select(i => i.Trim())
                                                       .Where(i => !string.IsNullOrEmpty(i))
                                                       .Distinct()
                                                       .ToArray());

                                ds.UpdateHeaders(mappingRule.SheetHeadersSearchTags
                                                 .Select(h => h.Tag.Trim())
                                                 .Where(i => !string.IsNullOrEmpty(i))
                                                 .Distinct()
                                                 .ToArray());
                            }

                            var oc = new ObservableCollection <OutputRow>(mappingRule.Convert(ds,
                                                                                              progressAction: (i) =>
                            {
                                item.Progress.Value = i;
                                ((BackgroundWorker)s).ReportProgress((int)progress.Value);
                            },
                                                                                              isCanceled: () => { return(((BackgroundWorker)s).CancellationPending); },
                                                                                              additionalErrorAction: (e, r) =>
                            {
                                addErr.Add(new Error()
                                {
                                    Description = e.GetExceptionText(includeStackTrace: false, clearText: true).Trim(), RowNumber = r
                                });
                            }));
                            Log.Add(string.Format("row count on sheet '{0}' : '{1}'", ds.Name, oc.Count));
                            rowsToExport = new ObservableCollection <OutputRow>(rowsToExport.Union(oc));
                            Log.Add(string.Format("subtotal row count on sheets: '{0}'", rowsToExport.Count));
                        }
                    }

                    ExelConvertionRule.RemoveRepeatingId(rowsToExport.ToList());

                    var UrlsPhoto  = new UrlCollection();
                    var UrlsSchema = new UrlCollection();
                    var UrlsAll    = new UrlCollection();

                    var photos  = rowsToExport.Select(r => r.Photo_img).Where(r => Helper.IsWellFormedUriString(r, UriKind.Absolute)).Distinct();
                    var schemas = rowsToExport.Select(r => r.Location_img).Where(r => Helper.IsWellFormedUriString(r, UriKind.Absolute)).Distinct();
                    var all     = photos.Union(schemas).Distinct();

                    foreach (var p in photos)
                    {
                        UrlsPhoto.Add(new StringUrlWithResultWrapper(p));
                    }
                    foreach (var p in schemas)
                    {
                        UrlsSchema.Add(new StringUrlWithResultWrapper(p));
                    }
                    foreach (var p in all)
                    {
                        UrlsAll.Add(new StringUrlWithResultWrapper(p));
                    }

                    if (!((BackgroundWorker)s).CancellationPending && s == loadWorker)
                    {
                        Disp.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                        {
                            UrlCollection.Clear();
                            if (UrlsPhoto.Count > 0)
                            {
                                UrlCollection.Add(new UrlCollectionAdditional()
                                {
                                    Name = DBParsers.Labels.ElementAt(0), Collection = UrlsPhoto
                                });
                            }
                            if (UrlsSchema.Count > 0)
                            {
                                UrlCollection.Add(new UrlCollectionAdditional()
                                {
                                    Name = DBParsers.Labels.ElementAt(1), Collection = UrlsSchema
                                });
                            }
                            if (UrlsPhoto.Count > 0 && UrlsSchema.Count > 0 && UrlsAll.Count > 0)
                            {
                                UrlCollection.Add(new UrlCollectionAdditional()
                                {
                                    Name = "Все", Collection = UrlsAll
                                });
                            }
                            UrlCollectionSelectedIndex = UrlCollection.Count - 1;
                            RowsToExport = rowsToExport;
                            UpdateErrors(addErr, addGErr);
                        }));
                    }
                    else
                    {
                        prm.Cancel = true;
                    }
                }
                catch (Exception ex)
                {
                    Helpers.Old.Log.Add(logSession, ex.GetExceptionText());
                    throw ex;
                }
                finally
                {
                    Log.Add(string.Format("total row count to export: '{0}'", rowsToExport.Count));
                    Helpers.Old.Log.SessionEnd(logSession);
                }
            };

            loadWorker.ProgressChanged += (s, e) =>
            {
                if (s == loadWorker)
                {
                    LoadProgress = e.ProgressPercentage;
                }
            };

            loadWorker.RunWorkerCompleted += (s, e) =>
            {
                if (s == loadWorker)
                {
                    try
                    {
                        if (e.Cancelled)
                        {
                            throw new Exception("Загрузка отменена пользователем");
                        }
                        if (e.Error != null)
                        {
                            throw e.Error;
                        }
                    }
                    catch (Exception ex)
                    {
                        InitializeError = ex.GetExceptionText();
                    }
                }
                finally
                {
                    if (s == loadWorker)
                    {
                        IsLoading  = false;
                        loadWorker = null;
                    }
                }
                ((BackgroundWorker)s).Dispose();
            };
Example #12
0
 public void Add_WithUrlElement_IncreasesCountByOne()
 {
     var urlCollection = new UrlCollection();
     urlCollection.Add(new UrlElement(new Uri("http://someurl.com"), DateTime.Today, ChangeFrequency.Daily, 1));
     Assert.AreEqual(1, urlCollection.Count);
 }
Example #13
0
 private string ReplaceUrlFromData(string url, string label, UrlCollection collection)
 {
     string result = url;
     var colRes = collection.FirstOrDefault(i => i.Value == url);
     if (colRes != null)
     {
         result = string.Empty;
         if (colRes.Result != null && colRes.Result.Data != null && colRes.Result.Data.ContainsLabel(label))
             result = colRes.Result.Data[label];
     }
     return result;
 }
Example #14
0
        public void Initialize()
        {
            InitializeError = string.Empty;
            if (Export2CsvCommand == null)
                Export2CsvCommand = new RelayCommand(() => Export2Csv());
            if (Export2DbCommand == null)
                Export2DbCommand = new RelayCommand(Export2Db);
            if (UpdateErrorsCommand == null)
                UpdateErrorsCommand = new RelayCommand(UpdateErrors);
            if (UpdateSelectedErrorCommand == null)
                UpdateSelectedErrorCommand = new RelayCommand(UpdateSelectedError);
            if (UpdateSelectedWarningCommand == null)
                UpdateSelectedWarningCommand = new RelayCommand(UpdateSelectedWarning);

            loadWorker = new BackgroundWorker() { WorkerReportsProgress = true, WorkerSupportsCancellation = true };
            loadWorker.DoWork += (s, prm) =>
            {
                var Disp = prm.Argument as System.Windows.Threading.Dispatcher;

                ObservableCollection<OutputRow> rowsToExport = new ObservableCollection<OutputRow>();
                Guid logSession = Helpers.Old.Log.SessionStart("ExportViewModel.Initialize()");
                try
                {
                    Log.Add(string.Format("total sheets count: '{0}'", App.Locator.Import.Document.DocumentSheets.Count));
                    var addErr = new List<Error>();
                    var addGErr = new List<GlobalError>();

                    var progress = new PercentageProgress();

                    foreach (var item in App.Locator.Import
                        .ExportRules
                        .Where(r => r.Rule != App.Locator.Import.NullRule)
                        .Select(r => new { Rule = r, Progress = progress.GetChild() })
                        .ToArray()
                        )
                    {
                        if (((BackgroundWorker)s).CancellationPending || s != loadWorker)
                            break;

                        var mappingRule = item.Rule.Rule;
                        var ds = item.Rule.Sheet;

                        if (mappingRule == null || ds == null)
                        {
                            if (!string.IsNullOrWhiteSpace(item.Rule.Status))
                                addGErr.Add(new GlobalError() { Description = item.Rule.Status });
                            item.Progress.Value = 100;
                            continue;
                        }
                        else
                        {
                            if (ds.MainHeader == null)
                            {
                                Log.Add(string.Format("should update main header row..."));

                                ds.UpdateMainHeaderRow(mappingRule.MainHeaderSearchTags
                                        .Select(h => h.Tag)
                                        .Union(SettingsProvider.CurrentSettings.HeaderSearchTags.Split(new char[] { ',' }))
                                        .Select(i => i.Trim())
                                        .Where(i => !string.IsNullOrEmpty(i))
                                        .Distinct()
                                        .ToArray());

                                ds.UpdateHeaders(mappingRule.SheetHeadersSearchTags
                                        .Select(h => h.Tag.Trim())
                                        .Where(i => !string.IsNullOrEmpty(i))
                                        .Distinct()
                                        .ToArray());
                            }

                            var oc = new ObservableCollection<OutputRow>(mappingRule.Convert(ds,
                                progressAction: (i) =>
                                {
                                    item.Progress.Value = i;
                                    ((BackgroundWorker)s).ReportProgress((int)progress.Value);
                                },
                                isCanceled: () => { return ((BackgroundWorker)s).CancellationPending; },
                                additionalErrorAction: (e, r) =>
                                {
                                    addErr.Add(new Error() { Description = e.GetExceptionText(includeStackTrace: false, clearText: true).Trim(), RowNumber = r });
                                }));
                            Log.Add(string.Format("row count on sheet '{0}' : '{1}'", ds.Name, oc.Count));
                            rowsToExport = new ObservableCollection<OutputRow>(rowsToExport.Union(oc));
                            Log.Add(string.Format("subtotal row count on sheets: '{0}'", rowsToExport.Count));
                        }
                    }

                    ExelConvertionRule.RemoveRepeatingId(rowsToExport.ToList());

                    var UrlsPhoto = new UrlCollection();
                    var UrlsSchema = new UrlCollection();
                    var UrlsAll = new UrlCollection();

                    var photos = rowsToExport.Select(r => r.Photo_img).Where(r => Helper.IsWellFormedUriString(r, UriKind.Absolute)).Distinct();
                    var schemas = rowsToExport.Select(r => r.Location_img).Where(r => Helper.IsWellFormedUriString(r, UriKind.Absolute)).Distinct();
                    var all = photos.Union(schemas).Distinct();

                    foreach (var p in photos)
                        UrlsPhoto.Add(new StringUrlWithResultWrapper(p));
                    foreach (var p in schemas)
                        UrlsSchema.Add(new StringUrlWithResultWrapper(p));
                    foreach (var p in all)
                        UrlsAll.Add(new StringUrlWithResultWrapper(p));

                    if (!((BackgroundWorker)s).CancellationPending && s == loadWorker)
                        Disp.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(() =>
                        {
                            UrlCollection.Clear();
                            if (UrlsPhoto.Count > 0)
                                UrlCollection.Add(new UrlCollectionAdditional() { Name = DBParsers.Labels.ElementAt(0), Collection = UrlsPhoto });
                            if (UrlsSchema.Count > 0)
                                UrlCollection.Add(new UrlCollectionAdditional() { Name = DBParsers.Labels.ElementAt(1), Collection = UrlsSchema });
                            if (UrlsPhoto.Count > 0 && UrlsSchema.Count > 0 && UrlsAll.Count > 0)
                                UrlCollection.Add(new UrlCollectionAdditional() { Name = "Все", Collection = UrlsAll });
                            UrlCollectionSelectedIndex = UrlCollection.Count - 1;
                            RowsToExport = rowsToExport;
                            UpdateErrors(addErr, addGErr);
                        }));
                    else
                        prm.Cancel = true;
                }
                catch (Exception ex)
                {
                    Helpers.Old.Log.Add(logSession, ex.GetExceptionText());
                    throw ex;
                }
                finally
                {
                    Log.Add(string.Format("total row count to export: '{0}'", rowsToExport.Count));
                    Helpers.Old.Log.SessionEnd(logSession);
                }
            };

            loadWorker.ProgressChanged += (s, e) =>
            {
                if (s == loadWorker)
                    LoadProgress = e.ProgressPercentage;
            };

            loadWorker.RunWorkerCompleted += (s, e) =>
            {
                if (s == loadWorker)
                try
                {
                    if (e.Cancelled)
                        throw new Exception("Загрузка отменена пользователем");
                    if (e.Error != null)
                        throw e.Error;
                }
                catch (Exception ex)
                {
                    InitializeError = ex.GetExceptionText();
                }
                finally
                {
                    if (s == loadWorker)
                    {
                        IsLoading = false;
                        loadWorker = null;
                    }
                }
                ((BackgroundWorker)s).Dispose();
            };

            LoadProgress = 0;
            IsLoading = true;
            CancelCommand.RaiseCanExecuteChanged();
            loadWorker.RunWorkerAsync(System.Windows.Threading.Dispatcher.CurrentDispatcher);
        }
 /// <summary>
 /// 将分组IList的增量部分合并到一个IList中
 /// </summary>
 /// <returns>IList</returns>
 private UrlCollection GetMergedList()
 {
     UrlCollection urls = new UrlCollection();
     for (int i = 0; i < this.lists.Length; i++)
     {
         for (int n = this.listInitItems[i]; n < this.lists[i].Count; n++)
         {
             urls.Add(this.lists[i][n].Value);
         }
     }
     return urls;
 }
Example #16
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/xml";

            UrlCollection urlCollection = new UrlCollection();

            // Let's add home page
            Url homePage = new Url(Config.CurrentBlog.HomeFullyQualifiedUrl, DateTime.Now, ChangeFrequency.Daily, 1.0M);
            urlCollection.Add(homePage);

            // then all the entries
            IList<Entry> posts = Entries.GetRecentPosts(0, PostType.BlogPost, PostConfig.IsActive, false);
            if (posts != null)
            {
                foreach (Entry post in posts)
                {
                    ChangeFrequency frequency = CalculateFrequency(post);
                    urlCollection.Add(
                        new Url(post.FullyQualifiedUrl, post.DateModified,
                                frequency, 0.8M));
                }
            }

            // all articles
            IList<Entry> stories = Entries.GetRecentPosts(0, PostType.Story, PostConfig.IsActive, false);
            if (stories != null)
            {
                foreach (Entry story in stories)
                {
                    ChangeFrequency frequency = CalculateFrequency(story);
                    urlCollection.Add(
                        new Url(story.FullyQualifiedUrl, story.DateModified,
                                frequency, 0.8M));
                }
            }

            // categories
            LinkCategory categories = Transformer.BuildLinks("", CategoryType.PostCollection, new UrlFormats(Config.CurrentBlog.RootUrl));
            if (categories != null)
            {
                foreach (Link category in categories.Links)
                {
                    urlCollection.Add(
                        new Url(new Uri("http://" + Config.CurrentBlog.Host + category.Url), DateTime.Today,
                                ChangeFrequency.Weekly, 0.6M));
                }
            }

            // archives
            // categories
            LinkCategory archives = Transformer.BuildMonthLinks("",new UrlFormats(Config.CurrentBlog.RootUrl));
            if (archives != null)
            {
                foreach (Link archive in archives.Links)
                {
                    urlCollection.Add(
                        new Url(
                            new Uri("http://" + Config.CurrentBlog.Host + archive.Url), DateTime.Today, ChangeFrequency.Weekly, 0.6M));
                }
            }

            // don't index contact form
            urlCollection.Add(new Url(new Uri(string.Format(System.Globalization.CultureInfo.InvariantCulture, "{0}contact.aspx", Config.CurrentBlog.HostFullyQualifiedUrl)), DateTime.Today, ChangeFrequency.Never, 0.0M));
            XmlSerializer serializer = new XmlSerializer(typeof(UrlCollection));
            XmlTextWriter xmlTextWriter = new XmlTextWriter(context.Response.OutputStream, Encoding.UTF8);
            serializer.Serialize(xmlTextWriter, urlCollection);
        }