/Overthere/Overthere/Consoles/RemoteConsole.cs
C# | 86 lines | 72 code | 14 blank | 0 comment | 6 complexity | 5ff72d124a57a14eb0bbd6d12be16f2c MD5 | raw file
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Diagnostics;
- using System.IO;
- using System.ServiceModel;
- using Overthere.Interfaces;
- using Overthere.Services;
- using RemoteConsole;
- using System.Windows.Input;
-
- namespace Overthere
- {
- public class RemoteConsole : IConsole, IDisposable, IRemoteConsoleServiceCallback
- {
- RemoteConsoleServiceClient _service;
-
- public RemoteConsole(string machineName)
- {
- Uri machineUri = new Uri("net.tcp://" + machineName + ":4005/Overthere");
- EndpointAddress machineAddress = new EndpointAddress(machineUri);
- _service = new RemoteConsoleServiceClient(new InstanceContext(this), "NetTcpBinding_IRemoteConsoleService", machineAddress);
- _service.Input("echo Connection Established" + Environment.NewLine);
- }
-
- public void Dispose()
- {
- if (_service != null)
- {
- _service.Close();
- _service = null;
-
- GC.SuppressFinalize(this);
- }
- }
-
- public void Input(string command)
- {
- _service.Input(command);
- }
-
- public event Action<string> Output;
- public event Action<string> Error;
-
- public string GetCurrentDirectory()
- {
- return _service.GetCurrentDirectory();
- }
-
- public IEnumerable<DirectoryInfo> GetDirectories(string directory)
- {
- return _service.GetDirectories(directory);
- }
-
- public IEnumerable<FileInfo> GetFiles(string directory)
- {
- return _service.GetFiles(directory);
- }
-
- #region IRemoteConsoleReceiver Members
-
- public void OutputCallback(string output)
- {
- if (Output != null)
- {
- Output(output);
- }
- }
-
- public void ErrorCallback(string error)
- {
- if (Error != null)
- {
- Error(error);
- }
- }
-
- public void SendKey(Key key, ModifierKeys modifiers)
- {
- _service.SendKey(key, modifiers);
- }
-
- #endregion
- }
- }