public MQKeySet RequestMQKeys(string strTokenType, string strAccessToken)
        {
            this.m_Logger.Log("RequestMQKeys Raised", Category.Info, Priority.None);

            try
            {
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(10);
                    dynamic Parameters = new JObject();
                    Parameters.tokentype   = strTokenType;
                    Parameters.accesstoken = strAccessToken;
                    var JsonParameters  = JsonConvert.SerializeObject(Parameters);
                    var postdataString  = new StringContent(JsonParameters, new UTF8Encoding(), "application/json");
                    var responseMessage = httpClient.PostAsync(
                        string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.GetMQInfoURI), postdataString).Result;

                    if (responseMessage.IsSuccessStatusCode)
                    {
                        var JMQInfo = JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result);
                        return(JsonConvert.DeserializeObject <MQKeySet>(JMQInfo.ToString()));
                    }
                }
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
            }

            return(null);
        }
Example #2
0
        public UserEntity GetUserInfo(string strUserSID)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(10);
                    dynamic parameter = new JObject();
                    parameter.usersid = strUserSID;
                    var JsonParameters = JsonConvert.SerializeObject(parameter);
                    var postdataString = new StringContent(JsonParameters, new UTF8Encoding(), "application/json");

                    var responseMessage = httpClient.PostAsync(
                        string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.GetUserInfoURI),
                        postdataString).Result;

                    if (responseMessage.IsSuccessStatusCode)
                    {
                        var JUserInfo = JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result);
                        return(JsonConvert.DeserializeObject <UserEntity>(JUserInfo.ToString()));
                    }
                }
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
            }

            return(null);
        }
        public bool AddFriend(string strMySID, string strFriendSID)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(10);
                    dynamic parameter = new JObject();
                    parameter.usersid   = strMySID;
                    parameter.friendsid = strFriendSID;
                    var JsonParameters = JsonConvert.SerializeObject(parameter);
                    var postdataString = new StringContent(JsonParameters, new UTF8Encoding(), "application/json");

                    var responseMessage = httpClient.PostAsync(
                        string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.AddFriendURI),
                        postdataString).Result;

                    return(responseMessage.IsSuccessStatusCode);
                }
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
                return(false);
            }
        }
        public void CollectFriends(string strUserSID, FriendCollection friends)
        {
            try
            {
                var FriendsCollection = ConnectionHelper.DB.GetCollection <FriendsEntity>("FriendsEntity");
                var FindFriendsQuery  = Query <FriendsEntity> .EQ(f => f.UserSID, strUserSID);

                var FindedFriends = FriendsCollection.FindOne(FindFriendsQuery);

                if (null != FindedFriends)
                {
                    var UserCollection = ConnectionHelper.DB.GetCollection <UserEntity>("UserEntity");

                    Parallel.ForEach(FindedFriends.FriendSIDs, fSid =>
                    {
                        var FindUserQuery = Query <UserEntity> .EQ(u => u.Sid, fSid);
                        var FindedUser    = UserCollection.FindOne(FindUserQuery);

                        if (null != FindedUser)
                        {
                            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new ThreadStart(() =>
                            {
                                friends.Add(new Friend(FindedUser.ThumbnailPath, FindedUser.UserId, FindedUser.Sid, FindedUser.NickName, FindedUser.Comment));
                            }));
                        }
                    });
                }
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
            }
        }
Example #5
0
        public RoomEntity GetRoomInfo(IList <string> arMembers)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(10);
                    dynamic JParams = new JObject();
                    JParams.membersids = new JArray(arMembers).ToString();

                    var JsonParameters = JsonConvert.SerializeObject(JParams);
                    var postdataString = new StringContent(JsonParameters, new UTF8Encoding(), "application/json");

                    var responseMessage = httpClient.PostAsync(
                        string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.GetRoomInfoURI),
                        postdataString).Result;

                    var JRoom = JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result);
                    return(JsonConvert.DeserializeObject <RoomEntity>(JRoom.ToString()));
                }
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
            }

            return(null);
        }
Example #6
0
        public bool ReadMessages(IList <UnReadMsg> unReadMsgs)
        {
            try
            {
                if (0 == unReadMsgs.Count)
                {
                    return(false);
                }
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(10);
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthRepository.AccessInfo.TokenType, AuthRepository.AccessInfo.AccessToken);

                    dynamic Parameters = new JObject();
                    Parameters.readmsgsids = string.Join(",", unReadMsgs.Select(m => m.Sid));
                    Parameters.roomsid     = unReadMsgs[0].RoomSid;
                    Parameters.fromsid     = unReadMsgs[0].FromSid;

                    var JsonParameters = JsonConvert.SerializeObject(Parameters);
                    var postdataString = new StringContent(JsonParameters, new UTF8Encoding(), "application/json");

                    var responseMessage = httpClient.PostAsync(
                        string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.ReadMsgURI),
                        postdataString).Result;

                    return(responseMessage.IsSuccessStatusCode);
                }
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
            }

            return(false);
        }
Example #7
0
        public AccessInformation RequestAccessInfo(string strId, string strPassword)
        {
            this.m_Logger.Log("RequestAccessInfo Raised", Category.Info, Priority.None);

            try
            {
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(10);
                    dynamic Parameters = new JObject();
                    Parameters.granttype     = "password";
                    Parameters.applicationid = BeautifulTalkProtocolSet.ApplicationId;
                    Parameters.id            = strId;
                    Parameters.password      = strPassword;
                    var JsonParameters  = JsonConvert.SerializeObject(Parameters);
                    var postdataString  = new StringContent(JsonParameters, new UTF8Encoding(), "application/json");
                    var responseMessage = httpClient.PostAsync(
                        string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.AccessTokenURI), postdataString).Result;

                    if (responseMessage.IsSuccessStatusCode)
                    {
                        var JAccessInformation = JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result);
                        return(JsonConvert.DeserializeObject <AccessInformation>(JAccessInformation.ToString()));
                    }
                }
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
            }

            return(null);
        }
Example #8
0
        private void ScrollViewer_ScrollChanged(object sender, ScrollChangedEventArgs e)
        {
            if (0 == e.VerticalOffset && 0 > e.VerticalChange)
            {
                try
                {
                    var TopMessage = this.Messages.First(m => m is ChatMsg);

                    if (null != TopMessage)
                    {
                        var TopMsg = (TopMessage as CommunicationMsg);
                        if (MsgStatus.Failed != TopMsg.MsgStatus)
                        {
                            var LoadedMsgs = this.m_LoadMsgService.LoadMessages(this.RoomSID, TopMsg.SendTime);

                            foreach (var Msg in LoadedMsgs)
                            {
                                this.Messages.Insert(0, Msg);
                            }
                        }
                    }

                    this.m_ChattingView.ScrollIntoView(TopMessage);
                }
                catch (NullReferenceException nullRefException)
                {
                    GlobalLogger.Log(nullRefException.Message);
                }
                catch (Exception unExpectedException)
                {
                    GlobalLogger.Log(unExpectedException.Message);
                }
            }
        }
        public IEnumerable <Msg> LoadMessages(string strRoomSID, long lCriterion)
        {
            IList <Msg> Msgs = new List <Msg>();

            try
            {
                if (0 == lCriterion)
                {
                    this.LoadRecentMessages(strRoomSID, Msgs);
                }
                else
                {
                    this.LoadMessagesLessThan(lCriterion, strRoomSID, Msgs);
                }
            }
            catch (NullReferenceException nullRefException)
            {
                GlobalLogger.Log(nullRefException.Message);
                throw nullRefException;
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
                throw unExpectedException;
            }

            return(Msgs);
        }
        private void ExecuteAddFriendCommand(string strRecommendUserSid)
        {
            if (true == string.IsNullOrEmpty(strRecommendUserSid))
            {
                return;
            }

            Task.Run(() =>
            {
                var TargetFriend = this.m_RecommendFriends.FirstOrDefault(r => r.UserSID == strRecommendUserSid);
                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new ThreadStart(() =>
                {
                    RecommendFriends.Remove(TargetFriend);
                }));

                if (true == this.m_AddFriendService.AddFriend(AuthRepository.MQKeyInfo.UserSid, strRecommendUserSid))
                {
                    try
                    {
                        var AddFriend = this.m_GetUserInfoService.GetUserInfo(strRecommendUserSid);

                        if (null != AddFriend)
                        {
                            var UserCollection = ConnectionHelper.DB.GetCollection <UserEntity>("UserEntity");
                            var FindUserQuery  = Query <UserEntity> .EQ(u => u.Sid, strRecommendUserSid);
                            var FindedUser     = UserCollection.FindOne(FindUserQuery);

                            if (null == FindedUser)
                            {
                                UserCollection.Save(AddFriend);
                            }
                        }

                        var FindFriendQuery   = Query <FriendsEntity> .EQ(u => u.UserSID, AuthRepository.MQKeyInfo.UserSid);
                        var FriendsCollection = ConnectionHelper.DB.GetCollection <FriendsEntity>("FriendsEntity");
                        var FindedFriend      = FriendsCollection.FindOne(FindFriendQuery);

                        if (null != FindedFriend)
                        {
                            if (false == FindedFriend.FriendSIDs.Contains(strRecommendUserSid))
                            {
                                FindedFriend.FriendSIDs.Add(strRecommendUserSid);
                                var UpdateQuery = Update <FriendsEntity> .Set(f => f.FriendSIDs, FindedFriend.FriendSIDs);
                                FriendsCollection.Update(FindFriendQuery, UpdateQuery);

                                Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new ThreadStart(() =>
                                {
                                    this.m_FriendsMainViewModel.Friends.Add(new Friend(AddFriend.ThumbnailPath, AddFriend.UserId, AddFriend.Sid, AddFriend.NickName, AddFriend.Comment));
                                }));
                            }
                        }
                    }
                    catch (Exception unExpectedException)
                    {
                        GlobalLogger.Log(unExpectedException.Message);
                    }
                }
            });
        }
Example #11
0
        public Brush GetRandomBrush()
        {
            try
            {
                int nRandomNumber = this.m_RandomPicker.Next(0, this.m_Window8Palette.Count - 1);
                return((Brush)this.m_BrushConverter.ConvertFrom(this.m_Window8Palette[nRandomNumber]));
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
            }

            return(null);
        }
        private void InitializeShellTitleAndMessage(string strRoomSid)
        {
            var RoomCollection = ConnectionHelper.DB.GetCollection <RoomEntity>("RoomEntity");
            var FindRoomQuery  = Query <RoomEntity> .EQ(r => r.Sid, strRoomSid);

            var FindedRoomEntity = RoomCollection.FindOne(FindRoomQuery);

            if (null != FindedRoomEntity)
            {
                try
                {
                    IList <string> arActiveMemberSids = FindedRoomEntity.ActiveMemberSids;
                    arActiveMemberSids.Remove(AuthRepository.MQKeyInfo.UserSid);
                    IList <string> arActiveMemberNickNames = new List <string>();
                    int            nCountOfMembers         = FindedRoomEntity.MemberSids.Count - 1;
                    var            UserCollection          = ConnectionHelper.DB.GetCollection <UserEntity>("UserEntity");
                    string         strComment = string.Empty;

                    foreach (string strMemberSid in arActiveMemberSids)
                    {
                        var FindUserQuery = Query <UserEntity> .EQ(u => u.Sid, strMemberSid);

                        var FindedUser = UserCollection.FindOne(FindUserQuery);

                        if (null != FindedUser)
                        {
                            arActiveMemberNickNames.Add(FindedUser.NickName);
                            strComment = FindedUser.Comment;
                        }
                    }

                    this.ShellTitle = string.Join(", ", arActiveMemberNickNames);

                    if (1 == nCountOfMembers)
                    {
                        this.StateMessage = strComment;
                    }
                    else
                    {
                        this.StateMessage = arActiveMemberSids.Count.ToString();
                    }
                }
                catch (Exception unExpectedException)
                {
                    GlobalLogger.Log(unExpectedException.Message);
                }
            }
        }
Example #13
0
        private void ExecuteReceiveReadMsgCommand(ReceivedReadMsg rcvdReadMsg)
        {
            var ChatMsgs = this.Messages.OfType <ChatMsg>();

            string[] arMsgSids = rcvdReadMsg.MsgSids.Split(',');

            foreach (string strMsgSid in arMsgSids)
            {
                try
                {
                    var TargetMessage = ChatMsgs.Single(m => m.Sid == strMsgSid);
                    TargetMessage.ReadMembersCount += 1;
                }
                catch (InvalidOperationException invalidOperException)
                {
                    GlobalLogger.Log("Target message doesn't exist.\n" + invalidOperException.Message);
                }
            }
        }
Example #14
0
        public void RequestReadMsgs()
        {
            bool bIsSuccess = this.m_ReadMsgService.ReadMessages(this.m_UnReadMessages);

            if (true == bIsSuccess)
            {
                var MessageCollection = ConnectionHelper.DB.GetCollection <MessageEntity>("MessageEntity");
                var ChatMsgs          = this.Messages.OfType <ChatMsg>();

                foreach (UnReadMsg msg in this.m_UnReadMessages)
                {
                    IList <string> ReadMembers = msg.ReadMembers;
                    if (null == ReadMembers)
                    {
                        ReadMembers = new List <String>();
                    }
                    if (false == ReadMembers.Contains(AuthRepository.MQKeyInfo.UserSid))
                    {
                        ReadMembers.Add(AuthRepository.MQKeyInfo.UserSid);
                    }
                    var UpdateMessageQuery = Update <MessageEntity>
                                             .Set(m => m.State, (int)MsgStatus.Read)
                                             .Set(m => m.ReadMembers, ReadMembers);

                    var FindMessageQuery = Query <MessageEntity> .EQ(m => m.Id, msg.Id);

                    MessageCollection.Update(FindMessageQuery, UpdateMessageQuery);

                    try
                    {
                        var TargetMessage = ChatMsgs.Single(m => m.Sid == msg.Sid);
                        TargetMessage.ReadMembersCount += 1;
                    }
                    catch (InvalidOperationException invalidOperException)
                    {
                        GlobalLogger.Log(invalidOperException.Message);
                    }
                }

                this.m_UnReadMessages.Clear();
            }
        }
Example #15
0
        public void Collect(int nUsersCount, string strMySID, RecommendFriendSummaryCollection recommendFriends)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(10);
                    dynamic parameter = new JObject();
                    parameter.count   = 20;
                    parameter.fromsid = strMySID;
                    var JsonParameters = JsonConvert.SerializeObject(parameter);
                    var postdataString = new StringContent(JsonParameters, new UTF8Encoding(), "application/json");

                    var responseMessage = httpClient.PostAsync(
                        string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.GetRandomUsersInfoURI),
                        postdataString).Result;

                    if (responseMessage.IsSuccessStatusCode)
                    {
                        var JRandomUsers      = JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result);
                        var JArrayRandomUsers = JsonConvert.DeserializeObject <JArray>(JRandomUsers.ToString());

                        foreach (JObject Juser in JArrayRandomUsers)
                        {
                            var RecommendUser = JsonConvert.DeserializeObject <UserEntity>(Juser.ToString());

                            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, new ThreadStart(() =>
                            {
                                recommendFriends.Add
                                    (new RecommendFriendSummary(RecommendUser.ThumbnailPath, RecommendUser.UserId,
                                                                RecommendUser.Sid, RecommendUser.Comment, RecommendUser.NickName));
                            }));
                        }
                    }
                }
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
            }
        }
 public void OnNavigatedTo(NavigationContext navigationContext)
 {
     try
     {
         this.m_FriendsMainViewModel = navigationContext.Parameters[typeof(FriendsViewModel).GetHashCode().ToString()] as IFriendsMainViewModel;
         this.m_FriendsMainViewModel.Friends.CollectionChanged -= Friends_CollectionChanged;
         this.m_FriendsMainViewModel.Friends.CollectionChanged += Friends_CollectionChanged;
     }
     catch (ArgumentNullException argsNullException)
     {
         GlobalLogger.Log(argsNullException.Message);
     }
     catch (NullReferenceException nullRefException)
     {
         GlobalLogger.Log(nullRefException.Message);
     }
     catch (InvalidCastException invalidCastException)
     {
         GlobalLogger.Log(invalidCastException.Message);
     }
 }
Example #17
0
        public SendingMsgResult SendMessage(SendingMsg sendingMsg)
        {
            try
            {
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromSeconds(10);
                    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(AuthRepository.AccessInfo.TokenType, AuthRepository.AccessInfo.AccessToken);
                    //TransmitMsgRequest.Headers.Add(HttpRequestHeader.Authorization, string.Format("{0} {1}", accessInfo.Token_Type, accessInfo.Access_Token));
                    //string postData = String.Format(BeautifulTalkProtocolSet.PublishFormat, BeautifulTalkProtocolSet.OS, BeautifulTalkProtocolSet.ReleaseVersion,
                    //BeautifulTalkProtocolSet.SdkVersion, Environment.UserName, strToSIDs, strRoomSID, nContentType, strContent);

                    dynamic Parameters = new JObject();
                    Parameters.tosids      = new JArray(sendingMsg.ToSIDs.ToArray());
                    Parameters.fromsid     = sendingMsg.FromSID;
                    Parameters.roomsid     = sendingMsg.RoomSID;
                    Parameters.contenttype = sendingMsg.ContentType;
                    Parameters.content     = sendingMsg.Content;

                    var JsonParameters = JsonConvert.SerializeObject(Parameters);
                    var postdataString = new StringContent(JsonParameters, new UTF8Encoding(), "application/json");

                    var responseMessage = httpClient.PostAsync(
                        string.Format("{0}{1}", BeautifulTalkProtocolSet.ServerURIwithPort, BeautifulTalkProtocolSet.SendMsgURI),
                        postdataString).Result;

                    if (responseMessage.IsSuccessStatusCode)
                    {
                        var JResult = JsonConvert.DeserializeObject(responseMessage.Content.ReadAsStringAsync().Result);
                        return(JsonConvert.DeserializeObject <SendingMsgResult>(JResult.ToString()));
                    }
                }
            }
            catch (Exception unExpectedException)
            {
                GlobalLogger.Log(unExpectedException.Message);
            }

            return(new SendingMsgResult());
        }
 private void channel_ModelShutdown(IModel model, ShutdownEventArgs reason)
 {
     GlobalLogger.Log("channel_ModelShutdown");
     this.StartListen();
 }
 private void connection_ConnectionShutdown(IConnection connection, ShutdownEventArgs reason)
 {
     GlobalLogger.Log("connection_ConnectionShutdown");
     this.StartListen();
 }