private dynamic BuildClassReport(dynamic className, string query) { Stopwatch sw = Stopwatch.StartNew(); try { using (ManagementObjectSearcher managementObjectSearcher = new ManagementObjectSearcher(query)) { List <dynamic> properties = new List <dynamic>(); dynamic firstRow = new ExpandoObject(); foreach (ManagementBaseObject wmiRow in managementObjectSearcher.Get()) { var propertyDataCollection = wmiRow.Properties; foreach (PropertyData property in propertyDataCollection) { object propertyValue; WmiUtils.TryGetProperty(wmiRow, property.Name, out propertyValue); ((IDictionary <string, object>)firstRow)[property.Name] = propertyValue; properties.Add(new { property.Name, property.Type, TypeName = ((System.Management.CimType)property.Type).ToString(), property.IsArray, property.IsLocal, property.Origin, FirstValue = propertyValue, }); } break; } return(new { ClassName = className, Duration = sw.ElapsedMilliseconds.ToString("n0"), Properties = properties, Exception = (string)null, ExceptionInfo = (string)null, }); } } catch (Exception ex) { return(new { ClassName = className, Duration = sw.ElapsedMilliseconds.ToString("n0"), Exception = ex.ToString(), ExceptionInfo = GetExeptionDigest(ex), }); } }
private void BtnNew_Click(object sender, RoutedEventArgs e) { if (!string.IsNullOrEmpty(TxtFreeMemory.Text)) { int availMB = WmiUtils.GetAvailablePhysicalMemory(); if (availMB < 0) { MessageBox.Show("无法获取当前空闲内存!请自行检查当前可用内存。", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error); } else if (int.Parse(TxtFreeMemory.Text) < availMB) { Initializer.Config.memoryTotal = WmiUtils.GetTotalPhysicalMemory(); } else { MessageBox.Show("内存设置大于系统可用空闲内存!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error); return; } Initializer.Config.memoryLimit = int.Parse(TxtFreeMemory.Text); Initializer.WriteConfig(); // 新建任务。具体实现请见Gui/wizardWindow try { var wizard = new WizardWindow(wm); wizard.ShowDialog(); int activeTaskCount = tm.GetActiveTaskCount(); BtnRun.IsEnabled = activeTaskCount > 0; BtnDelete.IsEnabled = activeTaskCount > 0; BtnEmpty.IsEnabled = activeTaskCount > 0; BtnMoveDown.IsEnabled = activeTaskCount > 1; BtnMoveUp.IsEnabled = activeTaskCount > 1; BtnMoveTop.IsEnabled = activeTaskCount > 2; BtnChap.IsEnabled = activeTaskCount > 0; } catch (Exception ex) { Logger.Fatal(ex.StackTrace); Environment.Exit(0); } } else { MessageBox.Show("请输入系统可用空闲内存!", "OKEGui", MessageBoxButton.OK, MessageBoxImage.Error); } }
public MainWindow() { InitializeComponent(); Version version = Assembly.GetExecutingAssembly().GetName().Version; Title += " v" + version; TaskList.ItemsSource = tm.taskStatus; wm = new WorkerManager(this, tm); BtnRun.IsEnabled = false; BtnMoveDown.IsEnabled = false; BtnMoveUp.IsEnabled = false; BtnMoveTop.IsEnabled = false; BtnPause.IsEnabled = false; BtnResume.IsEnabled = false; BtnChap.IsEnabled = false; BtnDelete.IsEnabled = false; BtnEmpty.IsEnabled = false; BtnCancelShutdown.IsEnabled = false; // 初始的worker数量等于Numa数量。 int numaCount = NumaNode.NumaCount; for (int i = 0; i < numaCount; i++) { WorkerCount++; wm.AddWorker("工作单元-" + WorkerCount.ToString()); } WorkerNumber.Text = "工作单元:" + WorkerCount.ToString(); // 初始化更新菜单 _systemMenu = new SystemMenu(this); _systemMenu.AddCommand("检查更新(&U)", () => { Updater.CheckUpdate(true); }, true); if (Initializer.Config.memoryTotal == WmiUtils.GetTotalPhysicalMemory()) { TxtFreeMemory.Text = Initializer.Config.memoryLimit.ToString(); } }