Beispiel #1
0
        }//CheckServerChanges

        /// <summary>
        /// SyncRequestResponseStorage
        /// </summary>
        /// <param name="logTimerType"></param>
        /// <param name="syncUi"></param>
        private void SyncRequestResponseStorage(string logTimerType, Action SyncUi, bool SaveWithSameHash)
        {
            if (string.IsNullOrEmpty(ShAppContext.UserId))
            {
                return;
            }

            ReqSyncDTO    SyncDTO  = ListsManager.Instance.GenerateRequestDTOForSync(ShAppContext.UserId, ShAppContext.UserLogin);
            Task <string> resSync  = HelperFactory.GetHttpHelper().HttpPut <ReqSyncDTO>(SyncDTO, Constants.URL_SYNC, ShAppContext.UserToken);
            string        sResJson = resSync.Result;

            Log.Debug(logTimerType, "Send request server DTO");

            ResSyncDTO ResSync = null;

            try
            {
                ResSync = JsonConvert.DeserializeObject <ResSyncDTO>(sResJson);
                Log.Debug(logTimerType, "OK response from server");
            }
            catch (Exception)
            {
                ResSync = new ResSyncDTO();
                Log.Debug(logTimerType, "Exception deserialize response from server");
            }

            string newhash = Guid.NewGuid().ToString();

            if (ResSync.ErrorCode == 0)
            {
                newhash = Tools.GetMd5Hash(sResJson);
                if (newhash != ListsManager.Instance.CurrentJsonHash && SyncUi != null)
                {
                    ListsManager.Instance.ImportSyncData(newhash, ResSync);
                    SyncUi();
                }//endif
                Log.Debug(logTimerType, "Sync OK");
            }
            else
            {
                Log.Debug(logTimerType, "Error response from server - NOT sync");
            }

            if ((SaveWithSameHash && newhash == ListsManager.Instance.CurrentJsonHash) || (newhash != ListsManager.Instance.CurrentJsonHash))
            {
                string sJson = ListsManager.Instance.GetSerializedDataForLocalStorage();
                FilesManager.WriteShListsState(sJson);
                Log.Debug(logTimerType, "Save in file the changes");
            } //endif
        }     //SyncRequestResponseStorage