示例#1
0
 public static bool EvaluateByRegex(this IEnumerable <FieldValue> filters, ContentBase content)
 {
     foreach (var field in filters)
     {
         if (content.ContainsKey(field.FieldName))
         {
             var value = content[field.FieldName];
             if (string.IsNullOrEmpty(field.Value))
             {
                 if (value == null || string.IsNullOrEmpty(value.ToString()))
                 {
                     continue;
                 }
                 else
                 {
                     return(false);
                 }
             }
             if (Regex.IsMatch(value.ToString(), field.Value, RegexOptions.IgnoreCase))
             {
                 continue;
             }
             else
             {
                 return(false);
             }
         }
         else
         {
             return(false);
         }
     }
     return(true);
 }
示例#2
0
        public virtual string Generate(ContentBase content)
        {
            string userKey = content.UserKey;

            if (string.IsNullOrEmpty(userKey))
            {
                userKey = GetColumnValueForUserKey(content);
            }
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = content.UUID;
            }
            else
            {
                if (userKey.Length > 90)
                {
                    userKey = userKey.Substring(0, 90);
                }

                var tmpUserKey = EscapeUserKey(content, userKey);

                int tries = 0;
                while (IfUserKeyExists(content, tmpUserKey))
                {
                    tries++;
                    tmpUserKey = userKey + "-" + tries.ToString();
                }
                userKey = tmpUserKey;
            }

            return(userKey);
        }
示例#3
0
        public virtual string Generate(ContentBase content)
        {
            string userKey = content.UserKey;
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = GetColumnValueForUserKey(content);
            }
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = content.UUID;
            }
            else
            {
                if (userKey.Length > 90)
                {
                    userKey = userKey.Substring(0, 90);
                }

                var tmpUserKey = EscapeUserKey(content, userKey);

                int tries = 0;
                while (IfUserKeyExists(content, tmpUserKey))
                {
                    tries++;
                    tmpUserKey = userKey + "-" + tries.ToString();
                }
                userKey = tmpUserKey;
            }

            return userKey;
        }
示例#4
0
文件: FieldValue.cs 项目: Epitomy/CMS
 public static bool EvaluateByRegex(this IEnumerable<FieldValue> filters, ContentBase content)
 {
     foreach (var field in filters)
     {
         if (content.ContainsKey(field.FieldName))
         {
             var value = content[field.FieldName];
             if (string.IsNullOrEmpty(field.Value))
             {
                 if (value == null || string.IsNullOrEmpty(value.ToString()))
                 {
                     continue;
                 }
                 else
                 {
                     return false;
                 }
             }
             if (Regex.IsMatch(value.ToString(), field.Value, RegexOptions.IgnoreCase))
             {
                 continue;
             }
             else
             {
                 return false;
             }
         }
         else
         {
             return false;
         }
     }
     return true;
 }
示例#5
0
        public virtual string Generate(ContentBase content)
        {
            string userKey = content.UserKey;
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = GetColumnValueForUserKey(content);
            }
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = content.UUID;
            }
            else
            {
                if (userKey.Length > 256)
                {
                    userKey = userKey.Substring(0, 256);
                }

                var tmpUserKey = EscapeUserKey(content, userKey);

                int tries = 0;
                while (IfUserKeyExists(content, tmpUserKey))
                {
                    tries++;
                    tmpUserKey = userKey + "-" + Kooboo.UniqueIdGenerator.GetInstance().GetBase32UniqueId(tries);
                }
                userKey = tmpUserKey;
            }

            return userKey;
        }
示例#6
0
        public virtual string Generate(ContentBase content)
        {
            string userKey = content.UserKey;

            if (string.IsNullOrEmpty(userKey))
            {
                userKey = GetColumnValueForUserKey(content);
            }
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = content.UUID;
            }
            else
            {
                if (userKey.Length > 256)
                {
                    userKey = userKey.Substring(0, 256);
                }

                var escapedUserKey = EscapeUserKey(content, userKey);

                var tmpUserKey = escapedUserKey;

                int tries = 0;
                while (IfUserKeyExists(content, tmpUserKey))
                {
                    tries++;
                    tmpUserKey = escapedUserKey + "-" + Kooboo.UniqueIdGenerator.GetInstance().GetBase32UniqueId(tries);
                }
                userKey = tmpUserKey;
            }

            return(userKey);
        }
示例#7
0
        protected virtual bool IfUserKeyExists(ContentBase content, string userKey)
        {
            var repository = new Repository(content.Repository);

            if (content is TextContent)
            {
                var textContent   = (TextContent)content;
                var schema        = new Schema(repository, textContent.SchemaName);
                var contentExists = schema.CreateQuery().WhereEquals("UserKey", userKey).FirstOrDefault();
                if (contentExists != null)
                {
                    return(contentExists.UUID != content.UUID);
                }
                return(false);
            }
            else if (content is MediaContent)
            {
                var mediaContent  = (MediaContent)content;
                var folder        = new MediaFolder(repository, mediaContent.FolderName);
                var contentExists = folder.CreateQuery().WhereEquals("UserKey", userKey).FirstOrDefault();
                if (contentExists != null)
                {
                    return(contentExists.UUID != content.UUID);
                }
                return(false);
            }
            return(false);
        }
示例#8
0
        protected virtual string EscapeUserKey(ContentBase content, string userKey)
        {
            string tmpUserKey = userKey.StripAllTags();

            //http://stackoverflow.com/questions/9565360/how-to-convert-utf-8-characters-to-ascii-for-use-in-a-url/9628594#9628594
            tmpUserKey = RemoveDiacritics(tmpUserKey);

            Repository repository = content.GetRepository().AsActual();
            tmpUserKey = Regex.Replace(tmpUserKey, repository.UserKeyReplacePattern, repository.UserKeyHyphens);

            return tmpUserKey;
        }
 /// <summary>
 /// 排序系统字段的其它自定义字段值
 /// </summary>
 /// <param name="content">The content.</param>
 /// <returns></returns>
 public static NameValueCollection ExcludeBasicFields(ContentBase content)
 {
     NameValueCollection values = new NameValueCollection();
     foreach (var key in content.Keys.Where(key => !contentBasicFields.Contains(key, StringComparer.CurrentCultureIgnoreCase)))
     {
         if (content[key] != null)
         {
             values[key] = content[key].ToString();
         }
     }
     return values;
 }
示例#10
0
        protected virtual string EscapeUserKey(ContentBase content, string userKey)
        {
            string tmpUserKey = userKey.StripAllTags();

            //http://stackoverflow.com/questions/9565360/how-to-convert-utf-8-characters-to-ascii-for-use-in-a-url/9628594#9628594
            tmpUserKey = RemoveDiacritics(tmpUserKey);

            Repository repository = content.GetRepository().AsActual();

            tmpUserKey = Regex.Replace(tmpUserKey, repository.UserKeyReplacePattern, repository.UserKeyHyphens);

            return(tmpUserKey);
        }
示例#11
0
 /// <summary>
 /// Gets the summary.
 /// </summary>
 /// <param name="content">The content.</param>
 /// <returns></returns>
 public static string GetSummary(this ContentBase content)
 {
     if (content is TextContent)
     {
         var textContent    = (TextContent)content;
         var schema         = textContent.GetSchema().AsActual();
         var summarizeField = schema.GetSummarizeColumn();
         if (summarizeField != null && content.ContainsKey(summarizeField.Name))
         {
             return(content[summarizeField.Name] == null ? "" : content[summarizeField.Name].ToString());
         }
         return("");
     }
     else
     {
         var mediaContent = (MediaContent)content;
         return(mediaContent.FileName);
     }
 }
示例#12
0
 protected virtual string GetColumnValueForUserKey(ContentBase content)
 {
     if (content is TextContent)
     {
         var textContent    = (TextContent)content;
         var repository     = new Repository(textContent.Repository);
         var schema         = new Schema(repository, textContent.SchemaName).AsActual();
         var summarizeField = schema.Columns.Where(it => it.Summarize == true).FirstOrDefault();
         if (summarizeField == null || textContent[summarizeField.Name] == null)
         {
             return(textContent.UUID);
         }
         else
         {
             return(textContent[summarizeField.Name].ToString());
         }
     }
     else if (content is MediaContent)
     {
         return(((MediaContent)content).FileName);
     }
     return(null);
 }
示例#13
0
 protected virtual string GetColumnValueForUserKey(ContentBase content)
 {
     if (content is TextContent)
     {
         var textContent = (TextContent)content;
         var repository = new Repository(textContent.Repository);
         var schema = new Schema(repository, textContent.SchemaName).AsActual();
         var summarizeField = schema.Columns.Where(it => it.Summarize == true).FirstOrDefault();
         if (summarizeField == null || textContent[summarizeField.Name] == null)
         {
             return textContent.UUID;
         }
         else
         {
             return textContent[summarizeField.Name].ToString();
         }
     }
     else if (content is MediaContent)
     {
         return ((MediaContent)content).FileName;
     }
     return null;
 }
示例#14
0
        public virtual string Generate(ContentBase content)
        {
            string userKey = content.UserKey;

            //#warning sqlce test...
            //            return userKey;
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = GetColumnValueForUserKey(content);
                if (!string.IsNullOrEmpty(userKey))
                {
                    Repository repository = content.GetRepository().AsActual();
                    userKey = TrimUserKey(userKey, repository.UserKeyReplacePattern, repository.UserKeyHyphens);
                }
            }
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = content.UUID;
            }
            else
            {
                if (userKey.Length > 90)
                {
                    userKey = userKey.Substring(0, 90);
                }
                int    tries      = 0;
                string tmpUserKey = userKey.StripAllTags();
                while (IfUserKeyExists(content, tmpUserKey))
                {
                    tries++;
                    tmpUserKey = userKey + "-" + tries.ToString();
                }
                userKey = tmpUserKey;
            }

            return(userKey);
        }
示例#15
0
        public virtual string Generate(ContentBase content)
        {
            string userKey = content.UserKey;
            //#warning sqlce test...
            //            return userKey;
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = GetColumnValueForUserKey(content);
                if (!string.IsNullOrEmpty(userKey))
                {
                    Repository repository = content.GetRepository().AsActual();
                    userKey = TrimUserKey(userKey, repository.UserKeyReplacePattern, repository.UserKeyHyphens);
                }
            }
            if (string.IsNullOrEmpty(userKey))
            {
                userKey = content.UUID;
            }
            else
            {
                if (userKey.Length > 90)
                {
                    userKey = userKey.Substring(0, 90);
                }
                int tries = 0;
                string tmpUserKey = userKey.StripAllTags();
                while (IfUserKeyExists(content, tmpUserKey))
                {
                    tries++;
                    tmpUserKey = userKey + "-" + tries.ToString();
                }
                userKey = tmpUserKey;
            }

            return userKey;
        }
示例#16
0
 public virtual string Generate(ContentBase content)
 {
     return UniqueIdGenerator.GetInstance().GetBase32UniqueId(16);
 }
示例#17
0
 protected virtual bool IfUserKeyExists(ContentBase content, string userKey)
 {
     var repository = new Repository(content.Repository);
     if (content is TextContent)
     {
         var textContent = (TextContent)content;
         var schema = new Schema(repository, textContent.SchemaName);
         var contentExists = schema.CreateQuery().WhereEquals("UserKey", userKey).FirstOrDefault();
         if (contentExists != null)
         {
             return contentExists.UUID != content.UUID;
         }
         return false;
     }
     else if (content is MediaContent)
     {
         var mediaContent = (MediaContent)content;
         var folder = new MediaFolder(repository, mediaContent.FolderName);
         var contentExists = folder.CreateQuery().WhereEquals("UserKey", userKey).FirstOrDefault();
         if (contentExists != null)
         {
             return contentExists.UUID != content.UUID;
         }
         return false;
     }
     return false;
 }
示例#18
0
 public virtual string Generate(ContentBase content)
 {
     return(UniqueIdGenerator.GetInstance().GetBase32UniqueId(16));
 }
示例#19
0
        public ContentIntegrateId(ContentBase content)
            : this(content.Repository, content.FolderName, content.UUID)
        {

        }
示例#20
0
 public ContentIntegrateId(ContentBase content)
     : this(content.Repository, content.FolderName, content.UUID)
 {
 }
示例#21
0
文件: QueryTests.cs 项目: Godoy/CMS
 public override string Generate(ContentBase content)
 {
     return content.UserKey;
 }
示例#22
0
 /// <summary>
 /// Gets the repository.
 /// </summary>
 /// <param name="content">The content.</param>
 /// <returns></returns>
 public static Repository GetRepository(this ContentBase content)
 {
     return(new Repository(content.Repository));
 }