-

 - e-mail

 

 -

   Flashr

 -

 LiveInternet.ru:
: 26.02.2007
:
:
: 6574

:


BlogEngine - MultiPost

, 23 2008 . 16:33 +

, ( ). , (Extension) BlogEngine.Net, ASP.NET. ? , , Ya.ru, .


1) , . , . , (, , , ), web.config:
  1. <system.net>

  2. <settings>

  3. <httpWebRequest useUnsafeHeaderParsing="true" />

  4. <servicePointManager expect100Continue="false"/>

  5. </settings>

  6. </system.net>





2) , , :


, , BlogEngine . , . , (bool=true/false). , , , . - BlogType - . - . BlogParam - , . , . MaxAttempts(int) - , , . - PostType(Public/Private/OnlyFriends) - . , Private, , , .


3) MultiPost:
  1. namespace MultiPost

  2. {

  3. /// <summary>

  4. /// Copy all your posts to blog at http://wow.ya.ru

  5. /// You have to assign an login and password inside constructor

  6. /// </summary>

  7. /// <remarks>

  8. /// Based on pure code - http://ya.topbot.ru

  9. /// </remarks>

  10. [Extension("Copy all your posts to blogs", "0.1.1", "http://ya.topbot.ru")]

  11. public class MultiPost

  12. {

  13. /// <summary>

  14. /// Name of Module

  15. /// </summary>

  16. private static String sExtensionName = "MultiPost";


  17. static protected ExtensionSettings _settings = null;

  18. /*....*/

  19. }

  20. }


, BlogEngine .
, :
  1. static MultiPost()

  2. {

  3. // create settings object. You need to pass exactly your

  4. // extension class name (case sencitive)

  5. ExtensionSettings settings = new ExtensionSettings(sExtensionName);

  6. /*.......*/

  7. ExtensionManager.ImportSettings(settings);

  8. _settings = ExtensionManager.GetSettings(sExtensionName);

  9. Post.Saved += new EventHandler<SavedEventArgs>(Post_Saved);

  10. }


,
  1. /// <summary>

  2. /// Occurs on new post

  3. /// <remarks>

  4. /// It opens a new thread and executes

  5. /// because it takes some time to complete.

  6. /// </remarks>

  7. /// </summary>

  8. private static void Post_Saved(object sender, SavedEventArgs e)

  9. {

  10. if (e.Action != SaveAction.Insert)

  11. return;


  12. IPublishable item = (IPublishable)sender;


  13. //(HttpContext.Current == null || !HttpContext.Current.Request.IsLocal)

  14. if (item.IsVisible)

  15. {

  16. //getting new thread to do all crap

  17. ThreadPool.QueueUserWorkItem(delegate {

  18. PostCycle(item);

  19. });

  20. }

  21. }


  22. /// <summary>

  23. /// Main process to post

  24. /// </summary>

  25. /// <param name="item"></param>

  26. public static void PostCycle(IPublishable item){

  27. // , ...

  28. DataTable dt = _settings.GetDataTable();

  29. //pure code, coz i cant change Categories class

  30. string catsline = "";

  31. foreach (Category c in item.Categories)

  32. {

  33. catsline += c.Title + ",";

  34. }

  35. for (int i = dt.Rows.Count - 1; i >= 0; i--)

  36. {

  37. SettingsCollection sets = new SettingsCollection(dt.Rows[i].ItemArray);

  38. if (!sets.Enabled ||

  39. (!String.IsNullOrEmpty(sets.CopyOnTags.Trim())

  40. && catsline.Contains(sets.CopyOnTags))

  41. )

  42. {//not allowed to post

  43. dt.Rows.RemoveAt(i);

  44. }

  45. }

  46. //lets finish the others

  47. for (int i = dt.Rows.Count - 1; dt.Rows.Count > 0; i--)

  48. {

  49. Thread.Sleep(5000);

  50. if (i < 0)//new cycle...bad...bad

  51. {

  52. i = dt.Rows.Count;

  53. }

  54. try

  55. {

  56. SettingsCollection sets = new SettingsCollection(dt.Rows[i].ItemArray);

  57. Type tBlog = Type.GetType("MultiPost.Blogs."+sets.BlogType);

  58. Object theBlog = Activator.CreateInstance(tBlog,

  59. new object[1] { sets });

  60. Type[] paramTypes = {

  61. typeof(IPublishable)

  62. };

  63. Object[] ps = new object[1] { item };

  64. MethodInfo mDefaults = tBlog.GetMethod("ProcessItem", paramTypes);

  65. if ((Boolean)mDefaults.Invoke(theBlog, ps))//if success

  66. {

  67. dt.Rows.RemoveAt(i);

  68. }

  69. //failed, lets continue

  70. }

  71. catch(Exception e)//toomanyattempts

  72. {

  73. dt.Rows.RemoveAt(i);

  74. }


  75. }

  76. }


, , , . 5 . Rows, , . .
PS: admin/Extension Manager/Settings.ascx.cs , . .






http://flashr.ya.ru/replies.xml?item_no=1251
:  

: [1] []
 

:
: 

: ( )

:

  URL