Class makes possible to connect to Syncano Sync Server over Tcp. Like in class Syncano, in Rest Api module, you can manage your Syncano Instance using it, but also it provides api for subscribing and listening for real time notifications that inform you, what is happening with your Syncano Instance right now. The Sync Server is meant to facilitate notification/subscription processing. To control what you subscribe to or what you want to send, refer to the notification and subscription API documentation. Once you are subscribed to and connected to the Sync Server, you will start receiving real-time notifications.
コード例 #1
0
        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();
        }
コード例 #2
0
        private async Task PrepareSyncServer()
        {
            _syncSubscriber = new SyncServer(TestData.InstanceName, TestData.BackendAdminApiKey);
            await _syncSubscriber.Start();


            _syncServer = new SyncServer(TestData.InstanceName, TestData.BackendAdminApiKey);
            await _syncServer.Start();
        }
コード例 #3
0
        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];
        }
コード例 #4
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>();
            }
            
        }
コード例 #6
0
        public async Task GetConnections_WithApiClientId()
        {
            //given
            var count = 10;
            var servers = new SyncServer[count];
            for (int i = 0; i < count; ++i)
            {
                servers[i] = new SyncServer(TestData.InstanceName, TestData.UserApiKey);
                await servers[i].Start();
            }

            //when
            var result = await _syncServer.RealTimeSync.GetConnections(TestData.BackendAdminApiId);

            //then
            result.ShouldNotBeNull();
            result.ShouldNotBeEmpty();
            result.Any(c => c.Source == Source.Tcp).ShouldBeTrue();
            result.Any(c => c.ApiClientId == TestData.BackendAdminApiId).ShouldBeTrue();

            //cleanup
            foreach (var server in servers)
                server.Stop();
        }
コード例 #7
0
        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>();
            }

            
        }
コード例 #8
0
        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>();
            }
            
        }