コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: ChatViewModel.cs プロジェクト: alski/ndistribute
        /// <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()
            };
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: alski/ndistribute
        /// <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();
        }
コード例 #4
0
        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();
        }
コード例 #5
0
        /// <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;
                    }
                }
            }
        }