MainWindowViewModel.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using CommunityToolkit.Mvvm.ComponentModel;
  2. using CommunityToolkit.Mvvm.Input;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Linq;
  7. using System.Runtime.CompilerServices;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows.Input;
  11. namespace AutoDeploy
  12. {
  13. public class MainWindowViewModel: ObservableObject
  14. {
  15. private MainWindowViewModel()
  16. {
  17. float f = 20;
  18. ushort[] v = new ushort[2] {0x42a0,0x0000 };
  19. byte[] b = new byte[4];
  20. //Unsafe.CopyBlock(ref Unsafe.As<ushort,byte>(ref v[0]), ref Unsafe.As<float, byte>(ref f), 4);
  21. v = v.Reverse().ToArray();
  22. float f1 = Unsafe.As<ushort, float>(ref v[0]);
  23. }
  24. static MainWindowViewModel()
  25. {
  26. }
  27. public ICommand StartCommand => new RelayCommand(Start);
  28. private async void Start()
  29. {
  30. Renci.SshNet.SshClient client = new Renci.SshNet.SshClient(IP, UserName, Password);
  31. client.Connect();
  32. var input = new System.IO.StreamWriter(new System.IO.MemoryStream());
  33. input.AutoFlush = true;
  34. var output = new System.IO.StreamReader(new System.IO.MemoryStream());
  35. var ext = new System.IO.StreamReader(new System.IO.MemoryStream());
  36. client.CreateShell(input.BaseStream, output.BaseStream,ext.BaseStream);
  37. input.WriteLine("opkg update");
  38. Debug.WriteLine(output.ReadLine());
  39. client.Disconnect();
  40. client.Dispose();
  41. }
  42. public string IP { get; set; } = "192.168.1.34";
  43. public string UserName { get; set; } = "admin";
  44. public string Password { get; set; } = "123456";
  45. public static MainWindowViewModel Instance { get; } = new MainWindowViewModel();
  46. }
  47. }