Ejemplo n.º 1
0
 //
 //========================================================================
 // ----- Process the send password form
 //
 public static void processSendPasswordForm(CoreController core)
 {
     try {
         string returnUserMessage = "";
         sendPassword(core, core.docProperties.getText("email"), ref returnUserMessage);
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
Ejemplo n.º 2
0
 //
 //====================================================================================================
 /// <summary>
 /// Create a topic. The actual topic will be appended to the appName
 /// </summary>
 /// <param name="core"></param>
 /// <param name="topic"></param>
 /// <returns></returns>
 public static string createTopic(CoreController core, AmazonSimpleNotificationServiceClient snsClient, string topic)
 {
     try {
         var topicResponse = snsClient.CreateTopic(core.appConfig.name + "_" + topic);
         return(topicResponse.TopicArn);
     } catch (Exception ex) {
         LogController.logError(core, ex);
         return("");
     }
 }
Ejemplo n.º 3
0
 //
 //========================================================================
 /// <summary>
 /// get site property, return as text. If not found, set and return default value
 /// </summary>
 /// <param name="propertyName"></param>
 /// <param name="DefaultValue"></param>
 /// <param name="memberId"></param>
 /// <returns></returns>
 /// <remarks></remarks>
 public string getText(string propertyName, string DefaultValue)
 {
     try {
         if (dbNotReady)
         {
             //
             // -- if db not ready, return default
             return(DefaultValue);
         }
         string cacheName = getNameValueDictKey(propertyName);
         if (cacheName.Equals("adminurl"))
         {
             //
             // -- adminRoute became an appConfig property
             return("/" + core.appConfig.adminRoute);
         }
         if (string.IsNullOrEmpty(cacheName))
         {
             //
             // -- return default if bad property name
             return(DefaultValue);
         }
         //
         // -- test simple lazy cache
         if (nameValueDict.ContainsKey(cacheName))
         {
             //
             // -- return property in memory cache
             return(nameValueDict[cacheName]);
         }
         //
         // -- read db value
         bool   propertyFound = false;
         string result        = getTextFromDb(propertyName, DefaultValue, ref propertyFound);
         if (propertyFound)
         {
             //
             // -- found in Db, save in lazy cache in case it is repeated
             if (nameValueDict.ContainsKey(cacheName))
             {
                 nameValueDict.Remove(cacheName);
             }
             nameValueDict.Add(cacheName, result);
             return(result);
         }
         //
         // -- property not found in db, cache and return default
         nameValueDict.Add(cacheName, DefaultValue);
         setProperty(cacheName, DefaultValue);
         return(DefaultValue);
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
Ejemplo n.º 4
0
 //
 //====================================================================================================
 //
 public static string createQueue(CoreController core, AmazonSQSClient sqsClient, string queueName)
 {
     try {
         var queueRequest = new Amazon.SQS.Model.CreateQueueRequest(core.appConfig.name.ToLowerInvariant() + "_" + queueName);
         queueRequest.Attributes.Add("VisibilityTimeout", "600");
         var queueResponse = sqsClient.CreateQueue(queueRequest);
         return(queueResponse.QueueUrl);
     } catch (Exception ex) {
         LogController.logError(core, ex);
         return("");
     }
 }
Ejemplo n.º 5
0
        //
        //====================================================================================================
        /// <summary>
        /// return true if an encrypted string matches an unencrypted string.
        /// </summary>
        /// <param name="sourceToTest"></param>
        /// <returns></returns>
        public static bool oneWayVerify(CoreController core, string sourceToTest, string encryptedToken)
        {
            bool returnResult = false;

            try {
                returnResult = HashEncode.verifyHash(sourceToTest, "SHA512", encryptedToken);
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnResult);
        }
Ejemplo n.º 6
0
        //
        //========================================================================
        /// <summary>
        /// Returns true if the user is an admin, or authenticated and in the group named
        /// </summary>
        /// <param name="core"></param>
        /// <param name="GroupName"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        //
        public static bool isMemberOfGroup(CoreController core, string GroupName, int userId)
        {
            bool result = false;

            try {
                result = isInGroupList(core, "," + GroupController.getGroupId(core, GroupName), userId, true);
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(result);
        }
Ejemplo n.º 7
0
        //
        //=============================================================================
        //   main_Get the link for a Content Record by the ContentName and RecordID
        //=============================================================================
        //
        public string getContentWatchLinkByName(string ContentName, int RecordID, string DefaultLink = "", bool IncrementClicks = true)
        {
            string result = "";

            try {
                string ContentRecordKey = Models.Domain.ContentMetadataModel.getContentId(core, GenericController.encodeText(ContentName)) + "." + GenericController.encodeInteger(RecordID);
                result = getContentWatchLinkByKey(ContentRecordKey, DefaultLink, IncrementClicks);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }
Ejemplo n.º 8
0
 //
 //====================================================================================================
 /// <summary>
 /// invalidates a list of keys
 /// </summary>
 /// <param name="keyList"></param>
 /// <remarks></remarks>
 public void invalidate(List <string> keyList)
 {
     try {
         foreach (var key in keyList)
         {
             invalidate(key);
         }
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
Ejemplo n.º 9
0
        //
        //====================================================================================================
        /// <summary>
        /// return an encrypted string. This is a one way so use it passwords, etc.
        /// </summary>
        /// <param name="password"></param>
        /// <returns></returns>
        public static string oneWayEncrypt(CoreController core, string password)
        {
            string returnResult = "";

            try {
                returnResult = HashEncode.computeHash(password, "SHA512", null);
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnResult);
        }
Ejemplo n.º 10
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);
     }
 }
Ejemplo n.º 11
0
 //
 //====================================================================================================
 /// <summary>
 /// Stop all activity through the content server, but do not unload
 /// </summary>
 public void stopTimerEvents()
 {
     try {
         processTimer.Enabled = false;
         using (CPClass cp = new CPClass()) {
             LogController.logTrace(cp.core, "stopTimerEvents");
         }
     } catch (Exception ex) {
         using (CPClass cp = new CPClass()) {
             LogController.logError(cp.core, ex);
         }
     }
 }
Ejemplo n.º 12
0
 //
 //====================================================================================================
 /// <summary>
 /// save object directly to cache.
 /// </summary>
 /// <param name="key"></param>
 /// <param name="cacheDocument">Either a string, a date, or a serializable object</param>
 /// <param name="invalidationDate"></param>
 /// <remarks></remarks>
 private void storeCacheDocument(string key, CacheDocumentClass cacheDocument)
 {
     try {
         //
         if (string.IsNullOrEmpty(key))
         {
             throw new ArgumentException("cache key cannot be blank");
         }
         string typeMessage = "";
         string serverKey   = createServerKey(key);
         if (core.serverConfig.enableLocalMemoryCache)
         {
             //
             // -- save local memory cache
             typeMessage = "local-memory";
             storeCacheDocument_MemoryCache(serverKey, cacheDocument);
         }
         if (core.serverConfig.enableLocalFileCache)
         {
             //
             // -- save local file cache
             typeMessage = "local-file";
             string serializedData = SerializeObject(cacheDocument);
             using (System.Threading.Mutex mutex = new System.Threading.Mutex(false, serverKey)) {
                 mutex.WaitOne();
                 core.privateFiles.saveFile("appCache\\" + FileController.encodeDosFilename(serverKey + ".txt"), serializedData);
                 mutex.ReleaseMutex();
             }
         }
         if (core.serverConfig.enableRemoteCache)
         {
             typeMessage = "remote";
             if (remoteCacheInitialized)
             {
                 //
                 // -- save remote cache
                 if (!cacheClient.Store(Enyim.Caching.Memcached.StoreMode.Set, serverKey, cacheDocument, cacheDocument.invalidationDate))
                 {
                     //
                     // -- store failed
                     LogController.logError(core, "Enyim cacheClient.Store failed, no details available.");
                 }
             }
         }
         //
         LogController.logTrace(core, "cacheType [" + typeMessage + "], key [" + key + "], expires [" + cacheDocument.invalidationDate + "], depends on [" + string.Join(",", cacheDocument.dependentKeyList) + "], points to [" + string.Join(",", cacheDocument.keyPtr) + "]");
         //
     } catch (Exception ex) {
         LogController.logError(core, ex);
     }
 }
Ejemplo n.º 13
0
 //
 //=============================================================
 /// <summary>
 /// Return a record name given the record id. If not record is found, blank is returned.
 /// </summary>
 public static string getRecordName(CoreController core, string ContentName, int recordID)
 {
     try {
         var meta = ContentMetadataModel.createByUniqueName(core, ContentName);
         if (meta == null)
         {
             return(string.Empty);
         }
         return(meta.getRecordName(core, recordID));
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
Ejemplo n.º 14
0
 //
 //====================================================================================================
 /// <summary>
 /// invalidates the entire cache (except those entires written with saveRaw)
 /// </summary>
 /// <remarks></remarks>
 public void invalidateAll()
 {
     try {
         string key = Regex.Replace(cacheNameGlobalInvalidationDate, "0x[a-fA-F\\d]{2}", "_").ToLowerInvariant().Replace(" ", "_");
         storeCacheDocument(key, new CacheDocumentClass(core.dateTimeNowMockable)
         {
             saveDate = core.dateTimeNowMockable
         });
         _globalInvalidationDate = null;
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
Ejemplo n.º 15
0
 //
 //========================================================================
 /// <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;
     }
 }
Ejemplo n.º 16
0
 //
 //========================================================================
 /// <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;
     }
 }
Ejemplo n.º 17
0
        //
        //====================================================================================================
        //   is the specified element a tag (or text)
        //
        public bool isTag(int ElementPointer)
        {
            bool result = false;

            try {
                LoadElement(ElementPointer);
                if (ElementPointer < elementCount)
                {
                    result = LocalElements[ElementPointer].IsTag;
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }
Ejemplo n.º 18
0
 //
 //====================================================================================================
 /// <summary>
 /// drop editRecordId, editarchive, and editblank and all the indexes that reference them
 /// </summary>
 /// <param name="core"></param>
 /// <param name="DataBuildVersion"></param>
 public static void dropLegacyWorkflowField(CoreController core, string fieldName)
 {
     try {
         //
         // verify Db field schema for fields handled internally (fix datatime2(0) problem -- need at least 3 digits for precision)
         var tableList = DbBaseModel.createList <TableModel>(core.cpParent, "(1=1)", "dataSourceId");
         foreach (TableModel table in tableList)
         {
             core.db.deleteTableField(table.name, fieldName, true);
         }
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
Ejemplo n.º 19
0
 //
 //
 //
 //========================================================================
 /// <summary>
 /// Set a site property
 /// </summary>
 /// <param name="propertyName"></param>
 /// <param name="Value"></param>
 public void setProperty(string propertyName, string Value)
 {
     try {
         if (dbNotReady)
         {
             //
             // -- cannot set property
             throw new GenericException("Cannot set site property before Db is ready.");
         }
         else
         {
             if (!string.IsNullOrEmpty(propertyName.Trim()))
             {
                 if (propertyName.ToLowerInvariant().Equals("adminurl"))
                 {
                     //
                     // -- intercept adminUrl for compatibility, always use admin route instead
                 }
                 else
                 {
                     //
                     // -- set value in Db
                     string SQLNow          = DbController.encodeSQLDate(core.dateTimeNowMockable);
                     string SQL             = "UPDATE ccSetup Set FieldValue=" + DbController.encodeSQLText(Value) + ",ModifiedDate=" + SQLNow + " WHERE name=" + DbController.encodeSQLText(propertyName);
                     int    recordsAffected = 0;
                     core.db.executeNonQuery(SQL, ref recordsAffected);
                     if (recordsAffected == 0)
                     {
                         SQL = "INSERT INTO ccSetup (ACTIVE,CONTENTCONTROLID,NAME,FIELDVALUE,ModifiedDate,DateAdded)VALUES("
                               + DbController.SQLTrue + "," + DbController.encodeSQLNumber(ContentMetadataModel.getContentId(core, "site properties")) + "," + DbController.encodeSQLText(propertyName.ToUpper()) + "," + DbController.encodeSQLText(Value) + "," + SQLNow + "," + SQLNow + ");";
                         core.db.executeNonQuery(SQL);
                     }
                     //
                     // -- set simple lazy cache
                     string cacheName = getNameValueDictKey(propertyName);
                     if (nameValueDict.ContainsKey(cacheName))
                     {
                         nameValueDict.Remove(cacheName);
                     }
                     nameValueDict.Add(cacheName, Value);
                 }
             }
         }
     } catch (Exception ex) {
         LogController.logError(core, ex);
         throw;
     }
 }
Ejemplo n.º 20
0
        //
        //====================================================================================================
        /// <summary>
        /// Permissions this user has for this content.
        /// </summary>
        public static UserContentPermissions getUserContentPermissions(CoreController core, ContentMetadataModel cdef)
        {
            var result = new UserContentPermissions {
                allowDelete = false,
                allowAdd    = false,
                allowSave   = false,
                allowEdit   = false
            };

            try {
                if ((!core.session.isAuthenticated) || (cdef == null))
                {
                    //
                    // -- exit with no rights
                    return(result);
                }
                if (core.session.isAuthenticatedDeveloper())
                {
                    //
                    // developers are always content managers
                    result.allowEdit   = true;
                    result.allowSave   = true;
                    result.allowAdd    = cdef.allowAdd;
                    result.allowDelete = cdef.allowDelete;
                }
                else if (core.session.isAuthenticatedAdmin())
                {
                    //
                    // admin is content manager if the CDef is not developer only
                    if (!cdef.developerOnly)
                    {
                        result.allowEdit   = true;
                        result.allowSave   = true;
                        result.allowAdd    = cdef.allowAdd;
                        result.allowDelete = cdef.allowDelete;
                    }
                }
                else
                {
                    //
                    // Authenticated and not admin or developer
                    result = getUserAuthoringPermissions_ContentManager(core, cdef, new List <int>());
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(result);
        }
Ejemplo n.º 21
0
 //
 //====================================================================================================
 /// <summary>
 /// save an object to cache, with invalidation date and dependentKeyList
 ///
 /// </summary>
 /// <param name="key"></param>
 /// <param name="content"></param>
 /// <param name="invalidationDate"></param>
 /// <param name="dependentKeyList">Each tag should represent the source of data, and should be invalidated when that source changes.</param>
 /// <remarks></remarks>
 public void storeObject(string key, object content, DateTime invalidationDate, List <string> dependentKeyList)
 {
     try {
         key = Regex.Replace(key, "0x[a-fA-F\\d]{2}", "_").ToLowerInvariant().Replace(" ", "_");
         var cacheDocument = new CacheDocumentClass(core.dateTimeNowMockable)
         {
             content          = content,
             saveDate         = core.dateTimeNowMockable,
             invalidationDate = invalidationDate,
             dependentKeyList = dependentKeyList
         };
         storeCacheDocument(key, cacheDocument);
     } catch (Exception ex) {
         LogController.logError(core, ex);
     }
 }
Ejemplo n.º 22
0
        //
        //========================================================================
        // ----- Returns true if the visitor is an admin, or authenticated and in the group list
        //========================================================================
        //
        public static bool isInGroupList(CoreController core, string GroupIDList, int checkMemberId = 0, bool adminReturnsTrue = false)
        {
            bool result = false;

            try {
                if (checkMemberId == 0)
                {
                    checkMemberId = core.session.user.id;
                }
                result = isInGroupList(core, checkMemberId, core.session.isAuthenticated, GroupIDList, adminReturnsTrue);
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(result);
        }
Ejemplo n.º 23
0
 //
 //====================================================================================================
 /// <summary>
 /// set a key ptr. A ptr points to a normal key, creating an altername way to get/invalidate a cache.
 /// ex - image with id=10, guid={999}. The normal key="image/id/10", the alias Key="image/ccguid/{9999}"
 /// </summary>
 /// <param name="CP"></param>
 /// <param name="keyPtr"></param>
 /// <param name="data"></param>
 /// <remarks></remarks>
 public void storePtr(string keyPtr, string key)
 {
     try {
         keyPtr = Regex.Replace(keyPtr, "0x[a-fA-F\\d]{2}", "_").ToLowerInvariant().Replace(" ", "_");
         key    = Regex.Replace(key, "0x[a-fA-F\\d]{2}", "_").ToLowerInvariant().Replace(" ", "_");
         CacheDocumentClass cacheDocument = new CacheDocumentClass(core.dateTimeNowMockable)
         {
             saveDate         = core.dateTimeNowMockable,
             invalidationDate = core.dateTimeNowMockable.AddDays(invalidationDaysDefault),
             keyPtr           = key
         };
         storeCacheDocument(keyPtr, cacheDocument);
     } catch (Exception ex) {
         LogController.logError(core, ex);
     }
 }
Ejemplo n.º 24
0
        //
        private static string ValidateEmail(CoreController core, string emailAddress)
        {
            var requestUrl = string.Format(QueryFormatString, ApiUrl, YourAPIKey, emailAddress);
            var myRequest  = (HttpWebRequest)WebRequest.Create(requestUrl);

            using (WebResponse webResponse = myRequest.GetResponse()) {
                try {
                    using (var reader = new StreamReader(webResponse.GetResponseStream())) {
                        return(reader.ReadToEnd());
                    }
                } catch (Exception exception) {
                    LogController.logError(core, exception);
                    return(string.Empty);
                }
            }
        }
Ejemplo n.º 25
0
        //
        //=============================================================================
        /// <summary>
        /// a simple email password form
        /// </summary>
        /// <returns></returns>
        public static string getSendPasswordForm(CoreController core)
        {
            string returnResult = "";

            try {
                string QueryString = null;
                //
                if (core.siteProperties.getBoolean("allowPasswordEmail", true))
                {
                    returnResult += Properties.Resources.defaultForgetPassword_html;
                    //
                    // write out all of the form input (except state) to hidden fields so they can be read after login
                    returnResult += HtmlController.inputHidden("Type", FormTypeSendPassword);
                    foreach (string formKey in core.docProperties.getKeyList())
                    {
                        var formValue = core.docProperties.getProperty(formKey);
                        if (formValue.propertyType == DocPropertyModel.DocPropertyTypesEnum.form)
                        {
                            switch (GenericController.toUCase(formValue.name))
                            {
                            case "S":
                            case "MA":
                            case "MB":
                            case "USERNAME":
                            case "PASSWORD":
                            case "EMAIL":
                            case "TYPE":
                                break;

                            default:
                                returnResult = returnResult + HtmlController.inputHidden(formValue.name, formValue.value);
                                break;
                            }
                        }
                    }
                    QueryString  = core.doc.refreshQueryString;
                    QueryString  = GenericController.modifyQueryString(QueryString, "S", "");
                    QueryString  = GenericController.modifyQueryString(QueryString, "ccIPage", "");
                    returnResult = HtmlController.form(core, returnResult, QueryString);
                }
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnResult);
        }
Ejemplo n.º 26
0
        //
        //========================================================================
        /// <summary>
        /// decode an encrypted token with an integer and a date.
        /// result is 0 if there was a decode error
        /// </summary>
        /// <param name="core"></param>
        /// <param name="token"></param>
        public static TokenData decodeToken(CoreController core, string token)
        {
            var result = new TokenData();

            try {
                string   decodedString = twoWayDecrypt(core, token);
                string[] parts         = decodedString.Split(Convert.ToChar("\t"));
                if (parts.Length == 2)
                {
                    result.id      = GenericController.encodeInteger(parts[0]);
                    result.expires = GenericController.encodeDate(parts[1]);
                }
            } catch (Exception ex) {
                LogController.logError(core, ex, "DecodeToken failure. Returning blank result for token [" + token + "]");
            }
            return(result);
        }
Ejemplo n.º 27
0
        //
        //====================================================================================================
        //
        public static List <FieldTypeEditorAddonModel> getFieldEditorAddonList(CoreController core)
        {
            var result = new List <FieldTypeEditorAddonModel>();

            try {
                //
                // --use the last addon installed that is set to each field
                {
                    core.db.executeNonQuery("delete  from ccAddonContentFieldTypeRules from ccAddonContentFieldTypeRules r left join ccAggregateFunctions a on a.id=r.addonid where a.id is null");
                    string    sql = "select contentfieldtypeid, max(addonId) as editorAddonId from ccAddonContentFieldTypeRules group by contentfieldtypeid";
                    DataTable dt  = core.db.executeQuery(sql);
                    foreach (DataRow row in dt.Rows)
                    {
                        result.Add(new FieldTypeEditorAddonModel {
                            fieldTypeId   = encodeInteger(row["contentfieldtypeid"]),
                            editorAddonId = encodeInteger(row["editorAddonId"])
                        });
                    }
                }
                //
                // -- for field types without custom addons, use the addon selected for the field type
                {
                    string sql = ""
                                 + " select"
                                 + " t.id as contentfieldtypeid"
                                 + " ,t.editorAddonId"
                                 + " from ccFieldTypes t"
                                 + " left join ccaggregatefunctions a on a.id=t.editorAddonId"
                                 + " where (t.active<>0)and(a.active<>0) order by t.id";
                    DataTable dt = core.db.executeQuery(sql);
                    foreach (DataRow dr in dt.Rows)
                    {
                        int fieldTypeId = GenericController.encodeInteger(dr["contentfieldtypeid"]);
                        result.Add(new FieldTypeEditorAddonModel {
                            fieldTypeId   = fieldTypeId,
                            editorAddonId = GenericController.encodeInteger(dr["editorAddonId"])
                        });
                    }
                }
                return(result);
            } catch (Exception ex) {
                LogController.logError(core, ex);
                return(null);
            }
        }
Ejemplo n.º 28
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);
            }
        }
Ejemplo n.º 29
0
        //
        //====================================================================================================
        /// <summary>
        /// Check if the database exists
        /// </summary>
        /// <param name="catalog"></param>
        /// <returns></returns>
        public bool checkCatalogExists(string catalog)
        {
            bool returnOk = false;

            try {
                string    sql = null;
                DataTable dt  = null;
                //
                sql      = string.Format("SELECT database_id FROM sys.databases WHERE Name = '{0}'", catalog);
                dt       = executeQuery(sql);
                returnOk = (dt.Rows.Count > 0);
                dt.Dispose();
            } catch (Exception ex) {
                LogController.logError(core, ex);
                throw;
            }
            return(returnOk);
        }
Ejemplo n.º 30
0
        //
        //====================================================================================================
        // Pass spaces at the current cursor position
        //
        private int PassWhiteSpace(int CursorPosition, string TagString)
        {
            int tempPassWhiteSpace = 0;

            try {
                //
                tempPassWhiteSpace = CursorPosition;
                while ((TagString.Substring(tempPassWhiteSpace - 1, 1) == " ") && (tempPassWhiteSpace < TagString.Length))
                {
                    tempPassWhiteSpace = tempPassWhiteSpace + 1;
                }
                //
                return(tempPassWhiteSpace);
            } catch (Exception ex) {
                LogController.logError(core, ex);
            }
            return(tempPassWhiteSpace);
        }