private void ProcessServerData(FirebaseServerEventType serverEvent, string serverData)
        {
            switch (serverEvent)
            {
            case FirebaseServerEventType.Put:
            case FirebaseServerEventType.Patch:
                var result = JObject.Parse(serverData);
                var path   = result["path"].ToString();
                var data   = result["data"].ToString();

                if (path == "/" && data == string.Empty)
                {
                    this.observer.OnNext(FirebaseEvent <T> .Empty(FirebaseEventSource.Online));
                    return;
                }

                var eventType = string.IsNullOrWhiteSpace(data) ? FirebaseEventType.Delete : FirebaseEventType.InsertOrUpdate;

                var items = this.cache.PushData(this.elementRoot + path, data);

                foreach (var i in items.ToList())
                {
                    this.observer.OnNext(new FirebaseEvent <T>(i.Key, i.Object, eventType, FirebaseEventSource.Online));
                }

                break;

            case FirebaseServerEventType.KeepAlive:
                break;

            case FirebaseServerEventType.Cancel:
                this.observer.OnError(new Exception("cancel"));
                this.Dispose();
                throw new OperationCanceledException();

            case FirebaseServerEventType.AuthRevoked:
                this.observer.OnError(new Exception("auth"));
                this.Dispose();
                throw new OperationCanceledException();
            }
        }
Exemplo n.º 2
0
        private void ProcessServerData(string url, FirebaseServerEventType serverEvent, string serverData)
        {
            switch (serverEvent)
            {
            case FirebaseServerEventType.Put:
            case FirebaseServerEventType.Patch:
                var result = JObject.Parse(serverData);
                var path   = result["path"].ToString();
                var data   = result["data"].ToString();

                // If an elementRoot parameter is provided, but it's not in the cache, it was already deleted. So we can return an empty object.
                if (string.IsNullOrWhiteSpace(this.elementRoot) || !this.cache.Contains(this.elementRoot))
                {
                    if (path == "/" && data == string.Empty)
                    {
                        this.observer.OnNext(FirebaseEvent <T> .Empty(FirebaseEventSource.OnlineStream));
                        return;
                    }
                }

                var eventType = string.IsNullOrWhiteSpace(data) ? FirebaseEventType.Delete : FirebaseEventType.InsertOrUpdate;

                var items = this.cache.PushData(this.elementRoot + path, data);

                foreach (var i in items.ToList())
                {
                    this.observer.OnNext(new FirebaseEvent <T>(i.Key, i.Object, eventType, FirebaseEventSource.OnlineStream));
                }

                break;

            case FirebaseServerEventType.KeepAlive:
                break;

            case FirebaseServerEventType.Cancel:
                this.observer.OnError(new FirebaseException(url, string.Empty, serverData, HttpStatusCode.Unauthorized));
                this.Dispose();
                break;
            }
        }