Beispiel #1
0
        // 某客户端用户的状态改变后,通知其他用户
        private void UserStateNotify(string userID, OnlineState ustate)
        {
            try
            {
                //用户状态契约类
                UserStateContract userState = new UserStateContract();
                userState.UserID = userID;
                userState.OnLine = ustate;
                IList <ShortGuid> allUserID;

                lock (syncLocker)
                {
                    //获取所有用户字典中的用户链接标识
                    allUserID = new List <ShortGuid>(userManager.Values);
                }

                //给所有用户发送某用户的在线状态
                foreach (ShortGuid netID in allUserID)
                {
                    List <Connection> result = NetworkComms.GetExistingConnection(netID, ConnectionType.TCP);

                    if (result.Count > 0 && result[0].ConnectionInfo.NetworkIdentifier == netID)
                    {
                        result[0].SendObject("UserStateNotify", userState);
                    }
                }
            }
            catch (Exception ex)
            {
                LogTools.LogException(ex, "MainForm.UserStateNotify");
            }
        }
Beispiel #2
0
 //用户状态改变通知<5>
 private void IncomingUserStateNotify(PacketHeader header, Connection connection, UserStateContract userStateContract)
 {
     lock (syncLocker)
     {
         IMUserInfo u = Common.GetFriend(userStateContract.UserID);
         if (u != null)
         {
             ChatListSubItem item = userItem[userStateContract.UserID];
             if (item != null)
             {
                 IMUserInfo user = item.Tag as IMUserInfo;
                 if (user != null)
                 {
                     if (userStateContract.OnLine == OnlineState.Online)
                     {
                         u.UserState   = (int)OnlineState.Online;
                         item.Status   = ChatListSubItem.UserStatus.Online;
                         user.IsOnline = true;
                     }
                     else
                     {
                         u.UserState   = (int)OnlineState.Offline;
                         item.Status   = ChatListSubItem.UserStatus.OffLine;
                         user.IsOnline = false;
                         //当某用户下线后,删除此用户相关的p2p 通道
                         Common.RemoveUserConn(userStateContract.UserID);
                     }
                 }
             }
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// List all group users.
        /// </summary>
        /// <param name='nextLink'>
        /// Required. NextLink from the previous successful call to List
        /// operation.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// List Users operation response details.
        /// </returns>
        public async Task <UserListResponse> ListNextAsync(string nextLink, CancellationToken cancellationToken)
        {
            // Validate
            if (nextLink == null)
            {
                throw new ArgumentNullException("nextLink");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("nextLink", nextLink);
                TracingAdapter.Enter(invocationId, this, "ListNextAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + nextLink;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    UserListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new UserListResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            UserPaged resultInstance = new UserPaged();
                            result.Result = resultInstance;

                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    UserContract userContractInstance = new UserContract();
                                    resultInstance.Values.Add(userContractInstance);

                                    JToken idValue = valueValue["id"];
                                    if (idValue != null && idValue.Type != JTokenType.Null)
                                    {
                                        string idInstance = ((string)idValue);
                                        userContractInstance.IdPath = idInstance;
                                    }

                                    JToken firstNameValue = valueValue["firstName"];
                                    if (firstNameValue != null && firstNameValue.Type != JTokenType.Null)
                                    {
                                        string firstNameInstance = ((string)firstNameValue);
                                        userContractInstance.FirstName = firstNameInstance;
                                    }

                                    JToken lastNameValue = valueValue["lastName"];
                                    if (lastNameValue != null && lastNameValue.Type != JTokenType.Null)
                                    {
                                        string lastNameInstance = ((string)lastNameValue);
                                        userContractInstance.LastName = lastNameInstance;
                                    }

                                    JToken emailValue = valueValue["email"];
                                    if (emailValue != null && emailValue.Type != JTokenType.Null)
                                    {
                                        string emailInstance = ((string)emailValue);
                                        userContractInstance.Email = emailInstance;
                                    }

                                    JToken stateValue = valueValue["state"];
                                    if (stateValue != null && stateValue.Type != JTokenType.Null)
                                    {
                                        UserStateContract stateInstance = ((UserStateContract)Enum.Parse(typeof(UserStateContract), ((string)stateValue), true));
                                        userContractInstance.State = stateInstance;
                                    }

                                    JToken registrationDateValue = valueValue["registrationDate"];
                                    if (registrationDateValue != null && registrationDateValue.Type != JTokenType.Null)
                                    {
                                        DateTime registrationDateInstance = ((DateTime)registrationDateValue);
                                        userContractInstance.RegistrationDate = registrationDateInstance;
                                    }

                                    JToken noteValue = valueValue["note"];
                                    if (noteValue != null && noteValue.Type != JTokenType.Null)
                                    {
                                        string noteInstance = ((string)noteValue);
                                        userContractInstance.Note = noteInstance;
                                    }

                                    JToken identitiesArray = valueValue["identities"];
                                    if (identitiesArray != null && identitiesArray.Type != JTokenType.Null)
                                    {
                                        foreach (JToken identitiesValue in ((JArray)identitiesArray))
                                        {
                                            UserIdentityContract userIdentityContractInstance = new UserIdentityContract();
                                            userContractInstance.Identities.Add(userIdentityContractInstance);

                                            JToken providerValue = identitiesValue["provider"];
                                            if (providerValue != null && providerValue.Type != JTokenType.Null)
                                            {
                                                string providerInstance = ((string)providerValue);
                                                userIdentityContractInstance.Provider = providerInstance;
                                            }

                                            JToken idValue2 = identitiesValue["id"];
                                            if (idValue2 != null && idValue2.Type != JTokenType.Null)
                                            {
                                                string idInstance2 = ((string)idValue2);
                                                userIdentityContractInstance.Id = idInstance2;
                                            }
                                        }
                                    }
                                }
                            }

                            JToken countValue = responseDoc["count"];
                            if (countValue != null && countValue.Type != JTokenType.Null)
                            {
                                long countInstance = ((long)countValue);
                                resultInstance.TotalCount = countInstance;
                            }

                            JToken nextLinkValue = responseDoc["nextLink"];
                            if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null)
                            {
                                string nextLinkInstance = ((string)nextLinkValue);
                                resultInstance.NextLink = nextLinkInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Beispiel #4
0
        /// <summary>
        /// List all group users.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. The name of the resource group.
        /// </param>
        /// <param name='serviceName'>
        /// Required. The name of the Api Management service.
        /// </param>
        /// <param name='gid'>
        /// Required. Identifier of the group.
        /// </param>
        /// <param name='query'>
        /// Optional.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// List Users operation response details.
        /// </returns>
        public async Task <UserListResponse> ListAsync(string resourceGroupName, string serviceName, string gid, QueryParameters query, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (serviceName == null)
            {
                throw new ArgumentNullException("serviceName");
            }
            if (gid == null)
            {
                throw new ArgumentNullException("gid");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceGroupName", resourceGroupName);
                tracingParameters.Add("serviceName", serviceName);
                tracingParameters.Add("gid", gid);
                tracingParameters.Add("query", query);
                TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/subscriptions/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId);
            }
            url = url + "/resourceGroups/";
            url = url + Uri.EscapeDataString(resourceGroupName);
            url = url + "/providers/";
            url = url + "Microsoft.ApiManagement";
            url = url + "/service/";
            url = url + Uri.EscapeDataString(serviceName);
            url = url + "/groups/";
            url = url + Uri.EscapeDataString(gid);
            url = url + "/users";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2014-02-14");
            List <string> odataFilter = new List <string>();

            if (query != null && query.Filter != null)
            {
                odataFilter.Add(Uri.EscapeDataString(query.Filter));
            }
            if (odataFilter.Count > 0)
            {
                queryParameters.Add("$filter=" + string.Join(null, odataFilter));
            }
            if (query != null && query.Top != null)
            {
                queryParameters.Add("$top=" + Uri.EscapeDataString(query.Top.Value.ToString()));
            }
            if (query != null && query.Skip != null)
            {
                queryParameters.Add("$skip=" + Uri.EscapeDataString(query.Skip.Value.ToString()));
            }
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    UserListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new UserListResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            UserPaged resultInstance = new UserPaged();
                            result.Result = resultInstance;

                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    UserContract userContractInstance = new UserContract();
                                    resultInstance.Values.Add(userContractInstance);

                                    JToken idValue = valueValue["id"];
                                    if (idValue != null && idValue.Type != JTokenType.Null)
                                    {
                                        string idInstance = ((string)idValue);
                                        userContractInstance.IdPath = idInstance;
                                    }

                                    JToken firstNameValue = valueValue["firstName"];
                                    if (firstNameValue != null && firstNameValue.Type != JTokenType.Null)
                                    {
                                        string firstNameInstance = ((string)firstNameValue);
                                        userContractInstance.FirstName = firstNameInstance;
                                    }

                                    JToken lastNameValue = valueValue["lastName"];
                                    if (lastNameValue != null && lastNameValue.Type != JTokenType.Null)
                                    {
                                        string lastNameInstance = ((string)lastNameValue);
                                        userContractInstance.LastName = lastNameInstance;
                                    }

                                    JToken emailValue = valueValue["email"];
                                    if (emailValue != null && emailValue.Type != JTokenType.Null)
                                    {
                                        string emailInstance = ((string)emailValue);
                                        userContractInstance.Email = emailInstance;
                                    }

                                    JToken stateValue = valueValue["state"];
                                    if (stateValue != null && stateValue.Type != JTokenType.Null)
                                    {
                                        UserStateContract stateInstance = ((UserStateContract)Enum.Parse(typeof(UserStateContract), ((string)stateValue), true));
                                        userContractInstance.State = stateInstance;
                                    }

                                    JToken registrationDateValue = valueValue["registrationDate"];
                                    if (registrationDateValue != null && registrationDateValue.Type != JTokenType.Null)
                                    {
                                        DateTime registrationDateInstance = ((DateTime)registrationDateValue);
                                        userContractInstance.RegistrationDate = registrationDateInstance;
                                    }

                                    JToken noteValue = valueValue["note"];
                                    if (noteValue != null && noteValue.Type != JTokenType.Null)
                                    {
                                        string noteInstance = ((string)noteValue);
                                        userContractInstance.Note = noteInstance;
                                    }

                                    JToken identitiesArray = valueValue["identities"];
                                    if (identitiesArray != null && identitiesArray.Type != JTokenType.Null)
                                    {
                                        foreach (JToken identitiesValue in ((JArray)identitiesArray))
                                        {
                                            UserIdentityContract userIdentityContractInstance = new UserIdentityContract();
                                            userContractInstance.Identities.Add(userIdentityContractInstance);

                                            JToken providerValue = identitiesValue["provider"];
                                            if (providerValue != null && providerValue.Type != JTokenType.Null)
                                            {
                                                string providerInstance = ((string)providerValue);
                                                userIdentityContractInstance.Provider = providerInstance;
                                            }

                                            JToken idValue2 = identitiesValue["id"];
                                            if (idValue2 != null && idValue2.Type != JTokenType.Null)
                                            {
                                                string idInstance2 = ((string)idValue2);
                                                userIdentityContractInstance.Id = idInstance2;
                                            }
                                        }
                                    }
                                }
                            }

                            JToken countValue = responseDoc["count"];
                            if (countValue != null && countValue.Type != JTokenType.Null)
                            {
                                long countInstance = ((long)countValue);
                                resultInstance.TotalCount = countInstance;
                            }

                            JToken nextLinkValue = responseDoc["nextLink"];
                            if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null)
                            {
                                string nextLinkInstance = ((string)nextLinkValue);
                                resultInstance.NextLink = nextLinkInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;
                    if (httpResponse.Headers.Contains("x-ms-request-id"))
                    {
                        result.RequestId = httpResponse.Headers.GetValues("x-ms-request-id").FirstOrDefault();
                    }

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Beispiel #5
0
 //用户状态改变通知<5>
 private void IncomingUserStateNotify(PacketHeader header, Connection connection, UserStateContract userStateContract)
 {
     //if (userStateContract.OnLine)
     //{
     //    lock (syncLocker)
     //    {
     //        //Common.GetDicUser(userStatecontract.SenderID).State = OnlineState.Online;
     //    }
     //}
     //else
     //{
     //    lock (syncLocker)
     //    {
     //        //Common.GetDicUser(userStatecontract.SenderID).State = OnlineState.Offline;
     //        ////当某用户下线后,删除此用户相关的p2p 通道
     //        //Common.RemoveUserConn(userStatecontract.SenderID);
     //    }
     //}
 }