PageRenderTime 54ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/Overthere/Overthere/Consoles/RemoteConsole.cs

https://bitbucket.org/floAr/personal
C# | 86 lines | 72 code | 14 blank | 0 comment | 6 complexity | 5ff72d124a57a14eb0bbd6d12be16f2c MD5 | raw file
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Diagnostics;
  6. using System.IO;
  7. using System.ServiceModel;
  8. using Overthere.Interfaces;
  9. using Overthere.Services;
  10. using RemoteConsole;
  11. using System.Windows.Input;
  12. namespace Overthere
  13. {
  14. public class RemoteConsole : IConsole, IDisposable, IRemoteConsoleServiceCallback
  15. {
  16. RemoteConsoleServiceClient _service;
  17. public RemoteConsole(string machineName)
  18. {
  19. Uri machineUri = new Uri("net.tcp://" + machineName + ":4005/Overthere");
  20. EndpointAddress machineAddress = new EndpointAddress(machineUri);
  21. _service = new RemoteConsoleServiceClient(new InstanceContext(this), "NetTcpBinding_IRemoteConsoleService", machineAddress);
  22. _service.Input("echo Connection Established" + Environment.NewLine);
  23. }
  24. public void Dispose()
  25. {
  26. if (_service != null)
  27. {
  28. _service.Close();
  29. _service = null;
  30. GC.SuppressFinalize(this);
  31. }
  32. }
  33. public void Input(string command)
  34. {
  35. _service.Input(command);
  36. }
  37. public event Action<string> Output;
  38. public event Action<string> Error;
  39. public string GetCurrentDirectory()
  40. {
  41. return _service.GetCurrentDirectory();
  42. }
  43. public IEnumerable<DirectoryInfo> GetDirectories(string directory)
  44. {
  45. return _service.GetDirectories(directory);
  46. }
  47. public IEnumerable<FileInfo> GetFiles(string directory)
  48. {
  49. return _service.GetFiles(directory);
  50. }
  51. #region IRemoteConsoleReceiver Members
  52. public void OutputCallback(string output)
  53. {
  54. if (Output != null)
  55. {
  56. Output(output);
  57. }
  58. }
  59. public void ErrorCallback(string error)
  60. {
  61. if (Error != null)
  62. {
  63. Error(error);
  64. }
  65. }
  66. public void SendKey(Key key, ModifierKeys modifiers)
  67. {
  68. _service.SendKey(key, modifiers);
  69. }
  70. #endregion
  71. }
  72. }