コード例 #1
0
        public override IEnumerable <UTCourse> FetchItems()
        {
            List <UTCourse> results = new List <UTCourse>();

            if (this.Content == null)
            {
                return(results);
            }
            this.Content = this.Content.Replace("\n", String.Empty).Replace("\r", String.Empty);
            MatchCollection matches = CourseRegex.Matches(this.Content);

            foreach (Match match in matches)
            {
                UTCourse course = new UTCourse()
                {
                    Code           = match.Groups["code"].Value,
                    SemesterPrefix = match.Groups["prefix"].Value,
                    Name           = SpaceRegex.Replace(HttpUtility.HtmlDecode(match.Groups["name"].Value).Trim(' ').Trim(' '), " ")
                };
                string[] properties = AngleRegex.Replace(match.Groups["content"].Value.Replace("<br>", "|"), String.Empty).Split('|');

                string description      = String.Empty;
                bool   afterDescription = false;
                foreach (string property in properties)
                {
                    if (property.Trim(' ').StartsWith("Prerequisite: "))
                    {
                        course.Prerequisites = SpaceRegex.Replace(HttpUtility.HtmlDecode(property.Trim(' ').Substring("Prerequisite: ".Length)), " ");
                        afterDescription     = true;
                    }
                    else if (property.Trim(' ').StartsWith("Exclusion: "))
                    {
                        course.Exclusions = SpaceRegex.Replace(HttpUtility.HtmlDecode(property.Trim(' ').Substring("Exclusion: ".Length)), " ");
                        afterDescription  = true;
                    }
                    else if (property.Trim(' ').StartsWith("Breadth Requirement: "))
                    {
                        course.Exclusions = SpaceRegex.Replace(HttpUtility.HtmlDecode(property.Trim(' ').Substring("Breadth Requirement: ".Length)), " ");
                        afterDescription  = true;
                    }
                    else if (property.Trim(' ').StartsWith("Corequisite: "))
                    {
                        course.Corequisites = SpaceRegex.Replace(HttpUtility.HtmlDecode(property.Trim(' ').Substring("Corequisite: ".Length)), " ");
                        afterDescription    = true;
                    }
                    else if (!afterDescription)
                    {
                        description += property;
                    }
                }
                course.Description = description;
                course.Department  = SpaceRegex.Replace(HttpUtility.HtmlDecode(description), " ").Trim(' ');
                course.Department  = UrlRegex.Match(this.Url).Groups["name"].Value.Replace("_", " ");
                results.Add(course);
                //Console.WriteLine("UTSC Course: " + course.Abbr);
            }

            return(results);
        }
コード例 #2
0
ファイル: MessageParser.cs プロジェクト: licnep/smuxi
        public static void ParseUrls(MessageModel msg)
        {
            // clone MessageParts
            IList <MessagePartModel> parts = new List <MessagePartModel>(msg.MessageParts);

            foreach (MessagePartModel part in parts)
            {
                if (part is UrlMessagePartModel)
                {
                    // no need to reparse URL parts
                    continue;
                }
                if (!(part is TextMessagePartModel))
                {
                    continue;
                }

                TextMessagePartModel textPart = (TextMessagePartModel)part;
                Match urlMatch = UrlRegex.Match(textPart.Text);
                // OPT: fast regex scan
                if (!urlMatch.Success)
                {
                    // no URLs in this MessagePart, nothing to do
                    continue;
                }

                // found URL(s)
                // remove current MessagePartModel as we need to split it
                int idx = msg.MessageParts.IndexOf(part);
                msg.MessageParts.RemoveAt(idx);

                string[] textPartParts = textPart.Text.Split(new char[] { ' ' });
                for (int i = 0; i < textPartParts.Length; i++)
                {
                    string textPartPart = textPartParts[i];
                    urlMatch = UrlRegex.Match(textPartPart);
                    if (urlMatch.Success)
                    {
                        UrlMessagePartModel urlPart = new UrlMessagePartModel(textPartPart);
                        //urlPart.ForegroundColor = new TextColor();
                        msg.MessageParts.Insert(idx++, urlPart);
                        msg.MessageParts.Insert(idx++, new TextMessagePartModel(" "));
                    }
                    else
                    {
                        // FIXME: we put each text part into it's own object, instead of combining them (the smart way)
                        TextMessagePartModel notUrlPart = new TextMessagePartModel(textPartPart + " ");
                        // restore formatting / colors from the original text part
                        notUrlPart.IsHighlight     = textPart.IsHighlight;
                        notUrlPart.ForegroundColor = textPart.ForegroundColor;
                        notUrlPart.BackgroundColor = textPart.BackgroundColor;
                        notUrlPart.Bold            = textPart.Bold;
                        notUrlPart.Italic          = textPart.Italic;
                        notUrlPart.Underline       = textPart.Underline;
                        msg.MessageParts.Insert(idx++, notUrlPart);
                    }
                }
            }
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: rmoorman/sd-agent-windows
        private bool IsURLValid()
        {
            Match match = UrlRegex.Match(_url.Text);

            if (!match.Success)
            {
                return(false);
            }
            return(true);
        }
コード例 #4
0
            public Task CheckAsync(DiscordMessage message)
            {
                //Set some obvious
                MessageId = message.Id;

                //Detect URL
                var matches = UrlRegex.Match(message.Content);

                if (matches.Success)
                {
                    URL = matches.Value;
                }

                return(Task.CompletedTask);
            }