public void Encode_ExceedMaximumContentLength_ShouldThrowException()
        {
            // Arrange
            var unicodeEncoder = new UnicodeEncoder();

            // Act
            Action action = () => unicodeEncoder.Encode(new string('A', 3000), ErrorCorrectionLevel.H);

            // Assert
            action.Should().Throw <InvalidOperationException>()
            .WithMessage("Too much data to encode");
        }
Example #2
0
        public int SequenceIdentifierFrequency(IEnumerable <string> gram)
        {
            string phrase = string.Join(".", gram);
            string key    = UnicodeEncoder.GetUnicodeKeyFromString(phrase,
                                                                   word => ReadCommands.LookupWordId(Connection, Cache, word));

            if (key == null)
            {
                return(0);
            }

            return(ReadCommands.LookupIdentifierSequenceFrequency(Connection, Cache, key));
        }
        public void Encode_UnicodeContent_ShouldEncodeCorrectly()
        {
            // Arrange
            var unicodeEncoder = new UnicodeEncoder();

            // Act
            (BitList bits, VersionInfo versionInfo) = unicodeEncoder.Encode("💩", ErrorCorrectionLevel.H);

            // Assert
            bits.Should().NotBeNull();
            versionInfo.Should().NotBeNull();
            versionInfo.Version.Should().Be(1);
            bits.GetBytes().Should().BeEquivalentTo(new byte[] { 64, 126, 251, 187, 255, 9, 249, 42, 144 });
        }
        public void Encode_NonUnicodeContent_ShouldEncodeCorrectly()
        {
            // Arrange
            var unicodeEncoder = new UnicodeEncoder();

            // Act
            (BitList bits, VersionInfo versionInfo) = unicodeEncoder.Encode("A", ErrorCorrectionLevel.H);

            // Assert
            bits.Should().NotBeNull();
            versionInfo.Should().NotBeNull();
            versionInfo.Version.Should().Be(1);
            bits.GetBytes().Should().BeEquivalentTo(new byte[] { 64, 20, 16, 236, 17, 236, 17, 236, 17 });
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ForumPage"/> class.
        /// </summary>
        /// <param name="transPage">
        /// The trans page.
        /// </param>
        public ForumPage([CanBeNull] string transPage)
        {
            this.Get <IInjectServices>().Inject(this);

            // create empty hashtable for cache entries));
            this._pageCache = new Hashtable();

            this._transPage = transPage;
            this.Init      += this.ForumPage_Init;
            this.Load      += this.ForumPage_Load;
            this.Unload    += this.ForumPage_Unload;
            this.PreRender += this.ForumPage_PreRender;

            this.unicodeEncoder = new UnicodeEncoder();
        }
        /// <summary>
        /// Processes the item.
        /// </summary>
        /// <param name="e">
        /// The <see cref="RepeaterItemEventArgs"/> instance containing the event data.
        /// </param>
        /// <returns>
        /// Returns the Item as string
        /// </returns>
        private string ProcessItem(RepeaterItemEventArgs e)
        {
            var currentRow = (DataRowView)e.Item.DataItem;

            var currentItem = this.itemTemplate;

            var messageUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                this.yafTabInfo,
                "{0}&g=posts&m={1}".FormatWith(
                    Globals.ApplicationURL(this.yafTabInfo.TabID),
                    currentRow["LastMessageID"]),
                UrlRewriteHelper.CleanStringForURL(
                    YafContext.Current.Get <IBadWordReplace>().Replace(currentRow["Topic"].ToString())),
                this.PortalSettings);

            try
            {
                // Render [LASTPOSTICON]
                var lastPostedImage = new ThemeImage
                {
                    LocalizedTitlePage = "DEFAULT",
                    LocalizedTitleTag  = "GO_LAST_POST",
                    LocalizedTitle     =
                        Localization.GetString(
                            "LastPost.Text",
                            this.LocalResourceFile),
                    ThemeTag = "TOPIC_NEW",
                    Style    = "width:16px;height:16px"
                };

                currentItem = currentItem.Replace("[LASTPOSTICON]", lastPostedImage.RenderToString());
            }
            catch (Exception)
            {
                currentItem = currentItem.Replace("[LASTPOSTICON]", string.Empty);
            }

            // Render [TOPICLINK]
            var textMessageLink = new HyperLink
            {
                Text =
                    YafContext.Current.Get <IBadWordReplace>()
                    .Replace(currentRow["Topic"].ToString()),
                NavigateUrl = messageUrl
            };

            currentItem = currentItem.Replace("[TOPICLINK]", textMessageLink.RenderToString());

            // Render [FORUMLINK]
            var forumLink = new HyperLink
            {
                Text        = currentRow["Forum"].ToString(),
                NavigateUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                    this.yafTabInfo,
                    "{0}&g=topics&f={1}".FormatWith(
                        Globals.ApplicationURL(this.yafTabInfo.TabID),
                        currentRow["ForumID"]),
                    UrlRewriteHelper.CleanStringForURL(
                        YafContext.Current.Get <IBadWordReplace>()
                        .Replace(currentRow["Forum"].ToString())),
                    this.PortalSettings)
            };

            currentItem = currentItem.Replace("[FORUMLINK]", forumLink.RenderToString());

            // Render [BYTEXT]
            currentItem = currentItem.Replace(
                "[BYTEXT]",
                YafContext.Current.Get <IHaveLocalization>().GetText("SEARCH", "BY"));

            // Render [LASTUSERLINK]
            // Just in case...
            if (currentRow["LastUserID"] != DBNull.Value)
            {
                var userName = YafContext.Current.Get <YafBoardSettings>().EnableDisplayName
                                   ? currentRow["LastUserDisplayName"].ToString()
                                   : currentRow["LastUserName"].ToString();

                userName = new UnicodeEncoder().XSSEncode(userName);

                var lastUserLink = new HyperLink
                {
                    Text        = userName,
                    ToolTip     = userName,
                    NavigateUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                        this.yafTabInfo,
                        "{0}&g=profile&u={1}".FormatWith(
                            Globals.ApplicationURL(this.yafTabInfo.TabID),
                            currentRow["LastUserID"]),
                        userName,
                        this.PortalSettings)
                };

                currentItem = currentItem.Replace("[LASTUSERLINK]", lastUserLink.RenderToString());
            }

            // Render [LASTMESSAGE]
            var lastMessage =
                BBCodeHelper.StripBBCode(
                    HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(currentRow["LastMessage"].ToType <string>())))
                .RemoveMultipleWhitespace();

            try
            {
                var match = Regex.Match(currentItem, @"\[LASTMESSAGE\:(?<count>[0-9]*)\]", RegexOptions.Compiled);

                if (match.Success)
                {
                    var messageLimit = match.Groups["count"].Value.ToType <int>();

                    currentItem = currentItem.Replace(
                        "[LASTMESSAGE:{0}]".FormatWith(match.Groups["count"].Value),
                        lastMessage.Truncate(messageLimit));
                }
                else
                {
                    currentItem = currentItem.Replace("[LASTMESSAGE]", lastMessage);
                }
            }
            catch (Exception)
            {
                currentItem = currentItem.Replace("[LASTMESSAGE]", lastMessage);
            }

            // Render [LASTPOSTEDDATETIME]
            var displayDateTime = new DisplayDateTime {
                DateTime = currentRow["LastPosted"].ToType <DateTime>()
            };

            currentItem = currentItem.Replace("[LASTPOSTEDDATETIME]", displayDateTime.RenderToString());

            return(currentItem);
        }
Example #7
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "ForumPage" /> class.
 /// </summary>
 public ForumPage()
     : this(string.Empty)
 {
     this.unicodeEncoder = new UnicodeEncoder();
 }
Example #8
0
 /// <summary>
 ///   Initializes a new instance of the <see cref = "ForumPage" /> class.
 /// </summary>
 protected ForumPage()
     : this(string.Empty)
 {
     this.unicodeEncoder = new UnicodeEncoder();
 }
Example #9
0
        /// <summary>
        /// Processes the item.
        /// </summary>
        /// <param name="e">
        /// The <see cref="RepeaterItemEventArgs"/> instance containing the event data.
        /// </param>
        /// <returns>
        /// Returns the Item as string
        /// </returns>
        private string ProcessItem(RepeaterItemEventArgs e)
        {
            var dataItem = (LatestTopic)e.Item.DataItem;

            var currentItem = this.itemTemplate;

            var messageUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                this.yafTabInfo,
                $"{Globals.ApplicationURL(this.yafTabInfo.TabID)}&g=posts&m={dataItem.LastMessageID}",
                UrlRewriteHelper.CleanStringForURL(
                    BoardContext.Current.Get <IBadWordReplace>().Replace(dataItem.Topic)));

            currentItem = currentItem.Replace("[LASTPOSTICON]", string.Empty);

            // Render TOPICLINK
            var textMessageLink = new HyperLink
            {
                Text =
                    BoardContext.Current.Get <IBadWordReplace>()
                    .Replace(dataItem.Topic),
                NavigateUrl = messageUrl
            };

            currentItem = currentItem.Replace("[TOPICLINK]", textMessageLink.RenderToString());

            // Render FORUMLINK
            var forumLink = new HyperLink
            {
                Text        = dataItem.Forum,
                NavigateUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                    this.yafTabInfo,
                    $"{Globals.ApplicationURL(this.yafTabInfo.TabID)}&g=topics&f={dataItem.ForumID}",
                    UrlRewriteHelper.CleanStringForURL(
                        BoardContext.Current.Get <IBadWordReplace>()
                        .Replace(dataItem.Forum)))
            };

            currentItem = currentItem.Replace("[FORUMLINK]", forumLink.RenderToString());

            // Render BYTEXT
            currentItem = currentItem.Replace(
                "[BYTEXT]",
                BoardContext.Current.Get <IHaveLocalization>().GetText("SEARCH", "BY"));

            // Render LASTUSERLINK
            // Just in case...
            if (dataItem.LastUserID.HasValue)
            {
                var userName = BoardContext.Current.Get <BoardSettings>().EnableDisplayName
                                   ? dataItem.LastUserDisplayName
                                   : dataItem.LastUserName;

                userName = new UnicodeEncoder().XSSEncode(userName);

                var lastUserLink = new HyperLink
                {
                    Text        = userName,
                    ToolTip     = userName,
                    NavigateUrl = FriendlyUrlProvider.Instance().FriendlyUrl(
                        this.yafTabInfo,
                        $"{Globals.ApplicationURL(this.yafTabInfo.TabID)}&g=profile&u={dataItem.LastUserID}",
                        userName)
                };

                currentItem = currentItem.Replace("[LASTUSERLINK]", lastUserLink.RenderToString());
            }

            // Render LASTMESSAGE
            var lastMessage =
                BBCodeHelper.StripBBCode(
                    HtmlHelper.StripHtml(HtmlHelper.CleanHtmlString(dataItem.LastMessage)))
                .RemoveMultipleWhitespace();

            try
            {
                var match = Regex.Match(currentItem, @"\[LASTMESSAGE\:(?<count>[0-9]*)\]", RegexOptions.Compiled);

                if (match.Success)
                {
                    var messageLimit = match.Groups["count"].Value.ToType <int>();

                    currentItem = currentItem.Replace(
                        $"[LASTMESSAGE:{match.Groups["count"].Value}]",
                        lastMessage.Truncate(messageLimit));
                }
                else
                {
                    currentItem = currentItem.Replace("[LASTMESSAGE]", lastMessage);
                }
            }
            catch (Exception)
            {
                currentItem = currentItem.Replace("[LASTMESSAGE]", lastMessage);
            }

            // Render LASTPOSTEDDATETIME
            var displayDateTime = new DisplayDateTime {
                DateTime = (DateTime)dataItem.LastPosted
            };

            currentItem = currentItem.Replace("[LASTPOSTEDDATETIME]", displayDateTime.RenderToString());

            return(currentItem);
        }