public void ParseSyncCommandResult_Memotoo() { string xml = @"<?xml version=""1.0"" encoding=""UTF-8""?> <Change xmlns:airsync=""AirSync""> <ServerId>3358341</ServerId> <ApplicationData> <Complete xmlns:tasks=""Tasks"">1</Complete> <DueDate xmlns:tasks=""Tasks"">2017-01-10T00:00:00.000Z</DueDate> <UtcDueDate xmlns:tasks=""Tasks"">2017-01-10T21:00:00.000Z</UtcDueDate> <Importance xmlns:tasks=""Tasks"">1</Importance> <ReminderSet xmlns:tasks=""Tasks"">1</ReminderSet> <ReminderTime xmlns:tasks=""Tasks"">2017-01-09T23:00:00.000Z</ReminderTime> <Sensitivity xmlns:tasks=""Tasks"">0</Sensitivity> <StartDate xmlns:tasks=""Tasks"">2017-01-10T00:00:00.000Z</StartDate> <UtcStartDate xmlns:tasks=""Tasks"">2017-01-10T21:00:00.000Z</UtcStartDate> <Subject xmlns:tasks=""Tasks"">Premix Business Manager position, High Frequnecy Plastics, Business Development Director Tuomas Kiikka at + 358 50 386 6420</Subject> <Categories xmlns:tasks=""Tasks""> <Category>Jobs</Category> </Categories> </ApplicationData> </Change>"; var xElement = XElement.Load(new StringReader(xml)); // act var exchangeTask = SyncCommandResult.GetExchangeTask(xElement); // check that we've fallback to today for the completion date Assert.IsNotNull(exchangeTask.Completed); Assert.AreEqual(DateTime.Now.Date, exchangeTask.Completed.Value.Date); }
public async Task <ExchangeSyncResult> ExecuteFirstSyncAsync(ExchangeConnectionInfo connectionInfo, ExchangeChangeSet changeSet) { ExchangeSyncResult loginResult = await this.EnsureLoginAsync(this.taskFolderId, connectionInfo); if (loginResult != null) { return(loginResult); } ActiveSyncServer server = CreateExchangeServer(connectionInfo); // Start sync with sync state = 0 // In this case we only obtain a non ero syncKey to use with future queries SyncCommandResult syncCommandResult = await server.Sync(InitialSyncKey, this.taskFolderId, new ExchangeChangeSet()); connectionInfo.PolicyKey = server.PolicyKey; if (syncCommandResult.Status != StatusOk) { var result = new ExchangeSyncResult { AuthorizationResult = this.GetFailedAuthResult("ExecuteFirstSync", syncCommandResult) }; return(result); } // As it is first sync, we have just picked a new SyncId // We have to re-sync with this new SyncId return(await this.ExecuteSyncAsync(connectionInfo, changeSet, syncCommandResult.SyncKey, this.taskFolderId, true)); }
private ExchangeAuthorizationResult GetFailedAuthResult(string command, SyncCommandResult syncResult) { return(new ExchangeAuthorizationResult { AuthorizationStatus = ExchangeAuthorizationStatus.OK, IsOperationSuccess = false, Status = syncResult.Status, ErrorMessage = $"command: {command} status: {ActiveSyncErrorHelper.GetSyncErrorMessage(syncResult.Status)}" }); }
public void ParseSyncCommandResult_AkrutoSync() { // non regression test for a case where sync fails with a reponse from AkrutoSync string xml = @"<?xml version=""1.0"" encoding=""utf-16""?> <Add xmlns:airsync=""AirSync""> <ServerId xmlns:airsync=""AirSync"">5:16:8052</ServerId> <ApplicationData xmlns:airsync=""AirSync""> <Body xmlns:airsyncbase=""AirSyncBase""> <Type xmlns:airsyncbase=""AirSyncBase"">1</Type> <EstimatedDataSize xmlns:airsyncbase=""AirSyncBase"">136</EstimatedDataSize> <Data xmlns:airsyncbase=""AirSyncBase"">In 2016: Christstollen mit Weihnachtskarten</Data> </Body> <Subject xmlns:tasks=""Tasks"">kleine Geschenke an die Hausmeister</Subject> <Importance xmlns:tasks=""Tasks"">1</Importance> <Categories xmlns:tasks=""Tasks""> <Category xmlns:tasks=""Tasks"">0171 LA-Team Kasse</Category> </Categories> <UtcDueDate xmlns:tasks=""Tasks"">2016-11-08T23:00:00.000Z</UtcDueDate> <DueDate xmlns:tasks=""Tasks"">2016-11-09T00:00:00.000Z</DueDate> <Recurrence xmlns:tasks=""Tasks""> <Type xmlns:tasks=""Tasks"">5</Type> <Start xmlns:tasks=""Tasks"">2015-11-09T00:00:00.000Z</Start> <Interval xmlns:tasks=""Tasks"">1</Interval> <DayOfMonth xmlns:tasks=""Tasks"">9</DayOfMonth> <MonthOfYear xmlns:tasks=""Tasks"">11</MonthOfYear> <Regenerate xmlns:tasks=""Tasks"">0</Regenerate> <DeadOccur xmlns:tasks=""Tasks"">0</DeadOccur> </Recurrence> <Complete xmlns:tasks=""Tasks"">1</Complete> <Sensitivity xmlns:tasks=""Tasks"">2</Sensitivity> <ReminderSet xmlns:tasks=""Tasks"">0</ReminderSet> </ApplicationData> </Add>"; var xElement = XElement.Load(new StringReader(xml)); // act var exchangeTask = SyncCommandResult.GetExchangeTask(xElement); // check that we've fallback to today for the completion date Assert.IsNotNull(exchangeTask.Completed); Assert.AreEqual(DateTime.Now.Date, exchangeTask.Completed.Value.Date); }
public async Task <IActionResult> AddCashExpense([FromBody] AddCashExpense.Command command) { await _mediator.Send(command); return(Ok(SyncCommandResult.From(command, _eventHub.GetEvents()))); }
public async Task <IActionResult> MoveToSavings([FromBody] MoveExpenseToSavings.Command command) { await _mediator.Send(command); return(Ok(SyncCommandResult.From(command, _eventHub.GetEvents()))); }
public async Task <IActionResult> SetExpnenseCategory([FromBody] SetExpenseCategory.Command command) { await _mediator.Send(command); return(Ok(SyncCommandResult.From(command, _eventHub.GetEvents()))); }
private async Task <ExchangeSyncResult> ExecuteSyncAsync(ExchangeConnectionInfo connectionInfo, ExchangeChangeSet changeSet, string syncState, string folderId, bool isFirstSync) { if (connectionInfo == null) { throw new ArgumentNullException("connectionInfo"); } if (changeSet == null) { throw new ArgumentNullException("changeSet"); } if (string.IsNullOrEmpty(syncState)) { throw new ArgumentNullException("syncState"); } if (string.IsNullOrEmpty(folderId) || connectionInfo.ServerUri == null || string.IsNullOrWhiteSpace(connectionInfo.ServerUri.ToString())) { ExchangeSyncResult loginResult = await this.EnsureLoginAsync(folderId, connectionInfo); if (loginResult != null) { return(loginResult); } } else { this.taskFolderId = folderId; } ActiveSyncServer server = CreateExchangeServer(connectionInfo); ExchangeSyncResult returnValue = new ExchangeSyncResult { SyncState = syncState, ChangeSet = new ExchangeChangeSet() }; bool mustSync = true; while (mustSync) { SyncCommandResult result = await server.Sync(returnValue.SyncState, this.taskFolderId, changeSet); if (result.Status != StatusOk) { returnValue.AuthorizationResult = this.GetFailedAuthResult("Sync", result); mustSync = false; } else { returnValue.AuthorizationResult = new ExchangeAuthorizationResult { AuthorizationStatus = ExchangeAuthorizationStatus.OK, IsOperationSuccess = true, ServerUri = connectionInfo.ServerUri }; if (result.SyncKey != null) { returnValue.SyncState = result.SyncKey; } connectionInfo.PolicyKey = server.PolicyKey; // If we don't have any syncstate (nothing has changed) we return the old one returnValue.OperationResult.IsOperationSuccess = true; returnValue.ChangeSet.AddedTasks.AddRange(result.AddedTasks); returnValue.ChangeSet.ModifiedTasks.AddRange(result.ModifiedTasks); returnValue.ChangeSet.DeletedTasks.AddRange(result.DeletedTasks); returnValue.TaskAddedCount += result.ServerAddedTasks; returnValue.TaskEditedCount += result.ServerModifiedTasks; foreach (var map in result.ClientServerMapIds) { returnValue.AddMap(map.Key, map.Value); } returnValue.TaskDeletedCount += changeSet.DeletedTasks.Count; mustSync = result.MoreAvailable; changeSet = new ExchangeChangeSet(); // changeSet has been pushed to server, reset it ! } } return(returnValue); }