private void  Connect(ConnectSettings settings)
        {
            var completed = default(EventHandler <SocketAsyncEventArgs>);

            var saea = new SocketAsyncEventArgs {
                RemoteEndPoint = new DnsEndPoint(_settings.Address, _settings.Port),
                UserToken      = _socket
            };

            saea.Completed += completed = (s, e) => {
                e.Completed -= completed;
                if (e.SocketError == SocketError.Success)
                {
                    _receive = _receive ?? (_receive = CreateSocketAsyncEventArgs());
                    Receive(_receive);
                }
                else
                {
                    Connect(settings);
                }
            };

            if (false == _socket.ConnectAsync(saea))
            {
                completed(this, saea);
            }
        }
        public ContractDataContext(ConnectSettings connectSettings)
        {
            var client = new MongoClient(connectSettings.MongoConnectionString);

            if (client != null)
            {
                _database = client.GetDatabase(connectSettings.MongoDb);
            }
        }
Exemple #3
0
        public async Task <bool> Auth(ConnectSettings s, Credentials i)
        {
            file.WriteLine("Auth function: {0}:{1} {2} {3}", s.Url, s.Port, i.UserName, i.Password);
            file.Flush();

            await Task.Delay(2000);

            if (i.UserName == "user" && i.Password == "password")
            {
                return(true);
            }
            return(false);
        }
Exemple #4
0
        /// <summary>
        /// Open the connectionsettings popup
        /// </summary>
        private void ShowConnectDialog()
        {
            ConnectSettings connectsettings = new ConnectSettings();

            connectsettings.ShowDialog();

            if (connectsettings.DialogResult == DialogResult.OK)
            {
                bl.SetSerial(connectsettings.ComPort);
            }
            else if (connectsettings.DialogResult == DialogResult.Retry)
            {
                ShowConnectDialog();
            }
        }
Exemple #5
0
        /// <summary>
        /// Connect to server with given settings
        /// </summary>
        /// <param name="s"></param>
        /// <param name="i"></param>
        /// <param name="onConnection">1 when OK 0 if error</param>
        async public void Connect(ConnectSettings s, Credentials i, Action <bool> onConnection)
        {
            try
            {
                StopDataSynchronization();
                var task = await server.Value.Auth(s, i);

                //wait for it to end without blocking the main thread
                if (task)
                {
                    await GetVersion();
                }

                onConnection?.Invoke(task);
            }
            catch
            {
                onConnection?.Invoke(false);
            }
        }
        public async Task <bool> Auth(ConnectSettings s, Credentials i)
        {
            handler = new HttpClientHandler
            {
                Credentials     = new NetworkCredential(i.UserName, i.Password),
                PreAuthenticate = true
            };


            http?.Dispose();
            http = new HttpClient(handler, true)
            {
                Timeout = Timeout.InfiniteTimeSpan
            };
            http.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            try
            {
                var u = new UriBuilder(s.Url);
                if (s.Port > 1024)
                {
                    u.Port = s.Port;
                }

                /*
                 * if(u.Scheme == "http")
                 * {
                 *  u.Scheme = "https";
                 * }
                 */

                http.BaseAddress = u.Uri;
                //http.BaseAddress = new Uri("https://httpbin.org/");
            }
            catch
            {
                return(false);
            }

            try
            {
                var cts = new CancellationTokenSource();
                cts.CancelAfter(TimeSpan.FromSeconds(30));

                var response = await http.GetAsync(authSite, cts.Token);

                response.EnsureSuccessStatusCode();

                var json = JsonSerializer.Deserialize <PasswdResponse>(await response.Content.ReadAsStringAsync());

                if (json.User == i.UserName && json.Authenticated)
                {
                    return(true);
                }
                return(false);
            }
            catch
            {
                return(false);
            }
        }
 public void Connect(Action <IConnectConfigurator> configure)
 {
     _settings = Configure <IConnectConfigurator, ConnectConfigurator>(configure).Build();
     Connect(_settings);
     _packets.Subscribe(x => ProcessPackets(x, _trades));
 }
Exemple #8
0
 public PublicContractKLineRepository(ConnectSettings connectSettings)
 {
     _context = new ContractDataContext(connectSettings);
 }
Exemple #9
0
 public void Save(ConnectSettings data)
 {
     Url  = data.Url;
     Port = data.Port.ToString();
 }
Exemple #10
0
 public void Restore(ConnectSettings data)
 {
     data.Url  = Url;
     data.Port = Int32.Parse(Port);
 }
        //HostName, Username, password, PortNumber, SelectedGroup)
        public bool Connect(string hostname, string username, string password, ushort portNumber, Symbol groupID, string locale)
        {
            IsConnected = false;


            var logonInfo = new StubLoginInfo
            {
                Hostname = hostname,
                //Hostname = User specified hostname,
                Port = portNumber,
                //Port = 1338,
                Security = TransportSecurity.Insecure,
                //Security = 0,
                UserName = username,
                GroupID  = groupID,
                Locale   = locale
                           //GroupID = Symbol.Intern("Pdmusers")
            };

            LoginInfo = logonInfo;

            var client = new TcpMessageClient(
                hostname,
                portNumber,
                TransportSecurity.Insecure);

            lock (this.interlock)
                this.client = client;

            // insert logging between stub and client
            BidiSharedPipe shared = new BidiSharedPipe();

            if (this.LogMessage != null)
            {
                shared.Send.MessageReceived += new LogPipe("sent", this.LogMessage).PostMessage;
                shared.Recv.MessageReceived += new LogPipe("recv", this.LogMessage).PostMessage;
            }

            shared.Send.MessageReceived += client.SendPipe.PostMessage;

            client.ReceivePipe = shared.Recv;

            shared.Recv.PipeDropped += OnConnectionDropped;

            client.StartReceiving();

            // create a stub system interface and get back some IDL
            Message idl;

            var connectSettings = new ConnectSettings
            {
                Client          = shared,
                Secret          = password,
                UiClientVersion = appVersion,
                ClientType      = "SSEClientUi"
            };

            var systemInterface = SystemInterfaceStub.Connect(connectSettings, logonInfo, out idl);

            lock (this.interlock)
            {
                idl.Extract(Symbol.Intern("GroupID"), out this.groupID);
                this.systemInterface = systemInterface;
                _idl        = idl;
                IsConnected = true;
            }

            sessionId_   = client.SessionId;
            remIPAddress = connectSettings.remIPAddress; // this session as seen by remote
            remPort      = connectSettings.remPort;      // this session as seen by remote
            return(IsConnected);
        }