예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RealtimeDatabase{T}"/> class.
        /// </summary>
        /// <param name="childQuery"> The child query.  </param>
        /// <param name="elementRoot"> The element Root. </param>
        /// <param name="offlineDatabaseFactory"> The offline database factory.  </param>
        /// <param name="filenameModifier"> Custom string which will get appended to the file name.  </param>
        /// <param name="streamChanges"> Specifies whether changes should be streamed from the server.  </param>
        /// <param name="pullEverythingOnStart"> Specifies if everything should be pull from the online storage on start. It only makes sense when <see cref="streamChanges"/> is set to true. </param>
        /// <param name="pushChanges"> Specifies whether changed items should actually be pushed to the server. It this is false, then Put / Post / Delete will not affect server data. </param>
        public RealtimeDatabase(ChildQuery childQuery, string elementRoot, Func <Type, string, IDictionary <string, OfflineEntry> > offlineDatabaseFactory, string filenameModifier, bool streamChanges, InitialPullStrategy initialPullStrategy, bool pushChanges)
        {
            this.childQuery          = childQuery;
            this.elementRoot         = elementRoot;
            this.streamChanges       = streamChanges;
            this.initialPullStrategy = initialPullStrategy;
            this.pushChanges         = pushChanges;
            this.Database            = offlineDatabaseFactory(typeof(T), filenameModifier);
            this.subject             = new Subject <FirebaseEvent <T> >();

            Task.Factory.StartNew(this.SynchronizeThread, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RealtimeDatabase{T}"/> class.
        /// </summary>
        /// <param name="childQuery"> The child query.  </param>
        /// <param name="elementRoot"> The element Root. </param>
        /// <param name="offlineDatabaseFactory"> The offline database factory.  </param>
        /// <param name="filenameModifier"> Custom string which will get appended to the file name.  </param>
        /// <param name="streamChanges"> Specifies whether changes should be streamed from the server.  </param>
        /// <param name="pullEverythingOnStart"> Specifies if everything should be pull from the online storage on start. It only makes sense when <see cref="streamChanges"/> is set to true. </param>
        /// <param name="pushChanges"> Specifies whether changed items should actually be pushed to the server. If this is false, then Put / Post / Delete will not affect server data. </param>
        public RealtimeDatabase(ChildQuery childQuery, string elementRoot, Func <Type, string, IDictionary <string, OfflineEntry> > offlineDatabaseFactory, string filenameModifier, StreamingOptions streamingOptions, InitialPullStrategy initialPullStrategy, bool pushChanges, ISetHandler <T> setHandler = null)
        {
            this.childQuery          = childQuery;
            this.elementRoot         = elementRoot;
            this.streamingOptions    = streamingOptions;
            this.initialPullStrategy = initialPullStrategy;
            this.pushChanges         = pushChanges;
            this.Database            = offlineDatabaseFactory(typeof(T), filenameModifier);
            this.firebaseCache       = new FirebaseCache <T>(new OfflineCacheAdapter <string, T>(this.Database));
            this.subject             = new Subject <FirebaseEvent <T> >();

            this.PutHandler = setHandler ?? new SetHandler <T>();

            this.isSyncRunning = true;
            Task.Factory.StartNew(this.SynchronizeThread, CancellationToken.None, TaskCreationOptions.LongRunning, TaskScheduler.Default);
        }
        public FirebaseOfflineCacheRepo(
            FirebaseClient client,
            string path,
            string key = "",
            StreamingOptions streaming      = StreamingOptions.None,
            InitialPullStrategy initialPull = InitialPullStrategy.Everything)
        {
            // The offline database filename is named after type T.
            // So, if you have more than one list of type T objects, you need to differentiate it
            // by adding a filename modifier; which is what we're using the "key" parameter for.
            _baseQuery  = client.Child(path);
            _realtimeDb = _baseQuery
                          .AsRealtimeDatabase <T>(key, string.Empty, streaming, initialPull, true);

            SyncExceptionThrown = Observable
                                  .FromEventPattern <ExceptionEventArgs>(
                h => _realtimeDb.SyncExceptionThrown += h,
                h => _realtimeDb.SyncExceptionThrown -= h);
        }
예제 #4
0
 /// <summary>
 /// Create new instances of the <see cref="RealtimeDatabase{T}"/>.
 /// </summary>
 /// <typeparam name="T"> Type of elements. </typeparam>
 /// <typeparam name="TSetHandler"> Type of the custom <see cref="ISetHandler{T}"/> to use. </typeparam>
 /// <param name="filenameModifier"> Custom string which will get appended to the file name. </param>
 /// <param name="elementRoot"> Optional custom root element of received json items. </param>
 /// <param name="streamingOptions"> Realtime streaming options. </param>
 /// <param name="initialPullStrategy"> Specifies what strategy should be used for initial pulling of server data. </param>
 /// <param name="pushChanges"> Specifies whether changed items should actually be pushed to the server. It this is false, then Put / Post / Delete will not affect server data. </param>
 /// <returns> The <see cref="RealtimeDatabase{T}"/>. </returns>
 public static RealtimeDatabase <T> AsRealtimeDatabase <T, TSetHandler>(this ChildQuery query, string filenameModifier = "", string elementRoot = "", StreamingOptions streamingOptions = StreamingOptions.LatestOnly, InitialPullStrategy initialPullStrategy = InitialPullStrategy.MissingOnly, bool pushChanges = true)
     where T : class
     where TSetHandler : ISetHandler <T>, new()
 {
     return(new RealtimeDatabase <T>(query, elementRoot, query.Client.Options.OfflineDatabaseFactory, filenameModifier, streamingOptions, initialPullStrategy, pushChanges, Activator.CreateInstance <TSetHandler>()));
 }
예제 #5
0
 /// <summary>
 /// The as offline database.
 /// </summary>
 /// <typeparam name="T"> Type of elements. </typeparam>
 /// <param name="filenameModifier"> Custom string which will get appended to the file name. </param>
 /// <param name="elementRoot"> Optional custom root element of received json items. </param>
 /// <param name="streamChanges"> Specifies whether changes should be streamed from the server. </param>
 /// <param name="initialPullStrategy"> Specifies what strategy should be used for initial pulling of server data. </param>
 /// <param name="pushChanges"> Specifies whether changed items should actually be pushed to the server. It this is false, then Put / Post / Delete will not affect server data. </param>
 /// <returns> The <see cref="RealtimeDatabase{T}"/>. </returns>
 public RealtimeDatabase <T> AsRealtimeDatabase <T>(string filenameModifier = "", string elementRoot = "", bool streamChanges = true, InitialPullStrategy initialPullStrategy = InitialPullStrategy.MissingOnly, bool pushChanges = true) where T : class
 {
     return(new RealtimeDatabase <T>(this, elementRoot, this.Client.Options.OfflineDatabaseFactory, filenameModifier, streamChanges, initialPullStrategy, pushChanges));
 }
예제 #6
0
 public static RealtimeDatabase <T> AsRealtimeDatabase <T>(this ChildQuery query, string filenameModifier = "", string elementRoot = "", bool streamChanges = true, InitialPullStrategy initialPullStrategy = InitialPullStrategy.MissingOnly, bool pushChanges = true)
     where T : class
 {
     return(new RealtimeDatabase <T>(query, elementRoot, query.Client.Options.OfflineDatabaseFactory, filenameModifier, streamChanges ? StreamingOptions.LatestOnly : StreamingOptions.None, initialPullStrategy, pushChanges));
 }