示例#1
0
        internal static FirebaseApp FromJson(string json)
        {
            // after the connect call, make it look like some data has shown up.
            var connection = A.Fake<IFirebaseNetworkConnection>();
            A.CallTo(() => connection.Connect()).Invokes(() =>
            {
                var msg = new FirebaseMessage(WriteBehavior.Replace, new FirebasePath(), json, null, MessageSouce.Remote);
                var args = new FirebaseEventReceivedEventArgs(msg);

                // do it on a separate thread to make sure we don't ignore
                // locking issues during tests
                Task.Run(() => connection.Received += Raise.With(args));
            });

            return new FirebaseApp(new Uri("https://example.com/"), connection);
        }
示例#2
0
 private void OnChanged(FirebaseMessage message)
 {
     var callback = Changed;
     if (callback != null)
     {
         callback(this, new JsonCacheUpdateEventArgs(message.Path));
     }
 }
示例#3
0
        public void Update(FirebasePath path, string data, FirebaseStatusCallback callback)
        {
            var message = new FirebaseMessage(WriteBehavior.Merge, path, data, callback, MessageSouce.Local);

            UpdateLocal(message);
        }
示例#4
0
 private void QueueUpdate(FirebaseMessage firebaseMessage)
 {
     _connection.Send(firebaseMessage);
 }
示例#5
0
        private void UpdateLocal(FirebaseMessage message)
        {
            if (message.Value == null)
            {
                Delete(message.Path);
            }
            else
            {
                JToken newData = CreateToken(message.Value);


                if (message.Behavior == WriteBehavior.Merge)
                {
                    Merge(message.Path, newData);
                }
                else
                {
                    if (message.Behavior == WriteBehavior.Replace)
                    {
                        if (message.Priority != null)
                        {
                            newData[".priority"] = new JValue(message.Priority.JsonValue);
                        }
                    }

                    InsertAt(message.Path, newData);
                }
            }

            OnChanged(message);

            if (message.Source == MessageSouce.Local)
            {
                QueueUpdate(message);
            }
        }
示例#6
0
        private void Set(FirebasePath path, string data, FirebasePriority priority, FirebaseStatusCallback callback,
            MessageSouce source)
        {
            var message = new FirebaseMessage(WriteBehavior.Replace, path, data, priority, callback, source);

            UpdateLocal(message);
        }
 public FirebaseEventReceivedEventArgs(FirebaseMessage message)
 {
     Message = message;
 }
 public void Send(FirebaseMessage message)
 {
     _sendQueue.Enqueue(_cancelSource.Token, message);
 }
        private HttpMethod GetMethod(FirebaseMessage message)
        {
            if (message.Value == null)
            {
                return HttpMethod.Delete;
            }

            switch (message.Behavior)
            {
                case WriteBehavior.Merge:
                    return new HttpMethod("PATCH");
                case WriteBehavior.Push:
                    return HttpMethod.Post;
                case WriteBehavior.Replace:
                    return HttpMethod.Put;
                default:
                    throw new NotImplementedException();
            }
        }