本文整理汇总了C#中DotNetWikiBot.Page.UploadImage方法的典型用法代码示例。如果您正苦于以下问题:C# Page.UploadImage方法的具体用法?C# Page.UploadImage怎么用?C# Page.UploadImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DotNetWikiBot.Page
的用法示例。
在下文中一共展示了Page.UploadImage方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UploadOriginalVersion
private static bool UploadOriginalVersion(out string failureReason, Page page, string mediaUrl,
string wikiImageFilename, string picasaImageFilename,
bool fetchThumbnailVersion, bool allowWikiBigger)
{
// if (!wikiImageFilename.ToLower().EndsWith(".jpg") && !wikiImageFilename.ToLower().EndsWith(".jpeg") &&
// !wikiImageFilename.ToLower().EndsWith(".png"))
// {
// failureReason = "Cannot compare non-bitmap files to original source - requires manual validation";
// return false;
// }
failureReason = null;
Bitmap wikiBitmap = new Bitmap(wikiImageFilename);
// First have the Picasa server resize to the desired size - this will
// ensure exactly the same resizing algorithm is used.
string thumbnailUrl =
new Regex("^(.*)/([^/]*)$").Replace(mediaUrl, "${1}/s" + wikiBitmap.Width + "/${2}");
string filename = "temp_picasa_image";
if (!fetchThumbnailVersion || !WgetToFile(thumbnailUrl, filename))
{
filename = picasaImageFilename;
}
Bitmap picasaBitmap = new Bitmap(filename);
if (wikiBitmap.Width < picasaBitmap.Width ||
wikiBitmap.Height < picasaBitmap.Height)
{
// Couldn't get version of same size from server - stretch to fit
Bitmap newPicasaBitmap = new Bitmap(picasaBitmap, wikiBitmap.Width, wikiBitmap.Height);
picasaBitmap.Dispose();
picasaBitmap = newPicasaBitmap;
}
bool wikiBitmapIsBigger = false;
if (wikiBitmap.Width >= picasaBitmap.Width ||
wikiBitmap.Height >= picasaBitmap.Height)
{
if (allowWikiBigger)
{
wikiBitmapIsBigger = true;
Bitmap newWikiBitmap = new Bitmap(wikiBitmap, picasaBitmap.Width, picasaBitmap.Height);
wikiBitmap.Dispose();
wikiBitmap = newWikiBitmap;
}
else
{
// Wiki version is bigger, something odd going on, skip it
wikiBitmap.Dispose();
picasaBitmap.Dispose();
failureReason = "license matches and is valid - but Commons version is of a different size than the Picasa version, may have been edited locally";
return false;
}
}
double avgDiff = ImagesMeanSquareDifference(wikiBitmap, picasaBitmap);
wikiBitmap.Dispose();
picasaBitmap.Dispose();
if (avgDiff >= 0.032 && avgDiff < 0.10)
{
failureReason = "license matches and is valid - but Picasa and Commons image were not a close enough match";
return false;
}
else if (avgDiff < 0.032)
{
// Got an approximate match, need to upload the full-size version
// (unless we've done so before and were reverted)
PageList pageHistory = new PageList(page.site);
pageHistory.FillFromPageHistory(page.title, int.MaxValue);
bool alreadyUploaded = false;
foreach (Page revision in pageHistory)
{
if (revision.lastUser == username && revision.comment.Contains("uploaded a new version"))
{
alreadyUploaded = true;
}
}
if (!alreadyUploaded && !wikiBitmapIsBigger)
{
string saveText = page.text;
page.UploadImage(picasaImageFilename,
"Uploading version from source, revert me if incorrect",
"", "", "");
// Set back to current wikitext
page.Load();
page.text = saveText;
}
return true;
}
else
{
failureReason = "license matches and is valid - but Picasa and Commons image do not match";
return false;
}
}
示例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: UploadFile
private static bool UploadFile(string fileToUpload)
{
logger.Info("Logging into Wiki");
string siteurl = "http://commons.wikimedia.org";
//string siteurl = "http://vgsales.wikia.com";
//string siteurl = "http://w3stfa11.limewebs.com/wiki/index.php?title=Main_Page";
Site wikiSite;
Page page;
try
{
wikiSite = new Site(siteurl, Configuration.WikiUsername, Configuration.WikiPassword);
//wikiSite = new Site(siteurl, "abc", "123"); //limewebs
page = new Page(wikiSite,videoInfo.Title);
}
catch (Exception e)
{
logger.Error("Unable to login to: " + siteurl + " error:" + e.Message + e.StackTrace + e.Source + e.InnerException + "\n" +e.Data);
return false;
}
string fileNamespace = "6";
string fileName = Path.GetFileName(fileToUpload);
page.title = wikiSite.namespaces[fileNamespace] + ":" + fileName;
StringBuilder sb = new StringBuilder();
sb.AppendLine("{{Information");
sb.AppendLine("|Description = {{en|1=" + videoInfo.Description + "}}");
sb.AppendFormat("|Source = originally posted to '''[[Flickr]]''' as [{0} {1}]", videoInfo.SourceUrl,
videoInfo.Title);
sb.AppendLine();
sb.AppendLine("|Date = " + videoInfo.Date);
sb.AppendLine("|Author = " + videoInfo.Author);
sb.AppendLine("|Permission = " + GetLicenseTemplate(videoInfo.License));
sb.AppendLine("|Other versions = ");
sb.AppendLine("}}");
string wikitext = sb.ToString();
logger.Info("--------------\n" + wikitext);
try {
page.Load();
}
catch(Exception ex)
{
return false;
}
if (page.Exists())
{
int x = 0;
//return false;
}
try {
logger.InfoFormat("Uploading {0} to Wiki", fileToUpload);
page.UploadImage(fileToUpload, wikitext, "", "", "");
logger.Info("Complete upload to Wiki");
}
catch (Exception ex)
{
logger.Error("Error in UploadFile: " + ex.Message + Environment.NewLine + "fileToUpload: " + fileToUpload + ex.GetBaseException());
}
return true;
}