/** * <summary> * grava o valor de uma chave no registro do windows. * <para> * <paramref name="ListaCamposValores"/> - Contém um conjunto de chaves e valores que serão gravados no registro do windwos. * </para> * </summary> */ public bool Gravar_ConteudoCampo(TipoChave TipoChave, string Chave, ref List <KeyValuePair <string, string> > ChavesAndValores) { try { if (TipoChave == TipoChave.LocalMachine) { RegistryKey CORAC = LocalMachine.OpenSubKey(Chave, true); foreach (KeyValuePair <string, string> Chaves in ChavesAndValores) { CORAC.SetValue(Chaves.Key, Chaves.Value); } ChavesAndValores.Clear(); return(true); } else { RegistryKey CORAC = Corrente_User.OpenSubKey(Chave, true); foreach (KeyValuePair <string, string> Chaves in ChavesAndValores) { CORAC.SetValue(Chaves.Key, Chaves.Value); } ChavesAndValores.Clear(); return(true); } } catch (Exception e) { TratadorErros(e, GetType().Name); return(false); } }
public void SnapshotLimitZero() { // Setup LocalMachine machine = LocalMachine.New("Test", null); int deleteSnapshotCount = 0; int createSnapshotCount = 0; machine.SnapshotLimit = 0; machine.Auditors += (a) => { switch (a.Type) { case CoreRequest.Types.CreateSnapshot: createSnapshotCount++; break; case CoreRequest.Types.DeleteSnapshot: deleteSnapshotCount++; break; } }; // Act TestHelpers.Run(machine, 400000); // Verify Assert.Zero(createSnapshotCount); Assert.Zero(deleteSnapshotCount); }
public void Setup() { _bookmarkTicks = new List <UInt64>(); LocalMachineTests machineTests = new LocalMachineTests(); machineTests.Setup(); using (LocalMachine machine = machineTests.CreateMachine()) { RunForAWhile(machine); machine.Key(Keys.A, true); RunForAWhile(machine); machine.Key(Keys.A, false); RunForAWhile(machine); machine.LoadDisc(0, null); RunForAWhile(machine); machine.LoadTape(null); RunForAWhile(machine); machine.AddBookmark(false); _bookmarkTicks.Add(machine.Ticks); RunForAWhile(machine); machine.AddBookmark(false); _bookmarkTicks.Add(machine.Ticks); Run(machine, 4000000); _finalHistoryEvent = machine.History.CurrentEvent; } }
/// <summary> /// Adds local services found with a specific pattern specified by users. /// </summary> private void AutoAddLocalServices() { if (!Settings.Default.AutoAddServicesToMonitor) { return; } // Verify if MySQL services are present on the local machine var autoAddPattern = Settings.Default.AutoAddPattern; var localServicesList = LocalMachine.GetWmiServices(autoAddPattern, true, false); var servicesToAddList = localServicesList.Cast <ManagementObject>().Where(mo => mo != null && Service.IsRealMySqlService(mo.Properties["Name"].Value.ToString(), false) && !LocalMachine.ContainsServiceByName(mo.Properties["Name"].Value.ToString())).ToList(); // If we found some services we will try to add the local machine to the list... if (servicesToAddList.Count <= 0) { return; } ChangeMachine(LocalMachine, ListChangeType.AutoAdd); // Try to add the services we found on it. var servicesList = servicesToAddList.Select(mo => new MySqlService(mo.Properties["Name"].Value.ToString(), true, true, LocalMachine)).ToList(); servicesList.Sort(); foreach (var service in servicesList) { service.SetServiceParameters(true); LocalMachine.ChangeService(service, ListChangeType.AutoAdd); } }
/// <summary> /// 检查电脑版本信息 /// </summary> private bool frameworkversioncheck() { bool is64 = Environment.Is64BitOperatingSystem; RegistryKey LocalMachine; if (is64) { LocalMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry64); } else { LocalMachine = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32); } RegistryKey currentversion = LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows NT\CurrentVersion", RegistryKeyPermissionCheck.ReadSubTree); string release = currentversion.GetValue(ReleaseId)?.ToString(); string sysname = currentversion.GetValue(ProductName)?.ToString(); if (!string.IsNullOrEmpty(sysname) && sysname.Contains("Windows 10")) { if (int.Parse(release) > 1511) { return(true); } } return(false); }
private HistoryEvent PromptForBookmark() { LocalMachine machine = _mainViewModel?.ActiveMachine as LocalMachine; using (machine.AutoPause()) { BookmarkSelectWindow dialog = new BookmarkSelectWindow(this, machine); bool?result = dialog.ShowDialog(); if (result.HasValue && result.Value) { if (dialog.SelectedReplayEvent != null) { string name = String.Format("{0} (Replay)", machine.Name); _mainViewModel.OpenReplayMachine(name, dialog.SelectedReplayEvent); return(null); } else if (dialog.SelectedJumpEvent is BookmarkHistoryEvent bookmarkHistoryEvent) { return(bookmarkHistoryEvent); } } return(null); } }
static string GetExePath(string subName) { try { var key = LocalMachine.OpenSubKey($"SOFTWARE\\{subName}"); if (key == null) { key = CurrentUser.OpenSubKey($"SOFTWARE\\{subName}"); if (key == null) { key = ClassesRoot.OpenSubKey($"VirtualStore\\MACHINE\\SOFTWARE\\{subName}"); if (key == null) { return(null); } } } var path = key.GetValue("Installed Path") as string; if (File.Exists(path)) { path = Path.GetDirectoryName(path); } return(string.IsNullOrEmpty(path) || !Directory.Exists(path) ? null : path); } catch { return(null); } }
public void Setup() { _remoteServersSetting = String.Empty; _mockSettings = new Mock <ISettings>(MockBehavior.Strict); _mockSettings.SetupGet(x => x.RecentlyOpened).Returns(() => _settingGet); _mockSettings.SetupSet(x => x.RecentlyOpened = It.IsAny <string>()); _mockSettings.SetupGet(x => x.RemoteServers).Returns(() => _remoteServersSetting); _mockSettings.SetupSet(x => x.RemoteServers = It.IsAny <string>()); _mockFileSystem = new Mock <IFileSystem>(MockBehavior.Strict); _mockFileSystem.Setup(fileSystem => fileSystem.DeleteFile(AnyString())); _mockFileSystem.Setup(fileSystem => fileSystem.ReplaceFile(AnyString(), AnyString())); _mockFileSystem.Setup(fileSystem => fileSystem.FileLength(AnyString())).Returns(100); _mockFileSystem.Setup(fileSystem => fileSystem.Exists(AnyString())).Returns(true); _mockFileSystem.Setup(ReadBytes()).Returns(new byte[1]); MockTextFile mockTextFile = new MockTextFile(); _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(AnyString())).Returns(mockTextFile); _mockSocket = new Mock <ISocket>(); _machine = LocalMachine.New("test", null); _mainViewModel = new MainViewModel(_mockSettings.Object, _mockFileSystem.Object); _mainViewModel.Model.AddMachine(_machine); }
public void MachineUnsubscribe() { // Setup LocalMachine machine1 = LocalMachine.New(null, null); LocalMachine machine2 = LocalMachine.New(null, null); _file.Machine = machine1; _file.Machine = machine2; // Act machine1.Name = "Test1"; int len1 = _mockFile.LineCount(); machine2.Name = "Test2"; int len2 = _mockFile.LineCount(); _file.Machine = null; machine1.Name = "Test3"; machine2.Name = "Test4"; int len3 = _mockFile.LineCount(); // Verify Assert.Zero(len1); Assert.NotZero(len2); Assert.AreEqual(len2, len3); }
public void Compact() { // Setup string tmpFilename = String.Format("{0}.tmp", _filename); LocalMachine machine = LocalMachine.OpenFromFile(_mockFileSystem.Object, _filename); machine.Close(); MockTextFile mockNewTextFile = new MockTextFile(); _mockFileSystem.Setup(fs => fs.OpenTextFile(tmpFilename)).Returns(mockNewTextFile); // Act machine.Compact(_mockFileSystem.Object); // Verify int keyLineCount = 0; string line; while ((line = mockNewTextFile.ReadLine()) != null) { if (line.StartsWith("key:")) { keyLineCount++; } } Assert.AreEqual(1, keyLineCount); _mockFileSystem.Verify(fs => fs.ReplaceFile(_filename, tmpFilename), Times.Once()); }
/** * <summary> * Cria os campos de configuração do sistema CORAC, baseado na STRUCT camposCORAC. Caminho da chave SOFTWARE/corac. * <para>eturn bools</para> * </summary> */ public bool Criar_Chaves_Campos_CORAC() { try { RegistryKey CORAC = LocalMachine.CreateSubKey("SOFTWARE\\CORAC"); CamposCORAC CMP = new CamposCORAC(); System.Reflection.FieldInfo[] Campos = CMP.GetType().GetFields(); foreach (System.Reflection.FieldInfo CPMIndividual in Campos) { string Tipo = CPMIndividual.FieldType.Name; Tipo = Tipo == "Boolean" ? "false" : ""; CORAC.SetValue(CPMIndividual.Name, Tipo); } CORAC.Close(); return(true); } catch (Exception e) { TratadorErros(e, GetType().Name); return(false); } }
public void NoPropertyChangedHandlers() { // Setup LocalMachine machine = LocalMachine.New("Test", null); // Act and Verify Assert.DoesNotThrow(() => machine.SnapshotLimit = machine.SnapshotLimit + 42); }
public void PersistAlreadyPersistedMachine() { // Setup LocalMachine machine = LocalMachine.OpenFromFile(_mockFileSystem.Object, _filename); // Act and Verify Assert.Throws <InvalidOperationException>(() => machine.Persist(_mockFileSystem.Object, _filename)); }
public void PersistToEmptyFilename() { // Setup LocalMachine machine = LocalMachine.New("Test", null); // Act and Verify Assert.Throws <ArgumentException>(() => machine.Persist(_mockFileSystem.Object, "")); }
public void CanCompactClosedMachine() { // Setup LocalMachine machine = LocalMachine.New("Test", "test.cpvc"); // Verify Assert.True(_mainViewModel.CompactCommand.CanExecute(machine)); }
public void Setup() { _mockFileSystem = new Mock <IFileSystem>(); MockTextFile mockTextFile = new MockTextFile(); _mockFileSystem.Setup(fileSystem => fileSystem.OpenTextFile(TestHelpers.AnyString())).Returns(mockTextFile); _machine = LocalMachine.New("test", null); _mockSettings = new Mock <ISettings>(); _mainModel = new MainModel(_mockSettings.Object, null); }
public void CanCompactOpenMachine() { // Setup LocalMachine machine = LocalMachine.New("Test", "test.cpvc"); machine.OpenFromFile(_mockFileSystem.Object); // Verify Assert.False(_mainViewModel.CompactCommand.CanExecute(machine)); }
public void AddMachineTwice() { // Setup _mainModel.AddMachine("test.cpvc", _mockFileSystem.Object, true); // Act LocalMachine machine = _mainModel.AddMachine("test.cpvc", _mockFileSystem.Object, true); // Verify Assert.IsNull(machine); }
public void NewMachineHasIdleRequestHandler() { // Setup using (LocalMachine machine = LocalMachine.New("test", null)) { // Act RunForAWhile(machine); // Verify Assert.Greater(machine.Ticks, 0); } }
public void WriteAndReadName() { // Setup LocalMachine machine = LocalMachine.New(String.Empty, null); _file.Machine = machine; // Act machine.Name = "Test"; _fileInfo = MachineFile.Read(_mockFile); // Verify Assert.AreEqual(machine.Name, _fileInfo.Name); }
public void SnapshotLimitPropertyChanged() { // Setup LocalMachine machine = LocalMachine.OpenFromFile(_mockFileSystem.Object, _filename); Mock <PropertyChangedEventHandler> propChanged = new Mock <PropertyChangedEventHandler>(); machine.PropertyChanged += propChanged.Object; // Act - note that setting the property to itself should not trigger the "property changed" event. machine.SnapshotLimit = machine.SnapshotLimit; machine.SnapshotLimit = machine.SnapshotLimit + 42; // Verify propChanged.Verify(p => p(machine, It.Is <PropertyChangedEventArgs>(e => e.PropertyName == nameof(machine.SnapshotLimit))), Times.Once()); }
private void ShowChangelog() { object LastLaunchedVersion = LocalMachine.OpenSubKey(@"SOFTWARE\TEKLauncher")?.GetValue("LastLaunchedVersion"); if ((string)LastLaunchedVersion != Version) { LocalMachine.CreateSubKey(@"SOFTWARE\TEKLauncher").SetValue("LastLaunchedVersion", Version); if (Settings.DwThreadsCount == 6) { Settings.DwThreadsCount = 20; } if (!(LastLaunchedVersion is null)) { new ChangelogWindow().Show(); } } }
/// <summary> /// Performs load operations that have to be done after the settings file was de-serialized. /// </summary> public void InitialLoad() { LocalMachine = GetMachineByName(MySqlWorkbenchConnection.DEFAULT_HOSTNAME) ?? new Machine(); LocalMachine.LoadServicesParameters(true); OnMachineListChanged(LocalMachine, ListChangeType.AutoAdd); RecreateInvalidScheduledTask(); MigrateOldServices(); AutoAddLocalServices(); if (!Settings.Default.FirstRun) { return; } Notifier.CreateScheduledTask(); Settings.Default.FirstRun = false; SaveToFile(); }
private MainViewModel SetupViewModel(int machineCount) { _settingGet = String.Join(",", Enumerable.Range(0, machineCount).Select(x => String.Format("test{0}.cpvc", x))); MainViewModel viewModel = new MainViewModel(_mockSettings.Object, _mockFileSystem?.Object); // Create a Replay machine. HistoryEvent historyEvent = null; using (LocalMachine machine = CreateTestMachine()) { historyEvent = machine.History.CurrentEvent; } viewModel.OpenReplayMachine("Test Replay", historyEvent); return(viewModel); }
protected virtual void Dispose(bool disposing) { if (disposing) { if (disposed) { return; } UserAccount.Dispose(); UserAccount.Shutdown.Wait(); LocalMachine.Dispose(); LocalMachine.Shutdown.Wait(); Secure.Dispose(); Secure.Shutdown.Wait(); disposed = true; } }
internal StartupWindow() { InitializeComponent(); if (LocCulture == "ar") { FreeDiskSpaceStack.FlowDirection = FlowDirection.RightToLeft; FreeDiskSpaceStack.HorizontalAlignment = HorizontalAlignment.Left; } string SteamGamePath = (string)LocalMachine?.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 346110")?.GetValue("InstallLocation"); if (!(SteamGamePath is null) && FileExists($@"{SteamGamePath}\ShooterGame\Binaries\Win64\ShooterGame.exe")) { Path = SteamGamePath; Selector.Tag = "D"; Selector.SetPath(SteamGamePath); ContinueButton.IsEnabled = true; } }
public void Dispose() { // Setup LocalMachine machine1 = LocalMachine.New(null, null); machine1.Name = "Test"; _history.AddCoreAction(CoreAction.Reset(100)); int len1 = _mockFile.LineCount(); // Act _file.Dispose(); machine1.Name = "Test"; _history.AddCoreAction(CoreAction.Reset(100)); int len2 = _mockFile.LineCount(); // Verify Assert.NotZero(len1); Assert.AreEqual(len1, len2); }
public LocalMachine CreateMachine() { LocalMachine machine = LocalMachine.New("test", null); machine.Auditors += _mockAuditor.Object; // For consistency with automated builds, use all zero ROMs. byte[] zeroROM = new byte[0x4000]; machine.Core.SetLowerROM(zeroROM); machine.Core.SetUpperROM(0, zeroROM); machine.Core.SetUpperROM(7, zeroROM); machine.Core.IdleRequest = () => { return((machine.RunningState == RunningState.Running) ? CoreRequest.RunUntil(machine.Core.Ticks + 10) : null); }; return(machine); }
public void Setup() { _mockFileSystem = new Mock <IFileSystem>(MockBehavior.Strict); _mockFileSystem.Setup(fileSystem => fileSystem.DeleteFile(AnyString())); _mockFileSystem.Setup(fileSystem => fileSystem.ReplaceFile(AnyString(), AnyString())); _mockFileSystem.Setup(fileSystem => fileSystem.FileLength(AnyString())).Returns(100); _mockTextFile = new MockTextFile(); _mockTextFile.WriteLine("name:Test"); _mockTextFile.WriteLine("key:1,10,58,True"); _mockTextFile.WriteLine("key:2,20,58,False"); _mockTextFile.WriteLine("current:1"); _mockTextFile.WriteLine("deletebranch:2"); _mockFileSystem.Setup(fs => fs.OpenTextFile(_filename)).Callback(() => _mockTextFile.SeekToStart()).Returns(_mockTextFile); _mockAuditor = new Mock <MachineAuditorDelegate>(); _machine = CreateMachine(); }
public BookmarkSelectWindow(Window owner, LocalMachine machine) { InitializeComponent(); _machine = machine; _viewModel = new BookmarksViewModel(_machine.History); _display = new Display(); Owner = owner; ReplayCommand = new Command( p => { if (_viewModel.SelectedItems.Count == 1) { SelectedReplayEvent = _viewModel.SelectedItems[0].HistoryEvent; DialogResult = true; } }, p => _viewModel.SelectedItems.Count == 1 ); JumpCommand = new Command( p => { if (_viewModel.SelectedItems.Count == 1) { SelectedJumpEvent = _viewModel.SelectedItems[0].HistoryEvent; DialogResult = true; } }, p => _viewModel.SelectedItems.Count == 1 && _viewModel.SelectedItems[0].HistoryEvent is BookmarkHistoryEvent ); DataContext = _viewModel; }