public static int?ExtractYear(System.Collections.Generic.IEnumerable <string> words)
        {
            if (words is null)
            {
                return(null);
            }

            System.Collections.Generic.List <int> parsedYears = new System.Collections.Generic.List <int>();

            foreach (string word in words)
            {
                int  year;
                bool successfullyParsed = int.TryParse(word, out year);

                if (successfullyParsed)
                {
                    parsedYears.Add(year);
                }
            }

            System.Collections.Generic.IEnumerable <int> yearsWithValidPriorities = parsedYears.Where(year => GetPriority(year) != 0);

            if (yearsWithValidPriorities.Count() == 0)
            {
                return(null);
            }

            return(yearsWithValidPriorities.OrderByDescending(year => GetPriority(year)).First());
        }
Пример #2
0
 SharedInterfaces(
     System.Collections.Generic.IEnumerable <Bam.Core.Module> objectFiles)
 {
     System.Collections.Generic.IEnumerable <System.Type> sharedInterfaces = null;
     foreach (var input in objectFiles)
     {
         var interfaces = input.Settings.GetType().GetInterfaces().Where(item => (item != typeof(Bam.Core.ISettingsBase)) && typeof(Bam.Core.ISettingsBase).IsAssignableFrom(item));
         if (null == sharedInterfaces)
         {
             sharedInterfaces = interfaces;
         }
         else
         {
             sharedInterfaces = sharedInterfaces.Intersect(interfaces);
         }
     }
     return(new Bam.Core.TypeArray(sharedInterfaces.OrderByDescending(item =>
     {
         var precedenceAttribs = item.GetCustomAttributes(typeof(Bam.Core.SettingsPrecedenceAttribute), false);
         if (precedenceAttribs.Length > 0)
         {
             return (precedenceAttribs[0] as Bam.Core.SettingsPrecedenceAttribute).Order;
         }
         return 0;
     })));
 }
Пример #3
0
        /// <summary>
        /// 得到有效的XPath表达式
        /// </summary>
        /// <param name="paths">原始表达式集合</param>
        /// <returns></returns>
        protected string GetValidaXpath(System.Collections.Generic.IEnumerable <Skybot.Collections.Analyse.ExpressionEntity> xPathEntitys)
        {
            //开始对数据进行分析
            if (xPathEntitys.Count() > 0)
            {
                //路径
                List <PathEneity> paths = new List <PathEneity>();
                #region 开始对xpath表达式进行分析

                //循环深度
                for (int Lay = 1; Lay <= xPathEntitys.OrderByDescending(p => p.NodeLayIndex).First().NodeLayIndex; Lay++)
                {
                    //分析当前 节点表达式的值所出现的位置与次数
                    var res = from x in xPathEntitys
                              select new
                    {
                        entity = x,
                        //字符串
                        str = (x.NodeLayIndex >= Lay ? x.NodeArr.ElementAt(Lay) : string.Empty),
                        Lay = Lay
                    };
                    //分组找出最大的那个 做为有效参数
                    var grores = res.Where(p => p.str != string.Empty).
                                 GroupBy(p => p.str).OrderByDescending(p => p.Key.Count());

                    //组总数如果小于0则放弃
                    if (grores.Count() > 0)
                    {
                        if (!(grores.First().Key.Contains("&") || grores.First().Key.Contains("\"")))
                        {
                            //添加到对像中
                            paths.Add(new PathEneity()
                            {
                                Count   = grores.First().Count(),
                                PathStr = grores.First().Key
                            });
                        }
                        else
                        {
                            break;
                        }
                    }
                    else
                    {
                        break;
                    }
                }



                #endregion

                string str = "/" + string.Join("/", paths.Select(p => p.PathStr));
                return(str);
            }
            return(string.Empty);
        }
Пример #4
0
        public ActionResult Index(string[] includedTags, string monthYearPair = "")
        {
            System.Collections.Generic.IEnumerable <IJournalEntry> validEntries    = Enumerable.Empty <IJournalEntry>();
            System.Collections.Generic.IEnumerable <IJournalEntry> filteredEntries = Enumerable.Empty <IJournalEntry>();
            ApplicationUser user = null;

            if (User.Identity.IsAuthenticated)
            {
                user = UserManager.FindById(User.Identity.GetUserId());
                StaffRank userRank = user.GetStaffRank(User);
                validEntries = TemplateCache.GetAll <IJournalEntry>().Where(blog => blog.IsPublished() && (blog.Public || blog.MinimumReadLevel <= userRank));
            }
            else
            {
                validEntries = TemplateCache.GetAll <IJournalEntry>().Where(blog => blog.IsPublished() && blog.Public);
            }

            System.Collections.Generic.IEnumerable <string> allTags = validEntries.SelectMany(blog => blog.Tags).Distinct();
            if (includedTags != null && includedTags.Count() > 0)
            {
                validEntries = validEntries.Where(blog => blog.Tags.Any(tag => includedTags.Contains(tag)));
            }

            if (!string.IsNullOrWhiteSpace(monthYearPair))
            {
                string[] pair  = monthYearPair.Split("|||", StringSplitOptions.RemoveEmptyEntries);
                string   month = pair[0];
                int      year  = -1;

                if (!string.IsNullOrWhiteSpace(month) && int.TryParse(pair[1], out year))
                {
                    filteredEntries = validEntries.Where(blog =>
                                                         month.Equals(blog.PublishDate.ToString("MMMM", CultureInfo.InvariantCulture), StringComparison.InvariantCultureIgnoreCase) &&
                                                         blog.PublishDate.Year.Equals(year));
                }
            }

            if (filteredEntries.Count() == 0)
            {
                filteredEntries = validEntries;
            }

            BlogViewModel vModel = new BlogViewModel(filteredEntries.OrderByDescending(obj => obj.PublishDate))
            {
                AuthedUser     = user,
                MonthYearPairs = validEntries.Select(blog => new Tuple <string, int>(blog.PublishDate.ToString("MMMM", CultureInfo.InvariantCulture), blog.PublishDate.Year)).Distinct(),
                IncludeTags    = includedTags?.Where(tag => tag != "false").ToArray() ?? (new string[0]),
                AllTags        = allTags.ToArray()
            };

            return(View(vModel));
        }
Пример #5
0
        /// <summary>
        /// Loads all the backing data in the current directories to the cache
        /// </summary>
        /// <returns>full or partial success</returns>
        public static bool LoadEverythingToCache()
        {
            System.Collections.Generic.IEnumerable <Type> implimentedTypes = typeof(EntityTemplatePartial).Assembly.GetTypes().Where(ty => ty.GetInterfaces().Contains(typeof(IKeyedData)) &&
                                                                                                                                     ty.IsClass &&
                                                                                                                                     !ty.IsAbstract &&
                                                                                                                                     !ty.GetCustomAttributes <IgnoreAutomatedBackupAttribute>().Any());

            foreach (Type t in implimentedTypes.OrderByDescending(type => type == typeof(GaiaTemplate) ? 6 :
                                                                  type == typeof(ZoneTemplate) ? 5 :
                                                                  type == typeof(LocaleTemplate) ? 4 :
                                                                  type == typeof(RoomTemplate) ? 3 :
                                                                  type == typeof(PathwayTemplate) ? 2 :
                                                                  type.GetInterfaces().Contains(typeof(ILookupData)) ? 1 : 0))
            {
                LoadAllToCache(t);
            }

            return(true);
        }