예제 #1
0
 public void Close(string code = "")
 {
     if (Instance4Net != null)
     {
         Instance4Net.Close(code);
     }
     else
     {
         Init();
     }
 }
예제 #2
0
        public void Init(Action resolveConnection = null, Action <IError> rejectConnection = null, SignInSession session = null, string seedString = null, string rememberMe = null, UserState state = null)
        {
            if (_pingTimeout > 0)
            {
                ClearTimeout(_pingTimeout);
            }

            // TODO: find out the scope of this code
            //for (const property of Object.keys(this)) {
            //    delete this[property];
            //}

            if (Instance4Net != null)
            {
                Instance4Net.Dispose();
                Instance4Net = null;
            }

            _connected = false;

            _resolveConnection  = resolveConnection;
            _rejectConnection   = rejectConnection;
            _connectionResolved = false;

            Session.Username     = session != null && !string.IsNullOrEmpty(session.Username) ? session.Username : "";
            Session.SessionId    = session != null && !string.IsNullOrEmpty(session.SessionId) ? session.SessionId : "";
            Session.CreationDate = session != null && !string.IsNullOrEmpty(session.CreationDate) ? session.CreationDate : "";

            _seedString = seedString;
            Keys.Clear();

            _rememberMe = rememberMe;

            _pendingRequests.Clear();

            State = state ?? new UserState
            {
                Databases    = new Dictionary <string, Database>(),
                DbIdToHash   = new Dictionary <string, string>(),
                DbNameToHash = new Dictionary <string, string>(),
            };
        }
예제 #3
0
        public async Task Request(string action, RequestParams reqParams)
        {
            // generate a new requestId
            var requestId = Guid.NewGuid().ToString();

            // add new pending request with success/failure callback when the WebSocket
            // receives a response for this requestId — the watch
            // would time out of x seconds
            await Watch(requestId, OnSuccess, OnFailure);

            // send the request on the WebSocket
            var message = JsonConvert.SerializeObject(new
            {
                requestId,
                action,
                @params = reqParams,
            });

            Instance4Net.Send(message);
            _ = _logger.Log($"SENT - {message}");

            // wait for the response to arrive
        }