, 23 2008 . 16:33
+
, ( ). ,
(Extension) BlogEngine.Net, ASP.NET. ? , , Ya.ru, .
1) , . , . , (, , , ), web.config:
- <system.net>
- <settings>
- <httpWebRequest useUnsafeHeaderParsing="true" />
- <servicePointManager expect100Continue="false"/>
- </settings>
- </system.net>
2) , , :

, , BlogEngine . , . , (bool=true/false). , , , . - BlogType - . - . BlogParam - , . , . MaxAttempts(int) - , , . - PostType(Public/Private/OnlyFriends) - . , Private, , , .
3) MultiPost:
- namespace MultiPost
- {
- /// <summary>
- /// Copy all your posts to blog at http://wow.ya.ru
- /// You have to assign an login and password inside constructor
- /// </summary>
- /// <remarks>
- /// Based on pure code - http://ya.topbot.ru
- /// </remarks>
- [Extension("Copy all your posts to blogs", "0.1.1", "http://ya.topbot.ru")]
- public class MultiPost
- {
- /// <summary>
- /// Name of Module
- /// </summary>
- private static String sExtensionName = "MultiPost";
- static protected ExtensionSettings _settings = null;
- /*....*/
- }
- }
, BlogEngine .
, :
- static MultiPost()
- {
- // create settings object. You need to pass exactly your
- // extension class name (case sencitive)
- ExtensionSettings settings = new ExtensionSettings(sExtensionName);
- /*.......*/
- ExtensionManager.ImportSettings(settings);
- _settings = ExtensionManager.GetSettings(sExtensionName);
- Post.Saved += new EventHandler<SavedEventArgs>(Post_Saved);
- }
,
- /// <summary>
- /// Occurs on new post
- /// <remarks>
- /// It opens a new thread and executes
- /// because it takes some time to complete.
- /// </remarks>
- /// </summary>
- private static void Post_Saved(object sender, SavedEventArgs e)
- {
- if (e.Action != SaveAction.Insert)
- return;
- IPublishable item = (IPublishable)sender;
- //(HttpContext.Current == null || !HttpContext.Current.Request.IsLocal)
- if (item.IsVisible)
- {
- //getting new thread to do all crap
- ThreadPool.QueueUserWorkItem(delegate {
- PostCycle(item);
- });
- }
- }
- /// <summary>
- /// Main process to post
- /// </summary>
- /// <param name="item"></param>
- public static void PostCycle(IPublishable item){
- // , ...
- DataTable dt = _settings.GetDataTable();
- //pure code, coz i cant change Categories class
- string catsline = "";
- foreach (Category c in item.Categories)
- {
- catsline += c.Title + ",";
- }
- for (int i = dt.Rows.Count - 1; i >= 0; i--)
- {
- SettingsCollection sets = new SettingsCollection(dt.Rows[i].ItemArray);
- if (!sets.Enabled ||
- (!String.IsNullOrEmpty(sets.CopyOnTags.Trim())
- && catsline.Contains(sets.CopyOnTags))
- )
- {//not allowed to post
- dt.Rows.RemoveAt(i);
- }
- }
- //lets finish the others
- for (int i = dt.Rows.Count - 1; dt.Rows.Count > 0; i--)
- {
- Thread.Sleep(5000);
- if (i < 0)//new cycle...bad...bad
- {
- i = dt.Rows.Count;
- }
- try
- {
- SettingsCollection sets = new SettingsCollection(dt.Rows[i].ItemArray);
- Type tBlog = Type.GetType("MultiPost.Blogs."+sets.BlogType);
- Object theBlog = Activator.CreateInstance(tBlog,
- new object[1] { sets });
- Type[] paramTypes = {
- typeof(IPublishable)
- };
- Object[] ps = new object[1] { item };
- MethodInfo mDefaults = tBlog.GetMethod("ProcessItem", paramTypes);
- if ((Boolean)mDefaults.Invoke(theBlog, ps))//if success
- {
- dt.Rows.RemoveAt(i);
- }
- //failed, lets continue
- }
- catch(Exception e)//toomanyattempts
- {
- dt.Rows.RemoveAt(i);
- }
- }
- }
, , , . 5 . Rows, , . .
PS: admin/Extension Manager/Settings.ascx.cs , . .
http://flashr.ya.ru/replies.xml?item_no=1251
:
ya.ru:text