private async void Connect() { //Login _syncServer = new SyncServer(this.InstanceName, this.ApiKey); var login = await _syncServer.Start(); this.IsConnected = login.WasSuccessful; //Add subscriptions. if ((await _syncServer.RealTimeSync.GetSubscriptions()).Any(s => s.Type == "Project" && s.Id == this.ProjectId) == false) await _syncServer.RealTimeSync.SubscribeProject(ProjectId); //React on subscriptions using reactive extensions //Subscribe to new data notifications _syncServer.NewDataObservable.SubscribeOnDispatcher().Subscribe(n => { App.Current.Dispatcher.Invoke(() => DataObjectsSync.Add(n.Data)); }); _syncServer.DeleteDataObservable.SubscribeOnDispatcher().Subscribe(n => { App.Current.Dispatcher.Invoke(() => { RefreshDataObjectsSync(); }); }); //Create Http connection object _syncanoClient = new Syncano.Net.SyncanoClient(this.InstanceName, this.ApiKey); //Load existing objects RefreshDataObjectsHttp(); RefreshDataObjectsSync(); }
private async Task PrepareSyncServer() { _syncSubscriber = new SyncServer(TestData.InstanceName, TestData.BackendAdminApiKey); await _syncSubscriber.Start(); _syncServer = new SyncServer(TestData.InstanceName, TestData.BackendAdminApiKey); await _syncServer.Start(); }
private async Task PrepareSyncServer() { _syncServer = new SyncServer(TestData.InstanceName, TestData.BackendAdminApiKey); var loginResult = await _syncServer.Start(); Debug.WriteLine("SyncServer login result: {0}, Info:{1}", loginResult.WasSuccessful, loginResult.Reason); var subscriptions = await _syncServer.RealTimeSync.GetSubscriptions(); if (subscriptions.Count > 0) { if (subscriptions.Any(s => s.Type == "Project")) await _syncServer.RealTimeSync.UnsubscribeProject(TestData.ProjectId); if (subscriptions.Any(s => s.Type == "Collection")) await _syncServer.RealTimeSync.UnsubscribeCollection(TestData.ProjectId, TestData.CollectionId); } _currentConnection = (await _syncServer.RealTimeSync.GetConnections())[0]; }
public async Task Login_WithInvalidPasswordOverTcp_ThrowsException() { //given var syncClient = new SyncServer(TestData.InstanceName, TestData.UserApiKey); await syncClient.Start(); try { //when await syncClient.Users.Login(TestData.UserName, "abcde"); throw new Exception("Login should throw an exception."); } catch (Exception e) { //then e.ShouldBeType<SyncanoException>(); } }
public async Task Merge_ByCollectionId_WithTooBigImageForTcp_ThrowsException() { //given var syncServer = new SyncServer(TestData.InstanceName, TestData.BackendAdminApiKey); await syncServer.Start(); var link = "custom link"; var request = new DataObjectDefinitionRequest(); request.ProjectId = TestData.ProjectId; request.CollectionId = TestData.CollectionId; request.Link = link; request.ImageBase64 = TestData.ImageToBase64("sampleImage.jpg"); request.Link = null; try { //when await syncServer.DataObjects.Merge(request, "dataObjectId"); throw new Exception("Merge should throw an exception."); } catch (Exception e) { //then e.ShouldBeType<SyncanoException>(); } }
public async Task Update_NewAvatarTooBigForTcp_ThrowsException() { //given var syncClient = new SyncServer(TestData.InstanceName, TestData.BackendAdminApiKey); await syncClient.Start(); const string password = "******"; try { //when await syncClient.Users.Update("userId", avatar: TestData.ImageToBase64("smallSampleImage.png"), currentPassword: password); throw new Exception("Update should throw an exception."); } catch (Exception e) { //then e.ShouldBeType<SyncanoException>(); } }
public async Task New_WithAvatarTooBigForTcp_ThrowsException() { //given var syncClient = new SyncServer(TestData.InstanceName, TestData.BackendAdminApiKey); await syncClient.Start(); string name = "newUserName" + Guid.NewGuid().GetHashCode(); string avatar = TestData.ImageToBase64("sampleImage.jpg"); try { //when var user = await syncClient.Users.New(name, avatar: avatar); throw new Exception("New should throw an exception."); } catch (Exception e) { //then e.ShouldBeType<SyncanoException>(); } }