/// <summary> /// Attempt to synchronize <see cref="Dataset"/> when connectivity is available. If /// the connectivity is available right away, it behaves the same as /// <see cref="Dataset.Synchronize()"/>. Otherwise it listens to connectivity /// changes, and will do a sync once the connectivity is back. Note that if /// this method is called multiple times, only the last synchronize request /// is kept. If either the dataset or the callback is garbage collected /// , this method will not perform a sync and the callback won't fire. /// </summary> public virtual void SynchronizeOnConnectivity() { if (NetworkInfo.GetReachability() != NetworkReachability.NotReachable) { Synchronize(); } else { waitingForConnectivity = true; } }
/// <summary> /// Determines whether this instance has network connectivity. /// </summary> /// <returns><c>true</c> if this instance has network connectivity; otherwise, <c>false</c>.</returns> private bool HasNetworkConnectivity() { NetworkReachability networkReachability = NetworkInfo.GetReachability(); bool networkFlag = false; switch (networkReachability) { case NetworkReachability.NotReachable: networkFlag = false; break; case NetworkReachability.ReachableViaLocalAreaNetwork: networkFlag = true; break; case NetworkReachability.ReachableViaCarrierDataNetwork: networkFlag = IsDataAllowed; break; } return(networkFlag); }
/// <summary> /// Synchronize <see cref="Dataset"/> between local storage and remote storage. /// </summary> public virtual void Synchronize() { if (NetworkInfo.GetReachability() == NetworkReachability.NotReachable) { FireSyncFailureEvent(new NetworkException("Network connectivity unavailable.")); return; } // if the thread is in background thread, then start synchronizing, // else queue the synchronization in a threadpool thread if (!UnityInitializer.IsMainThread()) { SynchronizeInternalAsync(); } else { ThreadPool.QueueUserWorkItem(new WaitCallback(delegate { SynchronizeInternalAsync(); })); } }