Advertisement
Guest User

Untitled

a guest
May 25th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Data.SqlClient;
  6. using System.IO;
  7. using MySql.Data.MySqlClient;
  8. using System.Data;
  9.  
  10. namespace ConsoleApplication1
  11. {
  12. class IrcChannel
  13. {
  14. public List<StalkWord> StalkWords { get; set; }
  15. public string ChannelName { get; set; }
  16.  
  17. public override string ToString()
  18. {
  19. string returnString = "";
  20. returnString += ChannelName;
  21. for (int i = 0; i < StalkWords.Count; i++)
  22. {
  23. if (i == 0) returnString += "{";
  24. returnString += StalkWords[i];
  25. if (i == 0) returnString += "}";
  26. }
  27. return returnString;
  28. }
  29. }
  30.  
  31. class StalkWord
  32. {
  33. public IrcChannel ircChannel;
  34. public string Word { get; set; }
  35. }
  36.  
  37. class Program
  38. {
  39. public static string SQLuser;
  40. public static string SQLpassword;
  41. public static List<IrcChannel> IrcChannels = new List<IrcChannel>();
  42.  
  43. static void Main(string[] args)
  44. {
  45. readconfigfile();
  46. string connectionString = "Server=sql;" +
  47. "Database=u_chzz_stalkbot;" +
  48. "User ID=" + SQLuser + ";" +
  49. "Password=" + SQLpassword + ";" +
  50. "Persist Security Info=True;";
  51.  
  52. MySqlConnection conn = new MySqlConnection(connectionString);
  53. conn.Open();
  54.  
  55. string SQLStatement = "SELECT name FROM channel";
  56. MySqlDataAdapter ChanAdapter = new MySqlDataAdapter(SQLStatement, conn);
  57. Console.WriteLine("TESTa");
  58. Console.ReadLine();
  59. DataTable dtResult = new DataTable();
  60. DataTable dtstalk = new DataTable();
  61. Console.WriteLine("TESTb");
  62. Console.ReadLine();
  63.  
  64. // Fill the DataTable with the result of the SQL statement
  65. Console.WriteLine("TESTc");
  66. Console.ReadLine();
  67.  
  68. ChanAdapter.Fill(dtResult);
  69. Console.WriteLine("TESTd");
  70. Console.ReadLine();
  71.  
  72. // Loop through all entries
  73.  
  74. foreach (DataRow drRow in dtResult.Rows)
  75. {
  76. Console.WriteLine("TESTe");
  77. Console.ReadLine();
  78. IrcChannel myChannel = new IrcChannel();
  79. myChannel.ChannelName = drRow["Name"].ToString();
  80. Console.WriteLine(myChannel.ChannelName);
  81. Console.WriteLine("TEST9");
  82. Console.ReadLine(); //now, for each channel, populate array of stalks
  83. SQLStatement = "SELECT text FROM chanstalk WHERE channel = '" + myChannel.ChannelName + "'";
  84. Console.WriteLine(SQLStatement);
  85. Console.WriteLine("TEST8");
  86. Console.ReadLine();
  87. MySqlDataAdapter stalkAdapter = new MySqlDataAdapter(SQLStatement, conn);
  88. Console.WriteLine("TEST1");
  89. Console.ReadLine();
  90. DataTable stResult = new DataTable();
  91. Console.WriteLine("TEST2");
  92. Console.ReadLine();
  93. stalkAdapter.Fill(stResult);
  94. Console.WriteLine("TEST3");
  95. Console.ReadLine();
  96. dtstalk.Rows.Add(stResult);
  97. foreach (DataRow stRow in stResult.Rows)
  98. {
  99. StalkWord myStalkWord = new StalkWord();
  100. myStalkWord.Word = stRow["text"].ToString();
  101. Console.WriteLine("****" + myStalkWord.Word);
  102. myChannel.StalkWords.Add(myStalkWord);
  103. }
  104. stalkAdapter.Dispose();
  105. IrcChannels.Add(myChannel);
  106. }
  107. // We don't need the data adapter any more
  108. ChanAdapter.Dispose();
  109. conn.Close();
  110. conn.Dispose();
  111. Console.WriteLine("XXXXXXX");
  112. foreach (IrcChannel myChan in IrcChannels)
  113. {
  114. Console.WriteLine(myChan);
  115. }
  116.  
  117.  
  118. }
  119. static void readconfigfile()
  120. {
  121. Console.WriteLine("reading .my.cnf");
  122. StreamReader settingsreader = new StreamReader("/home/chzz/.my.cnf");
  123. try
  124. {
  125. settingsreader.ReadLine();
  126. SQLuser = settingsreader.ReadLine();
  127. SQLuser = SQLuser.Remove(0, SQLuser.IndexOf("=") + 2);
  128. SQLpassword = settingsreader.ReadLine();
  129. SQLpassword = SQLpassword.Remove(0, SQLpassword.IndexOf("=") + 2);
  130. // SQLpassword = SQLpassword.Replace("\"","");
  131. }
  132. catch (Exception ex)
  133. {
  134. Console.WriteLine("Could not read .my.cnf for SQL user/password");
  135. Console.WriteLine(ex.Message);
  136. }
  137.  
  138. }
  139.  
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement