/*
         * Children with no priority (the default) come first.
         * Children with a number as their priority come next.
         *  They are sorted numerically by priority, small to large.
         * Children with a string as their priority come last.
         *  They are sorted lexicographically by priority.
         * Whenever two children have the same priority (including no priority),
         *  they are sorted by key. Numeric keys come first (sorted numerically),
         *  followed by the remaining keys (sorted lexicographically).
         */

        public int CompareTo(FirebasePriority other)
        {
            // Children with no priority (the default) come first.
            if (Type == PriorityType.None)
            {
                if (other.Type == PriorityType.None)
                {
                    return(0);
                }

                return(-1);
            }
            else if (other.Type == PriorityType.None)
            {
                return(1);
            }

            // Children with a number as their priority come next.
            if (Type == PriorityType.Numeric)
            {
                if (other.Type == PriorityType.Numeric)
                {
                    if (_fp.HasValue && other._fp.HasValue)
                    {
                        return(_fp.Value.CompareTo(other._fp.Value));
                    }

                    throw new Exception("Priority is a numeric but value not set");
                }

                return(-1);
            }
            else if (other.Type == PriorityType.Numeric)
            {
                return(1);
            }

            // Children with a string as their priority come last.
            if (Type == PriorityType.String)
            {
                if (other.Type == PriorityType.String)
                {
                    if (_sp != null && other._sp != null)
                    {
                        return(String.Compare(_sp, other._sp, StringComparison.Ordinal));
                    }

                    throw new Exception("Priority is a string but value not set");
                }

                // will throw in a moment in release builds
                Debug.Assert(false, "It should not be possible for both to not be strings at this point");
            }
            else if (other.Type == PriorityType.String)
            {
                return(1);
            }

            throw new Exception("Priority sorting did not detect a valid state");
        }
        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);
        }
예제 #3
0
 internal void SetWithPriority(FirebasePath path, string value, FirebasePriority priority,
                               FirebaseStatusCallback callback)
 {
     _cache.SetWithPriority(path, value, priority, callback);
 }
예제 #4
0
 internal void SetPriority(FirebasePath path, FirebasePriority priority, FirebaseStatusCallback callback)
 {
     _cache.SetPriority(path, priority, callback);
 }
 internal void SetWithPriority(FirebasePath path, string value, FirebasePriority priority,
                               FirebaseStatusCallback callback)
 {
     Set(path, value, priority, callback, MessageSouce.Local);
 }
 internal void SetPriority(FirebasePath path, FirebasePriority priority, FirebaseStatusCallback callback)
 {
     Set(path.Child(".priority"), priority.JsonValue, callback);
 }