本文整理汇总了C#中ParameterCollection.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# ParameterCollection.Clear方法的具体用法?C# ParameterCollection.Clear怎么用?C# ParameterCollection.Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ParameterCollection
的用法示例。
在下文中一共展示了ParameterCollection.Clear方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddNavigationTemplate
internal void AddNavigationTemplate(Wiki wiki)
{
ParameterCollection parameters = new ParameterCollection();
parameters.Add("list", "embeddedin");
parameters.Add("eititle", "Template:ВПКОБ-Навигация");
parameters.Add("eilimit", "max");
parameters.Add("einamespace", "4");
parameters.Add("eifilterredir", "nonredirects");
XmlDocument doc = wiki.Enumerate(parameters, true);
List<string> titles = new List<string>();
DateTime end = DateTime.Today;
DateTime start = end.AddDays(-7);
while (start <= end)
{
string pageDate = start.ToString("d MMMM yyyy",
CultureInfo.CreateSpecificCulture("ru-RU"));
string prefix = "Википедия:К объединению/";
string pageName = prefix + pageDate;
if (doc.SelectSingleNode("//ei[@title='" + pageName + "']") == null)
{
titles.Add(pageName);
}
start = start.AddDays(1);
}
parameters.Clear();
parameters.Add("prop", "info");
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, titles);
foreach (XmlNode node in xml.SelectNodes("//page"))
{
if (node.Attributes["missing"] == null)
{
Console.Out.WriteLine("Updating " + node.Attributes["title"].Value + "...");
wiki.Prepend(node.Attributes["title"].Value,
"{{ВПКОБ-Навигация}}\n",
"добавление навигационного шаблона");
}
}
}
示例2: UpdatePages
//.........这里部分代码省略.........
WikiPageSection verdict = new WikiPageSection(" Автоматический итог ",
subsection.Level + 1,
message);
subsection.AddSubsection(verdict);
StrikeOutSection(subsection);
++results;
}
}
}
}
Match matchClosed = closedRE.Match(text);
if (matchClosed.Success)
{
List<TalkResult> talkResults = new List<TalkResult>();
foreach (string name in titlesWithResults)
{
if (wiki.PageNamespace(name) > 0)
{
continue;
}
string movedTo;
string movedBy;
DateTime movedAt;
bool moved = MovedTo(wiki,
name,
day.Date,
out movedTo,
out movedBy,
out movedAt);
talkResults.Add(new TalkResult(name, movedTo, moved));
}
parameters.Clear();
parameters.Add("prop", "info");
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, talkResults.ConvertAll(r => r.Moved ? r.MovedTo : r.Title));
List<string> notificationList = new List<string>();
foreach (XmlNode node in xml.SelectNodes("//page"))
{
if (node.Attributes["missing"] == null && node.Attributes["ns"].Value == "0")
{
notificationList.Add(node.Attributes["title"].Value);
}
}
if (notificationList.Count > 0)
{
parameters.Clear();
parameters.Add("list", "backlinks");
parameters.Add("bltitle", pageName);
parameters.Add("blfilterredir", "nonredirects");
parameters.Add("blnamespace", "1");
parameters.Add("bllimit", "max");
XmlDocument backlinks = wiki.Enumerate(parameters, true);
foreach (string title in notificationList)
{
if (backlinks.SelectSingleNode("//bl[@title=\"Обсуждение:" + title + "\"]") == null)
{
TalkResult tr = talkResults.Find(r => r.Moved ? r.MovedTo == title : r.Title == title);
PutNotification(wiki, tr, day.Date);
}
}
}
}
string newText = day.Page.Text;
if (newText.Trim() == text.Trim())
{
continue;
}
try
{
Console.Out.WriteLine("Updating " + pageName + "...");
string revid = wiki.Save(pageName,
"",
newText,
"зачёркивание заголовков" + (results > 0 ? ", сообщение об итогах" : ""),
MinorFlags.Minor,
CreateFlags.NoCreate,
WatchFlags.None,
SaveFlags.Replace,
true,
basetimestamp,
"",
editToken);
using (FileStream fs = new FileStream(fileName, FileMode.Create))
using (GZipStream gs = new GZipStream(fs, CompressionMode.Compress))
using (StreamWriter sw = new StreamWriter(gs))
{
sw.WriteLine(revid);
sw.Write(newText);
}
}
catch (WikiException)
{
}
}
}
示例3: UpdateArchivePages
public void UpdateArchivePages(Wiki wiki)
{
ParameterCollection parameters = new ParameterCollection();
parameters.Add("generator", "categorymembers");
parameters.Add("gcmtitle", "Категория:Википедия:Незакрытые обсуждения объединения страниц");
parameters.Add("gcmlimit", "max");
parameters.Add("gcmnamespace", "4");
parameters.Add("prop", "info");
XmlDocument doc = wiki.Enumerate(parameters, true);
XmlNodeList pages = doc.SelectNodes("//page");
DateTime minDate = DateTime.Now;
foreach (XmlNode page in pages)
{
string pageName = page.Attributes["title"].Value;
string date = pageName.Substring("Википедия:К объединению/".Length);
try
{
DateTime day = DateTime.Parse(date,
CultureInfo.CreateSpecificCulture("ru-RU"),
DateTimeStyles.AssumeUniversal);
if (day < minDate)
{
minDate = day;
}
}
catch (FormatException)
{
continue;
}
}
List<string> titles = new List<string>();
minDate = new DateTime(minDate.Year, minDate.Month, 1);
DateTime currentMonth = new DateTime(DateTime.Today.Year,
DateTime.Today.Month, 1);
DateTime start = minDate;
while (start <= currentMonth)
{
string date = start.ToString("yyyy-MM");
string pageName = "Википедия:Архив запросов на объединение/" + date;
titles.Add(pageName);
start = start.AddMonths(1);
}
parameters.Clear();
parameters.Add("prop", "info");
XmlDocument archivesDoc = wiki.Query(QueryBy.Titles, parameters, titles);
pages = archivesDoc.SelectNodes("//page");
foreach (XmlNode archivePage in pages)
{
string archiveName = archivePage.Attributes["title"].Value;
string date = archiveName.Substring("Википедия:Архив запросов на объединение/".Length);
DateTime archiveDate;
try
{
archiveDate = DateTime.Parse(date,
CultureInfo.CreateSpecificCulture("ru-RU"),
DateTimeStyles.AssumeUniversal);
}
catch (FormatException)
{
continue;
}
string fileName = _cacheDir + "Archive-" + date + ".txt";
start = archiveDate;
DateTime end = start.AddMonths(1);
titles.Clear();
while (start < end)
{
string pageDate = start.ToString("d MMMM yyyy",
CultureInfo.CreateSpecificCulture("ru-RU"));
string prefix = "Википедия:К объединению/";
string pageName = prefix + pageDate;
titles.Add(pageName);
start = start.AddDays(1);
}
parameters.Clear();
parameters.Add("prop", "info");
List<Day> days = new List<Day>();
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, titles);
XmlNodeList archives = xml.SelectNodes("//page");
foreach (XmlNode page in archives)
{
string pageName = page.Attributes["title"].Value;
string dateString = pageName.Substring("Википедия:К объединению/".Length);
string pageFileName = _cacheDir + dateString + ".bin";
Day day = new Day();
day.Archived = doc.SelectSingleNode("//page[@title=\"" + pageName + "\"]") == null;
try
{
day.Date = DateTime.Parse(dateString,
CultureInfo.CreateSpecificCulture("ru-RU"),
//.........这里部分代码省略.........
示例4: Analyse
//.........这里部分代码省略.........
title = _l10i.Processor(section).Trim();
}
else
{
title = section.Title.Trim();
}
titles.Add(title + result);
}
sw.Write(string.Join(" • ", titles.ConvertAll(c => c).ToArray()));
sw.Write("}}\n\n");
}
sw.WriteLine("{{" + _l10i.BottomTemplate + "}}");
}
List<string> dates = new List<string>();
DateTime today = DateTime.Today;
DateTime currentMonth = new DateTime(today.Year, today.Month, 1);
for (int i = 0; i < 2; ++i)
{
DateTime start = currentMonth.AddMonths(-i);
DateTime end = start.AddMonths(1);
while (start < end)
{
string date = start.ToString("d MMMM yyyy",
CultureInfo.CreateSpecificCulture(_l10i.Culture));
string prefix = _l10i.MainPage + "/";
string pageName = prefix + date;
dates.Add(pageName);
start = start.AddDays(1);
}
}
parameters.Clear();
parameters.Add("prop", "info");
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, dates);
days.Clear();
foreach (string pageName in dates)
{
string prefix = _l10i.MainPage + "/";
string date = pageName.Substring(prefix.Length);
string fileName = _cacheDir + date + ".bin";
bool archived = doc.SelectSingleNode("//page[@title=\"" + pageName + "\"]") == null;
XmlNode page = xml.SelectSingleNode("//page[@title=\"" + pageName + "\"]");
Day day = new Day();
day.Archived = archived;
if (!DateTime.TryParse(date, CultureInfo.CreateSpecificCulture(_l10i.Culture),
DateTimeStyles.AssumeUniversal, out day.Date))
{
continue;
}
if (page.Attributes["missing"] != null)
{
day.Exists = false;
days.Add(day);
continue;
}
string text = "";
if (File.Exists(fileName))
{
using (FileStream fs = new FileStream(fileName, FileMode.Open))
using (GZipStream gs = new GZipStream(fs, CompressionMode.Decompress))
using (TextReader sr = new StreamReader(gs))
示例5: Process
public override Dictionary<string, string> Process(Wiki wiki, WikiPage page, ref int diffSize, ref int topicsArchived)
{
List<WikiPageSection> archivedSections = new List<WikiPageSection>();
foreach (WikiPageSection section in page.Sections)
{
WikiPageSection result = section.Subsections.FirstOrDefault(ss => ss.Title.Trim().ToLower() == "итог");
bool forceArchivation = LookForLines.Any(s => section.Text.ToLower().Contains(s.ToLower()));
if (!OnHold.Any(s => section.Text.ToLower().Contains(s.ToLower())) &&
((result != null && !string.IsNullOrEmpty(result.SectionText.Trim())) ||
forceArchivation ||
!CheckForResult))
{
MatchCollection ms = timeRE.Matches(FilterQuotes(section.Text));
DateTime published = DateTime.Today;
DateTime lastReply = DateTime.MinValue;
foreach (Match match in ms)
{
string value = match.Groups[1].Value;
DateTime time = DateTime.Parse(value, L10i.Culture,
DateTimeStyles.AssumeUniversal);
if (time < published)
{
published = time;
}
if (time > lastReply)
{
lastReply = time;
}
}
if (lastReply != DateTime.MinValue &&
((forceArchivation && (DateTime.Today - lastReply).TotalHours >= ForcedArchivationDelay) ||
(DateTime.Today - lastReply).TotalHours >= Delay))
{
archivedSections.Add(section);
}
}
if (IsMovedSection(section))
{
section.SectionText = section.SectionText.Trim(new char[] { ' ', '\t', '\n' }) + "\n~~~~\n";
archivedSections.Add(section);
}
}
Dictionary<string, string> archiveTexts = new Dictionary<string, string>();
if (archivedSections.Count == 0)
{
diffSize = 0;
return archiveTexts;
}
var parameters = new ParameterCollection()
{
{ "prop", "info" },
};
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, MainPage);
int ns = int.Parse(xml.SelectSingleNode("//page").Attributes["ns"].Value);
string prefix = wiki.GetNamespace(ns) + ":";
parameters = new ParameterCollection()
{
{ "list", "allpages" },
{ "apprefix", MainPage.Substring(prefix.Length) },
{ "apnamespace", ns.ToString() }
};
xml = wiki.Enumerate(parameters, true);
int maxNumber = 1;
foreach (XmlNode p in xml.SelectNodes("//p"))
{
string title = p.Attributes["title"].Value;
string format = Format.Replace("{0}", "");
if (title.StartsWith(format))
{
int number;
if (int.TryParse(title.Substring(format.Length), out number))
{
if (number > maxNumber)
{
maxNumber = number;
}
}
}
}
int index = 0;
string pageName = string.Format(Format, maxNumber);
parameters.Clear();
parameters.Add("prop", "info");
xml = wiki.Query(QueryBy.Titles, parameters, new string[] { pageName });
XmlNode node = xml.SelectSingleNode("//page");
if (node.Attributes["missing"] == null)
{
string pageFileName = _cacheDir + Cache.GenerateCachePath(pageName);
string text = Cache.LoadPageFromCache(pageFileName,
node.Attributes["lastrevid"].Value, pageName);
if (string.IsNullOrEmpty(text))
{
Console.Out.WriteLine("Downloading " + pageName + "...");
text = wiki.LoadText(pageName);
Cache.CachePage(pageName, _cacheDir, node.Attributes["lastrevid"].Value, text);
//.........这里部分代码省略.........
示例6: Run
public void Run(Wiki wiki)
{
Directory.CreateDirectory(_cacheDir);
Console.Out.WriteLine("Updating " + _page);
Regex wikiLinkRE = new Regex(@"\[{2}(.+?)(\|.+?)?]{2}");
Regex timeRE = new Regex(@"(\d{2}:\d{2}\, \d\d? [а-я]+ \d{4}) \(UTC\)");
ParameterCollection parameters = new ParameterCollection();
parameters.Add("prop", "info|revisions");
parameters.Add("intoken", "edit");
XmlDocument doc = wiki.Query(QueryBy.Titles, parameters, _page);
XmlNode page = doc.SelectSingleNode("//page");
string queryTimestamp = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
string pageName = page.Attributes["title"].Value;
string basetimestamp = page.FirstChild.FirstChild.Attributes["timestamp"].Value;
string editToken = page.Attributes["edittoken"].Value;
string starttimestamp = queryTimestamp;
string text = "";
string fileName = _cacheDir + WikiCache.EscapePath(_page);
if (File.Exists(fileName))
{
using (FileStream fs = new FileStream(fileName, FileMode.Open))
using (GZipStream gs = new GZipStream(fs, CompressionMode.Decompress))
using (TextReader sr = new StreamReader(gs))
{
string revid = sr.ReadLine();
if (revid == page.Attributes["lastrevid"].Value)
{
Console.Out.WriteLine("Loading " + pageName + "...");
text = sr.ReadToEnd();
}
}
}
if (string.IsNullOrEmpty(text))
{
Console.Out.WriteLine("Downloading " + pageName + "...");
text = wiki.LoadText(pageName);
starttimestamp = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ");
using (FileStream fs = new FileStream(fileName, FileMode.Create))
using (GZipStream gs = new GZipStream(fs, CompressionMode.Compress))
using (StreamWriter sw = new StreamWriter(gs))
{
sw.WriteLine(page.Attributes["lastrevid"].Value);
sw.Write(text);
}
}
Dictionary<string, List<WikiPageSection>> titles = new Dictionary<string, List<WikiPageSection>>();
WikiPage wikiPage = WikiPage.Parse(pageName, text);
foreach (WikiPageSection section in wikiPage.Sections)
{
if (section.Subsections.Count(s => s.Title.ToLower(CultureInfo.CreateSpecificCulture("ru-RU")).Trim() == "итог") == 0)
{
Match m = wikiLinkRE.Match(section.Title);
if (m.Success)
{
string title = m.Groups[1].Value.Trim();
if (titles.ContainsKey(title))
{
titles[title].Add(section);
}
else
{
titles.Add(title, new List<WikiPageSection>());
titles[title].Add(section);
}
}
}
}
parameters.Clear();
parameters.Add("prop", "info");
Dictionary<string, string> normalizedTitles = new Dictionary<string, string>();
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, titles.Keys);
foreach (XmlNode node in xml.SelectNodes("//n"))
{
normalizedTitles.Add(node.Attributes["to"].Value,
node.Attributes["from"].Value);
}
List<string> notificationList = new List<string>();
XmlNodeList missingTitles = xml.SelectNodes("//page");
foreach (XmlNode node in missingTitles)
{
string title = node.Attributes["title"].Value;
IEnumerable<WikiPageSection> sections;
if (titles.ContainsKey(title))
{
sections = titles[title];
}
else
{
sections = titles[normalizedTitles[title]];
}
if (node.Attributes["missing"] != null)
{
//.........这里部分代码省略.........
示例7: UpdatePages
//.........这里部分代码省略.........
}
List<WikiPageSection> sections = new List<WikiPageSection>();
section.Reduce(sections, SubsectionsList);
foreach (WikiPageSection subsection in sections)
{
m = wikiLinkRE.Match(subsection.Title);
if (m.Success && subsection.Title.Contains("<s>"))
{
titlesWithResults.Add(m.Groups[1].Value.Trim());
}
if (m.Success &&
!subsection.Title.Contains("<s>") &&
subsection.Subsections.Count(s => s.Title.Trim() == _l10i.ChallengedResult) == 0 &&
subsection.Subsections.Count(s => _l10i.Processor != null
? _l10i.Results.Any(r => r == _l10i.Processor(s).Trim())
: _l10i.Results.Any(r => r == s.Title.Trim())) == 0)
{
string title = m.Groups[1].Value.Trim();
if (titles.ContainsKey(title))
{
titles[title].Add(subsection);
}
else
{
titles.Add(title, new List<WikiPageSection>());
titles[title].Add(subsection);
}
}
}
}
}
parameters.Clear();
parameters.Add("prop", "info");
Dictionary<string, string> normalizedTitles = new Dictionary<string, string>();
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, titles.Keys);
foreach (XmlNode node in xml.SelectNodes("//n"))
{
normalizedTitles.Add(node.Attributes["to"].Value,
node.Attributes["from"].Value);
}
List<string> notificationList = new List<string>();
XmlNodeList missingTitles = xml.SelectNodes("//page");
foreach (XmlNode node in missingTitles)
{
string title = node.Attributes["title"].Value;
IEnumerable<WikiPageSection> sections;
if (titles.ContainsKey(title))
{
sections = titles[title];
}
else
{
sections = titles[normalizedTitles[title]];
}
if (node.Attributes["missing"] != null)
{
DateTime start = day.Date;
//foreach (WikiPageSection section in sections)
//{
// Match m = timeRE.Match(section.Text);
// if (m.Success)
// {
// start = DateTime.Parse(m.Groups[1].Value,
示例8: UpdatePages
//.........这里部分代码省略.........
else
{
titles.Add(title, new List<WikiPageSection>());
titles[title].Add(section);
}
}
}
{
List<WikiPageSection> sections = new List<WikiPageSection>();
section.Reduce(sections, SubsectionsList);
foreach (WikiPageSection subsection in sections)
{
Match m = _wikiLinkRE.Match(subsection.Title);
if (m.Success &&
!subsection.Title.Contains("<s>") &&
subsection.Subsections.Count(s => _results.Any(r => r.ToLower() == s.Title.Trim().ToLower())) == 0)
{
string title = m.Groups[1].Value.Trim();
if (titles.ContainsKey(title))
{
titles[title].Add(subsection);
}
else
{
titles.Add(title, new List<WikiPageSection>());
titles[title].Add(subsection);
}
}
}
}
}
parameters.Clear();
parameters.Add("prop", "info");
Dictionary<string, string> normalizedTitles = new Dictionary<string, string>();
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, titles.Keys);
foreach (XmlNode node in xml.SelectNodes("//n"))
{
normalizedTitles.Add(node.Attributes["to"].Value,
node.Attributes["from"].Value);
}
List<string> notificationList = new List<string>();
XmlNodeList missingTitles = xml.SelectNodes("//page");
foreach (XmlNode node in missingTitles)
{
string title = node.Attributes["title"].Value;
IEnumerable<WikiPageSection> sections;
if (titles.ContainsKey(title))
{
sections = titles[title];
}
else
{
sections = titles[normalizedTitles[title]];
}
if (node.Attributes["missing"] == null)
{
DateTime start = day.Date;
parameters.Clear();
parameters.Add("list", "logevents");
parameters.Add("letype", "delete");
parameters.Add("lemlimit", "max");
parameters.Add("lestart", start.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"));
parameters.Add("ledir", "newer");
示例9: Analyze
//.........这里部分代码省略.........
Regex wikiLinkRE = new Regex(@"\[{2}(.+?)(\|.+?)?]{2}");
List<string> sectionTitles = new List<string>();
foreach (Day day in days)
{
foreach (WikiPageSection section in day.Page.Sections)
{
RemoveStrikeOut(section);
StrikeOutSection(section);
if (section.Title.Contains("<s>"))
{
Match m = wikiLinkRE.Match(section.Title);
if (m.Success)
{
sectionTitles.Add(m.Groups[1].Value);
}
}
List<WikiPageSection> sections = new List<WikiPageSection>();
section.Reduce(sections, SubsectionsList);
foreach (WikiPageSection subsection in sections)
{
if (subsection.Title.Contains("<s>"))
{
Match m = wikiLinkRE.Match(subsection.Title);
if (m.Success)
{
sectionTitles.Add(m.Groups[1].Value);
}
}
}
}
}
parameters.Clear();
parameters.Add("prop", "info");
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, sectionTitles);
using (StreamWriter sw =
new StreamWriter(_cacheDir + "MainPage.txt"))
{
sw.WriteLine("== Текущие обсуждения ==\n");
sw.WriteLine("{{Восстановление статей/Статьи, вынесенные на обсуждение восстановления}}\n");
foreach (Day day in days)
{
sw.Write("{{Восстановление статей/День|" + day.Date.ToString("yyyy-M-d") + "|\n");
List<string> titles = new List<string>();
foreach (WikiPageSection section in day.Page.Sections)
{
string result = "";
string filler = "";
RemoveStrikeOut(section);
StrikeOutSection(section);
if (section.Title.Contains("<s>"))
{
Match m = wikiLinkRE.Match(section.Title);
if (m.Success)
{
string link = m.Groups[1].Value;
XmlNode node = xml.SelectSingleNode("//page[@title='" + link.Replace("'", @"'") + "']");
if (node != null)
{
if (node.Attributes["missing"] == null)
{
示例10: AddNavigationTemplate
internal void AddNavigationTemplate(Wiki wiki)
{
ParameterCollection parameters = new ParameterCollection();
parameters.Add("list", "embeddedin");
parameters.Add("eititle", "Template:" + _l10i.NavigationTemplate);
parameters.Add("eilimit", "max");
parameters.Add("einamespace", "4");
parameters.Add("eifilterredir", "nonredirects");
XmlDocument doc = wiki.Enumerate(parameters, true);
List<string> titles = new List<string>();
DateTime end = DateTime.Today;
DateTime start = end.AddDays(-7);
while (start <= end)
{
string pageDate = start.ToString("d MMMM yyyy", _l10i.Culture);
string prefix = _l10i.MainPage + "/";
string pageName = prefix + pageDate;
if (doc.SelectSingleNode("//ei[@title='" + pageName + "']") == null)
{
titles.Add(pageName);
}
start = start.AddDays(1);
}
parameters.Clear();
parameters.Add("prop", "info");
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, titles);
foreach (XmlNode node in xml.SelectNodes("//page"))
{
if (node.Attributes["missing"] == null)
{
Console.Out.WriteLine("Updating " + node.Attributes["title"].Value + "...");
wiki.Prepend(node.Attributes["title"].Value,
"{{" + _l10i.NavigationTemplate + "}}\n",
_l10i.MainPageUpdateComment);
}
}
}
示例11: UpdateArchivePages
public void UpdateArchivePages(Wiki wiki)
{
ParameterCollection parameters = new ParameterCollection();
parameters.Add("generator", "categorymembers");
parameters.Add("gcmtitle", _l10i.Category);
parameters.Add("gcmlimit", "max");
parameters.Add("gcmnamespace", "4");
parameters.Add("prop", "info");
XmlDocument doc = wiki.Enumerate(parameters, true);
XmlNodeList pages = doc.SelectNodes("//page");
DateTime minDate = DateTime.Now;
foreach (XmlNode page in pages)
{
string prefix = _l10i.MainPage + "/";
string pageName = page.Attributes["title"].Value;
string date = pageName.Substring(prefix.Length);
DateTime day;
if (DateTime.TryParse(date,
_l10i.Culture,
DateTimeStyles.AssumeUniversal, out day))
{
if (day < minDate)
{
minDate = day;
}
}
else
{
continue;
}
}
List<string> titles = new List<string>();
minDate = new DateTime(minDate.Year, minDate.Month, 1);
DateTime currentMonth = new DateTime(DateTime.Today.Year,
DateTime.Today.Month, 1);
DateTime start = minDate;
while (start <= currentMonth)
{
string date = start.ToString("yyyy-MM");
string pageName = _l10i.ArchivePage + date;
titles.Add(pageName);
start = start.AddMonths(1);
}
parameters.Clear();
parameters.Add("prop", "info");
XmlDocument archivesDoc = wiki.Query(QueryBy.Titles, parameters, titles);
pages = archivesDoc.SelectNodes("//page");
foreach (XmlNode archivePage in pages)
{
string archiveName = archivePage.Attributes["title"].Value;
string date = archiveName.Substring(_l10i.ArchivePage.Length);
DateTime archiveDate;
if (!DateTime.TryParse(date,
_l10i.Culture,
DateTimeStyles.AssumeUniversal, out archiveDate))
{
continue;
}
string fileName = _cacheDir + "Archive-" + date + ".txt";
start = archiveDate;
DateTime end = start.AddMonths(1);
titles.Clear();
while (start < end)
{
string pageDate = start.ToString("d MMMM yyyy",
_l10i.Culture);
string prefix = _l10i.MainPage + "/";
string pageName = prefix + pageDate;
titles.Add(pageName);
start = start.AddDays(1);
}
parameters.Clear();
parameters.Add("prop", "info");
List<Day> days = new List<Day>();
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, titles);
XmlNodeList archives = xml.SelectNodes("//page");
foreach (XmlNode page in archives)
{
string prefix = _l10i.MainPage + "/";
string pageName = page.Attributes["title"].Value;
string dateString = pageName.Substring(prefix.Length);
string pageFileName = _cacheDir + dateString + ".bin";
Day day = new Day();
day.Archived = doc.SelectSingleNode("//page[@title=\"" + pageName + "\"]") == null;
if (!DateTime.TryParse(dateString,
_l10i.Culture,
DateTimeStyles.AssumeUniversal, out day.Date))
{
continue;
//.........这里部分代码省略.........
示例12: UpdateArchivePages
public void UpdateArchivePages(Wiki wiki)
{
ParameterCollection parameters = new ParameterCollection();
parameters.Add("generator", "categorymembers");
parameters.Add("gcmtitle", "Категория:Википедия:Незакрытые обсуждения категорий");
parameters.Add("gcmlimit", "max");
parameters.Add("gcmnamespace", "4");
parameters.Add("prop", "info");
XmlDocument doc = wiki.Enumerate(parameters, true);
XmlNodeList pages = doc.SelectNodes("//page");
DateTime minDate = DateTime.Now;
foreach (XmlNode page in pages)
{
string pageName = page.Attributes["title"].Value;
string date = pageName.Substring("Википедия:Обсуждение категорий/".Length);
DateTime day;
if (DateTime.TryParse(date,
CultureInfo.CreateSpecificCulture("ru-RU"),
DateTimeStyles.AssumeUniversal, out day))
{
if (day < minDate)
{
minDate = day;
}
}
else
{
continue;
}
}
List<string> titles = new List<string>();
minDate = new DateTime(minDate.Year, minDate.Month, 1);
DateTime currentMonth = new DateTime(DateTime.Today.Year,
DateTime.Today.Month, 1);
DateTime start = new DateTime(minDate.Year, 1, 1);
while (start <= currentMonth)
{
string date = start.ToString("yyyy");
string pageName = "Википедия:Обсуждение категорий/Архив/" + date;
titles.Add(pageName);
start = start.AddYears(1);
}
parameters.Clear();
parameters.Add("prop", "info");
XmlDocument archivesDoc = wiki.Query(QueryBy.Titles, parameters, titles);
pages = archivesDoc.SelectNodes("//page");
foreach (XmlNode archivePage in pages)
{
string archiveName = archivePage.Attributes["title"].Value;
string date = archiveName.Substring("Википедия:Обсуждение категорий/Архив/".Length);
int year;
if (!int.TryParse(date, out year))
{
continue;
}
DateTime archiveDate = new DateTime(year, 1, 1);
string fileName = _cacheDir + "Archive-" + date + ".txt";
start = archiveDate;
DateTime end = start.AddYears(1);
titles.Clear();
while (start < end)
{
string pageDate = start.ToString("MMMM yyyy",
CultureInfo.CreateSpecificCulture("ru-RU"));
string prefix = "Википедия:Обсуждение категорий/";
string pageName = prefix + pageDate;
titles.Add(pageName);
start = start.AddMonths(1);
}
parameters.Clear();
parameters.Add("prop", "info");
List<Day> days = new List<Day>();
XmlDocument xml = wiki.Query(QueryBy.Titles, parameters, titles);
XmlNodeList archives = xml.SelectNodes("//page");
foreach (XmlNode page in archives)
{
string pageName = page.Attributes["title"].Value;
string dateString = pageName.Substring("Википедия:Обсуждение категорий/".Length);
string pageFileName = _cacheDir + dateString + ".bin";
Day day = new Day();
if (!DateTime.TryParse(dateString,
CultureInfo.CreateSpecificCulture("ru-RU"),
DateTimeStyles.AssumeUniversal, out day.Date))
{
continue;
}
if (page.Attributes["missing"] != null)
{
//.........这里部分代码省略.........