/// <summary> /// Perform the MediaRSS export. /// </summary> /// <param name="sLocation">The name of the file to export to.</param> /// <param name="oOptions">Options for the export.</param> /// <returns><c>true</c> if the export happened, <c>false</c> if not.</returns> protected bool PerformExport( string sLocation, frmExportMediaRSS oOptions ) { // Assume the worst. bool bExported = false; // Create the file to export to. using ( FileStream h = new FileStream( sLocation, FileMode.Create, FileAccess.Write, FileShare.None ) ) { try { using ( StreamWriter stream = new StreamWriter( h ) ) { try { // For when we need a time. string sNow = DateTime.Now.ToUniversalTime().ToString( "r" ); // First write the start of the document. stream.WriteLine( "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" ); stream.WriteLine( "<rss version=\"2.0\" xmlns:media=\"http://search.yahoo.com/mrss/\" xmlns:atom=\"http://www.w3.org/2005/Atom\">" ); stream.WriteLine( " <channel>" ); stream.WriteLine( " <title>" + Utils.HTMLEncode( oOptions.Title ) + "</title>" ); stream.WriteLine( " <description>" + Utils.HTMLEncode( oOptions.Title ) + "</description>" ); stream.WriteLine( " <copyright>" + Utils.HTMLEncode( oOptions.Copyright ) + "</copyright>" ); stream.WriteLine( " <link>" + RBUtils.RBProfileURL( doc.UserName ) + "</link>" ); stream.WriteLine( " <pubDate>" + sNow + "</pubDate>" ); stream.WriteLine( " <lastBuildDate>" + sNow + "</lastBuildDate>" ); stream.WriteLine( " <generator>http://www.davep.org/misc/RBArtMan/</generator>" ); stream.WriteLine( " <managingEditor>" + Utils.HTMLEncode( oOptions.Author ) + "</managingEditor>" ); stream.WriteLine( " <category>Art</category>" ); // <atom:link> // Now write each item in the channel. foreach ( RBArtItem item in doc.Items ) { string sTargetURL = ( oOptions.Buy ? RBUtils.WorkBuyURL( doc.UserName, item.ID ) : RBUtils.WorkURL( doc.UserName, item.ID ) ).ToString(); stream.WriteLine( " <item>" ); stream.WriteLine( " <title>" + Utils.HTMLEncode( item.Title ) + "</title>" ); stream.WriteLine( " <link>" + sTargetURL + "</link>" ); stream.WriteLine( " <guid isPermaLink=\"true\">" + sTargetURL + "</guid>" ); stream.WriteLine( " <pubDate>" + sNow + "</pubDate>" ); stream.WriteLine( " <author>" + Utils.HTMLEncode( oOptions.Author ) + "</author>" ); stream.WriteLine( " <media:thumbnail url=\"" + RBUtils.WorkImageURL( item.ID, ArtCropping.None, ArtSize.Small ) + "\" />" ); stream.WriteLine( " <media:content url=\"" + RBUtils.WorkImageURL( item.ID, ArtCropping.None, ArtSize.XLarge ) + "\" />" ); // <media:credit> // <description> stream.WriteLine( " <category>Art</category>" ); stream.WriteLine( " </item>" ); } // End of the document. stream.WriteLine( " </channel> " ); stream.WriteLine( "</rss>" ); // Done. bExported = true; } finally { stream.Close(); } } } finally { h.Close(); } } return bExported; }
/// <summary> /// Export the document as a MediaRSS file. /// </summary> /// <param name="sLocation">The name of the file to export to.</param> /// <returns><c>true</c> if the export happened, <c>false</c> if not.</returns> public override bool ExportTo( string sLocation ) { // Assume the worst. bool bExported = false; using ( frmExportMediaRSS oExport = new frmExportMediaRSS() ) { // Set any defaults. oExport.Link = RBUtils.RBProfileURL( doc.UserName ).ToString(); // Get options from the user. if ( oExport.ShowDialog() == DialogResult.OK ) { // They've confirmed the export, do it... bExported = PerformExport( sLocation, oExport ); } } return bExported; }