本文整理汇总了C#中Page.Exists方法的典型用法代码示例。如果您正苦于以下问题:C# Page.Exists方法的具体用法?C# Page.Exists怎么用?C# Page.Exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Page
的用法示例。
在下文中一共展示了Page.Exists方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
/// The entry point function. Start coding here.
public static void Main()
{
// Compiled documentation is available in Documentation.chm file.
// A very compehensive DotNetWikiBot usage examples can be found
// in unit testing file called DebugBot.cs:
// http://sourceforge.net/p/dotnetwikibot/svn/HEAD/tree/DebugBot.cs
// Bot scripts repository is being created at
// https://sourceforge.net/apps/mediawiki/dotnetwikibot/index.php?title=BSR
// You are welcome to share your scripts.
// And here you can find some basic usage examples:
Site site = new Site("https://en.wikipedia.org", "YourBotLogin", "YourBotPassword");
//Site site = new Site("http://mywikisite.com", "YourBotLogin", "YourBotPassword");
//Site site = new Site("https://sourceforge.net/apps/mediawiki/YourProjectName/",
//"YourSourceForgeLogin", "YourSourceForgePassword");
site.ShowNamespaces();
Page p = new Page(site, "Wikipedia:Sandbox");
p.LoadWithMetadata();
if (p.Exists())
Console.WriteLine(p.text);
p.SaveToFile("MyArticles\\file.txt");
p.LoadFromFile("MyArticles\\file.txt");
p.ResolveRedirect();
Console.WriteLine(p.GetNamespace());
p.text = "new text";
site.defaultEditComment = "saving test";
site.minorEditByDefault = true;
p.Save();
/**
string[] arr = {"Art", "Poetry", "Cinematography", "Camera", "Image"};
PageList pl = new PageList(site, arr);
pl.LoadWithMetadata();
pl.FillFromAllPages("Sw", 0, true, 100);
pl.SaveTitlesToFile("MyArticles\\list.txt");
pl.FillFromFile("MyArticles\\list.txt");
pl.FillFromCategory("Category:Cinematography");
pl.FillFromLinksToPage("Cinematography");
pl.RemoveEmpty();
pl.RemoveDisambigs();
pl.ResolveRedirects();
Console.WriteLine(pl[2].text);
pl[1].text = "#REDIRECT [[Some Page]]";
pl.FilterNamespaces(new int[] {0,3});
pl.RemoveNamespaces(new int[] {2,4});
pl.Clear();
site.defaultEditComment = "my edit comment";
site.minorEditByDefault = true;
pl.Save();
/**/
}
示例2: UploadButtonClick
void UploadButtonClick( object sender, EventArgs ea )
{
if ( string.IsNullOrEmpty( siteTextBox.Text ) ||
string.IsNullOrEmpty( userNameTextBox.Text ) ||
string.IsNullOrEmpty( passwordTextBox.Text ) ||
string.IsNullOrEmpty( folderTextBox.Text ) ||
string.IsNullOrEmpty( filesDescrTextBox.Text ) )
{
MessageBox.Show( "Fill in all required data fileds, please." );
return;
}
this.Cursor = Cursors.WaitCursor;
if ( site == null )
{
try
{
site = new Site(
siteTextBox.Text.Trim(),
userNameTextBox.Text.Trim(),
passwordTextBox.Text.Trim(),
userDomainTextBox.Text.Trim()
);
}
catch ( Exception e )
{
this.Cursor = Cursors.Default;
MessageBox.Show( e.Message );
return;
}
}
if ( !Directory.Exists( folderTextBox.Text ) )
{
this.Cursor = Cursors.Default;
MessageBox.Show( "Specified folder doesn't exist." );
return;
}
Regex allowedFileTypes;
if ( !string.IsNullOrEmpty( fileTypesTextBox.Text ) )
{
allowedFileTypes = new Regex( String.Format( "(?i)\\.({0})$",
fileTypesTextBox.Text.Replace( " ", "" ).Replace( ",", "|" ) ) );
}
else
{
allowedFileTypes = new Regex( "." );
}
string[] filenames =
Array.FindAll( Directory.GetFiles( folderTextBox.Text ), allowedFileTypes.IsMatch );
if ( filenames.Length == 0 )
{
this.Cursor = Cursors.Default;
MessageBox.Show( "Specified folder doesn't contain files, that could be uploaded." );
return;
}
UploadProgressBar.Visible = true;
UploadProgressBar.Minimum = 0;
UploadProgressBar.Maximum = filenames.Length;
UploadProgressBar.Value = 0;
UploadProgressBar.Step = 1;
Page p = new Page( site );
string filename;
for ( int i = 0; i < filenames.Length; UploadProgressBar.PerformStep(), i++ )
{
filename = Path.GetFileName( filenames[i] );
p.title = site.namespaces["6"] + ":" + filename;
try
{
p.Load();
}
catch ( Exception e )
{
MessageBox.Show( e.Message );
continue;
}
if ( p.Exists() && MessageBox.Show(
String.Format( "File \"{0}\" already exists. Overwrite?", filename ),
"Вопрос",
MessageBoxButtons.YesNo,
MessageBoxIcon.Question ) != DialogResult.Yes )
{
continue;
}
try
{
p.UploadImage( filenames[i], filesDescrTextBox.Text, "", "", "" );
}
catch ( Exception e )
{
MessageBox.Show( e.Message );
continue;
}
File.AppendAllText("UploadedFiles.txt", filenames[i] + "\r\n");
}
//.........这里部分代码省略.........
示例3: GeneratePageUrl
internal IHtmlString GeneratePageUrl(string urlMapKey, object values, Func<Site, string, Page> findPage, out Page page)
{
//System.Diagnostics.Contracts.Contract.Requires(!string.IsNullOrEmpty(urlMapKey));
var site = this.Site;
page = null;
var urlKeyMap = Persistence.Providers.UrlKeyMapProvider.Get(new UrlKeyMap(site, urlMapKey));
if (urlKeyMap != null)
{
if (!string.IsNullOrEmpty(urlKeyMap.PageFullName))
{
page = new Page(site, PageHelper.SplitFullName(urlKeyMap.PageFullName).ToArray());
}
else
page = null;
}
if (page == null)
{
page = new Page(site, PageHelper.SplitFullName(urlMapKey).ToArray()).LastVersion();
if (page == null || !page.Exists())
{
page = findPage(site, urlMapKey);
string pageFullName = "";
if (page != null && page.Exists())
{
pageFullName = page.FullName;
}
if (urlKeyMap == null)
Services.ServiceFactory.UrlKeyMapManager.Add(site, new UrlKeyMap(site, urlMapKey) { PageFullName = pageFullName });
}
}
if (page != null && page.Exists())
{
var url = GeneratePageUrl(page, values);
return url;
}
else
{
return new HtmlString("");
}
}