Advertisement
Guest User

Untitled

a guest
May 4th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.01 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Net.Mail;
  5. using System.Net.NetworkInformation;
  6. using System.Collections;
  7.  
  8. public class Test
  9. {
  10. public static void Main()
  11. {
  12. //int loop = 5;
  13. //while (loop < 5)
  14. Console.WriteLine(Environment.MachineName);
  15. {
  16. DriveInfo[] allDrives = DriveInfo.GetDrives();
  17.  
  18. foreach (DriveInfo d in allDrives)
  19.  
  20. {
  21. Console.WriteLine("Drive {0}", d.Name);
  22. Console.WriteLine(" Drive type: {0}", d.DriveType);
  23. if (d.IsReady == true)
  24. {
  25. Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
  26. Console.WriteLine(" File system: {0}", d.DriveFormat);
  27. Console.WriteLine(
  28. " Available space to current user:{0, 15} bytes",
  29. d.AvailableFreeSpace, String.Format("Value: {0:P2}.", 0.100));
  30. //storage is binary not decimal
  31. Console.WriteLine(
  32. " Total available space: {0, 15} bytes",
  33. d.TotalFreeSpace);
  34.  
  35. Console.WriteLine(
  36. " Total available space: {0, 15} Gigabytes",
  37. d.TotalFreeSpace / 1024m / 1024m / 1024m);
  38.  
  39. Console.WriteLine(
  40. " Total size of drive: {0, 15} bytes ",
  41. d.TotalSize);
  42.  
  43. /*long total = d.TotalSize;
  44.  
  45. Console.WriteLine(
  46. " Total size = {0}", total);*/
  47.  
  48. long half = 50 * d.TotalSize / 100;
  49. long quarter = 25 * d.TotalSize / 100;
  50. //double percent = (d.TotalFreeSpace / d.TotalSize) * 100;
  51.  
  52.  
  53. Console.WriteLine(
  54. " current percentage = {0}", percent);
  55. Console.WriteLine(
  56. " 50% = {0}", half);
  57. Console.WriteLine(
  58. " 25% = {0}", quarter);
  59.  
  60. string drivelabel = d.VolumeLabel;
  61. string bodydetails = Environment.MachineName + " " + d.Name + " on " + drivelabel + " has " + percent + "% remaining";
  62.  
  63. }
  64. double percent = (d.TotalFreeSpace / d.TotalSize) * 100;
  65. string drivelabel = d.VolumeLabel;
  66. string bodydetails = Environment.MachineName + " " + d.Name + " on " + drivelabel + " has " + percent + "% remaining";
  67. email(drivelabel, bodydetails, percent);
  68. }
  69. }
  70. }
  71.  
  72. public static void details(double percent, string drivelabel, string bodydetails)
  73. {
  74.  
  75. }
  76. public static void list(Double percent, string drivelabel, string bodydetails)
  77. //public static void list(string drivelabel, string bodydetails)
  78. {
  79. ArrayList content = new ArrayList();
  80. content.Add(Environment.MachineName);
  81. content.Add(bodydetails);
  82. listcount(percent, drivelabel, bodydetails, content);
  83. //listcount(drivelabel, bodydetails, content);
  84. }
  85.  
  86. public static void listcount(Double percent, string drivelabel, string bodydetails, ArrayList content)
  87. // public static void listcount(string drivelabel, string bodydetails, ArrayList content)
  88. {
  89. string temp = "out1";
  90. foreach (string line in content)
  91. {
  92. temp += line;
  93. }
  94. email(content, temp, percent);
  95. //email(content, temp);
  96. }
  97.  
  98. /*public static void contentadd(ArrayList list)
  99. {
  100. foreach ()
  101. }*/
  102.  
  103. /*public static void temp(Double percent, string drivelabel, string bodydetails)
  104. {
  105. ArrayList templist = new ArrayList();
  106. templist.Add("content1");
  107. templist.Add("content2");
  108. templist.Add("content3");
  109. email(percent, drivelabel, bodydetails, templist);
  110. }*/
  111.  
  112. public static void email(ArrayList content, string temp, Double percent)
  113. //public static void email(ArrayList content, string temp)
  114.  
  115. {
  116. if (90 >= percent)
  117. {
  118. string myemailaddress = "email";
  119. //var fromAddress = new MailAddress("", "Name");
  120. var fromAddress = new MailAddress(myemailaddress, "name");
  121. //var fromAddress = myemailaddress;
  122. var toAddress = new MailAddress("email", "name");
  123. const string fromPassword = "password";
  124. const string subject = "Subject";
  125. //const string body = "your storage is more than half";
  126. //const string body = "percent";
  127. //string body = content.ToString();
  128. string body = temp.ToString();
  129. Console.WriteLine(body);
  130. //string body = "{0}"
  131. //string body = "you have percent.ToString"();
  132. //string body = drivelabel + bodydetails+ Environment.MachineName + " has " + percent + "% remaining";
  133. //string body = content.ToString();
  134.  
  135. //string body = bodydetails;
  136.  
  137.  
  138. var smtp = new SmtpClient
  139. {
  140. Host = "smtp.gmail.com",
  141. Port = 587,
  142. EnableSsl = true,
  143. DeliveryMethod = SmtpDeliveryMethod.Network,
  144. UseDefaultCredentials = false,
  145. Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  146. };
  147. using (var message = new MailMessage(fromAddress, toAddress)
  148. {
  149. Subject = subject,
  150. Body = body
  151. })
  152. {
  153. smtp.Send(message);
  154. }
  155. return;
  156. }
  157. {
  158. //ping();
  159. //Console.WriteLine("body");
  160. }
  161. }
  162. }
  163.  
  164. /*public static void ping()
  165. {
  166. string input;
  167. input = "www.google.com";
  168. Console.WriteLine("What site would you like to check?");
  169. //input = Console.ReadLine();
  170.  
  171. var ping = new System.Net.NetworkInformation.Ping();
  172.  
  173. //var result = ping.Send("www.google.com");
  174. var result = ping.Send(input);
  175.  
  176. if (result.Status != System.Net.NetworkInformation.IPStatus.Success)
  177. return;
  178.  
  179. Console.WriteLine("Your site is: {0}", input);
  180. Console.WriteLine(result.Status);
  181. emailping(input);
  182. /*string pingresult;
  183. pingresult = result.Status;
  184.  
  185. emailping(pingresult);
  186. }
  187.  
  188. public static void emailping(string input)
  189.  
  190. {
  191. string myemailaddress = "";
  192. //var fromAddress = new MailAddress("", "name");
  193. var fromAddress = new MailAddress(myemailaddress, "");
  194. //var fromAddress = myemailaddress;
  195. var toAddress = new MailAddress("", "name");
  196. const string fromPassword = "password";
  197. const string subject = "Subject";
  198. //const string body = "your storage is more than half";
  199. //const string body = "percent";
  200. //string body = "{0}"
  201. //string body = "you have percent.ToString"();
  202. //string body = drivelabel + bodydetails+ Environment.MachineName + " has " + percent + "% remaining";
  203. string body = "input";
  204.  
  205.  
  206. var smtp = new SmtpClient
  207. {
  208. Host = "smtp.gmail.com",
  209. Port = 587,
  210. EnableSsl = true,
  211. DeliveryMethod = SmtpDeliveryMethod.Network,
  212. UseDefaultCredentials = false,
  213. Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  214. };
  215. using (var message = new MailMessage(fromAddress, toAddress)
  216. {
  217. Subject = subject,
  218. Body = body
  219. })
  220. {
  221. smtp.Send(message);
  222. }
  223.  
  224. //Console.WriteLine("body");
  225. }
  226. //Console.WriteLine("body2");
  227. }*/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement