private static void CreateWorkbook(out IPersistenceLayer persistence, out IWorkbook workbook) { persistence = new WinPersistenceLayer(false); IWorkbook currentWorkbook = null; if (persistence.HasSave) { try { currentWorkbook = persistence.Open() as Workbook; } catch (Exception ex) { Debug.Fail(ex.ToString()); } } if (currentWorkbook == null) { persistence.Initialize(); persistence.Save(); currentWorkbook = new Workbook(persistence.Context, WinSettings.Instance); } workbook = currentWorkbook; workbook.Initialize(); }
public override VoiceCommandResponse Execute(IWorkbook workbook, IPersistenceLayer persistenceLayer, Windows.ApplicationModel.VoiceCommands.VoiceCommand voiceCommand) { string content = this.ExtractPropertyFromVoiceCommand(voiceCommand, "speech"); content = content.FirstLetterToUpper(); content = content.Trim(); content = content.Trim('.'); var task = new Task { Added = DateTime.Now, Modified = DateTime.Now, Title = content, Folder = workbook.Folders[0] }; task.Priority = workbook.Settings.GetValue <TaskPriority>(CoreSettings.DefaultPriority); task.Due = ModelHelper.GetDefaultDueDate(workbook.Settings); task.Start = ModelHelper.GetDefaultStartDate(workbook.Settings); task.Context = ModelHelper.GetDefaultContext(workbook); persistenceLayer.Save(); this.UpdateLiveTiles(workbook); var userMessage = new VoiceCommandUserMessage { DisplayMessage = string.Format(StringResources.Notification_NewTaskCreatedNoDueDateFormat, content), SpokenMessage = StringResources.Notification_NewTaskCreatedNoDueDateFormat.Replace("\"{0}\"", string.Empty) }; this.SignalForegroundAppWorkbookChanged(); return(VoiceCommandResponse.CreateResponse(userMessage)); }
protected IWorkbook InitializeWorkbook(IPersistenceLayer persistence, IPlatformService platformService) { IWorkbook workbook = null; if (persistence.HasSave) { try { workbook = persistence.Open(); } catch (Exception ex) { TrackingManagerHelper.Exception(ex, "Initialize workbook"); platformService.DeleteFileAsync(persistence.DatabaseFilename).Wait(1000); } } if (workbook == null) { persistence.Initialize(); workbook = this.CreateDefaultWorkbook(persistence.Context, platformService); persistence.Save(); } // important: read view from persistence and not from workbook as they are not loaded yet in the workbook ! if (persistence.Context.Views.Count() != DefaultDataCreator.ViewCount) { CreateDefaultViews(workbook); } workbook.Initialize(); Ioc.RegisterInstance <IWorkbook, Workbook>((Workbook)workbook); return(workbook); }
public async Task <bool> TrySyncAsync(IPersistenceLayer persistenceLayer) { if (!this.CanSync()) { throw new NotSupportedException("Background sync is not available"); } try { LogService.Log("BackgroundSync", string.Format("Synchronization starting using {0}", NetworkHelper.GetNetworkStatus())); await this.synchronizationManager.Sync(); if (this.HasSyncProducedChanges(this.synchronizationManager.Metadata)) { this.workbook.Settings.SetValue(CoreSettings.SyncBackgroundOccured, true); } persistenceLayer.Save(); await this.WriteSyncMetadataAsync((SynchronizationMetadata)this.synchronizationManager.Metadata); LogService.Log("BackgroundSync", "Synchronization completed"); return(true); } catch (Exception ex) { var message = "Exception will doing background sync: " + ex.Message + " " + ex.StackTrace; if (this.toastBackgroundSync && this.toastMessage != null) { this.toastMessage(message); } TrackingManagerHelper.Exception(ex, "TrySyncAsync background"); return(false); } }