Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections.Generic;
- using System.Management;
- using System.Net.NetworkInformation;
- using System.Threading.Tasks;
- using Newtonsoft.Json;
- using ServiceManager.Definitions;
- using ServiceManager.Extensions;
- namespace ServiceManager
- {
- public class Computer
- {
- private readonly string _ip;
- private readonly string _user;
- private readonly string _password;
- private const string domain = @".\";
- public string IP => _ip;
- public string User => _user;
- public string Password => _password;
- public Computer(string ip, string user, string password)
- {
- _ip = ip;
- _user = user;
- _password = password;
- }
- [JsonIgnore]
- public Task<IPStatus> PingStatus => GetIPStatus(_ip);
- [JsonIgnore]
- public List<ServiceController> Services => InitServices();
- private async Task<IPStatus> GetIPStatus(string ip)
- {
- return await Task.Run(()=> new Ping().Send(ip,2000).Status);
- }
- [JsonIgnore]
- public ConnectionOptions ConnectionOptions =>
- new ConnectionOptions
- {
- Username = @".\" + _user,
- Password = _password,
- EnablePrivileges = true,
- Impersonation = ImpersonationLevel.Impersonate
- };
- private List<ServiceController> InitServices()
- {
- return new List<ServiceController>
- {
- new ServiceController(this, ServicesName.Transport.GetStringValue()),
- new ServiceController(this, ServicesName.TransportMonitoring.GetStringValue()),
- new ServiceController(this, ServicesName.TransportUpdater.GetStringValue())
- };
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement