Example #1
0
        internal void SetChannelState(ChannelState state, ErrorInfo error = null, ProtocolMessage protocolMessage = null)
        {
            if (Logger.IsDebug)
            {
                var errorMessage = error != null ? "Error: " + error : "";
                Logger.Debug($"#{Name}: Changing state to: '{state}'. {errorMessage}");
            }

            OnError(error);
            var previousState = State;

            HandleStateChange(state, error, protocolMessage);

            //Notify internal clients on the Managed thread
            InternalStateChanged.Invoke(this, new ChannelStateChange(state, previousState, error));

            //Notify external client using the thread they subscribe on
            RealtimeClient.NotifyExternalClients(() =>
            {
                var args = new ChannelStateChange(state, previousState, error);
                try
                {
                    StateChanged.Invoke(this, args);
                }
                catch (Exception ex)
                {
                    Logger.Error($"Error notifying event handlers for state change: {state}", ex);
                }

                Emit(state, args);
            });
        }
 private void Awake()
 {
     client                            = RealtimeClientStarter.Instance.Client;
     rooms                             = client.CachedRoomList;
     client.OnUpdate                  += () => redrawNeeded = true;
     UIController.CreateRoom          += CreateRoom;
     UIController.JoinRoom            += JoinRoom;
     UIController.PlayerNameInput.text = client.LocalPlayer.NickName;
 }
Example #3
0
        private async void StreamButton_Click(object sender, RoutedEventArgs e)
        {
            // Clicking this will begin text-file logging of response from API for all orders on below pair

            Uri gdaxUri = new Uri("wss://ws-feed.gdax.com");

            string[] products = new[] { "BTC-USD" };

            RealtimeClient  client = new RealtimeClient(gdaxUri, products);
            Action <string> a      = ProcessResult;
            await client.SubscribeAsync(a);
        }
Example #4
0
        internal void OnMessage(Message message)
        {
            foreach (var handler in _handlers.GetHandlers())
            {
                var loopHandler = handler;
                RealtimeClient.NotifyExternalClients(() => loopHandler.SafeHandle(message));
            }

            if (message.Name.IsNotEmpty())
            {
                foreach (var specificHandler in _handlers.GetHandlers(message.Name))
                {
                    var loopHandler = specificHandler;
                    RealtimeClient.NotifyExternalClients(() => loopHandler.SafeHandle(message));
                }
            }
        }
Example #5
0
        internal void UpdateState(ConnectionStateBase state)
        {
            if (state.State == State)
            {
                return;
            }

            if (Logger.IsDebug)
            {
                Logger.Debug($"Connection notifying subscribers for state change `{state.State}`");
            }

            var oldState = ConnectionState.State;
            var newState = state.State;

            ConnectionState = state;
            ErrorReason     = state.Error;
            var stateChange = new ConnectionStateChange(oldState, newState, state.RetryIn, ErrorReason);

            var internalHandlers = Volatile.Read(ref InternalStateChanged);   //Make sure we get all the subscribers on all threads
            var externalHandlers = Volatile.Read(ref ConnectionStateChanged); //Make sure we get all the subscribers on all threads

            internalHandlers(this, stateChange);

            RealtimeClient.NotifyExternalClients(() =>
            {
                try
                {
                    externalHandlers(this, stateChange);
                }
                catch (Exception ex)
                {
                    Logger.Error("Error notifying Connection state changed handlers", ex);
                }

                Emit(newState, stateChange);
            });
        }
Example #6
0
        internal void NotifyUpdate(ConnectionStateChange stateChange)
        {
            var externalHandlers =
                Volatile.Read(ref ConnectionStateChanged); // Make sure we get all the subscribers on all threads

            var internalHandlers = Volatile.Read(ref InternalStateChanged);

            internalHandlers(this, stateChange);

            RealtimeClient.NotifyExternalClients(
                () =>
            {
                Emit(stateChange.Event, stateChange);
                try
                {
                    externalHandlers?.Invoke(this, stateChange);
                }
                catch (Exception ex)
                {
                    Logger.Error("Error notifying Connection state changed handlers", ex);
                }
            });
        }
Example #7
0
        async void NavigateToMainViewAsync()
        {
            try
            {
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, /*async*/ () =>
                {
                    if (Views.Direct.InboxView.Current != null)
                    {
                        Views.Direct.InboxView.Current.ResetPageCache();
                        //ViewModels.Direct.InboxViewModel.ResetInstance();
                    }
                    UserHelper.GetSelfUser();
                    UserHelper.GetBanyan();

                    if (Views.Direct.ThreadView.Current != null)
                    {
                        Views.Direct.ThreadView.Current.ResetPageCache();
                    }
                    if (Views.Direct.DirectRequestsThreadView.Current != null)
                    {
                        Views.Direct.DirectRequestsThreadView.Current.ResetPageCache();
                    }
                    if (Views.Direct.DirectRequestsView.Current != null)
                    {
                        Views.Direct.DirectRequestsView.Current.ResetPageCache();
                    }
                    if (ActivitiesView.Current != null)
                    {
                        ActivitiesView.Current.ResetPageCache();
                        //ActivitiesView.Current.NavigationCacheMode = NavigationCacheMode.Disabled;
                        //ActivitiesView.Current.NavigationCacheMode = NavigationCacheMode.Enabled;
                    }
                    if (ExploreView.Current != null)
                    {
                        ExploreView.Current.ResetPageCache();
                        //ExploreView.Current.NavigationCacheMode = NavigationCacheMode.Disabled;
                        //ExploreView.Current.NavigationCacheMode = NavigationCacheMode.Enabled;
                    }
                    if (ExploreView.Current != null)
                    {
                        ExploreView.Current.ResetPageCache();
                    }
                    if (ExploreClusterView.Current != null)
                    {
                        ExploreClusterView.Current.ResetPageCache();
                    }
                    if (LikersView.Current != null)
                    {
                        LikersView.Current.ResetPageCache();
                    }
                    if (Views.Searches.SearchView.Current != null)
                    {
                        Views.Searches.SearchView.Current.ResetPageCache();
                        //Views.Searches.SearchView.Current.NavigationCacheMode = NavigationCacheMode.Disabled;
                        //Views.Searches.SearchView.Current.NavigationCacheMode = NavigationCacheMode.Enabled;
                    }
                    if (Views.Infos.SavedPostsView.Current != null)
                    {
                        Views.Infos.SavedPostsView.Current.ResetPageCache();
                    }
                    if (Views.Infos.CloseFriendsView.Current != null)
                    {
                        Views.Infos.CloseFriendsView.Current.ResetPageCache();
                    }
                    if (Views.Infos.ArchiveView.Current != null)
                    {
                        Views.Infos.ArchiveView.Current.ResetPageCache();
                    }
                    if (Views.Infos.ProfileDetailsView.Current != null)
                    {
                        Views.Infos.ProfileDetailsView.Current.ResetPageCache();
                        //Views.Searches.SearchView.Current.NavigationCacheMode = NavigationCacheMode.Disabled;
                        //Views.Searches.SearchView.Current.NavigationCacheMode = NavigationCacheMode.Enabled;
                    }
                    if (Views.Infos.UserDetailsView.Current != null)
                    {
                        Views.Infos.UserDetailsView.Current.ResetPageCache();
                    }
                    if (Views.Infos.FollowRequestsView.Current != null)
                    {
                        Views.Infos.FollowRequestsView.Current.ResetPageCache();
                        //ActivitiesView.Current.NavigationCacheMode = NavigationCacheMode.Disabled;
                        //ActivitiesView.Current.NavigationCacheMode = NavigationCacheMode.Enabled;
                    }
                    if (Views.Infos.FollowView.Current != null)
                    {
                        Views.Infos.FollowView.Current.ResetPageCache();
                    }
                    if (Views.Infos.HashtagView.Current != null)
                    {
                        Views.Infos.HashtagView.Current.ResetPageCache();
                    }
                    if (Views.Infos.RecentFollowersView.Current != null)
                    {
                        Views.Infos.RecentFollowersView.Current.ResetPageCache();
                    }

                    //if (Views.Posts.ScrollableUserPostView.Current != null)
                    //{
                    //    Views.Posts.ScrollableUserPostView.Current.ResetPageCache();
                    //}
                    if (Views.Posts.MultiplePostView.Current != null)
                    {
                        Views.Posts.MultiplePostView.Current.ResetPageCache();
                    }
                    if (Views.Posts.SinglePostView.Current != null)
                    {
                        Views.Posts.SinglePostView.Current.ResetPageCache();
                    }
                    if (Views.Posts.CommentView.Current != null)
                    {
                        Views.Posts.CommentView.Current.ResetPageCache();
                    }
                    //if (Views.Posts.ScrollableExplorePostView.Current != null)
                    //{
                    //    Views.Posts.ScrollableExplorePostView.Current.ResetPageCache();
                    //}
                    if (Views.TV.TVView.Current != null)
                    {
                        Views.TV.TVView.Current.ResetPageCache();
                    }
                    try
                    {
                        if (RealtimeClient != null)
                        {
                            try
                            {
                                RealtimeClient.Shutdown();
                            }
                            catch { }
                        }
                        RealtimeClient = new RealtimeClient(InstaApi);
                    }
                    catch { }
                    SessionHelper.DontSaveSettings = false;
                });
            }
            catch { }
        }
 public RealtimeClientStarter()
 {
     Client = new RealtimeClient(true);
 }
Example #9
0
        public void OnError(ErrorInfo error)
        {
            ErrorReason = error; //Set or clear the error

            RealtimeClient.NotifyExternalClients(() => Error.Invoke(this, new ChannelErrorEventArgs(error)));
        }