//
 //========================================================================
 /// <summary>
 /// Create a filename for the Virtual Directory
 /// </summary>
 /// <param name="contentName"></param>
 /// <param name="fieldName"></param>
 /// <param name="recordId"></param>
 /// <param name="originalFilename"></param>
 /// <returns></returns>
 public static string getVirtualFilename(CoreController core, string contentName, string fieldName, int recordId, string originalFilename = "")
 {
     try {
         if (string.IsNullOrEmpty(contentName.Trim()))
         {
             throw new ArgumentException("contentname cannot be blank");
         }
         if (string.IsNullOrEmpty(fieldName.Trim()))
         {
             throw new ArgumentException("fieldname cannot be blank");
         }
         if (recordId <= 0)
         {
             throw new ArgumentException("recordid is not valid");
         }
         var meta = ContentMetadataModel.createByUniqueName(core, contentName);
         if (meta == null)
         {
             throw new ArgumentException("contentName is not valid");
         }
         string workingFieldName = fieldName.Trim().ToLowerInvariant();
         if (!meta.fields.ContainsKey(workingFieldName))
         {
             throw new ArgumentException("content metadata does not include field [" + fieldName + "]");
         }
         if (string.IsNullOrEmpty(originalFilename))
         {
             return(FileController.getVirtualRecordUnixPathFilename(meta.tableName, fieldName, recordId, meta.fields[fieldName.ToLowerInvariant()].fieldTypeId));
         }
         return(FileController.getVirtualRecordUnixPathFilename(meta.tableName, fieldName, recordId, originalFilename));
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
        //
        //====================================================================================================
        /// <summary>
        /// setAdminSiteFieldHelp remote method
        /// </summary>
        /// <param name="cp"></param>
        /// <returns></returns>
        public override object Execute(Contensive.BaseClasses.CPBaseClass cp)
        {
            string result = "";

            try {
                CoreController core = ((CPClass)cp).core;
                if (cp.User.IsAdmin)
                {
                    int fieldId = cp.Doc.GetInteger("fieldId");
                    var help    = ContentFieldHelpModel.createByFieldId(cp, fieldId);
                    if (help == null)
                    {
                        help         = DbBaseModel.addDefault <ContentFieldHelpModel>(core.cpParent, Processor.Models.Domain.ContentMetadataModel.getDefaultValueDict(core, ContentFieldHelpModel.tableMetadata.contentName));
                        help.fieldId = fieldId;
                    }
                    help.helpCustom = cp.Doc.GetText("helpcustom");
                    help.save(cp);
                    ContentFieldModel contentField = DbBaseModel.create <ContentFieldModel>(core.cpParent, fieldId);
                    if (contentField != null)
                    {
                        ContentMetadataModel.invalidateCache(core, contentField.contentId);
                    }
                }
            } catch (Exception ex) {
                cp.Site.ErrorReport(ex);
            }
            return(result);
        }
Example #3
0
        //
        //====================================================================================================
        //
        public override int AddContentField(string contentName, string fieldName, CPContentBaseClass.FieldTypeIdEnum fieldType)
        {
            var contentMetadata = ContentMetadataModel.createByUniqueName(cp.core, contentName);
            var fieldMeta       = ContentFieldMetadataModel.createDefault(cp.core, fieldName, fieldType);

            contentMetadata.verifyContentField(cp.core, fieldMeta, false, "Api CPContent.AddContentField [" + contentName + "." + fieldName + "]");
            return(fieldMeta.id);
        }
        //
        // todo rename metadata as meta
        //========================================================================
        /// <summary>
        /// returns true if the metadata field exists
        /// </summary>
        /// <param name="ContentID"></param>
        /// <param name="FieldName"></param>
        /// <returns></returns>
        public static bool isMetadataField(CoreController core, int ContentID, string FieldName)
        {
            var meta = ContentMetadataModel.create(core, ContentID);

            if (meta == null)
            {
                return(false);
            }
            return(meta.fields.ContainsKey(FieldName.Trim().ToLower(CultureInfo.InvariantCulture)));
        }
Example #5
0
        //
        //====================================================================================================
        //
        public override string GetTable(string contentName)
        {
            var meta = ContentMetadataModel.createByUniqueName(cp.core, contentName);

            if (meta == null)
            {
                return(string.Empty);
            }
            return(meta.tableName);
        }
Example #6
0
        //
        //====================================================================================================
        /// <summary>
        /// returns the matching record name if a match is found, otherwise blank. Does NOT validate the record.
        /// </summary>
        /// <param name="contentName"></param>
        /// <param name="recordID"></param>
        /// <returns></returns>
        public override string GetRecordName(string contentName, int recordID)
        {
            var meta = ContentMetadataModel.createByUniqueName(cp.core, contentName);

            if (meta == null)
            {
                return(string.Empty);
            }
            return(meta.getRecordName(cp.core, recordID));
        }
Example #7
0
        //
        //====================================================================================================
        //
        public override string GetEditLink(int contentId, string recordGuid)
        {
            var contentMetadata = ContentMetadataModel.create(cp.core, contentId);

            if (contentMetadata == null)
            {
                throw new GenericException("contentId [" + contentId + "], but no content metadata found.");
            }
            return(AdminUIController.getRecordEditAnchorTag(cp.core, contentMetadata, recordGuid));
        }
Example #8
0
        //
        //====================================================================================================
        //
        public override string GetEditLink(string contentName, string recordGuid)
        {
            var contentMetadata = ContentMetadataModel.createByUniqueName(cp.core, contentName);

            if (contentMetadata == null)
            {
                throw new GenericException("ContentName [" + contentName + "], but no content metadata found with this name.");
            }
            return(AdminUIController.getRecordEditAnchorTag(cp.core, contentMetadata, recordGuid));
        }
Example #9
0
        //
        //====================================================================================================
        //
        public override string GetContentControlCriteria(string contentName)
        {
            var meta = ContentMetadataModel.createByUniqueName(cp.core, contentName);

            if (meta != null)
            {
                return(meta.legacyContentControlCriteria);
            }
            return(string.Empty);
        }
Example #10
0
        public override string GetProperty(string ContentName, string PropertyName)
        {
            var contentMetadata = ContentMetadataModel.createByUniqueName(cp.core, ContentName);

            if (contentMetadata == null)
            {
                return(string.Empty);
            }
            return(contentMetadata.getContentProperty(cp.core, PropertyName));
        }
Example #11
0
        //
        //====================================================================================================
        //
        public override int AddContent(string contentName, string sqlTableName, string dataSourceName)
        {
            var tmpList = new List <string> {
            };
            DataSourceModel dataSource = DataSourceModel.createByUniqueName(cp, dataSourceName, ref tmpList);

            return(ContentMetadataModel.verifyContent_returnId(cp.core, new Models.Domain.ContentMetadataModel {
                dataSourceName = dataSource.name,
                tableName = sqlTableName,
                name = contentName
            }, "Adding content [" + contentName + "], sqlTableName [" + sqlTableName + "]"));
        }
        //
        //========================================================================
        /// <summary>
        /// 'deleteContentRecords
        /// </summary>
        /// <param name="contentName"></param>
        /// <param name="sqlCriteria"></param>
        /// <param name="userId"></param>
        //
        public static void deleteContentRecords(CoreController core, string contentName, string sqlCriteria, int userId = 0)
        {
            var meta = ContentMetadataModel.createByUniqueName(core, contentName);

            if (meta == null)
            {
                return;
            }
            using (var db = new DbController(core, meta.dataSourceName)) {
                core.db.deleteRows(meta.tableName, sqlCriteria);
            }
        }
        //
        //========================================================================
        /// <summary>
        /// Delete Content Record
        /// </summary>
        /// <param name="contentName"></param>
        /// <param name="recordId"></param>
        /// <param name="userId"></param>
        //
        public static void deleteContentRecord(CoreController core, string contentName, int recordId, int userId = SystemMemberId)
        {
            var meta = ContentMetadataModel.createByUniqueName(core, contentName);

            if (meta == null)
            {
                return;
            }
            using (var db = new DbController(core, meta.dataSourceName)) {
                core.db.delete(recordId, meta.tableName);
            }
        }
Example #14
0
 //
 //====================================================================================================
 /// <summary>
 /// Add a command task to the taskQueue to be run by the taskRunner. Returns false if the task was already there (dups fround by command name and cmdDetailJson)
 /// </summary>
 /// <param name="core"></param>
 /// <param name="command"></param>
 /// <param name="cmdDetail"></param>
 /// <param name="downloadName"></param>
 /// <returns></returns>
 static public bool addTaskToQueue(CoreController core, TaskModel.CmdDetailClass cmdDetail, bool blockDuplicates, string downloadName, string downloadFilename)
 {
     try {
         //
         int downloadId = 0;
         if (!string.IsNullOrEmpty(downloadName))
         {
             Dictionary <string, string> defaultValues = ContentMetadataModel.getDefaultValueDict(core, DownloadModel.tableMetadata.contentName);
             var download = DbBaseModel.addDefault <DownloadModel>(core.cpParent, defaultValues);
             download.name          = downloadName;
             download.dateRequested = core.dateTimeNowMockable;
             download.requestedBy   = core.session.user.id;
             if (!string.IsNullOrEmpty(downloadFilename))
             {
                 //
                 // -- if the donwloadfilename is specified, save it in the download record and force the file to save with a space in content
                 download.filename.filename = FileController.getVirtualRecordUnixPathFilename(DownloadModel.tableMetadata.tableNameLower, "filename", download.id, downloadFilename);
                 download.filename.content  = " ";
             }
             downloadId = download.id;
             download.save(core.cpParent);
         }
         string cmdDetailJson = SerializeObject(cmdDetail);
         bool   allowAdd      = true;
         if (blockDuplicates)
         {
             //
             // -- Search for a duplicate
             string sql = "select top 1 id from cctasks where ((cmdDetail=" + DbController.encodeSQLText(cmdDetailJson) + ")and(datestarted is null)and(datecompleted is null))";
             using (var csData = new CsModel(core)) {
                 allowAdd = !csData.openSql(sql);
             }
         }
         //
         // -- add it to the queue and shell out to the command
         if (allowAdd)
         {
             var task = TaskModel.addEmpty <TaskModel>(core.cpParent);
             task.name             = "addon [#" + cmdDetail.addonId + "," + cmdDetail.addonName + "]";
             task.cmdDetail        = cmdDetailJson;
             task.resultDownloadId = downloadId;
             task.save(core.cpParent);
             LogController.logTrace(core, "addTaskToQueue, task added, cmdDetailJson [" + cmdDetailJson + "]");
             return(true);
         }
         LogController.logTrace(core, "addTaskToQueue, task blocked because duplicate found, cmdDetailJson [" + cmdDetailJson + "]");
         return(false);
     } catch (Exception ex) {
         LogController.logError(core, ex);
         return(false);
     }
 }
 //
 //========================================================================
 /// <summary>
 /// Get a Contents Name from the ContentID
 /// </summary>
 /// <param name="core"></param>
 /// <param name="contentID"></param>
 /// <returns></returns>
 public static string getContentNameByID(CoreController core, int contentID)
 {
     try {
         var meta = ContentMetadataModel.create(core, contentID);
         if (meta != null)
         {
             return(meta.name);
         }
         return(string.Empty);
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
 //
 //========================================================================
 /// <summary>
 /// Get a Contents Tablename from the ContentPointer
 /// </summary>
 /// <param name="core"></param>
 /// <param name="contentName"></param>
 /// <returns></returns>
 public static string getContentTablename(CoreController core, string contentName)
 {
     try {
         var meta = ContentMetadataModel.createByUniqueName(core, contentName);
         if (meta != null)
         {
             return(meta.tableName);
         }
         return(string.Empty);
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
        //
        //========================================================================
        /// <summary>
        /// get the id of the table record for a content
        /// </summary>
        /// <param name="contentName"></param>
        /// <returns></returns>
        public static int getContentTableID(CoreController core, string contentName)
        {
            var meta = ContentMetadataModel.createByUniqueName(core, contentName);

            if (meta == null)
            {
                return(0);
            }
            var table = DbBaseModel.createByUniqueName <TableModel>(core.cpParent, meta.tableName);

            if (table != null)
            {
                return(table.id);
            }
            return(0);
        }
Example #18
0
        //
        //====================================================================================================
        /// <summary>
        /// Add a user to a group. if group is missing and argument is name or guid, it is created.
        /// </summary>
        /// <param name="core"></param>
        /// <param name="groupNameIdOrGuid"></param>
        /// <param name="userid"></param>
        /// <param name="dateExpires"></param>
        public static void addUser(CoreController core, string groupNameIdOrGuid, int userid, DateTime dateExpires)
        {
            GroupModel group = null;

            if (groupNameIdOrGuid.isNumeric())
            {
                group = DbBaseModel.create <GroupModel>(core.cpParent, GenericController.encodeInteger(groupNameIdOrGuid));
                if (group == null)
                {
                    LogController.logError(core, new GenericException("addUser called with invalid groupId [" + groupNameIdOrGuid + "]"));
                    return;
                }
            }
            else if (GenericController.isGuid(groupNameIdOrGuid))
            {
                group = DbBaseModel.create <GroupModel>(core.cpParent, groupNameIdOrGuid);
                if (group == null)
                {
                    var defaultValues = ContentMetadataModel.getDefaultValueDict(core, "groups");
                    group         = DbBaseModel.addDefault <GroupModel>(core.cpParent, defaultValues);
                    group.ccguid  = groupNameIdOrGuid;
                    group.name    = groupNameIdOrGuid;
                    group.caption = groupNameIdOrGuid;
                    group.save(core.cpParent);
                }
            }
            else
            {
                group = DbBaseModel.createByUniqueName <GroupModel>(core.cpParent, groupNameIdOrGuid);
                if (group == null)
                {
                    group         = DbBaseModel.addDefault <GroupModel>(core.cpParent, Models.Domain.ContentMetadataModel.getDefaultValueDict(core, "groups"));
                    group.ccguid  = groupNameIdOrGuid;
                    group.name    = groupNameIdOrGuid;
                    group.caption = groupNameIdOrGuid;
                    group.save(core.cpParent);
                }
            }
            var user = DbBaseModel.create <PersonModel>(core.cpParent, userid);

            if (user != null)
            {
                addUser(core, group, user, dateExpires);
            }
        }
 //
 //=============================================================
 /// <summary>
 /// get the lowest recordId based on its name. If no record is found, 0 is returned
 /// </summary>
 /// <param name="contentName"></param>
 /// <param name="recordName"></param>
 /// <returns></returns>
 public static int getRecordIdByUniqueName(CoreController core, string contentName, string recordName)
 {
     try {
         if (String.IsNullOrWhiteSpace(recordName))
         {
             return(0);
         }
         var meta = ContentMetadataModel.createByUniqueName(core, contentName);
         if ((meta == null) || (String.IsNullOrWhiteSpace(meta.tableName)))
         {
             return(0);
         }
         using (DataTable dt = core.db.executeQuery("select top 1 id from " + meta.tableName + " where name=" + DbController.encodeSQLText(recordName) + " order by id")) {
             foreach (DataRow dr in dt.Rows)
             {
                 return(DbController.getDataRowFieldInteger(dr, "id"));
             }
         }
         return(0);
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }