public override void Execute(CommandContext context) { Assert.ArgumentNotNull(context, "context"); if (context.Items.Length == 1) { Item currentItem = context.Items[0]; LanguageCollection languages = LanguageManager.GetLanguages(currentItem.Database); SheerResponse.DisableOutput(); Menu menu = new Menu(); foreach (Language language in languages) { Item item = currentItem.Database.GetItem(currentItem.ID, language); if (item != null && item.Versions.GetVersionNumbers(false).Length == 0) { continue; } string id = "L" + ShortID.NewId(); string languageName = GetLanguageName(language.CultureInfo); string icon = LanguageService.GetIcon(language, currentItem.Database); string click = string.Format("item:addversionrecursive(id={0},sourceLang={1},targetLang={2})", currentItem.ID, language, currentItem.Language); menu.Add(id, languageName, icon, string.Empty, click, false, string.Empty, MenuItemType.Normal); } SheerResponse.EnableOutput(); SheerResponse.ShowPopup("CopyFromLanguageButton", "below", menu); } }
private void Crawl(IndexUpdateContext context) { if (_isrunning) { _logger.InfoFormat("Crawler is already running, aborting"); return; } lock (_runninglock) { if (_isrunning) { _logger.InfoFormat("Crawler is already running, aborting"); return; } _isrunning = true; var dir = _directoryHelper.GetDirectoryName(_index); _cancelled = false; try { _directoryHelper.CreateDirectoryBackup(dir); GetIndexWriter(context).DeleteDocuments(new Term(BuiltinFields.Tags, ValueOrEmpty(Tags))); var runningContextId = ShortID.NewId(); var urls = GetTransformedUrls().ToList(); if (_logger != null) { urls.ForEach(url => _logger.InfoFormat("Starting url: {0}", url)); } var documentProcessor = (_logger != null && _logger.IsDebugEnabled) ? new LogHtmlDocumentProcessor(_logger, _indexFilters, _followFilters) : new HtmlDocumentProcessor(_indexFilters, _followFilters); using (var c = new UpdateContextAwareCrawler(context, runningContextId, urls, new LogLoggerBridge(_logger), documentProcessor, this)) { if (_logger != null) { _logger.Info(String.Format("Crawler started: Using {0} threads", MaximumThreadCount)); } c.AdhereToRobotRules = AdhereToRobotRules; c.MaximumThreadCount = MaximumThreadCount; c.UriSensitivity = UriSensitivity; if (MaximumCrawlDepth > 0) { c.MaximumCrawlDepth = MaximumCrawlDepth; } if (MaximumDocuments > 0) { c.MaximumCrawlCount = MaximumDocuments; } if (MaximumCrawlTime.TotalMinutes > 0) { c.MaximumCrawlTime = MaximumCrawlTime; } c.UseCookies = UseCookies; c.ExcludeFilter = new[] { new RegexFilter(new Regex(RegexExcludeFilter)) }; c.AfterDownload += CrawlerAfterDownload; c.PipelineException += CrawlerPipelineException; c.DownloadException += CrawlerDownloadException; c.Cancelled += CrawlerCancelled; Event.RaiseEvent("SiteCrawler:Started", new CrawlStartedEventArgs(c)); c.Crawl(); Event.RaiseEvent("SiteCrawler:Finished", new CrawlFinishedEventArgs(c)); } } catch (Exception crawlException) { if (_logger != null) { _logger.Error(GetExceptionLog(crawlException).ToString()); } if (_directoryHelper.RestoreDirectoryBackup(dir)) { _cancelled = false; } } finally { if (_logger != null) { _logger.Info("Crawler finished"); } _isrunning = false; if (!_cancelled) { _directoryHelper.DeleteBackupDirectory(dir); } } } }