Exemplo n.º 1
0
        public void CheckForServiceUpdates()
        {
            var app = ApplicationState.Current;

            lock (_lock) {
                this.Log("Service request to Check for Service Updates", "", 3);
                WebServiceJsonRequestStatus status = ServerJsonRequest("GetUpdates", new GetServiceUpdatesModel()
                {
                    rid        = app.ResponderId,
                    reg        = app.ResponderRegion,
                    apn        = app.APNSId,
                    LastUpdate = app.LastSuccessfulServiceUpdate
                });
                app = ApplicationState.Current;
                if (status.Success)
                {
                    UpdateAppFromServiceModel updates = status.Response.ToObject <UpdateAppFromServiceModel> ();
                    if (updates.HasPromptUpdates || updates.Application != null)
                    {
                        ApplyUpdates(updates);
                    }
                    app = ApplicationState.Current;
                    app.LastSuccessfulServiceUpdate = DateTime.UtcNow;
                    app.Save();
                }
            }
        }
Exemplo n.º 2
0
        protected void ApplyUpdates(UpdateAppFromServiceModel updates)
        {
            var app = ApplicationState.Current;

            if (updates.HasPromptUpdates || updates.Application != null)
            {
                if (updates.Prompts != null && updates.Prompts.Count() > 0)
                {
                    SyncPrompts(updates.Prompts);
                }
                if (updates.Categories != null && updates.Categories.Count() > 0)
                {
                    foreach (var c in updates.Categories)
                    {
                        SyncCategory(c);
                    }
                }
                if (updates.Application != null)
                {
                    UpdateApplication(updates.Application, false);
                }
                app.LastSuccessfulServiceUpdate = updates.SyncTimestamp;
                app.Save();
            }
            if (updates.SyncSuccess)
            {
                app.LastSuccessfulDataPush = updates.SyncTimestamp;
                app.Save();
            }
        }
Exemplo n.º 3
0
        public ServiceSyncStatus SyncDataWithServer()
        {
            ServiceSyncStatus rtnStatus = new ServiceSyncStatus();

            lock (_lock) {
                this.Log("Service request to Sync with Server", "", 3);
                var app = ApplicationState.Current;
                IEnumerable <MoodResponseUpdateModel> responsesToUpdate = GetResponsesToSaveToServer(app.LastSuccessfulDataPush);
                rtnStatus.HasOutstandingResponsesToSync = responsesToUpdate.Count() > 0;

                WebServiceJsonRequestStatus status = SendSyncRequest(app, responsesToUpdate);

                app = ApplicationState.Current;
                if (status.Success)
                {
                    UpdateAppFromServiceModel updates = status.Response.ToObject <UpdateAppFromServiceModel> ();

                    if (status.Success)
                    {
                        ApplyUpdates(updates);
                        rtnStatus.HasPromptUpdates = updates.HasPromptUpdates;
                        rtnStatus.HasOutstandingResponsesToSync = false;
                    }

                    //server has different total of responses so resubmit all
                    if (updates.ResError)
                    {
                        this.Log("Server res error - resyncing", "", 2);
                        status = SendSyncRequest(app, GetResponsesToSaveToServer(null));
                        if (status.Success)
                        {
                            ApplyUpdates(updates);
                            rtnStatus.HasPromptUpdates = updates.HasPromptUpdates;
                            rtnStatus.HasOutstandingResponsesToSync = false;
                        }
                    }
                }
                rtnStatus.Success = status.Success;
                rtnStatus.LastSuccessfulDataPush = app.LastSuccessfulDataPush;
                rtnStatus.SuccessLevel           = GetSyncSuccessLevel(status.Success, responsesToUpdate.Count());
            }

            return(rtnStatus);
        }