/// <summary> /// 获取选中行的信息 /// </summary> /// <returns></returns> private RemoteMachine RemoteMachineGetRows() { RemoteMachine remoteMachine = new RemoteMachine(); int z = dataGridView1.CurrentRow.Index; remoteMachine.DesktopName = dataGridView1.Rows[z].Cells["服务器"].Value.ToString(); remoteMachine.WWW = dataGridView1.Rows[z].Cells["备注"].Value.ToString(); remoteMachine.Server = dataGridView1.Rows[z].Cells["ip"].Value.ToString(); remoteMachine.UserName = dataGridView1.Rows[z].Cells["账号"].Value.ToString(); remoteMachine.Password = dataGridView1.Rows[z].Cells["密码"].Value.ToString(); remoteMachine.Type = dataGridView1.Rows[z].Cells["类型"].Value.ToString(); //共享磁盘 if (checkBox1.Checked == true) { remoteMachine.RedirectDrives = true; } //共享打印机 if (checkBox2.Checked == true) { remoteMachine.RedirectPrinters = true; } //共享端口 if (checkBox3.Checked == true) { remoteMachine.RedirectPorts = true; } return(remoteMachine); }
private void PsUpdateExited(string psPath, TextBlock statusText, RemoteMachine client) { string readtext = System.IO.File.ReadAllText(psPath); if (readtext.Contains("Update Completed") && !readtext.Contains("Update Not Running")) { client.Status = "Success"; statusText.Dispatcher.Invoke(new Action(() => { statusText.Text = "Success"; })); RemoteMachineList.Dispatcher.Invoke(new Action(() => { RemoteMachineList.Items.Refresh(); })); } else { client.Status = "Failed"; //statusText.Text = "Failed"; //RemoteMachineList.Items.Refresh(); statusText.Dispatcher.Invoke(new Action(() => { statusText.Text = "Failed"; })); RemoteMachineList.Dispatcher.Invoke(new Action(() => { RemoteMachineList.Items.Refresh(); })); } }
/// <summary> /// Actualiza los datos de la lista de usuarios /// </summary> private void updateUserList() { NetUser[] netUsers = netUserList.userListToArray(); for (int i = 0; i < netUsers.Length; i++) { //decrementa el time out, para algoritmo de perdida de señal netUsers[i].qualityDown(configuration.NetData); //si llega a cero el time out, se ha ido de la red, hay que sacarlo if (netUsers[i].Timeout < 0) { disconnectNetUser(netUsers[i]); } else { if (netUsers[i].SignalQuality == NetUserQuality.LOW || netUsers[i].SignalQuality == NetUserQuality.NORMAL) { RemoteMachine remoteMachine = netHandler.TcpServerList.getRemoteMachine(netUsers[i].Ip); if (remoteMachine == null && netUsers[i].JumpsAway == 1) { if (netUsers[i].WaitTimeOut <= 0) { netUsers[i].WaitTimeOut = configuration.NetData.WaitForTCPConnection; netHandler.connectTo(netUsers[i].Ip); } else { netUsers[i].WaitTimeOut--; } } } produceEvent(CommunicationEvent.REFRESHUSER, netUsers[i]); } } }
static public void ProcessRemoteRequest(RemoteMachine machine, ReceiveCoreActionDelegate receive, CoreAction action) { ManualResetEvent e = new ManualResetEvent(false); RequestProcessedDelegate processed = (c, r, a) => { if (c == machine.Core && (r == null || r == action)) { e.Set(); } }; machine.Core.Auditors += processed; receive(action); machine.Start(); bool result = false; while (!result) { result = e.WaitOne(100); machine.AdvancePlayback(100000); } machine.Core.Auditors -= processed; machine.Stop(); if (!result) { throw new TimeoutException("Timeout while waiting for request to process."); } }
private List <RemoteMachine> Sourcebind(string path) { inipath = path; ini = new IniFile(path); macs = RemoteMachine.Load(ini); return(macs); }
private Task UpdateMachineMultiThread(RemoteMachine mech, int i) { //allows for updates to be run at the same time. otherwise, each task stays in queue until al awaits have finished return(Task.Run(() => { UpdateMachine(mech, i); })); }
public void CanClose() { // Setup using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object)) { // Verify Assert.True(machine.CanClose); } }
/// <summary> /// 数据源获取 /// </summary> /// <param name="path"></param> /// <returns></returns> private List <RemoteMachine> Sourcebind(string path) { string type = comboBoxType.Text; inipath = path; ini = new IniFile(path); macs = RemoteMachine.Load(ini, type, "1"); return(macs); }
public Form2(RemoteMachine remoteMachine) { InitializeComponent(); textBox1.Text = remoteMachine.DesktopName; textBox1.Enabled = false; textBox2.Text = remoteMachine.WWW; textBox3.Text = remoteMachine.Server; textBox4.Text = remoteMachine.UserName; textBox5.Text = remoteMachine.Password; }
public async Task ChangeOfficeChannelWmi(RemoteMachine client, OfficeInstallation localInstall) { var newChannel = client.Channel.ToString(); string version = null; if (client.Version != null) { version = client.Version.ToString(); } await Task.Run(async() => { var installOffice = new InstallOfficeWmi { remoteUser = client.UserName, remoteComputerName = client.Machine, remoteDomain = client.WorkGroup, remotePass = client.Password, newChannel = client.Channel.ToString(), newVersion = version, connectionNamespace = "\\root\\cimv2" }; try { var ppDownloader = new ProPlusDownloader(); var baseUrl = await ppDownloader.GetChannelBaseUrlAsync(newChannel, OfficeEdition.Office32Bit); if (string.IsNullOrEmpty(baseUrl)) { throw (new Exception(string.Format("Cannot find BaseUrl for Channel: {0}", newChannel))); } var channelToChangeTo = newChannel; if (string.IsNullOrEmpty(channelToChangeTo)) { throw (new Exception("Version required")); } await installOffice.ChangeOfficeChannel(channelToChangeTo, baseUrl); var installGenerator = new OfficeInstallManager(); } catch (Exception ex) { LogWmiErrorMessage(ex, new RemoteComputer() { Name = client.Machine, Domain = client.WorkGroup, UserName = client.UserName, Password = client.Password }); throw (new Exception("Update Failed")); } }); }
private void Sc_Click(object sender, EventArgs e) { RemoteMachine remoteMachine = RemoteMachineGetRows(); if (MessageBox.Show(string.Format("确认删除\"{0}\"?", remoteMachine.DesktopName), "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { remoteMachine.Delete(this.ini); this.DialogResult = System.Windows.Forms.DialogResult.OK; } LoadIni(Path.Combine(Application.StartupPath, "config.ini")); }
/// <summary> /// 修改选中行的信息 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { RemoteMachine remoteMachine = RemoteMachineGetRows(); using (Form2 form2 = new Form2(remoteMachine)) { if (form2.ShowDialog() == DialogResult.OK) { LoadIni(Path.Combine(Application.StartupPath, "config.ini")); } } }
public void Key() { // Setup using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object)) { // Act machine.Key(Keys.A, true); // Verify _mockRemote.Verify(remote => remote.SendCoreRequest(It.Is <CoreRequest>(request => request.Type == CoreRequest.Types.KeyPress && request.KeyCode == Keys.A && request.KeyDown)), Times.Once()); } }
public void ReceiveName() { // Setup using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object)) { // Act _receiveName("Test"); // Verify Assert.AreEqual("Test (remote)", machine.Name); } }
/// <summary> /// 获取选中行的信息 /// </summary> /// <returns></returns> private RemoteMachine RemoteMachineGetRows() { RemoteMachine remoteMachine = new RemoteMachine(); int z = dataGridView1.CurrentRow.Index; remoteMachine.DesktopName = dataGridView1.Rows[z].Cells["服务器"].Value.ToString(); remoteMachine.WWW = dataGridView1.Rows[z].Cells["域名"].Value.ToString(); remoteMachine.Server = dataGridView1.Rows[z].Cells["ip"].Value.ToString(); remoteMachine.UserName = dataGridView1.Rows[z].Cells["账号"].Value.ToString(); remoteMachine.Password = dataGridView1.Rows[z].Cells["密码"].Value.ToString(); return(remoteMachine); }
public void Reset() { // Setup using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object)) { // Act machine.Reset(); // Verify _mockRemote.Verify(remote => remote.SendCoreRequest(It.Is <CoreRequest>(request => request.Type == CoreRequest.Types.Reset)), Times.Once()); } }
public void LoadTape() { // Setup using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object)) { // Act machine.LoadTape(new byte[] { 0x01, 0x02 }); // Verify _mockRemote.Verify(remote => remote.SendCoreRequest(It.Is <CoreRequest>(request => request.Type == CoreRequest.Types.LoadTape && request.MediaBuffer.GetBytes().SequenceEqual(new byte[] { 0x01, 0x02 }))), Times.Once()); } }
public void CloseConnection() { // Setup using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object)) { // Act _closeConnection(); // Verify Assert.AreEqual("Connection closed", machine.Status); } }
private void buttonAddRemote_Click(object sender, RoutedEventArgs e) { try { RemoteMachine rm = new RemoteMachine("New Office", "New Computer", "New Directory"); this.Settings.Options.RemoteOptions.Add(rm); } catch (Exception ex) { string message = ex.Message; } }
/// <summary> /// 连接按钮 连接服务器 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { #region 原本的代码,初始连接尝试----通过----逻辑无错误 //if (Lj.Text == "连接") //{ // string ip= "118.24.20.161"; // string user = "******"; // string pwd = "2018"; // try // { // rdp.Server = ip; // rdp.UserName = user; // IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx(); // secured.ClearTextPassword = pwd; // rdp.Dock = DockStyle.Fill; // rdp.Connect(); // Lj.Text = "断开连接"; // Lj.BackColor = Color.Red; // } // catch (Exception ex) // { // MessageBox.Show(ex.Message); // return; // } //} //else //{ // Lj.Text = "连接"; // Lj.BackColor = Color.PaleGreen; // try // { // rdp.Disconnect(); // } // catch (Exception ex) // { // MessageBox.Show("断开连接失败:" + ex.Message); // return; // } //} #endregion RemoteMachine mac = RemoteMachineGetRows(); try { Form3 df = new Form3(mac); df.Show(); } catch (Exception ex) { } }
public void Dispose(int displayCount) { // Setup RemoteMachine machine = new RemoteMachine(_mockRemote.Object); // Act for (int c = 0; c < displayCount; c++) { machine.Dispose(); } // Verify Assert.Null(machine.Core); _mockRemote.Verify(r => r.Dispose(), Times.Exactly(displayCount)); }
public void EmptyRemoteServers() { // Setup MainViewModel viewModel = SetupViewModel(1); Mock <IRemote> mockRemote = new Mock <IRemote>(); RemoteMachine machine = new RemoteMachine(mockRemote.Object); viewModel.SelectRemoteMachine += (sender, e) => { e.SelectedMachine = machine; }; // Act viewModel.ConnectCommand.Execute(null); // Verify Assert.AreEqual(machine, viewModel.ActiveMachine); _mockSettings.VerifySet(s => s.RemoteServers = ""); }
private void MachineListBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) { if (!(_machineListBox.SelectedItem is string machineName)) { return; } IConnection connection = SocketConnection.ConnectToServer(new Socket(), _serverInfo.ServerName, _serverInfo.Port); Remote remote = new Remote(connection); RemoteMachine machine = new RemoteMachine(remote); remote.SendSelectMachine(machineName); _remoteMachine = machine; DialogResult = true; }
public void ReceiveCoreAction() { // Setup using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object)) { machine.Start(); // Act CoreAction action = CoreAction.RunUntil(0, 1, null); _receiveCoreAction(action); TestHelpers.ProcessOneRequest(machine.Core, action); // Verify Assert.Greater(machine.Ticks, 0); } }
public Form3(RemoteMachine remoteMachine) { InitializeComponent(); rdp.Width = this.Size.Width; rdp.Height = this.Size.Height; rdp.Server = remoteMachine.Server; rdp.UserName = remoteMachine.UserName; IMsTscNonScriptable secured = (IMsTscNonScriptable)rdp.GetOcx(); secured.ClearTextPassword = remoteMachine.Password; rdp.Dock = DockStyle.Fill; this.Text = remoteMachine.DesktopName; //if (!string.IsNullOrEmpty(remoteMachine.Password)) //rdp.AdvancedSettings5.ClearTextPassword = remoteMachine.Password; rdp.AdvancedSettings5.RedirectDrives = remoteMachine.RedirectDrives; rdp.AdvancedSettings5.RedirectPrinters = remoteMachine.RedirectPrinters; rdp.AdvancedSettings5.RedirectPorts = remoteMachine.RedirectPorts; }
private void buttonDeleteRemote_Click(object sender, RoutedEventArgs e) { try { if (null != dataGridRemote.SelectedItems && dataGridRemote.SelectedItems.Count > 0) { for (int i = dataGridRemote.SelectedItems.Count - 1; i > -1; i--) { RemoteMachine rm = dataGridRemote.SelectedItems[i] as RemoteMachine; this.Settings.Options.RemoteOptions.Remove(rm); } } } catch (Exception ex) { string message = ex.Message; } }
public void ReceiveCoreActionAuditor(bool closed) { // Setup using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object)) { machine.Auditors += _mockAuditor.Object; if (closed) { machine.Close(); } // Act _receiveCoreAction(CoreAction.RunUntil(0, 1, null)); // Verify _mockAuditor.Verify(a => a(It.Is <CoreAction>(action => action.Type == CoreRequest.Types.RunUntil)), Times.Exactly(closed ? 0 : 1)); } }
public void Connect() { // Setup MainViewModel viewModel = SetupViewModel(1); Mock <IRemote> mockRemote = new Mock <IRemote>(); RemoteMachine machine = new RemoteMachine(mockRemote.Object); viewModel.SelectRemoteMachine += (sender, e) => { e.SelectedMachine = machine; viewModel.RecentServers.Add(new ServerInfo("localhost", 6128)); }; // Act viewModel.ConnectCommand.Execute(null); // Verify Assert.AreEqual(machine, viewModel.ActiveMachine); _mockSettings.VerifySet(s => s.RemoteServers = "localhost:6128"); }
/// <summary> /// 操作成功 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button1_Click(object sender, EventArgs e) { try { IniFile iniFile = new IniFile(Path.Combine(Application.StartupPath, "config.ini")); RemoteMachine remoteMachine = new RemoteMachine(); remoteMachine.DesktopName = textBox1.Text; remoteMachine.WWW = textBox2.Text; remoteMachine.Server = textBox3.Text; remoteMachine.UserName = textBox4.Text; remoteMachine.Password = textBox5.Text; RemoteMachine.Save(remoteMachine, iniFile); MessageBox.Show("操作成功"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } this.DialogResult = DialogResult.OK; this.Close(); }
public void ReceiveLoadSnapshot() { // Setup using (RemoteMachine machine = new RemoteMachine(_mockRemote.Object)) { TestHelpers.ProcessRemoteRequest(machine, _receiveCoreAction, CoreAction.RunUntil(0, 100000, null)); TestHelpers.ProcessRemoteRequest(machine, _receiveCoreAction, CoreAction.CreateSnapshot(0, 0)); UInt64 saveSnapshotTicks = machine.Ticks; TestHelpers.ProcessRemoteRequest(machine, _receiveCoreAction, CoreAction.RunUntil(0, 200000, null)); UInt64 preLoadSnapshotTicks = machine.Ticks; // Act TestHelpers.ProcessRemoteRequest(machine, _receiveCoreAction, CoreAction.RevertToSnapshot(0, 0)); UInt64 loadSnapshotTicks = machine.Ticks; // Verify Assert.AreNotEqual(preLoadSnapshotTicks, loadSnapshotTicks); Assert.AreEqual(loadSnapshotTicks, saveSnapshotTicks); } }