Exemplo n.º 1
0
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed

        internal static void Connect()
        {
            AntVaultClient = new SimpleSocketTcpClient();
            if (HasSetupEvents == false)
            {
                AntVaultClient.BytesReceived   += BytesReceived;
                AntVaultClient.MessageReceived += MessageReceived;
                AntVaultClient.ObjectReceived  += AntVaultClient_ObjectReceived;
                HasSetupEvents = true;
                Console.WriteLine("Events setup complete");
            }
            try
            {
                AntVaultClient.StartClient(App.AuxiliaryClientWorker.ReadFromConfig("IP", MainClientWorker.ConfigDir), Convert.ToInt32(App.AuxiliaryClientWorker.ReadFromConfig("Port", MainClientWorker.ConfigDir)));
                Task.Run(() => AntVaultClient.SendMessage("/ServerStatus?"));
                Task.Run(() => Console.WriteLine("Requested server's status"));
                Task.Run(() => Application.Current.Dispatcher.Invoke(() =>
                {
                    WindowController.LoginPage.ConnectButton.Content = "Loading...";
                })
                         );
            }
            catch (Exception exc)
            {
                Task.Run(() => Console.WriteLine("Could not connect to the server due to " + exc));
                Task.Run(() => Application.Current.Dispatcher.Invoke(() =>
                {
                    WindowController.LoginPage.StatusLabel.Content = "ERROR-Server offline, try to Vault later.";
                })
                         );
                Thread.Sleep(3000);
                Connect();
            }
        }
Exemplo n.º 2
0
 internal static void DoAuthentication(string Username, string Password)
 {
     AntVaultClient.BytesReceived += MainClientWorker.AntVaultClient_BytesReceived;
     AntVaultClient.StartClient("AntVault.ddns.net", 8910);
     CurrentUser = Username;
     try
     {
         AntVaultClient.SendBytes(AuxiliaryClientWorker.MessageByte("/NewConnection -U " + Username + " -P " + Password + "."));//NewConnection -U Username -P Password.
     }
     catch
     {
         MessageBox.Show("Server is offline, therefore the authentication process could not take place, please try again later!", "Error! Server offline!", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Exemplo n.º 3
0
        private static void Main(string[] args)
        {
            _encrypt  = true;
            _compress = true;

            var jsonSer = new MessageTesting.JsonSerialization();
            var xmlSer  = new XmlSerialization();
            var binSer  = new BinarySerializer();

            var cert = new X509Certificate2(File.ReadAllBytes(Path.GetFullPath(@"C:\Users\" + Environment.UserName + @"\Desktop\test.pfx")), "Password");

            _client = new SimpleSocketTcpClient();
            //_client = new SimpleSocketTcpSslClient(cert);

            _client.ObjectSerializer    = jsonSer;
            _client.EnableExtendedAuth  = true;
            _client.AllowReceivingFiles = true;


            //Create the MessageContract implementation and add to the client
            _messageAContract = new MessageA("MessageAHeader");
            _client.AddMessageContract(_messageAContract);
            //Bind MessageContract Event
            _messageAContract.OnMessageReceived += MessageAContractOnOnMessageReceived;

            BindEvents();


            _client.StartClient("127.0.0.1", 13000);
            while (true)
            {
                Options();


                WriteLine("Press any key to continue...");
                System.Console.Read();
                System.Console.Clear();
            }
        }
Exemplo n.º 4
0
        private static void Main(string[] args)
        {
            _encrypt  = true;
            _compress = false;

            var xmlSer = new XmlSerialization();
            var binSer = new BinarySerializer();

            _client = new SimpleSocketTcpClient();
            //_client = new SimpleSocketTcpSslClient(@"PATH\TO\CERT.pfx", "Password");

            _client.ObjectSerializer    = binSer;
            _client.EnableExtendedAuth  = true;
            _client.AllowReceivingFiles = true;


            //Create the MessageContract implementation and add to the client
            _messageAContract = new MessageA("MessageAHeader");
            _client.AddMessageContract(_messageAContract);
            //Bind MessageContract Event
            _messageAContract.OnMessageReceived += MessageAContractOnOnMessageReceived;

            BindEvents();
            _client.StartClient("127.0.0.1", 13000);


            while (true)
            {
                Options();


                WriteLine("Press any key to continue...");
                System.Console.Read();
                System.Console.Clear();
            }
        }