public bool TryConvert(Statement statement, string text, out Lifetime lifetime)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            Match match   = null;
            var   success = false;

            lifetime = Lifetime.Transient;
            do
            {
                match = match?.NextMatch() ?? Regex.Match(text);
                if (!match.Success)
                {
                    break;
                }

                var lifetimeName = match.Groups[1].Value.Replace(" ", string.Empty).Replace($"{nameof(Lifetime)}.", string.Empty).Trim();
                try
                {
                    lifetime = (Lifetime)Enum.Parse(TypeDescriptor <Lifetime> .Type, lifetimeName, true);
                }
                catch (Exception)
                {
                    lifetime = _issueResolver.CannotParseLifetime(statement.Text, statement.LineNumber, statement.Position, lifetimeName);
                }

                success = true;
            }while (true);
            return(success);
        }
Example #2
0
        /// <summary>
        /// Parses the message.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public static Message ParseMessage(byte[] data)
        {
            Message message = new Message();

            try
            {
                // Build a part tree and get all headers.
                MimePart part = ParseMimePart(data, message);

                // Fill a new message object with the new information.
                message.OriginalData     = data;
                message.HeaderFields     = part.HeaderFields;
                message.HeaderFieldNames = part.HeaderFieldNames;

                // Dispatch header fields to corresponding object.
                foreach (string key in message.HeaderFields.AllKeys)
                {
                    string value = message.HeaderFields[key];
                    if (key.Equals("received"))
                    {
                        Match m = Regex.Match(value, @"from.+?(?=(from|$))");
                        while (m.Success)
                        {
                            message.Trace.Add(ParseTrace(key + ": " + m.Value));
                            m = m.NextMatch();
                        }
                    }
                    else if (key.Equals("to"))
                    {
                        message.To = ParseAddresses(value);
                    }
                    else if (key.Equals("cc"))
                    {
                        message.Cc = ParseAddresses(value);
                    }
                    else if (key.Equals("bcc"))
                    {
                        message.Bcc = ParseAddresses(value);
                    }
                    else if (key.Equals("reply-to"))
                    {
                        message.ReplyTo = ParseAddress(value);
                    }
                    else if (key.Equals("from"))
                    {
                        message.From = ParseAddress(value);
                    }
                    else if (key.Equals("sender"))
                    {
                        message.Sender = ParseAddress(value);
                    }
                    else if (key.Equals("content-type"))
                    {
                        message.ContentType = GetContentType(key + ": " + value);
                    }
                    else if (key.Equals("content-disposition"))
                    {
                        message.ContentDisposition = GetContentDisposition(key + ": " + value);
                    }
                    else if (key.Equals("domainkey-signature"))
                    {
                        message.Signatures.DomainKeys = Signature.Parse(key + ": " + value, message);
                    }
                }

                if (message.ContentType.MimeType.Equals("application/pkcs7-mime") || message.ContentType.MimeType.Equals("application/x-pkcs7-mime"))
                {
                    if (message.ContentType.Parameters["smime-type"] != null && message.ContentType.Parameters["smime-type"].Equals("enveloped-data"))
                    {
                        message.IsSmimeEncrypted = true;
                    }
                    if (message.ContentType.Parameters["smime-type"] != null && message.ContentType.Parameters["smime-type"].Equals("signed-data"))
                    {
                        message.HasSmimeSignature = true;
                    }
                }

                if (message.ContentType.MimeType.Equals("multipart/signed"))
                {
                    message.HasSmimeDetachedSignature = true;
                }

                // Keep a reference to the part tree within the new Message object.
                message.PartTreeRoot = part;

                DispatchParts(ref message);

                // Dispatch the part tree content to the appropriate collections and properties.
                // TODO
            }
            catch (Exception ex)
            {
                if (ErrorParsing != null)
                {
                    ErrorParsing(null, ex);
                }
            }
            return(message);
        }
        public bool TryConvert(Statement context, string text, out IEnumerable <object> tags)
        {
            if (text == null)
            {
                throw new ArgumentNullException(nameof(text));
            }
            var   tagSet = new HashSet <object>();
            Match match  = null;

            do
            {
                match = match?.NextMatch() ?? Regex.Match(text);
                if (!match.Success)
                {
                    break;
                }

                var tag = match.Groups[1].Value.Trim();
                // empty
                if (string.IsNullOrWhiteSpace(tag))
                {
                    tagSet.Add(null);
                    continue;
                }

                // string
                if (tag.StartsWith("\"") && tag.EndsWith("\""))
                {
                    tagSet.Add(tag.Substring(1, tag.Length - 2));
                    continue;
                }

                // char
                if (tag.Length == 3 && tag.StartsWith("'") && tag.EndsWith("'"))
                {
                    tagSet.Add(tag[1]);
                    continue;
                }

                // int
                if (int.TryParse(tag, NumberStyles.Any, CultureInfo.InvariantCulture, out var intValue))
                {
                    tagSet.Add(intValue);
                    continue;
                }

                // long
                if (long.TryParse(tag, NumberStyles.Any, CultureInfo.InvariantCulture, out var longValue))
                {
                    tagSet.Add(longValue);
                    continue;
                }

                // double
                if (double.TryParse(tag, NumberStyles.Any, CultureInfo.InvariantCulture, out var doubleValue))
                {
                    tagSet.Add(doubleValue);
                    continue;
                }

                // DateTimeOffset
                if (DateTimeOffset.TryParse(tag, out var dateTimeOffsetValue))
                {
                    tagSet.Add(dateTimeOffsetValue);
                }
            }while (true);

            tags = tagSet;
            return(tagSet.Any());
        }
        private void btnList_Click(object sender, EventArgs e)
        {
            helper.play_sound("click");

            string show_name = txtShow.Text;

            if (show_name == "")
            {
                MessageBox.Show("Enter show name", application_title, MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                lvEpisodes.Items.Clear();

                int counter = 0;

                show_name = show_name.Replace(" ", "");

                string html = http_get("http://epguides.com/" + show_name);

                Match search1 = Regex.Match(html, "<pre[^<>]*>(.*?)</pre>", RegexOptions.Singleline);

                if (search1.Success)
                {
                    string   pre = search1.Groups[1].Value;
                    string[] stringSeparators = new string[] { "\n" };
                    string[] lineas           = pre.Split(stringSeparators, StringSplitOptions.None);

                    foreach (string linea in lineas)
                    {
                        string pre_cleaned = Regex.Replace(linea, @"\s+", " ");

                        string number         = "";
                        string episode_number = "";
                        string air_date       = "";
                        string title          = "";

                        Match search2 = Regex.Match(pre_cleaned, "(.*?). (.*?)-(.*?) (.*?) <a target=\"_blank\" href=\"(.*?)\">(.*?)</a>", RegexOptions.IgnoreCase);
                        while (search2.Success)
                        {
                            number         = search2.Groups[1].Value;
                            episode_number = search2.Groups[2].Value + "-" + search2.Groups[3].Value;
                            air_date       = search2.Groups[4].Value;
                            title          = search2.Groups[6].Value;
                            counter++;
                            search2 = search2.NextMatch();
                        }

                        if (air_date == "")
                        {
                            Match search3 = Regex.Match(pre_cleaned, "(.*?). (.*?) <a target=\"_blank\" href=\"(.*?)\">(.*?)</a>", RegexOptions.IgnoreCase);
                            while (search3.Success)
                            {
                                number         = search3.Groups[1].Value;
                                episode_number = search3.Groups[2].Value;
                                air_date       = "No date";
                                title          = search3.Groups[4].Value;
                                counter++;
                                search3 = search3.NextMatch();
                            }
                        }

                        ListViewItem item = new ListViewItem();
                        item.Text = number;
                        item.SubItems.Add(episode_number);
                        item.SubItems.Add(air_date);
                        item.SubItems.Add(title);

                        if (title != "")
                        {
                            lvEpisodes.Items.Add(item);
                        }
                    }

                    gbEpisodes.Text = "Episodes : " + counter;
                }
                else
                {
                    MessageBox.Show("Show not found, try another name", application_title, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }

                helper.play_sound("done");
            }
        }
Example #5
0
        public expression NewFormatString(string_const str)
        {
            try
            {
                method_call mc = new method_call();
                mc.dereferencing_value = new dot_node(new ident("string", str.source_context), new ident("Format", str.source_context), str.source_context);
                mc.parameters          = new expression_list();
                if (!str.Value.Contains("{"))
                {
                    return(str);
                }
                string val = str.Value.Replace("{{", "![&").Replace("}}}", "}&]!").Replace("}}", "&]!");

                string[]      arr   = Regex.Split(val, @"\{[^\}]+\}");
                Match         match = Regex.Match(val, @"\{[^\}]+\}");
                List <string> vars  = new List <string>();
                //Dictionary<string, int> var_offsets = new Dictionary<string, int>();
                List <int> var_offsets = new List <int>();
                Dictionary <int, string> var_formats = new Dictionary <int, string>();
                int ind = 0;
                while (match.Success)
                {
                    string s             = match.Value.Replace("{", "").Replace("}", "");
                    int    colon_pos     = s.LastIndexOf(':');
                    int    comma_pos     = s.LastIndexOf(',');
                    int    bracket_pos   = s.LastIndexOf(')');
                    int    sqbracked_pos = s.LastIndexOf(']');
                    if (comma_pos != -1 && comma_pos > bracket_pos && comma_pos > sqbracked_pos)
                    {
                        colon_pos = comma_pos;
                    }
                    if (colon_pos != -1 && s.IndexOf('?') == -1 && s.Substring(colon_pos).IndexOf(']') == -1)
                    {
                        var_formats.Add(ind, s.Substring(colon_pos));
                        s = s.Substring(0, colon_pos);
                    }
                    if (s.IndexOf("&]!") != -1 || s.IndexOf("![&") != -1)
                    {
                        parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
                        return(str);
                    }
                    vars.Add(s);
                    var_offsets.Add(match.Index);
                    match = match.NextMatch();
                    ind++;
                }
                if (vars.Count == 0 && val.IndexOf("![&") == -1 && val.IndexOf("{") != -1)
                {
                    parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
                    return(str);
                }

                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < arr.Length; i++)
                {
                    if (arr[i].IndexOf("{") != -1 || arr[i].IndexOf("}") != -1)
                    {
                        parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
                        return(str);
                    }
                    sb.Append(arr[i].Replace("![&", "{{").Replace("&]!", "}}"));
                    if (i < arr.Length - 1)
                    {
                        sb.Append("{" + i);
                        string fmt;
                        if (var_formats.TryGetValue(i, out fmt))
                        {
                            sb.Append(fmt);
                        }
                        sb.Append("}");
                    }
                }
                string str2 = sb.ToString();
                if (str2.Trim().EndsWith("{"))
                {
                    parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
                    return(str);
                }
                mc.parameters.Add(new string_const(str2, str.source_context), str.source_context);
                for (int i = 0; i < vars.Count; i++)
                {
                    string s    = vars[i];
                    var    expr = ParseExpression(new string('\n', str.source_context.begin_position.line_num - 1) + new string(' ', str.source_context.begin_position.column_num + var_offsets[i] + 2) + s, str.source_context.begin_position.line_num, str.source_context.begin_position.column_num + var_offsets[i] + 2);
                    if (expr == null)
                    {
                        var err = parsertools.errors[0] as LocatedError;
                        err.SourceContext.begin_position.line_num   = str.source_context.begin_position.line_num;
                        err.SourceContext.begin_position.column_num = str.source_context.begin_position.column_num + var_offsets[i] + vars[i].Length + 3;
                        return(str);
                    }
                    expr.source_context.begin_position.line_num = str.source_context.begin_position.line_num;
                    expr.source_context.end_position.line_num   = str.source_context.end_position.line_num;
                    mc.parameters.Add(expr);
                }

                mc.source_context = str.source_context;
                return(mc);
            }
            catch (Exception ex)
            {
                parsertools.errors.Add(new bad_format_string(parsertools.CurrentFileName, str.source_context, str));
            }
            return(str);
        }
Example #6
0
        /// <summary>
        /// Parses the MIME part.
        /// </summary>
        /// <param name="data">The data.</param>
        /// <returns></returns>
        public static MimePart ParseMimePart(string data, Message message)
        {
            MimePart part = new MimePart();

            part.ParentMessage   = message;
            part.OriginalContent = data;

            try
            {
                // Separate header and body.
                int headerEnd = Regex.Match(data, @".(?=\r?\n\r?\n)").Index + 1;
                int bodyStart = Regex.Match(data, @"(?<=\r?\n\r?\n).").Index;

                //TODO: remove this workaround
                if (bodyStart == 0)
                {
                    //bodyStart = data.IndexOf("\r\n\r\n");
                    // Fix for a bug - the bodyStart was -1 (Invalid), MCALADO: 04/07/2008
                    int indexBody = data.IndexOf("\r\n\r\n");
                    if (indexBody > 0)
                    {
                        bodyStart = indexBody;
                    }
                }
                if (data.Length >= headerEnd)
                {
                    string header = data.Substring(0, headerEnd);

                    header = Parser.Unfold(header);
                    //header = header);

                    // The bodyStart need to be greather than data.length - MCALADO: 04/07/2008
                    string body = string.Empty;
                    if (bodyStart < data.Length)
                    {
                        body = data.Substring(bodyStart);
                    }

                    // Store the (maybe still encoded) body.
                    part.TextContent = body;



                    // Parse header fields and their parameters.
                    Match m = Regex.Match(header, @"(?<=((\r?\n)|\n)|\A)\S+:(.|(\r?\n[\t ]))+(?=((\r?\n)\S)|\Z)");
                    while (m.Success)
                    {
                        if (m.Value.ToLower().StartsWith("content-type:"))
                        {
                            part.ContentType = Parser.GetContentType(m.Value);
                        }
                        else if (m.Value.ToLower().StartsWith("content-disposition:"))
                        {
                            part.ContentDisposition = Parser.GetContentDisposition(m.Value);
                        }
                        part.HeaderFields.Add(FormatFieldName(m.Value.Substring(0, m.Value.IndexOf(':'))), Codec.RFC2047Decode(m.Value.Substring(m.Value.IndexOf(':') + 1).Trim(' ', '\r', '\n')));
                        part.HeaderFieldNames.Add(FormatFieldName(m.Value.Substring(0, m.Value.IndexOf(':'))), Codec.RFC2047Decode(m.Value.Substring(0, m.Value.IndexOf(':')).Trim(' ', '\r', '\n')));
                        m = m.NextMatch();
                    }

                    // Build the part tree.

                    // This is a container part.
                    if (part.ContentType.Type.ToLower().Equals("multipart"))
                    {
                        Parser.ParseSubParts(ref part, message);
                    }
                    // This is a nested message.
                    else if (part.ContentType.Type.ToLower().Equals("message"))
                    {
                        // TODO
                    }
                    // This is a leaf of the part tree
                    // Check necessary for single part emails (fix from alex294 on CodePlex)
                    // Why would we consider the body only to the first string?  Doesn't make sense - and fails
                    //else if (part.ContentType.Type.ToLower().Equals("text"))
                    //{
                    //    int BodyEnd = body.IndexOf(' ');
                    //    if (BodyEnd > 0)
                    //    {
                    //        part.TextContent = body.Substring(0, BodyEnd);
                    //    }
                    //}

                    DecodePartBody(ref part);

                    try
                    {
                        BodyParsed(null, message);
                    }
                    catch (Exception)
                    {
                        // event is not supported.
                    }
                }
            }
            catch (Exception ex)
            {
                throw new ParsingException(ex.Message);
            }

            return(part);
        }
        /// <summary>
        /// Extracts a snippet from a given rule pattern.
        /// </summary>
        /// <param name="fileSystemInfo">The file system info.</param>
        /// <param name="memberPattern">The member pattern to extract.</param>
        /// <returns>The extracted snippet.</returns>
        public override Extension.Model.Snippet Extract(FileSystemInfoBase fileSystemInfo, string memberPattern)
        {
            // Return the entire code if no member is specified
            if (string.IsNullOrWhiteSpace(memberPattern))
            {
                return(base.Extract(fileSystemInfo, memberPattern));
            }

            // Load the xml document for xpath execution
            if (null == this.xmlDocument)
            {
                // Load file content
                string sourceCode = base.LoadFile(this.ConvertToFile(fileSystemInfo));

                // Remove default avoiding to define and use a prefix for the default namespace
                // This is not strictly correct in a xml point of view but it's closest to most needs
                sourceCode = Regex.Replace(sourceCode, @"xmlns\s*=\s*""[^""]*""", string.Empty);

                // Parse the file as xml
                this.xmlDocument = new XmlDocument();
                try
                {
                    // Initialize the document and the namespace manager
                    this.xmlDocument.LoadXml(sourceCode);
                    this.xmlNamespaceManager = new XmlNamespaceManager(this.xmlDocument.NameTable);

                    // Match namespace declaration for filling the namespace manager
                    Match match = this.regex.Match(sourceCode);
                    while (match.Success)
                    {
                        // Collect prefix and namespace value
                        string prefix = match.Groups[1].Value.Trim();
                        string ns     = match.Groups[2].Value.Trim();

                        // Add namespace declaration to the namespace manager
                        xmlNamespaceManager.AddNamespace(prefix, ns);

                        // Mode to the next matching
                        match = match.NextMatch();
                    }
                }

                // Throw an exception is the file is not loadable as xml document
                catch (System.Exception exception)
                {
                    throw new SnippetExtractionException("Cannot parse xml file", exception.Message);
                }
            }

            // Execute Xpath query
            XmlNodeList xmlNodeList = null;

            try
            {
                xmlNodeList = this.xmlDocument.SelectNodes(memberPattern, this.xmlNamespaceManager);
            }
            catch
            {
                throw new SnippetExtractionException("Invalid extraction rule", memberPattern);
            }

            // Ensure we found a result
            if (xmlNodeList.Count <= 0)
            {
                throw new SnippetExtractionException("Cannot find member", memberPattern);
            }

            // Build a snippet for extracted nodes
            return(this.BuildSnippet(xmlNodeList));
        }
Example #8
0
        public override int DiscoverDynamicCategories()
        {
            Settings.Categories.Clear();
            string data = GetWebData(ORF_BASE);

            //Add the url for upcoming livestreams
            RssLink catLive = new RssLink();

            catLive.Name             = "[Live-Streams]";
            catLive.Url              = ORF_BASE + "/live";
            catLive.HasSubCategories = false;
            catLive.Other            = CategoryType.Live;
            Settings.Categories.Add(catLive);

            //Parse and add the url for archived videos
            if (View == CategoryShowTypes.Site)
            {
                Match c = regEx_MainCategories.Match(data);
                while (c.Success)
                {
                    RssLink cat = new RssLink();
                    cat.Name             = c.Groups["title"].Value;
                    cat.HasSubCategories = true;
                    cat.Other            = CategoryType.VOD;
                    cat.SubCategories    = new List <Category>();

                    Match c2 = regEx_SubCategories.Match(c.Groups["subcategories"].Value);
                    while (c2.Success)
                    {
                        String categoryUrl   = ORF_BASE + c2.Groups["url"].Value;
                        String categoryTitle = c2.Groups["title"].Value;

                        RssLink sub = new RssLink();
                        sub.Name             = categoryTitle;
                        sub.Url              = categoryUrl;
                        sub.HasSubCategories = false;
                        sub.Other            = CategoryType.VOD;
                        sub.ParentCategory   = cat;

                        cat.SubCategories.Add(sub);
                        c2 = c2.NextMatch();
                    }
                    Settings.Categories.Add(cat);
                    c = c.NextMatch();
                }
            }
            else
            {
                Match c = regEx_Categories.Match(data);
                while (c.Success)
                {
                    Match c2 = regEx_Categories.Match(c.Value);
                    while (c2.Success)
                    {
                        String categoryUrl   = c2.Groups["url"].Value;
                        String categoryTitle = c2.Groups["title"].Value;

                        RssLink cat = new RssLink();
                        cat.Name             = categoryTitle;
                        cat.Url              = categoryUrl;
                        cat.HasSubCategories = false;
                        cat.Other            = CategoryType.VOD;

                        Settings.Categories.Add(cat);

                        c2 = c2.NextMatch();
                    }

                    c = c.NextMatch();
                }
            }

            Settings.DynamicCategoriesDiscovered = true;
            return(Settings.Categories.Count);
        }
Example #9
0
        private string parseDesc(Sample s, XmlNode descNode)
        {
            System.Diagnostics.Debug.Assert(descNode != null);

            string t = descNode.InnerText.ToString().Trim();

            // Regexp:      ... <p> name        = value     </p> ...
            Regex r = new Regex(@">(?<1>[\w\s]+)=(?<2>[^<]+)<", RegexOptions.Singleline | RegexOptions.Compiled);

            string timeCode = "";

            for (Match m = r.Match(t); m.Success; m = m.NextMatch())
            {
                string name  = m.Groups[1].Value;
                string value = m.Groups[2].Value;

                switch (name)
                {
                case "time":
                    // This is an ISO time code with actually enough milliseconds to be interesting.
                    // We have the same info in elapsed_time so we're not going to bother decoding
                    // the ISO time string. However we want the value to quickly discard dups.
                    timeCode = value;
                    break;

                case "accel":
                    s.mAccel = Convert.ToDouble(value);
                    break;

                case "lateral_accel":
                    s.mLateralAccel = Convert.ToDouble(value);
                    break;

                case "bearing":
                    s.mBearing = Convert.ToDouble(value);
                    break;

                case "speed":
                    int    space = value.IndexOf(' ');
                    string num   = space > 0 ? value.Substring(0, space) : value;
                    s.mSpeed = Convert.ToDouble(num);
                    if (value.IndexOf("mph") > 0)
                    {
                        s.mSpeed = mph2ms(s.mSpeed);
                    }
                    else if (value.IndexOf("kmh") > 0)
                    {
                        s.mSpeed = kmh2ms(s.mSpeed);
                    }
                    break;

                case "elapsed time":
                    int    col = value.IndexOf(':');
                    string min = value.Substring(0, col);
                    string sec = value.Substring(col + 1);
                    s.mElapsedTime = Convert.ToDouble(min) * 60 + Convert.ToDouble(sec);
                    break;
                }
            }

            return(timeCode);
        }
Example #10
0
        private List <VideoInfo> GetLiveVideoList(Category category)
        {
            List <VideoInfo> videos = new List <VideoInfo>();
            string           data   = GetWebData((category as RssLink).Url);

            if (!string.IsNullOrEmpty(data))
            {
                if (data.Contains("<div id=\"livestreamCommingSoon\""))
                {
                    Match m = regEx_LiveNoStreamRunning.Match(data);
                    if (m.Success)
                    {
                        VideoInfo video = new VideoInfo();
                        //the video that is shown on front should have the same format
                        //as the videos shown in the "Weitere Livestreams" section
                        //(e.g. "Live: Burgenland heute, 19:00 Uhr")
                        video.Title = m.Groups["title"].Value + ", " + m.Groups["begintime"].Value;

                        video.Title = video.Title.Replace("&#160;", " ");

                        video.Thumb    = m.Groups["img"].Value;
                        video.VideoUrl = (category as RssLink).Url;
                        video.Other    = CategoryType.Live;

                        videos.Add(video);
                    }
                }
                else
                {
                    Match m = regEx_LiveStreamRunning.Match(data);
                    if (m.Success)
                    {
                        VideoInfo video = new VideoInfo();
                        video.Title = m.Groups["title"].Value;
                        video.Title = video.Title.Replace("&#160;", " ");

                        video.Thumb    = m.Groups["img"].Value;
                        video.VideoUrl = ORF_BASE + m.Groups["url"].Value;
                        video.Other    = CategoryType.Live;

                        videos.Add(video);
                    }
                }

                Match m2 = regEx_LiveFurther.Match(data);
                while (m2.Success)
                {
                    VideoInfo video = new VideoInfo();
                    video.Title = m2.Groups["title"].Value;
                    video.Title = video.Title.Replace("&#160;", " ");

                    video.Thumb    = m2.Groups["img"].Value;
                    video.VideoUrl = ORF_BASE + m2.Groups["url"].Value;
                    video.Other    = CategoryType.Live;

                    videos.Add(video);

                    m2 = m2.NextMatch();
                }

                Match m3 = regEx_LiveUpcoming.Match(data);
                while (m3.Success)
                {
                    VideoInfo video = new VideoInfo();
                    String    date  = m3.Groups["date"].Value.Replace("&#160;", " ").Trim();
                    video.Title       = "Demnächst: " + m3.Groups["title"].Value + " (" + date + ")";
                    video.Airdate     = date;
                    video.Description = m3.Groups["title"].Value;
                    video.Thumb       = m3.Groups["img"].Value;
                    //video.VideoUrl = ORF_BASE + m2.Groups["url"].Value;
                    video.Other = CategoryType.Live;

                    videos.Add(video);

                    m3 = m3.NextMatch();
                }
            }
            return(videos);
        }
Example #11
0
        /// <summary>
        /// Returns the archive videos for the category.
        /// </summary>
        /// <param name="category">Selected category</param>
        /// <returns>List of videos</returns>
        private List <VideoInfo> GetVodVideoList(Category category)
        {
            List <VideoInfo> videos = new List <VideoInfo>();
            string           data   = GetWebData((category as RssLink).Url);

            if (!string.IsNullOrEmpty(data))
            {
                String thumb = null;

                //gets the thumb of the current show. Disabled for now, as the image format is too wide

                /*Match i = new Regex(@"<span>Weitere Folgen</span>.*?<img src=""(?<img>.*?)"".*?/>.*?<div class=""scrollbox"">", RegexOptions.Singleline).Match(data);
                 * if (i.Success)
                 * {
                 *  thumb = i.Groups["img"].Value;
                 * }*/

                //the main video that is shown on the category site (the newest one available)
                Match m = regEx_Videolist.Match(data);
                if (m.Success)
                {
                    VideoInfo video = new VideoInfo();
                    video.Title    = m.Groups["title"].Value;
                    video.Airdate  = m.Groups["date"].Value;
                    video.Title    = video.Title.Replace("&amp;", "&");
                    video.VideoUrl = (category as RssLink).Url;
                    video.Other    = CategoryType.VOD;
                    video.Thumb    = thumb;
                    videos.Add(video);
                }

                string cutOut = "";
                int    idx1   = data.IndexOf("<span>Weitere Folgen</span>");
                if (idx1 > -1)
                {
                    int idx2 = data.IndexOf("</div>", idx1);
                    cutOut = data.Substring(idx1, idx2 - idx1);
                    if (!string.IsNullOrEmpty(cutOut))
                    {
                        Match c = regEx_Videolist2.Match(cutOut);
                        while (c.Success)
                        {
                            String day   = c.Groups["day"].Value;
                            String items = c.Groups["items"].Value;

                            Match n = regEx_Videolist3.Match(items);
                            while (n.Success)
                            {
                                VideoInfo video = new VideoInfo();
                                video.Title    = n.Groups["title"].Value;
                                video.VideoUrl = n.Groups["url"].Value;
                                video.VideoUrl = ORF_BASE + video.VideoUrl;
                                video.Airdate  = day;
                                video.Other    = CategoryType.VOD;
                                video.Thumb    = thumb;
                                videos.Add(video);

                                n = n.NextMatch();
                            }
                            string prefix = "";
                            Match  o      = regEx_Videolist4.Match(items);
                            while (o.Success)
                            {
                                if (o.Groups["url"].Value.StartsWith("#"))
                                {
                                    prefix = o.Groups["title"].Value;
                                }
                                else
                                {
                                    VideoInfo video = new VideoInfo();
                                    video.Title    = prefix + " " + HttpUtility.HtmlDecode(o.Groups["title"].Value) + ", " + day;
                                    video.Airdate  = day;
                                    video.VideoUrl = o.Groups["url"].Value;
                                    video.VideoUrl = ORF_BASE + video.VideoUrl;
                                    video.Thumb    = thumb;
                                    video.Other    = CategoryType.VOD;

                                    //only add episode from the same show (e.g. ZiB 9, ZiB 13, ...)
                                    if (CompareEpisodes(videos[0].Title, video.Title))
                                    {
                                        videos.Add(video);
                                    }
                                }

                                o = o.NextMatch();
                            }

                            c = c.NextMatch();
                        }
                    }
                }
            }
            return(videos);
        }
Example #12
0
        public override List <String> GetMultipleVideoUrls(VideoInfo video, bool inPlaylist = false)
        {
            Log.Info("Get multiple urls: " + video.VideoUrl);
            if ((CategoryType)video.Other == CategoryType.VOD)
            {
                string data = GetWebData(video.VideoUrl);
                if (useAlternative)
                {
                    /*
                     * Alternative video urls. The tvthek also streams for Android and iOS devices.
                     * Unfortunately, currently OV can't play these formats (rtsp and m3u)
                     *
                     * Android: rtsp stream (low/medium -> 3gp, high -> mp4)
                     * iOS: http streaming (m3u)
                     */
                    List <String> returnList = new List <string>();
                    Match         m1         = regEx_VideoAlternativeSources.Match(data);
                    while (m1.Success)
                    {
                        Match m2 = regEx_VideoAlternativeFormats.Match(m1.Groups["source"].Value);
                        while (m2.Success)
                        {
                            String source     = m2.Groups["src"].Value.Replace("\\/", "/");
                            String quality    = m2.Groups["qualitystring"].Value;
                            String typeString = m2.Groups["typestring"].Value;

                            if (typeString.Equals("apple_Q4A"))
                            {
                                returnList.Add(source);
                                break;
                            }

                            m2 = m2.NextMatch();
                        }
                        m1 = m1.NextMatch();
                    }

                    return(returnList);
                }
                else
                {
                    /*
                     * The default video urls (mms stream)
                     */
                    string videoUrl = "";
                    if (!string.IsNullOrEmpty(data))
                    {
                        Match m = regEx_Playlist.Match(data);
                        if (m.Success)
                        {
                            videoUrl = m.Groups["url"].Value;
                            videoUrl = ORF_BASE + videoUrl;
                            return(Helpers.AsxUtils.ParseASX(GetWebData(videoUrl)));
                        }
                    }
                }
            }
            else
            {
                return(base.GetMultipleVideoUrls(video, inPlaylist));
            }
            return(null);
        }
Example #13
0
        /// <summary>
        /// 执行解析
        /// </summary>
        /// <param name="sourceText">富文本</param>
        /// <param name="tokens">结果</param>
        public static void Execute(string sourceText, ref List <Token> tokens)
        {
            Match match = regex.Match(sourceText);

            int position = 0;

            while (match.Success)
            {
                string preText = sourceText.Substring(position, match.Index - position);
                string tagText = match.Value;

                if (preText != "")
                {
                    //构造一个word类型的token
                    Token token = new Token();
                    tempParamStrings[0] = preText;
                    tokenParserHandlerReflectionMap["word"](ref token, tempParamStrings);
                    tokens.Add(token);
                }

                //解析这个tag
                //构造一个tag类型的token
                tempBuilder.Length = 0;
                string tagTextEx = Regex.Replace(tagText, elementString, string.Empty);
                tagTextEx = tagTextEx.Substring(1, tagTextEx.Length - 2);

                tempBuilder.Append(tagTextEx);
                tempBuilder.Append(endTail);
                tagTextEx          = tempBuilder.ToString();
                tempBuilder.Length = 0;

                string tagName    = string.Empty;
                int    paramIndex = 0;

                bool meetEqual = false;
                for (int i = 0; i < tagTextEx.Length; i++)
                {
                    char tagChar = tagTextEx[i];
                    if (!meetEqual)
                    {
                        //到了末尾也没有看到等于号,说明无参数,只有tag
                        if (tagChar == endTail)
                        {
                            tagName            = tempBuilder.ToString();
                            tempBuilder.Length = 0;
                        }
                        //看到等于号了,之前的是tag
                        else if (tagChar == equalOperator)
                        {
                            meetEqual          = true;
                            tagName            = tempBuilder.ToString();
                            tempBuilder.Length = 0;
                        }
                        else
                        {
                            tempBuilder.Append(tagChar);
                        }
                    }
                    else
                    {
                        //最后一个了,收束;遇见分隔符,也得收束
                        if (tagChar == endTail || tagChar == ',')
                        {
                            tempParamStrings[paramIndex++] = tempBuilder.ToString();
                            tempBuilder.Length             = 0;
                        }
                        else
                        {
                            tempBuilder.Append(tagChar);
                        }
                    }
                }

                if (tokenParserHandlerReflectionMap.ContainsKey(tagName))
                {
                    Token token = new Token();
                    tokenParserHandlerReflectionMap[tagName].Invoke(ref token, tempParamStrings);
                    tokens.Add(token);
                }

                position = match.Index + tagText.Length;
                match    = match.NextMatch();
            }

            if (position < sourceText.Length)
            {
                string postText = sourceText.Substring(position, sourceText.Length - position);
                if (postText.Length > 0)
                {
                    Token token = new Token();
                    tempParamStrings[0] = postText;
                    tokenParserHandlerReflectionMap["word"](ref token, tempParamStrings);
                    tokens.Add(token);
                }
            }
        }
Example #14
0
        /**
         *  Change Case
         *
         *@param  string typeOfCase
         */
        private void changeCase(string typeOfCase)
        {
            string result = textBox1.SelectedText;
            int    start  = textBox1.SelectionStart;

            if (typeOfCase == "UPPER CASE")
            {
                result = result.ToUpper();
            }
            else if (typeOfCase == "lower case")
            {
                result = result.ToLower();
            }
            else if (typeOfCase == "Title Case")
            {
                StringBuilder strB = new StringBuilder(result.ToLower());

                Regex           regex = new Regex("(?<!\\p{IsCombiningDiacriticalMarks}|\\p{L})\\p{L}"); // word boundary \\b\\w
                MatchCollection mc    = regex.Matches(result);

                // Loop through  the match collection to retrieve all
                // matches and positions.
                for (int i = 0; i < mc.Count; i++)
                {
                    int index = mc[i].Index;
                    strB[index] = Char.ToUpper(strB[index]);
                }

                result = strB.ToString();
            }
            else if (typeOfCase == "Sentence case")
            {
                StringBuilder   strB  = new StringBuilder(result.ToUpper() == result ? result.ToLower() : result);
                Regex           regex = new Regex("\\p{L}(\\p{L}+)");
                MatchCollection mc    = regex.Matches(result);

                for (Match m = regex.Match(result); m.Success; m = m.NextMatch())
                {
                    if (!(
                            m.Groups[0].Value.ToUpper() == m.Groups[0].Value ||
                            m.Groups[1].Value.ToLower() == m.Groups[1].Value
                            ))
                    {
                        for (int i = 0; i < mc.Count; i++)
                        {
                            int j = mc[i].Index;
                            strB[j] = Char.ToLower(strB[j]);
                        }
                    }
                }

                const string QUOTE = "\"'`,<>\u00AB\u00BB\u2018-\u203A";
                regex = new Regex("(?:[.?!\u203C-\u2049][])}"
                                  + QUOTE + "]*|^|\n|:\\s+["
                                  + QUOTE + "])[-=_*\u2010-\u2015\\s]*["
                                  + QUOTE + "\\[({]*\\p{L}"
                                  ); // begin of a sentence

                // Use the Matches method to find all matches in the input string.
                mc = regex.Matches(result);
                // Loop through  the match collection to retrieve all
                // matches and positions.
                for (int i = 0; i < mc.Count; i++)
                {
                    int j = mc[i].Index + mc[i].Length - 1;
                    strB[j] = Char.ToUpper(strB[j]);
                }

                result = strB.ToString();
            }
            else
            {
                return;
            }

            textBox1.SelectedText    = result;
            textBox1.SelectionStart  = start;
            textBox1.SelectionLength = result.Length;
        }
Example #15
0
        public void SetEventInfo(EpgEventInfo eventData)
        {
            try
            {
                eventInfo         = eventData;
                textBox_info.Text = CommonManager.Instance.ConvertProgramText(eventData, EventInfoTextMode.BasicOnly);
                String text = CommonManager.Instance.ConvertProgramText(eventData, EventInfoTextMode.ExtOnly);

                int       searchFrom = 0;
                Paragraph para       = new Paragraph();
                string    rtext      = CommonManager.ReplaceText(text, CommonManager.Instance.ReplaceUrlDictionary);
                if (rtext.Length == text.Length)
                {
                    for (Match m = Regex.Match(rtext, @"https?://[0-9A-Za-z!#$%&'()~=@;:?_+\-*/.]+"); m.Success; m = m.NextMatch())
                    {
                        para.Inlines.Add(text.Substring(searchFrom, m.Index - searchFrom));
                        Hyperlink h = new Hyperlink(new Run(text.Substring(m.Index, m.Length)));
                        h.MouseLeftButtonDown += new MouseButtonEventHandler(h_MouseLeftButtonDown);
                        h.Foreground           = Brushes.Blue;
                        h.Cursor      = Cursors.Hand;
                        h.NavigateUri = new Uri(m.Value);
                        para.Inlines.Add(h);
                        searchFrom = m.Index + m.Length;
                    }
                }
                para.Inlines.Add(text.Substring(searchFrom));
                richTextBox_descInfo.Document = new FlowDocument(para);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
            }
        }
Example #16
0
        public IEnumerable <LogEntry> WhileParse(string rawData)
        {
            var parsedData = new List <LogEntry>();

            Match lastMatch = _dateRegEx.Match(rawData);
            var   lastDate  = lastMatch.Value.Replace("\r\n", "");

            lastMatch = lastMatch.NextMatch();

            bool threshold = true;

            while (lastMatch.Success || threshold)
            {
                sw.Restart();
                var entry = "";
                if (lastMatch.Success)
                {
                    entry   = rawData.Substring(0, lastMatch.Index);
                    rawData = rawData.Remove(0, entry.Length);
                }
                else
                {
                    entry = rawData;
                }

                sw.Stop();
                Console.WriteLine(sw.ElapsedMilliseconds);
                DateTime dateTime;
                if (!DateTime.TryParse(lastDate, out dateTime))
                {
                    continue;
                }

                entry = entry.Remove(0, entry.IndexOf('['));

                var match = _sourceRegEx.Match(entry);

                if (!match.Success)
                {
                    continue;
                }

                var matchValue = match.Value.Trim();

                var sources = matchValue.Substring(1, match.Length - 2).Split(':');

                LogEntryLevel level;
                if (!Enum.TryParse(sources[0], true, out level))
                {
                    continue;
                }

                var message = _sourceRegEx.Replace(entry, string.Empty)
                              .TrimStart();

                parsedData.Add(new LogEntry(dateTime, level, SourceId, sources[1], message));

                if (lastMatch.Success == false)
                {
                    threshold = false;
                }
                else
                {
                    lastMatch = _dateRegEx.Match(rawData);
                    lastDate  = lastMatch.Value.Replace("\r\n", "");
                    lastMatch = lastMatch.NextMatch();
                }
            }

            return(parsedData);
        }
Example #17
0
        /// <summary>
        /// The C# version of Mark Miller。Makes the X path. Use a format like //configuration/appSettings/add[@key='name']/@value
        /// </summary>
        /// <param name="doc">The doc.</param>
        /// <param name="xpath">The xpath.</param>
        /// <returns></returns>
        public static XNode createNodeFromXPath(XElement elem, string xpath)
        {
            // Create a new Regex object
            //用正则把分割符号 / 过滤出来
            Regex r = new Regex(@"/*([a-zA-Z0-9_\.\-]+)(\[@([a-zA-Z0-9_\.\-]+)='([^']*)'\])?|/@([a-zA-Z0-9_\.\-]+)");

            xpath = xpath.Replace("\"", "'");
            // Find matches
            Match m = r.Match(xpath);

            XNode         currentNode = elem;
            StringBuilder currentPath = new StringBuilder();

            while (m.Success)
            {
                String currentXPath  = m.Groups[0].Value;   // "/configuration" or "/appSettings" or "/add"
                String elementName   = m.Groups[1].Value;   // "configuration" or "appSettings" or "add"
                String filterName    = m.Groups[3].Value;   // "" or "key"
                String filterValue   = m.Groups[4].Value;   // "" or "name"
                String attributeName = m.Groups[5].Value;   // "" or "value"

                StringBuilder builder      = currentPath.Append(currentXPath);
                String        relativePath = builder.ToString();
                XNode         newNode      = (XNode)elem.XPathSelectElement(relativePath);

                if (newNode == null)
                {
                    if (!string.IsNullOrEmpty(attributeName))
                    {
                        ((XElement)currentNode).Attribute(attributeName).Value = "";
                        newNode = (XNode)elem.XPathEvaluate(relativePath);
                    }
                    else if (!string.IsNullOrEmpty(elementName))
                    {
                        XElement newElem = new XElement(elementName);
                        if (!string.IsNullOrEmpty(filterName))
                        {
                            newElem.Add(new XAttribute(filterName, filterValue));
                        }

                        ((XElement)currentNode).Add(newElem);
                        newNode = newElem;
                    }
                    else
                    {
                        throw new FormatException("The given xPath is not supported " + relativePath);
                    }
                }

                currentNode = newNode;
                m           = m.NextMatch();
            }

            // Assure that the node is found or created
            if (elem.XPathEvaluate(xpath) == null)
            {
                throw new FormatException("The given xPath cannot be created " + xpath);
            }

            return(currentNode);
        }
        /// <summary>
        /// Method implementaion for IHistoryParser
        /// </summary>
        /// <param name="starTeamLog"></param>
        /// <returns></returns>
        public Modification[] Parse(TextReader starTeamLog, DateTime from, DateTime to)
        {
            Regex folderRegex  = new Regex(starTeamRegExProvider.FolderRegEx);
            Regex fileRegex    = new Regex(starTeamRegExProvider.FileRegEx);
            Regex historyRegex = new Regex(starTeamRegExProvider.FileHistoryRegEx);

            // Temporary holder of Modification objects
            ArrayList modList = new ArrayList();

            // Read conetent of the stream as a string
            // ASSUMPTION: entire log fits into the available memory
            String s = starTeamLog.ReadToEnd();

            // Append folder info separator at the end of the string so
            // that the regular expression engine does not miss the last
            // folder's information. This is required because of the way
            // the expression FolderRegEx is constructed.
            s += StarTeamHistoryParser.FolderInfoSeparator;

            // Parse the whole content to separate the info about each
            // folder and the files it has
            for (Match mFolder = folderRegex.Match(s); mFolder.Success; mFolder = mFolder.NextMatch())
            {
                // Working folder
                String folder = mFolder.Result("${working_directory}");

                // Scan changes for each file in the folder
                for (Match mFile = fileRegex.Match(mFolder.Value); mFile.Success; mFile = mFile.NextMatch())
                {
                    // Create a Modification object for the current file
                    Modification mod = new Modification();

                    // Set the modification attributes
                    mod.FolderName = folder;
                    mod.FileName   = mFile.Result("${file_name}");
                    mod.Type       = mFile.Result("${file_status}");

                    // Substring that contains file history. Append a new line
                    // followed by the FileHistorySeparator so that the parse
                    // engine can extract the comments for the last history
                    String fileHistory = mFile.Result("${file_history}") + "\n" +
                                         StarTeamHistoryParser.FileHistorySeparator;

                    // Only get the first match which describes the
                    // most recent changes
                    Match mHistory = historyRegex.Match(fileHistory);
                    if (mHistory.Success)
                    {
                        mod.EmailAddress = "N/A";
                        mod.UserName     = mHistory.Result("${author_name}");

                        // date_string looks like "12/9/02 10:33:36 AM"
                        // ASSUMPTION: StarTeam server and this application
                        // runs in the same TIMEZONE
                        mod.ModifiedTime = DateTime.Parse(mHistory.Result("${date_string}"), Culture.DateTimeFormat);
                        mod.Comment      = mHistory.Result("${change_comment}");
                    }
                    modList.Add(mod);
                }
            }
            return((Modification[])modList.ToArray(typeof(Modification)));
        }
Example #19
0
        /// <summary>
        /// 講義サイトからファイルをダウンロードする
        /// </summary>
        /// <param name="state">0:定期 1:手動</param>
        private void Download_DataFile(int state)
        {
            int       count    = 0;
            Regex     reg      = new Regex("<a href=\"(?<url>.*?)\".*?>(?<text>.*?)</a>", RegexOptions.IgnoreCase | RegexOptions.Singleline);
            string    anchor   = "<a href=\"(?<url>.*?)\".*?>(?<text>.*?)</a>";
            string    url      = "";
            string    htmlUrl  = "";
            string    html     = "";
            string    fileName = "";
            DateTime  dtNow    = DateTime.Now;
            WebClient wc       = new WebClient();
            Regex     re       = new Regex(anchor, RegexOptions.IgnoreCase | RegexOptions.Singleline);

            /*------------------------
            *  データベースのデータ数取得
            *  ------------------------*/
            using (global.conn = new SQLiteConnection(global.gDataSource))
            {
                try
                {
                    global.conn.Open();

                    global.sql = "select count(*) from Settings";

                    global.command = new SQLiteCommand(global.sql, global.conn);
                    global.rd      = global.command.ExecuteReader();

                    while (global.rd.Read())
                    {
                        try
                        {
                            count = int.Parse(global.rd.GetValue(0).ToString());
                        }
                        catch (Exception) { }
                    }
                }
                catch (Exception) { }
                finally
                {
                    global.conn.Close();
                }
            }

            if (count == 0)
            {
                if (state == 0)
                {
                    return;
                }
                else if (state == 1)
                {
                    MessageBox.Show(this, "講義データを登録してください", "エラー", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            /*------------------------
            *  ダウンロード処理
            *  ------------------------*/
            for (int i = 0; i < count; i++)
            {
                using (global.conn = new SQLiteConnection(global.gDataSource))
                {
                    try
                    {
                        global.conn.Open();

                        global.sql = "select * from Settings";

                        global.command = new SQLiteCommand(global.sql, global.conn);
                        global.rd      = global.command.ExecuteReader();

                        while (global.rd.Read())
                        {
                            try
                            {
                                url = global.rd.GetValue(global.URL).ToString();

                                //htmlからファイルのURLを取得
                                html = wc.DownloadString(url);

                                for (Match m = re.Match(html); m.Success; m = m.NextMatch())
                                {
                                    htmlUrl = m.Groups["url"].Value;

                                    //ダウンロード基のURL
                                    if (htmlUrl.Substring(0, 1) == ".")
                                    {
                                        htmlUrl.Remove(0, 1);
                                    }
                                    else if (htmlUrl.Substring(0, 2) == "./")
                                    {
                                        htmlUrl.Remove(0, 2);
                                    }

                                    Uri u = new Uri(global.rd.GetValue(global.URL) + htmlUrl);

                                    //保存先
                                    fileName = global.rd.GetValue(global.PATH) + Path.GetFileName(global.rd.GetValue(global.URL) + htmlUrl);

                                    //ダウンロード
                                    if (Path.GetExtension(global.rd.GetValue(global.URL) + htmlUrl) == ".pdf" || Path.GetExtension(global.rd.GetValue(global.URL) + htmlUrl) == ".ppt" || Path.GetExtension(global.rd.GetValue(global.URL) + htmlUrl) == ".pptx" || Path.GetExtension(global.rd.GetValue(global.URL) + htmlUrl) == ".doc" || Path.GetExtension(global.rd.GetValue(global.URL) + htmlUrl) == ".docx" || Path.GetExtension(global.rd.GetValue(global.URL) + htmlUrl) == ".xls" || Path.GetExtension(global.rd.GetValue(global.URL) + htmlUrl) == ".xlsx")
                                    {
                                        if (!File.Exists(fileName))
                                        {
                                            downloadClient = new System.Net.WebClient();
                                            //downloadClient.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(downloadClient_DownloadProgressChanged);
                                            //downloadClient.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(downloadClient_DownloadFileCompleted);
                                            downloadClient.DownloadFileAsync(u, fileName);
                                        }
                                    }
                                }
                            }
                            catch (Exception) { }
                        }
                    }
                    catch (Exception) { }
                    finally
                    {
                        global.conn.Close();
                    }
                }
            }

            if (System.IO.File.Exists(@"settings.ini")) //INIファイルが存在する
            {
                if (ini.getValueString("Notify", "checked") == "true")
                {
                    /*------------------------
                    *  ダウンロード完了通知
                    *  ------------------------*/
                    new Thread(
                        new ThreadStart(
                            delegate
                    {
                        Invoke(
                            (notifyDel) delegate
                        {
                            notifyIcon1.ShowBalloonTip(5000, "お知らせ", "講義資料のダウンロードが完了しました\r\n" + dtNow.ToString(), ToolTipIcon.Info);
                        }
                            );
                    }
                            )
                        ).Start();
                }
            }
            downloadClient = null;
        }
Example #20
0
    public static void Main()
    {
        //if we need a ref to the active project
        if (Program.ActiveProjectShell == null)
        {
            return;
        }
        SwissAcademic.Citavi.Project activeProject = Program.ActiveProjectShell.Project;

        if (activeProject == null)
        {
            DebugMacro.WriteLine("No active project.");
            return;
        }

        /*if this macro should ALWAYS affect all titles in active project, choose first option
         * if this macro should affect just filtered rows if there is a filter applied and ALL if not, choose second option
         * if this macro should affect just selected rows, choose third option */

        //ProjectReferenceCollection references = Program.ActiveProjectShell.Project.References;
        //List<Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetFilteredReferences();
        List <Reference> references = Program.ActiveProjectShell.PrimaryMainForm.GetSelectedReferences();

        if (references == null || !references.Any())
        {
            DebugMacro.WriteLine("No references selected.");
            return;
        }

        int countNotProvisional = 0;
        int countProvisional    = 0;
        int countReferences     = 0;

        foreach (Reference reference in references)
        {
            countReferences = countReferences + 1;

            string budgetCode     = "Budget?";
            string specialistName = "Michael Freiberg";
            string edition        = "p";
            string price          = "? €";
            string taskType       = "?";
            string orderNote      = "-";
            string normalizedISBN = reference.Isbn.Isbn13.ToString();
            string buchhandelURL  = "https://www.buchhandel.de/jsonapi/products?filter[products][query]=(is=" + normalizedISBN + ")";

            // Get availability information of the title from "buchhandel.de"
            try {
                Cursor.Current = Cursors.WaitCursor;

                DebugMacro.WriteLine("Getting availability information from " + buchhandelURL);
                WebClient client = new WebClient();
                client.Headers["Accept"] = "application/vnd.api+json";
                var jsonString = client.DownloadString(buchhandelURL);
                // DebugMacro.WriteLine(jsonString);


                // Get budget code from groups
                List <SwissAcademic.Citavi.Group> refGroups = reference.Groups.ToList();

                foreach (SwissAcademic.Citavi.Group refGroup in refGroups)
                {
                    Match match = Regex.Match(refGroup.Name, @"budget\:\s*(.+)", RegexOptions.IgnoreCase);
                    if (match.Success)
                    {
                        budgetCode = match.Groups[1].Value;
                    }
                }

                // Quick and dirty extraction of price information via RegEx.
                // Parsing of JSON response would be preferred, but I could not handle
                // the concepts of System.Runtime.Serialization and System.Runtime.Serialization.Json;



                // Get first match. Book price in Austria.
                Match matchPrice = Regex.Match(jsonString, @"\""value\""\:(\d+\.\d+)");
                if (matchPrice.Success)
                {
                    var priceAT = matchPrice.Groups[1].Value;
                    // DebugMacro.WriteLine(priceAT);
                }

                // Get second match. Book price in Germany.
                matchPrice = matchPrice.NextMatch();
                if (matchPrice.Success)
                {
                    var priceDE = matchPrice.Groups[1].Value;
                    price = Regex.Replace(priceDE, @"\.", ",") + " €";
                    // DebugMacro.WriteLine(priceDE);
                }

                Match matchAvail = Regex.Match(jsonString, @"\""provisional\""\:true");
                if (matchAvail.Success)
                {
                    reference.Groups.Add("Noch nicht erschienen");
                    countProvisional = countProvisional + 1;
                }
                else
                {
                    countNotProvisional = countNotProvisional + 1;

                    foreach (SwissAcademic.Citavi.Group refGroup in refGroups)
                    {
                        Match match = Regex.Match(refGroup.Name, @"Noch nicht erschienen", RegexOptions.IgnoreCase);
                        if (match.Success)
                        {
                            reference.Groups.Remove(refGroup);
                        }
                    }

                    taskType  = "Bestellen";
                    orderNote = "Verfügbar. " + edition + " " + price;


                    TaskItem order = reference.Tasks.Add(taskType);

                    // Assign specialist.
                    ContactInfo taskAssignee = activeProject.Contacts.GetMembers().FirstOrDefault <ContactInfo>(item => item.FullName.Equals(specialistName));
                    if (taskAssignee == null)
                    {
                        DebugMacro.WriteLine("No such contact.");
                        return;
                    }
                    order.AssignedTo = taskAssignee.Key;

                    order.Notes = orderNote;
                }
            }
            catch (Exception e) {
                Cursor.Current = Cursors.Default;
                DebugMacro.WriteLine("Could not read file from " + buchhandelURL + ": " + e.Message);
                return;
            }
        }

        // Message upon completion
        string message = "{0} Titel wurden geprüft. {1} sind noch nicht erschienen. {2} sind lieferbar.";

        message = string.Format(message, countReferences.ToString(), countProvisional.ToString(), countNotProvisional.ToString());
        MessageBox.Show(message, "Bericht", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
Example #21
0
        /// <summary>
        /// Splits the given string into an array of strings by separating the string into substrings.
        /// </summary>
        /// <param name="input"> The string to split. </param>
        /// <param name="limit"> The maximum number of array items to return.  Defaults to unlimited. </param>
        /// <returns> An array containing the split strings. </returns>
        public ArrayInstance Split(string input, [DefaultParameterValue(uint.MaxValue)] uint limit = uint.MaxValue)
        {
            // Return an empty array if limit = 0.
            if (limit == 0)
            {
                return(this.Engine.Array.New(new object[0]));
            }

            // Find the first match.
            Match match = this.value.Match(input, 0);

            var   results    = new List <object>();
            int   startIndex = 0;
            Match lastMatch  = null;

            while (match.Success == true)
            {
                // Do not match the an empty substring at the start or end of the string or at the
                // end of the previous match.
                if (match.Length == 0 && (match.Index == 0 || match.Index == input.Length || match.Index == startIndex))
                {
                    // Find the next match.
                    match = match.NextMatch();
                    continue;
                }

                // Add the match results to the array.
                results.Add(input.Substring(startIndex, match.Index - startIndex));
                if (results.Count >= limit)
                {
                    return(this.Engine.Array.New(results.ToArray()));
                }
                startIndex = match.Index + match.Length;
                for (int i = 1; i < match.Groups.Count; i++)
                {
                    var group = match.Groups[i];
                    if (group.Captures.Count == 0)
                    {
                        results.Add(Undefined.Value);       // Non-capturing groups return "undefined".
                    }
                    else
                    {
                        results.Add(match.Groups[i].Value);
                    }
                    if (results.Count >= limit)
                    {
                        return(this.Engine.Array.New(results.ToArray()));
                    }
                }

                // Record the last match.
                lastMatch = match;

                // Find the next match.
                match = match.NextMatch();
            }
            results.Add(input.Substring(startIndex, input.Length - startIndex));

            // Set the deprecated RegExp properties.
            if (lastMatch != null)
            {
                this.Engine.RegExp.SetDeprecatedProperties(input, lastMatch);
            }

            return(this.Engine.Array.New(results.ToArray()));
        }
Example #22
0
        public void GetMovieInfo(MovieRule r, MovieInfo m, string InfoUrl)
        {
            red();
            w(string.Format("打开电影《{0}》的信息页:{1}", m.Title, InfoUrl));
            string html = Url.GetHtml(InfoUrl, r.Encoding);

            using (kuaiboyingshiEntities ent = new kuaiboyingshiEntities())
            {
                string short_title = m.Title.TrimEnd('.');
                var    movies      = (from l in ent.MovieInfo where l.Title.Contains(short_title) select l).ToList();
                Match  match       = html.GetMatchGroup(r.InfoRule);
                if (movies.Count == 0)
                {
                    if (!match.Success)
                    {
                        w("这个电影无法和规则匹配\n ");
                        return;
                    }



                    m.ClassName  = m.ClassName.IsNull(match.Groups["class"].Value).IsNull("其他");
                    m.Title      = match.Groups["title"].Value;
                    m.Location   = m.Title.IsNull(match.Groups["location"].Value);
                    m.PublicYear = m.PublicYear.IsNull(match.Groups["publicyear"].Value).IsNull("2012");;
                    m.Actors     = m.Actors.IsNull(match.Groups["actors"].Value).TrimHTML();
                    m.Director   = m.Director.IsNull(match.Groups["director"].Value);
                    m.Info       = m.Info.IsNull(match.Groups["intro"].Value).Replace(r.SiteName, "");
                    m.Intro      = m.Intro.IsNull(match.Groups["intro"].Value).Replace(r.SiteName, "");

                    m.FaceImage = m.FaceImage.IsNull(match.Groups["image"].Value.AppendToDomain(InfoUrl));

                    m.Status         = 0;
                    m.ClassID        = GetClassByName(m.ClassName).ID;
                    m.ClickCount     = 0;
                    m.DayClick       = 0;
                    m.UpdateTime     = DateTime.Now;
                    m.InsertTime     = DateTime.Now;
                    m.IsMove         = false;
                    m.LastClickTime  = DateTime.Now;
                    m.LastDramaID    = 0;
                    m.LastDramaTitle = "";
                    m.MonthClick     = 0;
                    m.ReplyCount     = 0;
                    m.ScoreAvg       = 0;
                    m.ScoreTime      = 0;
                    m.StandardTitle  = StandTitle(m.Title);
                    m.Enable         = true;
                    if ((from l in ent.MovieInfo where l.Title == m.Title select l).Count() > 0)
                    {
                        w(string.Format("电影:{0}  类型:{1}  地区:{2}  年代:{3}  演员:{4}  导演:{5}", m.Title, m.ClassName, m.Location, m.PublicYear, m.Actors, m.Director));
                        ent.AddToMovieInfo(m);

                        w("保存电影信息...");
                        ent.SaveChanges();

                        if (!m.FaceImage.IsNullOrEmpty())
                        {
                            w("设置封面");

                            SaveFace(m.FaceImage, m.id);
                            m.FaceImage = string.Format("/u/MovieFace/{0}.jpg", m.id);
                            w("保存封面...");
                            ent.SaveChanges();
                        }
                    }
                }
                else
                {
                    string imageUrl = m.FaceImage.IsNull(match.Groups["image"].Value.AppendToDomain(InfoUrl));
                    m = movies.FirstOrDefault();
                    if (m.FaceImage.IsNullOrEmpty())
                    {
                        SaveFace(imageUrl, m.id);
                    }
                }



                //获取百度和快播区域并且开始采集

                #region 百度区域
                yellow();
                Match m_baiduarea = html.GetMatchGroup(r.BaiduAreaRule);
                if (m_baiduarea.Success && !r.BaiduAreaRule.IsNullOrEmpty())
                {
                    w("分析百度区域");
                    Match m_drama = m_baiduarea.Groups["key"].Value.GetMatchGroup(r.BaiduDramaRule);
                    while (m_drama.Success)
                    {
                        string title   = m_drama.Groups["title"].Value;
                        string playurl = m_drama.Groups["playurl"].Value;
                        string url     = m_drama.Groups["url"].Value;

                        #region 打开播放页面处理
                        if (url.IsNullOrEmpty())
                        {
                            CollectBaiduMovie(m, r, playurl.AppendToDomain(InfoUrl), title);
                            if (!r.SourceBaiduRule.IsNullOrEmpty())
                            {
                                break;
                            }
                        }
                        #endregion

                        else
                        {
                            var dramas = (from l in ent.MovieUrlBaidu where l.MovieID == m.id && l.Title == title select l);
                            if (dramas.Count() == 0)
                            {
                                w(string.Format("在信息页面得到地址:{0}", url));
                                ent.AddToMovieUrlBaidu(new MovieUrlBaidu()
                                {
                                    Enable     = true,
                                    MovieID    = m.id,
                                    MovieTitle = m.Title,
                                    Title      = title,
                                    UpdateTime = DateTime.Now,
                                    Url        = url
                                });
                                m.UpdateTime     = DateTime.Now;
                                m.LastDramaTitle = title;
                                w("保存");
                                ent.SaveChanges();
                            }
                        }

                        m_drama = m_drama.NextMatch();
                    }
                }
                #endregion

                #region 快播区域
                Match m_kuaiboarea = html.GetMatchGroup(r.KuaibAreaRule);
                if (m_kuaiboarea.Success && !r.KuaibAreaRule.IsNullOrEmpty())
                {
                    w("分析快播区域");
                    Match m_drama = m_kuaiboarea.Groups["key"].Value.GetMatchGroup(r.KuaibDramaRule);
                    while (m_drama.Success)
                    {
                        string title   = m_drama.Groups["title"].Value.IsNull("全集");
                        string playurl = m_drama.Groups["playurl"].Value;
                        string url     = m_drama.Groups["url"].Value;

                        #region 打开播放页面处理
                        if (url.IsNullOrEmpty())
                        {
                            CollectKuaiboMovie(m, r, playurl.AppendToDomain(InfoUrl), title);
                            if (!r.SourceKuaibRule.IsNullOrEmpty())
                            {
                                break;
                            }
                        }
                        #endregion

                        else
                        {
                            var dramas = (from l in ent.MovieUrlKuaib where l.MovieID == m.id && l.Title == title select l);
                            if (dramas.Count() == 0)
                            {
                                w(string.Format("在信息页面得到地址:{0}", url));
                                ent.AddToMovieUrlKuaib(new MovieUrlKuaib()
                                {
                                    Enable     = true,
                                    MovieID    = m.id,
                                    MovieTitle = m.Title,
                                    Title      = title,
                                    UpdateTime = DateTime.Now,
                                    Url        = url
                                });
                                m.UpdateTime     = DateTime.Now;
                                m.LastDramaTitle = title;

                                w("保存");
                                ent.SaveChanges();
                            }
                        }

                        m_drama = m_drama.NextMatch();
                    }
                }
                #endregion
            }
        }
Example #23
0
        public void Fix(Subtitle subtitle, IFixCallbacks callbacks)
        {
            var    language  = Configuration.Settings.Language.FixCommonErrors;
            string fixAction = language.FixUppercaseIInsideLowercaseWord;
            int    uppercaseIsInsideLowercaseWords = 0;

            for (int i = 0; i < subtitle.Paragraphs.Count; i++)
            {
                Paragraph p       = subtitle.Paragraphs[i];
                string    oldText = p.Text;

                Match match = ReAfterLowercaseLetter.Match(p.Text);
                while (match.Success)
                {
                    if (!(match.Index > 1 && p.Text.Substring(match.Index - 1, 2) == "Mc") && // irish names, McDonalds etc.
                        p.Text[match.Index + 1] == 'I' &&
                        callbacks.AllowFix(p, fixAction))
                    {
                        p.Text = p.Text.Substring(0, match.Index + 1) + "l";
                        if (match.Index + 2 < oldText.Length)
                        {
                            p.Text += oldText.Substring(match.Index + 2);
                        }

                        uppercaseIsInsideLowercaseWords++;
                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                    }
                    match = match.NextMatch();
                }

                var st = new StrippableText(p.Text);
                match = ReBeforeLowercaseLetter.Match(st.StrippedText);
                while (match.Success)
                {
                    string word = GetWholeWord(st.StrippedText, match.Index);
                    if (!callbacks.IsName(word))
                    {
                        if (callbacks.AllowFix(p, fixAction))
                        {
                            if (word.Equals("internal", StringComparison.OrdinalIgnoreCase) ||
                                word.Equals("island", StringComparison.OrdinalIgnoreCase) ||
                                word.Equals("islands", StringComparison.OrdinalIgnoreCase))
                            {
                            }
                            else if (match.Index == 0)
                            {  // first letter in paragraph
                               //too risky! - perhaps if periods is fixed at the same time... or too complicated!?
                               //if (isLineContinuation)
                               //{
                               //    st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
                               //    p.Text = st.MergedString;
                               //    uppercaseIsInsideLowercaseWords++;
                               //    AddFixToListView(p, fixAction, oldText, p.Text);
                               //}
                            }
                            else
                            {
                                if (match.Index > 2 && st.StrippedText[match.Index - 1] == ' ')
                                {
                                    if ((Utilities.AllLettersAndNumbers + @",").Contains(st.StrippedText[match.Index - 2]) &&
                                        match.Length >= 2 && Utilities.LowercaseVowels.Contains(char.ToLower(match.Value[1])))
                                    {
                                        st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
                                        p.Text          = st.MergedString;
                                        uppercaseIsInsideLowercaseWords++;
                                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                                    }
                                }
                                else if (match.Index > Environment.NewLine.Length + 1 && Environment.NewLine.Contains(st.StrippedText[match.Index - 1]))
                                {
                                    if ((Utilities.AllLettersAndNumbers + @",").Contains(st.StrippedText[match.Index - Environment.NewLine.Length + 1]) &&
                                        match.Length >= 2 && Utilities.LowercaseVowels.Contains(match.Value[1]))
                                    {
                                        st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
                                        p.Text          = st.MergedString;
                                        uppercaseIsInsideLowercaseWords++;
                                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                                    }
                                }
                                else if (match.Index > 1 && ((st.StrippedText[match.Index - 1] == '\"') || (st.StrippedText[match.Index - 1] == '\'') ||
                                                             (st.StrippedText[match.Index - 1] == '>') || (st.StrippedText[match.Index - 1] == '-')))
                                {
                                }
                                else
                                {
                                    var before = '\0';
                                    var after  = '\0';
                                    if (match.Index > 0)
                                    {
                                        before = st.StrippedText[match.Index - 1];
                                    }
                                    if (match.Index < st.StrippedText.Length - 2)
                                    {
                                        after = st.StrippedText[match.Index + 1];
                                    }
                                    if (before != '\0' && char.IsUpper(before) && after != '\0' && char.IsLower(after) &&
                                        !Utilities.LowercaseVowels.Contains(char.ToLower(before)) && !Utilities.LowercaseVowels.Contains(after))
                                    {
                                        st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "i");
                                        p.Text          = st.MergedString;
                                        uppercaseIsInsideLowercaseWords++;
                                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                                    }
                                    else if (@"‘’¡¿„“()[]♪'. @".Contains(before) && !Utilities.LowercaseVowels.Contains(char.ToLower(after)))
                                    {
                                    }
                                    else
                                    {
                                        st.StrippedText = st.StrippedText.Remove(match.Index, 1).Insert(match.Index, "l");
                                        p.Text          = st.MergedString;
                                        uppercaseIsInsideLowercaseWords++;
                                        callbacks.AddFixToListView(p, fixAction, oldText, p.Text);
                                    }
                                }
                            }
                        }
                    }
                    match = match.NextMatch();
                }
            }
            callbacks.UpdateFixStatus(uppercaseIsInsideLowercaseWords, language.FixUppercaseIInsindeLowercaseWords, language.XUppercaseIsFoundInsideLowercaseWords);
        }
Example #24
0
        private void btnPreview_Click(object sender, EventArgs e)
        {
            var dgv = dataGridView1;

            if (dgv.Rows.Count <= 0)
            {
                MessageBox.Show("列表还没文件,搞清楚啊");
                return;
            }
            string rule = textBox1.Text.Trim();

            if (rule.Length == 0)
            {
                MessageBox.Show("规则还没写呢,搞清楚啊");
                return;
            }

            int   idx = 1;
            Regex reg = new Regex(@"\[o(\d+)-(\d+)\]");

            foreach (DataGridViewRow row in dgv.Rows)
            {
                //重命名说明:[o]为原名,[o2-5]为原名第2~5个字符,[d]为1开始的序号,[p]为拍照日期
                string newname   = rule;
                string oldname   = Convert.ToString(row.Cells[1].Value);
                string phototime = Regex.Replace(Convert.ToString(row.Cells[6].Value), @"[_\-\\\/\s:]", "");

                newname = newname.Replace("[o]", oldname);
                newname = newname.Replace("[d]", idx.ToString());
                newname = newname.Replace("[p]", phototime);
                newname = newname.Replace("[e]", Path.GetExtension(oldname));

                // 取原名某几个字符的代码
                Match match = reg.Match(newname);
                while (match.Success)
                {
                    int start = int.Parse(match.Groups[1].Value);
                    if (start <= 0)
                    {
                        start = 1;
                    }
                    int end = int.Parse(match.Groups[2].Value);
                    if (end <= start)
                    {
                        MessageBox.Show("结束值要大于开始值啊:" + match.Value);
                        return;
                    }
                    string cutstr;
                    if (start > oldname.Length)
                    {
                        cutstr = "";
                    }
                    else
                    {
                        if (end >= oldname.Length)
                        {
                            end = oldname.Length;
                        }
                        cutstr = oldname.Substring(start - 1, end - start + 1);
                    }
                    newname = reg.Replace(newname, cutstr);
                    match   = match.NextMatch();
                }

                row.Cells[9].Value = newname;
                idx++;
            }
            btnSave.Enabled = true;
        }
Example #25
0
        /// <summary>
        /// Parses the header.
        /// </summary>
        /// <param name="header">The header.</param>
        public static void ParseHeader(ref Header header)
        {
#if !PocketPC
            string hdr = Encoding.GetEncoding("iso-8859-1").GetString(header.OriginalData, 0, header.OriginalData.Length);
#else
            string hdr = Pop3Client.PPCEncode.GetString(header.OriginalData, 0, header.OriginalData.Length);
#endif
            hdr = Regex.Match(hdr, @"[\s\S]+?((?=\r?\n\r?\n)|\Z)").Value;
            hdr = Unfold(hdr);
            //hdr = hdr);
            Match m = Regex.Match(hdr, @"(?<=((\r?\n)|\n)|\A)\S+:(.|(\r?\n[\t ]))+(?=((\r?\n)\S)|\Z)");
            while (m.Success)
            {
                string name  = FormatFieldName(m.Value.Substring(0, m.Value.IndexOf(':')));
                string value = Codec.RFC2047Decode(m.Value.Substring(m.Value.IndexOf(":") + 1)).Trim('\r', '\n').TrimStart(' ');
                if (name.Equals("received"))
                {
                    header.Trace.Add(ParseTrace(m.Value.Trim(' ')));
                }
                else if (name.Equals("to"))
                {
                    header.To = ParseAddresses(value);
                }
                else if (name.Equals("cc"))
                {
                    header.Cc = ParseAddresses(value);
                }
                else if (name.Equals("bcc"))
                {
                    header.Bcc = ParseAddresses(value);
                }
                else if (name.Equals("reply-to"))
                {
                    header.ReplyTo = ParseAddress(value);
                }
                else if (name.Equals("from"))
                {
                    header.From = ParseAddress(value);
                }
                else if (name.Equals("sender"))
                {
                    header.Sender = ParseAddress(value);
                }
                else if (name.Equals("content-type"))
                {
                    header.ContentType = GetContentType(m.Value);
                }
                else if (name.Equals("content-disposition"))
                {
                    header.ContentDisposition = GetContentDisposition(m.Value);
                }
                //else
                //{
                header.HeaderFields.Add(name, value);
                header.HeaderFieldNames.Add(name, m.Value.Substring(0, m.Value.IndexOf(':')));
                //}
                m = m.NextMatch();

                if (HeaderFieldParsing != null)
                {
                    HeaderFieldParsing(null, header);
                }
            }
        }
Example #26
0
        void AnalyzeGoodsPaoPao(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, int iPage)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                Match match = Regex.Match(strContent, "产品描述</a></div>(.+?)报价时间");

                int    match_num  = 0;          //总共匹配到的数量
                string matchValue = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;         //获取匹配到的字符串
                    //"><textarea id="txtRemark384380
                    goodModify.strNo = GetKeyString(matchValue, "productInfoChanged('", "'");
                    string strPrice = GetKeyString(matchValue,
                                                   string.Format("class=\"currentPrice\" value=\""),
                                                   "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);


                    goodModify.strNoEx = GetKeyString(matchValue,
                                                      string.Format("id=\"txtProductName{0}\" value=\"", goodModify.strNo),
                                                      "\"");// +"    " + iPage.ToString();
                    goodModify.strName = goodModify.strNoEx;


                    //获取最高和最低价格
                    string strData = string.Format("action=getLimitPrice&productId={0}", goodModify.strNo);
                    try
                    {
                        string strRet = m_webPost.GetHttpPage("http://my.shop.pcpop.com/Handler/Price/Price.ashx",
                                                              "gb2312", "post", "", strData,
                                                              "",
                                                              "*/*", "");
                        //{type:"2",res:"620 - 930 "}
                        if (strRet.IndexOf("res:\"") < 0)
                        {
                            goodModify.fLowPrice = goodModify.fHighPrice = goodModify.fPrice;
                        }
                        else
                        {
                            strRet   = strRet.Substring(strRet.IndexOf("res:\""));
                            strPrice = GetKeyString(strRet,
                                                    "res:\"",
                                                    " -");
                            float.TryParse(strPrice, out goodModify.fLowPrice);
                            strPrice = GetKeyString(strRet,
                                                    " - ",
                                                    " ");
                            float.TryParse(strPrice, out goodModify.fHighPrice);
                        }
                    }
                    catch (System.Exception ex)
                    {
                    }
                    //string strPageNum =
                    match_num++;                //匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {
            }
        }
Example #27
0
        public virtual List <Token> Tokenize(string storyText)
        {
            List <Token> tokens = new List <Token>();

            string pattern = @"\{.*?\}";
            Regex  myRegex = new Regex(pattern);

            Match m = myRegex.Match(storyText);   // m is the first match

            int position = 0;

            while (m.Success)
            {
                // Get bit leading up to tag
                string preText = storyText.Substring(position, m.Index - position);
                string tagText = m.Value;

                if (preText != "")
                {
                    AddWordsToken(tokens, preText);
                }
                AddTagToken(tokens, tagText);

                position = m.Index + tagText.Length;
                m        = m.NextMatch();
            }

            if (position < storyText.Length)
            {
                string postText = storyText.Substring(position, storyText.Length - position);
                if (postText.Length > 0)
                {
                    AddWordsToken(tokens, postText);
                }
            }

            // Remove all leading whitespace & newlines after a {c} or {wc} tag
            // These characters are usually added for legibility when editing, but are not
            // desireable when viewing the text in game.
            bool trimLeading = false;

            foreach (Token token in tokens)
            {
                if (trimLeading &&
                    token.type == TokenType.Words)
                {
                    token.paramList[0] = token.paramList[0].TrimStart(' ', '\t', '\r', '\n');
                }

                if (token.type == TokenType.Clear ||
                    token.type == TokenType.WaitForInputAndClear)
                {
                    trimLeading = true;
                }
                else
                {
                    trimLeading = false;
                }
            }

            return(tokens);
        }
Example #28
0
        void AnalyzeGoods(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, int iPage)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                strContent = strContent.Replace("\t", "");
                Match match = Regex.Match(strContent, "<i>商品型号:</i>(.+?)删除商品");

                int    match_num  = 0;          //总共匹配到的数量
                string matchValue = "";
                string strPrice   = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;         //获取匹配到的字符串


                    goodModify.strNo = GetKeyString(matchValue, "\"down_limit_", "\"");
                    if (matchValue.IndexOf("自定义商品") > 0)
                    {
                        //索尼爱立信 XPERIA E15i(自定义商品)
                        goodModify.fHighPrice = 100000;
                        goodModify.fLowPrice  = 0;
                        goodModify.strNoEx    = matchValue.Substring(0, matchValue.IndexOf("</div>"));
                    }
                    else
                    {
                        strPrice = GetKeyString(matchValue,
                                                string.Format("id=\"down_limit_{0}\" type=\"hidden\" value=\"", goodModify.strNo),
                                                "\"");
                        float.TryParse(strPrice, out goodModify.fLowPrice);
                        strPrice = GetKeyString(matchValue,
                                                string.Format("id=\"up_limit_{0}\" type=\"hidden\" value=\"", goodModify.strNo),
                                                "\"");
                        float.TryParse(strPrice, out goodModify.fHighPrice);

                        // +"    " + iPage.ToString();
                        goodModify.strNoEx = GetKeyString(matchValue,
                                                          "target=\"_blank\">",
                                                          "</a>");
                    }
                    strPrice = GetKeyString(matchValue,
                                            string.Format("id=\"retailPrice{0}\" type=\"text\" value=\"", goodModify.strNo),
                                            "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);
                    goodModify.strName = GetKeyString(matchValue,
                                                      string.Format("id=\"title{0}\" type=\"text\" value=\"", goodModify.strNo),
                                                      "\"");
                    //string strPageNum =
                    match_num++;                //匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {
            }
        }
    /*ストリーム情報から正規表現を利用して文字列を抽出する*/
    private string XML_search(string stream)
    {
        string tmp = string.Empty;

        //Debug.Log ("Stream: " + stream.ToString());
        //正規表現
        xml_data = new Regex(regular);
        //初回抽出(NextMatch()を使うため)
        sampling = xml_data.Match(stream);
        while(sampling.Success){//最後まで抽出
            //結合処理
            for(int i = 1;i<sampling.Groups.Count;i++){//なぜかi = 1にしたらうまく行った
                tmp += sampling.Groups[i].Value;
                //!changed part!
                    tmp += " ";
            }
            //順次抽出していく
            sampling = sampling.NextMatch();
        }
        //最終的に結合した文字列を返す
        return tmp;
    }
Example #30
0
        public static string DecodeJsonResponse(string jsonResponse)
        {
            // Convert unicode style character to string.
            // Then, convert to their unescaped form.

            Hashtable CharTable = new Hashtable();

            Regex unicodeExpression = new Regex(@"(\\u){1}[0-9a-fA-F]{4}");

            for (Match matchedUniCode = unicodeExpression.Match(jsonResponse); matchedUniCode.Success; matchedUniCode = matchedUniCode.NextMatch())
            {
                string unicodeValue = matchedUniCode.Groups[0].Value.Replace(@"\u", "");

                if (!CharTable.ContainsKey(unicodeValue))
                {
                    char[] charArray = unicodeValue.ToCharArray();
                    int    intValue1 = Convert.ToByte(charArray[0].ToString(), 16) * 16 + Convert.ToByte(charArray[1].ToString(), 16);
                    int    intValue2 = Convert.ToByte(charArray[2].ToString(), 16) * 16 + Convert.ToByte(charArray[3].ToString(), 16);

                    string encodedValue = Encoding.Unicode.GetString(new byte[] { (byte)intValue2, (byte)intValue1 });

                    CharTable.Add(unicodeValue, encodedValue);
                }
            }

            string result = jsonResponse;

            foreach (string key in CharTable.Keys)
            {
                result = result.Replace("\\u" + key, CharTable[key].ToString());
            }

            return(Regex.Unescape(result));
        }
 public static void VerifyMatches(Match match, CaptureData[] expected)
 {
     for (int i = 0; match.Success; i++, match = match.NextMatch())
     {
         VerifyMatch(match, expected[i]);
     }
 }
Example #32
0
        // ignores the website projects, in the websiteProjectInfos
        void ParseProjectConfigurationPlatforms(string section, Dictionary <Guid, ProjectInfo> projectInfos,
                                                Dictionary <Guid, ProjectInfo> websiteProjectInfos)
        {
            List <Guid> missingGuids = new List <Guid> ();
            Match       projectConfigurationPlatform = projectConfigurationActiveCfgRegex.Match(section);

            while (projectConfigurationPlatform.Success)
            {
                Guid        guid = new Guid(projectConfigurationPlatform.Groups[1].Value);
                ProjectInfo projectInfo;
                if (!projectInfos.TryGetValue(guid, out projectInfo))
                {
                    if (!missingGuids.Contains(guid))
                    {
                        if (!websiteProjectInfos.ContainsKey(guid))
                        {
                            // ignore website projects
                            RaiseWarning(0, string.Format("Failed to find project {0}", guid));
                        }
                        missingGuids.Add(guid);
                    }
                    projectConfigurationPlatform = projectConfigurationPlatform.NextMatch();
                    continue;
                }
                string solConf  = projectConfigurationPlatform.Groups[2].Value;
                string solPlat  = projectConfigurationPlatform.Groups[3].Value;
                string projConf = projectConfigurationPlatform.Groups[4].Value;
                string projPlat = projectConfigurationPlatform.Groups[5].Value;
                // hack, what are they doing here?
                if (projPlat == "Any CPU")
                {
                    projPlat = "AnyCPU";
                }
                projectInfo.TargetMap.Add(new TargetInfo(solConf, solPlat), new TargetInfo(projConf, projPlat));
                projectConfigurationPlatform = projectConfigurationPlatform.NextMatch();
            }
            Match projectConfigurationPlatformBuild = projectConfigurationBuildRegex.Match(section);

            while (projectConfigurationPlatformBuild.Success)
            {
                Guid        guid = new Guid(projectConfigurationPlatformBuild.Groups[1].Value);
                ProjectInfo projectInfo;
                if (!projectInfos.TryGetValue(guid, out projectInfo))
                {
                    if (!missingGuids.Contains(guid))
                    {
                        RaiseWarning(0, string.Format("Failed to find project {0}", guid));
                        missingGuids.Add(guid);
                    }
                    projectConfigurationPlatformBuild = projectConfigurationPlatformBuild.NextMatch();
                    continue;
                }
                string solConf  = projectConfigurationPlatformBuild.Groups[2].Value;
                string solPlat  = projectConfigurationPlatformBuild.Groups[3].Value;
                string projConf = projectConfigurationPlatformBuild.Groups[4].Value;
                string projPlat = projectConfigurationPlatformBuild.Groups[5].Value;
                // hack, what are they doing here?
                if (projPlat == "Any CPU")
                {
                    projPlat = "AnyCPU";
                }
                projectInfo.TargetMap[new TargetInfo(solConf, solPlat)] = new TargetInfo(projConf, projPlat, true);
                projectConfigurationPlatformBuild = projectConfigurationPlatformBuild.NextMatch();
            }
        }