Ejemplo n.º 1
0
 internal LoginSession(Client client, AccountId accountId)
 {
     if (AccountId.IsNullOrEmpty(accountId))
     {
         throw new ArgumentNullException(nameof(accountId));
     }
     if (client == null)
     {
         throw new ArgumentNullException(nameof(client));
     }
     Key            = accountId;
     _accountHandle = accountId.ToString();
     _groupHandle   = "sg_" + _accountHandle;
     _client        = client;
     VxClient.Instance.EventMessageReceived += Instance_EventMessageReceived;
 }
Ejemplo n.º 2
0
        public IAsyncResult BeginSendDirectedMessage(AccountId userId, string language, string message, string applicationStanzaNamespace, string applicationStanzaBody, AsyncCallback callback)
        {
            if (AccountId.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }
            if (string.IsNullOrEmpty(message) && string.IsNullOrEmpty(applicationStanzaBody))
            {
                throw new ArgumentNullException($"{nameof(message)} and {nameof(applicationStanzaBody)} cannot both be null");
            }

            AssertLoggedIn();
            AsyncNoResult ar = new AsyncNoResult(callback);

            var request = new vx_req_account_send_message_t
            {
                account_handle = _accountHandle,
                message_body   = message,
                user_uri       = userId.ToString(),
                language       = language,
                application_stanza_namespace = applicationStanzaNamespace,
                application_stanza_body      = applicationStanzaBody
            };

            VxClient.Instance.BeginIssueRequest(request, result =>
            {
                vx_resp_account_send_message_t response;
                try
                {
                    response = VxClient.Instance.EndIssueRequest(result);
                    _directedMessageResult = new DirectedMessageResult(response.request_id);
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(DirectedMessageResult)));
                    ar.SetComplete();
                }
                catch (Exception e)
                {
                    VivoxDebug.Instance.VxExceptionMessage($"{request.GetType().Name} failed: {e}");
                    ar.SetComplete(e);
                    return;
                }
            });
            return(ar);
        }
Ejemplo n.º 3
0
        public IAsyncResult BeginSessionArchiveQuery(DateTime?timeStart, DateTime?timeEnd, string searchText,
                                                     AccountId userId, uint max, string afterId, string beforeId, int firstMessageIndex,
                                                     AsyncCallback callback)
        {
            AssertSessionNotDeleted();
            if (TextState != ConnectionState.Connected)
            {
                throw new InvalidOperationException($"{GetType().Name}: {nameof(TextState)} must equal ChannelState.Connected");
            }
            if (afterId != null && beforeId != null)
            {
                throw new ArgumentException($"{GetType().Name}: Parameters {nameof(afterId)} and {nameof(beforeId)} cannot be used at the same time");
            }
            if (max > 50)
            {
                throw new ArgumentException($"{GetType().Name}: {nameof(max)} cannot be greater than 50");
            }


            var ar = new AsyncNoResult(callback);

            var request = new vx_req_session_archive_query_t
            {
                session_handle      = _sessionHandle,
                max                 = max,
                after_id            = afterId,
                before_id           = beforeId,
                first_message_index = firstMessageIndex,
                search_text         = searchText
            };

            if (timeStart != null && timeStart != DateTime.MinValue)
            {
                request.time_start = (timeStart?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"));
            }
            if (timeEnd != null && timeEnd != DateTime.MaxValue)
            {
                request.time_end = (timeEnd?.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ"));
            }

            if (!AccountId.IsNullOrEmpty(userId))
            {
                request.participant_uri = userId.ToString();
            }

            VxClient.Instance.BeginIssueRequest(request, result =>
            {
                vx_resp_session_archive_query_t response;
                try
                {
                    response = VxClient.Instance.EndIssueRequest(result);
                    _sessionArchiveResult = new ArchiveQueryResult(response.query_id);
                    PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SessionArchiveResult)));
                    ar.SetComplete();
                }
                catch (Exception e)
                {
                    VivoxDebug.Instance.VxExceptionMessage($"{request.GetType().Name} failed: {e}");
                    ar.SetComplete(e);
                    if (VivoxDebug.Instance.throwInternalExcepetions)
                    {
                        throw;
                    }
                    return;
                }
            });
            return(ar);
        }