/// <summary> /// Factory method to create a <see cref="WCFNetwork"/> /// </summary> /// <returns>A new <see cref="WCFNetwork"/></returns> public static WCFNetwork Build() { WCFNetwork network = new WCFNetwork(() => Properties.Settings.Default.WasConnectedTo); network.IsConnectedChanged += RememberNetwork; network.Start(); return(network); }
/// <summary> /// Initializes a new instance of the <see cref="ChatViewModel"/> class. /// </summary> public ChatViewModel() { User = Environment.UserName; timerTask = new Task(TimerMain, TaskCreationOptions.LongRunning); timerTask.Start(); network = WCFNetworkManager.Build(); network.IsConnectedChanged += NetworkIsConnectedChanged; channel = network.GetChannel <Message>(); channel.Received += ChannelReceived; SendCommand = new Command { CanExecuteFunc = x => true, ExecuteAction = x => SendMessage() }; }
/// <summary> /// Main method for simple test exe /// </summary> /// <param name="args">Startup arguments.</param> public static void Main(string[] args) { Debugger.Launch(); network = new WCFNetwork(); network.Start(); network.GetChannel <OutgoingMessage>().Received += Program_Received; network.Connect(new NodeAddress(args[0])); network.GetChannel <RegisteredMessage>().Send(new RegisteredMessage { Address = network.Local.Address.AsString }); returnChannel = network.GetChannel <ReturnMessage>(); //You should never see this, but just in case Console.WriteLine("Press any key to terminate"); Console.ReadKey(); }
public void ShouldConnect() { var registeredNetwork = new WCFNetwork(); registeredNetwork.Start(); var manager = new NetworkManager(); manager.Register(registeredNetwork); var externalNetwork = new WCFNetwork(); externalNetwork.Start(); var connection = manager.ConnectTo(externalNetwork.Local.Address); connection.ShouldNotBeNull(); }
/// <summary> /// Try and connect to the network according to the settings I have saved /// </summary> /// <param name="network">Network to connect to</param> /// <remarks>Kill me quickly</remarks> public static void TryConnect(WCFNetwork network) { var wasConnectedTo = Properties.Settings.Default.WasConnectedTo; if (string.IsNullOrEmpty(wasConnectedTo) == false) { foreach (var connection in wasConnectedTo.Split('|')) { try { network.Connect(new NodeAddress(connection)); } catch { } if (network.IsConnected) { break; } } } }