private void SaveResponse(FeatureController ctlModule, int PortalId, DisqusInfo oHeader, DisqusResponseInfo oResponse, int ItemId) { // assign the response to the header record oHeader.Response[0] = oResponse; // get a identity reference ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_IDENTIFIER, oHeader.Response[0].Thread.Identifiers[0])); DisqusIdentifierInfo oIdentity = ctlModule.GetIdentifier(oHeader.Response[0].Thread.Identifiers[0]); try { // save the response object ctlModule.AddDisqus(PortalId, oIdentity.TabId, oIdentity.TabModuleId, oIdentity.RawUrl, SerializeToXML(oHeader), oHeader.Response[0].CreatedAt.ToString()); } catch (Exception exSave) { ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(ERROR_MESSAGE_1, ItemId)); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(ERROR_MESSAGE_2, PortalId, oIdentity.TabId, oIdentity.TabModuleId, oIdentity.RawUrl, oHeader.Response[0].CreatedAt.ToString())); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(ERROR_MESSAGE_3, exSave.Message, exSave.StackTrace)); } }
public string SerializeToXML(DisqusInfo oDisqus) { StringWriter outStream = new StringWriter(); XmlSerializer oSerializer = new XmlSerializer(typeof(DisqusInfo)); oSerializer.Serialize(outStream, oDisqus); return(outStream.ToString()); }
private void ParseCommentsView() { // if a setting isn't in place, let the end-user know if (this.AttachedModule > 0 && string.IsNullOrEmpty(DisqusApplicationName) == false && string.IsNullOrEmpty(DisqusApiSecret) == false) { // add the view this.phScript.Controls.Add(new LiteralControl(this.GetDisqusCommentsScript())); FeatureController ctlModule = new FeatureController(); DisqusInfo oComment = ctlModule.GetDisqusByModule(TabModuleId); divComments.Visible = ctlModule.IsSearchEngine(Request.UserAgent) && (oComment != null); if (divComments.Visible == true) { // generate & inject the HTML markup divComments.InnerHtml = GetCommentsForSearchEngines(oComment); } } else { // tell the user why we cannot add the view if (DisqusView == "comments" && this.AttachedModule < 1) { UI.Skins.Skin.AddModuleMessage(this, this.GetLocalizedString("NoModuleAttached.Text"), ModuleMessage.ModuleMessageType.YellowWarning); } if (DisqusView == "comments" && string.IsNullOrEmpty(DisqusApplicationName)) { UI.Skins.Skin.AddModuleMessage(this, this.GetLocalizedString("NoApplicationName.Text"), ModuleMessage.ModuleMessageType.YellowWarning); } if (DisqusView == "comments" && string.IsNullOrEmpty(DisqusApiSecret)) { UI.Skins.Skin.AddModuleMessage(this, this.GetLocalizedString("NoApiSecret.Text"), ModuleMessage.ModuleMessageType.YellowWarning); } } AttachModuleScript(); }
private string GetCommentsForSearchEngines(DisqusInfo oComment) { if (oComment == null) { return(string.Empty); } StringBuilder sb = new StringBuilder(); for (int i = 0; i < oComment.Response.Length - 1; i++) { sb.Append("<div class=\"hreview\">"); sb.Append("<span class=\"item\">"); sb.AppendFormat("<span class=\"fn\">{0}</span>", oComment.Response[i].Thread.Title); sb.Append("</span>"); sb.AppendFormat("<span class=\"reviewer\">{0}</span>", oComment.Response[i].Author.Name); sb.Append("<span class=\"dtreviewed\">"); sb.Append(oComment.Response[i].CreatedAt.ToString("MMM dd, yyyy")); sb.AppendFormat("<span class=\"value-title\" title=\"{0}\"></span>", oComment.Response[i].CreatedAt.ToString("yyyy-MM-dd")); sb.Append("</span>"); sb.AppendFormat("<span class=\"summary\">{0}</span>", oComment.Response[i].RawMessage.Substring(0, 50)); sb.AppendFormat("<span class=\"description\">{0}</span>", oComment.Response[i].Message); // no way to really implement this since we aren't really posting reviews //sb.AppendFormat("<span class=\"rating\">{0}</span>", ); sb.Append("</div>"); } return(sb.ToString()); }
private void ImportCommentsFromDisqus() { PortalController ctlPortal = new PortalController(); ArrayList lstPortal = ctlPortal.GetPortals(); // cycle through each portal foreach (PortalInfo oPortal in lstPortal) { ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_PROCESSING, oPortal.PortalID, oPortal.PortalName)); try { // if the portal has the site settings, import its comments string DisqusApplicationName = PortalController.GetPortalSetting(APPLICATION_NAME, oPortal.PortalID, string.Empty); if (string.IsNullOrEmpty(DisqusApplicationName) == false) { var ctlModule = new FeatureController(); string DisqusApiSecret = PortalController.GetPortalSetting(API_SECRET, oPortal.PortalID, string.Empty); string strResponse = ctlModule.GetContent( string.Format(ctlModule.GenericDisqusUrl(DisqusApplicationName, DisqusApiSecret), FeatureController.DISQUS_POST_LIST)); DisqusInfo oPosts = JsonConvert.DeserializeObject <DisqusInfo>(strResponse); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_CALLED, string.Format(ctlModule.GenericDisqusUrl(DisqusApplicationName, DisqusApiSecret), FeatureController.DISQUS_POST_LIST))); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_DISQUS_COMMENTS, oPosts.Response.Length)); /* * TODO: Finish the scheduler item * 1. Delete all posts from the DB for the Portal * 1. Save all responses to memory * 2. Slice up 1 per record * a. Be mindful of TabId, TabModuleId, PortalId * b. PortalId will require parsing to figure out * 3. Save to DB * 4. Determine if subsequent requests need to be made * a. Use the cursor to plan subsequent requests * b. Request repeatedly until the * I. API refuses the request * II. Cursor reveals no further records */ // delete all saved Disqus records for the site ScheduleHistoryItem.AddLogNote(Environment.NewLine + MESSAGE_DELETE_COMMENTS); ctlModule.DeleteDisqusbyPortal(oPortal.PortalID); ArrayList lstResponse = new ArrayList(); foreach (DisqusResponseInfo oResponse in oPosts.Response) { lstResponse.Add(oResponse); } ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_LSTRESPONSE_COMMENTS, lstResponse.Count)); // build a header object DisqusInfo oHeader = oPosts; oHeader.Response = new DisqusResponseInfo[1]; ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_OPOST_COMMENTS, oPosts.Response.Length)); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_OHEADER_COMMENTS, oHeader.Response.Length)); int i = 0; // iterate through all responses (comments) foreach (DisqusResponseInfo oResponse in lstResponse) { ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_SAVING_COMMENT, i)); SaveResponse(ctlModule, oPortal.PortalID, oHeader, oResponse, i); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_COMMENT_SAVED, i)); i++; } ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_COMMENT_SUMMARY, oPortal.PortalName, i)); } } catch (Exception ex) { Exceptions.LogException(ex); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_UNEXPECTED_ERROR, ex.Message, ex.StackTrace)); continue; } } }
private string GetCommentsForSearchEngines(DisqusInfo oComment) { if (oComment == null) return string.Empty; StringBuilder sb = new StringBuilder(); for (int i = 0; i < oComment.Response.Length - 1; i++) { sb.Append("<div class=\"hreview\">"); sb.Append("<span class=\"item\">"); sb.AppendFormat("<span class=\"fn\">{0}</span>", oComment.Response[i].Thread.Title); sb.Append("</span>"); sb.AppendFormat("<span class=\"reviewer\">{0}</span>", oComment.Response[i].Author.Name); sb.Append("<span class=\"dtreviewed\">"); sb.Append(oComment.Response[i].CreatedAt.ToString("MMM dd, yyyy")); sb.AppendFormat("<span class=\"value-title\" title=\"{0}\"></span>", oComment.Response[i].CreatedAt.ToString("yyyy-MM-dd")); sb.Append("</span>"); sb.AppendFormat("<span class=\"summary\">{0}</span>", oComment.Response[i].RawMessage.Substring(0, 50)); sb.AppendFormat("<span class=\"description\">{0}</span>", oComment.Response[i].Message); // no way to really implement this since we aren't really posting reviews //sb.AppendFormat("<span class=\"rating\">{0}</span>", ); sb.Append("</div>"); } return sb.ToString(); }
private void SaveResponse(FeatureController ctlModule, int PortalId, DisqusInfo oHeader, DisqusResponseInfo oResponse, int ItemId) { // assign the response to the header record oHeader.Response[0] = oResponse; // get a identity reference ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(MESSAGE_IDENTIFIER, oHeader.Response[0].Thread.Identifiers[0])); DisqusIdentifierInfo oIdentity = ctlModule.GetIdentifier(oHeader.Response[0].Thread.Identifiers[0]); try { // save the response object ctlModule.AddDisqus(PortalId, oIdentity.TabId, oIdentity.TabModuleId, oIdentity.RawUrl, SerializeToXML(oHeader), oHeader.Response[0].CreatedAt.ToString()); } catch (Exception exSave) { ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(ERROR_MESSAGE_1, ItemId)); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(ERROR_MESSAGE_2, PortalId, oIdentity.TabId, oIdentity.TabModuleId, oIdentity.RawUrl, oHeader.Response[0].CreatedAt.ToString())); ScheduleHistoryItem.AddLogNote(Environment.NewLine + string.Format(ERROR_MESSAGE_3, exSave.Message, exSave.StackTrace)); } }
public string SerializeToXML(DisqusInfo oDisqus) { StringWriter outStream = new StringWriter(); XmlSerializer oSerializer = new XmlSerializer(typeof(DisqusInfo)); oSerializer.Serialize(outStream, oDisqus); return outStream.ToString(); }