示例#1
0
        /// <summary>
        /// Sync
        /// </summary>
        /// <returns></returns>
        public async Task SyncAsync()
        {
            Debug.WriteLine($"Synchro de : {typeof(T).Name}");

            if (!Debugger.IsAttached && !connectivityService.IsConnected)
            {
                return;
            }
            if (!Debugger.IsAttached && !await connectivityService.IsRemoteReachable(configuration.ApiBaseUrl))
            {
                errorService.Value.ShowError($"Server not available ({configuration.ApiBaseUrl})");
                return;
            }

            if (Application.Current.Properties.TryGetValue($"{typeof(T).Name}.LastSynchroDate", out object date))
            {
                Debug.WriteLine($"Last sync done : {date}");
                lastSync = DateTimeOffset.Parse(date.ToString());
            }
            else
            {
                lastSync = DateTimeOffset.MinValue;
            }

            var nowSyncDate = DateTimeOffset.Now;

            await PushAsync();

            await PullAsync();

            Application.Current.Properties[$"{typeof(T).Name}.LastSynchroDate"] = nowSyncDate;

            await Application.Current.SavePropertiesAsync();
        }