Пример #1
0
        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;
                }
            }
        }