Advertisement
Guest User

Untitled

a guest
Aug 30th, 2014
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. using System.Text.RegularExpressions;
  9. using System.Threading;
  10. using System.Threading.Tasks;
  11. //using Lexicons;
  12.  
  13. namespace ConsoleApplication2
  14. {
  15. public class Program
  16. {
  17.  
  18. //private static List<KeyValuePair<string, string>> firstNames = new List<KeyValuePair<string, string>>();
  19. static void Main(string[] args)
  20. {
  21.  
  22. //Consider making this configurable
  23. const string sourceFile = "testSolar.txt";
  24.  
  25. //const string pattern = "http://10.123.9.66:80";
  26. //var FirstSeparatorLastNameExact = new[] { "nosyn_name_last_exact:(qxq" };
  27. //var SecondSeparatorLastNameExact = new[] { "qxq)" };
  28.  
  29. string[] FirstSeparator = new string[] { "nosyn_name_last_exact:(qxq" };
  30. string[] SecondSeparator = new string[] { "qxq)" };
  31.  
  32. string[] FirstSeperatorFirstName = new string[] { "nosyn_name_first_exact:(qxq" };
  33. string[] secondSeperatorFirstName = new string[] { "qxq)" };
  34.  
  35. string[] nameLastBFirst = new string[] {"nosyn_name_last_b_exact:(qxq" };
  36. string[] nameLastBSecond = new string[] {"qxq)"};
  37.  
  38.  
  39.  
  40. Regex re = new Regex("^(http|https)://");
  41. HttpWebResponse response;
  42.  
  43. // var webClient = new WebClient();
  44. var times = new Dictionary<string, TimeSpan>();
  45. var stopwatch = new System.Diagnostics.Stopwatch();
  46.  
  47. //Add header so if headers are tracked, it will show it is your application rather than something ambiguous
  48. //webClient.Headers.Add(HttpRequestHeader.UserAgent, "Response-Tester-Client");
  49.  
  50. var urlList = new List<string>();
  51. var listNames = new List<string>();
  52.  
  53. //var firstname = new List<string>();
  54. var firstNames = new Dictionary<string, string>();
  55. List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
  56. //var firstNames = new Func<string, string>();
  57.  
  58.  
  59.  
  60. //Loop through the lines in the file to get the urls
  61. try
  62. {
  63. stopwatch.Start();
  64. using (var reader = new StreamReader(sourceFile))
  65. {
  66.  
  67. while (!reader.EndOfStream)
  68. {
  69. //var urNewList = new List<string>();
  70. var line = reader.ReadLine();
  71. var columns = line.Split('t');
  72.  
  73. if (columns[2] == "R")
  74. {
  75. var url = columns[4] + "?" + columns[5];
  76. urlList.Add(url);
  77. //Thread.Sleep(250);
  78. }
  79.  
  80. var temp = line.Split(FirstSeparator, StringSplitOptions.RemoveEmptyEntries)[1];
  81. var result2 = temp.Split(SecondSeparator, StringSplitOptions.RemoveEmptyEntries)[0];
  82. //Console.WriteLine(result2);
  83. listNames.Add(result2);
  84.  
  85.  
  86.  
  87.  
  88. foreach (KeyValuePair<string, string> pair in firstNames)
  89. {
  90. var split = line.Split(FirstSeperatorFirstName, StringSplitOptions.RemoveEmptyEntries);
  91. if (split.Length > 1)
  92. {
  93.  
  94. var hallo = (split[1].Split(')')[0]);
  95. Console.WriteLine(pair.Key + "....." + pair.Value + "<br />");
  96. }
  97.  
  98. }
  99.  
  100. }
  101. }
  102. }
  103.  
  104. catch (Exception e)
  105. {
  106. Console.WriteLine("An error occured while attempting to access the source file at {0}", sourceFile);
  107. }
  108. finally
  109. {
  110. //Stop, record and reset the stopwatch
  111. stopwatch.Stop();
  112. times.Add("FileReadTime", stopwatch.Elapsed);
  113. stopwatch.Reset();
  114. }
  115.  
  116. //Try to connect to each url
  117. var counter = 1;
  118. foreach (var url in urlList)
  119. {
  120. try
  121. {
  122. stopwatch.Start();
  123.  
  124. using (WebClient webClient = new WebClient())
  125. {
  126.  
  127. webClient.Headers.Add(HttpRequestHeader.UserAgent, "Response-Tester-Client");
  128.  
  129. // HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  130. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  131. request.Method = "POST";
  132.  
  133. //webClient.Dispose();
  134. }
  135. }
  136. catch (Exception e)
  137. {
  138. Console.WriteLine("An error occured while attempting to connect to {0}", url);
  139. }
  140. finally
  141. {
  142. stopwatch.Stop();
  143. //We use the counter for a friendlier url as the current ones are unwieldly
  144. times.Add("Url " + counter, stopwatch.Elapsed);
  145. counter++;
  146. stopwatch.Reset();
  147. }
  148. }
  149.  
  150. //Release the resources for the WebClient
  151. //webClient.Dispose();
  152.  
  153. //Write the response times
  154. Console.WriteLine("Url " + "ttttLast Name" + "ttt first Name");
  155. int index = -1;
  156.  
  157. foreach (var key in times.Keys)
  158. {
  159. if (key.Contains("Url"))
  160. {
  161. index++;
  162. var temp = firstNames.ContainsKey(listNames[index]) ? "tt" + listNames[index] + "tt" + firstNames[listNames[index]] : "tt" + listNames[index];
  163. Console.WriteLine("{0}: {1} {2}", key, times[key].TotalSeconds, temp);
  164. }
  165. else
  166. {
  167. Console.WriteLine("{0}: {1}", key, times[key].TotalSeconds);
  168. }
  169. }
  170. Console.ReadKey();
  171. }
  172. }
  173. }
  174.  
  175. foreach (KeyValuePair<string, string> pair in firstNames)
  176. {
  177. var split = line.Split(FirstSeperatorFirstName, StringSplitOptions.RemoveEmptyEntries);
  178. if (split.Length > 1)
  179. {
  180.  
  181. var hallo = (split[1].Split(')')[0]);
  182. Console.WriteLine(pair.Key + "....." + pair.Value + "<br />");
  183. }
  184.  
  185. }
  186.  
  187. 2014-08-25 14:20:45,930 DEV hmb0uqzc10s0ounwdhpwmflp 1 R O http://10.123.9.66:80/solr_3.6/combi_live/select/ qt=standard_a2aperson&q=(((((nosyn_name_last_b_exact:(qxqkruijsqxq))))))&fq=(nosyn_name_first_exact:(qxqw*qxq))&fq=(nosyn_name_last_exact:(qxqtreurenqxq))&spellcheck.q=(qxqw*qxq qxqtreurenqxq kruijs)&spellcheck=true&spellcheck.count=-3&start=0&sort=date_main asc, score desc&omitHeader=true
  188. 2014-08-25 14:20:45,478 DEV z5gyjtcexs41vra4yegqejcf 0 R . http://10.123.9.66:80/solr_3.6/combi_live/select/ qt=standard_a2aperson&q=(((((nosyn_name_last_b_exact:(qxqkuilenburgqxq))))))&fq=(nosyn_name_last_exact:(qxqbroekqxq))&spellcheck.q=(qxqbroekqxq kuilenburg)&fq=(fk_collectiontype:6)&spellcheck=true&spellcheck.count=-3&start=10&sort=date_main asc, score desc&omitHeader=true
  189. 2014-08-25 14:20:43,949 DEV belkbyavlahok0jrvoutn2xd 21 R O http://10.123.9.66:80/solr_3.6/wiewaswie_live/select/ qt=standard_a2aperson&q=*:*&fq=(nosyn_name_last_exact:(qxqroelofqxq))&fq=(nosyn_name_patronym_exact:(qxqharmsqxq))&spellcheck.q=(qxqroelofqxq qxqharmsqxq)&fq={!tag%3Dalldoctypes}doc_type:1&fq=date_main:[0 TO 18133112]&facet.query={!ex%3Dalldoctypes}doc_type:3 AND (b_public:1)&facet.query={!ex%3Dalldoctypes}doc_type:2 AND (b_public:1)&spellcheck=true&spellcheck.count=-3&start=0&sort=name_last asc, score desc&omitHeader=true
  190. 2014-08-25 14:20:43,949 DEV belkbyavlahok0jrvoutn2xd 21 R O http://10.123.9.66:80/solr_3.6/wiewaswie_live/select/ qt=standard_a2aperson&q=*:*&fq=(nosyn_name_last_exact:(qxqroelofqxq))&fq=(nosyn_name_patronym_exact:(qxqharmsqxq))&spellcheck.q=(qxqroelofqxq qxqharmsqxq)&fq={!tag%3Dalldoctypes}doc_type:1&fq=date_main:[0 TO 18133112]&facet.query={!ex%3Dalldoctypes}doc_type:3 AND (b_public:1)&facet.query={!ex%3Dalldoctypes}doc_type:2 AND (b_public:1)&spellcheck=true&spellcheck.count=-3&start=0&sort=name_last asc, score desc&omitHeader=true
  191.  
  192. var temp = firstNames.ContainsKey(listNames[index]) ? "tt" + listNames[index] + "tt" + firstNames[listNames[index]] : "tt" + listNames[index];
  193.  
  194. foreach (KeyValuePair<string, string> pair in firstNames)
  195. {
  196. var split = line.Split(FirstSeperatorFirstName, StringSplitOptions.RemoveEmptyEntries);
  197. if (split.Length > 1)
  198. {
  199.  
  200. var hallo = (split[1].Split(')')[0]);
  201. Console.WriteLine(pair.Key + "....." + pair.Value + "<br />");
  202. }
  203.  
  204. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement