public void CreateTasksInfo() { //////////////////////////////////////////////////// // Данные о заданиях планировщика Windows // TaskService ts = new TaskService(); List <TaskItem> taskItems = new List <TaskItem>(); foreach (Microsoft.Win32.TaskScheduler.Task SelestTask in ts.AllTasks.ToList()) { if (SelestTask.Name.StartsWith(Cliest.TaskPrefix)) { taskItems.Add(new TaskItem() { Name = SelestTask.Name, State = SelestTask.State.ToString(), LastTaskResult = String.Format("0x{0:X}", SelestTask.LastTaskResult), LastRunTime = SelestTask.LastRunTime, NextRunTime = SelestTask.NextRunTime }); } } TaskDataCollection ThisComp = new TaskDataCollection { Company = Cliest.Company, CompanyPrefix = Cliest.CompanyPrefix, TaskItems = taskItems }; // Сохранение пакета данных о задачах DataFileSave TaskFile = new DataFileSave { FileName = "task", json = JsonConvert.SerializeObject(ThisComp, Formatting.Indented) }; TaskFile.Save(); }
public void CreateSystemInfo() { //////////////////////////////////////////////////// // Данные о системе // // Получение данных о объеме памяти в системе PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes"); MemoryStatus status = MemoryStatus.CreateInstance(); ulong ram = status.TotalPhys; List <disk> drives = new List <disk>(); foreach (var drive in DriveInfo.GetDrives()) { if (drive.DriveType == DriveType.Fixed || drive.DriveType == DriveType.Removable) { disk driv = new disk(); driv.Name = drive.Name; driv.DiskType = drive.DriveType; driv.IsReady = drive.IsReady; if (drive.IsReady) { driv.DriveFormat = drive.DriveFormat; driv.AvailableFreeSpace = drive.AvailableFreeSpace; driv.TotalFreeSpace = drive.TotalFreeSpace; driv.TotalSize = drive.TotalSize; driv.VolumeLabel = drive.VolumeLabel; } drives.Add(driv); } } OperatingSystem os = Environment.OSVersion; List <Dictionary <string, string> > dicPerfOS = ProcessorInf.GetPerfOS(); List <PerfOS> perfOS = new List <PerfOS>(); foreach (var dic in dicPerfOS) { perfOS.Add(new PerfOS { Name = dic["Name"], InterruptsPersec = Int32.Parse(dic["InterruptsPersec"]), PercentIdleTime = Int32.Parse(dic["PercentIdleTime"]), PercentPrivilegedTime = Int32.Parse(dic["PercentPrivilegedTime"]), PercentProcessorTime = Int32.Parse(dic["PercentProcessorTime"]), PercentUserTime = Int32.Parse(dic["PercentUserTime"]) }); } ProcessorInfo procInfo = new ProcessorInfo { Name = ProcessorInf.GetName(), ProcessorCount = Environment.ProcessorCount, PerfOS = perfOS }; SysInfo sysInf = new SysInfo { ComputerName = Environment.MachineName, Processor = procInfo, Memory = ram / 1024 / 1024, MemoryFree = (int)ramCounter.NextValue(), UpTime = Environment.TickCount, OSVersion = os.Version, Platform = os.Platform, ServicePack = os.ServicePack, VerString = os.VersionString, drives = drives }; // Формирование набора данных с информацией о системе SysDataCollection ThisComp = new SysDataCollection { Company = Cliest.Company, CompanyPrefix = Cliest.CompanyPrefix, SystemInfo = sysInf }; // Сохранение пакета данных о системе DataFileSave SysFile = new DataFileSave { FileName = "system", json = JsonConvert.SerializeObject(ThisComp, Formatting.Indented) }; SysFile.Save(); }