Beispiel #1
0
        protected override void CreateChildControls()
        {
            var settings = new SummarySettings(SummaryMode.Words, WordLength, false);

            Text = SummaryParser.GetSummary(Text, settings);
            base.CreateChildControls();
        }
            public void Should_Return_True_For_Correct_Element()
            {
                // Given
                var parser = new SummaryParser();
                var node   = "<summary>Hello World</summary>".CreateXmlNode();

                // When
                var result = parser.CanParse(node);

                // Then
                Assert.True(result);
            }
            public void Should_Parse_Content_Recursivly()
            {
                // Given
                var commentParser = Substitute.For <ICommentParser>();
                var nodeParser    = new SummaryParser();
                var node          = "<summary>Hello World</summary>".CreateXmlNode();

                // When
                nodeParser.Parse(commentParser, node);

                // Then
                commentParser.Received(1).Parse(Arg.Any <XmlNode>());
            }
Beispiel #4
0
        public static IEnumerable <ContentListSearchResult> GetSearchResults(string catalog, ContentListSearchCriteria criteria, int skip, int take, int summaryWordCount, out int hitCount)
        {
            var searchService = ServiceBus.ResolveService <LuceneSearchService>();

            var searchQuery = new SearchQuery();

            if (String.IsNullOrWhiteSpace(criteria.Term) && criteria.Topics == null && criteria.Types == null && string.IsNullOrEmpty(criteria.StartDate))
            {
                searchQuery.Text         = "a* OR b* OR c* OR d* OR e* OR f* OR g* OR h* OR i* OR j* OR k* OR l* OR m* OR n* OR o* OR p* OR r* OR s* OR t* OR u* OR v* OR w*";
                searchQuery.SearchFields = new[] { "Title" };

                if (string.IsNullOrEmpty(criteria.OrderBy))
                {
                    criteria.OrderBy = "PublishDate DESC";
                }
            }
            else
            {
                BuildSearchQuery(out searchQuery, criteria, criteria.SearchFieldNames);
            }

            searchQuery.IndexName         = catalog;
            searchQuery.HighlightedFields = null;
            searchQuery.Skip    = skip;
            searchQuery.Take    = take;
            searchQuery.OrderBy = criteria.OrderBy == null ? null : new string[] { criteria.OrderBy, "PublishDate DESC" };

            var resultSet = searchService.Search(searchQuery);


            hitCount = resultSet.HitCount;

            var results = new List <ContentListSearchResult>();

            foreach (var result in resultSet.SetContentLinks())
            {
                var searchResult = new ContentListSearchResult();
                foreach (var fieldName in criteria.FieldsToShow)
                {
                    switch (fieldName)
                    {
                    case "Title":
                        searchResult.Title = result.GetValue("Title");
                        break;

                    case "PublicationDate":
                        searchResult.PublicationDate = DateTime.Parse(result.GetValue("PublicationDate")).ToLocalTime();
                        break;

                    case "Link":
                        searchResult.Link = result.GetValue("Link");
                        break;

                    case "Type":
                        var type = result.GetValue("ContentType");
                        searchResult.Type = _searchTypes.Where(t => t.Item2 == type).FirstOrDefault().Item1;
                        break;

                    default:
                        searchResult.Summary = result.GetValue(fieldName);
                        if (string.IsNullOrWhiteSpace(searchResult.Summary))
                        {
                            var content = result.GetValue("Content").StripHtmlTags();
                            searchResult.Summary = SummaryParser.GetSummary(content, new SummarySettings(SummaryMode.Words, summaryWordCount, true, true));
                        }
                        break;
                    }
                }
                results.Add(searchResult);
            }

            return(results);
        }
Beispiel #5
0
        public DataSet GenerateSkillTable()
        {
            Wz_Node skillWz = PluginManager.FindWz(Wz_Type.Skill);

            if (skillWz == null)
            {
                return(null);
            }

            Regex r = new Regex(@"^(\d+)\.img", RegexOptions.Compiled);

            DataSet   ds       = new DataSet();
            DataTable jobTable = new DataTable("ms_job");

            jobTable.Columns.Add("jobID", typeof(string));
            jobTable.Columns.Add("jobName", typeof(string));

            DataTable skillTable = new DataTable("ms_skill");

            skillTable.Columns.Add("jobID", typeof(string));
            skillTable.Columns.Add("skillID", typeof(string));
            skillTable.Columns.Add("skillName", typeof(string));
            skillTable.Columns.Add("skillDesc", typeof(string));
            skillTable.Columns.Add("maxLevel", typeof(int));
            skillTable.Columns.Add("invisible", typeof(bool));
            skillTable.Columns.Add("hyper", typeof(int));
            skillTable.Columns.Add("reqSkill", typeof(string));
            skillTable.Columns.Add("reqSkillLevel", typeof(int));
            skillTable.Columns.Add("reqLevel", typeof(int));

            DataTable skillLevelTable = new DataTable("ms_skillLevel");

            skillLevelTable.Columns.Add("skillID", typeof(string));
            skillLevelTable.Columns.Add("level", typeof(int));
            skillLevelTable.Columns.Add("levelDesc", typeof(string));

            DataTable skillCommonTable = new DataTable("ms_skillCommon");

            skillCommonTable.Columns.Add("skillID", typeof(string));
            skillCommonTable.Columns.Add("commonName", typeof(string));
            skillCommonTable.Columns.Add("commonValue", typeof(string));

            DataTable skillPVPCommonTable = new DataTable("ms_skillPVPCommon");

            skillPVPCommonTable.Columns.Add("skillID", typeof(string));
            skillPVPCommonTable.Columns.Add("commonName", typeof(string));
            skillPVPCommonTable.Columns.Add("commonValue", typeof(string));

            DataTable skillHTable = new DataTable("ms_skillH");

            skillHTable.Columns.Add("skillID", typeof(string));
            skillHTable.Columns.Add("desc", typeof(string));
            skillHTable.Columns.Add("pdesc", typeof(string));
            skillHTable.Columns.Add("h", typeof(string));
            skillHTable.Columns.Add("ph", typeof(string));
            skillHTable.Columns.Add("hch", typeof(string));

            StringResult sr;

            foreach (Wz_Node node in skillWz.Nodes)
            {
                //获取职业
                Match    m   = r.Match(node.Text);
                Wz_Image img = node.GetValue <Wz_Image>(null);
                if (!m.Success)
                {
                    continue;
                }
                if (img == null || !img.TryExtract())
                {
                    continue;
                }
                //导入职业
                string jobID = m.Result("$1");
                sl.StringSkill2.TryGetValue(jobID, out sr);
                jobTable.Rows.Add(jobID, (sr != null ? sr["bookName"] : null));

                //获取技能
                Wz_Node skillListNode = img.Node.FindNodeByPath("skill");
                if (skillListNode == null || skillListNode.Nodes.Count <= 0)
                {
                    continue;
                }

                foreach (Wz_Node skillNode in skillListNode.Nodes)
                {
                    Skill skill = Skill.CreateFromNode(skillNode, PluginManager.FindWz);
                    if (skill == null)
                    {
                        continue;
                    }

                    // if (skill.Invisible) //过滤不可见技能
                    //     continue;

                    //导入技能
                    string skillID = skillNode.Text;
                    sl.StringSkill2.TryGetValue(skillID, out sr);

                    string reqSkill      = null;
                    int    reqSkillLevel = 0;
                    if (skill.ReqSkill.Count > 0)
                    {
                        foreach (var kv in skill.ReqSkill)
                        {
                            reqSkill      = kv.Key.ToString();
                            reqSkillLevel = kv.Value;
                        }
                    }

                    skillTable.Rows.Add(
                        jobID,
                        skillID,
                        sr != null ? sr.Name : null,
                        sr != null ? sr.Desc : null,
                        skill.MaxLevel,
                        skill.Invisible,
                        skill.Hyper,
                        reqSkill,
                        reqSkillLevel,
                        skill.ReqLevel
                        );


                    if (!skill.PreBBSkill)
                    {
                        //导入技能common
                        foreach (var kv in skill.Common)
                        {
                            skillCommonTable.Rows.Add(
                                skillID,
                                kv.Key,
                                kv.Value
                                );
                        }
                        foreach (var kv in skill.PVPcommon)
                        {
                            skillPVPCommonTable.Rows.Add(
                                skillID,
                                kv.Key,
                                kv.Value
                                );
                        }
                        //导入技能说明
                        skillHTable.Rows.Add(
                            skillID,
                            sr != null ? sr["desc"] : null,
                            sr != null ? sr["pdesc"] : null,
                            sr != null ? sr["h"] : null,
                            sr != null ? sr["ph"] : null,
                            sr != null ? sr["hch"] : null
                            );
                    }

                    //导入技能等级
                    for (int i = 1, j = skill.MaxLevel + (skill.CombatOrders ? 2 : 0); i <= j; i++)
                    {
                        skill.Level = i;
                        string levelDesc = SummaryParser.GetSkillSummary(skill, sr, SummaryParams.Default);
                        skillLevelTable.Rows.Add(
                            skillID,
                            i,
                            levelDesc);
                    }
                }

                img.Unextract();
            }

            ds.Tables.Add(jobTable);
            ds.Tables.Add(skillTable);
            ds.Tables.Add(skillLevelTable);
            ds.Tables.Add(skillCommonTable);
            ds.Tables.Add(skillPVPCommonTable);
            ds.Tables.Add(skillHTable);
            return(ds);
        }
Beispiel #6
0
        private Bitmap RenderSkill(out int picH)
        {
            //int h = 128;
            Bitmap   bitmap = new Bitmap(290, DefaultPicHeight);
            Graphics g      = Graphics.FromImage(bitmap);

            picH = 33; //iconY

            StringResult sr;

            if (!StringLinker.StringSkill.TryGetValue(skill.SkillID, out sr))
            {
                sr      = new StringResult(true);
                sr.Name = "(null)";
            }

            StringFormat format = new StringFormat();

            format.Alignment = StringAlignment.Center;

            g.DrawString(sr.Name, GearGraphics.ItemNameFont, Brushes.White, 143, 10, format);//绘制标题
            if (skill.Icon.Bitmap != null)
            {
                g.DrawImage(GearGraphics.EnlargeBitmap(skill.Icon.Bitmap),
                            14 + (1 - skill.Icon.Origin.X) * 2,
                            picH + (33 - skill.Icon.Bitmap.Height) * 2);//绘制图标
            }

            //绘制desc
            picH = 35;
            GearGraphics.DrawString(g, "[最高等级:" + skill.MaxLevel + "]", GearGraphics.ItemDetailFont, 90, 270, ref picH, 16);
            if (sr.Desc != null)
            {
                GearGraphics.DrawString(g, sr.Desc, GearGraphics.ItemDetailFont, 90, 270, ref picH, 16);
            }

            picH = Math.Max(picH, 114);
            g.DrawLine(Pens.White, 6, picH, 283, picH); //分割线
            picH += 5;

            if (skill.Level > 0)
            {
                string hStr = null;
                if (skill.PreBBSkill)
                {
                    if (sr.SkillH.Count >= skill.Level)
                    {
                        hStr = sr.SkillH[skill.Level - 1];
                    }
                }
                else
                {
                    if (sr.SkillH.Count > 0)
                    {
                        hStr = SummaryParser.GetSkillSummary(skill, skill.Level, sr, SummaryParams.Default);
                    }
                }

                picH += 4;
                GearGraphics.DrawString(g, "[现在等级 " + skill.Level + "]", GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
                GearGraphics.DrawString(g, hStr, GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
            }

            if (skill.Level < skill.MaxLevel)
            {
                string hStr = null;
                if (skill.PreBBSkill)
                {
                    if (sr.SkillH.Count >= skill.Level + 1)
                    {
                        hStr = sr.SkillH[skill.Level];
                    }
                }
                else
                {
                    if (sr.SkillH.Count > 0)
                    {
                        hStr = SummaryParser.GetSkillSummary(skill, skill.Level + 1, sr, SummaryParams.Default);
                    }
                }

                picH += 4;
                GearGraphics.DrawString(g, "[下次等级 " + (skill.Level + 1) + "]", GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
                GearGraphics.DrawString(g, hStr, GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
            }
            picH += 9;
            g.Dispose();
            return(bitmap);
        }
        private Bitmap RenderSkill(CanvasRegion region, out int picH)
        {
            Bitmap       bitmap = new Bitmap(region.Width, DefaultPicHeight);
            Graphics     g      = Graphics.FromImage(bitmap);
            StringFormat format = (StringFormat)StringFormat.GenericDefault.Clone();

            picH = 0;

            //获取文字
            StringResult sr;

            if (StringLinker == null || !StringLinker.StringSkill.TryGetValue(Skill.SkillID, out sr))
            {
                sr      = new StringResultSkill();
                sr.Name = "(null)";
            }

            //绘制技能名称
            format.Alignment = StringAlignment.Center;
            g.DrawString(sr.Name, GearGraphics.ItemNameFont2, Brushes.White, region.TitleCenterX, 10, format);

            //绘制图标
            picH = 33;
            g.FillRectangle(GearGraphics.GearIconBackBrush2, 14, picH, 68, 68);
            if (Skill.Icon.Bitmap != null)
            {
                g.DrawImage(GearGraphics.EnlargeBitmap(Skill.Icon.Bitmap),
                            14 + (1 - Skill.Icon.Origin.X) * 2,
                            picH + (33 - Skill.Icon.Bitmap.Height) * 2);
            }

            //绘制desc
            picH = 35;
            if (!Skill.PreBBSkill)
            {
                GearGraphics.DrawString(g, "[Max Level:" + Skill.MaxLevel + "]", GearGraphics.ItemDetailFont2, region.SkillDescLeft, region.TextRight, ref picH, 16);
            }

            if (sr.Desc != null)
            {
                string hdesc = SummaryParser.GetSkillSummary(sr.Desc, Skill.Level, Skill.Common, SummaryParams.Default);
                //string hStr = SummaryParser.GetSkillSummary(skill, skill.Level, sr, SummaryParams.Default);
                GearGraphics.DrawString(g, hdesc, GearGraphics.ItemDetailFont2, region.SkillDescLeft, region.TextRight, ref picH, 16);
            }
            if (Skill.ReqLevel > 0)
            {
                GearGraphics.DrawString(g, "#c[Requires: " + Skill.ReqLevel.ToString() + "]#", GearGraphics.ItemDetailFont2, region.SkillDescLeft, region.TextRight, ref picH, 16);
            }
            if (Skill.ReqAmount > 0)
            {
                GearGraphics.DrawString(g, "#c" + ItemStringHelper.GetSkillReqAmount(Skill.SkillID, Skill.ReqAmount) + "#", GearGraphics.ItemDetailFont2, region.SkillDescLeft, region.TextRight, ref picH, 16);
            }

            //分割线
            picH = Math.Max(picH, 114);
            g.DrawLine(Pens.White, region.SplitterX1, picH, region.SplitterX2, picH);
            picH += 9;

            if (Skill.Level > 0)
            {
                string hStr = SummaryParser.GetSkillSummary(Skill, Skill.Level, sr, SummaryParams.Default, new SkillSummaryOptions
                {
                    ConvertCooltimeMS = this.DisplayCooltimeMSAsSec,
                    ConvertPerM       = this.DisplayPermyriadAsPercent
                });
                GearGraphics.DrawString(g, "[Level " + Skill.Level + "]", GearGraphics.ItemDetailFont, region.LevelDescLeft, region.TextRight, ref picH, 16);
                if (hStr != null)
                {
                    GearGraphics.DrawString(g, hStr, GearGraphics.ItemDetailFont2, region.LevelDescLeft, region.TextRight, ref picH, 16);
                }
            }

            if (Skill.Level < Skill.MaxLevel)
            {
                string hStr = SummaryParser.GetSkillSummary(Skill, Skill.Level + 1, sr, SummaryParams.Default, new SkillSummaryOptions
                {
                    ConvertCooltimeMS = this.DisplayCooltimeMSAsSec,
                    ConvertPerM       = this.DisplayPermyriadAsPercent
                });
                GearGraphics.DrawString(g, "[Next Level " + (Skill.Level + 1) + "]", GearGraphics.ItemDetailFont, region.LevelDescLeft, region.TextRight, ref picH, 16);
                if (hStr != null)
                {
                    GearGraphics.DrawString(g, hStr, GearGraphics.ItemDetailFont2, region.LevelDescLeft, region.TextRight, ref picH, 16);
                }
            }
            picH += 9;

            List <string> skillDescEx = new List <string>();

            if (ShowProperties)
            {
                List <string> attr = new List <string>();
                if (Skill.Invisible)
                {
                    attr.Add("Invisible");
                }
                if (Skill.Hyper != HyperSkillType.None)
                {
                    attr.Add("Hyper: " + Skill.Hyper);
                }
                if (Skill.CombatOrders)
                {
                    attr.Add("Combat Orders");
                }
                if (Skill.NotRemoved)
                {
                    attr.Add("Not Removed");
                }
                if (Skill.MasterLevel > 0 && Skill.MasterLevel < Skill.MaxLevel)
                {
                    attr.Add("Inital Mastery LVL: " + Skill.MasterLevel);
                }

                if (attr.Count > 0)
                {
                    skillDescEx.Add("#c" + string.Join(", ", attr.ToArray()) + "#");
                }
            }

            if (ShowDelay && Skill.Action.Count > 0)
            {
                foreach (string action in Skill.Action)
                {
                    skillDescEx.Add("#c[Delay] " + action + ": " + CharaSimLoader.GetActionDelay(action) + " ms#");
                }
            }

            if (ShowReqSkill && Skill.ReqSkill.Count > 0)
            {
                foreach (var kv in Skill.ReqSkill)
                {
                    string skillName;
                    if (this.StringLinker != null && this.StringLinker.StringSkill.TryGetValue(kv.Key, out sr))
                    {
                        skillName = sr.Name;
                    }
                    else
                    {
                        skillName = kv.Key.ToString();
                    }
                    skillDescEx.Add("#c[Requires] " + skillName + ": " + kv.Value + "#");
                }
            }

            if (skillDescEx.Count > 0)
            {
                g.DrawLine(Pens.White, region.SplitterX1, picH, region.SplitterX2, picH);
                picH += 9;
                foreach (var descEx in skillDescEx)
                {
                    GearGraphics.DrawString(g, descEx, GearGraphics.ItemDetailFont, region.LevelDescLeft, region.TextRight, ref picH, 16);
                }
                picH += 9;
            }

            format.Dispose();
            g.Dispose();
            return(bitmap);
        }
        //***********Helper Methods***********//
        //************************************//
        //************************************//
        #region SetBlendedListItems

        private List <BlendedListItem> SetBlendedListItems(IResultSet results)
        {
            log.Info("Begin SetBlendedListItems.");
            var resultSet       = new List <BlendedListItem>();
            var taxonomyManager = TaxonomyManager.GetManager();

            log.Debug("Iterating through the results.");
            foreach (IDocument result in results)
            {
                log.Trace("Getting a new instance of BlendedListItem.");
                var newsResult = new BlendedListItem();

                log.Trace(() => String.Join("\n", result.Fields.Select(f => f.Name + ": " + f.Value)));

                if (result.Fields.Any(x => x.Name == "Title"))
                {
                    newsResult.Title = result.GetValue("Title").ToString();
                    log.Trace("Title Set.");
                }

                if (result.Fields.Any(x => x.Name == "LocationStreet"))
                {
                    newsResult.LocationStreet = result.GetValue("LocationStreet").ToString();
                    log.Trace("LocationStreet Set.");
                }

                if (result.Fields.Any(x => x.Name == "LocationState"))
                {
                    newsResult.LocationState = result.GetValue("LocationState").ToString();
                    log.Trace("LocationState Set.");
                }

                if (result.Fields.Any(x => x.Name == "LocationCity"))
                {
                    newsResult.LocationCity = result.GetValue("LocationCity").ToString();
                    log.Trace("LocationCity Set.");
                }

                if (result.Fields.Any(x => x.Name == "Summary"))
                {
                    newsResult.Summary = result.GetValue("Summary").ToString();
                    log.Trace("Summary Set.");
                }

                if (result.Fields.Any(x => x.Name == "Content"))
                {
                    newsResult.Content = result.GetValue("Content").ToString();
                    log.Trace("Content Set.");
                }

                var featured = result.GetValue("FeaturedRank").ToString() == "1" ? true : false;
                newsResult.Featured = featured;

                if (result.Fields.Any(x => x.Name == "Link"))
                {
                    newsResult.Link = result.GetValue("Link").ToString();
                    log.Trace("Link  Set.");
                }

                if (result.Fields.Any(x => x.Name == "EventStart"))
                {
                    try
                    {
                        DateTime dp = DateTime.MinValue;
                        //newsResult.EventStartDate = DateTime.ParseExact(result.GetValue("EventStart").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                        DateTime.TryParseExact(result.GetValue("EventStart").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out dp);
                        newsResult.EventStartDate = dp;
                        //log.Trace("EventStart Set.");
                    }
                    catch (Exception ex)
                    {
                        log.Error("Source: {0}", ex.Source);
                        log.Error("Stack Trace: {0}", ex.StackTrace);
                        log.Error("Message: {0}", ex.Message);
                    }
                }

                if (result.Fields.Any(x => x.Name == "EventEnd"))
                {
                    try
                    {
                        /*newsResult.EventEndDate = DateTime.ParseExact(result.GetValue("EventStart").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                         * log.Trace("EventStart Set.");*/
                        DateTime dp = DateTime.MinValue;
                        DateTime.TryParseExact(result.GetValue("EventEnd").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out dp);
                        newsResult.EventEndDate = dp;
                    }
                    catch (Exception ex)
                    {
                        log.Error("Source: {0}", ex.Source);
                        log.Error("Stack Trace: {0}", ex.StackTrace);
                        log.Error("Message: {0}", ex.Message);
                    }
                }

                if (result.Fields.Any(x => x.Name == "PublishDate"))
                {
                    try
                    {
                        /*newsResult.PublicationDate = DateTime.ParseExact(result.GetValue("PublishDate").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                         * log.Trace("PublishDate Set.");*/
                        DateTime dp = DateTime.MinValue;
                        DateTime.TryParseExact(result.GetValue("PublishDate").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out dp);
                        newsResult.PublicationDate = dp;
                    }
                    catch (Exception ex)
                    {
                        log.Error("Source: {0}", ex.Source);
                        log.Error("Stack Trace: {0}", ex.StackTrace);
                        log.Error("Message: {0}", ex.Message);
                    }
                }

                if (result.Fields.Any(x => x.Name == "CategoryIds"))
                {
                    newsResult.Categories = new List <CategoryPair>();

                    var categoryIds = result.GetValue("CategoryIds").ToString().Split(',').ToList();
                    foreach (var categoryItem in categoryIds)
                    {
                        try
                        {
                            if (!categoryItem.IsNullOrWhitespace())
                            {
                                var categoryPair = new CategoryPair();
                                if (categoryItem.IsGuid())
                                {
                                    categoryPair.Guid = categoryItem;
                                    var taxon = taxonomyManager.GetTaxon(Guid.Parse(categoryItem));
                                    categoryPair.Name = taxon.Title.Value;
                                    newsResult.Categories.Add(categoryPair);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Source: {0}", ex.Source);
                            log.Error("Stack Trace: {0}", ex.StackTrace);
                            log.Error("Message: {0}", ex.Message);
                        }
                    }
                    //newsResult.Categories = result.GetValue("CategoryList").ToString().Split(',').Select(x => x.Trim()).ToList();
                    //log.Trace("CategoryList Set.");
                }

                if (result.Fields.Any(x => x.Name == "ResourceTypesIds"))
                {
                    newsResult.ResourceTypes = new List <CategoryPair>();

                    var resourceTypesIds = result.GetValue("ResourceTypesIds").ToString().Split(',').ToList();
                    foreach (var resourceTypeItem in resourceTypesIds)
                    {
                        try
                        {
                            if (!resourceTypeItem.IsNullOrWhitespace())
                            {
                                var categoryPair = new CategoryPair();
                                if (resourceTypeItem.IsGuid())
                                {
                                    categoryPair.Guid = resourceTypeItem;
                                    var taxon = taxonomyManager.GetTaxon(Guid.Parse(resourceTypeItem));
                                    categoryPair.Name = taxon.Title.Value;
                                    newsResult.Categories.Add(categoryPair);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Source: {0}", ex.Source);
                            log.Error("Stack Trace: {0}", ex.StackTrace);
                            log.Error("Message: {0}", ex.Message);
                        }
                    }
                    //newsResult.ResourceTypes = result.GetValue("ResourceTypesList").ToString().Split(',').Select(x => x.Trim()).ToList();
                    //log.Trace("ResourceTypesList Set.");
                }

                if (result.Fields.Any(x => x.Name == "OrganizationalAuthorsIds"))
                {
                    newsResult.OrganizationalAuthors = new List <CategoryPair>();

                    var organizationalAuthorIds = result.GetValue("OrganizationalAuthorsIds").ToString().Split(',').ToList();
                    foreach (var organizationalAuthorItem in organizationalAuthorIds)
                    {
                        try
                        {
                            if (!organizationalAuthorItem.IsNullOrWhitespace())
                            {
                                var categoryPair = new CategoryPair();
                                if (organizationalAuthorItem.IsGuid())
                                {
                                    categoryPair.Guid = organizationalAuthorItem;
                                    var taxon = taxonomyManager.GetTaxon(Guid.Parse(organizationalAuthorItem));
                                    categoryPair.Name = taxon.Title.Value;
                                    newsResult.Categories.Add(categoryPair);
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                            log.Error("Source: {0}", ex.Source);
                            log.Error("Stack Trace: {0}", ex.StackTrace);
                            log.Error("Message: {0}", ex.Message);
                        }
                    }
                    //newsResult.OrganizationalAuthors = result.GetValue("OrganizationalAuthorsList").ToString().Split(',').Select(x => x.Trim()).ToList();
                    //log.Trace("OrganizationalAuthorsList Set.");
                }

                if (result.Fields.Any(x => x.Name == "DefaultLinkBase"))
                {
                    newsResult.DefaultLinkBase = result.GetValue("DefaultLinkBase").ToString();
                    log.Trace("DefaultLinkBase Set.");
                }

                if (result.Fields.Any(x => x.Name == "Selfpaced"))
                {
                    var selfPaced = result.GetValue("Selfpaced").ToString();
                    if (!selfPaced.IsNullOrWhitespace())
                    {
                        newsResult.SelfPaced = bool.Parse(result.GetValue("Selfpaced").ToString());
                        log.Trace("SelfPaced Set.");
                    }
                }

                if (result.Fields.Any(x => x.Name == "DisplayDate"))
                {
                    newsResult.DisplayDate = result.GetValue("DisplayDate").ToString();
                    log.Trace("DisplayDate Set.");
                }

                if (result.Fields.Any(x => x.Name == "DateField"))
                {
                    try
                    {
                        /*newsResult.DateField = DateTime.ParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                         * log.Trace("DateField Set.");*/
                        DateTime dp = DateTime.MinValue;
                        DateTime.TryParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out dp);
                        newsResult.DateField = dp;
                    }
                    catch (Exception ex)
                    {
                        log.Error("Source: {0}", ex.Source);
                        log.Error("Stack Trace: {0}", ex.StackTrace);
                        log.Error("Message: {0}", ex.Message);
                    }
                }

                if (result.Fields.Any(x => x.Name == "ContentTypeDescription"))
                {
                    newsResult.ContentType = result.GetValue("ContentTypeDescription").ToString();
                    log.Trace("ContentTypeDescription Set.");
                }

                if (result.Fields.Any(x => x.Name == "ImageUrl"))
                {
                    newsResult.Image = result.GetValue("ImageUrl").ToString();
                    log.Trace("Image Set.");
                }

                if (result.Fields.Any(x => x.Name == "Protected"))
                {
                    newsResult.Protected = result.GetValue("Protected") == "1";
                    log.Trace("Protected Set.");
                }

                if (string.IsNullOrWhiteSpace(newsResult.Summary) && !string.IsNullOrWhiteSpace(newsResult.Content))
                {
                    log.Trace("The summary field is empty and the content has a value, so we will make a summary.");
                    newsResult.Summary = SummaryParser.GetSummary(newsResult.Content, new SummarySettings(SummaryMode.Words, 40, true));
                    log.Trace("Summary made and set.");
                }

                resultSet.Add(newsResult);
                log.Trace("result added to the resturn set.");
            }

            log.Info("Finishing SetBlendedListItems.");
            return(resultSet);
        }
        private Bitmap RenderSkill(out int picH)
        {
            Bitmap       bitmap = new Bitmap(290, DefaultPicHeight);
            Graphics     g      = Graphics.FromImage(bitmap);
            StringFormat format = (StringFormat)StringFormat.GenericDefault.Clone();

            picH = 0;

            //获取文字
            StringResult sr;

            if (StringLinker == null || !StringLinker.StringSkill.TryGetValue(Skill.SkillID, out sr))
            {
                sr      = new StringResultSkill();
                sr.Name = "(null)";
            }

            //绘制技能名称
            format.Alignment = StringAlignment.Center;
            g.DrawString(sr.Name, GearGraphics.ItemNameFont2, Brushes.White, 144, 10, format);

            //绘制图标
            picH = 33;
            g.FillRectangle(GearGraphics.GearIconBackBrush2, 14, picH, 68, 68);
            if (Skill.Icon.Bitmap != null)
            {
                g.DrawImage(GearGraphics.EnlargeBitmap(Skill.Icon.Bitmap),
                            14 + (1 - Skill.Icon.Origin.X) * 2,
                            picH + (33 - Skill.Icon.Bitmap.Height) * 2);
            }

            //绘制desc
            picH = 35;
            if (!Skill.PreBBSkill)
            {
                GearGraphics.DrawString(g, "[Master Level: " + Skill.MaxLevel + "]", GearGraphics.ItemDetailFont2, 90, 270, ref picH, 16);
            }

            if (sr.Desc != null)
            {
                string hdesc = SummaryParser.GetSkillSummary(sr.Desc, Skill.Level, Skill.Common, SummaryParams.Default);
                //string hStr = SummaryParser.GetSkillSummary(skill, skill.Level, sr, SummaryParams.Default);
                GearGraphics.DrawString(g, hdesc, GearGraphics.ItemDetailFont2, 90, 270, ref picH, 16);
            }
            if (Skill.ReqLevel > 0)
            {
                GearGraphics.DrawString(g, "#c[Required Level:" + Skill.ReqLevel.ToString() + "]#", GearGraphics.ItemDetailFont2, 90, 270, ref picH, 16);
            }
            if (Skill.ReqAmount > 0)
            {
                GearGraphics.DrawString(g, "#c" + ItemStringHelper.GetSkillReqAmount(Skill.SkillID, Skill.ReqAmount) + "#", GearGraphics.ItemDetailFont2, 90, 270, ref picH, 16);
            }

            //分割线
            picH = Math.Max(picH, 114);
            g.DrawLine(Pens.White, 6, picH, 283, picH);
            picH += 9;

            if (Skill.Level > 0)
            {
                string hStr = SummaryParser.GetSkillSummary(Skill, Skill.Level, sr, SummaryParams.Default);
                GearGraphics.DrawString(g, "[Current Level " + Skill.Level + "]", GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
                if (hStr != null)
                {
                    GearGraphics.DrawString(g, hStr, GearGraphics.ItemDetailFont2, 8, 272, ref picH, 16);
                }
            }

            if (Skill.Level < Skill.MaxLevel)
            {
                string hStr = SummaryParser.GetSkillSummary(Skill, Skill.Level + 1, sr, SummaryParams.Default);
                GearGraphics.DrawString(g, "[Next Level " + (Skill.Level + 1) + "]", GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
                if (hStr != null)
                {
                    GearGraphics.DrawString(g, hStr, GearGraphics.ItemDetailFont2, 8, 272, ref picH, 16);
                }
            }
            picH += 9;

            List <string> skillDescEx = new List <string>();

            if (ShowProperties)
            {
                List <string> attr = new List <string>();
                if (Skill.Invisible)
                {
                    attr.Add("[Hidden Skill]");
                }
                if (Skill.Hyper != HyperSkillType.None)
                {
                    attr.Add("[Hyper Skill: " + Skill.Hyper + "]");
                }
                if (Skill.CombatOrders)
                {
                    attr.Add("[Can pass Master Level with Combat Orders]");
                }
                if (Skill.NotRemoved)
                {
                    attr.Add("[Cannot be canceled]");
                }
                if (Skill.MasterLevel > 0 && Skill.MasterLevel < Skill.MaxLevel)
                {
                    attr.Add("[Requires Mastery Book to pass Lv. " + Skill.MasterLevel + "]");
                }
                if (Skill.NotIncBuffDuration)
                {
                    attr.Add("[Not affected by Buff Duration increases]");
                }
                if (Skill.NotCooltimeReset)
                {
                    attr.Add("[Not affected by Cooldown reductions/resets]");
                }
                if (attr.Count > 0)
                {
                    skillDescEx.Add("#c" + string.Join("\n", attr.ToArray()) + "#");
                }
            }

            if (ShowDelay && Skill.Action.Count > 0)
            {
                foreach (string action in Skill.Action)
                {
                    skillDescEx.Add("#c[Skill Delay] " + action + ": " + CharaSimLoader.GetActionDelay(action) + " ms#");
                }
            }

            if (ShowReqSkill && Skill.ReqSkill.Count > 0)
            {
                foreach (var kv in Skill.ReqSkill)
                {
                    string skillName;
                    if (this.StringLinker != null && this.StringLinker.StringSkill.TryGetValue(kv.Key, out sr))
                    {
                        skillName = sr.Name;
                    }
                    else
                    {
                        skillName = kv.Key.ToString();
                    }
                    skillDescEx.Add("#c[Required Skill]: " + skillName + ": " + kv.Value + " #");
                }
            }

            if (skillDescEx.Count > 0)
            {
                g.DrawLine(Pens.White, 6, picH, 283, picH);
                picH += 9;
                foreach (var descEx in skillDescEx)
                {
                    GearGraphics.DrawString(g, descEx, GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
                }
                picH += 9;
            }

            format.Dispose();
            g.Dispose();
            return(bitmap);
        }
        private Bitmap RenderSkill(out int picH)
        {
            Bitmap       bitmap = new Bitmap(290, DefaultPicHeight);
            Graphics     g      = Graphics.FromImage(bitmap);
            StringFormat format = (StringFormat)StringFormat.GenericDefault.Clone();

            picH = 0;

            //获取文字
            StringResult sr;

            if (StringLinker == null || !StringLinker.StringSkill.TryGetValue(Skill.SkillID, out sr))
            {
                sr      = new StringResult(true);
                sr.Name = "(null)";
            }

            //绘制技能名称
            format.Alignment = StringAlignment.Center;
            g.DrawString(sr.Name, GearGraphics.ItemNameFont2, Brushes.White, 144, 10, format);

            //绘制图标
            picH = 33;
            g.FillRectangle(GearGraphics.GearIconBackBrush2, 14, picH, 68, 68);
            if (Skill.Icon.Bitmap != null)
            {
                g.DrawImage(GearGraphics.EnlargeBitmap(Skill.Icon.Bitmap),
                            14 + (1 - Skill.Icon.Origin.X) * 2,
                            picH + (33 - Skill.Icon.Bitmap.Height) * 2);
            }

            //绘制desc
            picH = 35;
            if (!Skill.PreBBSkill)
            {
                GearGraphics.DrawString(g, "[最高等级:" + Skill.MaxLevel + "]", GearGraphics.ItemDetailFont2, 90, 270, ref picH, 16);
            }

            if (sr.Desc != null)
            {
                string hdesc = SummaryParser.GetSkillSummary(sr.Desc, Skill.Level, Skill.Common, SummaryParams.Default);
                //string hStr = SummaryParser.GetSkillSummary(skill, skill.Level, sr, SummaryParams.Default);
                GearGraphics.DrawString(g, hdesc, GearGraphics.ItemDetailFont2, 90, 270, ref picH, 16);
            }
            if (Skill.ReqLevel > 0)
            {
                GearGraphics.DrawString(g, "#c[要求等级:" + Skill.ReqLevel.ToString() + "]#", GearGraphics.ItemDetailFont2, 90, 270, ref picH, 16);
            }
            if (Skill.ReqAmount > 0)
            {
                GearGraphics.DrawString(g, "#c" + ItemStringHelper.GetSkillReqAmount(Skill.SkillID, Skill.ReqAmount) + "#", GearGraphics.ItemDetailFont2, 90, 270, ref picH, 16);
            }

            //分割线
            picH = Math.Max(picH, 114);
            g.DrawLine(Pens.White, 6, picH, 283, picH);
            picH += 9;

            if (Skill.Level > 0)
            {
                string hStr = SummaryParser.GetSkillSummary(Skill, Skill.Level, sr, SummaryParams.Default);
                GearGraphics.DrawString(g, "[现在等级 " + Skill.Level + "]", GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
                if (hStr != null)
                {
                    GearGraphics.DrawString(g, hStr, GearGraphics.ItemDetailFont2, 8, 272, ref picH, 16);
                }
            }

            if (Skill.Level < Skill.MaxLevel)
            {
                string hStr = SummaryParser.GetSkillSummary(Skill, Skill.Level + 1, sr, SummaryParams.Default);
                GearGraphics.DrawString(g, "[下次等级 " + (Skill.Level + 1) + "]", GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
                if (hStr != null)
                {
                    GearGraphics.DrawString(g, hStr, GearGraphics.ItemDetailFont2, 8, 272, ref picH, 16);
                }
            }
            picH += 9;

            List <string> skillDescEx = new List <string>();

            if (ShowProperties)
            {
                List <string> attr = new List <string>();
                if (Skill.Invisible)
                {
                    attr.Add("隐藏技能");
                }
                if (Skill.Hyper != HyperSkillType.None)
                {
                    attr.Add("超级技能:" + Skill.Hyper);
                }
                if (Skill.CombatOrders)
                {
                    attr.Add("战斗命令加成");
                }
                if (Skill.NotRemoved)
                {
                    attr.Add("无法被移除");
                }
                if (Skill.MasterLevel > 0 && Skill.MasterLevel < Skill.MaxLevel)
                {
                    attr.Add("初始掌握:Lv." + Skill.MasterLevel);
                }

                if (attr.Count > 0)
                {
                    skillDescEx.Add("#c" + string.Join(", ", attr.ToArray()) + "#");
                }
            }

            if (ShowDelay && Skill.Action.Count > 0)
            {
                foreach (string action in Skill.Action)
                {
                    skillDescEx.Add("#c[技能延时] " + action + ": " + CharaSimLoader.GetActionDelay(action) + " ms#");
                }
            }

            if (ShowReqSkill && Skill.ReqSkill.Count > 0)
            {
                foreach (var kv in Skill.ReqSkill)
                {
                    string skillName;
                    if (this.StringLinker != null && this.StringLinker.StringSkill.TryGetValue(kv.Key, out sr))
                    {
                        skillName = sr.Name;
                    }
                    else
                    {
                        skillName = kv.Key.ToString();
                    }
                    skillDescEx.Add("#c[前置技能] " + skillName + ": " + kv.Value + " 级#");
                }
            }

            if (skillDescEx.Count > 0)
            {
                g.DrawLine(Pens.White, 6, picH, 283, picH);
                picH += 9;
                foreach (var descEx in skillDescEx)
                {
                    GearGraphics.DrawString(g, descEx, GearGraphics.ItemDetailFont, 8, 272, ref picH, 16);
                }
                picH += 9;
            }

            format.Dispose();
            g.Dispose();
            return(bitmap);
        }
Beispiel #11
0
        private List <NewsResult> GetBlenedResult_org(out int hitCount, string term, int skip, int take)
        {
            var results = BlendedNewsHelper.GetNewsItems(Providers, SearchIndex, out hitCount, Categories, term, skip, take);

            log.InfoFormat("There are {0}, results, prov:{1}, idx:{2}, term:{3}, take:{4}",
                           results.HitCount,
                           Providers?.Join(","),
                           SearchIndex,
                           Categories?.Join(","),
                           term, take);

            List <NewsResult> resultSet = new List <NewsResult>();
            //log.Info("content, title, Id \r\n");
            StringBuilder sb = new StringBuilder();

            foreach (var result in results)
            {
                //newsResult.DisplayDate = result.GetValue("DisplayDate").ToString();
                //
                try
                {
                    var ctnType = result.GetValue("ContentType")?.ToString() ?? string.Empty;

                    var        featured   = result.GetValue("FeaturedRank")?.ToString() ?? string.Empty;
                    NewsResult newsResult = new NewsResult()
                    {
                        ImageId  = result.GetValue("ImageId")?.ToString() ?? string.Empty,
                        Title    = result.GetValue("Title")?.ToString() ?? string.Empty,
                        Summary  = result.GetValue("Summary")?.ToString() ?? string.Empty,
                        Featured = !string.IsNullOrEmpty(featured) && (featured == "1" ? true : false),
                        Content  = result.GetValue("Content")?.ToString() ?? string.Empty,
                        Link     = result.GetValue("Link")?.ToString() ?? string.Empty
                    };

                    var    dynaManager = DynamicModuleManager.GetManager();
                    string txtId       = result.GetValue("Id")?.ToString() ?? String.Empty;
                    log.InfoFormat("try to get from iD:{0} ofType:{1}-title:{2}", txtId, ctnType, newsResult.Title);
                    try
                    {
                        if (!string.IsNullOrEmpty(ctnType) && !string.IsNullOrEmpty(txtId) && txtId.IsGuid())
                        {
                            Guid itemId = new Guid(txtId);
                            if (ctnType.IndexOf("BlogPost") > 0)
                            {
                                var manager = BlogsManager.GetManager();
                                var bp      = manager.GetBlogPosts()
                                              //.Where(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
                                              .FirstOrDefault(b => b.Id == itemId);
                                if (bp != null)
                                {
                                    bp = manager.Lifecycle.GetLive(bp) as BlogPost;
                                    log.InfoFormat("has item:{0}-date:{1}", bp?.GetType()?.FullName, bp?.GetValue("DisplayDate")?.ToString() ?? string.Empty);
                                    newsResult.DisplayDate = bp?.GetValue("DisplayDate")?.ToString() ?? string.Empty;
                                }
                            }
                            else
                            {
                                var item = dynaManager.GetDataItems(TypeResolutionService.ResolveType(ctnType))
                                           .Where(c => c.Status == Telerik.Sitefinity.GenericContent.Model.ContentLifecycleStatus.Live)
                                           .FirstOrDefault(c => c.Id == itemId);

                                log.InfoFormat("has item:{0}-date:{1}", item?.GetType()?.FullName, item?.GetValue("DisplayDate")?.ToString() ?? string.Empty);
                                newsResult.DisplayDate = item?.GetValue("DisplayDate")?.ToString() ?? string.Empty;
                            }

                            /*if (result.Fields.Any(x => x.Name == "DisplayDate") && item?.GetValue("DisplayDate") != null)
                             * {
                             *  newsResult.DisplayDate = item.GetValue("DisplayDate").ToString() ?? string.Empty;
                             * }*/
                        }
                    }
                    catch (Exception ex)
                    {
                        log.InfoFormat("failedToGetDateItemType:{0}-id:{1}, msg:{2}", ctnType, txtId, ex.Message);
                    }

                    string formatString = "yyyyMMddHHmmssfff";
                    // seem like there are already assing below
                    if (!String.IsNullOrEmpty(result.GetValue("PublicationDate")?.ToString()))
                    {
                        DateTime pubd = DateTime.MinValue;
                        //DateTime dt = DateTime.ParseExact(result.GetValue("PublicationDate").ToString(), formatString, null);
                        //newsResult.PublicationDate = dt.ToLocalTime();
                        DateTime.TryParseExact(result.GetValue("PublicationDate").ToString(), formatString, new CultureInfo("en-US"), DateTimeStyles.None, out pubd);
                        newsResult.PublicationDate = pubd;
                        //log.InfoFormat("pubd:{0}", pubd.ToString("MMMM d, yyyy"));
                        //sb.Append("PubDate:").Append(pubd).Append("\r");
                    }

                    if (result.Fields.Any(x => x.Name == "DateField"))
                    {
                        try
                        {
                            /*DateTime dt2 = DateTime.ParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                             * newsResult.DateField = dt2.ToLocalTime();*/
                            if (!String.IsNullOrEmpty(result.GetValue("DateField")?.ToString()))
                            {
                                DateTime eDateTime = DateTime.MinValue;
                                DateTime.TryParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out eDateTime);
                                newsResult.DateField = eDateTime;
                                //log.InfoFormat("datef:{0}", eDateTime.ToString("MMMM d, yyyy"));
                            }
                        }
                        catch (Exception ex)
                        {
                            log.ErrorFormat("GetBlendedResult-DateField:{0}, inner:{1}, stack:{2}", ex.Message, ex.InnerException?.Message, ex.StackTrace);
                        }
                    }

                    if (string.IsNullOrWhiteSpace(newsResult.Summary) && !string.IsNullOrWhiteSpace(newsResult.Content))
                    {
                        newsResult.Summary = SummaryParser.GetSummary(newsResult.Content, new SummarySettings(SummaryMode.Words, 40, true));
                    }

                    resultSet.Add(newsResult);
                }
                catch (Exception ex)
                {
                    log.InfoFormat("bled-createNewsResult:{0}", ex.Message);
                }



                //newsResult.ImageCaption = result.GetValue("ImageCaption").ToString();

                // testing below

                /*if (!String.IsNullOrEmpty(result.GetValue("PublicationDate")?.ToString()))
                 * {
                 *  //DateTime dt = DateTime.ParseExact(result.GetValue("PublicationDate").ToString(), formatString, null);
                 *  //newsResult.PublicationDate = dt.ToLocalTime();
                 *  DateTime.TryParseExact(result.GetValue("PublicationDate").ToString(), formatString, new CultureInfo("en-US"), DateTimeStyles.None, out eDateTime);
                 *  newsResult.DisplayDate = eDateTime.ToLocalTime().ToShortDateString();
                 * }*/
                ///
            }
            return(resultSet);
        }
Beispiel #12
0
        //***********Helper Methods***********//
        //************************************//
        //************************************//
        #region SetBlendedListItems

        private List <BlendedListItem> SetBlendedListItems(IEnumerable <IDocument> results)
        {
            log.Info("Begin SetBlendedListItems");


            var resultSet       = new List <BlendedListItem>();
            var taxonomyManager = TaxonomyManager.GetManager();

            if (results != null)
            {
                foreach (var result in results)
                {
                    //log.Trace("Getting a new instance of BlendedListItem.");
                    var featured   = result.Fields.Any(c => c.Name == "FeaturedRank") && (result.GetValue("FeaturedRank")?.ToString() == "1" ? true : false);
                    var newsResult = new BlendedListItem()
                    {
                        Title           = result.GetValue("Title")?.ToString() ?? string.Empty,
                        LocationStreet  = result.Fields.Any(c => c.Name == "LocationStreet") ? (result.GetValue("LocationStreet")?.ToString() ?? string.Empty):String.Empty,
                        LocationState   = result.Fields.Any(c => c.Name == "LocationState") ? result.GetValue("LocationState")?.ToString() ?? string.Empty: string.Empty,
                        LocationCity    = result.Fields.Any(c => c.Name == "LocationCity") ? result.GetValue("LocationCity")?.ToString() ?? string.Empty: string.Empty,
                        Summary         = result.GetValue("Summary")?.ToString() ?? string.Empty,
                        Content         = result.GetValue("Content")?.ToString() ?? String.Empty,
                        Featured        = featured,
                        Link            = result.Fields.Any(c => c.Name == "Link") ? result.GetValue("Link")?.ToString() ?? string.Empty: string.Empty,
                        DefaultLinkBase = result.Fields.Any(c => c.Name == "DefaultLinkBase") ? result.GetValue("DefaultLinkBase")?.ToString() ?? string.Empty: string.Empty,
                        DisplayDate     = result.Fields.Any(c => c.Name == "DisplayDate") ? result.GetValue("DisplayDate")?.ToString() ?? string.Empty: string.Empty,
                        ContentType     = result.Fields.Any(c => c.Name == "ContentTypeDescription") ? result.GetValue("ContentTypeDescription")?.ToString() ?? String.Empty: string.Empty,
                        Image           = result.Fields.Any(c => c.Name == "ImageUrl") ? result.GetValue("ImageUrl")?.ToString() ?? string.Empty: string.Empty
                    };


                    if (result.Fields.Any(x => x.Name == "Selfpaced"))
                    {
                        var selfPaced = result.GetValue("Selfpaced")?.ToString() ?? String.Empty;
                        if (!selfPaced.IsNullOrWhitespace())
                        {
                            newsResult.SelfPaced = bool.Parse(result.GetValue("Selfpaced").ToString());
                        }
                    }
                    if (result.Fields.Any(x => x.Name == "DateField"))
                    {
                        if (result.Fields.Any(x => x.Name == "EventStart"))
                        {
                            DateTime dt;
                            if (!String.IsNullOrEmpty(result.GetValue("DateField")?.ToString()))
                            {
                                //newsResult.DateField = DateTime.ParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);

                                DateTime.TryParseExact(result.GetValue("DateField").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out dt);
                                newsResult.DateField = dt;
                            }
                        }
                    }

                    if (result.Fields.Any(x => x.Name == "Protected"))
                    {
                        string IsProtected = result.GetValue("Protected")?.ToString() ?? "0";
                        newsResult.Protected = !string.IsNullOrEmpty(IsProtected) && (IsProtected == "1" ? true : false);
                    }

                    DateTime eDateTime;
                    if (result.Fields.Any(x => x.Name == "EventStart"))
                    {
                        if (!String.IsNullOrEmpty(result.GetValue("EventStart")?.ToString()))
                        {
                            //ParseExact(result.GetValue("EventStart").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                            DateTime.TryParseExact(result.GetValue("EventStart").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out eDateTime);
                            newsResult.EventStartDate = eDateTime;
                        }
                    }

                    if (result.Fields.Any(x => x.Name == "EventEnd"))
                    {
                        //newsResult.EventEndDate = DateTime.ParseExact(result.GetValue("EventStart").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                        if (!String.IsNullOrEmpty(result.GetValue("EventEnd")?.ToString()))
                        {
                            DateTime.TryParseExact(result.GetValue("EventEnd").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out eDateTime);
                            newsResult.EventEndDate = eDateTime;
                        }
                    }

                    if (result.Fields.Any(x => x.Name == "PublishDate"))
                    {
                        //newsResult.PublicationDate = DateTime.ParseExact(result.GetValue("PublishDate").ToString(), "MM/dd/yyyy HH:mm:ss", CultureInfo.InvariantCulture);
                        if (!String.IsNullOrEmpty(result.GetValue("PublishDate")?.ToString()))
                        {
                            DateTime.TryParseExact(result.GetValue("PublishDate").ToString(), "MM/dd/yyyy HH:mm:ss", new CultureInfo("en-US"), DateTimeStyles.None, out eDateTime);
                            newsResult.PublicationDate = eDateTime;
                        }
                    }

                    if (result.Fields.Any(x => x.Name == "CategoryIds"))
                    {
                        newsResult.Categories = new List <CategoryPair>();

                        var categoryIds = result.GetValue("CategoryIds")?.ToString()?.Split(',')?.ToList();
                        if (categoryIds != null && categoryIds.Any())
                        {
                            foreach (var categoryItem in categoryIds)
                            {
                                try
                                {
                                    var categoryPair = new CategoryPair();
                                    if (!String.IsNullOrEmpty(categoryItem) && categoryItem.IsGuid())
                                    {
                                        categoryPair.Guid = categoryItem;
                                        var taxon = taxonomyManager.GetTaxon(Guid.Parse(categoryItem));
                                        categoryPair.Name = taxon.Title.Value;
                                        newsResult.Categories.Add(categoryPair);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    log.Error("Source: {0}", ex.Source);
                                    log.Error("Stack Trace: {0}", ex.StackTrace);
                                    log.Error("RelatedContentDyn-GetCategoryIds: {0}", ex.Message);
                                }
                            }
                        }

                        //newsResult.Categories = result.GetValue("CategoryList").ToString().Split(',').Select(x => x.Trim()).ToList();
                        //log.Trace("CategoryList Set.");
                    }

                    if (result.Fields.Any(x => x.Name == "ResourceTypesIds"))
                    {
                        newsResult.ResourceTypes = new List <CategoryPair>();

                        var resourceTypesIds = result.GetValue("ResourceTypesIds")?.ToString()?.Split(',')?.ToList();
                        if (resourceTypesIds != null && resourceTypesIds.Any())
                        {
                            foreach (var resourceTypeItem in resourceTypesIds)
                            {
                                try
                                {
                                    var categoryPair = new CategoryPair();
                                    if (!String.IsNullOrEmpty(resourceTypeItem) && resourceTypeItem.IsGuid())
                                    {
                                        categoryPair.Guid = resourceTypeItem;
                                        var taxon = taxonomyManager.GetTaxon(Guid.Parse(resourceTypeItem));
                                        categoryPair.Name = taxon.Title.Value;
                                        newsResult.Categories.Add(categoryPair);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    log.Error("Source: {0}", ex.Source);
                                    log.Error("Stack Trace: {0}", ex.StackTrace);
                                    log.Error("RelatedContentDyn-GetResourceTypesIds: {0}", ex.Message);
                                }
                            }
                        }

                        //newsResult.ResourceTypes = result.GetValue("ResourceTypesList").ToString().Split(',').Select(x => x.Trim()).ToList();
                        //log.Trace("ResourceTypesList Set.");
                    }

                    if (result.Fields.Any(x => x.Name == "OrganizationalAuthorsIds"))
                    {
                        newsResult.OrganizationalAuthors = new List <CategoryPair>();

                        var organizationalAuthorIds = result.GetValue("OrganizationalAuthorsIds")?.ToString()?.Split(',')?.ToList();
                        if (organizationalAuthorIds != null && organizationalAuthorIds.Any())
                        {
                            foreach (var organizationalAuthorItem in organizationalAuthorIds)
                            {
                                try
                                {
                                    var categoryPair = new CategoryPair();
                                    if (!String.IsNullOrEmpty(organizationalAuthorItem) && organizationalAuthorItem.IsGuid())
                                    {
                                        categoryPair.Guid = organizationalAuthorItem;
                                        var taxon = taxonomyManager.GetTaxon(Guid.Parse(organizationalAuthorItem));
                                        categoryPair.Name = taxon.Title.Value;
                                        newsResult.Categories.Add(categoryPair);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    log.Error("Source: {0}", ex.Source);
                                    log.Error("Stack Trace: {0}", ex.StackTrace);
                                    log.Error("RelatedContentDyn-GetOrganizationalAuthorsIds: {0}", ex.Message);
                                }
                            }
                        }

                        //newsResult.OrganizationalAuthors = result.GetValue("OrganizationalAuthorsList").ToString().Split(',').Select(x => x.Trim()).ToList();
                        //log.Trace("OrganizationalAuthorsList Set.");
                    }

                    if (string.IsNullOrWhiteSpace(newsResult.Summary) && !string.IsNullOrWhiteSpace(newsResult.Content))
                    {
                        newsResult.Summary = SummaryParser.GetSummary(newsResult.Content, new SummarySettings(SummaryMode.Words, 40, true));
                    }

                    resultSet.Add(newsResult);
                }
            }
            return(resultSet);
        }
Beispiel #13
0
        public static IEnumerable <SearchResult> GetSearchResults_stv(string catalog, SearchCriteria criteria, int skip, int take, int summaryWordCount, out int hitCount)
        {
            var searchService = ServiceBus.ResolveService <ISearchService>();
            var searchQuery   = ObjectFactory.Resolve <ISearchQuery>();

            var           queryBuilder = ObjectFactory.Resolve <IQueryBuilder>();
            StringBuilder sb           = new StringBuilder();


            searchQuery.Skip              = skip;
            searchQuery.Take              = take;
            searchQuery.OrderBy           = criteria.OrderBy == null ? new string[] { "PublicationDate DESC" } : new string[] { criteria.OrderBy };
            searchQuery.HighlightedFields = null;
            searchQuery.IndexName         = catalog;
            searchQuery.SearchGroup       = BuildSearchQuery(criteria, new[] { "Title", "Content", "DocumentText" });

            var resultSet = searchService.Search(searchQuery);

            hitCount = resultSet.HitCount;

            var results         = new List <SearchResult>();
            var taxonomyManager = TaxonomyManager.GetManager();

            log.InfoFormat("ResourceLib:{0};",
                           criteria.ToQueryString());

            foreach (var result in resultSet.SetContentLinks())
            {
                var searchResult = new SearchResult();

                try
                {
                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("CategoryIds").ToString()))
                    {
                        var categoryIds = result.GetValue("CategoryIds").ToString().Split(' ').ToList();

                        searchResult.CategoryPair = new List <CategoryPair>();
                        var parentGuidId = AppSettingsUtility.GetValue <Guid>("ResourceLibraryTaxonomyId");

                        foreach (var categoryId in categoryIds)
                        {
                            log.InfoFormat("ResourceLibraryTaxonomyId-cateids:{0}, parentGuidId:{1}", categoryIds, parentGuidId);
                            var category = taxonomyManager.GetTaxon(Guid.Parse(categoryId)) as HierarchicalTaxon;

                            do
                            {
                                if (category.Parent != null && category.Parent.Id == parentGuidId)
                                {
                                    category = taxonomyManager.GetTaxon(Guid.Parse(categoryId)) as HierarchicalTaxon;
                                    var categoryPair = new CategoryPair();
                                    categoryPair.Name = category.Title.Value;
                                    categoryPair.Guid = categoryId.ToString().Replace("-", "");

                                    log.InfoFormat("CateInParent, Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid);
                                    sb.Append(String.Format("CateInParent, Title:{0}, guid:{1}", categoryPair.Name,
                                                            categoryPair.Guid));
                                    searchResult.CategoryPair.Add(categoryPair);
                                    break;
                                }

                                category = taxonomyManager.GetTaxon(category.Parent.Id) as HierarchicalTaxon;
                            } while (category.Parent != null);
                        }
                    }
                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("OrganizationalAuthorsIds").ToString()))
                    {
                        var categoryIds = result.GetValue("OrganizationalAuthorsIds").ToString().Split(' ').ToList();
                        searchResult.Author = new List <CategoryPair>();
                        var taxonomyGuidId = AppSettingsUtility.GetValue <Guid>("ResourceLibraryTaxonomyAuthorId");

                        foreach (var categoryId in categoryIds)
                        {
                            var category = taxonomyManager.GetTaxon(Guid.Parse(categoryId)) as HierarchicalTaxon;

                            if (category.Taxonomy.Id == taxonomyGuidId)
                            {
                                var categoryPair = new CategoryPair();
                                categoryPair.Name = category.Title.Value;
                                categoryPair.Guid = categoryId.ToString().Replace("-", "");
                                searchResult.Author.Add(categoryPair);

                                log.InfoFormat("ResourceLibraryTaxonomyAuthorId-Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid);
                                sb.AppendFormat("ResourceLibraryTaxonomyAuthorId-Title:{0}, guid:{1}", categoryPair.Name,
                                                categoryPair.Guid);
                            }
                        }
                    }
                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("ResourceTypesIds").ToString()))
                    {
                        var categoryIds = result.GetValue("ResourceTypesIds").ToString().Split(' ').ToList();
                        searchResult.ResourceTypes = new List <CategoryPair>();
                        var taxonomyGuidId = AppSettingsUtility.GetValue <Guid>("ResourceLibraryTaxonomyTypeId");

                        foreach (var categoryId in categoryIds)
                        {
                            var category = taxonomyManager.GetTaxon(Guid.Parse(categoryId)) as HierarchicalTaxon;

                            if (category.Taxonomy.Id == taxonomyGuidId)
                            {
                                var categoryPair = new CategoryPair();
                                categoryPair.Name = category.Title.Value;
                                categoryPair.Guid = categoryId.ToString().Replace("-", "");
                                searchResult.ResourceTypes.Add(categoryPair);

                                log.InfoFormat("ResourceLibraryTaxonomyTypeId-Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid);
                                sb.AppendFormat("ResourceLibraryTaxonomyTypeId-Title:{0}, guid:{1}", categoryPair.Name, categoryPair.Guid);
                            }
                        }
                    }
                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("Title").ToString()))
                    {
                        searchResult.Title = result.GetValue("Title").ToString();
                    }
                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("Link").ToString()))
                    {
                        searchResult.Link = result.GetValue("Link").ToString();
                    }
                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("PublishDate").ToString()))
                    {
                        searchResult.PublicationDate = DateTime.Parse(result.GetValue("PublishDate").ToString());
                    }
                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("DocumentLibrary").ToString()))
                    {
                        searchResult.DocumentFolder = result.GetValue("DocumentLibrary").ToString();
                    }
                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("Summary").ToString()))
                    {
                        searchResult.Summary = result.GetValue("Summary").ToString();
                    }
                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("ContentType").ToString()))
                    {
                        searchResult.Type = result.GetValue("ContentType").ToString();
                    }

                    if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("ThumbnailUrl").ToString()))
                    {
                        searchResult.ImageUrl = result.GetValue("ThumbnailUrl").ToString();
                    }
                    else if (!SitefinityExtensions.IsNullOrEmpty(result.GetValue("ImageUrl").ToString()))
                    {
                        searchResult.ImageUrl = result.GetValue("ImageUrl").ToString();
                    }

                    var contentType = TypeResolutionService.ResolveType(searchResult.Type);

                    searchResult.Type = contentType.Name;



                    if (result.Fields.Any(f => f.Name == "EventStart") && !string.IsNullOrWhiteSpace(result.GetValue("EventStart").ToString()))
                    {
                        searchResult.EventStart = DateTime.Parse(result.GetValue("EventStart").ToString());
                    }

                    if (result.Fields.Any(f => f.Name == "EventEnd") && !string.IsNullOrWhiteSpace(result.GetValue("EventEnd").ToString()))
                    {
                        searchResult.EventEnd = DateTime.Parse(result.GetValue("EventEnd").ToString());
                    }
                    var content      = result.GetValue("Content").ToString().StripHtmlTags();
                    var docLink      = result.GetValue("DocumentLink");
                    var documentText = result.GetValue("DocumentText");
                    if (string.IsNullOrWhiteSpace(content) && !string.IsNullOrWhiteSpace(docLink.ToString()))
                    {
                        searchResult.Link = docLink.ToString();
                        content           = documentText.ToString();
                    }

                    if (string.IsNullOrWhiteSpace(searchResult.Summary))
                    {
                        searchResult.Summary = SummaryParser.GetSummary(content, new SummarySettings(SummaryMode.Words, summaryWordCount, true, true));
                    }
                }
                catch (Exception ex)
                {
                    //ex.ToString();
                    log.InfoFormat("Resources-Exception:{0}, details:{1}", ex.Message, sb.ToString());
                }

                results.Add(searchResult);
            }

            return(results);
        }