Exemple #1
0
 public static ContentIndexModel ToModel(ContentIndex entity)
 {
     if (entity == null)
     {
         return(null);
     }
     return(new ContentIndexModel()
     {
         Id = entity.Id,
         PolicyTitle = entity.PolicyTitle,
         PolicyContent = entity.PolicyContent,
         ButtonReadMore = entity.ButtonReadMore,
         ButtonContact = entity.ButtonContact,
         FeatureTitle = entity.FeatureTitle,
         FeatureContent = entity.FeatureContent,
         AboutUsTitle = entity.AboutUsTitle,
         AboutUsContent = entity.AboutUsContent,
         ContactTitle = entity.ContactTitle,
         ContactContent = entity.ContactContent,
         AboutUsLeftTitle = entity.AboutUsLeftTitle,
         AboutUsLeftSrc = entity.AboutUsLeftSrc,
         AboutUsLeftSubContent = entity.AboutUsLeftSubContent,
         AboutUsLeftContent = entity.AboutUsLeftContent,
         AboutUsLeftUrl = entity.AboutUsLeftUrl,
         WhyChooseTitle = entity.WhyChooseTitle,
         WhyChooseContent = entity.WhyChooseContent,
         HomePageTitle = entity.HomePageTitle
     });
 }
Exemple #2
0
    protected void imgSearchIcon_Click(object sender, ImageClickEventArgs e)
    {
        string               helpCultureName  = _cultureCookie != null ? _cultureCookie.Value : string.Empty;
        string               rootUrl          = HelpSiteMapProvider.GetProviderRootUrlByCultureName(helpCultureName);
        string               contentIndexName = "HelpContentIndex:" + rootUrl;
        ContentIndex         myContentIndex   = null;
        ContentSearchResult  mySearchResult   = null;
        XmlDocument          doc           = new XmlDocument();
        XslCompiledTransform xslt          = new XslCompiledTransform();
        XsltArgumentList     xsltArgs      = new XsltArgumentList();
        StringWriter         xsltResult    = null;
        string               exprPageTitle = @"(?si)(?:(?<=<meta\s*name\s*=\s*(?:""|')menuText(?:""|')\s*content\s*=\s*(?:""|'))(?<contentAttribute>.*?[^(?:"")]*)(?=(?:"")[^>]*>)|(?<=<meta\s*content\s*=\s*(?:""|'))(?<contentAttribute>.*?[^(?:"")]*)(?=(?:"")\s*name\s*=\s*(?:""|')menuText(?:""|')\s*[^>]*>))";

        if (txtSearch.Text.Length > 0)
        {
            try
            {
                myContentIndex = Application[contentIndexName] as ContentIndex;
                if (myContentIndex == null)
                {
                    myContentIndex = new ContentIndex(Page.MapPath(rootUrl), exprPageTitle);
                    Application[contentIndexName] = myContentIndex;
                }

                mySearchResult = myContentIndex.Search(txtSearch.Text);
                doc.LoadXml(mySearchResult.ToXml());
                xslt.Load(Server.MapPath("css/searchResult.xsl"));
                xsltArgs.AddParam("hrefPrefix", string.Empty, Request.Url.GetLeftPart(System.UriPartial.Path) + "?page=Help&content=");
                xsltArgs.AddParam("relativeURL", string.Empty, rootUrl);
                xsltArgs.AddParam("mappedURL", string.Empty, Page.MapPath(rootUrl));

                xsltResult = new StringWriter();
                xslt.Transform(doc, xsltArgs, xsltResult);

                litMainContent.Text = xsltResult.ToString();
            }
            catch (XmlException xmlEx)
            {
                if (xmlEx.Message.ToLowerInvariant().Contains("root"))
                {   //Missing root element.
                    litMainContent.Text = String.Format(GetLocalResourceObject("NoContentFound").ToString(), txtSearch.Text);
                }
                else
                {
                    litMainContent.Text = String.Format(GetLocalResourceObject("UnableToSearch").ToString(), xmlEx.Message);
                }
            }
            catch (Exception ex)
            {
                litMainContent.Text = String.Format(GetLocalResourceObject("UnableToSearch").ToString(), ex.Message);
            }
            finally
            {
                if (xsltResult != null)
                {
                    xsltResult.Close();
                }
            }
        }
    }
    protected void imgSearchIcon_Click(object sender, ImageClickEventArgs e)
    {
        string helpCultureName = _cultureCookie != null ? _cultureCookie.Value : string.Empty;
        string rootUrl = HelpSiteMapProvider.GetProviderRootUrlByCultureName(helpCultureName);
        string contentIndexName = "HelpContentIndex:" + rootUrl;
        ContentIndex myContentIndex = null;
        ContentSearchResult mySearchResult = null;
        XmlDocument doc = new XmlDocument();
        XslCompiledTransform xslt = new XslCompiledTransform();
        XsltArgumentList xsltArgs = new XsltArgumentList();
        StringWriter xsltResult = null;
        string exprPageTitle = @"(?si)(?:(?<=<meta\s*name\s*=\s*(?:""|')menuText(?:""|')\s*content\s*=\s*(?:""|'))(?<contentAttribute>.*?[^(?:"")]*)(?=(?:"")[^>]*>)|(?<=<meta\s*content\s*=\s*(?:""|'))(?<contentAttribute>.*?[^(?:"")]*)(?=(?:"")\s*name\s*=\s*(?:""|')menuText(?:""|')\s*[^>]*>))";

        if (txtSearch.Text.Length > 0)
        {
            try
            {
                myContentIndex = Application[contentIndexName] as ContentIndex;
                if (myContentIndex == null)
                {
                    myContentIndex = new ContentIndex(Page.MapPath(rootUrl), exprPageTitle);
                    Application[contentIndexName] = myContentIndex;
                }

                mySearchResult = myContentIndex.Search(txtSearch.Text);
                doc.LoadXml(mySearchResult.ToXml());
                xslt.Load(Server.MapPath("css/searchResult.xsl"));
                xsltArgs.AddParam("hrefPrefix", string.Empty, Request.Url.GetLeftPart(System.UriPartial.Path) + "?page=Help&content=");
                xsltArgs.AddParam("relativeURL", string.Empty, rootUrl);
                xsltArgs.AddParam("mappedURL", string.Empty, Page.MapPath(rootUrl));

                xsltResult = new StringWriter();
                xslt.Transform(doc, xsltArgs, xsltResult);

                litMainContent.Text = xsltResult.ToString();
            }
            catch (XmlException xmlEx)
            {
                if (xmlEx.Message.ToLowerInvariant().Contains("root"))
                {   //Missing root element.
                    litMainContent.Text = String.Format(GetLocalResourceObject("NoContentFound").ToString(), txtSearch.Text);
                }
                else
                {
                    litMainContent.Text = String.Format(GetLocalResourceObject("UnableToSearch").ToString(), xmlEx.Message);
                }
            }
            catch (Exception ex)
            {
                litMainContent.Text = String.Format(GetLocalResourceObject("UnableToSearch").ToString(), ex.Message);
            }
            finally
            {
                if (xsltResult != null)
                    xsltResult.Close();
            }
        }
    }
Exemple #4
0
 public void Setup()
 {
     _paragraph      = TestData.Wiki;
     _questions      = TestData.Questions;
     _correctAnswers = TestData.CorrectAnswers;
     _answers        = TestData.Answers;
     _answerFinder   = new AnswerFinder();
     _contentIndex   = new ContentIndexBuilder().Build(_paragraph);
 }
Exemple #5
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            ContentIndex.LoadContent(Content, GraphicsDevice);
            SceneManager.Initialize();
            SceneManager.AddScene("StartScene", new StartScene());
            SceneManager.AddScene("MenuScene", new MenuScene());
            SceneManager.AddScene("GameScene", new GameScene());

            TextRenderer.Initialize(ContentIndex.Textures["chars"], "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_!?><");

            Canvas = new RenderTarget2D(GraphicsDevice, 256, 240);
            sky    = new SkyBackground();
        }
Exemple #6
0
        public string FindBestAnswer(ContentIndex indexData, string question, IEnumerable <string> answers)
        {
            var questionTermWithPriority = _keywordPrioritizer.GetWordsWithPriority(question, indexData.AllWords);

            var relevantLinesWithRank = _lineMatchRanker
                                        .GetRelevantLinesWithRank(questionTermWithPriority, indexData.Lines);

            var predictedLine = relevantLinesWithRank
                                .MaxBy(lr => lr.Score)
                                .Line;

            var answersWithRank = _answerRanker.GetWordMatchRanks(predictedLine, answers, indexData.AllWords);

            var predictedAnswer = answersWithRank
                                  .MaxBy(ar => ar.WeightedScore);

            //.OrderByDescending(a => a.WordMatch).ThenByDescending(m => m.WeightedScore).First();

            return(predictedAnswer.Answer);
        }
Exemple #7
0
        public ContentIndex Build(string paragraph)
        {
            if (string.IsNullOrWhiteSpace(paragraph))
            {
                return(null);
            }

            var result = new ContentIndex
            {
                Content  = paragraph,
                Lines    = new List <LineIndex>(),
                AllWords = new List <WordFrequency>()
            };

            var lines = StringProcessor.GetSentences(paragraph);

            var lineIndex = 0;

            foreach (var line in lines)
            {
                var words = StringProcessor.GetWordsLower(line);
                result.Lines.Add(new LineIndex
                {
                    Id        = ++lineIndex,
                    Line      = line,
                    WordIndex = GetWordFrequency(words).ToList()
                });
            }

            var allWordCombinationsInAllLines = result.Lines.Select(l => l.WordIndex);

            result.AllWords = GetCombinedWordFrequency(allWordCombinationsInAllLines)
                              .ToList();

            return(result);
        }
 internal Memento(CryptoStorage storage)
 {
     this.storage = storage;
     content      = new ContentIndex(storage.ContentIndex);
 }
Exemple #9
0
        private byte[] seekAndLoadCttBlock(Stream fs, ContentIndex ci)
        {
            var ofs = ContentIndexTableEndPos + 8 + ci.Offset;

            fs.Seek((long)ofs, SeekOrigin.Begin);
            Console.WriteLine();
            Console.WriteLine(
                $"<!-- seek to 0x{fs.Position:X8}/{fs.Position}, file length = 0x{fs.Length:X8}/{fs.Length} -->");
            Console.WriteLine();

            #region read this content table

            var magicNumber = _seg2.MagicNumber;
            var rawData     = new byte[ci.CompressedSize];
            var r           = fs.Read(rawData, 0, rawData.Length);
            if (_seg2.MagicNumber == 0)
            {
                if (ci.CompressedSize == ci.UncompressedSize)
                {
                    return(rawData);
                }
                magicNumber = 0x01000000;
            }

            #endregion

            #region unzip it

            if (magicNumber == 0x02000000)
            {
                #region InflaterDecompress, Passed

                try
                {
                    // var txt = CompressUtil.InflaterDecompress(rawData, 0, rawData.Length);
                    var txt = Zipper.InflateBufferWithPureZlib(rawData, rawData.Length);

                    var path = $"{Util.StripPathExt(DictFileName)}.ctt.blk.ofs.{ofs}.txt";
                    writeFile(path, txt);

                    // var b = new byte[ci.UncompressedSize];
                    // Array.Copy(txt, (int) kwi2.CIUncompOffset, b, 0, (int) kwi2.CIUncompLength);
                    // return b;

                    return(txt);
                }
                catch (Exception ex)
                {
                    ErrorLog(ex.ToString());
                    throw;
                }

                #endregion
            }
            else if (magicNumber == 0x01000000)
            {
                //对于1.2版本格式,可能并未压缩,故如果LZO失败,则将rawdata原样返回

                #region 试图进行 LZO Decompress。

                //Lzo1x解压缩
                var ok          = false;
                var _decompData = new byte[ci.UncompressedSize];
                var _decompSize = 0;

                // if (!ok)
                {
                    try
                    {
                        Zipper.MiniLzoDecompress(rawData, 0, (int)ci.CompressedSize - 8, _decompData);
                        ok = _decompData.Length == (int)ci.UncompressedSize;

                        // var b = new byte[ci.UncompressedSize];
                        // Array.Copy(_decompData, (int) kwi2.CIUncompOffset, b, 0, (int) kwi2.CIUncompLength);
                        // return b;
                        return(_decompData);
                    }
                    catch (Exception ex1)
                    {
                        ErrorLog(ex1.ToString());
                    }
                }

                if (!ok)
                {
                    try
                    {
                        // 1.2版本格式,cti数据块的长度为CompressedSize-8,数据块的末尾8个字节含义暂时未知。
                        //byte[] xyz = new byte[rawdata.Length - 8];
                        //Array.Copy(rawdata, xyz, xyz.Length);
                        Zipper.MiniLzoDecompress(rawData, 0, rawData.Length - 8, _decompData);
                        // _decompSize = Zipper.MiniLzoDecompress(rawdata, 0, rawdata.Length - 8, _decompData);
                        //xyz = new byte[8];
                        //byte[] _decompData1 = new byte[100];
                        //Array.Copy(rawdata, ci.CompressedSize-8, xyz, 0, xyz.Length);
                        //_decompSize = Zipper.MiniLzoDecompress(xyz, _decompData1);

                        #region debug

                        //if (k < 1)
                        //{
                        //    string path = string.Format("{0}.seg2.cti.{1:D5}.unz", CompressUtil.stripPathExt(fs.Name), k);
                        //    write_file(path, _decompData, _decompSize);
                        //    //write_file(CompressUtil.stripPathExt(fs.Name) + ".seg2.cti." + k + ".unz", _decompData, _decompSize);
                        //}

                        #endregion

                        if (_decompSize == (int)ci.UncompressedSize)
                        {
                            return(_decompData);
                        }

                        // var b = new byte[kwi2.CIUncompLength];
                        // Array.Copy(_decompData, (int) kwi2.CIUncompOffset, b, 0, (int) kwi2.CIUncompLength);
                        // return b;
                        // //byte[] b = new byte[_decompSize];
                        // //Array.Copy(_decompData, b, _decompSize);
                        // //return b;
                        return(_decompData);
                    }
                    catch (Exception ex)
                    {
                        //if (this.DictHeader.GeneratedByEngineVersion == "2.0")
                        {
                            ErrorLog(ex.ToString());
                        }
                    }
                }

                if (!ok)
                {
                    try
                    {
                        Zipper.MiniLzoDecompress(rawData, 0, (int)ci.CompressedSize, _decompData);
                        // _decompData = LZOHelper.LZOCompressor.Decompress(rawdata, 0, (int) ci.UncompressedSize);
                        //write_file(path, _decompData, _decompData.Length);
                        ok = _decompData.Length == (int)ci.UncompressedSize;
                    }
                    catch (Exception ex1)
                    {
                        ErrorLog(ex1.ToString());
                        throw;
                    }
                }

                #endregion

                //此外,1.2版本格式也可能采用了第二种压缩方式,这种情况下ci.UncompressedSize!=ci.CompressedSize
                //if (this.DictHeader.GeneratedByEngineVersion == "1.2")
                if (ci.UncompressedSize == ci.CompressedSize)
                {
                    //Version 1.2: 数据内容并未压缩故可直接取用。
                    return(rawData);
                }
                else
                {
                    return(rawData);
                }
            }
            else
            {
                throw new Exception($"提取KWIndex时,期望正确的算法标志0x2000000/0x1000000,然而遇到了{_seg2.MagicNumber}");
            }

            #endregion
        }
Exemple #10
0
        public List <ContentIndex> GetContentIndex(int rid, int cid)
        {
            //decide the length of the partial introduction
            int substringlength = 30;

            conn.ConnectionString = mysqlconnection;
            if (conn.State != ConnectionState.Open)
            {
                conn.Open();
            }
            var contentList = new List <ContentIndex>();
            //active = 1 means its an active row
            var sqlcmd = @"SELECT c.* ,r.regionName AS Region_Name,ca.Category_Name AS Category_Name,u.Name AS UserName,p.Picture_Path AS Path FROM content c LEFT JOIN region r ON (r.regionID = c.Region_Id) 
  LEFT JOIN category ca ON (ca.Category_Id = c.Category_Id) LEFT JOIN user u ON(u.User_Id = c.Last_Update_User_Id) LEFT JOIN picture p ON(p.Picture_Id = c.Picture_Id) WHERE c.Active = 1 ";

            if (rid != 0)
            {
                sqlcmd = sqlcmd + @" AND c.Region_Id = @rid ";
            }

            if (cid != 0)
            {
                sqlcmd = sqlcmd + @" AND c.Category_Id = @cid ";
            }
            sqlcmd = sqlcmd + @" ORDER BY c.Content_Name";
            using (var cmd = new MySqlCommand(sqlcmd, conn))
            {
                if (rid != 0)
                {
                    cmd.Parameters.AddWithValue("@rid", rid);
                }
                if (cid != 0)
                {
                    cmd.Parameters.AddWithValue("@cid", cid);
                }
                using (MySqlDataReader rd = cmd.ExecuteReader())
                {
                    while (rd.Read())
                    {
                        var content = new ContentIndex();
                        content.Region_Id      = Convert.ToInt32(rd["Region_Id"]);
                        content.regionName     = rd["Region_Name"].ToString();
                        content.Category_Id    = Convert.ToInt32(rd["Category_Id"]);
                        content.categoryName   = rd["Category_Name"].ToString();
                        content.Content_Id     = Convert.ToInt32(rd["Content_Id"]);
                        content.Content_Name   = rd["Content_Name"].ToString();
                        content.picname        = rd["Path"].ToString();
                        content.detail         = rd["Detail"].ToString().Substring(0, substringlength);
                        content.year           = Convert.ToInt32(rd["Year"]);
                        content.picture_id     = Convert.ToInt32(rd["Year"]);
                        content.userid         = Convert.ToInt32(rd["Last_Update_User_Id"]);
                        content.usename        = rd["UserName"].ToString();
                        content.Lastupdatetime = Convert.ToDateTime(rd["Last_Update_Date_Time"]);
                        contentList.Add(content);
                    }
                }
            }
            conn.Close();


            return(contentList);
        }