Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="consoleWriteLine"></param>
        /// <param name="portNumber">default is 19134</param>
        public static void Connect(ConsoleWriteLineDelegate consoleWriteLine, int portNumber)
        {
            var binding        = new NetTcpBinding();
            var url            = $"net.tcp://localhost:{portNumber}/MinecraftConsole";
            var address        = new EndpointAddress(url);
            var channelFactory =
                new ChannelFactory <IWCFConsoleServer>(binding, address);

            do
            {
                _server = channelFactory.CreateChannel();
                if (_server == null)
                {
                    Console.WriteLine($"Trying to connect to {url}");
                }
                else
                {
                    try
                    {
                        _server.GetVersion();
                        consoleWriteLine($"Connection to '{url}' established.");
                    }
                    catch (System.ServiceModel.EndpointNotFoundException)
                    {
                        consoleWriteLine($"Trying to connect to {url}");
                        _server = null;
                    }
                }
            }while (_server == null);
        }
Beispiel #2
0
 public static void SendCommand(string command, ConsoleWriteLineDelegate consoleWriteLine)
 {
     try
     {
         _server.SendConsoleCommand(command);
     }
     catch (System.ServiceModel.CommunicationObjectFaultedException)
     {
         consoleWriteLine($"ERROR:Connection to server lost command '{command}' was not processed. Please try again.");
     }
 }
Beispiel #3
0
 public ThreadPayLoad(ConsoleWriteLineDelegate consoleWriteLine, int portNumber)
 {
     ConsoleWriteLine = consoleWriteLine;
     PortNumber       = portNumber;
 }