Advertisement
Guest User

Untitled

a guest
Mar 5th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.77 KB | None | 0 0
  1. using System.Collections.Generic;
  2. using System.Management;
  3. using System.Net.NetworkInformation;
  4. using System.Threading.Tasks;
  5. using Newtonsoft.Json;
  6. using ServiceManager.Definitions;
  7. using ServiceManager.Extensions;
  8.  
  9. namespace ServiceManager
  10. {
  11. public class Computer
  12. {
  13. private readonly string _ip;
  14. private readonly string _user;
  15. private readonly string _password;
  16.  
  17. private const string domain = @".\";
  18.  
  19. public string IP => _ip;
  20. public string User => _user;
  21. public string Password => _password;
  22.  
  23. public Computer(string ip, string user, string password)
  24. {
  25. _ip = ip;
  26. _user = user;
  27. _password = password;
  28. }
  29.  
  30. [JsonIgnore]
  31. public Task<IPStatus> PingStatus => GetIPStatus(_ip);
  32.  
  33. [JsonIgnore]
  34. public List<ServiceController> Services => InitServices();
  35.  
  36. private async Task<IPStatus> GetIPStatus(string ip)
  37. {
  38. return await Task.Run(()=> new Ping().Send(ip,2000).Status);
  39. }
  40.  
  41. [JsonIgnore]
  42. public ConnectionOptions ConnectionOptions =>
  43. new ConnectionOptions
  44. {
  45. Username = @".\" + _user,
  46. Password = _password,
  47. EnablePrivileges = true,
  48. Impersonation = ImpersonationLevel.Impersonate
  49. };
  50.  
  51. private List<ServiceController> InitServices()
  52. {
  53. return new List<ServiceController>
  54. {
  55. new ServiceController(this, ServicesName.Transport.GetStringValue()),
  56. new ServiceController(this, ServicesName.TransportMonitoring.GetStringValue()),
  57. new ServiceController(this, ServicesName.TransportUpdater.GetStringValue())
  58. };
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement