示例#1
0
        //==========================================================================================
        /// <summary>
        /// handle a transient fail
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="emailAddress"></param>
        private static void transientFail(CPBaseClass cp, string emailAddress, string bounceMsg)
        {
            const string spAWSGracePeriod = "AWS SES Transient Email Grace Period";
            //
            // do not clear allowBulkEmail
            // add or update email bounce list
            //
            CPCSBaseClass cs = cp.CSNew();

            if (cs.Open("Email Bounce List", "(name=" + cp.Db.EncodeSQLText(emailAddress) + ")"))
            {
                if (cs.GetBoolean("transient"))
                {
                    //
                    // previous transient failure
                    //
                    if (DateTime.Now > cs.GetDate("transientFixDeadline"))
                    {
                        //
                        // past deadline, covert to permanent fail
                        //
                        cs.Close();
                        permanentFail(cp, emailAddress, bounceMsg);
                    }
                    else
                    {
                        //
                        // not past deadline, update details
                        //
                        cs.SetField("details", bounceMsg);
                    }
                }
                else
                {
                    //
                    // previous permanent failure - do nothing
                    //
                }
            }
            else
            {
                //
                // no previous failures, add them
                //
                cs.Close();
                if (cs.Insert("Email Bounce List"))
                {
                    cs.SetField("name", emailAddress);
                    cs.SetField("details", bounceMsg);
                    cs.SetField("transient", "1");
                    cs.SetField("transientFixDeadline", DateTime.Now.AddDays(cp.Site.GetInteger(spAWSGracePeriod)).ToShortDateString());
                }
            }
            cs.Close();
        }
        //
        //====================================================================================================
        /// <summary>
        /// return a new model with the data selected. All cacheNames related to the object will be added to the cacheNameList.
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="recordId">The id of the record to be read into the new object</param>
        protected static T create <T>(CPBaseClass cp, int recordId) where T : baseModel
        {
            T result = null;

            try
            {
                if (recordId > 0)
                {
                    Type          instanceType = typeof(T);
                    string        contentName  = derivedContentName(instanceType);
                    CPCSBaseClass cs           = cp.CSNew();
                    if (cs.Open(contentName, "(id=" + recordId.ToString() + ")"))
                    {
                        result = loadRecord <T>(cp, cs);
                    }
                    cs.Close();
                }
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex);
                throw;
            }
            return(result);
        }
        //
        //====================================================================================================
        /// <summary>
        /// pattern get a list of objects from this model
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="sqlCriteria"></param>
        /// <returns></returns>
        protected static List <T> createList <T>(CPBaseClass cp, string sqlCriteria, string sqlOrderBy) where T : baseModel
        {
            List <T> result = new List <T>();

            try
            {
                CPCSBaseClass cs = cp.CSNew();
                List <string> ignoreCacheNames = new List <string>();
                Type          instanceType     = typeof(T);
                string        contentName      = derivedContentName(instanceType);
                if ((cs.Open(contentName, sqlCriteria, sqlOrderBy)))
                {
                    T instance = default(T);
                    do
                    {
                        instance = loadRecord <T>(cp, cs);
                        if ((instance != null))
                        {
                            result.Add(instance);
                        }
                        cs.GoNext();
                    } while (cs.OK());
                }
                cs.Close();
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex);
            }
            return(result);
        }
        //
        //====================================================================================================
        protected static int getCount <T>(CPBaseClass cp, string sqlCriteria) where T : baseModel
        {
            int result = 0;

            try
            {
                Type          instanceType = typeof(T);
                string        tableName    = derivedContentTableName(instanceType);
                CPCSBaseClass cs           = cp.CSNew();
                string        sql          = "select count(id) as cnt from " + tableName;
                if ((!string.IsNullOrEmpty(sqlCriteria)))
                {
                    sql += " where " + sqlCriteria;
                }
                if ((cs.OpenSQL(sql)))
                {
                    result = cs.GetInteger("cnt");
                }
                cs.Close();
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex);
            }
            return(result);
        }
示例#5
0
 //
 // ====================================================================================================
 /// <summary>
 /// pattern get a list of objects from this model
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="cp"></param>
 /// <param name="sql"></param>
 /// <param name="pageSize"></param>
 /// <param name="pageNumber"></param>
 /// <returns></returns>
 protected static List <T> createListFromSql <T>(CPBaseClass cp, string sql, int pageSize, int pageNumber) where T : BaseDomainModel
 {
     try {
         using (CPCSBaseClass cs = cp.CSNew()) {
             List <T> result = new List <T>();
             if ((cs.OpenSQL(sql, "", pageSize, pageNumber)))
             {
                 do
                 {
                     T instance = loadRecord <T>(cp, cs);
                     if ((instance != null))
                     {
                         result.Add(instance);
                     }
                     cs.GoNext();
                 } while (cs.OK());
             }
             cs.Close();
             return(result);
         }
     } catch (Exception ex) {
         cp.Site.ErrorReport(ex);
         throw;
     }
 }
示例#6
0
        //
        // ===============================================================================
        // process Form
        // ===============================================================================
        //
        public int processForm(CPBaseClass cp, int srcFormId, string rqs, DateTime rightNow, ref int appId)
        {
            int nextFormId = srcFormId;

            try
            {
                string        button = cp.Doc.GetProperty(constants.rnButton, "");
                CPCSBaseClass cs     = cp.CSNew();
                //
                if (button != "")
                {
                    //
                    // server-side validation
                    // add client-side validation in the javascript tab of the addon. (but still always include server-side)
                    //
                    constants.checkRequiredFieldText(cp, "name", "Name");
                    //
                    if (cp.UserError.OK())
                    {
                        cs.Open("people", "id=" + cp.User.Id.ToString(), "", true, "", 1, 1);
                        cs.SetField("name", cp.Doc.GetText("name", ""));
                        cs.Close();
                    }
                }
            }
            catch (Exception ex)
            {
                errorReport(cp, ex, "processForm");
            }
            return(nextFormId);
        }
示例#7
0
        //
        // ===============================================================================================
        // performs all housekeeping when a thread record is changed (add,mod,del)
        // ===============================================================================================
        //
        public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
        {
            //int sourceFormId = 0;
            //int formId = 0;
            //int forumId = 0;
            int           threadId = 0;
            string        s        = "";
            string        sql      = "";
            CPCSBaseClass cs       = cp.CSNew();

            //
            threadId = cp.Utils.EncodeInteger(cp.Doc.GetProperty("recordId", ""));
            if (threadId == 0)
            {
                //
                // re count 'threads' in all forums
                //
                sql = "select ccforums.id as forumId"
                      + ",(select count(ccforumthreads.id) from ccforumthreads where forumId=ccForums.id) as threadCnt"
                      + ",(select count(p.id) from ccforumPosts p left join ccforumThreads t on t.id=p.threadid where t.forumId=ccforums.id) as postCnt"
                      + ",(select max(p.id) from ccforumPosts p left join ccforumThreads t on t.id=p.threadid where t.forumId=ccforums.id) as lastPostId"
                      + " from ccforums"
                      + "";
            }
            else
            {
                //
                // update forum for thread provided
                //
                sql = "select ccforums.id as forumId"
                      + ",(select count(ccforumthreads.id) from ccforumthreads where forumId=ccForums.id) as threadCnt"
                      + ",(select count(p.id) from ccforumPosts p left join ccforumThreads t on t.id=p.threadid where t.forumId=ccforums.id) as postCnt"
                      + ",(select max(p.id) from ccforumPosts p left join ccforumThreads t on t.id=p.threadid where t.forumId=ccforums.id) as lastPostId"
                      + " from ccforums"
                      + " where ccforums.id in (select forumid from ccforumthreads where id=" + threadId + ")"
                      + "";
            }
            //
            if (cs.OpenSQL2(sql, "", 1000, 1))
            {
                while (cs.OK())
                {
                    sql = "update ccforums set threads=" + cs.GetInteger("threadCnt") + ",posts=" + cs.GetInteger("postCnt") + ",lastPostId=" + cs.GetInteger("lastPostId") + " where id=" + cs.GetInteger("forumId");
                    cp.Db.ExecuteSQL(sql, "", "1", "1", "1");
                    cs.GoNext();
                }
            }
            cs.Close();
            //
            return(s);
        }
        //
        //
        //
        public static applicationClass getApplication(CPBaseClass cp, Boolean createRecordIfMissing)
        {
            applicationClass application = new applicationClass();

            try {
                CPCSBaseClass cs    = cp.CSNew();
                CPCSBaseClass csSrc = cp.CSNew();

                // get id of this user's application
                // use visit property if they keep the same application for the visit
                // use visitor property if each time they open thier browser, they get the previous application
                // use user property if they only get to the application when they are associated to the current user (they should be authenticated first)

                application.completed = false;
                application.changed   = false;
                application.id        = cp.Visit.GetInteger("multiformAjaxSample ApplicationId");

                if (application.id != 0)
                {
                    if (!cs.Open("MultiFormAjax Application", "(dateCompleted is null)"))
                    {
                        application.id = 0;
                    }
                }

                if (cs.OK())
                {
                    application.firstName = cs.GetText("firstName");
                    application.lastName  = cs.GetText("lastName");
                    application.email     = cs.GetText("email");
                }
                else
                {
                    if (csSrc.Open("people", "id=" + cp.User.Id))
                    {
                        application.firstName = csSrc.GetText("firstName");
                        application.lastName  = csSrc.GetText("lastName");
                        application.email     = csSrc.GetText("email");
                    }
                    csSrc.Close();
                }
                cs.Close();
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex, "Error in getApplication");
            }

            return(application);
        }
示例#9
0
        //==========================================================================================
        /// <summary>
        /// handle a permanent fail
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="emailAddress"></param>
        private static void permanentFail(CPBaseClass cp, string emailAddress, string bounceMsg)
        {
            //
            // -- clear allowBulkEmail
            cp.Db.ExecuteNonQuery("update ccmembers set allowBulkEmail=0 where email=" + cp.Db.EncodeSQLText(emailAddress));
            //
            // -- add or update email bounce list
            using (CPCSBaseClass cs = cp.CSNew()) {
                if (cs.Open("Email Bounce List", "name=" + cp.Db.EncodeSQLText(emailAddress)))
                {
                    //
                    // -- found in bounce list already, update
                    cs.SetField("details", bounceMsg);
                    cs.SetField("transient", "0");
                }
                else
                {
                    //
                    // -- add to bounce list
                    cs.Close();
                    if (cs.Insert("Email Bounce List"))
                    {
                        cs.SetField("name", emailAddress);
                        cs.SetField("details", bounceMsg);
                        cs.SetField("transient", "0");
                    }
                }
                cs.Close();
            }
            //
            // add to server's block list, "(programfiles)\config\SMTPBlockList_(appName).txt", vbcrlf + emailAddress + vbTab + dateTime
            //
            string filename  = "\\config\\SMTPBlockList_" + cp.Site.Name + ".txt";
            string blockList = cp.CdnFiles.Read(filename);

            cp.CdnFiles.Save(filename, blockList + "\n\r" + emailAddress + "\t" + DateTime.Now.ToString());
        }
示例#10
0
 //====================================================================================================
 /// <summary>
 /// get a portal feature available to developers that provides tool for creating portals
 /// </summary>
 /// <param name="CP"></param>
 /// <returns></returns>
 public static string getDevTool(CPBaseClass CP, PortalDataModel portalData, string frameRqs)
 {
     try {
         string section;
         //
         // this is a feature list, display the feature list
         //
         FormSimpleClass content = new FormSimpleClass {
             title = "Developer Tool",
             body  = ""
         };
         //
         // process snapshot tool
         //
         if (CP.Doc.GetText("button") == "Take Snapshot")
         {
             CPCSBaseClass cs = CP.CSNew();
             if (cs.Open("portals", "ccguid=" + CP.Db.EncodeSQLText(portalData.guid), "", true, "", 9999, 1))
             {
                 System.Web.Script.Serialization.JavaScriptSerializer msJson = new System.Web.Script.Serialization.JavaScriptSerializer();
                 string configJson = msJson.Serialize(portalData);
                 cs.SetField("defaultConfigJson", configJson);
             }
             cs.Close();
         }
         //
         // output snapshot tool
         //
         section       = "<h3>Portal Snapshot</h3>";
         section      += "<p>Click the snapshot button to save the current features for this portal in the portal's default configuration field.</p>";
         section      += CP.Html.Button("button", "Take Snapshot");
         section      += "<p>Modify Portal and Portal Features data directly</p>";
         section      += "<ul>";
         section      += "<li><a href=\"?cid=" + CP.Content.GetID("Portals") + "\">Portals</a></li>";
         section      += "<li><a href=\"?cid=" + CP.Content.GetID("Portal Features") + "\">Portal Features</a></li>";
         section      += "<li><a href=\"?cid=" + CP.Content.GetID("Admin Framework Reports") + "\">Admin Framework Reports</a></li>";
         section      += "<li><a href=\"?cid=" + CP.Content.GetID("Admin Framework Report Columns") + "\">Admin Framework Report Columns</a></li>";
         section      += "</ul>";
         section       = CP.Html.Form(section, "", "", "", frameRqs);
         content.body += section;
         //
         //
         //
         return(content.getHtml(CP));
     } catch (Exception ex) {
         CP.Site.ErrorReport(ex, "exception in loadPortal");
         throw;
     }
 }
        //
        //
        //
        public static void saveApplication(CPBaseClass cp, applicationClass application, DateTime rightNow)
        {
            try {
                CPCSBaseClass cs = cp.CSNew();

                if (application.changed)
                {
                    if (application.id > 0)
                    {
                        cs.Open(cnMultiFormAjaxApplications, "(id=" + application.id + ")");
                    }
                    if (!cs.OK())
                    {
                        if (cs.Insert("MultiFormAjax Application"))
                        {
                            //
                            // create a new record.
                            // Set application Id incase needed later
                            // Set visit property to save the application Id
                            //
                            application.id = cs.GetInteger("id");
                            cp.Visit.SetProperty("multiformAjaxSample ApplicationId", application.id.ToString());
                            cs.SetField("visitId", cp.Visit.Id.ToString());
                        }
                    }

                    if (cs.OK())
                    {
                        cs.SetField("firstName", application.firstName);
                        cs.SetField("lastName", application.lastName);
                        cs.SetField("email", application.email);
                        if (application.completed)
                        {
                            cs.SetField("datecompleted", rightNow.ToString());
                        }
                    }

                    cs.Close();
                }
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex, "Error in getApplication");
            }
        } // End saveApplication
示例#12
0
 //
 // ====================================================================================================
 /// <summary>
 /// return a layout record by it's guid. If not found populate the default values
 /// </summary>
 /// <param name="cp"></param>
 /// <param name="LayoutGuid"></param>
 /// <param name="LayoutDefaultName"></param>
 /// <param name="LayoutDefaultHtml"></param>
 /// <returns></returns>
 public static string getLayoutByGuid(CPBaseClass cp, string LayoutGuid, string LayoutDefaultName, string LayoutDefaultHtml)
 {
     using (CPCSBaseClass cs = cp.CSNew()) {
         if (cs.Open("layouts", "ccguid=" + cp.Db.EncodeSQLText(LayoutGuid)))
         {
             return(cp.Html5.Form(cs.GetText("layout")));
         }
         //
         // -- record not found, create it and return the default layout
         cs.Close();
         cs.Insert("Layouts");
         cs.SetField("name", LayoutDefaultName);
         cs.SetField("ccguid", LayoutGuid);
         cs.SetField("layout", LayoutDefaultHtml);
         cs.Save();
     }
     return(cp.Html5.Form(LayoutDefaultHtml));
 }
示例#13
0
 //
 //====================================================================================================
 /// <summary>
 /// get the id of the record by it's guid
 /// </summary>
 /// <param name="cp"></param>
 /// <param name="ccGuid"></param>record
 /// <returns></returns>
 protected static int getRecordId <T>(CPBaseClass cp, string ccGuid) where T : baseModel
 {
     try {
         if ((!string.IsNullOrEmpty(ccGuid)))
         {
             Type          instanceType = typeof(T);
             string        tableName    = derivedContentTableName(instanceType);
             CPCSBaseClass cs           = cp.CSNew();
             if ((cs.OpenSQL("select id from " + tableName + " where ccguid=" + cp.Db.EncodeSQLText(ccGuid))))
             {
                 return(cs.GetInteger("id"));
             }
             cs.Close();
         }
     } catch (Exception ex) {
         cp.Site.ErrorReport(ex);
     }
     return(0);
 }
示例#14
0
            //
            //====================================================================================================
            /// <summary>
            /// open an existing object
            /// </summary>
            /// <param name="cp"></param>
            /// <param name="recordGuid"></param>
            protected static T create <T>(CPBaseClass cp, string recordGuid) where T : baseModel
            {
                T result = null;

                try {
                    Type          instanceType = typeof(T);
                    string        contentName  = derivedContentName(instanceType);
                    CPCSBaseClass cs           = cp.CSNew();
                    if (cs.Open(contentName, "(ccGuid=" + cp.Db.EncodeSQLText(recordGuid) + ")"))
                    {
                        result = loadRecord <T>(cp, cs);
                    }
                    cs.Close();
                } catch (Exception ex) {
                    cp.Site.ErrorReport(ex);
                    throw;
                }
                return(result);
            }
示例#15
0
 //
 //====================================================================================================
 /// <summary>
 /// get the name of the record by it's id
 /// </summary>
 /// <param name="cp"></param>
 /// <param name="recordId"></param>record
 /// <returns></returns>
 protected static string getRecordName <T>(CPBaseClass cp, int recordId) where T : baseModel
 {
     try {
         if ((recordId > 0))
         {
             Type          instanceType = typeof(T);
             string        tableName    = derivedContentTableName(instanceType);
             CPCSBaseClass cs           = cp.CSNew();
             if ((cs.OpenSQL("select name from " + tableName + " where id=" + recordId.ToString())))
             {
                 return(cs.GetText("name"));
             }
             cs.Close();
         }
     } catch (Exception ex) {
         cp.Site.ErrorReport(ex);
     }
     return("");
 }
        //==========================================================================================
        /// <summary>
        /// for each user in bounce email list that is not transient, set that their allowbulkemail to false
        /// </summary>
        /// <param name="cp"></param>
        private static void removeAllowGroupEmailFromPermanentFails(CPBaseClass cp)
        {
            try {
                using (CPCSBaseClass cs = cp.CSNew()) {
                    if (cs.Open("email bounce list", "transient=0"))
                    {
                        do
                        {
                            string emailAddress = "";
                            string recordName   = cs.GetText("name");

                            //takes into account records with names like "John Doe <*****@*****.**>"
                            int subStart = recordName.IndexOf("<");
                            int subEnd   = recordName.IndexOf(">");
                            //-2 so the final ">" is not included and thestarting "<" is not included
                            int SubLen = (recordName.Length - subStart) - 2;
                            //checks if the bounce list name name has both "<" and ">" in it
                            if ((subStart != -1) && (subEnd != -1))
                            {
                                emailAddress = recordName.Substring((subStart + 1), SubLen);
                            }
                            else
                            {
                                emailAddress = recordName;
                            }
                            cp.Db.ExecuteNonQuery("update ccmembers set allowBulkEmail=0 where email=" + cp.Db.EncodeSQLText(emailAddress));
                            cs.GoNext();
                        } while (cs.OK());
                    }
                    cs.Close();
                }
            }
            catch (Exception ex) {
                cp.Site.ErrorReport(ex);
                throw;
            }
        }
        //
        // ====================================================================================================
        //
        public static string getNodeList(CPBaseClass cp, string DataRecordList, List <string> tempPathFileList, string tempExportPath)
        {
            try {
                string result = "";
                if (DataRecordList != "")
                {
                    result += System.Environment.NewLine + "\t" + "<DataRecordList>" + ExportController.EncodeCData(DataRecordList) + "</DataRecordList>";
                    string[] DataRecords = Strings.Split(DataRecordList, System.Environment.NewLine);
                    string   RecordNodes = "";
                    for (var Ptr = 0; Ptr <= Information.UBound(DataRecords); Ptr++)
                    {
                        string FieldNodes     = "";
                        string DataRecordName = "";
                        string DataRecordGuid = "";
                        string DataRecord     = DataRecords[Ptr];
                        if (DataRecord != "")
                        {
                            string[] DataSplit = Strings.Split(DataRecord, ",");
                            if (Information.UBound(DataSplit) >= 0)
                            {
                                string DataContentName = Strings.Trim(DataSplit[0]);
                                int    DataContentId   = cp.Content.GetID(DataContentName);
                                if (DataContentId <= 0)
                                {
                                    RecordNodes = ""
                                                  + RecordNodes
                                                  + System.Environment.NewLine + "\t" + "<!-- data missing, content not found during export, content=\"" + DataContentName + "\" guid=\"" + DataRecordGuid + "\" name=\"" + DataRecordName + "\" -->";
                                }
                                else
                                {
                                    bool   supportsGuid = cp.Content.IsField(DataContentName, "ccguid");
                                    string Criteria;
                                    if (Information.UBound(DataSplit) == 0)
                                    {
                                        Criteria = "";
                                    }
                                    else
                                    {
                                        string TestString = Strings.Trim(DataSplit[1]);
                                        if (TestString == "")
                                        {
                                            //
                                            // blank is a select all
                                            //
                                            Criteria       = "";
                                            DataRecordName = "";
                                            DataRecordGuid = "";
                                        }
                                        else if (!supportsGuid)
                                        {
                                            //
                                            // if no guid, this is name
                                            //
                                            DataRecordName = TestString;
                                            DataRecordGuid = "";
                                            Criteria       = "name=" + cp.Db.EncodeSQLText(DataRecordName);
                                        }
                                        else if ((Strings.Len(TestString) == 38) & (Strings.Left(TestString, 1) == "{") & (Strings.Right(TestString, 1) == "}"))
                                        {
                                            //
                                            // guid {726ED098-5A9E-49A9-8840-767A74F41D01} format
                                            //
                                            DataRecordGuid = TestString;
                                            DataRecordName = "";
                                            Criteria       = "ccguid=" + cp.Db.EncodeSQLText(DataRecordGuid);
                                        }
                                        else if ((Strings.Len(TestString) == 36) & (Strings.Mid(TestString, 9, 1) == "-"))
                                        {
                                            //
                                            // guid 726ED098-5A9E-49A9-8840-767A74F41D01 format
                                            //
                                            DataRecordGuid = TestString;
                                            DataRecordName = "";
                                            Criteria       = "ccguid=" + cp.Db.EncodeSQLText(DataRecordGuid);
                                        }
                                        else if ((Strings.Len(TestString) == 32) & (Strings.InStr(1, TestString, " ") == 0))
                                        {
                                            //
                                            // guid 726ED0985A9E49A98840767A74F41D01 format
                                            //
                                            DataRecordGuid = TestString;
                                            DataRecordName = "";
                                            Criteria       = "ccguid=" + cp.Db.EncodeSQLText(DataRecordGuid);
                                        }
                                        else
                                        {
                                            //
                                            // use name
                                            //
                                            DataRecordName = TestString;
                                            DataRecordGuid = "";
                                            Criteria       = "name=" + cp.Db.EncodeSQLText(DataRecordName);
                                        }
                                    }
                                    using (CPCSBaseClass CSData = cp.CSNew()) {
                                        if (!CSData.Open(DataContentName, Criteria, "id"))
                                        {
                                            RecordNodes = ""
                                                          + RecordNodes
                                                          + System.Environment.NewLine + "\t" + "<!-- data missing, record not found during export, content=\"" + DataContentName + "\" guid=\"" + DataRecordGuid + "\" name=\"" + DataRecordName + "\" -->";
                                        }
                                        else
                                        {
                                            //
                                            // determine all valid fields
                                            //
                                            int    fieldCnt = 0;
                                            string Sql      = "select * from ccFields where contentid=" + DataContentId;

                                            string   fieldLookupListValue = "";
                                            string[] fieldNames           = Array.Empty <string>();
                                            int[]    fieldTypes           = Array.Empty <int>();
                                            string[] fieldLookupContent   = Array.Empty <string>();
                                            string[] fieldLookupList      = Array.Empty <string>();
                                            string   FieldLookupContentName;
                                            int      FieldTypeNumber;
                                            string   FieldName;
                                            using (CPCSBaseClass csFields = cp.CSNew()) {
                                                if (csFields.Open("content fields", "contentid=" + DataContentId))
                                                {
                                                    do
                                                    {
                                                        FieldName = csFields.GetText("name");
                                                        if (FieldName != "")
                                                        {
                                                            int FieldLookupContentID = 0;
                                                            FieldLookupContentName = "";
                                                            FieldTypeNumber        = csFields.GetInteger("type");
                                                            switch (Strings.LCase(FieldName))
                                                            {
                                                            case "ccguid":
                                                            case "name":
                                                            case "id":
                                                            case "dateadded":
                                                            case "createdby":
                                                            case "modifiedby":
                                                            case "modifieddate":
                                                            case "createkey":
                                                            case "contentcontrolid":
                                                            case "editsourceid":
                                                            case "editarchive":
                                                            case "editblank":
                                                            case "contentcategoryid": {
                                                                break;
                                                            }

                                                            default: {
                                                                if (FieldTypeNumber == 7)
                                                                {
                                                                    FieldLookupContentID = csFields.GetInteger("Lookupcontentid");
                                                                    fieldLookupListValue = csFields.GetText("LookupList");
                                                                    if (FieldLookupContentID != 0)
                                                                    {
                                                                        FieldLookupContentName = cp.Content.GetRecordName("content", FieldLookupContentID);
                                                                    }
                                                                }
                                                                //CPContentBaseClass.FieldTypeIdEnum.File
                                                                switch (FieldTypeNumber)
                                                                {
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.File:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.FileImage:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.Lookup:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.Boolean:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.FileCSS:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.FileJavascript:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.FileText:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.FileXML:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.Currency:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.Float:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.Integer:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.Date:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.Link:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.LongText:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.ResourceLink:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.Text:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.HTML:
                                                                case (int)CPContentBaseClass.FieldTypeIdEnum.FileHTML: {
                                                                    var oldFieldNames = fieldNames;
                                                                    fieldNames = new string[fieldCnt + 1];
                                                                    //
                                                                    // this is a keeper
                                                                    //
                                                                    if (oldFieldNames != null)
                                                                    {
                                                                        Array.Copy(oldFieldNames, fieldNames, Math.Min(fieldCnt + 1, oldFieldNames.Length));
                                                                    }
                                                                    var oldFieldTypes = fieldTypes;
                                                                    fieldTypes = new int[fieldCnt + 1];
                                                                    if (oldFieldTypes != null)
                                                                    {
                                                                        Array.Copy(oldFieldTypes, fieldTypes, Math.Min(fieldCnt + 1, oldFieldTypes.Length));
                                                                    }
                                                                    var oldFieldLookupContent = fieldLookupContent;
                                                                    fieldLookupContent = new string[fieldCnt + 1];
                                                                    if (oldFieldLookupContent != null)
                                                                    {
                                                                        Array.Copy(oldFieldLookupContent, fieldLookupContent, Math.Min(fieldCnt + 1, oldFieldLookupContent.Length));
                                                                    }
                                                                    var oldFieldLookupList = fieldLookupList;
                                                                    fieldLookupList = new string[fieldCnt + 1];
                                                                    if (oldFieldLookupList != null)
                                                                    {
                                                                        Array.Copy(oldFieldLookupList, fieldLookupList, Math.Min(fieldCnt + 1, oldFieldLookupList.Length));
                                                                    }
                                                                    // fieldLookupContent
                                                                    fieldNames[fieldCnt]         = FieldName;
                                                                    fieldTypes[fieldCnt]         = FieldTypeNumber;
                                                                    fieldLookupContent[fieldCnt] = FieldLookupContentName;
                                                                    fieldLookupList[fieldCnt]    = fieldLookupListValue;
                                                                    fieldCnt = fieldCnt + 1;
                                                                    break;
                                                                }
                                                                }

                                                                break;
                                                            }
                                                            }
                                                        }

                                                        csFields.GoNext();
                                                    }while (csFields.OK());
                                                }
                                                csFields.Close();
                                            }
                                            //
                                            // output records
                                            //
                                            DataRecordGuid = "";
                                            while (CSData.OK())
                                            {
                                                FieldNodes     = "";
                                                DataRecordName = CSData.GetText("name");
                                                if (supportsGuid)
                                                {
                                                    DataRecordGuid = CSData.GetText("ccguid");
                                                    if (DataRecordGuid == "")
                                                    {
                                                        DataRecordGuid = cp.Utils.CreateGuid();
                                                        CSData.SetField("ccGuid", DataRecordGuid);
                                                    }
                                                }
                                                int fieldPtr;
                                                for (fieldPtr = 0; fieldPtr <= fieldCnt - 1; fieldPtr++)
                                                {
                                                    FieldName       = fieldNames[fieldPtr];
                                                    FieldTypeNumber = cp.Utils.EncodeInteger(fieldTypes[fieldPtr]);
                                                    // Dim ContentID As Integer
                                                    string FieldValue;
                                                    switch (FieldTypeNumber)
                                                    {
                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.File:
                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.FileImage: {
                                                        //
                                                        // files -- copy pathFilename to tmp folder and save pathFilename to fieldValue
                                                        FieldValue = CSData.GetText(FieldName).ToString();
                                                        if ((!string.IsNullOrWhiteSpace(FieldValue)))
                                                        {
                                                            string pathFilename = FieldValue;
                                                            cp.CdnFiles.Copy(pathFilename, tempExportPath + pathFilename, cp.TempFiles);
                                                            if (!tempPathFileList.Contains(tempExportPath + pathFilename))
                                                            {
                                                                tempPathFileList.Add(tempExportPath + pathFilename);
                                                                string path     = FileController.getPath(pathFilename);
                                                                string filename = FileController.getFilename(pathFilename);
                                                                result += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(filename) + "\" type=\"content\" path=\"" + System.Net.WebUtility.HtmlEncode(path) + "\" />";
                                                            }
                                                        }

                                                        break;
                                                    }

                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.Boolean: {
                                                        //
                                                        // true/false
                                                        //
                                                        FieldValue = CSData.GetBoolean(FieldName).ToString();
                                                        break;
                                                    }

                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.FileCSS:
                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.FileJavascript:
                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.FileText:
                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.FileXML: {
                                                        //
                                                        // text files
                                                        //
                                                        FieldValue = CSData.GetText(FieldName);
                                                        FieldValue = ExportController.EncodeCData(FieldValue);
                                                        break;
                                                    }

                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.Integer: {
                                                        //
                                                        // integer
                                                        //
                                                        FieldValue = CSData.GetInteger(FieldName).ToString();
                                                        break;
                                                    }

                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.Currency:
                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.Float: {
                                                        //
                                                        // numbers
                                                        //
                                                        FieldValue = CSData.GetNumber(FieldName).ToString();
                                                        break;
                                                    }

                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.Date: {
                                                        //
                                                        // date
                                                        //
                                                        FieldValue = CSData.GetDate(FieldName).ToString();
                                                        break;
                                                    }

                                                    case (int)CPContentBaseClass.FieldTypeIdEnum.Lookup: {
                                                        //
                                                        // lookup
                                                        //
                                                        FieldValue = "";
                                                        int FieldValueInteger = CSData.GetInteger(FieldName);
                                                        if ((FieldValueInteger != 0))
                                                        {
                                                            FieldLookupContentName = fieldLookupContent[fieldPtr];
                                                            fieldLookupListValue   = fieldLookupList[fieldPtr];
                                                            if ((FieldLookupContentName != ""))
                                                            {
                                                                //
                                                                // content lookup
                                                                //
                                                                if (cp.Content.IsField(FieldLookupContentName, "ccguid"))
                                                                {
                                                                    using (CPCSBaseClass CSlookup = cp.CSNew()) {
                                                                        CSlookup.OpenRecord(FieldLookupContentName, FieldValueInteger);
                                                                        if (CSlookup.OK())
                                                                        {
                                                                            FieldValue = CSlookup.GetText("ccguid");
                                                                            if (FieldValue == "")
                                                                            {
                                                                                FieldValue = cp.Utils.CreateGuid();
                                                                                CSlookup.SetField("ccGuid", FieldValue);
                                                                            }
                                                                        }
                                                                        CSlookup.Close();
                                                                    }
                                                                }
                                                            }
                                                            else if (fieldLookupListValue != "")
                                                            {
                                                                //
                                                                // list lookup, ok to save integer
                                                                //
                                                                FieldValue = FieldValueInteger.ToString();
                                                            }
                                                        }

                                                        break;
                                                    }

                                                    default: {
                                                        //
                                                        // text types
                                                        //
                                                        FieldValue = CSData.GetText(FieldName);
                                                        FieldValue = ExportController.EncodeCData(FieldValue);
                                                        break;
                                                    }
                                                    }
                                                    FieldNodes = FieldNodes + System.Environment.NewLine + "\t" + "<field name=\"" + System.Net.WebUtility.HtmlEncode(FieldName) + "\">" + FieldValue + "</field>";
                                                }
                                                RecordNodes = ""
                                                              + RecordNodes
                                                              + System.Environment.NewLine + "\t" + "<record content=\"" + System.Net.WebUtility.HtmlEncode(DataContentName) + "\" guid=\"" + DataRecordGuid + "\" name=\"" + System.Net.WebUtility.HtmlEncode(DataRecordName) + "\">"
                                                              + ExportController.tabIndent(cp, FieldNodes)
                                                              + System.Environment.NewLine + "\t" + "</record>";
                                                CSData.GoNext();
                                            }
                                        }
                                        CSData.Close();
                                    }
                                }
                            }
                        }
                    }
                    if (RecordNodes != "")
                    {
                        result = ""
                                 + result
                                 + System.Environment.NewLine + "\t" + "<data>"
                                 + ExportController.tabIndent(cp, RecordNodes)
                                 + System.Environment.NewLine + "\t" + "</data>";
                    }
                }
                return(result);
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex);
                return(string.Empty);
            }
        }
示例#18
0
        //
        // execute method is the only public
        //
        public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
        {
            const string forumNotificationBody = ""
                                                 + "<h2>Forum Notification</h2>"
                                                 + "<p>The following forums have had changes over the past day.<p>"
                                                 + "";
            string        returnHtml = "";
            DateTime      dateLastEmail;
            DateTime      rightNow  = DateTime.Now;
            DateTime      today     = rightNow.Date;
            DateTime      yesterday = today.AddDays(-1);
            CPCSBaseClass cs        = cp.CSNew();
            int           memberId;
            bool          memberMatch;
            string        sqlCriteria        = "";
            string        forumIdChangedList = "";
            int           forumId;
            Hashtable     forumNamesRef = new Hashtable();
            string        emailBody     = "";
            string        sql;
            string        testSrc;
            int           testId           = 0;
            string        qs               = "";
            string        forumQs          = cp.Site.GetText("forum last display qs", "");
            string        sqlDateLastEmail = "";
            string        emailDomain      = cp.Site.DomainPrimary;

            //
            try
            {
                dateLastEmail = cp.Site.GetDate("Forums Notification Last Sent", yesterday.ToString());
                cp.Site.SetProperty("Forums Notification Last Sent", rightNow.ToString());
                sqlDateLastEmail = cp.Db.EncodeSQLDate(dateLastEmail);
                //
                // verify Forum Notification email
                //
                testId = cp.Content.GetRecordID("system email", "Forum Notification");
                if (testId == 0)
                {
                    if (emailDomain.IndexOf(".") < 0)
                    {
                        emailDomain = "kma.net";
                    }
                    cs.Insert("system Email");
                    cs.SetField("name", "Forum Notification");
                    cs.SetField("subject", cp.Site.DomainPrimary + " Daily Forum Updates");
                    cs.SetField("fromAddress", "ForumNotification@" + emailDomain);
                    cs.SetField("copyFilename", forumNotificationBody);
                    cs.Close();
                }
                //
                // make a list of forums with changes
                //
                sql = "select distinct f.id as forumId,f.name as forumName"
                      + " from ((ccForums f"
                      + " left join ccforumThreads t on t.forumId=f.id)"
                      + " left join ccforumPosts p on p.threadid=t.id)"
                      + " where"
                      + " (t.dateAdded>" + sqlDateLastEmail + ")"
                      + " or(p.dateAdded>" + sqlDateLastEmail + ")"
                      + " order by f.id";
                cs.OpenSQL(sql);
                while (cs.OK())
                {
                    forumId = cs.GetInteger("forumId");
                    testSrc = "," + forumIdChangedList + ",";
                    if (testSrc.IndexOf("," + forumId.ToString() + ",") < 0)
                    {
                        forumIdChangedList += "," + forumId;
                        sqlCriteria        += "or(forumId=" + forumId + ")";
                        forumNamesRef.Add(forumId, cs.GetText("forumName"));
                    }
                    cs.GoNext();
                }
                cs.Close();
                //
                // check for people who want notifications for these forums
                //
                if (sqlCriteria != "")
                {
                    sqlCriteria = "(" + sqlCriteria.Substring(2) + ")";
                    if (cs.Open("forum notification rules", sqlCriteria, "memberId,forumId", true, "memberId,forumId", 999, 1))
                    {
                        do
                        {
                            //
                            // send this member a list of forums that changed and are on his list
                            //
                            memberId  = cs.GetInteger("memberId");
                            emailBody = "";
                            do
                            {
                                memberMatch = (memberId == cs.GetInteger("memberId"));
                                if (memberMatch)
                                {
                                    forumId = cs.GetInteger("forumId");
                                    testSrc = "," + forumIdChangedList + ",";
                                    if (testSrc.IndexOf("," + forumIdChangedList.ToString() + ",") >= 0)
                                    {
                                        qs         = cp.Utils.ModifyQueryString(forumQs, "forumId", forumId.ToString(), true);
                                        emailBody += "<li><a href=\"http://" + cp.Site.DomainPrimary + cp.Site.AppRootPath + cp.Site.PageDefault + "?" + qs + "\">" + forumNamesRef[forumId].ToString() + "</a></li>";
                                    }
                                    cs.GoNext();
                                }
                            }while (cs.OK() && memberMatch);
                            if (emailBody != "")
                            {
                                emailBody = "<ul>" + emailBody + "</ul>";
                                cp.Email.sendSystem("Forum Notification", emailBody, memberId);
                            }
                        }while (cs.OK());
                    }
                }
            }
            catch (Exception ex)
            {
                errorReport(cp, ex, "execute");
            }
            return(returnHtml);
        }
示例#19
0
        //
        // ===============================================================================================
        // performs all housekeeping when a post record is changed (add,mod,del)
        // ===============================================================================================
        //
        public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
        {
            //int sourceFormId = 0;
            //int formId = 0;
            //int forumId = 0;
            int           threadId = 0;
            int           postId   = 0;
            string        s        = "";
            string        sql      = "";
            CPCSBaseClass cs       = cp.CSNew();

            //
            postId = cp.Utils.EncodeInteger(cp.Doc.GetProperty("recordId", ""));
            if (postId == 0)
            {
                //
                // re count posts for all threads
                //
                sql = "select ccforumThreads.id as threadId"
                      + ",(select count(p.id) from ccforumPosts p where p.threadId=ccforumThreads.id) as postCnt"
                      + ",(select max(p.id) from ccforumPosts p where p.threadId=ccforumThreads.id) as lastPostId"
                      + " from ccforumThreads"
                      + "";
            }
            else
            {
                //
                // recount posts for just the thread effected
                //
                sql = "select ccforumThreads.id as threadId"
                      + ",(select count(p.id) from ccforumPosts p where p.threadId=ccforumThreads.id) as postCnt"
                      + ",(select max(p.id) from ccforumPosts p where p.threadId=ccforumThreads.id) as lastPostId"
                      + " from ccforumThreads"
                      + " where ccforumThreads.id in (select threadid from ccforumPosts where id=" + postId + ")"
                      + "";
            }
            if (cs.OpenSQL2(sql, "", 1000, 1))
            {
                threadId = cs.GetInteger("threadId");
                while (cs.OK())
                {
                    sql = "update ccforumthreads"
                          + " set replyCnt=" + cs.GetInteger("postCnt") + ""
                          + ",lastPostId=" + cs.GetInteger("lastPostId") + ""
                          + " where id=" + cs.GetInteger("threadId");
                    cp.Db.ExecuteSQL(sql, "", "1", "1", "1");
                    cs.GoNext();
                }
                if (postId != 0)
                {
                    //
                    // this only affected one post, so only housekeep one thread
                    //
                    cp.Doc.SetProperty("recordId", threadId.ToString());
                }
            }
            cs.Close();
            //
            // this effects lastPostId, so housekeep threads also
            //
            threadHousekeepClass threadHousekeep = new threadHousekeepClass();

            threadHousekeep.Execute(cp);
            //
            return(s);
        }
示例#20
0
 //
 //==========================================================================================
 /// <summary>
 /// addon method
 /// </summary>
 /// <param name="cp"></param>
 /// <returns></returns>
 public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
 {
     try {
         const string spAwsSecretAccessKey             = "AWS Secret Access Key";
         const string spAwsAccessKeyId                 = "AWS Access Key Id";
         const string spAwsSQSBounceEmailQueueEndpoint = "AWS SQS Bounce Email Queue Endpoint";
         //
         bool awsAllowBounceProcess = cp.Site.GetBoolean("AWS SES Allow Bounce Process");
         if (awsAllowBounceProcess)
         {
             //
             // -- aws keys, use the server config, but allow over-ride by site property
             string awsAccessKeyId = cp.Site.GetText(spAwsAccessKeyId);
             if (string.IsNullOrEmpty(awsAccessKeyId))
             {
                 awsAccessKeyId = cp.ServerConfig.awsAccessKey;
             }
             string awsSecretAccessKey = cp.Site.GetText(spAwsSecretAccessKey);
             if (string.IsNullOrEmpty(awsSecretAccessKey))
             {
                 awsSecretAccessKey = cp.ServerConfig.awsSecretAccessKey;
             }
             //
             // -- settings
             string awsSQSBounceEmailQueueEndpoint = cp.Site.GetText(spAwsSQSBounceEmailQueueEndpoint);
             //
             // -- setup aws client
             AmazonSQSClient       sqsClient             = new AmazonSQSClient(awsAccessKeyId, awsSecretAccessKey, Amazon.RegionEndpoint.USEast1);
             ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest {
                 QueueUrl            = awsSQSBounceEmailQueueEndpoint,
                 MaxNumberOfMessages = 10
             };
             //
             // -- download a message from queue, process and repeat until no more
             while (true)
             {
                 ReceiveMessageResponse receiveMessageResponse = sqsClient.ReceiveMessage(receiveMessageRequest);
                 if (receiveMessageResponse.Messages.Count == 0)
                 {
                     //
                     // -- no message, exit loop
                     break;
                 }
                 foreach (Message msg in receiveMessageResponse.Messages)
                 {
                     //
                     // -- convert the Amazon SNS message into a JSON object.
                     AmazonSqsNotification notification = Newtonsoft.Json.JsonConvert.DeserializeObject <AmazonSqsNotification>(msg.Body);
                     if (notification.type == "Notification")
                     {
                         //
                         // -- process SES bounce notification.
                         AmazonSesBounceNotification message = Newtonsoft.Json.JsonConvert.DeserializeObject <AmazonSesBounceNotification>(notification.message);
                         processSesBounceNotificationMessage(cp, message);
                     }
                     else if (notification.type == null)
                     {
                         //
                         // --unknown type, assume valid message
                         AmazonSesBounceNotification message = Newtonsoft.Json.JsonConvert.DeserializeObject <AmazonSesBounceNotification>(msg.Body);
                         processSesBounceNotificationMessage(cp, message);
                     }
                     //
                     // -- delete the processed message from the SES queue
                     var deleteMessageRequest = new DeleteMessageRequest {
                         QueueUrl      = awsSQSBounceEmailQueueEndpoint,
                         ReceiptHandle = msg.ReceiptHandle
                     };
                     sqsClient.DeleteMessage(deleteMessageRequest);
                 }
             }
             //
             // -- transient bounces beyond the grace period - convert to permanent failures
             using (CPCSBaseClass cs = cp.CSNew()) {
                 if (cs.Open("email bounce list", "(transient=1)and(transientFixDeadline<" + cp.Db.EncodeSQLDate(DateTime.Now) + ")"))
                 {
                     do
                     {
                         permanentFail(cp, cs.GetText("name"), DateTime.Now.ToString() + " converted from transient to permanent because grace period past with no action, original failure[" + cs.GetText("details") + "]");
                         cs.GoNext();
                     } while (cs.OK());
                 }
                 cs.Close();
             }
         }
         return(string.Empty);
     } catch (Exception ex) {
         cp.Site.ErrorReport(ex);
         return(string.Empty);
     }
 }
示例#21
0
        //
        // ====================================================================================================

        public static string getAddonNode(CPBaseClass cp, int addonid, ref string Return_IncludeModuleGuidList, ref string Return_IncludeSharedStyleGuidList)
        {
            string result = "";

            try {
                using (CPCSBaseClass CS = cp.CSNew()) {
                    if (CS.OpenRecord("Add-ons", addonid))
                    {
                        string addonName      = CS.GetText("name");
                        bool   processRunOnce = CS.GetBoolean("ProcessRunOnce");
                        if (((Strings.LCase(addonName) == "oninstall") | (Strings.LCase(addonName) == "_oninstall")))
                        {
                            processRunOnce = true;
                        }
                        //
                        // content
                        result += ExportController.getNode("Copy", CS.GetText("Copy"));
                        result += ExportController.getNode("CopyText", CS.GetText("CopyText"));
                        //
                        // DLL
                        result += ExportController.getNode("ActiveXProgramID", CS.GetText("objectprogramid"), true);
                        result += ExportController.getNode("DotNetClass", CS.GetText("DotNetClass"));
                        //
                        // Features
                        result += ExportController.getNode("ArgumentList", CS.GetText("ArgumentList"));
                        result += ExportController.getNodeLookupContentName(cp, "instanceSettingPrimaryContentId", CS.GetInteger("instanceSettingPrimaryContentId"), "content");
                        result += ExportController.getNode("AsAjax", CS.GetBoolean("AsAjax"));
                        result += ExportController.getNode("Filter", CS.GetBoolean("Filter"));
                        result += ExportController.getNode("Help", CS.GetText("Help"));
                        result += ExportController.getNode("HelpLink", CS.GetText("HelpLink"));
                        result += System.Environment.NewLine + "\t" + "<Icon Link=\"" + CS.GetText("iconfilename") + "\" width=\"" + CS.GetInteger("iconWidth") + "\" height=\"" + CS.GetInteger("iconHeight") + "\" sprites=\"" + CS.GetInteger("iconSprites") + "\" />";
                        result += ExportController.getNode("InIframe", CS.GetBoolean("InFrame"));
                        result += ExportController.getNode("BlockEditTools", CS.GetBoolean("BlockEditTools"));
                        result += ExportController.getNode("AliasList", CS.GetText("aliasList"));
                        //
                        // -- Form XML
                        result += ExportController.getNode("FormXML", CS.GetText("FormXML"));
                        //
                        // -- addon dependencies
                        using (CPCSBaseClass CS2 = cp.CSNew()) {
                            CS2.Open("Add-on Include Rules", "addonid=" + addonid);
                            while (CS2.OK())
                            {
                                int IncludedAddonID = CS2.GetInteger("IncludedAddonID");
                                using (CPCSBaseClass CS3 = cp.CSNew()) {
                                    CS3.Open("Add-ons", "ID=" + IncludedAddonID);
                                    if (CS3.OK())
                                    {
                                        string Guid = CS3.GetText("ccGuid");
                                        if (Guid == "")
                                        {
                                            Guid = cp.Utils.CreateGuid();
                                            CS3.SetField("ccGuid", Guid);
                                        }
                                        result += System.Environment.NewLine + "\t" + "<IncludeAddon name=\"" + System.Net.WebUtility.HtmlEncode(CS3.GetText("name")) + "\" guid=\"" + Guid + "\"/>";
                                    }
                                    CS3.Close();
                                }
                                CS2.GoNext();
                            }
                            CS2.Close();
                        }
                        //
                        // -- is inline/block
                        result += ExportController.getNode("IsInline", CS.GetBoolean("IsInline"));
                        //
                        // -- javascript (xmlnode may not match Db filename)
                        result += ExportController.getNode("JavascriptInHead", CS.GetText("JSFilename"));
                        result += ExportController.getNode("javascriptForceHead", CS.GetBoolean("javascriptForceHead"));
                        result += ExportController.getNode("JSHeadScriptSrc", CS.GetText("JSHeadScriptSrc"));
                        //
                        // -- javascript deprecated
                        result += ExportController.getNode("JSBodyScriptSrc", CS.GetText("JSBodyScriptSrc"), true);
                        result += ExportController.getNode("JavascriptBodyEnd", CS.GetText("JavascriptBodyEnd"), true);
                        result += ExportController.getNode("JavascriptOnLoad", CS.GetText("JavascriptOnLoad"), true);
                        //
                        // -- Placements
                        result += ExportController.getNode("Content", CS.GetBoolean("Content"));
                        result += ExportController.getNode("Template", CS.GetBoolean("Template"));
                        result += ExportController.getNode("Email", CS.GetBoolean("Email"));
                        result += ExportController.getNode("Admin", CS.GetBoolean("Admin"));
                        result += ExportController.getNode("OnPageEndEvent", CS.GetBoolean("OnPageEndEvent"));
                        result += ExportController.getNode("OnPageStartEvent", CS.GetBoolean("OnPageStartEvent"));
                        result += ExportController.getNode("OnBodyStart", CS.GetBoolean("OnBodyStart"));
                        result += ExportController.getNode("OnBodyEnd", CS.GetBoolean("OnBodyEnd"));
                        result += ExportController.getNode("RemoteMethod", CS.GetBoolean("RemoteMethod"));
                        result += CS.FieldOK("Diagnostic") ? ExportController.getNode("Diagnostic", CS.GetBoolean("Diagnostic")) : "";
                        //
                        // -- Presentation
                        result += ExportController.getNode("category", CS.GetText("addoncategoryid"));
                        //
                        // -- Process
                        result += ExportController.getNode("ProcessRunOnce", processRunOnce);
                        result += ExportController.getNode("ProcessInterval", CS.GetInteger("ProcessInterval"));
                        //
                        // Meta
                        //
                        result += ExportController.getNode("MetaDescription", CS.GetText("MetaDescription"));
                        result += ExportController.getNode("OtherHeadTags", CS.GetText("OtherHeadTags"));
                        result += ExportController.getNode("PageTitle", CS.GetText("PageTitle"));
                        result += ExportController.getNode("RemoteAssetLink", CS.GetText("RemoteAssetLink"));
                        //
                        // Styles
                        string Styles = "";
                        if (!CS.GetBoolean("BlockDefaultStyles"))
                        {
                            Styles = CS.GetText("StylesFilename").Trim();
                        }
                        string StylesTest = CS.GetText("CustomStylesFilename").Trim();
                        if (StylesTest != "")
                        {
                            if (Styles != "")
                            {
                                Styles = Styles + System.Environment.NewLine + StylesTest;
                            }
                            else
                            {
                                Styles = StylesTest;
                            }
                        }
                        result += ExportController.getNode("Styles", Styles);
                        result += ExportController.getNode("styleslinkhref", CS.GetText("styleslinkhref"));
                        //
                        //
                        // Scripting
                        //
                        string NodeInnerText = CS.GetText("ScriptingCode").Trim();
                        if (NodeInnerText != "")
                        {
                            NodeInnerText = System.Environment.NewLine + "\t" + "\t" + "<Code>" + ExportController.EncodeCData(NodeInnerText) + "</Code>";
                        }
                        using (CPCSBaseClass CS2 = cp.CSNew()) {
                            CS2.Open("Add-on Scripting Module Rules", "addonid=" + addonid);
                            while (CS2.OK())
                            {
                                int ScriptingModuleID = CS2.GetInteger("ScriptingModuleID");
                                using (CPCSBaseClass CS3 = cp.CSNew()) {
                                    CS3.Open("Scripting Modules", "ID=" + ScriptingModuleID);
                                    if (CS3.OK())
                                    {
                                        string Guid = CS3.GetText("ccGuid");
                                        if (Guid == "")
                                        {
                                            Guid = cp.Utils.CreateGuid();
                                            CS3.SetField("ccGuid", Guid);
                                        }
                                        Return_IncludeModuleGuidList = Return_IncludeModuleGuidList + System.Environment.NewLine + Guid;
                                        NodeInnerText = NodeInnerText + System.Environment.NewLine + "\t" + "\t" + "<IncludeModule name=\"" + System.Net.WebUtility.HtmlEncode(CS3.GetText("name")) + "\" guid=\"" + Guid + "\"/>";
                                    }
                                    CS3.Close();
                                }
                                CS2.GoNext();
                            }
                            CS2.Close();
                        }
                        if (NodeInnerText == "")
                        {
                            result += System.Environment.NewLine + "\t" + "<Scripting Language=\"" + CS.GetText("ScriptingLanguageID") + "\" EntryPoint=\"" + CS.GetText("ScriptingEntryPoint") + "\" Timeout=\"" + CS.GetText("ScriptingTimeout") + "\"/>";
                        }
                        else
                        {
                            result += System.Environment.NewLine + "\t" + "<Scripting Language=\"" + CS.GetText("ScriptingLanguageID") + "\" EntryPoint=\"" + CS.GetText("ScriptingEntryPoint") + "\" Timeout=\"" + CS.GetText("ScriptingTimeout") + "\">" + NodeInnerText + System.Environment.NewLine + "\t" + "</Scripting>";
                        }
                        //
                        // Shared Styles
                        //
                        using (CPCSBaseClass CS2 = cp.CSNew()) {
                            CS2.Open("Shared Styles Add-on Rules", "addonid=" + addonid);
                            while (CS2.OK())
                            {
                                int styleId = CS2.GetInteger("styleId");
                                using (CPCSBaseClass CS3 = cp.CSNew()) {
                                    CS3.Open("shared styles", "ID=" + styleId);
                                    if (CS3.OK())
                                    {
                                        string Guid = CS3.GetText("ccGuid");
                                        if (Guid == "")
                                        {
                                            Guid = cp.Utils.CreateGuid();
                                            CS3.SetField("ccGuid", Guid);
                                        }
                                        Return_IncludeSharedStyleGuidList = Return_IncludeSharedStyleGuidList + System.Environment.NewLine + Guid;
                                        result += System.Environment.NewLine + "\t" + "<IncludeSharedStyle name=\"" + System.Net.WebUtility.HtmlEncode(CS3.GetText("name")) + "\" guid=\"" + Guid + "\"/>";
                                    }
                                    CS3.Close();
                                }
                                CS2.GoNext();
                            }
                            CS2.Close();
                        }
                        //
                        // Process Triggers
                        //
                        NodeInnerText = "";
                        using (CPCSBaseClass CS2 = cp.CSNew()) {
                            CS2.Open("Add-on Content Trigger Rules", "addonid=" + addonid);
                            while (CS2.OK())
                            {
                                int TriggerContentID = CS2.GetInteger("ContentID");
                                using (CPCSBaseClass CS3 = cp.CSNew()) {
                                    CS3.Open("content", "ID=" + TriggerContentID);
                                    if (CS3.OK())
                                    {
                                        string Guid = CS3.GetText("ccGuid");
                                        if (Guid == "")
                                        {
                                            Guid = cp.Utils.CreateGuid();
                                            CS3.SetField("ccGuid", Guid);
                                        }
                                        NodeInnerText = NodeInnerText + System.Environment.NewLine + "\t" + "\t" + "<ContentChange name=\"" + System.Net.WebUtility.HtmlEncode(CS3.GetText("name")) + "\" guid=\"" + Guid + "\"/>";
                                    }
                                    CS3.Close();
                                }
                                CS2.GoNext();
                            }
                            CS2.Close();
                        }
                        if (NodeInnerText != "")
                        {
                            result += System.Environment.NewLine + "\t" + "<ProcessTriggers>" + NodeInnerText + System.Environment.NewLine + "\t" + "</ProcessTriggers>";
                        }
                        //
                        // Editors
                        //
                        if (cp.Content.IsField("Add-on Content Field Type Rules", "id"))
                        {
                            NodeInnerText = "";
                            using (CPCSBaseClass CS2 = cp.CSNew()) {
                                CS2.Open("Add-on Content Field Type Rules", "addonid=" + addonid);
                                while (CS2.OK())
                                {
                                    int    fieldTypeID = CS2.GetInteger("contentFieldTypeID");
                                    string fieldType   = cp.Content.GetRecordName("Content Field Types", fieldTypeID);
                                    if (fieldType != "")
                                    {
                                        NodeInnerText = NodeInnerText + System.Environment.NewLine + "\t" + "\t" + "<type>" + fieldType + "</type>";
                                    }
                                    CS2.GoNext();
                                }
                                CS2.Close();
                            }
                            if (NodeInnerText != "")
                            {
                                result += System.Environment.NewLine + "\t" + "<Editors>" + NodeInnerText + System.Environment.NewLine + "\t" + "</Editors>";
                            }
                        }
                        //
                        string addonGuid = CS.GetText("ccGuid");
                        if ((string.IsNullOrWhiteSpace(addonGuid)))
                        {
                            addonGuid = cp.Utils.CreateGuid();
                            CS.SetField("ccGuid", addonGuid);
                        }
                        string NavType = CS.GetText("NavTypeID");
                        if ((NavType == ""))
                        {
                            NavType = "Add-on";
                        }
                        result = ""
                                 + System.Environment.NewLine + "\t" + "<Addon name=\"" + System.Net.WebUtility.HtmlEncode(addonName) + "\" guid=\"" + addonGuid + "\" type=\"" + NavType + "\">"
                                 + ExportController.tabIndent(cp, result)
                                 + System.Environment.NewLine + "\t" + "</Addon>";
                    }
                    CS.Close();
                }
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex, "GetAddonNode");
            }
            return(result);
        }
示例#22
0
        //
        //====================================================================================================
        /// <summary>
        /// save the instance properties to a record with matching id. If id is not provided, a new record is created.
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        protected int save(CPBaseClass cp)
        {
            try
            {
                CPCSBaseClass cs           = cp.CSNew();
                Type          instanceType = this.GetType();
                string        contentName  = derivedContentName(instanceType);
                string        tableName    = derivedContentTableName(instanceType);
                if ((id > 0))
                {
                    if (!cs.Open(contentName, "id=" + id))
                    {
                        string message = "Unable to open record in content [" + contentName + "], with id [" + id + "]";
                        cs.Close();
                        id = 0;
                        throw new ApplicationException(message);
                    }
                }
                else
                {
                    if (!cs.Insert(contentName))
                    {
                        cs.Close();
                        id = 0;
                        throw new ApplicationException("Unable to insert record in content [" + contentName + "]");
                    }
                }
                foreach (PropertyInfo resultProperty in this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public))
                {
                    switch (resultProperty.Name.ToLower())
                    {
                    case "id":
                        id = cs.GetInteger("id");
                        break;

                    case "ccguid":
                        if ((string.IsNullOrEmpty(ccguid)))
                        {
                            ccguid = Guid.NewGuid().ToString();
                        }
                        string value = null;
                        value = resultProperty.GetValue(this, null).ToString();
                        cs.SetField(resultProperty.Name, value);
                        break;

                    default:
                        switch (resultProperty.PropertyType.Name)
                        {
                        case "Int32":
                            int integerValue = 0;
                            int.TryParse(resultProperty.GetValue(this, null).ToString(), out integerValue);
                            cs.SetField(resultProperty.Name, integerValue.ToString());
                            break;

                        case "Boolean":
                            bool booleanValue = false;
                            bool.TryParse(resultProperty.GetValue(this, null).ToString(), out booleanValue);
                            cs.SetField(resultProperty.Name, booleanValue.ToString());
                            break;

                        case "DateTime":
                            System.DateTime dateValue = default(System.DateTime);
                            System.DateTime.TryParse(resultProperty.GetValue(this, null).ToString(), out dateValue);
                            cs.SetField(resultProperty.Name, dateValue.ToString());
                            break;

                        case "Double":
                            double doubleValue = 0;
                            double.TryParse(resultProperty.GetValue(this, null).ToString(), out doubleValue);
                            cs.SetField(resultProperty.Name, doubleValue.ToString());
                            break;

                        default:
                            string stringValue = resultProperty.GetValue(this, null).ToString();
                            cs.SetField(resultProperty.Name, stringValue);
                            break;
                        }
                        break;
                    }
                }
                cs.Close();
            }
            catch (Exception ex)
            {
                cp.Site.ErrorReport(ex);
                throw;
            }
            return(id);
        }
示例#23
0
        //
        //====================================================================================================
        /// <summary>
        /// render the report
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public string getHtml(CPBaseClass cp)
        {
            StringBuilder rowBuilder = new StringBuilder("");
            //string classAttribute;
            //string content;
            //string userErrors;
            string   sortLink;
            string   columnSort         = cp.Doc.GetText("columnSort");
            string   csvDownloadContent = "";
            DateTime rightNow           = DateTime.Now;

            //
            if (!localFrameRqsSet)
            {
                refreshQueryString = cp.Doc.RefreshQueryString;
            }
            if (!localFormActionQueryStringSet)
            {
                // set locals not public property bc public also sets the includeForm
                localFormActionQueryString    = localFrameRqs;
                localFormActionQueryStringSet = true;
                //formActionQueryString = localFrameRqs;
            }
            //
            // add user errors
            //
            string userErrors = cp.Utils.EncodeText(cp.UserError.GetList());

            if (!string.IsNullOrEmpty(userErrors))
            {
                warning = userErrors;
            }
            int           colPtr;
            int           colPtrDownload;
            StringBuilder result = new StringBuilder("");

            //
            // headers
            //
            if (captionIncluded)
            {
                rowBuilder = new StringBuilder("");
                for (colPtr = 0; colPtr <= columnMax; colPtr++)
                {
                    if (columns[colPtr].visible)
                    {
                        string classAttribute = columns[colPtr].captionClass;
                        if (classAttribute != "")
                        {
                            classAttribute = " class=\"" + classAttribute + "\"";
                        }
                        string content   = columns[colPtr].caption;
                        string sortField = columns[colPtr].name;
                        if (content == "")
                        {
                            content = "&nbsp;";
                        }
                        else if (columns[colPtr].sortable)
                        {
                            if (localFrameRqsSet)
                            {
                                sortLink = "?" + localFrameRqs + "&columnSort=" + sortField;
                            }
                            else
                            {
                                sortLink = "?" + cp.Doc.RefreshQueryString + "&columnSort=" + sortField;
                            }
                            if (columnSort == sortField)
                            {
                                sortLink += "Desc";
                            }
                            content = "<a href=\"" + sortLink + "\">" + content + "</a>";
                        }
                        string styleAttribute = "";
                        if (columns[colPtr].columnWidthPercent > 0)
                        {
                            styleAttribute = " style=\"width:" + columns[colPtr].columnWidthPercent.ToString() + "%;\"";
                        }
                        //row += Constants.cr + "<td" + classAttribute + styleAttribute + ">" + localReportCells[rowPtr, colPtr] + "</td>";
                        rowBuilder.Append(Constants.cr + "<th" + classAttribute + styleAttribute + ">" + content + "</th>");
                    }
                }
                result.Append(""
                              + Constants.cr + "<thead>"
                              + Constants.cr2 + "<tr>"
                              + indent(indent(rowBuilder.ToString()))
                              + Constants.cr2 + "</tr>"
                              + Constants.cr + "</thead>"
                              + "");
                if (addCsvDownloadCurrentPage)
                {
                    colPtrDownload = 0;
                    for (colPtr = 0; colPtr <= columnMax; colPtr++)
                    {
                        if (columns[colPtr].downloadable)
                        {
                            if (colPtrDownload == 0)
                            {
                                csvDownloadContent += "\"" + columns[colPtr].caption.Replace("\"", "\"\"") + "\"";
                            }
                            else
                            {
                                csvDownloadContent += ",\"" + columns[colPtr].caption.Replace("\"", "\"\"") + "\"";
                            }
                            colPtrDownload += 1;
                        }
                    }
                }
            }
            //
            // body
            //
            rowBuilder = new StringBuilder("");
            if (localIsEmptyReport)
            {
                string classAttribute = columns[0].cellClass;
                if (classAttribute != "")
                {
                    classAttribute = " class=\"" + classAttribute + "\"";
                }
                //row = Constants.cr + "<td style=\"text-align:left\" " + classAttribute + " colspan=\"" + (columnMax + 1) + "\">[empty]</td>";
                rowBuilder.Append(""
                                  + Constants.cr + "<tr>"
                                  + Constants.cr + "<td style=\"text-align:left\" " + classAttribute + " colspan=\"" + (columnMax + 1) + "\">[empty]</td>"
                                  + Constants.cr + "</tr>");
            }
            else if (ReportTooLong)
            {
                // -- report is too long
                string classAttribute = columns[0].cellClass;
                if (classAttribute != "")
                {
                    classAttribute = " class=\"" + classAttribute + "\"";
                }
                //row = Constants.cr + "<td style=\"text-align:left\" " + classAttribute + " colspan=\"" + (columnMax + 1) + "\">There are too many rows in this report. Please consider filtering the data.</td>";
                rowBuilder.Append(""
                                  + Constants.cr + "<tr>"
                                  + Constants.cr + "<td style=\"text-align:left\" " + classAttribute + " colspan=\"" + (columnMax + 1) + "\">There are too many rows in this report. Please consider filtering the data.</td>"
                                  + Constants.cr + "</tr>");
            }
            else
            {
                // -- display th report
                for (int rowPtr = 0; rowPtr <= rowCnt; rowPtr++)
                {
                    string row = "";
                    colPtrDownload = 0;
                    int colVisibleCnt = 0;
                    for (colPtr = 0; colPtr <= columnMax; colPtr++)
                    {
                        if (columns[colPtr].visible)
                        {
                            colVisibleCnt++;
                            string classAttribute2 = columns[colPtr].cellClass;
                            if (!string.IsNullOrEmpty(classAttribute2))
                            {
                                classAttribute2 = " class=\"" + classAttribute2 + "\"";
                            }
                            string rowContent = localReportCells[rowPtr, colPtr];
                            if ((colVisibleCnt == 1) && rowEllipseMenuDict.ContainsKey(rowPtr))
                            {
                                //
                                // -- add ellipse menu
                                EllipseMenuDataModel ellipseMenu = new EllipseMenuDataModel {
                                    menuId   = rowPtr,
                                    content  = rowContent,
                                    hasMenu  = true,
                                    menuList = new List <EllipseMenuDataItemModel>()
                                };
                                foreach (var menuItem in rowEllipseMenuDict[rowPtr])
                                {
                                    ellipseMenu.menuList.Add(new EllipseMenuDataItemModel {
                                        menuName = menuItem.name,
                                        menuHref = menuItem.url
                                    });
                                }
                                rowContent = cp.Mustache.Render(Properties.Resources.ellipseMenu, ellipseMenu);
                            }
                            row += Constants.cr + "<td" + classAttribute2 + ">" + rowContent + "</td>";
                        }
                        if (addCsvDownloadCurrentPage && !localExcludeRowFromDownload[rowPtr])
                        {
                            if (columns[colPtr].downloadable)
                            {
                                if (colPtrDownload == 0)
                                {
                                    csvDownloadContent += Environment.NewLine;
                                }
                                else
                                {
                                    csvDownloadContent += ",";
                                }
                                if (!string.IsNullOrEmpty(localDownloadData[rowPtr, colPtr]))
                                {
                                    csvDownloadContent += "\"" + localDownloadData[rowPtr, colPtr].Replace("\"", "\"\"") + "\"";
                                }
                                colPtrDownload += 1;
                            }
                        }
                    }
                    string classAttribute = localRowClasses[rowPtr];
                    if (rowPtr % 2 != 0)
                    {
                        classAttribute += " afwOdd";
                    }
                    if (classAttribute != "")
                    {
                        classAttribute = " class=\"" + classAttribute + "\"";
                    }
                    rowBuilder.Append(""
                                      + Constants.cr + "<tr" + classAttribute + ">"
                                      + indent(row)
                                      + Constants.cr + "</tr>");
                }
            }
            string csvDownloadFilename = string.Empty;

            if (addCsvDownloadCurrentPage)
            {
                //
                // todo implement cp.db.CreateCsv()
                // 5.1 -- download
                CPCSBaseClass csDownloads = cp.CSNew();
                if (csDownloads.Insert("downloads"))
                {
                    csvDownloadFilename = csDownloads.GetFilename("filename", "export.csv");
                    cp.CdnFiles.Save(csvDownloadFilename, csvDownloadContent);
                    csDownloads.SetField("name", "Download for [" + title + "], requested by [" + cp.User.Name + "]");
                    csDownloads.SetField("requestedBy", cp.User.Id.ToString());
                    csDownloads.SetField("filename", csvDownloadFilename);
                    csDownloads.SetField("dateRequested", DateTime.Now.ToString());
                    csDownloads.SetField("datecompleted", DateTime.Now.ToString());
                    csDownloads.SetField("resultmessage", "Completed");
                    csDownloads.Save();
                }
                csDownloads.Close();
            }
            result.Append(""
                          + Constants.cr + "<tbody>"
                          + indent(rowBuilder.ToString())
                          + Constants.cr + "</tbody>"
                          + "");
            result = new StringBuilder(Constants.cr + "<table class=\"afwListReportTable\">" + indent(result.ToString()) + Constants.cr + "</table>");
            if (htmlLeftOfTable != "")
            {
                result = new StringBuilder(""
                                           + Constants.cr + "<div class=\"afwLeftSideHtml\">" + indent(htmlLeftOfTable) + Constants.cr + "</div>"
                                           + Constants.cr + "<div class=\"afwRightSideHtml\">" + indent(result.ToString()) + Constants.cr + "</div>"
                                           + Constants.cr + "<div style=\"clear:both\"></div>"
                                           + "");
            }
            if (htmlBeforeTable != "")
            {
                result.Insert(0, "<div class=\"afwBeforeHtml\">" + htmlBeforeTable + "</div>");
            }
            if (htmlAfterTable != "")
            {
                result.Append("<div class=\"afwAfterHtml\">" + htmlAfterTable + "</div>");
            }
            //
            // headers
            //
            if (addCsvDownloadCurrentPage && (!string.IsNullOrEmpty(csvDownloadFilename)))
            {
                result = new StringBuilder(Constants.cr + "<p id=\"afwDescription\"><a href=\"" + cp.Http.CdnFilePathPrefix + csvDownloadFilename + "\">Click here</a> to download the data.</p>" + result.ToString());
            }
            if (description != "")
            {
                result = new StringBuilder(Constants.cr + "<p id=\"afwDescription\">" + description + "</p>" + result.ToString());
            }
            if (warning != "")
            {
                result = new StringBuilder(Constants.cr + "<div id=\"afwWarning\">" + warning + "</div>" + result.ToString());
            }
            if (title != "")
            {
                result = new StringBuilder(Constants.cr + "<h2 id=\"afwTitle\">" + title + "</h2>" + result.ToString());
            }
            //
            // add form
            //
            if (localIncludeForm)
            {
                if (localButtonList != "")
                {
                    localButtonList = ""
                                      + Constants.cr + "<div class=\"afwButtonCon\">"
                                      + indent(localButtonList)
                                      + Constants.cr + "</div>";
                }
                result = new StringBuilder(Constants.cr + cp.Html.Form(localButtonList + result.ToString() + localButtonList + localHiddenList, "", "", "", localFormActionQueryString, ""));
            }
            if (_includeBodyPadding)
            {
                result = new StringBuilder(cp.Html.div(result.ToString(), "", "afwBodyPad", ""));
            }
            ;
            if (_includeBodyColor)
            {
                result = new StringBuilder(cp.Html.div(result.ToString(), "", "afwBodyColor", ""));
            }
            ;
            //
            // if outer container, add styles and javascript
            //
            if (localIsOuterContainer)
            {
                cp.Doc.AddHeadJavascript(Properties.Resources.javascript);
                cp.Doc.AddHeadStyle(Properties.Resources.styles);
                result = new StringBuilder(""
                                           + Constants.cr + "<div id=\"afw\">"
                                           + indent(result.ToString())
                                           + Constants.cr + "</div>");
            }
            //
            // -- set the optional title of the portal subnav
            if (!string.IsNullOrEmpty(portalSubNavTitle))
            {
                cp.Doc.SetProperty("portalSubNavTitle", portalSubNavTitle);
            }
            return(result.ToString());
        }
示例#24
0
 //====================================================================================================
 /// <summary>
 /// Return a portal object read from the Db based on the portal guid argument
 /// </summary>
 /// <param name="cp"></param>
 /// <param name="portalRecordGuid"></param>
 /// <returns></returns>
 public static PortalDataModel create(CPBaseClass CP, int portalId)
 {
     try {
         PortalDataModel result = new PortalDataModel {
             featureList = new Dictionary <string, PortalDataFeatureModel>()
         };
         using (CPCSBaseClass portalCs = CP.CSNew()) {
             string defaultConfigJson;
             if (!portalCs.Open("portals", (portalId == 0 ? "" : "id=" + portalId), "id", true, "", 9999, 1))
             {
                 //
                 // -- no portals found, create demo portal
                 portalCs.Close();
                 result.name        = "Empty";
                 result.guid        = "";
                 result.id          = 0;
                 result.featureList = new Dictionary <string, PortalDataFeatureModel>();
                 PortalDataFeatureModel feature = new PortalDataFeatureModel {
                     addonId         = 0,
                     dataContentId   = 0,
                     guid            = "",
                     heading         = "Sample",
                     id              = 0,
                     name            = "Demo",
                     parentFeatureId = 0,
                     sortOrder       = ""
                 };
                 return(result);
             }
             //
             // -- load selected portal
             result.name = portalCs.GetText("name");
             result.guid = portalCs.GetText("ccguid");
             result.id   = portalCs.GetInteger("id");
             int portalDefaultFeatureId = portalCs.GetInteger("defaultFeatureId");
             defaultConfigJson = portalCs.GetText("defaultConfigJson");
             portalCs.Close();
             //
             // -- portal links
             result.linkedPortals = new List <PortalDataModel>();
             string sql = "select p.id,p.ccguid,p.name from ccPortals p left join ccPortalLinks l on l.toPortalId=p.id where p.active>0 and l.fromPortalId=" + result.id;
             if (portalCs.OpenSQL(sql))
             {
                 do
                 {
                     int linkedPortalId = portalCs.GetInteger("id");
                     if (!result.id.Equals(linkedPortalId))
                     {
                         PortalDataModel linkedPortal = new PortalDataModel {
                             id   = linkedPortalId,
                             name = portalCs.GetText("name")
                         };
                         result.linkedPortals.Add(linkedPortal);
                     }
                     portalCs.GoNext();
                 } while (portalCs.OK());
             }
             portalCs.Close();
             //
             // -- load features and subfeatures
             string featureSql = ""
                                 + " select"
                                 + " f.id,f.name,f.heading,f.sortOrder,f.addPadding,f.ccguid,f.addonId,f.dataContentId,f.parentFeatureId,"
                                 + " sub.id as subId,sub.name as subName,sub.heading as subheading,sub.sortOrder as subSortOrder,sub.addPadding as subAddPadding,sub.ccguid as subccGuid,sub.addonId as subAddonId,sub.dataContentId as subdatacontentid,sub.parentFeatureId as subparentFeatureId"
                                 + " from ccPortalFeatures f left join ccPortalFeatures sub on sub.parentFeatureId=f.id "
                                 + " where (f.active>0) and ((sub.active is null)or(sub.active>0))and f.portalid=" + portalId
                                 + " order by f.sortOrder,f.name,sub.name";
             using (CPCSBaseClass csFeature = CP.CSNew()) {
                 if (csFeature.OpenSQL(featureSql))
                 {
                     //
                     // -- load features from Db
                     int lastFeatureId = 0;
                     PortalDataFeatureModel feature = null;
                     do
                     {
                         if (lastFeatureId != csFeature.GetInteger("id"))
                         {
                             //
                             // -- new feature, load the feature
                             feature = new PortalDataFeatureModel {
                                 id                = csFeature.GetInteger("id"),
                                 name              = csFeature.GetText("name"),
                                 heading           = (string.IsNullOrEmpty(csFeature.GetText("heading")) ? csFeature.GetText("name") : csFeature.GetText("heading")),
                                 sortOrder         = csFeature.GetText("sortOrder"),
                                 addPadding        = csFeature.GetBoolean("addPadding"),
                                 guid              = csFeature.GetText("ccguid"),
                                 addonId           = csFeature.GetInteger("addonId"),
                                 dataContentId     = csFeature.GetInteger("dataContentId"),
                                 parentFeatureId   = csFeature.GetInteger("parentFeatureId"),
                                 subFeatureList    = new List <PortalDataFeatureModel>(),
                                 addonGuid         = "",
                                 dataContentGuid   = "",
                                 parentFeatureGuid = ""
                             };
                             //
                             // -- add the new feature to the list
                             string featureGuid = csFeature.GetText("ccguid");
                             if (result.featureList.ContainsKey(featureGuid))
                             {
                                 //
                                 // -- data error, duplicate features
                                 CP.Site.ErrorReport("Portal Error, 2 portal features with the same guid [" + featureGuid + "]");
                             }
                             else
                             {
                                 result.featureList.Add(featureGuid, feature);
                                 if (result.defaultFeature == null)
                                 {
                                     result.defaultFeature = feature;
                                 }
                                 if (portalDefaultFeatureId == feature.id)
                                 {
                                     result.defaultFeature = feature;
                                 }
                             }
                         }
                         //
                         // -- load subfeatures
                         int subFeatureId = csFeature.GetInteger("subid");
                         if (subFeatureId > 0)
                         {
                             PortalDataFeatureModel subFeature = new PortalDataFeatureModel {
                                 id              = subFeatureId,
                                 name            = csFeature.GetText("subname"),
                                 heading         = (string.IsNullOrEmpty(csFeature.GetText("subheading")) ? csFeature.GetText("subname") : csFeature.GetText("subheading")),
                                 sortOrder       = csFeature.GetText("subsortOrder"),
                                 addPadding      = csFeature.GetBoolean("subaddPadding"),
                                 guid            = csFeature.GetText("subccguid"),
                                 addonId         = csFeature.GetInteger("subaddonId"),
                                 dataContentId   = csFeature.GetInteger("subdataContentId"),
                                 parentFeatureId = csFeature.GetInteger("subparentFeatureId"),
                             };
                             feature.subFeatureList.Add(subFeature);
                         }
                         lastFeatureId = csFeature.GetInteger("id");
                         csFeature.GoNext();
                     } while (csFeature.OK());
                     csFeature.Close();
                     //
                     // -- populate parentFeatureGuid from parentFeatureId
                     foreach (var kvp in result.featureList)
                     {
                         PortalDataFeatureModel testFeature = kvp.Value;
                         if ((testFeature.parentFeatureId > 0) && string.IsNullOrEmpty(testFeature.parentFeatureGuid))
                         {
                             foreach (var searchFeature in  result.featureList)
                             {
                                 if (testFeature.parentFeatureId == searchFeature.Value.id)
                                 {
                                     //
                                     testFeature.parentFeatureGuid = searchFeature.Value.guid;
                                     break;
                                 }
                             }
                         }
                     }
                     return(result);
                 }
             }
             //
             // -- no features found, load default portal features
             if (string.IsNullOrEmpty(defaultConfigJson))
             {
                 //
                 // no default, fake a tab
                 //
                 result.featureList = new Dictionary <string, PortalDataFeatureModel>();
                 PortalDataFeatureModel feature = new PortalDataFeatureModel {
                     addonId         = 0,
                     dataContentId   = 0,
                     guid            = "",
                     heading         = "Sample",
                     id              = 0,
                     name            = "Demo",
                     parentFeatureId = 0,
                     sortOrder       = "",
                     addPadding      = false
                 };
                 return(result);
             }
             //
             // legacy - load features from portal record alone
             //
             System.Web.Script.Serialization.JavaScriptSerializer msJson = new System.Web.Script.Serialization.JavaScriptSerializer();
             result = msJson.Deserialize <PortalDataModel>(defaultConfigJson);
             savePortalToDb(CP, result);
             //
             using (CPCSBaseClass featureCs = CP.CSNew()) {
                 if (!string.IsNullOrEmpty(result.defaultFeature.guid))
                 {
                     if (featureCs.Open("portal features", "ccguid=" + CP.Db.EncodeSQLText(result.defaultFeature.guid), "", true, "", 9999, 1))
                     {
                         result.defaultFeature = loadPortalFeatureFromCs(CP, featureCs);
                     }
                     featureCs.Close();
                 }
             }
             return(result);
         }
     } catch (Exception ex) {
         CP.Site.ErrorReport(ex, "exception in loadPortal");
         throw;
     }
 }
 //
 //-------------------------------------------------
 // initialize
 //  read the report and column settings from the Db
 //  if no localGuid set, sync to Db does not work
 //  if the report does not exist in teh Db, use the input values
 //-------------------------------------------------
 //
 private void reportDbInit(CPBaseClass cp)
 {
     try {
         int    colPtr;
         string colName;
         string colCaption;
         string colSortOrder;
         string colCaptionClass;
         string colCellClass;
         bool   colSortable     = false;
         bool   colVisible      = true;
         bool   colDownloadable = true;
         string textVisible     = "";
         //string textDownloadable = "";
         CPCSBaseClass cs = cp.CSNew();
         int           reportId;
         string        sqlCriteria;
         //
         if (localGuid != "")
         {
             sqlCriteria = "ccguid=" + cp.Db.EncodeSQLText(localGuid);
             if (!cs.Open("Admin Framework Reports", sqlCriteria, "", true, "", 9999, 1))
             {
                 cs.Close();
                 if (localName == "")
                 {
                     localName = localTitle;
                 }
                 cs.Insert("Admin Framework reports");
                 cs.SetField("ccguid", localGuid);
                 cs.SetField("name", localName);
                 cs.SetField("title", localTitle);
                 //cs.SetField("description", localDescription);
             }
             reportId   = cs.GetInteger("id");
             localName  = cs.GetText("name");
             localTitle = cs.GetText("title");
             //localDescription = cs.GetText("description");
             // tmp solution for reports created with a name and no title
             if ((localTitle == "") && (localName != ""))
             {
                 localTitle = localName;
             }
             cs.Close();
             //
             //
             for (colPtr = 0; colPtr <= columnMax; colPtr++)
             {
                 colCaption      = columns[colPtr].caption;
                 colName         = columns[colPtr].name;
                 colSortOrder    = (colPtr * 10).ToString();
                 colSortOrder    = colSortOrder.PadLeft(4 - colSortOrder.Length, '0');
                 colCaptionClass = columns[colPtr].captionClass;
                 colCellClass    = columns[colPtr].cellClass;
                 colSortable     = columns[colPtr].sortable; // not part of Db config
                 colVisible      = columns[colPtr].visible;
                 colDownloadable = columns[colPtr].downloadable;
                 if (colName == "")
                 {
                     colName = colCaption;
                 }
                 if ((colName != "") && (reportId != 0))
                 {
                     if (!cs.Open("Admin Framework Report Columns", "(reportId=" + reportId.ToString() + ")and(name=" + cp.Db.EncodeSQLText(colName) + ")", "id", true, "", 9999, 1))
                     {
                         cs.Close();
                         cs.Insert("Admin Framework Report Columns");
                         cs.SetField("reportId", reportId.ToString());
                         cs.SetField("name", colName);
                         cs.SetField("caption", colCaption);
                         cs.SetField("sortOrder", colSortOrder);
                         cs.SetField("captionClass", colCaptionClass);
                         cs.SetField("cellClass", colCellClass);
                         cs.SetField("visible", colVisible.ToString());
                         // for another day
                         //cs.SetField("downloadable", colDownloadable.ToString());
                     }
                     else
                     {
                         // tmp - if name but not caption, use the other
                         colCaption = cs.GetText("caption");
                         colName    = cs.GetText("name");
                         if (colCaption == "")
                         {
                             colCaption = colName;
                         }
                         else if (colName == "")
                         {
                             colName = colCaption;
                         }
                         columns[colPtr].name         = colName;
                         columns[colPtr].caption      = colCaption;
                         columns[colPtr].captionClass = cs.GetText("captionClass");
                         columns[colPtr].cellClass    = cs.GetText("cellClass");
                         textVisible = cs.GetText("visible");
                         if (textVisible == "")
                         {
                             cs.SetField("visible", colVisible.ToString());
                         }
                         else
                         {
                             columns[colPtr].visible = cp.Utils.EncodeBoolean(textVisible);
                         }
                         // for another day
                         //textDownloadable = cs.GetText("downloadable");
                         //if (textDownloadable == "")
                         //{
                         //    cs.SetField("downloadable", textDownloadable.ToString());
                         //}
                         //else
                         //{
                         //    columns[colPtr].visible = cp.Utils.EncodeBoolean(textDownloadable);
                         //}
                     }
                     cs.Close();
                 }
             }
         }
     } catch (Exception ex) {
         cp.Site.ErrorReport(ex, "Exception in reportListClass.init");
     }
 }
        //
        //-------------------------------------------------
        // getResult
        //-------------------------------------------------
        //
        public string getHtml(CPBaseClass cp)
        {
            StringBuilder s              = new StringBuilder("");
            string        row            = "";
            StringBuilder rowList        = new StringBuilder("");
            int           rowPtr         = 0;
            int           colPtr         = 0;
            int           colPtrDownload = 0;
            string        styleClass;
            string        content;
            string        userErrors;
            string        sortLink;
            string        columnSort         = cp.Doc.GetText("columnSort");
            string        sortField          = "";
            string        csvDownloadContent = "";
            DateTime      rightNow           = DateTime.Now;

            //
            // initialize - setup Db and/or read Db values
            //
            reportDbInit(cp);
            //
            if (!localFrameRqsSet)
            {
                refreshQueryString = cp.Doc.RefreshQueryString;
            }
            if (!localFormActionQueryStringSet)
            {
                // set locals not public property bc public also sets the includeForm
                localFormActionQueryString    = localFrameRqs;
                localFormActionQueryStringSet = true;
                //formActionQueryString = localFrameRqs;
            }
            //
            // add user errors
            //
            userErrors = cp.Utils.EncodeText(cp.UserError.GetList());
            if (userErrors != "")
            {
                warning = userErrors;
            }
            //
            // headers
            //
            if (formIncludeHeader)
            {
                rowList = new StringBuilder("");
                for (colPtr = 0; colPtr <= columnMax; colPtr++)
                {
                    if (columns[colPtr].visible)
                    {
                        styleClass = columns[colPtr].captionClass;
                        if (styleClass != "")
                        {
                            styleClass = " class=\"" + styleClass + "\"";
                        }
                        content   = columns[colPtr].caption;
                        sortField = columns[colPtr].name;
                        if (content == "")
                        {
                            content = "&nbsp;";
                        }
                        else if (columns[colPtr].sortable)
                        {
                            if (localFrameRqsSet)
                            {
                                sortLink = "?" + localFrameRqs + "&columnSort=" + sortField;
                            }
                            else
                            {
                                sortLink = "?" + cp.Doc.RefreshQueryString + "&columnSort=" + sortField;
                            }
                            if (columnSort == sortField)
                            {
                                sortLink += "Desc";
                            }
                            content = "<a href=\"" + sortLink + "\">" + content + "</a>";
                        }
                        rowList.Append(cr + "<th" + styleClass + ">" + content + "</th>");
                    }
                }
                s.Append(""
                         + cr + "<thead>"
                         + cr2 + "<tr>"
                         + indent(indent(rowList.ToString()))
                         + cr2 + "</tr>"
                         + cr + "</thead>"
                         + "");
                if (addCsvDownloadCurrentPage)
                {
                    colPtrDownload = 0;
                    for (colPtr = 0; colPtr <= columnMax; colPtr++)
                    {
                        if (columns[colPtr].downloadable)
                        {
                            if (colPtrDownload == 0)
                            {
                                csvDownloadContent += "\"" + columns[colPtr].caption.Replace("\"", "\"\"") + "\"";
                            }
                            else
                            {
                                csvDownloadContent += ",\"" + columns[colPtr].caption.Replace("\"", "\"\"") + "\"";
                            }
                            colPtrDownload += 1;
                        }
                    }
                }
            }
            //
            // body
            //
            rowList = new StringBuilder("");
            if (localIsEmptyReport)
            {
                styleClass = columns[0].cellClass;
                if (styleClass != "")
                {
                    styleClass = " class=\"" + styleClass + "\"";
                }
                row = cr + "<td style=\"text-align:left\" " + styleClass + " colspan=\"" + (columnMax + 1) + "\">[empty]</td>";
                rowList.Append(""
                               + cr + "<tr>"
                               + indent(row)
                               + cr + "</tr>");
            }
            else if (ReportTooLong)
            {
                // -- report is too long
                styleClass = columns[0].cellClass;
                if (styleClass != "")
                {
                    styleClass = " class=\"" + styleClass + "\"";
                }
                row = cr + "<td style=\"text-align:left\" " + styleClass + " colspan=\"" + (columnMax + 1) + "\">There are too many rows in this report. Please consider filtering the data.</td>";
                rowList.Append(""
                               + cr + "<tr>"
                               + indent(row)
                               + cr + "</tr>");
            }
            else
            {
                // -- display th report
                for (rowPtr = 0; rowPtr <= rowCnt; rowPtr++)
                {
                    row            = "";
                    colPtrDownload = 0;
                    for (colPtr = 0; colPtr <= columnMax; colPtr++)
                    {
                        styleClass = columns[colPtr].cellClass;
                        if (columns[colPtr].visible)
                        {
                            if (styleClass != "")
                            {
                                styleClass = " class=\"" + styleClass + "\"";
                            }
                            row += cr + "<td" + styleClass + ">" + localReportCells[rowPtr, colPtr] + "</td>";
                        }
                        if (addCsvDownloadCurrentPage && !localExcludeRowFromDownload[rowPtr])
                        {
                            if (columns[colPtr].downloadable)
                            {
                                if (colPtrDownload == 0)
                                {
                                    csvDownloadContent += Environment.NewLine;
                                }
                                else
                                {
                                    csvDownloadContent += ",";
                                }
                                if (!string.IsNullOrEmpty(localDownloadData[rowPtr, colPtr]))
                                {
                                    csvDownloadContent += "\"" + localDownloadData[rowPtr, colPtr].Replace("\"", "\"\"") + "\"";
                                }
                                colPtrDownload += 1;
                            }
                        }
                    }
                    styleClass = localRowClasses[rowPtr];
                    if (rowPtr % 2 != 0)
                    {
                        styleClass += " afwOdd";
                    }
                    if (styleClass != "")
                    {
                        styleClass = " class=\"" + styleClass + "\"";
                    }
                    rowList.Append(""
                                   + cr + "<tr" + styleClass + ">"
                                   + indent(row)
                                   + cr + "</tr>");
                }
            }
            string csvDownloadFilename = string.Empty;

            if (addCsvDownloadCurrentPage)
            {
                //
                // todo implement cp.db.CreateCsv()
                // 5.1 -- download
                CPCSBaseClass csDownloads = cp.CSNew();
                if (csDownloads.Insert("downloads"))
                {
                    csvDownloadFilename = csDownloads.GetFilename("filename", "export.csv");
                    cp.CdnFiles.Save(csvDownloadFilename, csvDownloadContent);
                    csDownloads.SetField("name", "Download for [" + localTitle + "], requested by [" + cp.User.Name + "]");
                    csDownloads.SetField("requestedBy", cp.User.Id.ToString());
                    csDownloads.SetField("filename", csvDownloadFilename);
                    csDownloads.SetField("dateRequested", DateTime.Now.ToString());
                    csDownloads.SetField("datecompleted", DateTime.Now.ToString());
                    csDownloads.SetField("resultmessage", "Completed");
                    csDownloads.Save();
                }
                csDownloads.Close();
            }
            s.Append(""
                     + cr + "<tbody>"
                     + indent(rowList.ToString())
                     + cr + "</tbody>"
                     + "");
            s = new StringBuilder(""
                                  + cr + "<table class=\"afwListReportTable\">"
                                  + indent(s.ToString())
                                  + cr + "</table>");
            if (localHtmlLeftOfTable != "")
            {
                s = new StringBuilder(""
                                      + cr + "<div class=\"afwLeftSideHtml\">"
                                      + indent(localHtmlLeftOfTable)
                                      + cr + "</div>"
                                      + cr + "<div class=\"afwRightSideHtml\">"
                                      + indent(s.ToString())
                                      + cr + "</div>"
                                      + cr + "<div style=\"clear:both\"></div>"
                                      + "");
            }
            if (localHtmlBeforeTable != "")
            {
                s = new StringBuilder(""
                                      + localHtmlBeforeTable
                                      + s.ToString()
                                      + "");
            }
            if (localHtmlAfterTable != "")
            {
                s.Append(localHtmlAfterTable);
            }
            //
            // headers
            //
            if (addCsvDownloadCurrentPage && (!string.IsNullOrEmpty(csvDownloadFilename)))
            {
                s = new StringBuilder(cr + "<p id=\"afwDescription\"><a href=\"" + cp.Site.FilePath + csvDownloadFilename + "\">Click here</a> to download the data.</p>" + s.ToString());
            }
            if (localDescription != "")
            {
                s = new StringBuilder(cr + "<p id=\"afwDescription\">" + localDescription + "</p>" + s.ToString());
            }
            if (localWarning != "")
            {
                s = new StringBuilder(cr + "<div id=\"afwWarning\">" + localWarning + "</div>" + s.ToString());
            }
            if (localTitle != "")
            {
                s = new StringBuilder(cr + "<h2 id=\"afwTitle\">" + localTitle + "</h2>" + s.ToString());
            }
            //
            // add form
            //
            if (localIncludeForm)
            {
                if (localButtonList != "")
                {
                    localButtonList = ""
                                      + cr + "<div class=\"afwButtonCon\">"
                                      + indent(localButtonList)
                                      + cr + "</div>";
                }
                s = new StringBuilder(cr + cp.Html.Form(localButtonList + s.ToString() + localButtonList + localHiddenList, "", "", "", localFormActionQueryString, ""));
                //body = ""
                //    + cr + cp.Html.Form( localButtonList + body + localHiddenList )
                //    + cr + "<form action=\"" + localFormAction + "\" method=\"post\" enctype=\"MULTIPART/FORM-DATA\">"
                //    + indent(localButtonList + body + localHiddenList)
                //    + cr + "</form>";
            }
            if (_includeBodyPadding)
            {
                s = new StringBuilder(cp.Html.div(s.ToString(), "", "afwBodyPad", ""));
            }
            if (_includeBodyColor)
            {
                s = new StringBuilder(cp.Html.div(s.ToString(), "", "afwBodyColor", ""));
            }
            //
            // if outer container, add styles and javascript
            //
            if (localIsOuterContainer)
            {
                //cp.Doc.AddHeadJavascript(Properties.Resources.javascript);
                //cp.Doc.AddHeadStyle(Properties.Resources.styles);
                s = new StringBuilder(""
                                      + cr + "<div id=\"afw\">"
                                      + indent(s.ToString())
                                      + cr + "</div>");
            }
            return(s.ToString());
        }
示例#27
0
        //====================================================================================================
        /// <summary>
        /// If the portal does not exist in the Db, create it and all its features based on the portal argument
        /// </summary>
        /// <param name="CP"></param>
        /// <param name="newPortal"></param>
        public static void savePortalToDb(CPBaseClass CP, PortalDataModel newPortal)
        {
            try {
                CPCSBaseClass cs  = CP.CSNew();
                CPCSBaseClass cs2 = CP.CSNew();
                //
                // insert or update the portal record
                //
                if (!cs.Open("portals", "ccguid=" + CP.Db.EncodeSQLText(newPortal.guid), "", true, "", 9999, 1))
                {
                    cs.Close();
                    cs.Insert("portals");
                    newPortal.id = cs.GetInteger("id");
                }
                newPortal.id = cs.GetInteger("id");
                cs.SetField("ccguid", newPortal.guid);
                cs.SetField("name", newPortal.name);
                cs.Close();
                //
                // insert or update portal feature records
                //
                foreach (KeyValuePair <string, PortalDataFeatureModel> kvp in newPortal.featureList)
                {
                    PortalDataFeatureModel feature = kvp.Value;
                    if (feature.guid != Constants.devToolGuid)
                    {
                        if (!cs.Open("portal features", "ccguid=" + CP.Db.EncodeSQLText(feature.guid), "", true, "", 9999, 1))
                        {
                            cs.Insert("portal features");
                            cs.SetField("ccGuid", feature.guid);
                        }
                        if (cs.OK())
                        {
                            feature.id = cs.GetInteger("id");
                            cs.SetField("portalId", newPortal.id.ToString());
                            cs.SetField("name", feature.name);
                            cs.SetField("heading", feature.heading);
                            cs.SetField("sortOrder", feature.sortOrder);
                            if (feature.addonId == 0 && !string.IsNullOrEmpty(feature.addonGuid))
                            {
                                //
                                // lookup addon by guid, set addonid
                                //
                                if (cs2.Open("add-ons", "ccguid=" + CP.Db.EncodeSQLText(feature.addonGuid), "", true, "", 9999, 1))
                                {
                                    cs.SetField("addonId", cs2.GetInteger("id").ToString());
                                }
                                cs2.Close();
                            }
                            if (feature.dataContentId == 0 && !string.IsNullOrEmpty(feature.dataContentGuid))
                            {
                                //
                                // save dataContentId based on dataContentGuid
                                //
                                if (cs2.Open("content", "ccguid=" + CP.Db.EncodeSQLText(feature.dataContentGuid), "", true, "", 9999, 1))
                                {
                                    feature.dataContentId = cs2.GetInteger("id");
                                    cs.SetField("dataContentId", feature.dataContentId.ToString());
                                }
                                cs2.Close();
                            }
                            if (newPortal.defaultFeature.guid == feature.guid)
                            {
                                newPortal.defaultFeature = feature;
                            }
                        }
                        cs.Close();
                    }
                }
                //
                // lookup parent features by guid and set id
                //

                foreach (KeyValuePair <string, PortalDataFeatureModel> kvp in newPortal.featureList)
                {
                    PortalDataFeatureModel feature = kvp.Value;
                    if (feature.guid != Constants.devToolGuid)
                    {
                        if (feature.parentFeatureId == 0 && !string.IsNullOrEmpty(feature.parentFeatureGuid))
                        {
                            //
                            // get the id of the parentFeature
                            //
                            if (cs.Open("portal features", "ccguid=" + CP.Db.EncodeSQLText(feature.parentFeatureGuid), "", true, "", 9999, 1))
                            {
                                feature.parentFeatureId = cs.GetInteger("id");
                            }
                            cs.Close();
                            if (feature.parentFeatureId > 0)
                            {
                                //
                                // set the parentFeatureId field of the current feature
                                //
                                if (cs.Open("portal features", "id=" + feature.id.ToString(), "", true, "", 9999, 1))
                                {
                                    cs.SetField("parentFeatureId", feature.parentFeatureId.ToString());
                                }
                                cs.Close();
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                CP.Site.ErrorReport(ex, "exception in loadPortal");
                throw;
            }
        }
示例#28
0
        //
        // ====================================================================================================
        /// <summary>
        /// create the colleciton zip file and return the pathFilename in the Cdn
        /// </summary>
        /// <param name="cp"></param>
        /// <param name="collectionId"></param>
        /// <returns></returns>
        public static string createCollectionZip_returnCdnPathFilename(CPBaseClass cp, AddonCollectionModel collection)
        {
            string cdnExportZip_Filename = "";

            try {
                if ((collection == null))
                {
                    //
                    // -- exit with error
                    cp.UserError.Add("The collection you selected could not be found");
                    return(string.Empty);
                }
                using (CPCSBaseClass CS = cp.CSNew()) {
                    CS.OpenRecord("Add-on Collections", collection.id);
                    if (!CS.OK())
                    {
                        //
                        // -- exit with error
                        cp.UserError.Add("The collection you selected could not be found");
                        return(string.Empty);
                    }
                    string collectionXml  = "<?xml version=\"1.0\" encoding=\"windows-1252\"?>";
                    string CollectionGuid = CS.GetText("ccGuid");
                    if (CollectionGuid == "")
                    {
                        CollectionGuid = cp.Utils.CreateGuid();
                        CS.SetField("ccGuid", CollectionGuid);
                    }
                    string onInstallAddonGuid = "";
                    if ((CS.FieldOK("onInstallAddonId")))
                    {
                        int onInstallAddonId = CS.GetInteger("onInstallAddonId");
                        if ((onInstallAddonId > 0))
                        {
                            AddonModel addon = AddonModel.create <AddonModel>(cp, onInstallAddonId);
                            if ((addon != null))
                            {
                                onInstallAddonGuid = addon.ccguid;
                            }
                        }
                    }
                    string CollectionName = CS.GetText("name");
                    collectionXml        += System.Environment.NewLine + "<Collection";
                    collectionXml        += " name=\"" + CollectionName + "\"";
                    collectionXml        += " guid=\"" + CollectionGuid + "\"";
                    collectionXml        += " system=\"" + GenericController.getYesNo(CS.GetBoolean("system")) + "\"";
                    collectionXml        += " updatable=\"" + GenericController.getYesNo(CS.GetBoolean("updatable")) + "\"";
                    collectionXml        += " blockNavigatorNode=\"" + GenericController.getYesNo(CS.GetBoolean("blockNavigatorNode")) + "\"";
                    collectionXml        += " onInstallAddonGuid=\"" + onInstallAddonGuid + "\"";
                    collectionXml        += ">";
                    cdnExportZip_Filename = encodeFilename(cp, CollectionName + ".zip");
                    List <string> tempPathFileList = new List <string>();
                    string        tempExportPath   = "CollectionExport" + Guid.NewGuid().ToString() + @"\";
                    //
                    // --resource executable files
                    string        wwwFileList          = CS.GetText("wwwFileList");
                    string        ContentFileList      = CS.GetText("ContentFileList");
                    List <string> execFileList         = ExportResourceListController.getResourceFileList(cp, CS.GetText("execFileList"), CollectionGuid);
                    string        execResourceNodeList = ExportResourceListController.getResourceNodeList(cp, execFileList, CollectionGuid, tempPathFileList, tempExportPath);
                    //
                    // helpLink
                    //
                    if (CS.FieldOK("HelpLink"))
                    {
                        collectionXml += System.Environment.NewLine + "\t" + "<HelpLink>" + System.Net.WebUtility.HtmlEncode(CS.GetText("HelpLink")) + "</HelpLink>";
                    }
                    //
                    // Help
                    //
                    collectionXml += System.Environment.NewLine + "\t" + "<Help>" + System.Net.WebUtility.HtmlEncode(CS.GetText("Help")) + "</Help>";
                    //
                    // Addons
                    //
                    string IncludeSharedStyleGuidList = "";
                    string IncludeModuleGuidList      = "";
                    foreach (var addon in DbBaseModel.createList <AddonModel>(cp, "collectionid=" + collection.id))
                    {
                        //
                        // -- style sheet is in the wwwroot
                        if (!string.IsNullOrEmpty(addon.stylesLinkHref))
                        {
                            string filename = addon.stylesLinkHref.Replace("/", "\\");
                            if (filename.Substring(0, 1).Equals(@"\"))
                            {
                                filename = filename.Substring(1);
                            }
                            if (!cp.WwwFiles.FileExists(filename))
                            {
                                cp.WwwFiles.Save(filename, @"/* css file created as exported for addon [" + addon.name + "], collection [" + collection.name + "] in site [" + cp.Site.Name + "] */");
                            }
                            wwwFileList += System.Environment.NewLine + addon.stylesLinkHref;
                        }
                        //
                        // -- js is in the wwwroot
                        if (!string.IsNullOrEmpty(addon.jsHeadScriptSrc))
                        {
                            string filename = addon.jsHeadScriptSrc.Replace("/", "\\");
                            if (filename.Substring(0, 1).Equals(@"\"))
                            {
                                filename = filename.Substring(1);
                            }
                            if (!cp.WwwFiles.FileExists(filename))
                            {
                                cp.WwwFiles.Save(filename, @"// javascript file created as exported for addon [" + addon.name + "], collection [" + collection.name + "] in site [" + cp.Site.Name + "]");
                            }
                            wwwFileList += System.Environment.NewLine + addon.jsHeadScriptSrc;
                        }
                        collectionXml += ExportAddonController.getAddonNode(cp, addon.id, ref IncludeModuleGuidList, ref IncludeSharedStyleGuidList);
                    }
                    //
                    // Layouts
                    foreach (var layout in DbBaseModel.createList <LayoutModel>(cp, "(installedByCollectionId=" + collection.id + ")"))
                    {
                        collectionXml += ExportLayoutController.get(cp, layout);
                    }
                    //
                    // Templates
                    foreach (var template in DbBaseModel.createList <PageTemplateModel>(cp, "(collectionId=" + collection.id + ")"))
                    {
                        collectionXml += ExportTemplateController.get(cp, template);
                    }
                    //
                    // Data Records
                    string DataRecordList = CS.GetText("DataRecordList");
                    collectionXml += ExportDataRecordController.getNodeList(cp, DataRecordList, tempPathFileList, tempExportPath);
                    //
                    // CDef
                    foreach (Contensive.Models.Db.ContentModel content in createListFromCollection(cp, collection.id))
                    {
                        if ((string.IsNullOrEmpty(content.ccguid)))
                        {
                            content.ccguid = cp.Utils.CreateGuid();
                            content.save(cp);
                        }
                        XmlController xmlTool = new XmlController(cp);
                        string        Node    = xmlTool.GetXMLContentDefinition3(content.name);
                        //
                        // remove the <collection> top node
                        //
                        int Pos = Strings.InStr(1, Node, "<cdef", CompareMethod.Text);
                        if (Pos > 0)
                        {
                            Node = Strings.Mid(Node, Pos);
                            Pos  = Strings.InStr(1, Node, "</cdef>", CompareMethod.Text);
                            if (Pos > 0)
                            {
                                Node           = Strings.Mid(Node, 1, Pos + 6);
                                collectionXml += System.Environment.NewLine + "\t" + Node;
                            }
                        }
                    }
                    //
                    // Scripting Modules
                    if (IncludeModuleGuidList != "")
                    {
                        string[] Modules = Strings.Split(IncludeModuleGuidList, System.Environment.NewLine);
                        for (var Ptr = 0; Ptr <= Information.UBound(Modules); Ptr++)
                        {
                            string ModuleGuid = Modules[Ptr];
                            if (ModuleGuid != "")
                            {
                                using (CPCSBaseClass CS2 = cp.CSNew()) {
                                    CS2.Open("Scripting Modules", "ccguid=" + cp.Db.EncodeSQLText(ModuleGuid));
                                    if (CS2.OK())
                                    {
                                        string Code = CS2.GetText("code").Trim();
                                        Code           = EncodeCData(Code);
                                        collectionXml += System.Environment.NewLine + "\t" + "<ScriptingModule Name=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("name")) + "\" guid=\"" + ModuleGuid + "\">" + Code + "</ScriptingModule>";
                                    }
                                    CS2.Close();
                                }
                            }
                        }
                    }
                    //
                    // shared styles
                    string[] recordGuids;
                    string   recordGuid;
                    if ((IncludeSharedStyleGuidList != ""))
                    {
                        recordGuids = Strings.Split(IncludeSharedStyleGuidList, System.Environment.NewLine);
                        for (var Ptr = 0; Ptr <= Information.UBound(recordGuids); Ptr++)
                        {
                            recordGuid = recordGuids[Ptr];
                            if (recordGuid != "")
                            {
                                using (CPCSBaseClass CS2 = cp.CSNew()) {
                                    CS2.Open("Shared Styles", "ccguid=" + cp.Db.EncodeSQLText(recordGuid));
                                    if (CS2.OK())
                                    {
                                        collectionXml += System.Environment.NewLine + "\t" + "<SharedStyle"
                                                         + " Name=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("name")) + "\""
                                                         + " guid=\"" + recordGuid + "\""
                                                         + " alwaysInclude=\"" + CS2.GetBoolean("alwaysInclude") + "\""
                                                         + " prefix=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("prefix")) + "\""
                                                         + " suffix=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("suffix")) + "\""
                                                         + " sortOrder=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("sortOrder")) + "\""
                                                         + ">"
                                                         + EncodeCData(CS2.GetText("styleFilename").Trim())
                                                         + "</SharedStyle>";
                                    }
                                    CS2.Close();
                                }
                            }
                        }
                    }
                    //
                    // Import Collections
                    {
                        string Node = "";
                        using (CPCSBaseClass CS3 = cp.CSNew()) {
                            if (CS3.Open("Add-on Collection Parent Rules", "parentid=" + collection.id))
                            {
                                do
                                {
                                    using (CPCSBaseClass CS2 = cp.CSNew()) {
                                        if (CS2.OpenRecord("Add-on Collections", CS3.GetInteger("childid")))
                                        {
                                            string Guid = CS2.GetText("ccGuid");
                                            if (Guid == "")
                                            {
                                                Guid = cp.Utils.CreateGuid();
                                                CS2.SetField("ccGuid", Guid);
                                            }

                                            Node = Node + System.Environment.NewLine + "\t" + "<ImportCollection name=\"" + System.Net.WebUtility.HtmlEncode(CS2.GetText("name")) + "\">" + Guid + "</ImportCollection>";
                                        }

                                        CS2.Close();
                                    }

                                    CS3.GoNext();
                                }while (CS3.OK());
                            }
                            CS3.Close();
                        }
                        collectionXml += Node;
                    }
                    //
                    // wwwFileList
                    if (wwwFileList != "")
                    {
                        string[] Files = Strings.Split(wwwFileList, System.Environment.NewLine);
                        for (int Ptr = 0; Ptr <= Information.UBound(Files); Ptr++)
                        {
                            string pathFilename = Files[Ptr];
                            if (pathFilename != "")
                            {
                                pathFilename = Strings.Replace(pathFilename, @"\", "/");
                                string path     = "";
                                string filename = pathFilename;
                                int    Pos      = Strings.InStrRev(pathFilename, "/");
                                if (Pos > 0)
                                {
                                    filename = Strings.Mid(pathFilename, Pos + 1);
                                    path     = Strings.Mid(pathFilename, 1, Pos - 1);
                                }
                                string fileExtension = System.IO.Path.GetExtension(filename);
                                pathFilename = Strings.Replace(pathFilename, "/", @"\");
                                if (tempPathFileList.Contains(tempExportPath + filename))
                                {
                                    //
                                    // -- the path already has a file with this name
                                    cp.UserError.Add("There was an error exporting this collection because there were multiple files with the same filename [" + filename + "]");
                                }
                                else if (fileExtension.ToUpperInvariant().Equals(".ZIP"))
                                {
                                    //
                                    // -- zip files come from the collection folder
                                    CoreController core           = ((CPClass)cp).core;
                                    string         addonPath      = AddonController.getPrivateFilesAddonPath();
                                    string         collectionPath = CollectionFolderController.getCollectionConfigFolderPath(core, collection.ccguid);
                                    if (!cp.PrivateFiles.FileExists(addonPath + collectionPath + filename))
                                    {
                                        //
                                        // - not there
                                        cp.UserError.Add("There was an error exporting this collection because the zip file [" + pathFilename + "] was not found in the collection path [" + collectionPath + "].");
                                    }
                                    else
                                    {
                                        //
                                        // -- copy file from here
                                        cp.PrivateFiles.Copy(addonPath + collectionPath + filename, tempExportPath + filename, cp.TempFiles);
                                        tempPathFileList.Add(tempExportPath + filename);
                                        collectionXml += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(filename) + "\" type=\"www\" path=\"" + System.Net.WebUtility.HtmlEncode(path) + "\" />";
                                    }
                                }
                                else if ((!cp.WwwFiles.FileExists(pathFilename)))
                                {
                                    cp.UserError.Add("There was an error exporting this collection because the www file [" + pathFilename + "] was not found.");
                                }
                                else
                                {
                                    cp.WwwFiles.Copy(pathFilename, tempExportPath + filename, cp.TempFiles);
                                    tempPathFileList.Add(tempExportPath + filename);
                                    collectionXml += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(filename) + "\" type=\"www\" path=\"" + System.Net.WebUtility.HtmlEncode(path) + "\" />";
                                }
                            }
                        }
                    }
                    //
                    // ContentFileList
                    //
                    if (true)
                    {
                        if (ContentFileList != "")
                        {
                            string[] Files = Strings.Split(ContentFileList, System.Environment.NewLine);
                            for (var Ptr = 0; Ptr <= Information.UBound(Files); Ptr++)
                            {
                                string PathFilename = Files[Ptr];
                                if (PathFilename != "")
                                {
                                    PathFilename = Strings.Replace(PathFilename, @"\", "/");
                                    string Path     = "";
                                    string Filename = PathFilename;
                                    int    Pos      = Strings.InStrRev(PathFilename, "/");
                                    if (Pos > 0)
                                    {
                                        Filename = Strings.Mid(PathFilename, Pos + 1);
                                        Path     = Strings.Mid(PathFilename, 1, Pos - 1);
                                    }
                                    if (tempPathFileList.Contains(tempExportPath + Filename))
                                    {
                                        cp.UserError.Add("There was an error exporting this collection because there were multiple files with the same filename [" + Filename + "]");
                                    }
                                    else if ((!cp.CdnFiles.FileExists(PathFilename)))
                                    {
                                        cp.UserError.Add("There was an error exporting this collection because the cdn file [" + PathFilename + "] was not found.");
                                    }
                                    else
                                    {
                                        cp.CdnFiles.Copy(PathFilename, tempExportPath + Filename, cp.TempFiles);
                                        tempPathFileList.Add(tempExportPath + Filename);
                                        collectionXml += System.Environment.NewLine + "\t" + "<Resource name=\"" + System.Net.WebUtility.HtmlEncode(Filename) + "\" type=\"content\" path=\"" + System.Net.WebUtility.HtmlEncode(Path) + "\" />";
                                    }
                                }
                            }
                        }
                    }
                    //
                    // ExecFileListNode
                    //
                    collectionXml += execResourceNodeList;
                    //
                    // Other XML
                    //
                    string OtherXML;
                    OtherXML = CS.GetText("otherxml");
                    if (Strings.Trim(OtherXML) != "")
                    {
                        collectionXml += System.Environment.NewLine + OtherXML;
                    }
                    collectionXml += System.Environment.NewLine + "</Collection>";
                    CS.Close();
                    string tempExportXml_Filename = encodeFilename(cp, CollectionName + ".xml");
                    //
                    // Save the installation file and add it to the archive
                    //
                    cp.TempFiles.Save(tempExportPath + tempExportXml_Filename, collectionXml);
                    if (!tempPathFileList.Contains(tempExportPath + tempExportXml_Filename))
                    {
                        tempPathFileList.Add(tempExportPath + tempExportXml_Filename);
                    }
                    string tempExportZip_Filename = encodeFilename(cp, CollectionName + ".zip");
                    //
                    // -- zip up the folder to make the collection zip file in temp filesystem
                    zipTempCdnFile(cp, tempExportPath + tempExportZip_Filename, tempPathFileList);
                    //
                    // -- copy the collection zip file to the cdn filesystem as the download link
                    cp.TempFiles.Copy(tempExportPath + tempExportZip_Filename, cdnExportZip_Filename, cp.CdnFiles);
                    //
                    // -- delete the temp folder
                    cp.TempFiles.DeleteFolder(tempExportPath);
                }
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex);
            }
            return(cdnExportZip_Filename);
        }
示例#29
0
        //
        // ===============================================================================
        // get Form
        // ===============================================================================
        //
        public string getForm(CPBaseClass cp, int dstFormId, string rqs, DateTime rightNow, ref int appId)
        {
            string returnHtml = "";

            try
            {
                string           form     = "";
                CPBlockBaseClass layout   = cp.BlockNew();
                string           returnJs = "";
                CPCSBaseClass    cs       = cp.CSNew();
                //
                // open layout, grab form, add hiddens, replace back into layout
                //
                layout.OpenLayout("sample layout");
                if (layout.GetHtml() == "")
                {
                    layout.Load(sampleLayout);
                    cs.Insert("Layouts");
                    cs.SetField("name", "sample layout");
                    cs.SetField("layout", layout.GetHtml());
                    cs.Close();
                }
                //
                form  = layout.GetInner("#myForm");
                form += cp.Html.Hidden(constants.rnSrcFormId, dstFormId.ToString(), "", "");
                form += cp.Html.Hidden(constants.rnAppId, appId.ToString(), "", "");
                if (!cp.UserError.OK())
                {
                    form = cp.Html.div(cp.UserError.GetList(), "", "", "") + form;
                }
                form = cp.Html.Form(form, "", "", "", "", "");
                layout.SetOuter("#myForm", form);
                //
                // Populate the layout
                // attempt to open the application record. It is created in the process so this may fail.
                //      if not cs.OK(), the getFormField will return blank.
                //
                cs.Open("people", "id=" + cp.User.Id.ToString(), "", true, "", 1, 1);
                if (true)
                {
                    //
                    // either server-side
                    //
                    layout.SetOuter(".myInputRow input", cp.Html.InputText("name", constants.getFormField(cp, cs, "name"), "", "", false, "", ""));
                }
                else
                {
                    //
                    // or client-side
                    //
                    returnJs += constants.cr + "jQuery('.myInputRow myLabel').html('" + constants.getFormField(cp, cs, "name") + "')";
                }
                cs.Close();
                //
                // apply any javascript to doc
                //
                if (returnJs != "")
                {
                    cp.Doc.AddHeadJavascript("jQuery(document).ready(function(){" + returnJs + constants.cr + "});");
                }
                //
                // return converted layout
                //
                returnHtml = layout.GetHtml();
            }
            catch (Exception ex)
            {
                errorReport(cp, ex, "getForm");
            }
            return(returnHtml);
        }
示例#30
0
        //
        // ===========================================================================================
        //
        public void bounceProcess(Contensive.BaseClasses.CPBaseClass cp)
        {
            try {
                CPCSBaseClass CS = cp.CSNew();
                string        MessageText;
                string[]      FilterLines;
                string[]      FilterText = Array.Empty <string>();
                int[]         FilterType = Array.Empty <int>();
                int           LinePtr;
                string[]      LineSplit;
                int           FilterLineCnt = 0;
                string        Filter;
                int           BounceType;
                string        EmailAddress;
                string        PopServer;
                int           popPort;
                string        POPServerUsername;
                string        POPServerPassword;
                int           EmailBounceProcessAction;
                bool          AllowEmailBounceProcessing;
                string        bounceLogPathPage;
                string        ActionTaken;
                string        FilterFilename;
                string        Filename     = "";
                DateTime      rightNowDate = DateTime.Now.Date;
                string        logDatePart  = rightNowDate.Year + rightNowDate.Month.ToString().PadLeft(2) + rightNowDate.Day.ToString().PadLeft(2);
                string        amazonMsg    = "An error occurred while trying to deliver the mail to the following recipients:" + "\r\n";
                //
                AllowEmailBounceProcessing = cp.Site.GetBoolean("AllowEmailBounceProcessing", false);
                if (AllowEmailBounceProcessing)
                {
                    PopServer = cp.Site.GetText("PopServer", "");
                    popPort   = cp.Site.GetInteger("popServerPort", 110);
                    if (popPort <= 0)
                    {
                        popPort = 110;
                    }
                    POPServerUsername = cp.Site.GetText("POPServerUsername", "");
                    POPServerPassword = cp.Site.GetText("POPServerPassword", "");
                    if ((PopServer == "") | (POPServerUsername == "") | (POPServerPassword == ""))
                    {
                        cp.Utils.AppendLog("AllowEmailBounceProcessing true but server, username or password is blank");
                    }
                    else
                    {
                        bounceLogPathPage        = @"BounceLog\" + logDatePart + @"\trace.txt";
                        FilterFilename           = @"\config\EmailBounceFilters.txt";
                        EmailBounceProcessAction = cp.Site.GetInteger("EmailBounceProcessAction", 0);
                        //
                        // Read in the filter file
                        //
                        if (true)
                        {
                            string copy;
                            copy = cp.CdnFiles.Read(FilterFilename);
                            if (copy == "")
                            {
                                cp.Utils.AppendLog(@"Bounce processing filters file \config\EmailBounceFilters.txt is empty");
                            }
                            else
                            {
                                copy          = copy.Replace("\r\n", "\r");
                                copy          = copy.Replace("\n", "\r");
                                FilterLines   = copy.Split('\r');
                                FilterLineCnt = FilterLines.Length;
                                FilterText    = new string[FilterLineCnt + 100 + 1];
                                FilterType    = new int[FilterLineCnt + 100 + 1];
                                //
                                //
                                //
                                for (LinePtr = 0; LinePtr <= FilterLineCnt - 1; LinePtr++)
                                {
                                    if (FilterLines[LinePtr] != "")
                                    {
                                        LineSplit           = FilterLines[LinePtr].Split(',');
                                        FilterText[LinePtr] = LineSplit[0];
                                        if (LineSplit.Length > 0)
                                        {
                                            FilterType[LinePtr] = cp.Utils.EncodeInteger(LineSplit[1]);
                                        }
                                    }
                                }
                                //
                                // add amazon
                                //
                                FilterText[FilterLineCnt] = amazonMsg;
                                FilterType[FilterLineCnt] = 2;
                                FilterLineCnt            += 1;
                            }
                        }
                        //
                        // Retrieve the emails
                        //
                        int    MessageCnt;
                        string headerList;
                        OpenPop.Mime.Message msg;
                        using (OpenPop.Pop3.Pop3Client pop = new OpenPop.Pop3.Pop3Client()) {
                            try {
                                pop.Connect(PopServer, popPort, true);
                                pop.Authenticate(POPServerUsername, POPServerPassword);
                                MessageCnt = pop.GetMessageCount();
                                //
                                cp.CdnFiles.Append(bounceLogPathPage, "\r\n" + "New bounce emails, cnt=" + MessageCnt);
                                //
                                for (int msgPtr = 1; msgPtr <= MessageCnt; msgPtr++)
                                {
                                    msg          = pop.GetMessage(msgPtr);
                                    headerList   = "";
                                    EmailAddress = "";
                                    headerList   = "";
                                    MessageText  = "";
                                    if (!msg.Headers.From.HasValidMailAddress)
                                    {
                                        //
                                        cp.CdnFiles.Append(bounceLogPathPage, "\n\r" + "email" + msgPtr + "-" + "email address not found");
                                    }
                                    else
                                    {
                                        EmailAddress = msg.Headers.From.Address;

                                        foreach (string key in msg.Headers.UnknownHeaders.AllKeys)
                                        {
                                            string keyValue = msg.Headers.UnknownHeaders[key];
                                            headerList += "\r\n" + key + "=" + keyValue;
                                        }

                                        OpenPop.Mime.MessagePart msgBody;
                                        msgBody = msg.FindFirstPlainTextVersion();
                                        if ((msgBody == null))
                                        {
                                            msgBody = msg.FindFirstHtmlVersion();
                                        }
                                        MessageText = "";
                                        if (!(msgBody == null))
                                        {
                                            MessageText = msgBody.GetBodyAsText();
                                        }

                                        if (string.IsNullOrEmpty(MessageText))
                                        {
                                            //
                                            cp.CdnFiles.Append(bounceLogPathPage, "\n\r" + "email" + msgPtr + "-" + "email has blank body");
                                        }
                                        else
                                        {
                                            //
                                            // Process them as they come in
                                            //
                                            if ((EmailAddress == "*****@*****.**"))
                                            {
                                                if ((MessageText.IndexOf(amazonMsg) > -1))
                                                {
                                                    EmailAddress = MessageText.Replace(amazonMsg, "");
                                                }
                                            }
                                            ActionTaken = "no action";
                                            if (EmailAddress == "")
                                            {
                                                //
                                                cp.CdnFiles.Append(bounceLogPathPage, "\n\r" + "email" + msgPtr + "-" + "email address was blank");
                                                //
                                                ActionTaken = "deleted with no action, email address could not be determined, email content saved [" + Filename + "]";
                                            }
                                            else if (FilterLineCnt == 0)
                                            {
                                                //
                                                cp.CdnFiles.Append(bounceLogPathPage, "\n\r" + "email" + msgPtr + "-" + "email filter file was not found (" + FilterFilename + ")");
                                                //
                                                ActionTaken = "[" + EmailAddress + "], deleted with no action, no Filter File [" + FilterFilename + "]";
                                            }
                                            else
                                            {
                                                // Copy = strDecodeMime(MessageText, MessageHeaders)
                                                for (LinePtr = 0; LinePtr <= FilterLineCnt - 1; LinePtr++)
                                                {
                                                    Filter = FilterText[LinePtr].Trim();
                                                    if (Filter != "")
                                                    {
                                                        if (MessageText.IndexOf(Filter) >= 0)
                                                        {
                                                            BounceType = FilterType[LinePtr];
                                                            switch (BounceType)
                                                            {
                                                            case 0: {
                                                                //
                                                                ActionTaken = "[" + EmailAddress + "], deleted with no action, Filter [" + Filter + "] is not a bounce";
                                                                break;
                                                            }

                                                            case 1: {
                                                                //
                                                                // soft bounce - may recover
                                                                //
                                                                ActionTaken = "[" + EmailAddress + "], deleted with no action, Filter [" + Filter + "] is soft error, may recover";
                                                                break;
                                                            }

                                                            case 2: {
                                                                //
                                                                // hard bounce - take action on the member email
                                                                //
                                                                //
                                                                //
                                                                //
                                                                //
                                                                EmailBounceProcessAction = 1;
                                                                //
                                                                //
                                                                //
                                                                switch (EmailBounceProcessAction)
                                                                {
                                                                case 1: {
                                                                    //
                                                                    // clear allowgroupemail
                                                                    //
                                                                    ActionTaken = "[" + EmailAddress + "], clear allowBulkEmail action, Filter [" + Filter + "] is hard error";
                                                                    CS.Open("people", "email=" + cp.Db.EncodeSQLText(EmailAddress), "", true, "ID,Name,OrganizationID,allowbulkemail");
                                                                    if (!(CS.OK()))
                                                                    {
                                                                        ActionTaken += ", NO RECORD FOUND";
                                                                    }
                                                                    else
                                                                    {
                                                                        ActionTaken += ", clearing allowGroupEmail for records [";
                                                                        while (CS.OK())
                                                                        {
                                                                            ActionTaken += "," + CS.GetInteger("id").ToString();
                                                                            CS.SetField("allowbulkemail", 0.ToString());
                                                                            CS.GoNext();
                                                                        }
                                                                        ActionTaken += "]";
                                                                    }
                                                                    CS.Close();
                                                                    break;
                                                                }

                                                                case 2: {
                                                                    //
                                                                    // clear email
                                                                    //
                                                                    ActionTaken = "[" + EmailAddress + "], clear email address action, Filter [" + Filter + "] is hard error";
                                                                    CS.Open("people", "email=" + cp.Db.EncodeSQLText(EmailAddress), "", true, "ID,Name,OrganizationID,email");
                                                                    if (!CS.OK())
                                                                    {
                                                                        ActionTaken += ", NO RECORD FOUND";
                                                                    }
                                                                    else
                                                                    {
                                                                        ActionTaken += ", clear email address for records [";
                                                                        while (CS.OK())
                                                                        {
                                                                            CS.SetField("email", "");
                                                                            CS.GoNext();
                                                                        }
                                                                        ActionTaken += "]";
                                                                    }
                                                                    CS.Close();
                                                                    break;
                                                                }

                                                                case 3: {
                                                                    //
                                                                    // Delete Member
                                                                    //
                                                                    ActionTaken = "[" + EmailAddress + "], delete member, Filter [" + Filter + "] is hard error";
                                                                    CS.Open("people", "email=" + cp.Db.EncodeSQLText(EmailAddress), "", true, "ID,Name,OrganizationID");
                                                                    if (!CS.OK())
                                                                    {
                                                                        ActionTaken += ", NO RECORD FOUND";
                                                                    }
                                                                    else
                                                                    {
                                                                        ActionTaken += ", delete people records [";
                                                                        while (CS.OK())
                                                                        {
                                                                            CS.Delete();
                                                                            CS.GoNext();
                                                                        }
                                                                        ActionTaken += "]";
                                                                    }
                                                                    CS.Close();
                                                                    break;
                                                                }

                                                                default: {
                                                                    //
                                                                    // Unknown Process Action
                                                                    //
                                                                    ActionTaken = "[" + EmailAddress + "], deleted with no action, Filter [" + Filter + "] is hard error, but Process Action is unknown [" + EmailBounceProcessAction + "]";
                                                                    break;
                                                                }
                                                                }

                                                                break;
                                                            }
                                                            }
                                                            //
                                                            cp.CdnFiles.Append(bounceLogPathPage, "\n\r" + "email" + msgPtr + "-" + ActionTaken);
                                                            //
                                                            break;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    //
                                    // save bounced email
                                    //
                                    cp.CdnFiles.Save(@"BounceLog\" + logDatePart + @"\email-" + msgPtr + ".txt", EmailAddress + "\n\r" + headerList + "\n\r" + MessageText);
                                    //
                                    // delete the message
                                    //
                                    pop.DeleteMessage(msgPtr);
                                }
                            } catch (Exception ex) {
                                cp.Site.ErrorReport(ex, "Bounce Processing exception");
                            } finally {
                            }
                        }
                    }
                }
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex);
            }
        }