public string GetValidationSystemInfoError(SystemInfoDto argument, SystemInfoDto result, LogAction logAction) { if (argument == null) { result.Status = StatusInfoFail("SystemInfo отсутствует."); SaveAnswer(result, logAction); return("SystemInfo отсутствует."); } var sender = argument.Sender; if (string.IsNullOrEmpty(sender)) { result.Status = StatusInfoFail("Sender не указан."); SaveAnswer(result, logAction); return("Sender не указан."); } if (!sender.Equals(CommonConstants.SenderKazPatent, StringComparison.OrdinalIgnoreCase) && !sender.Equals(CommonConstants.SenderPep, StringComparison.OrdinalIgnoreCase)) { result.Status = StatusInfoFail($"Sender {sender} неизвестен."); SaveAnswer(result, logAction); return($"Sender {sender} неизвестен."); } if (argument.ChainId == null) { result.Status = StatusInfoFail("ChainId не указан."); SaveAnswer(result, logAction); return("ChainId не указан."); } return(null); }
public async Task OnGet() { var httpClient = this.clientFactory.CreateClient("apigateway"); this.SystemInfoDto = await httpClient.GetFromJsonAsync <SystemInfoDto>("system"); this.Forecast = await httpClient.GetFromJsonAsync <IEnumerable <WeatherDto> >("weather"); }
public IEnumerable <SystemInfoDto> FetchInformation() { var processedLogicalDrives = new HashSet <string>(); using (var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskDrive")) using (var results = searcher.Get()) { foreach (var managementObject in results.Cast <ManagementObject>()) { if (managementObject.TryGetProperty("Caption", out string caption)) { var driveRoot = new SystemInfoDto { Category = SystemInfoCategory.Drives, Name = caption, Value = HeaderValueDto.Instance }; driveRoot.Childs.AddRange(GetDiskDriveProperties(managementObject)); var deviceId = (string)managementObject.Properties["DeviceID"].Value; foreach (var(partition, partitionDeviceId) in QueryPartitions(deviceId)) { driveRoot.Childs.Add(partition); foreach (var(logicalDrive, logicalDriveId) in QueryLogicalDrives(partitionDeviceId)) { partition.Childs.Add(logicalDrive); processedLogicalDrives.Add(logicalDriveId); } } yield return(driveRoot); } } } //find missing logical disks using (var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_LogicalDisk")) using (var results = searcher.Get()) { foreach (var managementObject in results.Cast <ManagementObject>()) { var deviceId = (string)managementObject.Properties["DeviceID"].Value; if (processedLogicalDrives.Contains(deviceId)) { continue; } if (managementObject.TryGetProperty("Caption", out string caption)) { var driveRoot = new SystemInfoDto { Name = caption, Value = HeaderValueDto.Instance, Category = SystemInfoCategory.Drives }; driveRoot.Childs.AddRange(GetLogicalDriveProperties(managementObject)); yield return(driveRoot); } } } }
public static void TryAddDateTime(this IList <SystemInfoDto> dtos, string category, ManagementObject managementObject, string name) { if (managementObject.TryGetDateTime(name, out DateTimeOffset value)) { var dto = new SystemInfoDto { Name = $"@{category}.{name}", Category = category, Value = new DateTimeValueDto(value) }; dtos.Add(dto); } }
public static void TryAdd <T>(this IList <SystemInfoDto> dtos, string category, ManagementObject managementObject, string name, Func <T, ValueDto> getValue) { if (managementObject.TryGetProperty(name, out T value)) { var dto = new SystemInfoDto { Name = $"@{category}.{name}", Category = category, Value = getValue(value) }; dtos.Add(dto); } }
public void SaveAnswer(SystemInfoDto resultSystemInfo, LogAction logAction) { try { logAction.SystemInfoAnswerId = _logging.CreateLogSystemInfo(Mapper.Map <LogSystemInfo>(resultSystemInfo)); _logging.UpdateLogAction(logAction); } catch (Exception ex) { Log.Error(ex, ex.Message); } }
public SystemInfoViewModel(SystemInfoDto systemInfoDto) { Value = systemInfoDto.Value; if (systemInfoDto.Name[0] == '@') { Name = Tx.T($"SystemInformation:Labels.{systemInfoDto.Name.TrimStart('@')}"); } else { Name = systemInfoDto.Name; } Childs = systemInfoDto.Childs?.Select(x => new SystemInfoViewModel(x)).OrderBy(x => x.Childs.Any()).ThenBy(x => x.Name).ToList() ?? new List <SystemInfoViewModel>(0); }
public static void TryAdd <T>(this IList <SystemInfoDto> dtos, string category, ManagementObject managementObject, string name) { if (managementObject.TryGetProperty(name, out T value)) { var dto = new SystemInfoDto { Name = $"@{category}.{name}", Category = category }; switch (value) { case var val when val is string stringValue: dto.Value = new TextValueDto(stringValue); break; case var val when val is ulong ulongValue: dto.Value = new NumberValueDto((long)ulongValue); break; case var val when val is uint uintValue: dto.Value = new NumberValueDto(uintValue); break; case var val when val is bool boolValue: dto.Value = new BoolValueDto(boolValue); break; case var val when val is short number: dto.Value = new NumberValueDto(number); break; case var val when val is byte number: dto.Value = new NumberValueDto(number); break; case var val when val is ushort number: dto.Value = new NumberValueDto(number); break; default: throw new ArgumentOutOfRangeException(); } dtos.Add(dto); } }
public IEnumerable <SystemInfoDto> FetchInformation() { using (var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PhysicalMemory")) using (var results = searcher.Get()) { foreach (var managementObject in results.Cast <ManagementObject>()) { if (managementObject.TryGetProperty("Tag", out string name)) { var info = new SystemInfoDto { Category = SystemInfoCategory.Memory, Name = name, Value = HeaderValueDto.Instance }; AddMemoryProperties(managementObject, info.Childs); yield return(info); } } } }
public SystemInfoDto InitializeSystemInfo(SystemInfoDto argumentSystemInfo = null) { var systemInfo = new SystemInfoDto { MessageDate = DateTime.Now, MessageId = Guid.NewGuid().ToString(), Sender = CommonConstants.SystemInfoSenderNiis, AdditionalInfo = null, ChainId = null }; if (argumentSystemInfo != null) { systemInfo.MessageId = argumentSystemInfo.MessageId; systemInfo.ChainId = argumentSystemInfo.ChainId; } return(systemInfo); }
public IEnumerable <SystemInfoDto> FetchInformation() { using (var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_VideoController")) using (var results = searcher.Get()) { foreach (var managementObject in results.Cast <ManagementObject>()) { if (managementObject.TryGetProperty("Caption", out string caption)) { var info = new SystemInfoDto { Category = SystemInfoCategory.VideoCard, Name = caption, Value = HeaderValueDto.Instance }; AddVideoCardProperties(managementObject, info.Childs); yield return(info); } } } }
public IEnumerable <SystemInfoDto> FetchInformation() { using (var searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_NetworkAdapter")) using (var results = searcher.Get()) { foreach (var managementObject in results.Cast <ManagementObject>()) { if (managementObject.TryGetProperty("Caption", out string caption)) { var networkAdapter = new SystemInfoDto { Name = caption, Category = SystemInfoCategory.Network, Value = HeaderValueDto.Instance }; networkAdapter.Childs.AddRange(GetNetworkAdapterProperties(managementObject)); yield return(networkAdapter); } } } }
public IEnumerable <(SystemInfoDto, string deviceId)> QueryPartitions(string deviceId) { using (var searcher = new ManagementObjectSearcher("root\\CIMV2", $"ASSOCIATORS OF {{Win32_DiskDrive.DeviceID='{deviceId}'}} WHERE ASSOCCLASS=Win32_DiskDriveToDiskPartition")) using (var results = searcher.Get()) { foreach (var managementObject in results.Cast <ManagementObject>()) { if (managementObject.TryGetProperty("Caption", out string caption)) { var driveRoot = new SystemInfoDto { Name = caption, Value = HeaderValueDto.Instance }; driveRoot.Childs.AddRange(GetPartitionProperties(managementObject)); yield return(driveRoot, (string)managementObject.Properties["DeviceID"].Value); } } } }
public async Task <SystemInfoDto> CheckAsync() { SystemInfoDto si = new SystemInfoDto(); try { using (var c = this.OpenConnection) { // arbitrary select statement. var cc = await c.QueryAsync("SELECT top 1 * FROM Customers"); si.DbWorks = true; } } catch (Exception ex) { si.DbWorks = false; si.DbCheckError = ex.Message; } return(si); }
public void LoggingSystemInfo(SystemInfoDto systemInfo, LogAction logAction) { logAction.SystemInfoQueryId = _logging.CreateLogSystemInfo(Mapper.Map <LogSystemInfo>(systemInfo)); _logging.CreateLogAction(logAction); }
public async Task <SystemInfoDto> GetInfoAsync() { SystemInfoDto si = await this._systemInfoRepository.CheckAsync(); return(si); }