Пример #1
0
        private void btnUserState_Click(object sender, RoutedEventArgs e)
        {
            CheckUserInputs();
            channel      = txtChannel.Text;
            channelGroup = txtChannelGroup.Text.Trim();

            if (authKey.Trim() != "")
            {
                pubnub.AuthenticationKey = authKey;
            }

            UserStateDialog userStatePopup = new UserStateDialog();

            userStatePopup.txtGetUserStateUUID.Text = uuid;
            userStatePopup.Show();

            userStatePopup.Closed += (obj, args) =>
            {
                if (userStatePopup.DialogResult == true)
                {
                    if (userStatePopup.radGetUserState.IsChecked.Value)
                    {
                        string getUserStateUUID = userStatePopup.txtGetUserStateUUID.Text.Trim();
                        Console.WriteLine("Running GetUserState()");
                        pubnub.GetUserState <string>(channel, getUserStateUUID, DisplayUserCallbackMessage, DisplayErrorMessage);
                    }
                    else if (userStatePopup.radSetUserState.IsChecked.Value)
                    {
                        Console.WriteLine("Running SetUserState()");
                        string userStateKey1   = userStatePopup.txtKey1.Text;
                        string userStateValue1 = userStatePopup.txtValue1.Text;

                        int    valueInt;
                        double valueDouble;
                        if (Int32.TryParse(userStateValue1, out valueInt))
                        {
                            pubnub.SetUserState <string>(channel, new KeyValuePair <string, object>(userStateKey1, valueInt), DisplayUserCallbackMessage, DisplayErrorMessage);
                        }
                        else if (Double.TryParse(userStateValue1, out valueDouble))
                        {
                            pubnub.SetUserState <string>(channel, new KeyValuePair <string, object>(userStateKey1, valueDouble), DisplayUserCallbackMessage, DisplayErrorMessage);
                        }
                        else
                        {
                            pubnub.SetUserState <string>(channel, new KeyValuePair <string, object>(userStateKey1, userStateValue1), DisplayUserCallbackMessage, DisplayErrorMessage);
                        }
                    }
                }
            };
        }
Пример #2
0
        private void btnUserState_Click(object sender, RoutedEventArgs e)
        {
            CheckUserInputs();
            channel = txtChannel.Text;

            if (authKey.Trim() != "")
            {
                pubnub.AuthenticationKey = authKey;
            }

            UserStateDialog userStatePopup = new UserStateDialog();

            userStatePopup.Show();

            userStatePopup.Closed += (obj, args) =>
            {
                if (userStatePopup.DialogResult == true)
                {
                    if (userStatePopup.radGetUserState.IsChecked.Value)
                    {
                        Console.WriteLine("Running GetUserState()");
                        pubnub.GetUserState <string>(channel, DisplayUserCallbackMessage, DisplayErrorMessage);
                    }
                    else if (userStatePopup.radSetUserState.IsChecked.Value)
                    {
                        string userStateKey1 = userStatePopup.txtKey1.Text;
                        string userStateKey2 = userStatePopup.txtKey2.Text;

                        string userStateValue1 = userStatePopup.txtValue1.Text;
                        string userStateValue2 = userStatePopup.txtValue2.Text;

                        int    valueInt;
                        double valueDouble;
                        if (Int32.TryParse(userStateValue1, out valueInt))
                        {
                            pubnub.SetLocalUserState(channel, userStateKey1, valueInt);
                        }
                        else if (Double.TryParse(userStateValue1, out valueDouble))
                        {
                            pubnub.SetLocalUserState(channel, userStateKey1, valueDouble);
                        }
                        else
                        {
                            pubnub.SetLocalUserState(channel, userStateKey1, userStateValue1);
                        }

                        if (Int32.TryParse(userStateValue2, out valueInt))
                        {
                            pubnub.SetLocalUserState(channel, userStateKey2, valueInt);
                        }
                        else if (Double.TryParse(userStateValue2, out valueDouble))
                        {
                            pubnub.SetLocalUserState(channel, userStateKey2, valueDouble);
                        }
                        else
                        {
                            pubnub.SetLocalUserState(channel, userStateKey2, userStateValue2);
                        }

                        string jsonUserState = pubnub.GetLocalUserState(channel);

                        if (!string.IsNullOrEmpty(jsonUserState) && jsonUserState.Trim().Length > 0)
                        {
                            Console.WriteLine("Running SetUserState()");

                            pubnub.SetUserState <string>(channel, uuid, jsonUserState, DisplayUserCallbackMessage, DisplayErrorMessage);
                        }
                        else
                        {
                            Console.WriteLine("Oops. Required Data Missing. Verify user state");
                        }
                    }
                }
            };
        }
        private void btnUserState_Click(object sender, RoutedEventArgs e)
        {
            CheckUserInputs();
            channel = txtChannel.Text;
            channelGroup = txtChannelGroup.Text.Trim();

            if (authKey.Trim() != "")
            {
                pubnub.AuthenticationKey = authKey;
            }

            UserStateDialog userStatePopup = new UserStateDialog();
            userStatePopup.txtGetUserStateUUID.Text = uuid;
            userStatePopup.Show();

            userStatePopup.Closed += (obj, args) =>
            {
                if (userStatePopup.DialogResult == true)
                {
                    if (userStatePopup.radGetUserState.IsChecked.Value)
                    {
                        string getUserStateUUID = userStatePopup.txtGetUserStateUUID.Text.Trim();
                        Console.WriteLine("Running GetUserState()");
                        pubnub.GetUserState<string>(channel, getUserStateUUID, DisplayUserCallbackMessage, DisplayErrorMessage);
                    }
                    else if (userStatePopup.radSetUserState.IsChecked.Value)
                    {
                        Console.WriteLine("Running SetUserState()");
                        string userStateKey1 = userStatePopup.txtKey1.Text;
                        string userStateValue1 = userStatePopup.txtValue1.Text;

                        int valueInt;
                        double valueDouble;
                        if (Int32.TryParse(userStateValue1, out valueInt))
                        {
                            pubnub.SetUserState<string>(channel, new KeyValuePair<string, object>(userStateKey1, valueInt), DisplayUserCallbackMessage, DisplayErrorMessage);
                        }
                        else if (Double.TryParse(userStateValue1, out valueDouble))
                        {
                            pubnub.SetUserState<string>(channel, new KeyValuePair<string, object>(userStateKey1, valueDouble), DisplayUserCallbackMessage, DisplayErrorMessage);
                        }
                        else
                        {
                            pubnub.SetUserState<string>(channel, new KeyValuePair<string, object>(userStateKey1, userStateValue1), DisplayUserCallbackMessage, DisplayErrorMessage);
                        }
                    }
                }
            };
        }
        private void btnUserState_Click(object sender, RoutedEventArgs e)
        {
            CheckUserInputs();
            channel = txtChannel.Text;

            if (authKey.Trim() != "")
            {
                pubnub.AuthenticationKey = authKey;
            }

            UserStateDialog userStatePopup = new UserStateDialog();
            userStatePopup.Show();

            userStatePopup.Closed += (obj, args) =>
            {
                if (userStatePopup.DialogResult == true)
                {
                    if (userStatePopup.radGetUserState.IsChecked.Value)
                    {
                        Console.WriteLine("Running GetUserState()");
                        pubnub.GetUserState<string>(channel, DisplayUserCallbackMessage, DisplayErrorMessage);
                    }
                    else if (userStatePopup.radSetUserState.IsChecked.Value)
                    {
                        string userStateKey1 = userStatePopup.txtKey1.Text;
                        string userStateKey2 = userStatePopup.txtKey2.Text;

                        string userStateValue1 = userStatePopup.txtValue1.Text;
                        string userStateValue2 = userStatePopup.txtValue2.Text;

                        int valueInt;
                        double valueDouble;
                        if (Int32.TryParse(userStateValue1, out valueInt))
                        {
                            pubnub.SetLocalUserState(channel, userStateKey1, valueInt);
                        }
                        else if (Double.TryParse(userStateValue1, out valueDouble))
                        {
                            pubnub.SetLocalUserState(channel, userStateKey1, valueDouble);
                        }
                        else
                        {
                            pubnub.SetLocalUserState(channel, userStateKey1, userStateValue1);
                        }

                        if (Int32.TryParse(userStateValue2, out valueInt))
                        {
                            pubnub.SetLocalUserState(channel, userStateKey2, valueInt);
                        }
                        else if (Double.TryParse(userStateValue2, out valueDouble))
                        {
                            pubnub.SetLocalUserState(channel, userStateKey2, valueDouble);
                        }
                        else
                        {
                            pubnub.SetLocalUserState(channel, userStateKey2, userStateValue2);
                        }
                        
                        string jsonUserState = pubnub.GetLocalUserState(channel);

                        if (!string.IsNullOrEmpty(jsonUserState) && jsonUserState.Trim().Length > 0)
                        {
                            Console.WriteLine("Running SetUserState()");

                            pubnub.SetUserState<string>(channel, uuid, jsonUserState, DisplayUserCallbackMessage, DisplayErrorMessage);
                        }
                        else
                        {
                            Console.WriteLine("Oops. Required Data Missing. Verify user state");
                        }
                    }
                }
            };
        }