예제 #1
0
        public static MatchCollection GetCollection(int matchId)
        {
            MatchCollection tempList = null;
            using (SqlConnection myConnection = new SqlConnection(AppConfiguration.ConnectionString))
            {
                using (SqlCommand myCommand = new SqlCommand("usp_GetMatch", myConnection))
                {
                    myCommand.CommandType = CommandType.StoredProcedure;
                    myCommand.Parameters.AddWithValue("@QueryId", 30);
                    myCommand.Parameters.AddWithValue("@MatchId", matchId);

                    myConnection.Open();
                    using (SqlDataReader myReader = myCommand.ExecuteReader())
                    {
                        if (myReader.HasRows)
                        {
                            tempList = new MatchCollection();
                            while (myReader.Read())
                            {
                                tempList.Add(FillDataRecord(myReader));
                            }
                        }
                        myReader.Close();
                    }

                }
            }
            return tempList;
        }
예제 #2
0
        public MatchCollection TokenizeBody(Session s)
        {
            MatchCollection mc = new MatchCollection();
            int offsetCount = 0;

            string body = s.Request.GetBodyEncodedAs(Encoding.UTF8);

            string[] paramaters = body.Split('&');

            foreach (string param in paramaters) {
                string[] rawParams = param.Split('=');
                if (rawParams.Length == 0 || rawParams.Length > 2) throw new ArgumentException();
                // if the length is equal to two then we have a name value pair.. otherwise we have a "single" param.
                if (rawParams.Length == 2) {
                    //then add the value as a token along with it's offset..
                    offsetCount += rawParams[0].Length + 1;
                    mc.Add(new BodyMatch(new Token(rawParams[1]), offsetCount, s.Id));
                    offsetCount += rawParams[1].Length + 1;
                } else {
                    //offset = offsetCount;
                    //add the token..
                    mc.Add(new BodyMatch(new Token(rawParams[0]), offsetCount, s.Id));
                    offsetCount += rawParams[0].Length + 1;//the plus one is for the & symbol..
                }
            }
            return mc;
        }
 private static void IncrementOccuranceCountTrie( TrieNode start, MatchCollection allWords)
 {
     foreach (var word in allWords)
         {
             start.AddOccuranceIfExists(start, word.ToString());
         }
 }
예제 #4
0
		public GrammarMatch(Grammar grammar, Scanner scanner, int index, int length, MatchCollection matches, int errorIndex, int childErrorIndex, IEnumerable<Parser> errors)
			: base(grammar.Name, grammar, scanner, index, length, matches)
		{
			this.errors = errors;
			this.ErrorIndex = errorIndex;
			this.ChildErrorIndex = childErrorIndex;
		}
        public MatchCollection TokenizeQueryString(Session s)
        {
            MatchCollection mc = new MatchCollection();
            int offsetCount = 0;

            string rawQueryString = s.Request.Path;

            string[] tmp = rawQueryString.Split('?');
            if (tmp.Length < 2) throw new ArgumentException();

            //Keep track of the offset. (+1 for the ?)
            offsetCount += tmp[0].Length + 1;

            string[] paramaters = tmp[1].Split('&');

            foreach (string param in paramaters) {
                string[] rawParams = param.Split('=');
                //BUGBUG: Sometimes this returns when  i fail to parse the query string =( i could add better handlings.. maybe another layer of splittings.. i'll think about it.
                if (rawParams.Length == 0 || rawParams.Length > 2) return mc;
                // if the length is equal to two then we have a name value pair.. otherwise we have a "single" param.
                if (rawParams.Length == 2) {
                    //then add the value as a token along with it's offset..
                    offsetCount += rawParams[0].Length + 1;
                    mc.Add(new QueryStringMatch(new Token(rawParams[1]), offsetCount, s.Id));
                    offsetCount += rawParams[1].Length + 1;
                } else {
                    //offset = offsetCount;
                    //add the token..
                    mc.Add(new QueryStringMatch(new Token(rawParams[0]), offsetCount, s.Id));
                    offsetCount += rawParams[0].Length + 1;//the plus one is for the & symbol..
                }
            }
            return mc;
        }
예제 #6
0
 public MatchCollection InspectResponse(Session s, Token t)
 {
     MatchCollection retList = new MatchCollection();
     retList.AddRange(s.Response.FindTokenInHeaders(t, s.Id));
     retList.AddRange(s.Response.FindTokenInBody(t, s.Id));
     return retList;
 }
예제 #7
0
 static void Show(MatchCollection coll)
 {
     foreach (var item in coll)
         {
             Console.WriteLine(item);
         }
 }
예제 #8
0
        //below is for dealing with "Request checking" when looking for a token in a request to replace with a test case.
        public MatchCollection LocateTokensInRequest(Session s, Token canary)
        {
            MatchCollection retList = new MatchCollection();
            retList.AddRange(s.Request.FindTokenInHeaders(canary, s.Id));
            retList.AddRange(s.Request.FindTokenInBody(canary, s.Id));

            return retList;
        }
예제 #9
0
 private static void WriteToFile(string writeTo, MatchCollection col)
 {
     using (StreamWriter writer = new StreamWriter(writeTo))
     {
         foreach(object s in col){
             writer.WriteLine(s.ToString().Trim());
             writer.Flush();
         }
     }
 }
예제 #10
0
 private MatchCollection parseSession(Session s)
 {
     MatchCollection ret = new MatchCollection();
     //Call the appropriate parser here.. I can add logic to call them based off of criteria or other mechanisms.
     //Lets get the default case.. AutoRequestParser
     foreach (IRequestParser parser in parsers) {
         ret.AddRange(parser.TokenizeRequest(s));
     }
     return ret;
 }
예제 #11
0
    private static void Print(MatchCollection collection)
    {
        Console.WriteLine("Extracted e-mail addresses:");
        Console.WriteLine(new string('*', 27));

        foreach (var item in collection)
        {
            Console.WriteLine(item);
        }
    }
예제 #12
0
        public MatchCollection TokenizeBody(Session s)
        {
            MatchCollection mc = new MatchCollection();

            string body = s.Request.GetBodyEncodedAs(Encoding.UTF8);

            parseJsonObject(body, mc, 0, s);

            return mc;
        }
예제 #13
0
    private static void IncrementOccuranceCountTrie(Stopwatch sw, TrieNode start, MatchCollection allWords)
    {
        sw.Restart();
        foreach (var word in allWords)
        {
            start.AddOccuranceIfExists(start, word.ToString());
        }

        sw.Stop();
        Console.WriteLine("Adding searched words count trie for: {0}", sw.Elapsed);
    }
    private static string ConnectionMatches(MatchCollection paragraphText)
    {
        StringBuilder wholeText = new StringBuilder();
        foreach (var match in paragraphText)
        {
            wholeText.Append(match.ToString());
        }

        string text = Regex.Replace(wholeText.ToString(), @"[^a-z|\d]", " ");
        return text;
    }
    private static void Slice(string sourceFile, string destinationDirectory, int parts)
    {
        using (var source = new FileStream(sourceFile, FileMode.Open))
        {
            long partSize = (long)Math.Ceiling((double)source.Length / parts);

            // The offset at which to start reading from the source file
            long fileOffset = 0;
            ;
            string currPartPath;
            FileStream fsPart;
            long sizeRemaining = source.Length;

            // extracting name and extension of the input file
            string pattern = @"(\w+)(?=\.)\.(?<=\.)(\w+)";
            Regex pairs = new Regex(pattern);
            matches = pairs.Matches(sourceFile);
            for (int i = 0; i < parts; i++)
            {
                currPartPath = destinationDirectory + matches[0].Groups[1] + String.Format(@"-{0}", i) + "." + "gz";
                files.Add(currPartPath);

                // reading one part size
                using (fsPart = new FileStream(currPartPath, FileMode.Create))
                {
                    using (var compressionStream = new GZipStream(fsPart, CompressionMode.Compress, false))
                    {
                        long currentPieceSize = 0;
                        byte[] buffer = new byte[4096];
                        while (currentPieceSize < partSize)
                        {
                            int readBytes = source.Read(buffer, 0, buffer.Length);
                            if (readBytes == 0)
                            {
                                break;
                            }

                            // creating one part size file
                            compressionStream.Write(buffer, 0, readBytes);
                            currentPieceSize += readBytes;
                        }
                    }
                }

                // calculating the remaining file size which iis still too be read
                sizeRemaining = (int)source.Length - (i * partSize);
                if (sizeRemaining < partSize)
                {
                    partSize = sizeRemaining;
                }
                fileOffset += partSize;
            }
        }
    }
        public void InternalAddFailsWhenAddedLockedAndAdded()
        {
            MatchCollection<char> matches = new MatchCollection<char> ();

             matches.Add (m_noDigitsMatch);

             matches.Lock ();

             // Fails
             matches.Add (m_allDigitsMatch);
        }
예제 #17
0
        public MatchCollection FindTokenInBody(Token t, int sessionId)
        {
            string body = System.Text.Encoding.UTF8.GetString(this.BodyBytes);

            MatchCollection mc = new MatchCollection();
            for (int i = body.IndexOf(t.Identifier); i > 0 && i != -1; ) {
                //so the canary is present, lets muck with it!
                mc.Add(new BodyMatch(t, i, sessionId));
                i = body.IndexOf(t.Identifier, i + t.TokenLength);
            }
            return mc;
        }
예제 #18
0
    private static void ProcessStringNumberSequences(StringBuilder finalSymbolSequence, MatchCollection inputStrings)
    {
        for (int i = 0; i < inputStrings.Count; i++)
        {
            string symbolSequence = inputStrings[i].Groups[1].Value.ToUpper();
            int timesToReapeat = int.Parse(inputStrings[i].Groups[2].Value);

            string replacer = string.Concat(Enumerable.Repeat(symbolSequence, timesToReapeat));

            finalSymbolSequence.Append(replacer);
        }
    }
 public TournoiModels(TournoiWCF tournoi)
 {
     TournoiWCF = tournoi;
     Id = tournoi.Id;
     Nom = tournoi.Nom;
     bank = 500;
     List<MatchModels> list = new List<MatchModels>();
     foreach(MatchWCF m in tournoi.Matches)
     {
         list.Add(new MatchModels(m));
     }
     Matches = new MatchCollection(list);
 }
예제 #20
0
    static void Slice(string sourceFile, string destinationDirectory, int parts)
    {
        using (var sourceStream = new FileStream(sourceFile, FileMode.Open))
        {
            //get the sizes of each part
            long partSize = (long)Math.Ceiling((double)sourceStream.Length / parts);

            // The offset at which to start reading from the source file
            long fileOffset = 0;

            string currentPartPath;
            FileStream fsPart;
            long sizeRemaining = sourceStream.Length;

            // extracting name and extension of the input file
            string pattern = @"((\w+)\.(\w+))";
            Regex fileNames = new Regex(pattern);
            matches = fileNames.Matches(sourceFile);
            for (int i = 0; i < parts; i++)
            {
                currentPartPath = destinationDirectory + String.Format(@"Part{0}", i) + "." + matches[0].Groups[3];
                files.Add(currentPartPath);

                using (fsPart = new FileStream(currentPartPath, FileMode.Create))
                {
                    long currentPieceSize = 0;
                    byte[] buffer = new byte[4096];
                    while (currentPieceSize < partSize)
                    {
                        int readBytes = sourceStream.Read(buffer, 0, buffer.Length);
                        if (readBytes == 0)
                        {
                            break;
                        }

                        fsPart.Write(buffer, 0, readBytes);
                        currentPieceSize += readBytes;
                    }
                }

                sizeRemaining = (int)sourceStream.Length - (i * partSize);
                if (sizeRemaining < partSize)
                {
                    partSize = sizeRemaining;
                }
                fileOffset += partSize;
            }
        }
    }
예제 #21
0
    public void getlistaLivros(MatchCollection listaNomes, string tipoCapa, ref ArrayList listaLivros)
    {
        LivroPromocao livro = null;

        foreach (Match grupo in listaNomes) {

            livro = new LivroPromocao();

            livro.TipoCapa = tipoCapa;
            livro.Titulo = retiraNomeLivro(grupo.Groups[0].Value);
            livro.NomeAutor = retiraNomeAutor(grupo.Groups[0].Value);

            listaLivros.Add(livro);
        }
    }
예제 #22
0
    private static void Slice(string sourceFile, string destinationDirectory, int parts)
    {
        using (var source = new FileStream(sourceFile, FileMode.Open))
        {
            long partSize = (long)Math.Ceiling((double)source.Length / parts);

            long fileOffset = 0;
            ;
            string currPartPath;
            FileStream fsPart;
            long sizeRemaining = source.Length;

            string pattern = @"(\w+)(?=\.)\.(?<=\.)(\w+)";
            Regex pairs = new Regex(pattern);
            matches = pairs.Matches(sourceFile);
            for (int i = 0; i < parts; i++)
            {
                currPartPath = destinationDirectory + String.Format(@"Part-{0}", i) + "." + matches[0].Groups[2];
                files.Add(currPartPath);

                using (fsPart = new FileStream(currPartPath, FileMode.Create))
                {
                    long currentPieceSize = 0;
                    byte[] buffer = new byte[4096];
                    while (currentPieceSize < partSize)
                    {
                        int readBytes = source.Read(buffer, 0, buffer.Length);
                        if (readBytes == 0)
                        {
                            break;
                        }

                        // creating one part size file
                        fsPart.Write(buffer, 0, readBytes);
                        currentPieceSize += readBytes;
                    }
                }

                // calculating the remaining file size which iis still too be read
                sizeRemaining = (int)source.Length - (i * partSize);
                if (sizeRemaining < partSize)
                {
                    partSize = sizeRemaining;
                }
                fileOffset += partSize;
            }
        }
    }
예제 #23
0
    private static void IncrementOccuranceCountDictionary(Stopwatch sw, Dictionary<string, int> wordsInDictionary, MatchCollection allWords)
    {
        sw.Restart();
        foreach (var word in allWords)
        {
            string wordStr = word.ToString();
            if (wordsInDictionary.ContainsKey(wordStr))
            {
                wordsInDictionary[wordStr] += 1;
            }
        }

        sw.Stop();

        Console.WriteLine("Adding searched words count dictionary for: {0}\n", sw.Elapsed);
    }
예제 #24
0
 public int First()
 {
     mc = regex.Matches(text); // collection of all word beginnings
     //		for (int i = 0; i < mc.Count; i++)
     //		{
     //			System.Console.WriteLine("Found '{0}' at position {1}", mc[i].Value, mc[i].Index);
     //		}
     index = 0;
     if (mc.Count > 0)
     {
         return mc[0].Index;
     }
     else
     {
         return index;
     }
 }
예제 #25
0
 public MatchCollection FindTokenInHeaders(Token t, int sessionId)
 {
     MatchCollection mc = new MatchCollection();
     foreach (string header in this.headers.Keys) {
         int k = 0;
         foreach(string val in this.headers[header]){
             if (val.Contains(t.Identifier)) {
                 for (int i = header.IndexOf(t.Identifier); i > 0 && i != -1; ) {
                     //so the canary is present, lets muck with it!
                     mc.Add(new ResponseHeaderMatch(t, i, sessionId, header, k));
                     i = header.IndexOf(t.Identifier, i + t.TokenLength);
                 }
             }
             k++;
         }
     }
     return mc;
 }
예제 #26
0
	public void typeText(string text,float delay)
		{
		if(label==null){
			sendFinishEvent();
			return;
		}
		label.text="";
		if(delay>0)
			defaultDelay=delay;
		
		string t=text;
//		t="asdb\\nasdg\\1.5hjkh\\nhjkhg";
		Regex reg=new Regex(@"\\n|\\\d{1,5}\.\d{0,2}|\\\d{1,5}");
		mc=reg.Matches(t);
		typingText=reg.Split(t);
		StopAllCoroutines();
		StartCoroutine(typing());
		}
예제 #27
0
파일: CodeFile.cs 프로젝트: SteGriff/NCover
		public string ParseString(string source)
		{
			this.source = source;
			this.coveragepoints = new ArrayList();
			
			Matcher.Comments = new Comments(this.source);

			this.namespaces = filenamespaceRegex.Matches(this.source);
			
			foreach(Matcher matcher in this.matchers)
			{
				this.source = matcher.Replace(this.source);
			}
			
			baseCoveragePoint += this.coveragepoints.Count;

			return this.source;
		}
예제 #28
0
 static void Main(string[] args)
 {
     try
     {
         using (StreamReader reader = new StreamReader(@"..\..\text.txt"))
         {
             while (reader.Peek() >= 0)
             {
                 m = Regex.Matches(reader.ReadLine(), @"(?<=^|>)[^><]+?(?=<|$)");
                 foreach (var i in m)
                     Console.WriteLine(i.ToString().Trim());
             }
         }
     }
     catch (IOException IOE)
     {
         Console.WriteLine(IOE.Message);
     }
 }
예제 #29
0
        /// <summary>
        /// Extracts the matches of this pattern from <paramref name="source" />.
        /// </summary>
        /// <param name="filename">The name of the file associated with <paramref name="source" />.</param>
        /// <param name="source">The source string</param>
        /// <returns>
        /// A collection of found matches.
        /// </returns>
        public MatchCollection Extract(string filename, string source) {
            MatchCollection resultMatches = new MatchCollection();
            LineCounter lineCounter = new LineCounter(source); 

            RegexMatch regexMatch = _scanner.Match(source);
            while (regexMatch.Success) {
                Match match = new Match();
                match["Path"] = Path.GetDirectoryName(filename);
                match["File"] = Path.GetFileName(filename);
                match["LineNumber"] = lineCounter.CountTo(regexMatch.Index).ToString(); 
                foreach (string groupName in _scanner.GetGroupNames()) {
                    // ignore default-names like '0', '1' ... as produced
                    // by the Regex class
                    if (Char.IsLetter(groupName[0]) || (groupName[0] == '_')) {
                        match[groupName] = ConcatenateCaptures(regexMatch.Groups[groupName]);
                    }
                }
                resultMatches.Add(match);
                regexMatch = regexMatch.NextMatch();
            }
            return resultMatches;
        }
예제 #30
0
        public UAEngine()
        {
            Matches = new MatchCollection();
            MatchRWLock = new ReaderWriterLock();
            requestEngine = Secsay.RequestParsingEngine.GetInstance();
            responseEngine = Secsay.ResponseEngine.GetInstance();

            // Load the configuration options
            this.loadSettings();

            // Check for new version of the product
            if (this.Settings.autoCheckForUpdates)
            {
                UpdateManager updateManager = new UpdateManager();
                updateManager.CheckForUpdate(false);
            }

            // Start the "request throttling injection thread"
            FiddlerUtils.RequestManager.Throttle = this.Settings.throttleRequests;
            FiddlerUtils.RequestManager.Delay = this.Settings.throttleDelayPeriod;
            FiddlerUtils.RequestManager.BatchSize = this.Settings.throttleBatchSize;
            FiddlerUtils.RequestManager.Start();
        }
예제 #31
0
        public void run()

        {
            ArrayList lists = getListviewValue1(listView1);



            try

            {
                foreach (string id in lists)
                {
                    toolStripLabel2.Text = id.ToString();
                    string html = method.GetUrl("https://author.baidu.com/pipe?tab=2&app_id=" + id + "&num=20&pagelets[]=article&reqID=1&isspeed=0", "utf-8");


                    string          rxg     = @"data-event-data=\\""news_([\s\S]*?)\\"" data-thread-id=\\""([\s\S]*?)\\""([\s\S]*?)>   <div class=\\""text\\""><h2>([\s\S]*?)</h2> ";
                    MatchCollection titles  = Regex.Matches(html, @"<h2>([\s\S]*?)</h2>");
                    MatchCollection times   = Regex.Matches(html, @"<div class=\\""time\\"">([\s\S]*?)</div>");
                    MatchCollection urls    = Regex.Matches(html, @"<a href=\\""([\s\S]*?)\\""");
                    MatchCollection matches = Regex.Matches(html, rxg);


                    for (int i = 0; i < matches.Count; i++)
                    {
                        string url = "https://mbd.baidu.com/webpage?type=homepage&action=interact&format=jsonp&params=[{\"user_type\":\"3\",\"dynamic_id\":\"" + matches[i].Groups[1].Value + "\",\"dynamic_type\":\"2\",\"dynamic_sub_type\":\"2001\",\"thread_id\":" + matches[i].Groups[2].Value + ",\"feed_id\":\"" + matches[i].Groups[1].Value + "\"}]&uk=bYnkwu6b6HSuNmRoc92UbA&_=1547616333196&callback=jsonp1";

                        string readHtml = method.GetUrl(url, "utf-8");

                        Match reads = Regex.Match(readHtml, @"read_num"":([\s\S]*?),");

                        if (reads.Groups[1].Value != null && reads.Groups[1].Value != "")
                        {
                            if (comboBox1.Text == "1小时内")
                            {
                                this.condition = (times[i].Groups[1].Value.Contains("分") || times[i].Groups[1].Value.Contains("秒") || times[i].Groups[1].Value.Contains("1小时")) && Convert.ToInt32(reads.Groups[1].Value) >= Convert.ToInt32(textBox4.Text);
                            }

                            else if (comboBox1.Text == "3小时内")
                            {
                                this.condition = (times[i].Groups[1].Value.Contains("分") || times[i].Groups[1].Value.Contains("秒") || times[i].Groups[1].Value.Contains("1小时") || times[i].Groups[1].Value.Contains("2小时") || times[i].Groups[1].Value.Contains("3小时")) && Convert.ToInt32(reads.Groups[1].Value) >= Convert.ToInt32(textBox4.Text);
                            }
                            else if (comboBox1.Text == "8小时内")
                            {
                                this.condition = (times[i].Groups[1].Value.Contains("分") || times[i].Groups[1].Value.Contains("秒") || times[i].Groups[1].Value.Contains("1小时") || times[i].Groups[1].Value.Contains("2小时") || times[i].Groups[1].Value.Contains("3小时") || times[i].Groups[1].Value.Contains("4小时") || times[i].Groups[1].Value.Contains("5小时") || times[i].Groups[1].Value.Contains("6小时") || times[i].Groups[1].Value.Contains("7小时") || times[i].Groups[1].Value.Contains("8小时")) && Convert.ToInt32(reads.Groups[1].Value) >= Convert.ToInt32(textBox4.Text);
                            }
                            else if (comboBox1.Text == "24小时内")
                            {
                                this.condition = (times[i].Groups[1].Value.Contains("分") || times[i].Groups[1].Value.Contains("秒") || times[i].Groups[1].Value.Contains("小时") || times[i].Groups[1].Value.Contains("昨天")) && Convert.ToInt32(reads.Groups[1].Value) >= Convert.ToInt32(textBox4.Text);
                            }
                            else if (comboBox1.Text == "48小时内")
                            {
                                this.condition = (times[i].Groups[1].Value.Contains("分") || times[i].Groups[1].Value.Contains("秒") || times[i].Groups[1].Value.Contains("小时") || times[i].Groups[1].Value.Contains("昨天")) && Convert.ToInt32(reads.Groups[1].Value) >= Convert.ToInt32(textBox4.Text);
                            }
                            else if (comboBox1.Text == "3天内")
                            {
                                if (!times[i].Groups[1].Value.Contains("-"))
                                {
                                    this.condition = (times[i].Groups[1].Value.Contains("分") || times[i].Groups[1].Value.Contains("秒") || times[i].Groups[1].Value.Contains("小时") || times[i].Groups[1].Value.Contains("昨天")) && Convert.ToInt32(reads.Groups[1].Value) >= Convert.ToInt32(textBox4.Text);
                                }
                                else if (times[i].Groups[1].Value.Contains("-") && !times[i].Groups[1].Value.Contains("2018") && !times[i].Groups[1].Value.Contains("2017"))
                                {
                                    string time = "2019," + times[i].Groups[1].Value.Replace("-", ",").Replace(" ", ",").Replace(":", ",");

                                    string[] utimes = time.Split(',');

                                    DateTime atime = new DateTime(Convert.ToInt32(utimes[0]), Convert.ToInt32(utimes[1]), Convert.ToInt32(utimes[2]));
                                    TimeSpan d3    = DateTime.Now.Subtract(atime);
                                    this.condition = d3.Days < 3 && Convert.ToInt32(reads.Groups[1].Value) >= Convert.ToInt32(textBox4.Text);
                                }
                            }
                            else if (comboBox1.Text == "1周内")
                            {
                                if (!times[i].Groups[1].Value.Contains("-"))
                                {
                                    this.condition = (times[i].Groups[1].Value.Contains("分") || times[i].Groups[1].Value.Contains("秒") || times[i].Groups[1].Value.Contains("小时") || times[i].Groups[1].Value.Contains("昨天")) && Convert.ToInt32(reads.Groups[1].Value) >= Convert.ToInt32(textBox4.Text);
                                }
                                else if (times[i].Groups[1].Value.Contains("-") && !times[i].Groups[1].Value.Contains("2018") && !times[i].Groups[1].Value.Contains("2017"))
                                {
                                    string time = "2019," + times[i].Groups[1].Value.Replace("-", ",").Replace(" ", ",").Replace(":", ",");

                                    string[] utimes = time.Split(',');


                                    DateTime atime = new DateTime(Convert.ToInt32(utimes[0]), Convert.ToInt32(utimes[1]), Convert.ToInt32(utimes[2]));
                                    TimeSpan d3    = DateTime.Now.Subtract(atime);
                                    this.condition = d3.Days < 8 && Convert.ToInt32(reads.Groups[1].Value) >= Convert.ToInt32(textBox4.Text);
                                }
                            }
                        }


                        else
                        {
                            this.condition = true;
                        }


                        if (this.condition)
                        {
                            ListViewItem lv2 = listView2.Items.Add((listView2.Items.Count + 1).ToString());     //使用Listview展示数据
                            lv2.SubItems.Add(titles[i].Groups[1].Value);

                            lv2.SubItems.Add(reads.Groups[1].Value);
                            lv2.SubItems.Add(times[i].Groups[1].Value);
                            lv2.SubItems.Add(urls[i].Groups[1].Value);



                            if (listView2.Items.Count - 1 > 1)
                            {
                                listView2.EnsureVisible(listView2.Items.Count - 1);
                            }
                            //如果loader是false表明正在加载,,则Application.DoEvents()意思就是处理其他消息。阻止当前的队列继续执行。

                            while (this.zanting == false)
                            {
                                Application.DoEvents();
                            }
                            Thread.Sleep(1000);
                        }
                    }
                }
            }


            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #32
0
        public static void Alg2ParseThread()
        {
            string line;

            while (true)
            {
                line = null;
                if (mLinesBuffer.Count > 0)
                {
                    lock ("queue")
                    {
                        if (mLinesBuffer.Count > 0)
                        {
                            line = mLinesBuffer.Dequeue();
                        }
                    }
                    if (line != null)
                    {
                        String[] wordsArray  = line.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                        Char[]   letterArray = line.ToCharArray();

                        foreach (var word in wordsArray)
                        {
                            String lowerWord = word.ToLower();
                            if (!mWordDic.ContainsKey(lowerWord))
                            {
                                lock ("addword")
                                {
                                    if (!mWordDic.ContainsKey(lowerWord))
                                    {
                                        mWordDic.Add(lowerWord, 1);
                                    }
                                    else
                                    {
                                        mWordDic[lowerWord] += 1;
                                    }
                                }
                            }
                            else
                            {
                                lock ("addword")
                                {
                                    mWordDic[lowerWord] += 1;
                                }
                            }
                        }
                        foreach (var letter in letterArray)
                        {
                            if (!mLetterDic.ContainsKey(letter))
                            {
                                lock ("addLetter")
                                {
                                    if (!mLetterDic.ContainsKey(letter))
                                    {
                                        mLetterDic.Add(letter, 1);
                                    }
                                    else
                                    {
                                        mLetterDic[letter] += 1;
                                    }
                                }
                            }
                            else
                            {
                                lock ("addLetter")
                                {
                                    mLetterDic[letter] += 1;
                                }
                            }
                        }


                        MatchCollection matches = r.Matches(line);


                        lock ("addSentence")
                        {
                            mSentenceCount += matches.Count;
                        }
                        line = null;
                    }
                }
                else
                {
                    if (mCurFile >= n)
                    {
                        break;
                    }
                }
            }
        }
예제 #33
0
        /// <summary>
        /// 更新一场篮球(载入比赛页面使用)
        /// </summary>
        /// <param name="p_id">球探标识ID</param>
        public void Update(int p_id)
        {
            //得到整个页面
            string Basketvip = new TPR3.Collec.Basketvip().GetBasketvip(p_id);//166516、160572
            //得到让球盘赔率集合
            string Basketvip1 = new TPR3.Collec.Basketvip().BasketvipHtml(Basketvip);
            //得到大小盘赔率集合
            string Basketvip2 = new TPR3.Collec.Basketvip().BasketvipHtml2(Basketvip);

            //分析让球盘赔率
            if (!string.IsNullOrEmpty(Basketvip1))
            {
                Basketvip1 = Utils.Mid(Basketvip1, 1, Basketvip1.Length);

                string[] Temp  = Regex.Split(Basketvip1, "@");
                string   ypxml = Temp[0];

                string          ypodds = "";
                MatchCollection mc     = Regex.Matches(ypxml, @"<td style=""color[\s\S]+?>([\s\S]+?)</td>", RegexOptions.IgnoreCase);
                if (mc.Count > 0)
                {
                    for (int i = 0; i < mc.Count; i++)
                    {
                        ypodds += "@" + mc[i].Groups[1].Value.ToString();
                    }
                    ypodds = Utils.Mid(ypodds, 1, ypodds.Length);
                }
                //builder.Append(ypodds + "<br />");//此值当显示封盘时取不到
                int p_isluckone = 0;
                if (ypodds.Contains("封"))
                {
                    p_isluckone = 1;
                }
                else
                {
                    string[] ypTemp               = Regex.Split(ypodds, "@");
                    decimal  p_one_lu             = Convert.ToDecimal(ypTemp[1]) + 1;
                    decimal  p_pk                 = Convert.ToDecimal(ypTemp[2]);
                    decimal  p_two_lu             = Convert.ToDecimal(ypTemp[3]) + 1;
                    TPR3.Model.guess.BaList model = new TPR3.Model.guess.BaList();
                    model.p_id = p_id;
                    model.p_se = 0;
                    //更新让球盘
                    model.p_pk     = p_pk;
                    model.p_one_lu = p_one_lu;
                    model.p_two_lu = p_two_lu;
                    if (p_pk < 0)
                    {
                        model.p_pn = 2;
                    }
                    else
                    {
                        model.p_pn = 1;
                    }

                    new TPR3.BLL.guess.BaList().BasketUpdateYp(model);
                }
                //更新是否封盘
                if (ypxml.Contains("滚"))
                {
                    new TPR3.BLL.guess.BaList().Updatep_isluck(p_id, p_isluckone, 1);
                }
            }
            //分析大小盘赔率
            if (!string.IsNullOrEmpty(Basketvip2))
            {
                Basketvip2 = Utils.Mid(Basketvip2, 1, Basketvip2.Length);

                string[] Temp2 = Regex.Split(Basketvip2, "@");
                string   dxxml = Temp2[0];

                string          dxodds = "";
                MatchCollection mc2    = Regex.Matches(dxxml, @"<td style=""color[\s\S]+?>([\s\S]+?)</td>", RegexOptions.IgnoreCase);
                if (mc2.Count > 0)
                {
                    for (int i = 0; i < mc2.Count; i++)
                    {
                        dxodds += "@" + mc2[i].Groups[1].Value.ToString();
                    }
                    dxodds = Utils.Mid(dxodds, 1, dxodds.Length);
                }
                //builder.Append(dxodds + "<br />");//此值当显示封盘时取不到
                int p_islucktwo = 0;
                if (dxodds.Contains("封"))
                {
                    p_islucktwo = 1;
                }
                else
                {
                    string[] dxTemp     = Regex.Split(dxodds, "@");
                    decimal  p_big_lu   = Convert.ToDecimal(dxTemp[1]) + 1;
                    decimal  p_dx_pk    = Convert.ToDecimal(dxTemp[2]);
                    decimal  p_small_lu = Convert.ToDecimal(dxTemp[3]) + 1;

                    TPR3.Model.guess.BaList model = new TPR3.Model.guess.BaList();
                    model.p_id = p_id;
                    model.p_se = 0;
                    //更新大小盘
                    model.p_dx_pk    = p_dx_pk;
                    model.p_big_lu   = p_big_lu;
                    model.p_small_lu = p_small_lu;
                    new TPR3.BLL.guess.BaList().BasketUpdateDx(model);
                }
                //更新是否封盘
                if (dxxml.Contains("滚"))
                {
                    new TPR3.BLL.guess.BaList().Updatep_isluck(p_id, p_islucktwo, 2);
                }
            }
        }
예제 #34
0
        static void CheckMD5(IProgressReporterDialogue frmProgressReporter, string md5url, string baseurl)
        {
            log.InfoFormat("get checksums {0} - base {1}", md5url, baseurl);

            string responseFromServer = "";

            responseFromServer = client.GetStringAsync(md5url).GetAwaiter().GetResult();

            File.WriteAllText(Settings.GetRunningDirectory() + "checksums.txt.new", responseFromServer);

            Regex regex = new Regex(@"([^\s]+)\s+[^/]+/(.*)", RegexOptions.IgnoreCase);

            if (regex.IsMatch(responseFromServer))
            {
                if (frmProgressReporter != null)
                {
                    frmProgressReporter.UpdateProgressAndStatus(-1, "Hashing Files");
                }

                // cleanup dll's with the same exe name
                var           dlls  = Directory.GetFiles(Settings.GetRunningDirectory(), "*.dll", SearchOption.AllDirectories);
                var           exes  = Directory.GetFiles(Settings.GetRunningDirectory(), "*.exe", SearchOption.AllDirectories);
                List <string> files = new List <string>();

                // hash everything
                MatchCollection matchs = regex.Matches(responseFromServer);
                for (int i = 0; i < matchs.Count; i++)
                {
                    string hash = matchs[i].Groups[1].Value.ToString();
                    string file = matchs[i].Groups[2].Value.ToString();

                    files.Add(file);
                }

                // cleanup unused dlls and exes
                dlls.ForEach(dll =>
                {
                    try
                    {
                        var result = files.Any(task => Path.Combine(Settings.GetRunningDirectory(), task).ToLower().Equals(dll.ToLower()));

                        if (result == false)
                        {
                            File.Delete(dll);
                        }
                    }
                    catch { }
                });

                exes.ForEach(exe =>
                {
                    try
                    {
                        var result = files.Any(task => Path.Combine(Settings.GetRunningDirectory(), task).ToLower().Equals(exe.ToLower()));

                        if (result == false)
                        {
                            File.Delete(exe);
                        }
                    }
                    catch { }
                });



                // background md5
                List <Tuple <string, string, Task <bool> > > tasklist = new List <Tuple <string, string, Task <bool> > >();

                for (int i = 0; i < matchs.Count; i++)
                {
                    string hash = matchs[i].Groups[1].Value.ToString();
                    string file = matchs[i].Groups[2].Value.ToString();

                    if (file.ToLower().EndsWith("files.html"))
                    {
                        continue;
                    }

                    Task <bool> ismatch = Task <bool> .Factory.StartNew(() => MD5File(file, hash));

                    tasklist.Add(new Tuple <string, string, Task <bool> >(file, hash, ismatch));
                }
                // get count and wait for all hashing to be done
                int count = tasklist.Count(a =>
                {
                    a.Item3.Wait();
                    return(!a.Item3.Result);
                });

                // parallel download
                ParallelOptions opt = new ParallelOptions()
                {
                    MaxDegreeOfParallelism = 3
                };

                tasklist.Sort((a, b) =>
                {
                    if (a == null || b == null)
                    {
                        return(0);
                    }

                    if (a.Item1.ToLower().EndsWith(".exe") && b.Item1.ToLower().EndsWith(".exe"))
                    {
                        return(a.Item1.CompareTo(b.Item1));
                    }
                    if (a.Item1.ToLower().EndsWith(".exe"))
                    {
                        return(-1);
                    }
                    if (b.Item1.ToLower().EndsWith(".exe"))
                    {
                        return(1);
                    }

                    if (a.Item1.ToLower().EndsWith(".dll") && b.Item1.ToLower().EndsWith(".dll"))
                    {
                        return(a.Item1.CompareTo(b.Item1));
                    }
                    if (a.Item1.ToLower().EndsWith(".dll"))
                    {
                        return(-1);
                    }
                    if (b.Item1.ToLower().EndsWith(".dll"))
                    {
                        return(1);
                    }

                    return(a.Item1.CompareTo(b.Item1));
                });

                int done = 0;

                Parallel.ForEach(tasklist, opt, task =>
                                 //foreach (var task in tasklist)
                {
                    string file = task.Item1;
                    string hash = task.Item2;
                    // check if existing matchs hash
                    task.Item3.Wait();
                    bool match = task.Item3.Result;

                    if (!match)
                    {
                        done++;
                        log.Info("Newer File " + file);

                        if (frmProgressReporter != null && frmProgressReporter.doWorkArgs.CancelRequested)
                        {
                            frmProgressReporter.doWorkArgs.CancelAcknowledged = true;
                            throw new Exception("User Request");
                        }

                        // check is we have already downloaded and matchs hash
                        if (!MD5File(file + ".new", hash))
                        {
                            if (frmProgressReporter != null)
                            {
                                frmProgressReporter.UpdateProgressAndStatus((int)((done / (double)count) * 100),
                                                                            Strings.Getting + file + "\n" + done + " of " + count + " of total " +
                                                                            tasklist.Count);
                            }

                            string subdir = Path.GetDirectoryName(file) + Path.DirectorySeparatorChar;

                            subdir = subdir.Replace("" + Path.DirectorySeparatorChar + Path.DirectorySeparatorChar,
                                                    "" + Path.DirectorySeparatorChar);

                            if (baseurl.ToLower().Contains(".zip"))
                            {
                                GetNewFileZip(frmProgressReporter, baseurl, subdir,
                                              Path.GetFileName(file));
                            }
                            else
                            {
                                GetNewFile(frmProgressReporter, baseurl + subdir.Replace('\\', '/'), subdir,
                                           Path.GetFileName(file));
                            }

                            // check the new downloaded file matchs hash
                            if (!MD5File(file + ".new", hash))
                            {
                                throw new Exception("File downloaded does not match hash: " + file);
                            }
                        }
                        else
                        {
                            log.Info("already got new File " + file);
                        }
                    }
                    else
                    {
                        log.Info("Same File " + file);

                        if (frmProgressReporter != null)
                        {
                            frmProgressReporter.UpdateProgressAndStatus(-1, Strings.Checking + file);
                        }
                    }
                });
            }
        }
예제 #35
0
        private async void buttonSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                var source = textBoxInput.Text;
                var regex  = "";
                var target = textBoxOutput.Text;

                if (!File.Exists(source))
                {
                    MessageBox.Show("Input file not exists", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var             text            = File.ReadAllText(source);
                Regex           regexExpression = null;
                MatchCollection matches         = null;
                List <string>   outputResult    = new List <string>();

                if (comboBoxRegex.SelectedIndex == 0)
                {
                    regex           = "aria-label=\"[a-z0-9A-Z\\s]{1,}\"";
                    regexExpression = new Regex(regex);
                    matches         = regexExpression.Matches(text);

                    for (var i = 0; i < matches.Count; i++)
                    {
                        outputResult.Add(matches[i].Value.Remove(0, 11).Replace("\"", ""));
                    }
                }
                else if (comboBoxRegex.SelectedIndex == 1)
                {
                    regex           = "_2lel\">[a-z0-9A-Z\\s]{1,}<";
                    regexExpression = new Regex(regex);
                    matches         = regexExpression.Matches(text);

                    for (var i = 0; i < matches.Count; i++)
                    {
                        outputResult.Add(matches[i].Value.Remove(0, 7).Replace("<", ""));
                    }
                }
                else
                {
                    MessageBox.Show("Please select a dropdown value to retrieve the results", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (textBoxOutput.Text == string.Empty)
                {
                    MessageBox.Show("Specify a output file name tobe saved", "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                outputResult.Sort();
                textBoxOutput.Text = outputResult.Count.ToString() + " people liked this post";

                File.WriteAllText(target, string.Join("\n", outputResult.ToArray()));

                using (StreamReader reader = new StreamReader(target))
                {
                    richTextBoxOutput.Text = await reader.ReadToEndAsync();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error Message", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
            }
        }
예제 #36
0
        public void tengxun()

        {
            try

            {
                string[] citys    = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);
                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);



                int pages = 250;

                foreach (string city in citys)

                {
                    string cityutf8 = System.Web.HttpUtility.UrlEncode(city, System.Text.Encoding.GetEncoding("utf-8"));
                    foreach (string keyword in keywords)

                    {
                        string keywordutf8 = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("utf-8"));
                        for (int i = 0; i <= pages; i++)


                        {
                            String Url = "http://map.qq.com/m/place/result/city=" + cityutf8 + "&word=" + keywordutf8 + "&bound=&page=" + i + "&cpos=&mode=list";

                            textBox3.Text = Url;
                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"poid=([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";

                            Application.DoEvents();
                            Thread.Sleep(100);



                            foreach (string poid in lists)

                            {
                                int index = this.dataGridView1.Rows.Add();

                                string Url1    = "http://map.qq.com/m/detail/poi/poid=" + poid;
                                string strhtml = Method.GetUrl(Url1);


                                string title = @"<div class=""poiDetailTitle "">([\s\S]*?)</div>";
                                string Rxg   = @"<a href=""tel:([\s\S]*?)""";
                                string Rxg1  = @"span class=""poiDetailAddrTxt"">([\s\S]*?)</span>";



                                Match titles  = Regex.Match(strhtml, title);
                                Match tell    = Regex.Match(strhtml, Rxg);
                                Match address = Regex.Match(strhtml, Rxg1);

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }
                                if (tell.Groups[1].Value.Trim() != "")

                                {
                                    this.dataGridView1.Rows[index].Cells[0].Value = index;
                                    this.dataGridView1.Rows[index].Cells[1].Value = titles.Groups[1].Value;
                                    this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];

                                    this.dataGridView1.Rows[index].Cells[2].Value += tell.Groups[1].Value.Trim() + ",";

                                    this.dataGridView1.Rows[index].Cells[3].Value = address.Groups[1].Value;

                                    this.dataGridView1.Rows[index].Cells[4].Value = keyword;
                                    this.dataGridView1.Rows[index].Cells[5].Value = city;
                                }



                                Application.DoEvents();
                                Thread.Sleep(500);   //内容获取间隔,可变量
                            }
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox3.Text = ex.ToString();
            }
        }
예제 #37
0
        public void gaode()

        {
            try

            {
                string[] citys    = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);
                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);



                int pages = 200;

                foreach (string city in citys)

                {
                    int citycode = gaodeCityId(city);
                    foreach (string keyword in keywords)

                    {
                        string keywordutf8 = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("utf-8"));

                        for (int i = 0; i <= pages; i++)
                        {
                            String Url = "http://m.amap.com/service/poi/keywords.json?pagenum=" + i + "&user_loc=undefined&geoobj=&city=" + citycode + "&keywords=" + keywordutf8;

                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""diner_flag"":([\s\S]*?),""id"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[2].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";


                            Application.DoEvents();
                            Thread.Sleep(100);



                            foreach (string poid in lists)

                            {
                                int index = this.dataGridView1.Rows.Add();

                                string Url1    = "https://www.amap.com/detail/" + poid + "?citycode=" + citycode;
                                string strhtml = Method.GetUrl(Url1);


                                string title = @"<h4 class=""detail_title"">([\s\S]*?)</h4>";
                                string Rxg   = @"""telephone"":""([\s\S]*?)""";
                                string Rxg1  = @"""address"":""([\s\S]*?)""";



                                MatchCollection titles  = Regex.Matches(strhtml, title);
                                MatchCollection tell    = Regex.Matches(strhtml, Rxg);
                                MatchCollection address = Regex.Matches(strhtml, Rxg1);

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }


                                foreach (Match match in titles)
                                {
                                    this.dataGridView1.Rows[index].Cells[0].Value = index;
                                    this.dataGridView1.Rows[index].Cells[1].Value = match.Groups[1].Value;
                                    this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];
                                }
                                foreach (Match match in tell)
                                {
                                    this.dataGridView1.Rows[index].Cells[2].Value += match.Groups[1].Value.Trim() + ",";
                                }
                                foreach (Match match in address)
                                {
                                    this.dataGridView1.Rows[index].Cells[3].Value = match.Groups[1].Value;
                                }


                                this.dataGridView1.Rows[index].Cells[4].Value = keyword;
                                this.dataGridView1.Rows[index].Cells[5].Value = city;



                                Application.DoEvents();
                                Thread.Sleep(500);   //内容获取间隔,可变量
                            }
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox3.Text = ex.ToString();
            }
        }
예제 #38
0
        protected virtual void AddLegacyHostEnvironmentVariables(string scriptFile, string workingDirectory)
        {
            // scriptName
            AddEnvironmentVariable("VSTSPSHOSTSCRIPTNAME", scriptFile);

            // workingFolder
            AddEnvironmentVariable("VSTSPSHOSTWORKINGFOLDER", workingDirectory);

            // outputPreference
            AddEnvironmentVariable("VSTSPSHOSTOUTPUTPREFER", ExecutionContext.WriteDebug ? "Continue" : "SilentlyContinue");

            // inputParameters
            if (Inputs.Count > 0)
            {
                AddEnvironmentVariable("VSTSPSHOSTINPUTPARAMETER", JsonUtility.ToString(Inputs));
            }

            List <String> arguments = new List <string>();
            Dictionary <String, String> argumentParameters = new Dictionary <String, String>();
            string argumentFormat = GetArgumentFormat();

            if (string.IsNullOrEmpty(argumentFormat))
            {
                // treatInputsAsArguments
                AddEnvironmentVariable("VSTSPSHOSTINPUTISARG", "True");
            }
            else
            {
                MatchCollection matches = _argumentMatching.Matches(argumentFormat);
                if (matches[0].Value.StartsWith("-"))
                {
                    String currentKey = String.Empty;
                    foreach (Match match in matches)
                    {
                        if (match.Value.StartsWith("-"))
                        {
                            currentKey = match.Value.Trim('-');
                            argumentParameters.Add(currentKey, String.Empty);
                        }
                        else if (!match.Value.StartsWith("-") && !String.IsNullOrEmpty(currentKey))
                        {
                            argumentParameters[currentKey] = match.Value;
                            currentKey = String.Empty;
                        }
                        else
                        {
                            throw new Exception($"Found value {match.Value} with no corresponding named parameter");
                        }
                    }
                }
                else
                {
                    foreach (Match match in matches)
                    {
                        arguments.Add(match.Value);
                    }
                }

                // arguments
                if (arguments.Count > 0)
                {
                    AddEnvironmentVariable("VSTSPSHOSTARGS", JsonUtility.ToString(arguments));
                }

                // argumentParameters
                if (argumentParameters.Count > 0)
                {
                    AddEnvironmentVariable("VSTSPSHOSTARGPARAMETER", JsonUtility.ToString(argumentParameters));
                }
            }

            // push all variable.
            foreach (var variable in ExecutionContext.Variables.Public.Concat(ExecutionContext.Variables.Private))
            {
                AddEnvironmentVariable("VSTSPSHOSTVAR_" + variable.Key, variable.Value);
            }

            // push all public variable.
            foreach (var variable in ExecutionContext.Variables.Public)
            {
                AddEnvironmentVariable("VSTSPSHOSTPUBVAR_" + variable.Key, variable.Value);
            }

            // push all endpoints
            List <String> ids = new List <string>();

            foreach (ServiceEndpoint endpoint in ExecutionContext.Endpoints)
            {
                string partialKey = null;
                if (string.Equals(endpoint.Name, ServiceEndpoints.SystemVssConnection, StringComparison.OrdinalIgnoreCase))
                {
                    partialKey = ServiceEndpoints.SystemVssConnection.ToUpperInvariant();
                    AddEnvironmentVariable("VSTSPSHOSTSYSTEMENDPOINT_URL", endpoint.Url.ToString());
                    AddEnvironmentVariable("VSTSPSHOSTSYSTEMENDPOINT_AUTH", JsonUtility.ToString(endpoint.Authorization));
                }
                else
                {
                    if (endpoint.Id == Guid.Empty && endpoint.Data.ContainsKey("repositoryId"))
                    {
                        partialKey = endpoint.Data["repositoryId"].ToUpperInvariant();
                    }
                    else
                    {
                        partialKey = endpoint.Id.ToString("D").ToUpperInvariant();
                    }

                    ids.Add(partialKey);
                    AddEnvironmentVariable("VSTSPSHOSTENDPOINT_URL_" + partialKey, endpoint.Url.ToString());
                    AddEnvironmentVariable("VSTSPSHOSTENDPOINT_NAME_" + partialKey, endpoint.Name);
                    AddEnvironmentVariable("VSTSPSHOSTENDPOINT_TYPE_" + partialKey, endpoint.Type);
                    AddEnvironmentVariable("VSTSPSHOSTENDPOINT_AUTH_" + partialKey, JsonUtility.ToString(endpoint.Authorization));
                    AddEnvironmentVariable("VSTSPSHOSTENDPOINT_DATA_" + partialKey, JsonUtility.ToString(endpoint.Data));
                }
            }

            if (ids.Count > 0)
            {
                AddEnvironmentVariable("VSTSPSHOSTENDPOINT_IDS", JsonUtility.ToString(ids));
            }
        }
예제 #39
0
        public void FileTextChina(string path, Action <JsonModel> callback)
        {
            Regex            regex = new Regex("[\u4E00-\u9FA5]");
            List <TextModel> listText; int countList = 1;
            JsonModel        json;
            string           textContent   = readTextFromPath(path);
            MatchCollection  listWordChina = regex.Matches(textContent);

            listText = new List <TextModel>();

            TextModel text;
            int       count          = 0;
            int       countSTT       = 1;
            bool      isAddLastChina = false;

            for (int i = 1; i < listWordChina.Count; i++)
            {
                if (listWordChina[i].Index - listWordChina[i - 1].Index != 1 || listWordChina.Count - 1 == i)
                {
                    countList++;
                    text            = new TextModel(path);
                    text.StartIndex = listWordChina[count].Index;

                    if (listWordChina.Count - 1 == i && listWordChina[i].Index - listWordChina[i - 1].Index == 1)
                    {
                        text.ChinaText = textContent.Substring(text.StartIndex, (listWordChina[i].Index - text.StartIndex) + 1);
                    }
                    else if (listWordChina.Count - 1 == i && listWordChina[i].Index - listWordChina[i - 1].Index != 1)
                    {
                        text.ChinaText = textContent.Substring(text.StartIndex, (listWordChina[i - 1].Index - text.StartIndex) + 1);
                        //add last china
                        isAddLastChina = true;
                    }
                    else
                    {
                        text.ChinaText = textContent.Substring(text.StartIndex, (listWordChina[i - 1].Index - text.StartIndex) + 1);
                    }
                    text.RealLineText = GetLineTextInIndex(textContent, text.StartIndex, text.ChinaText);

                    count    = i;
                    text.STT = countSTT;
                    listText.Add(text);
                    if (isAddLastChina)
                    {
                        text              = new TextModel(path);
                        text.StartIndex   = listWordChina[listWordChina.Count - 1].Index;
                        text.ChinaText    = textContent.Substring(text.StartIndex, 1);
                        text.RealLineText = GetLineTextInIndex(textContent, text.StartIndex, text.ChinaText);
                        text.STT          = countSTT;

                        listText.Add(text);
                        isAddLastChina = false;
                    }
                    countSTT++;
                }
            }
            json              = new JsonModel();
            json.FullPath     = path;
            json.IsChangeJson = false;
            json.IsChangeTxt  = false;
            json.Name         = Path.GetFileNameWithoutExtension(path);
            json.ListText     = listText;
            callback(json);
        }
예제 #40
0
        static void Main(string[] args)
        {
            string pattern = @"(?<name>^[A-Z]{1}[a-z?' ]+):(?<song>[A-Z ]+)";

            string input = Console.ReadLine();

            while (input != "end")
            {
                MatchCollection matches = Regex.Matches(input, pattern);

                string artist = "";
                string song   = "";

                foreach (Match match in matches)
                {
                    artist = match.Groups["name"].Value;
                    song   = match.Groups["song"].Value;
                }

                if (Regex.IsMatch(input, pattern))
                {
                    int key = artist.Length;

                    char[] encArtist = artist.ToCharArray();
                    char[] encSong   = song.ToCharArray();

                    for (int i = 0; i < encArtist.Length; i++)
                    {
                        int result = encArtist[i] + key;

                        if (encArtist[i] == '\'' || encArtist[i] == ' ')
                        {
                            continue;
                        }
                        else if (char.IsUpper(encArtist[i]) && result > 90)
                        {
                            result = 64 + (encArtist[i] + key - 90);
                        }
                        else if (char.IsLower(encArtist[i]) && result > 122)
                        {
                            result = 96 + (encArtist[i] + key - 122);
                        }

                        encArtist[i] = (char)result;
                    }

                    for (int i = 0; i < encSong.Length; i++)
                    {
                        int result = encSong[i] + key;

                        if (encSong[i] == '\'' || encSong[i] == ' ')
                        {
                            continue;
                        }
                        else if (char.IsUpper(encSong[i]) && result > 90)
                        {
                            result = 64 + (encSong[i] + key - 90);
                        }
                        else if (char.IsLower(encSong[i]) && result > 122)
                        {
                            result = 96 + (encSong[i] + key - 122);
                        }

                        encSong[i] = (char)result;
                    }

                    Console.WriteLine($"Successful encryption: {new string(encArtist)}@{new string(encSong)}");
                }
                else
                {
                    Console.WriteLine("Invalid input!");
                }

                input = Console.ReadLine();
            }
        }
예제 #41
0
        public static void Alg12Thread(Object param) // массив путей, левая граница, правая граница
        {
            string[] paths = (string[])((Object[])param)[0];
            int      left  = (int)((Object[])param)[1];
            int      right = (int)((Object[])param)[2];


            for (int pathNum = left; pathNum < right; pathNum++)
            {
                using (StreamReader sr = new StreamReader(paths[pathNum], System.Text.Encoding.Default))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] wordsArray  = line.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                        Char[]   letterArray = line.ToCharArray();

                        foreach (var word in wordsArray)
                        {
                            String lowerWord = word.ToLower();
                            if (!mWordDic.ContainsKey(lowerWord))
                            {
                                lock ("addword")
                                {
                                    if (!mWordDic.ContainsKey(lowerWord))
                                    {
                                        mWordDic.Add(lowerWord, 1);
                                    }
                                    else
                                    {
                                        mWordDic[lowerWord] += 1;
                                    }
                                }
                            }
                            else
                            {
                                lock ("addword")
                                {
                                    mWordDic[lowerWord] += 1;
                                }
                            }
                        }
                        foreach (var letter in letterArray)
                        {
                            if (!mLetterDic.ContainsKey(letter))
                            {
                                lock ("addLetter")
                                {
                                    if (!mLetterDic.ContainsKey(letter))
                                    {
                                        mLetterDic.Add(letter, 1);
                                    }
                                    else
                                    {
                                        mLetterDic[letter] += 1;
                                    }
                                }
                            }
                            else
                            {
                                lock ("addLetter")
                                {
                                    mLetterDic[letter] += 1;
                                }
                            }
                        }
                    }
                }
                String fullText = File.ReadAllText(paths[pathNum], Encoding.GetEncoding(1251));


                MatchCollection matches = r.Matches(fullText);
                lock ("plussentence")
                {
                    mSentenceCount += matches.Count;
                }
            }
        }
예제 #42
0
        RPDUSMS[] ReadPDUInboxSMS(string pdu, out int[] index, out int[] message_status, out string[] address_text)
        {
            //RPDUSMS pdusms = new RPDUSMS();

            /*
             +CMGL: 11,0,,44
             * 07919730071111F1040B919730232933F10000904082904343611C31D98C56B3DD7039582C2693CD66345AAD66B3DD6E385C2E07
             * OK
             */
            string pat1 = @"\+CMGL:\s(?<index>[0-9]+),(?<message_status>[0-9]+),(?<address_text>[0-9A-Za-z\-]*),(?<TPDU_length>[0-9]+)(\r\n)(?<SMSC_number_and_TPDU>[0-9A-F]+)[\r\n]";
            Regex  reg1 = new Regex(pat1, RegexOptions.IgnoreCase);
            //string s = ReadFromPort();
            //Match m = reg1.Match(pdu);
            MatchCollection m = reg1.Matches(pdu);

            RPDUSMS[] pdusms = new RPDUSMS[m.Count];
            index          = new int[m.Count];
            message_status = new int[m.Count];
            address_text   = new string[m.Count];

            for (int i = 0; i < m.Count; i++)
            {
                //ret[i] = m[i].Groups["addr"].Value;
                index[i]          = int.Parse(m[i].Groups["index"].Value);
                message_status[i] = int.Parse(m[i].Groups["message_status"].Value);
                address_text[i]   = m[i].Groups["address_text"].Value;

                string stpdu = m[i].Groups["SMSC_number_and_TPDU"].Value;

                int cursor = 0;
                pdusms[i].SMSC_num_len = Convert.ToByte(stpdu.Substring(cursor, 2), 16);
                cursor = 2;
                if (pdusms[i].SMSC_num_len != 0x00)
                {
                    pdusms[i].SMSC_type_of_num = Convert.ToByte(stpdu.Substring(cursor, 2), 16);
                    cursor += 2;
                    int chread = ((int)pdusms[i].SMSC_num_len * 2) - 2;//2-длина SMSC_num_len
                    pdusms[i].SMSC_num = BCDUnFixNum(stpdu.Substring(cursor, chread));
                    cursor            += chread;
                }
                else
                {
                    pdusms[i].SMSC_type_of_num = 0x00;
                    pdusms[i].SMSC_num         = string.Empty;
                }
                pdusms[i].TPDU = Convert.ToByte(stpdu.Substring(cursor, 2), 16);
                cursor        += 2;

                pdusms[i].OA_ref_num_len = Convert.ToByte(stpdu.Substring(cursor, 2), 16);//TODO не нашел, что делать, но говорят, что мб 0x00
                cursor += 2;

                pdusms[i].OA_type_of_num = Convert.ToByte(stpdu.Substring(cursor, 2), 16);
                cursor += 2;

                int OA_num_len = (int)pdusms[i].OA_ref_num_len;
                if (OA_num_len % 2 > 0)
                {
                    OA_num_len++;
                }

                pdusms[i].OA_num = BCDUnFixNum(stpdu.Substring(cursor, OA_num_len));
                cursor          += OA_num_len;

                pdusms[i].PID = Convert.ToByte(stpdu.Substring(cursor, 2), 16);
                cursor       += 2;

                pdusms[i].DCS = Convert.ToByte(stpdu.Substring(cursor, 2), 16);
                cursor       += 2;

                pdusms[i].SCTS = GetSMSTime(stpdu.Substring(cursor, 14));
                cursor        += 14;

                pdusms[i].UDL = Convert.ToByte(stpdu.Substring(cursor, 2), 16);
                cursor       += 2;

                switch (pdusms[i].DCS)
                {
                case (byte)DEncProtocol.SbitDefault:
                {
                    pdusms[i].UD = PDU7bToString(stpdu.Substring(cursor));
                }
                break;

                case (byte)DEncProtocol.UTF7:
                {
                    pdusms[i].UD = USC2toString(stpdu.Substring(cursor));
                }
                break;

                default:
                {
                    pdusms[i].UD = PDU7bToString(stpdu.Substring(cursor));
                }
                break;
                }
            }


            #region why

            /*
             +CMGL: index,message_status,[address_text],TPDU_length<CR><LF>SMSC_number_and_TPDU[<CR><LF>+CMGL: ...]
             *
             * Before we discuss each of the fields that appear in the +CMGL information response, let's see an example
             * that gives you some idea of how an actual +CMGL information response should look like:
             *
             +CMGL: 1,0,,62
             * 07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
             *
             * The index Field
             * The first field of the information response of the +CMGL AT command, index, is an integer that specifies
             * the location of the SMS message in the message storage area.
             *
             * The message_status Field
             * The second field of the information response of the +CMGL AT command, message_status,
             * is an integer that indicates the status of the SMS message. It can be one of the following four values:
             * 0. It refers to the message status "received unread".
             * 1. It refers to the message status "received read".
             * 2. It refers to the message status "stored unsent".
             * 3. It refers to the message status "stored sent".
             *
             * The address_text Field
             * The third field of the information response of the +CMGL AT command, address_text, is a string that
             * contains the text associated to address in the phonebook, where address is the phone number encoded in the
             * TPDU of the SMSC_number_and_TPDU field. For example, if the phone number encoded in the TPDU is "91234567"
             * and the text "Alice" is associated to the phone number "91234567" in the phonebook, address_text will be
             * "Alice". The AT command +CSCS (command name in text: Select TE Character Set) can be used to specify the
             * character set for displaying address_text.
             *
             * Note that address_text is an optional field. Some GSM/GPRS modems and mobile phones leave this field empty.
             * (Examples: Philips 598 supports this field, while most Nokia products, including my Nokia 6021, and
             * Sony Ericsson T68i does not.)
             *
             * The TPDU_length Field
             * The fourth field of the information response of the +CMGL AT command, TPDU_length, is an integer that
             * indicates the length (in octets. 1 octet = 8 bits) of the TPDU contained in the SMSC_number_and_TPDU field.
             * In the earlier example command line, the value of the SMSC_number_and_TPDU field is:
             *
             * 07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
             *
             * It can be divided into two parts. The following part is the TPDU:
             *
             *              040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
             *
             * The TPDU is coded in hexadecimal format. Each character represents 4 bits, i.e. 1/2 octet.
             * The TPDU has 124 characters and so there are totally 62 octets. That's why the value of the
             * TPDU_length field is 62.
             *
             * The SMSC_number_and_TPDU Field
             * The fifth field of the information response of the +CMGL AT command, SMSC_number_and_TPDU, specifies
             * the SMSC number and the TPDU (Transfer Protocol Data Unit) in hexadecimal format.
             *
             * If the SMS message to be read is an incoming SMS message, the value of the SMSC_number_and_TPDU field
             * will be something like this:
             *
             * 07915892000000F0040B915892214365F700007040213252242331493A283D0795C3F33C88FE06C9CB6132885EC6D341EDF27C1E3E97E7207B3A0C0A5241E377BB1D7693E72E
             *
             * The TPDU embedded in the above hexadecimal sequence is of the type SMS-DELIVER. Here is some of the
             * information encoded in the hexadecimal sequence:
             * SMSC number from which the SMS message was received: +85290000000
             * Sender phone number: +85291234567
             * Time and date at which the SMSC received the SMS message: 12 April 2007, 23:25:42 GMT+8 hours
             * Text message: "It is easy to read text messages via AT commands."
             * For the details about how the hexadecimal sequence of an incoming SMS message is coded,
             * please refer to the section titled "Some Explanation about the Decoding of the SMSC_number_and_TPDU Field
             * Value of the +CMGR AT Command" of this SMS tutorial.
             *
             * If the SMS message to be read is an outgoing SMS message, the value of the SMSC_number_and_TPDU
             * field will be something like this:
             *
             * 07915892000000F001000B915892214365F7000021493A283D0795C3F33C88FE06CDCB6E32885EC6D341EDF27C1E3E97E72E
             *
             * The TPDU embedded in the above hexadecimal sequence is of the type SMS-SUBMIT.
             * Its format is different from that of an SMS-DELIVER TPDU. Below shows some of the information
             * encoded in the hexadecimal sequence above:
             * SMSC number to be used if the SMS message is sent out: +85290000000
             * Destination phone number: +85291234567
             * Text message: "It is easy to send text messages."
             * For the details about how the hexadecimal sequence of an outgoing SMS message is coded,
             * please refer to the section titled "Some Explanation about the Coding of the
             * SMSC_number_and_TPDU Parameter Value of the +CMGS AT Command" of this SMS tutorial.
             */
            #endregion

            return(pdusms);
        }
예제 #43
0
        static string GetMsgById(string argtoken, string argId, string argEmailFrom, string argPath)
        {
            string sret = string.Empty;

            StringBuilder sbXML2 = new StringBuilder();

            sbXML2.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
            sbXML2.Append("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">");
            sbXML2.Append("<soap:Header>");
            sbXML2.Append("<context xmlns=\"urn:zimbra\">");
            sbXML2.Append("<format type=\"xml\"/>");
            sbXML2.Append(string.Format("<authToken>{0}</authToken>", argtoken));
            sbXML2.Append("</context>");
            sbXML2.Append("</soap:Header>");
            sbXML2.Append("<soap:Body>");
            sbXML2.Append("<GetMsgRequest ");
            sbXML2.Append(string.Format(" xmlns=\"urn:zimbraMail\">"));
            sbXML2.Append(string.Format("<m id=\"{0}\" />", argId));
            sbXML2.Append("</GetMsgRequest>");
            sbXML2.Append("</soap:Body>");
            sbXML2.Append("</soap:Envelope>");
            Console.WriteLine(sbXML2);

            HttpWebRequest httpZimbraRequest2 = (HttpWebRequest)WebRequest.Create("https://accounts.mail.go.th/service/soap");

            httpZimbraRequest2.ContentType = "application/soapxml";

            byte[] byteArray2 = Encoding.UTF8.GetBytes(sbXML2.ToString());

            httpZimbraRequest2.Method        = "POST";
            httpZimbraRequest2.ContentLength = byteArray2.Length;

            using (var stream = httpZimbraRequest2.GetRequestStream())
            {
                stream.Write(byteArray2, 0, byteArray2.Length);
            }
            var response2 = (HttpWebResponse)httpZimbraRequest2.GetResponse();

            var responseString2 = new StreamReader(response2.GetResponseStream()).ReadToEnd();

            Console.WriteLine("<<<<<<<<<<<<<<<<<<<<<<< Response part >>>>>>>>>>>>>>>>>>");
            Console.WriteLine(responseString2);

            XmlDocument responseDoc = new XmlDocument();

            responseDoc.LoadXml(responseString2);
            XmlNodeList docs     = responseDoc.GetElementsByTagName("content");
            string      scontent = string.Empty;

            if (docs[0].InnerText.Length > 0)
            {
                scontent = docs[0].InnerText;
            }
            Console.WriteLine("content ={0}", scontent);

            Console.WriteLine("Catch by Pattern below.........");
            string          sPattern         = "<mp cd=\"attachment\"(.*?)/>";
            MatchCollection mtResults        = Regex.Matches(responseString2, sPattern);
            bool            bHaveNewItem     = false;
            string          sMailBody        = string.Empty;
            int             iCount           = 0;
            StreamWriter    writerLinkResult = new StreamWriter(string.Format(@"{0}\{1}id{2}_link.html", argPath, argEmailFrom, argId), true);

            writerLinkResult.AutoFlush = true;
            StreamWriter writerContent = new StreamWriter(string.Format(@"{0}\{1}id{2}_content.html", argPath, argEmailFrom, argId), true);

            writerContent.AutoFlush = true;

            writerContent.WriteLine(scontent);
            writerLinkResult.WriteLine("Image links for this {0} email", argEmailFrom);
            writerLinkResult.WriteLine("</br></br>");
            foreach (Match m in mtResults)
            {
                iCount += 1;
                string sValue = m.Value;
                Console.WriteLine(sValue);

                string sFilename = sValue.Substring(sValue.IndexOf("filename=\"") + 10, (sValue.IndexOf("s=\"") - sValue.IndexOf("filename=\"")) - 12);
                string sPart     = sValue.Substring(sValue.IndexOf("part=\"") + 6, (sValue.IndexOf("\"/>") - sValue.IndexOf("part=\"")) - 6);
                Console.WriteLine("filename ={0}", sFilename);
                Console.WriteLine("Part ={0}", sPart);
                string simglink = string.Format(@"https://accounts.mail.go.th/service/home/~/?auth=co&loc=th&id={0}&part={1}", argId, sPart);
                downloadImage(simglink + "&disp=a", sFilename, argPath, argtoken);
                string sHref = string.Format("{0}.) ", iCount) + string.Format("<a href=\"{0}\">{1}</a>", simglink, sFilename) + Environment.NewLine + "</br>" + string.Format("\r\n");
                writerLinkResult.WriteLine(sHref);
            }

            writerLinkResult.Close();
            writerContent.Close();
            return(sret);
        }
예제 #44
0
        public void sougou()

        {
            string cookie = "CXID=D44C63D34623066DA36D11B4B82C488C; SUV=1518337255419884; SMAPUVID=1518337255419884; SUV=1801190926013760; IPLOC=CN3213; sct=1; SNUID=D67B2A4373761425DCE0226F733E2FA7; ad=zMGYjlllll2zYIpclllllVr1fv6lllllGq6poyllll9llllljZlll5@@@@@@@@@@; SUID=A10659313565860A5A6291B800040AA1; wP_w=544ebe2c0329~HXcgwyvcH_c_5BDcHXULrZvNyX9XwbmSJXPsNNDN3XNBbbDJbdNhb; activecity=%u5BBF%u8FC1%2C13168867%2C3999623%2C12; ho_co=";
            string url    = "http://map.sogou.com/EngineV6/search/json";

            string charset = "gb2312";

            try

            {
                string[] citys    = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);
                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);



                int pages = 200;

                foreach (string city in citys)

                {
                    //搜索的城市和关键词都需要两次url编码

                    string city1    = System.Web.HttpUtility.UrlEncode(city, System.Text.Encoding.GetEncoding("utf-8"));
                    string cityutf8 = System.Web.HttpUtility.UrlEncode(city1, System.Text.Encoding.GetEncoding("utf-8"));
                    foreach (string keyword in keywords)

                    {
                        string keyword1    = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("utf-8"));
                        string keywordutf8 = System.Web.HttpUtility.UrlEncode(keyword1, System.Text.Encoding.GetEncoding("utf-8"));

                        for (int i = 1; i <= pages; i++)
                        {
                            string postData = "what=keyword%3A" + keywordutf8 + "&range=bound%3A00000000.5%2C0000000.5%2C99999999.5%2C9999999.5%3A0&othercityflag=1&appid=1361&thiscity=" + cityutf8 + "&lastcity=" + cityutf8 + "&userdata=3&encrypt=1&pageinfo=" + i + "%2C10&locationsort=0&version=7.0&ad=0&level=12&exact=1&type=&attr=&order=&submittime=0&resultTypes=poi&sort=0&reqid=1526008949358471&cb=parent.IFMS.search";

                            string html = Method.PostUrl(url, postData, cookie, charset);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""dataid"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";


                            Application.DoEvents();
                            Thread.Sleep(100);



                            foreach (string poid in lists)

                            {
                                int index = this.dataGridView1.Rows.Add();


                                string Url1    = "http://map.sogou.com/poi/1_" + poid + ".htm";
                                string strhtml = GetUrl(Url1);


                                string title = @"""caption"":""([\s\S]*?)""";
                                string Rxg   = @"""phone"":""([\s\S]*?)""";
                                string Rxg1  = @"""address"":""([\s\S]*?)""";



                                MatchCollection titles  = Regex.Matches(strhtml, title);
                                MatchCollection tell    = Regex.Matches(strhtml, Rxg);
                                MatchCollection address = Regex.Matches(strhtml, Rxg1);

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }


                                foreach (Match match in titles)
                                {
                                    this.dataGridView1.Rows[index].Cells[0].Value = index;
                                    this.dataGridView1.Rows[index].Cells[1].Value = match.Groups[1].Value;
                                    this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];
                                }
                                foreach (Match match in tell)
                                {
                                    this.dataGridView1.Rows[index].Cells[2].Value += match.Groups[1].Value.Trim() + ",";
                                }
                                foreach (Match match in address)
                                {
                                    this.dataGridView1.Rows[index].Cells[3].Value = match.Groups[1].Value;
                                }


                                this.dataGridView1.Rows[index].Cells[4].Value = keyword;
                                this.dataGridView1.Rows[index].Cells[5].Value = city;


                                Application.DoEvents();
                                Thread.Sleep(500);   //内容获取间隔,可变量
                            }
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox3.Text = ex.ToString();
            }
        }
예제 #45
0
        public void map_360()

        {
            try

            {
                string[] citys    = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);
                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);



                int pages = 100;

                foreach (string city in citys)

                {
                    string cityutf8 = System.Web.HttpUtility.UrlEncode(city, System.Text.Encoding.GetEncoding("utf-8"));
                    foreach (string keyword in keywords)

                    {
                        string keywordutf8 = System.Web.HttpUtility.UrlEncode(keyword, System.Text.Encoding.GetEncoding("utf-8"));
                        for (int i = 1; i <= pages; i++)



                        {
                            String Url = "https://ditu.so.com/app/pit?jsoncallback=jQuery18308131636402501483_1525852464213&keyword=" + keywordutf8 + "&cityname=" + cityutf8 + "&batch=" + i + "%2c" + (i + 1) + "%2c" + (i + 2) + "%2c" + (i + 3) + "%2c" + (i + 4) + "&number=10";



                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""pguid"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";

                            Application.DoEvents();
                            Thread.Sleep(100);



                            foreach (string poid in lists)

                            {
                                int index = this.dataGridView1.Rows.Add();

                                string Url1    = "https://m.map.so.com/onebox/?type=detail&id=" + poid + "&mso_x=&mso_y=&d=mobile&src=map_wap&fields=movies_all";
                                string strhtml = Method.GetUrl(Url1);


                                string title = @"data_poi_name = ""([\s\S]*?)""";
                                string Rxg   = @"href=""tel:([\s\S]*?)""";
                                string Rxg1  = @"data_poi_address = ""([\s\S]*?)""";



                                MatchCollection titles  = Regex.Matches(strhtml, title);
                                MatchCollection tell    = Regex.Matches(strhtml, Rxg);
                                MatchCollection address = Regex.Matches(strhtml, Rxg1);

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }


                                foreach (Match match in titles)
                                {
                                    this.dataGridView1.Rows[index].Cells[0].Value = index;
                                    this.dataGridView1.Rows[index].Cells[1].Value = match.Groups[1].Value;
                                    this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];
                                }
                                foreach (Match match in tell)
                                {
                                    this.dataGridView1.Rows[index].Cells[2].Value += match.Groups[1].Value.Trim() + ",";
                                }
                                foreach (Match match in address)
                                {
                                    this.dataGridView1.Rows[index].Cells[3].Value = match.Groups[1].Value;
                                }


                                this.dataGridView1.Rows[index].Cells[4].Value = keyword;
                                this.dataGridView1.Rows[index].Cells[5].Value = city;



                                Application.DoEvents();
                                Thread.Sleep(500);   //内容获取间隔,可变量
                            }
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox3.Text = ex.ToString();
            }
        }
예제 #46
0
        /// <summary>
        /// Seach Decimal Number
        /// </summary>
        /// <returns>The number.</returns>
        public static string RegexNumber(string value)
        {
            MatchCollection matches = Regex.Matches(value, numberRegex);

            return("");
        }
예제 #47
0
        public void txMap()

        {
            try

            {
                string[] citys = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);


                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);

                int pages = 200;


                foreach (string city in citys)

                {
                    int cityid = getcityId(city + "市");  //获取 citycode;

                    foreach (string keyword in keywords)

                    {
                        for (int i = 0; i <= pages; i++)

                        {
                            String Url = "https://map.baidu.com/?newmap=1&reqflag=pcmap&biz=1&from=webmap&da_par=direct&pcevaname=pc4.1&qt=con&from=webmap&c=" + cityid + "&wd=" + keyword + "&wd2=&pn=" + i + "&nn=" + i + "0&db=0&sug=0&addr=0&&da_src=pcmappg.poi.page&on_gel=1&src=7&gr=3&l=13&tn=B_NORMAL_MAP&u_loc=13167420,3999298&ie=utf-8";

                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""primary_uid"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";



                            JsonParser jsonParser = JsonConvert.DeserializeObject <JsonParser>(html);



                            foreach (Content content in jsonParser.Content)
                            {
                                int index = this.dataGridView1.Rows.Add();
                                this.dataGridView1.Rows[index].Cells[0].Value = index;
                                this.dataGridView1.Rows[index].Cells[1].Value = content.name;
                                this.dataGridView1.Rows[index].Cells[2].Value = content.tel;
                                this.dataGridView1.Rows[index].Cells[3].Value = content.addr;
                                this.dataGridView1.Rows[index].Cells[4].Value = keyword.Trim();
                                this.dataGridView1.Rows[index].Cells[5].Value = city;

                                this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];  //让datagridview滚动到当前行

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }
                            }



                            Application.DoEvents();
                            Thread.Sleep(100);   //内容获取间隔,可变量
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                textBox1.Text = ex.ToString();
            }
        }
예제 #48
0
        public void run()
        {
            try
            {
                ArrayList lists = new ArrayList();

                foreach (string keyword in lists)
                {
                    for (int i = 1; i <= 70; i++)
                    {
                        String Url = "https://m.1688.com/offer_search/-6D7033.html?keywords=" + System.Web.HttpUtility.UrlEncode(keyword);

                        string html = GetUrl(Url);

                        MatchCollection TitleMatchs = Regex.Matches(html, @"https://[a-z]+.58.com/[a-z]+/[0-9]+x.shtml", RegexOptions.IgnoreCase | RegexOptions.Multiline);



                        foreach (Match NextMatch in TitleMatchs)
                        {
                            if (!lists.Contains(NextMatch.Groups[0].Value))
                            {
                                lists.Add(NextMatch.Groups[0].Value);
                            }
                        }


                        foreach (string list in lists)
                        {
                            Match uid = Regex.Match(list, @"\d{10,}");

                            string strhtml = GetUrl("https://miniappfang.58.com/shop/plugin/v1/shopdetail?infoId=" + uid.Groups[0].Value + "&openId=77AA769A2A2C8740ECF1EDB47CD855A04C573D57DAF470CD8AD018A504661F6A");  //定义的GetRul方法 返回 reader.ReadToEnd()

                            Match title    = Regex.Match(strhtml, @"""title"":""([\s\S]*?)""");
                            Match contacts = Regex.Match(strhtml, @"""brokerName"":""([\s\S]*?)""");
                            Match tel      = Regex.Match(strhtml, @"""phone"":""([\s\S]*?)""");
                            Match region   = Regex.Match(strhtml, @"""quyu"":""([\s\S]*?)""");
                            Match dizhi    = Regex.Match(strhtml, @"""dizhi"":""([\s\S]*?)""");

                            Match date        = Regex.Match(strhtml, @"""postDate"":""([\s\S]*?)""");
                            Match description = Regex.Match(strhtml, @"""description"":""([\s\S]*?)""");

                            ListViewItem listViewItem = this.listView1.Items.Add((listView1.Items.Count + 1).ToString());
                            listViewItem.SubItems.Add(title.Groups[1].Value);
                            listViewItem.SubItems.Add(contacts.Groups[1].Value);
                            listViewItem.SubItems.Add(tel.Groups[1].Value);
                            listViewItem.SubItems.Add(region.Groups[1].Value);
                            listViewItem.SubItems.Add(dizhi.Groups[1].Value);
                            listViewItem.SubItems.Add(date.Groups[1].Value);
                            listViewItem.SubItems.Add(description.Groups[1].Value);



                            Application.DoEvents();
                            Thread.Sleep(1000);   //内容获取间隔,可变量

                            while (this.zanting == false)
                            {
                                Application.DoEvents();//如果loader是false表明正在加载,,则Application.DoEvents()意思就是处理其他消息。阻止当前的队列继续执行。
                            }
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
예제 #49
0
        public void baidu()

        {
            try

            {
                string[] citys = textBox1.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);


                string[] keywords = textBox2.Text.Trim().Split(new string[] { "\r\n" }, StringSplitOptions.None);

                int pages = 200;


                foreach (string city in citys)

                {
                    int cityid = getcityId(city + "市");  //获取 citycode;

                    foreach (string keyword in keywords)

                    {
                        for (int i = 0; i <= pages; i++)

                        {
                            int j = i - 1 > 0 ? i - 1 :0;

                            String Url = "https://map.baidu.com/?newmap=1&reqflag=pcmap&biz=1&from=webmap&da_par=direct&pcevaname=pc4.1&qt=con&from=webmap&c=" + cityid + "&wd=" + keyword + "&wd2=&pn=" + i + "&nn=" + j + "0&db=0&sug=0&addr=0&&da_src=pcmappg.poi.page&on_gel=1&src=7&gr=3&l=9.557396536572428&auth=Y%3DyW9VVIUF45OV8VGZCZb85Tzf4HRUPIuxHENxTzTzztComRB199Ay1uVt1GgvPUDZYOYIZuVt1cv3uVtGccZcuVtPWv3GuNtZComRdXmB1F234Q6W89AcEWe1GD8zv7u%40ZPuNtkB1FAprGnrFHQNWHaJ9caEmqQQDICfy9GUIsxA2wEjjg2JK&device_ratio=1&tn=B_NORMAL_MAP&u_loc=13177040,3994297&ie=utf-8&b=(12730445.232221898,4765711.534422691;13205701.20474543,4916707.941505569)&t=1547192932734";



                            string html = Method.GetUrl(Url);


                            MatchCollection TitleMatchs = Regex.Matches(html, @"""primary_uid"":""([\s\S]*?)""", RegexOptions.IgnoreCase);

                            ArrayList lists = new ArrayList();

                            foreach (Match NextMatch in TitleMatchs)
                            {
                                lists.Add(NextMatch.Groups[1].Value);
                            }
                            if (lists.Count == 0)  //当前页没有网址数据跳过之后的网址采集,进行下个foreach采集

                            {
                                break;
                            }

                            string tm1 = DateTime.Now.ToString();  //获取系统时间

                            textBox3.Text += tm1 + "-->正在采集" + city + "" + keyword + "第" + i + "页\r\n";



                            JsonParser jsonParser = JsonConvert.DeserializeObject <JsonParser>(html);



                            foreach (Content content in jsonParser.Content)
                            {
                                int index = this.dataGridView1.Rows.Add();
                                this.dataGridView1.Rows[index].Cells[0].Value = index;
                                this.dataGridView1.Rows[index].Cells[1].Value = content.name;
                                this.dataGridView1.Rows[index].Cells[2].Value = content.tel;
                                this.dataGridView1.Rows[index].Cells[3].Value = content.addr;
                                this.dataGridView1.Rows[index].Cells[4].Value = keyword.Trim();
                                this.dataGridView1.Rows[index].Cells[5].Value = city;

                                this.dataGridView1.CurrentCell = this.dataGridView1.Rows[index].Cells[0];  //让datagridview滚动到当前行

                                if (visualButton2.Text == "已停止")
                                {
                                    return;
                                }
                            }

                            Application.DoEvents();
                            Thread.Sleep(10);   //内容获取间隔,可变量
                        }
                    }
                }
            }

            catch (System.Exception ex)
            {
                ex.ToString();
            }
        }
예제 #50
0
        public static string FormatContentToShow(string content)
        {
            //group 1 <figure
            //group 2 <img src="
            //group 5 oembed
            //group 6 abre parenteses
            //group 7 url
            //group 9 fecha parenteses
            //group 10 oembed ending
            //group 11 figure ending

            string patternUrl = @"(<figure class=""image"">)?(<img(.?)?(data-)?src="")?(<figure class=""media""><oembed url=""|<figure class=""media""><div data-oembed-url=""|<oembed>)?(\()?([(http(s)?):\/\/(www\.)?a-zA-Z0-9\-@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&//=\,]*)\/[\w|\?|\=|\&|\;|\-\%\.]+)""?(\))?(<\/oembed>|><\/oembed><\/figure>)?(><\/figure>)?(.>)?";

            Regex theRegex = new Regex(patternUrl);

            MatchCollection matchesUrl = theRegex.Matches(content);

            foreach (Match match in matchesUrl)
            {
                string toReplace        = match.Groups[0].Value;
                string imagePrefix      = match.Groups[2].Value;
                string oembedPrefix     = match.Groups[5].Value;
                string openParenthesis  = match.Groups[6].Value;
                string url              = match.Groups[7].Value;
                string closeParenthesis = match.Groups[9].Value;

                url = !url.TrimStart('(').TrimEnd(')').ToLower().StartsWith("http") ? String.Format("http://{0}", url) : url;

                string newText = string.Empty;
                if (!string.IsNullOrWhiteSpace(imagePrefix))
                {
                    newText = String.Format("<img src=\"{0}\" />", url);
                }
                else if (!string.IsNullOrWhiteSpace(oembedPrefix))
                {
                    newText = String.Format(@"<div class=""videoWrapper""><oembed>{0}</oembed></div>", url);
                }
                else
                {
                    newText = string.Format(@"<a href=""{0}"" target=""_blank"" style=""font-weight:500"">{0}</a>", url);
                }

                if (!string.IsNullOrWhiteSpace(openParenthesis) && !string.IsNullOrWhiteSpace(closeParenthesis))
                {
                    newText = String.Format("({0})", newText);
                }

                string templateUrlCkEditor = String.Format("<a href=\"{0}\">{0}</a>", url);

                bool isAlreadyUrl = Regex.IsMatch(content, templateUrlCkEditor);

                if (!isAlreadyUrl)
                {
                    content = content.Replace(toReplace, newText);
                }
            }

            content = FormatHashTagsToShow(content);

            return(content);
        }
예제 #51
0
        static private List <RepositoryTranslation> initFromCSV(string filePath, bool hasInstance)
        {
            List <RepositoryTranslation> translations = new List <RepositoryTranslation>();

            if (File.Exists(filePath))
            {
                bool          isHeader  = true;
                Regex         regexp    = null;
                List <string> languages = new List <string>();

                foreach (string line in File.ReadAllLines(filePath, System.Text.Encoding.UTF8))
                {
                    if (regexp == null)
                    {
                        string exp       = "(?<=^|,)(\"(?:[^\"]|\"\")*\"|[^,]*)";
                        char   separator = ',';
                        //use the first line to determine the separator
                        if (line.StartsWith("Context"))
                        {
                            separator = line[7];
                        }
                        if (separator != ',')
                        {
                            exp = exp.Replace(',', separator);
                        }
                        regexp = new Regex(exp);
                    }

                    MatchCollection collection = regexp.Matches(line);
                    int             startCol   = (hasInstance ? 3 : 2);
                    if (collection.Count > startCol)
                    {
                        if (isHeader)
                        {
                            for (int i = startCol; i < collection.Count; i++)
                            {
                                languages.Add(ExcelHelper.FromCsv(collection[i].Value));
                            }
                            isHeader = false;
                        }
                        else
                        {
                            RepositoryTranslation translation = new RepositoryTranslation()
                            {
                                Context = ExcelHelper.FromCsv(collection[0].Value), Reference = ExcelHelper.FromCsv(collection[startCol - 1].Value)
                            };
                            if (hasInstance)
                            {
                                translation.Instance = ExcelHelper.FromCsv(collection[1].Value);
                            }
                            translations.Add(translation);
                            for (int i = 0; i < languages.Count && i + startCol < collection.Count; i++)
                            {
                                if (string.IsNullOrEmpty(languages[i]))
                                {
                                    continue;
                                }
                                translation.Translations.Add(languages[i], ExcelHelper.FromCsv(collection[i + startCol].Value));
                            }
                        }
                    }
                }
            }
            return(translations);
        }
        private string[] Headers(Project project, string filename, bool with_system)
        {
            List <string> headers  = new List <string> ();
            CProject      cproject = project as CProject;

            if (cproject == null)
            {
                return(headers.ToArray());
            }

            StringBuilder output = new StringBuilder();
            StringBuilder option = new StringBuilder("-M");

            if (!with_system)
            {
                option.Append("M");
            }

            option.Append(" -MG ");
            foreach (Package package in cproject.Packages)
            {
                package.ParsePackage();
                option.AppendFormat("{0} ", string.Join(" ", package.CFlags.ToArray()));
            }

            ProcessWrapper p = null;

            try {
                p = Runtime.ProcessService.StartProcess("gcc", option.ToString() + filename.Replace(@"\ ", " ").Replace(" ", @"\ "), null, null);
                p.WaitForOutput();

                // Doing the below completely breaks header parsing
                // // Skip first two lines (.o & .c* files) - WARNING, sometimes this is compacted to 1 line... we need a better way of handling this.
                // if(p.StandardOutput.ReadLine () == null) return new string[0]; // object file
                // if(p.StandardOutput.ReadLine () == null) return new string[0]; // compile file

                string line;
                while ((line = p.StandardOutput.ReadLine()) != null)
                {
                    output.Append(line);
                }
            } catch (Exception ex) {
                LoggingService.LogError(ex.ToString());
                return(new string [0]);
            }
            finally {
                if (p != null)
                {
                    p.Dispose();
                }
            }

            MatchCollection files = Regex.Matches(output.ToString().Replace(@" \", String.Empty), @" (?<file>([^ \\]|(\\ ))+)", RegexOptions.IgnoreCase);

            foreach (Match match in files)
            {
                string depfile = findFileInIncludes(project, match.Groups["file"].Value.Trim());

                headers.Add(depfile.Replace(@"\ ", " ").Replace(" ", @"\ "));
            }

            return(headers.ToArray());
        }
예제 #53
0
        private void InsertResultStringToRedis(NsReceivedQuery receivedQuery)
        {
            var commandText = receivedQuery.Query;

            SqlConnection conn = new SqlConnection(sqlConnectionString);

            using (SqlCommand cmd = new SqlCommand(commandText, conn))
            {
                cmd.CommandType = CommandType.Text;
                conn.Open();

                using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
                {
                    var cols = new List <string>();
                    for (var j = 0; j < reader.FieldCount; j++)
                    {
                        cols.Add(reader.GetName(j));
                    }

                    var client = NsRedisHelper.getRedisClient();
                    var key    = receivedQuery.KeyMask.ToString();

                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            Regex           regex   = new Regex(@"(\{.+?\})");
                            MatchCollection matches = regex.Matches(key);

                            string redisKey = key;

                            if (matches.Count != 0)
                            {
                                foreach (Match match in matches)
                                {
                                    redisKey = redisKey.Replace(match.Value,
                                                                reader.GetValue(
                                                                    reader.GetOrdinal(match.Value.Trim(new char[] { '{', '}' }))
                                                                    ).ToString()
                                                                );
                                }
                            }

                            string redisValue = "";
                            redisValue += "{";
                            for (int i = 0; i < cols.Count; i++)
                            {
                                string elementOfValue = '"' + cols[i] + '"' + ":" + '"' + reader.GetValue(i).ToString() + '"';
                                redisValue += elementOfValue;
                                if (i != cols.Count - 1)
                                {
                                    redisValue += ",";
                                }
                            }
                            redisValue += "},";

                            string existingValue = client.Get(redisKey);
                            if (existingValue != null)
                            {
                                existingValue = existingValue.Trim(new char[] { '[', ']' });
                                redisValue   += existingValue;
                                redisValue    = "[" + redisValue + "]";
                                if (!client.Set(redisKey, redisValue))
                                {
                                    throw new Exception($"Execution canceled. Redis cannot set {redisKey}{redisValue}.");
                                }
                                else
                                {
                                    var span = new TimeSpan(24, 1, 1);
                                    client.Expire(redisKey, span);
                                }
                            }
                            else
                            {
                                redisValue = "[" + redisValue + "]";
                                if (!client.Set(redisKey, redisValue))
                                {
                                    throw new Exception($"Execution canceled. Redis cannot set {redisKey}{redisValue}.");
                                }
                                else
                                {
                                    var span = new TimeSpan(24, 1, 1);
                                    client.Expire(redisKey, span);
                                }
                            }
                        }
                    }
                    client.Dispose();
                }
            }
        }
        static void Main(string[] args)
        {
            StringBuilder code = new StringBuilder();

            string[] numbers = code.ToString().Split(' ');

            bool inMultiLineComment   = false;
            bool inString             = false;
            bool inMultilineString    = false;
            bool inSingleQuotedString = false;
            bool indDiez = false;

            while (true)
            {
                string line = Console.ReadLine();
                if (line == "?>")
                {
                    break;
                }
                // code.Append(line);

                for (int j = 0; j < line.Length; j++)
                {
                    if (inMultilineString)
                    {
                        if (line[j] == '\"' && j + 1 < line.Length && line[j + 1] == '\"')
                        {
                            code.Append("\"\"");
                            j++;
                            continue;
                        }
                    }
                    if (inString)
                    {
                        if (line[j] == '\\' && j + 1 < line.Length && line[j + 1] == '\"')
                        {
                            code.Append("\\\"");
                            j++;
                            continue;
                        }
                        if (line[j] == '\\' && j + 1 < line.Length && line[j + 1] == '\'')
                        {
                            code.Append("\\\'");
                            j++;
                            continue;
                        }
                        if (line[j] == '\"' && !inSingleQuotedString)
                        {
                            inString          = false;
                            inMultilineString = false;
                            code.Append('\"');
                            continue;
                        }
                        if (line[j] == '\'' && inSingleQuotedString)
                        {
                            inString             = false;
                            inSingleQuotedString = false;
                            code.Append('\'');
                            continue;
                        }
                        code.Append(line[j]);
                        continue;
                    }

                    // Multiline comments
                    if (!inMultiLineComment && j + 1 < line.Length && line[j] == '/' && line[j + 1] == '*')
                    {
                        inMultiLineComment = true;
                        j++;
                        continue;
                    }
                    if (inMultiLineComment && j + 1 < line.Length && line[j] == '*' && line[j + 1] == '/')
                    {
                        inMultiLineComment = false;
                        j++;
                        continue;
                    }
                    if (inMultiLineComment)
                    {
                        continue;
                    }

                    // One line comment
                    if (line[j] == '/' && j + 1 < line.Length && line[j + 1] == '/')
                    {
                        if (j + 2 >= line.Length || line[j + 2] != '/')
                        {
                            break;
                        }
                        else
                        {
                            // Inline documentation (///)
                            code.Append("///");
                            j += 2;
                            continue;
                        }
                    }

                    //----



                    if (line[j] == '#' && j + 1 < line.Length)
                    {
                        if (j + 2 >= line.Length || line[j + 2] != '/')
                        {
                            break;
                        }
                        else
                        {
                            // Inline documentation (///)
                            code.Append("#");
                            //j += 2;
                            j++;
                            continue;
                        }
                    }


                    if (line[j] == '\\' && j + 1 < line.Length)
                    {
                        if (j + 2 >= line.Length || line[j + 2] != '/')
                        {
                            break;
                        }
                        else
                        {
                            // Inline documentation (///)
                            code.Append("\\");
                            //j += 2;
                            j++;
                            continue;
                        }
                    }



                    //---

                    if (line[j] == '@' && j + 1 < line.Length && line[j + 1] == '\"')
                    {
                        inString          = true;
                        inMultilineString = true;
                        j++;
                        code.Append("@\"");
                        continue;
                    }

                    if (line[j] == '\"')
                    {
                        inString = true;
                    }

                    if (line[j] == '\'')
                    {
                        inString             = true;
                        inSingleQuotedString = true;
                    }


                    code.Append(line[j]);
                }

                if (!inMultiLineComment)
                {
                    code.AppendLine();
                }
            }


            StringReader sr          = new StringReader(code.ToString());
            string       lineToPrint = null;

            StringBuilder res = new StringBuilder();

            while ((lineToPrint = sr.ReadLine()) != null)
            {
                if (!string.IsNullOrWhiteSpace(lineToPrint))
                {
                    res.Append(lineToPrint);
                }
            }

            //char[] delimiterChars = {'\n'};
            //string[] words = res.ToString().Split(delimiterChars);

            // Console.WriteLine(res);

            // Console.WriteLine(sb);
            MatchCollection matches = Regex.Matches(res.ToString(), "([$]+[a-zA-Z0-9_]*)");

            //[a-zA-Z0-9_]{1,}$ [^p]-ne izpechatwa p
            //[$]+[a-zA-Z0-9_]

            int           count = 0;
            List <string> var   = new List <string>();

            foreach (Match match in matches)
            {
                string num = match.Value.Substring(1, match.Length - 1);
                // Console.WriteLine(num);
                // Console.WriteLine(match);
                // count++;


                var.Add(num);
            }

            //foreach (var i in var)
            //{
            //   Console.WriteLine(i);
            //}

            // Console.WriteLine(count);
            // Console.WriteLine(var);

            IEnumerable <string> distinctAges = var.Distinct();

            string[] arr = distinctAges.ToArray();

            Console.WriteLine(arr.Length);

            for (int i = 0; i < arr.Length - 1; i++)
            {
                string lex = arr[i];

                for (int j = 1; j < arr.Length; j++)
                {
                    //  var[0].CompareTo(var[j]);

                    if (arr[i].CompareTo(arr[j]) == 1)
                    {
                        // continue;
                        string temp = arr[j];
                        arr[j] = arr[i];
                        arr[i] = temp;
                    }
                    else if (arr[i].CompareTo(arr[j]) == -1)
                    {
                        continue;
                    }
                    else if (arr[i].CompareTo(arr[j]) == 0)
                    {
                        continue;
                    }
                }
            }
            foreach (var i in arr)
            {
                Console.WriteLine(i);
            }
        }
예제 #55
0
        public static void main()
        {
            log.Debug("D2MP starting...");
            var notifyThread = new Thread(delegate()
            {
                using (notifier = new notificationForm())
                {
                    notifier.Visible = true;
                    Application.Run();
                }
            });

            notifyThread.SetApartmentState(ApartmentState.STA);
            notifyThread.Start();
            ourDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            File.WriteAllText(Path.Combine(ourDir, "version.txt"), ClientCommon.Version.ClientVersion);
            var iconThread = new Thread(delegate()
            {
                using (icon = new ProcessIcon())
                {
                    icon.Display();
                    icon.showNotification = delegate { notifier.Invoke(new MethodInvoker(delegate { notifier.Fade(1); notifier.hideTimer.Start(); })); };
                    Application.Run();
                }
            });

            iconThread.SetApartmentState(ApartmentState.STA);
            iconThread.Start();

            try
            {
                var steam = new SteamFinder();
                if (!Directory.Exists(Settings.steamDir) || !Directory.Exists(Settings.dotaDir))
                {
                    Settings.steamDir = steam.FindSteam(true);
                    Settings.dotaDir  = steam.FindDota(true);
                }

                if (Settings.steamDir == null || Settings.dotaDir == null)
                {
                    log.Fatal("Steam/dota was not found!");
                    return;
                }
                log.Debug("Steam found: " + Settings.steamDir);
                log.Debug("Dota found: " + Settings.dotaDir);

                addonsDir = Path.Combine(Settings.dotaDir, @"dota\addons\");
                d2mpDir   = Path.Combine(Settings.dotaDir, @"dota\d2moddin\");
                modDir    = Path.Combine(addonsDir, "d2moddin");
                if (!Directory.Exists(addonsDir))
                {
                    Directory.CreateDirectory(addonsDir);
                }
                if (!Directory.Exists(d2mpDir))
                {
                    Directory.CreateDirectory(d2mpDir);
                }
                if (!Directory.Exists(modDir))
                {
                    Directory.CreateDirectory(modDir);
                }

                {
                    modController.getLocalMods();
                }

                //Detect user
                string          config  = File.ReadAllText(Path.Combine(Settings.steamDir, @"config\config.vdf"));
                MatchCollection matches = Regex.Matches(config, "\"\\d{17}\"");
                string          steamid;
                steamids = new List <string>();
                if (matches.Count > 0)
                {
                    foreach (Match match in matches)
                    {
                        steamid = match.Value.Substring(1).Substring(0, match.Value.Length - 2);
                        log.Debug("Steam ID detected: " + steamid);
                        steamids.Add(steamid);
                    }
                }
                else
                {
                    log.Fatal("Could not detect steam ID.");
                    return;
                }

                //Modify gameinfo.txt
                ModGameInfo();

                log.Debug("Starting shutdown file watcher...");
                string pathToShutdownFile = Path.Combine(ourDir, "d2mp.pid");
                File.WriteAllText(pathToShutdownFile, "Delete this file to shutdown D2MP.");

                var watcher = new FileSystemWatcher();
                watcher.Path         = ourDir;
                watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite
                                       | NotifyFilters.FileName;
                watcher.Filter              = "d2mp.pid";
                watcher.Deleted            += (sender, args) => { shutDown = true; };
                watcher.EnableRaisingEvents = true;

                try
                {
                    SetupClient();
                    client.Open();
                }
                catch (Exception ex)
                {
                    notifier.Notify(4, "Server error", "Can't connect to the lobby server!");
                    Thread.Sleep(5000);
                    HandleClose();
                }
                while (!shutDown)
                {
                    Thread.Sleep(100);
                }
                client.Close();
            }
            catch (Exception ex)
            {
                log.Fatal("Overall error in the program: " + ex);
            }
            //UnmodGameInfo();
            shutDown = true;
            Application.Exit();
        }
예제 #56
0
    public static string ParseLastNoun(string text)
    {
        MatchCollection matches = lastNountRegEx.Matches(text);

        return(matches.Count > 0 ? matches[matches.Count - 1].Value : "");
    }
예제 #57
0
        private void UpdateSystemNameFromLogFile_worker()
        {
            SingleThreadLogger logger      = new SingleThreadLogger(ThreadLoggerType.FileScanner);
            Regex RegExTest_FindBestIsland = new Regex(String.Format("FindBestIsland:.+:.+:.+:.+", Regex.Escape(Program.DBCon.getIniValue <String>(IBE.IBESettingsView.DB_GROUPNAME, "PilotsName"))), RegexOptions.IgnoreCase);
            Regex RegExTest_Island_Claimed = new Regex(String.Format("vvv------------ ISLAND .+ CLAIMED ------------vvv"), RegexOptions.IgnoreCase);

            do
            {
                try
                {
                    Boolean         EndNow       = false;
                    string          Systemname   = "";
                    string          Locationname = "";
                    string          currentLogString;
                    Match           m                    = null;
                    Boolean         Got_Jump             = false;
                    List <String>   PossibleLocations    = new List <string>();
                    List <LogEvent> LoggedEvents         = new List <LogEvent>();
                    DateTime        TimestampCurrentLine = DateTime.MinValue;
                    String          InfoCurrentLine      = "";
                    //DateTime Timestamp_YoungestLine     = DateTime.MaxValue;
                    Int32    LineCountRaw = 0;
                    Int32    LineCount    = 0;
                    DateTime TimestampLastScanCandidate = DateTime.MinValue;
                    String   InfoLastScanCandidate      = "";

                    #if extScanLog
                    logger.Log("start, RegEx = <" + String.Format("FindBestIsland:.+:.+:.+:.+", Regex.Escape(Program.RegulatedNoiseSettings.PilotsName)) + ">");
                    #endif

                    var appConfigPath = Program.DBCon.getIniValue("Settings", "GamePath");

                    if (Directory.Exists(appConfigPath))
                    {
                        //var versions = Directory.GetDirectories(appConfigPath).Where(x => x.Contains("FORC-FDEV")).ToList().OrderByDescending(x => x).ToList();
                        var versions = new String[] { appConfigPath };

                        if (versions.Count() == 0)
                        {
#if extScanLog
                            logger.Log("no dirs with <FORC-FDEV> found");
                            var versions2 = Directory.GetDirectories(appConfigPath).ToList().OrderByDescending(x => x).ToList();
                            foreach (string SubPath in versions2)
                            {
                                logger.Log("but found <" + SubPath + ">");
                            }
#endif
                        }
                        else
                        {
#if extScanLog
                            logger.Log("lookin' for files in <" + versions[0] + ">");
#endif

                            // We'll just go right ahead and use the latest log...
                            var netLogs =
                                Directory.GetFiles(versions[0] + "\\Logs", "netLog*.log")
                                .OrderByDescending(File.GetLastWriteTime)
                                .ToArray();

                            if (netLogs.Length != 0)
                            {
                                Systemname   = "";
                                Locationname = "";
                                LoggedEvents.Clear();
                                var newestNetLog = netLogs[0];

                                if (!m_currentLogFile.Equals(newestNetLog, StringComparison.InvariantCultureIgnoreCase))
                                {
                                    // new logfile -> ignore the first jump again, it's simpply the "startjump" of ED, not a real jump
                                    m_InitialJumpFound = false;
                                    m_currentLogFile   = newestNetLog;

                                    Program.DBCon.setIniValue(DB_GROUPNAME, "CurrentLogfile", m_currentLogFile);
                                    Program.DBCon.setIniValue(DB_GROUPNAME, "InitialJumpFound", m_InitialJumpFound.ToString());

                                    m_TimestampLastScan = DateTime.MinValue;
                                    m_InfoLastScan      = "";
                                    Program.DBCon.setIniValue(DB_GROUPNAME, "TimestampLastScan", m_TimestampLastScan.ToString());
                                    Program.DBCon.setIniValue(DB_GROUPNAME, "InfoLastScan", m_InfoLastScan);
                                }

                                #if extScanLog
                                Debug.Print("File opened : <" + newestNetLog + ">");
                                logger.Log("File opened : <" + newestNetLog + ">");
                                #endif

                                FileStream Datei      = new FileStream(newestNetLog, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                                Byte[]     ByteBuffer = new Byte[1];
                                Byte[]     LineBuffer = new Byte[SEARCH_MAXLENGTH];

                                Datei.Seek(0, SeekOrigin.End);

                                while (!EndNow && (Datei.Position >= 2))
                                {
                                    long StartPos = -1;
                                    long EndPos   = -1;

                                    do
                                    {
                                        Datei.Read(ByteBuffer, 0, ByteBuffer.Length);
                                        //Debug.Print(ByteBuffer[0].ToString("x") + " ");
                                        if ((ByteBuffer[0] == 0x0A) || (ByteBuffer[0] == 0x0D))
                                        {
                                            if (EndPos == -1)
                                            {
                                                if (ByteBuffer[0] == 0x0D)
                                                {
                                                    EndPos = Datei.Position + 1;
                                                }
                                                else
                                                {
                                                    EndPos = Datei.Position;
                                                }

                                                Datei.Seek(-3, SeekOrigin.Current);
                                            }
                                            else
                                            {
                                                if (ByteBuffer[0] == 0x0D)
                                                {
                                                    StartPos = Datei.Position + 1;
                                                }
                                                else
                                                {
                                                    StartPos = Datei.Position;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if ((LineCountRaw == 0) && (EndPos == -1))
                                            {
                                                EndPos = Datei.Position;
                                            }

                                            Datei.Seek(-3, SeekOrigin.Current);
                                        }
                                    } while (StartPos == -1 && Datei.Position >= 3);

                                    LineCountRaw++;

                                    if ((StartPos == -1) && ((EndPos - StartPos) > SEARCH_MINLENGTH))
                                    {
                                        StartPos = 0;
                                    }

                                    if ((StartPos >= 0) && ((EndPos - StartPos) <= SEARCH_MAXLENGTH))
                                    {
                                        // found a line and it's not too long
                                        // read
                                        Datei.Read(LineBuffer, 0, (int)(EndPos - StartPos));
                                        // and convert to string
                                        currentLogString = Encoding.ASCII.GetString(LineBuffer, 0, (int)(EndPos - StartPos));

                                        Debug.Print("log - scanning :" + currentLogString);

                                        if (currentLogString != null)
                                        {
                                            // *********************************************
                                            // check the timestamp of the current line to avoid to re-analyse older data
                                            if (TryGetTimeFromLine(currentLogString, ref TimestampCurrentLine, ref InfoCurrentLine))
                                            {
                                                if (TimestampCurrentLine < m_TimestampLastScan)
                                                {
                                                    // everything is coming now is older
                                                    EndNow = true;
                                                }
                                                else if ((TimestampCurrentLine == m_TimestampLastScan) && (InfoCurrentLine.Equals(m_InfoLastScan)))
                                                {
                                                    // everything is coming now is older
                                                    EndNow = true;
                                                }

                                                // if it's the first line we have to save the "new youngest line"
                                                // to avoid to re-analyse the same lines lines next scan
                                                if (LineCount == 0)
                                                {
                                                    TimestampLastScanCandidate = TimestampCurrentLine;
                                                    InfoLastScanCandidate      = InfoCurrentLine;
                                                }

                                                LineCount++;

                                                if (!EndNow)
                                                {
                                                    // first: check if we've jumped
                                                    m = RegExTest_Island_Claimed.Match(currentLogString);
                                                    if (m.Success)
                                                    {
                                                        if (!Got_Jump)
                                                        {
                                                            LoggedEvents.Add(new LogEvent()
                                                            {
                                                                EventType = enLogEvents.Jump, Value = "", Time = TimestampCurrentLine
                                                            });
                                                            Got_Jump = true;
                                                        }

                                                        #if extScanLog
                                                        Debug.Print("Jump Recognized");
                                                        logger.Log("Jump Recognized : " + currentLogString.Replace("\n", "").Replace("\r", ""));
                                                        #endif
                                                    }

                                                    // *********************************************
                                                    // second: looking for the systemname
                                                    if (String.IsNullOrEmpty(Systemname))
                                                    {
                                                        if (currentLogString.Contains("System:"))
                                                        {
                                                            #if extScanLog
                                                            Debug.Print("Systemstring:" + currentLogString);
                                                            logger.Log("Systemstring:" + currentLogString.Replace("\n", "").Replace("\r", ""));
                                                            #endif

                                                            // before 2.1 :
                                                            // Systemname = currentLogString.Substring(currentLogString.IndexOf("(", StringComparison.Ordinal) + 1);
                                                            // Systemname = Systemname.Substring(0, Systemname.IndexOf(")", StringComparison.Ordinal));

                                                            // since 2.1 :
                                                            currentLogString = currentLogString.Replace("\r", "").Replace("\n", "").Replace(@"\\", "");
                                                            MatchCollection matchCollection = Regex.Matches(currentLogString, @"(?<match>[^""\s]+)|\""(?<match>[^""]*)""");
                                                            Point3Dbl       systemPosition  = new Point3Dbl();

                                                            for (int i = 0; i < matchCollection.Count; i++)
                                                            {
                                                                if ((matchCollection[i].ToString().Equals("System:")) && (matchCollection.Count > i))
                                                                {
                                                                    Systemname = matchCollection[i + 1].ToString().Replace("\"", "");
                                                                }
                                                                else if ((matchCollection[i].ToString().StartsWith("System:")) && (matchCollection[i].ToString().Length > "System:".Length))
                                                                {
                                                                    Systemname = matchCollection[i].ToString().Substring("System:".Length).Replace("\"", "");
                                                                }
                                                                else if (matchCollection[i].ToString().StartsWith("StarPos:("))
                                                                {
                                                                    try
                                                                    {
                                                                        var posParts = matchCollection[i].ToString().Replace("StarPos:(", "").Replace(")ly", "").Replace(")", "").Split(new char[] { ',' });

                                                                        systemPosition.X = Double.Parse(posParts[0], System.Globalization.CultureInfo.InvariantCulture);
                                                                        systemPosition.Y = Double.Parse(posParts[1], System.Globalization.CultureInfo.InvariantCulture);
                                                                        systemPosition.Z = Double.Parse(posParts[2], System.Globalization.CultureInfo.InvariantCulture);
                                                                    }
                                                                    catch (Exception)
                                                                    {
                                                                    }
                                                                }
                                                            }


                                                            LoggedEvents.Add(new LogEvent()
                                                            {
                                                                EventType = enLogEvents.System, Value = Systemname, Time = TimestampCurrentLine, Position = systemPosition
                                                            });

                                                            #if extScanLog
                                                            Debug.Print("System: " + systemName);
                                                            logger.Log("System: " + systemName);
                                                            #endif

                                                            // preparing search for location info
                                                            RegExTest_FindBestIsland = new Regex(String.Format("FindBestIsland:.+:.+:.+:{0}", Regex.Escape(Systemname)), RegexOptions.IgnoreCase);

                                                            #if extScanLog
                                                            logger.Log("new Regex : <" + String.Format("FindBestIsland:.+:.+:.+:{0}", Regex.Escape(systemName)) + ">");
                                                            #endif

                                                            // we may have candidates, check them and if nothing found search from the current position
                                                            foreach (string candidate in PossibleLocations)
                                                            {
                                                                #if extScanLog
                                                                Debug.Print("check candidate : " + candidate);
                                                                logger.Log("check candidate : " + candidate.Replace("\n", "").Replace("\r", ""));
                                                                #endif

                                                                m = RegExTest_FindBestIsland.Match(candidate);
                                                                //Debug.Print(currentLogString);
                                                                //if (currentLogString.Contains("Duke Jones"))
                                                                //    Debug.Print("Stop");
                                                                if (m.Success)
                                                                {
                                                                    #if extScanLog
                                                                    Debug.Print("locationstring from candidate : " + candidate);
                                                                    logger.Log("locationstring from candidate : " + candidate.Replace("\n", "").Replace("\r", ""));
                                                                    #endif

                                                                    getLocation(ref Locationname, m);

                                                                    DateTime CurrentTimestamp = new DateTime();
                                                                    String   CurrentInfo      = "";
                                                                    TryGetTimeFromLine(currentLogString, ref CurrentTimestamp, ref CurrentInfo);
                                                                    LoggedEvents.Add(new LogEvent()
                                                                    {
                                                                        EventType = enLogEvents.Location, Value = Locationname, Time = CurrentTimestamp
                                                                    });

                                                                    EndNow = true;
                                                                    break;
                                                                }
                                                            }
                                                        }
                                                        else
                                                        {
                                                            m = RegExTest_FindBestIsland.Match(currentLogString);
                                                            if (m.Success)
                                                            {
                                                                #if extScanLog
                                                                Debug.Print("Candidate : " + currentLogString);
                                                                logger.Log("Candidate added : " + currentLogString.Replace("\n", "").Replace("\r", ""));
                                                                #endif

                                                                PossibleLocations.Add(currentLogString);
                                                            }
                                                        }
                                                    }
                                                }

                                                if (!EndNow)
                                                {
                                                    // if we have the systemname we're looking for the locationname
                                                    if (!string.IsNullOrEmpty(Systemname) && string.IsNullOrEmpty(Locationname))
                                                    {
                                                        m = RegExTest_FindBestIsland.Match(currentLogString);
                                                        //Debug.Print(currentLogString);
                                                        //if (currentLogString.Contains("Duke Jones"))
                                                        //    Debug.Print("Stop");
                                                        if (m.Success)
                                                        {
                                                            #if extScanLog
                                                            Debug.Print("locationstring (direct) : " + currentLogString);
                                                            logger.Log("locationstring (direct) : " + currentLogString.Replace("\n", "").Replace("\r", ""));
                                                            #endif

                                                            getLocation(ref Locationname, m);
                                                            LoggedEvents.Add(new LogEvent()
                                                            {
                                                                EventType = enLogEvents.Location, Value = Locationname, Time = TimestampCurrentLine
                                                            });

                                                            EndNow = true;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }

                                    if (!EndNow)
                                    {
                                        if (StartPos >= 3)
                                        {
                                            Datei.Seek(StartPos - 1, SeekOrigin.Begin);
                                        }
                                        else
                                        {
                                            Datei.Seek(0, SeekOrigin.Begin);
                                        }
                                    }
                                }


                                if ((!m_TimestampLastScan.Equals(TimestampLastScanCandidate)) || (!m_InfoLastScan.Equals(InfoLastScanCandidate)))
                                {
                                    // save only if changed
                                    m_TimestampLastScan = TimestampLastScanCandidate;
                                    m_InfoLastScan      = InfoLastScanCandidate;

                                    Program.DBCon.setIniValue(DB_GROUPNAME, "TimestampLastScan", m_TimestampLastScan.ToString());
                                    Program.DBCon.setIniValue(DB_GROUPNAME, "InfoLastScan", m_InfoLastScan);
                                }

                                Datei.Close();
                                Datei.Dispose();

                                #if extScanLog
                                Debug.Print("Datei geschlossen");
                                logger.Log("File closed");
                                #endif

                                processingLocationInfo(LoggedEvents);

                                LoggedEvents.Clear();
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    Debug.Print("AnalyseError");
                    logger.Log(ex.Message + "\n" + ex.StackTrace + "\n\n");
                }

                #if extScanLog
                logger.Log("sleeping...");
                logger.Log("\n\n\n");
                Debug.Print("\n\n\n");
                #endif

                m_LogfileScanner_ARE.WaitOne();

                #if extScanLog
                logger.Log("awake...");
                #endif
            }while (!m_Closing);

            #if extScanLog
            Debug.Print("out");
            #endif
        }
예제 #58
0
        public static void Alg11Thread(Object param) // массив путей, левая граница, правая граница
        {
            string[] paths         = (string[])((Object[])param)[0];
            int      left          = (int)((Object[])param)[1];
            int      right         = (int)((Object[])param)[2];
            var      dic           = new Dictionary <string, int>();
            var      LetterDic     = new Dictionary <char, int>();
            int      WordCount     = 0;
            int      sentenceCount = 0;
            int      LetterCount   = 0;

            Char[] separators = { ' ', ',', '-', '.', '!', '?', '\"', '\n', '\r' };
            for (int pathNum = left; pathNum < right; pathNum++)
            {
                using (StreamReader sr = new StreamReader(paths[pathNum], System.Text.Encoding.Default))
                {
                    string line;
                    while ((line = sr.ReadLine()) != null)
                    {
                        String[] wordsArray  = line.Split(separators, StringSplitOptions.RemoveEmptyEntries);
                        Char[]   letterArray = line.ToCharArray();

                        foreach (var word in wordsArray)
                        {
                            WordCount++;
                            String lowerWord = word.ToLower();
                            if (!dic.ContainsKey(lowerWord))
                            {
                                dic.Add(lowerWord, 1);
                            }
                            else
                            {
                                dic[lowerWord] += 1;
                            }
                        }
                        foreach (var letter in letterArray)
                        {
                            LetterCount++;
                            if (!LetterDic.ContainsKey(letter))
                            {
                                LetterDic.Add(letter, 1);
                            }
                            else
                            {
                                LetterDic[letter] += 1;
                            }
                        }
                    }
                }
                String fullText = File.ReadAllText(paths[pathNum], Encoding.GetEncoding(1251));


                MatchCollection matches = r.Matches(fullText);
                sentenceCount += matches.Count;
            }
            MergeLetterDic(LetterDic);
            MergeWordDic(dic);
            lock ("mergeSentence")
            {
                mSentenceCount += sentenceCount;
            }
        }
예제 #59
0
        /// <summary>
        /// Checks if a string matches pattern
        /// </summary>
        /// <param name="str"></param>
        /// <param name="patternValue">The pattern to compare: *=any characters, ?=a character, #=a digit, etc.</param>
        /// <param name="comparisonType">One of the enumeration values that specifies the rules for the search</param>
        /// <returns></returns>
        public static bool Like(this string str, string patternValue, StringComparison comparisonType = UseCase)
        {
            int    Index        = 0;
            string Ch           = "";
            string regexPattern = "";

            // Escape parens
            patternValue = patternValue.Replace("(", @"\(");
            patternValue = patternValue.Replace(")", @"\)");

            // Convert Pattern from a like operand to a regular expression
            while (Index < patternValue.Length)
            {
                Ch = patternValue.Substring(Index, 1);

                // Ignore escaped literals
                if (Ch == "[")
                {
                    while (Ch != "]" & Index <= patternValue.Length)
                    {
                        regexPattern += Ch;
                        Index        += 1;
                        Ch            = patternValue.Substring(Index, 1);
                    }
                }

                // Convert wildcards
                switch (Ch)
                {
                case "*":
                case "%":
                    regexPattern += "(.|\n)*";
                    break;

                case "?":
                case "_":
                    regexPattern += ".{1}";
                    break;

                case "#":
                    regexPattern += "[\\d]+";
                    break;

                default:
                    regexPattern += Ch;
                    break;
                }
                Index += 1;
            }

            // Convert character exclusion syntax
            regexPattern = regexPattern.Replace("[!", "[^");
            if (comparisonType.ToRegEx() == RegexOptions.IgnoreCase)
            {
                regexPattern = "(?i)" + regexPattern;
            }

            MatchCollection Matches = Regex.Matches(str, regexPattern, RegexOptions.Multiline & comparisonType.ToRegEx());

            if (Matches.Count > 0)
            {
                return(Matches[0].Value.Equals(str, comparisonType));
            }
            return(false);
        }
예제 #60
0
        public virtual void LoadContent()
        {
            if (Request.QueryString[Keys.QueryStringLogout] != null)
            {
                UserInfo.LogOut();
                Response.Redirect(Path.Full.Split('?')[0]);
            }

            if (Request.QueryString[Keys.QueryStringAutoLogin] != null)
            {
                string token = Request.QueryString[Keys.QueryStringAutoLogin];
                UserInfo.LoginNew(token);
                Response.Redirect(Path.Full.Split('?')[0]);
            }

            PageInfo pi = PageInfo.Current;

            if (pi == null)
            {
                return;
            }
            if (pi.SecurityPart != -1)
            {
                if (!UserInfo.Current.CanAccess(pi.SecurityPart) &&
                    !IsLoginPage)
                {
                    Response.Redirect(LoginPage + Keys.UrlParamPageDelimiter + Keys.QueryStringUrl + Keys.UrlParamValueDelimiter + Server.UrlEncode(Path.Full));
                }
            }
            switch (pi.GenerateLastModified)
            {
            case GenerateLastModified.FromFiles:
                SetLastModified(System.IO.File.GetLastWriteTime(pi.DataFileName));
                SetLastModified(System.IO.File.GetLastWriteTime(Request.PhysicalPath));
                break;

            case GenerateLastModified.Now:
                SetLastModified(DateTime.Now);
                break;
            }
            if (pi.Cache > 0)
            {
                Response.Cache.SetCacheability(System.Web.HttpCacheability.Public);
                Response.Cache.SetVaryByCustom(Keys.CustomPath);
                Response.Cache.SetExpires(DateTime.Now.AddSeconds(pi.Cache));
            }
            if (pi.Header.Length > 0)
            {
                string[] headers = pi.Header.Split('\n');
                for (int i = 0; i < headers.Length; i++)
                {
                    Response.AppendHeader(
                        headers[i].Substring(0, headers[i].IndexOf(":")),
                        headers[i].Substring(headers[i].IndexOf(":") + 1));
                }
            }
            if (pi.StatusCode > 0)
            {
                Response.StatusCode = pi.StatusCode;
            }
            System.Web.UI.Control mc = this.MainPlaceHolder;
            if (mc != null)
            {
                if (pi.CodeFile.Length > 0)
                {
                    mc.Controls.Add(this.LoadControl(Keys.ServerRoot + Keys.UrlPathDelimiter + pi.CodeFile));
                    if (pi.GenerateLastModified == GenerateLastModified.FromFiles)
                    {
                        SetLastModified(System.IO.File.GetLastWriteTime(Request.MapPath(Keys.ServerRoot + Keys.UrlPathDelimiter + pi.CodeFile)));
                    }
                }
                else
                {
                    if (!Config.IsBlank(pi.Body))
                    {
                        MatchCollection col = regexControl.Matches(pi.Body);
                        if (col.Count == 0)
                        {
                            Literal l = new Literal();
                            l.Text = pi.Body;                            //this.ParseContent()
                            mc.Controls.Add(l);
                        }
                        else
                        {
                            int start = 0;
                            System.Web.UI.Control ctrl;
                            Literal lt;
                            foreach (Match m in col)
                            {
                                lt      = new Literal();
                                lt.Text = pi.Body.Substring(start, m.Index - start);                              //this.ParseContent()
                                start   = m.Index + m.Length;
                                mc.Controls.Add(lt);
                                string[] arrC = m.Groups[1].Value.Split(Keys.UrlParamDelimiter[0]);
                                ctrl = LoadControl(Keys.ServerRoot + Keys.UrlPathDelimiter + arrC[0]);
                                if (ctrl != null)
                                {
                                    if (arrC.Length > 1)
                                    {
                                        PropertyInfo[] prop = ctrl.GetType().GetProperties();
                                        for (int i = 1; i < arrC.Length; i++)
                                        {
                                            int    j   = arrC[i].IndexOf(Keys.UrlParamValueDelimiter);
                                            string pr  = arrC[i].Substring(0, j);
                                            string val = arrC[i].Substring(j + 1);
                                            for (int p = 0; p < prop.Length; p++)
                                            {
                                                if (prop[p].Name == pr)
                                                {
                                                    prop[p].SetValue(ctrl, val, null);
                                                }
                                            }
                                        }
                                    }
                                    mc.Controls.Add(ctrl);
                                }
                            }
                            if (start < pi.Body.Length)
                            {
                                lt      = new Literal();
                                lt.Text = pi.Body.Substring(start);
                                mc.Controls.Add(lt);
                            }
                        }
                    }
                    if (pi.GenerateLastModified == GenerateLastModified.Standard)
                    {
                        SetLastModified(System.IO.File.GetLastWriteTime(pi.DataFileName));
                        SetLastModified(System.IO.File.GetLastWriteTime(Request.PhysicalPath));
                    }
                }
            }
            System.Web.UI.Control c;
            DataTable             t = Config.GetConfigTable("controls.config", "load");

            if (t.Rows.Count > 0)
            {
                DateTime  dtControls = System.IO.File.GetLastWriteTime(Request.MapPath(Config.ConfigFolderPath + "/controls.config"));
                DataRow[] rows       = t.Select("(page='" + pi.FileName + "') OR (template='" + pi.Template + "')", "order ASC");
                for (int i = 0; i < rows.Length; i++)
                {
                    if (rows[i]["allow"].ToString() == "0" ||
                        (Util.IsBlank(rows[i]["page"]) &&
                         t.Select("(page='" + pi.FileName + "') AND (control='" + rows[i]["control"].ToString() + "') AND (placeholder='" + rows[i]["placeholder"].ToString() + "') AND (allow='0')").Length > 0))
                    {
                        continue;
                    }
                    c = FindPlaceHolder(rows[i]["placeholder"].ToString());
                    if (c != null)
                    {
                        SetLastModifiedIfSet(dtControls);
                        SetLastModifiedIfSet(System.IO.File.GetLastWriteTime(Request.MapPath(Keys.ServerRoot + Keys.UrlPathDelimiter + rows[i]["control"].ToString())));
                        c.Controls.Add(this.LoadControl(Keys.ServerRoot + Keys.UrlPathDelimiter + rows[i]["control"].ToString()));
                    }
                }
            }
        }