public void CreateMetaWeblogPost() { site.ApiType = "metaweblog"; site.BlogId = "BlogId"; site.Username = BloggerApiTest.Username; site.Password = BloggerApiTest.Password; crosspostInfo = new CrosspostInfo(site); proxy = new BloggerAPIClientProxy(); UriBuilder uriBuilder = new UriBuilder("http",crosspostInfo.Site.HostName,crosspostInfo.Site.Port,crosspostInfo.Site.Endpoint); proxy.Url = uriBuilder.ToString(); proxy.UserAgent="newtelligence dasBlog/1.4"; Entry testEntry = TestEntry.CreateEntry("MetaWeblog " + DateTime.Now.ToShortTimeString(), 5, 2); testEntry.Author = BloggerApiTest.Username; mwPost newPost = CreateMovableTypePost(testEntry); Entry newEntry = GetDataService().GetEntry(newPost.postid); Assert.IsNotNull(newEntry); Assert.IsTrue(testEntry.CompareTo(newEntry) == 0); // now delete the entry string entryId = newEntry.EntryId; GetDataService().DeleteEntry(entryId, null); Assert.IsNull(localhostBlogService.GetEntry(entryId)); }
private void crosspostSitesGrid_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e) { if ( e.CommandName == "AddItem" ) { CrosspostSite newSite = new CrosspostSite(); newSite.ProfileName = "New Profile"; newSite.Port=80; // luke@jurasource 24-MAR-04 // init all blog names newSite.AllBlogNames = new string[]{""}; crosspostSites.Insert(0,newSite); crosspostSitesGrid.CurrentPageIndex = 0; crosspostSitesGrid.EditItemIndex = 0; BindGrid(); } else if ( e.CommandName == "autoFill" ) { DropDownList dropDownList = (DropDownList)e.Item.FindControl("blogSoftware"); TextBox textHostName = (TextBox)e.Item.FindControl("textHostName"); TextBox textEndpoint = (TextBox)e.Item.FindControl("textEndpoint"); TextBox textBoxBlogURL = (TextBox)e.Item.FindControl("textBoxBlogURL"); DropDownList dropDownApi = (DropDownList)e.Item.FindControl("listApiType"); string rawBlogUrl = textBoxBlogURL.Text; rawBlogUrl = rawBlogUrl.Replace("http://", ""); string[] blogUrl = rawBlogUrl.Split('/'); textHostName.Text = blogUrl[0]; string endpoint = ""; for (int index = 1; index < blogUrl.Length; index++) { endpoint += "/" + blogUrl[index]; } CrossPostServerInfo currentInfo = (CrossPostServerInfo)crossPostServerInfo.GetValue(dropDownList.SelectedIndex); if (endpoint.Length != 0 && endpoint.EndsWith("/") == false) endpoint += "/"; textEndpoint.Text = endpoint + currentInfo.Endpoint; dropDownApi.SelectedIndex = currentInfo.Service; } else if ( e.CommandName =="testConnection" ) { Label labelTestError; labelTestError = ((Label)e.Item.FindControl("labelTestError")); labelTestError.Text = ""; try { TextBox textBlogName; TextBox textPassword; CrosspostSite site = crosspostSites[e.Item.DataSetIndex]; site.ProfileName = ((TextBox)e.Item.FindControl("textProfileName")).Text; site.HostName = ((TextBox)e.Item.FindControl("textHostName")).Text; site.Port = int.Parse(((TextBox)e.Item.FindControl("textPort")).Text); site.Endpoint = ((TextBox)e.Item.FindControl("textEndpoint")).Text; site.Username = ((TextBox)e.Item.FindControl("textUsername")).Text; site.ApiType = ((DropDownList)e.Item.FindControl("listApiType")).SelectedValue; textPassword = ((TextBox)e.Item.FindControl("textPassword")); if ( textPassword.Text.Length > 0 ) { site.Password = textPassword.Text; } textBlogName = ((TextBox)e.Item.FindControl("textBlogName")); UriBuilder uriBuilder = new UriBuilder("http",site.HostName,site.Port,site.Endpoint); BloggerAPIClientProxy proxy = new BloggerAPIClientProxy(); proxy.Url = uriBuilder.ToString(); proxy.UserAgent="newtelligence dasBlog/1.4"; bgBlogInfo[] blogInfos = proxy.blogger_getUsersBlogs("",site.Username, site.Password); if ( blogInfos.Length > 0 ) { // [email protected] 24-MAR-04 // refresh all the blog names for this crosspost site string[] allBlogNames = new string[blogInfos.Length]; for (int blog=0; blog<blogInfos.Length; blog++) allBlogNames[blog] = blogInfos[blog].blogName; site.AllBlogNames = allBlogNames; // Default the crosspost blog to the first one site.BlogName = textBlogName.Text = blogInfos[0].blogName; site.BlogId = blogInfos[0].blogid; } BindGrid(); } catch( Exception exc ) { labelTestError.Text = exc.Message; } finally { } } }
protected void HandleCrosspost(CrosspostInfo ci, Entry entry) { try { BloggerAPIClientProxy proxy = new BloggerAPIClientProxy(); UriBuilder uriBuilder = new UriBuilder("http", ci.Site.HostName, ci.Site.Port, ci.Site.Endpoint); proxy.Url = uriBuilder.ToString(); proxy.UserAgent = this.UserAgent; if (ci.IsAlreadyPosted) { try { if (ci.Site.ApiType == "metaweblog") { mwPost existingPost = new mwPost(); existingPost.link = ""; existingPost.permalink = ""; existingPost.categories = ci.Categories.Split(';'); existingPost.postid = ci.TargetEntryId; existingPost.dateCreated = entry.CreatedLocalTime; existingPost.title = entry.Title; existingPost.description = entry.Content + ci.GetTrackingSnippet(entry.EntryId); proxy.metaweblog_editPost(ci.TargetEntryId, ci.Site.Username, ci.Site.Password, existingPost, true); Crosspost cp = new Crosspost(); cp.TargetEntryId = ci.TargetEntryId; cp.ProfileName = ci.Site.ProfileName; cp.Categories = ci.Categories; entry.Crossposts.Add(cp); } else if (ci.Site.ApiType == "blogger") { proxy.blogger_editPost("", ci.TargetEntryId, ci.Site.Username, ci.Site.Password, entry.Content + ci.GetTrackingSnippet(entry.EntryId), true); Crosspost cp = new Crosspost(); cp.TargetEntryId = ci.TargetEntryId; cp.ProfileName = ci.Site.ProfileName; entry.Crossposts.Add(cp); } if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.CrosspostChanged, ci.Site.HostName, null)); } } catch (XmlRpcFaultException xrfe) { ErrorTrace.Trace(TraceLevel.Error, xrfe); if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.Error, xrfe.Message, String.Format("Updating cross-post entry {0} on {1}; Failed with server-fault code, {2} \"{3}\"", ci.TargetEntryId, ci.Site.ProfileName, xrfe.FaultCode, xrfe.FaultString))); } } catch (Exception e) { ErrorTrace.Trace(TraceLevel.Error, e); if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.Error, e.ToString().Replace("\n", "<br />"), String.Format("Updating cross-post entry {0} on {1}", ci.TargetEntryId, ci.Site.ProfileName))); } } } else { try { if (ci.Site.ApiType == "metaweblog") { mwPost newPost = new mwPost(); newPost.link = ""; newPost.permalink = ""; newPost.postid = ""; newPost.categories = ci.Categories.Split(';'); newPost.dateCreated = entry.CreatedLocalTime; newPost.description = entry.Content + ci.GetTrackingSnippet(entry.EntryId); newPost.title = entry.Title; newPost.postid = proxy.metaweblog_newPost(ci.Site.BlogId, ci.Site.Username, ci.Site.Password, newPost, true); Crosspost cp = new Crosspost(); cp.TargetEntryId = newPost.postid; cp.ProfileName = ci.Site.ProfileName; cp.Categories = ci.Categories; entry.Crossposts.Add(cp); } else if (ci.Site.ApiType == "blogger") { Crosspost cp = new Crosspost(); cp.TargetEntryId = proxy.blogger_newPost("", ci.Site.BlogId, ci.Site.Username, ci.Site.Password, entry.Content + ci.GetTrackingSnippet(entry.EntryId), true); cp.ProfileName = ci.Site.ProfileName; entry.Crossposts.Add(cp); } if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.CrosspostAdded, ci.Site.HostName, null)); } } catch (XmlRpcFaultException xrfe) { ErrorTrace.Trace(TraceLevel.Error, xrfe); if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.Error, xrfe.Message, String.Format("Adding cross-post entry to {0}; Failed with server-fault code, {1} \"{2}\"", ci.Site.ProfileName, xrfe.FaultCode, xrfe.FaultString))); } } catch (Exception e) { ErrorTrace.Trace(TraceLevel.Error, e); if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.Error, e.ToString().Replace("\n", "<br />"), String.Format("Adding cross-post entry to {0}", ci.Site.ProfileName))); } } } } catch (Exception e) { ErrorTrace.Trace(TraceLevel.Error, e); if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.Error, e.ToString().Replace("\n", "<br />"), String.Format("HandleCrosspost to {0}", ci.Site.ProfileName))); } } }
void IBlogDataService.DeleteEntry(string entryId, CrosspostSiteCollection crosspostSites) { DateTime foundDate = GetDateForEntry(entryId); if (foundDate == DateTime.MinValue) return; DayEntry day = InternalGetDayEntry(foundDate); Entry currentEntry = day.Entries[entryId]; if (currentEntry != null) { if (crosspostSites != null) { foreach (Crosspost cp in currentEntry.Crossposts) { foreach (CrosspostSite site in crosspostSites) { if (site.ProfileName == cp.ProfileName) { try { BloggerAPIClientProxy proxy = new BloggerAPIClientProxy(); UriBuilder uriBuilder = new UriBuilder("http", site.HostName, site.Port, site.Endpoint); proxy.Url = uriBuilder.ToString(); proxy.UserAgent = this.UserAgent; proxy.blogger_deletePost("", cp.TargetEntryId, site.Username, site.Password, true); if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.CrosspostDeleted, currentEntry.Title, site.ProfileName)); } } catch (XmlRpcFaultException xrfe) { ErrorTrace.Trace(TraceLevel.Error, xrfe); if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.Error, xrfe.Message, String.Format("Deleting cross-post entry {0} on {1}; Failed with server-fault code, {2} \"{3}\"", cp.TargetEntryId, cp.ProfileName, xrfe.FaultCode, xrfe.FaultString))); } } catch (Exception e) { ErrorTrace.Trace(TraceLevel.Error, e); if (loggingService != null) { loggingService.AddEvent( new EventDataItem(EventCodes.Error, e.ToString().Replace("\n", "<br />"), String.Format("Deleting cross-post entry {0} from {1}", cp.TargetEntryId, cp.ProfileName))); } } break; } } } } day.Entries.Remove(currentEntry); } day.Save(data); }