예제 #1
0
        static void Main(string[] args)
        {
            var cfg = new DummyConfig();

            cfg.Clients.Add(new RegisteredClient
            {
                Id = Guid.Empty,
                FolderEndpoints =
                {
                    new ClientFolderEndpoint
                    {
                        Id          = Guid.Empty,
                        DisplayName = "f1",
                        LocalPath   = @"C:\shcherban\stest\tests\server",
                    }
                }
            });

            var srv = new SyncServer(ServerPort, Guid.Empty, cfg);

            srv.Msg += Console.WriteLine;
            srv.Start();

            var ipEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), ServerPort);
            var client     = SyncClientFactory.GetTwoWay(ipEndPoint, @"C:\shcherban\stest\tests\client", null, Guid.Empty, Guid.Empty);

            client.Log += Console.WriteLine;
            client.Sync().Wait();

            Console.WriteLine("Done");
            Console.ReadKey();

            srv.Stop();
        }
        private async void SyncBtnOnClick(object sender, EventArgs e)
        {
            _syncBtn.Enabled = false;

            try
            {
                if (FileSyncApp.Instance.ActiveClients.ContainsKey(_folderId))
                {
                    throw new Exception("WTF, sync in progress");
                }

                _client = SyncClientFactory.GetTwoWay(Common.Extensions.ParseEndpoint(_serverUrl), _folderItem.LocalPath, null, FileSyncApp.Instance.Config.ClientId, _folderItem.Id);

                FileSyncApp.Instance.ActiveClients[_folderId] = _client; // TODO

                _client.Log += AppendLog;

                await Task.Run(_client.Sync);

                FileSyncApp.Instance.ActiveClients.Remove(_folderId);

                _client.Log -= AppendLog;
                _client      = null;
            }
            finally
            {
                _syncBtn.Enabled = true;
                _client          = null;
            }
        }
        private void PrepareServerClient()
        {
            _testServerConfig = new TestServerConfig();
            _testServerConfig.Clients.Add(new RegisteredClient
            {
                Id = Guid.Empty,
                FolderEndpoints =
                {
                    new ClientFolderEndpoint
                    {
                        Id          = Guid.Empty,
                        DisplayName = "folder1",
                        LocalPath   = _serverFolder,
                    }
                }
            });

            SessionStorage.Instance.SetTimeout(0);

            _server      = new SyncServer(ServerPort, Guid.Empty, _testServerConfig);
            _server.Msg += ServerWrite;
            _server.Start();

            var serverEp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), ServerPort);

            _client             = SyncClientFactory.GetTwoWay(serverEp, _clientFolder, null, Guid.Empty, Guid.Empty);
            _client.Log        += ClientWrite;
            _client.ErrorEvent += ClientOnErrorEvent;
        }
예제 #4
0
        public void TwoWaySync_Test()
        {
            var server = new SyncServer(9211, @"D:\Taras\stest");

            server.Msg += Console.WriteLine;

            server.Start();

            var client = SyncClientFactory.GetTwoWay("127.0.0.1", 9211, @"D:\Taras\stestsrc");

            client.Sync().Wait();

            server.Stop();
        }
예제 #5
0
        private async void SyncBtn_OnClick(object sender, EventArgs e)
        {
            _syncBtn.Enabled = false;

            try
            {
                var res = await TryGetPermissionsAsync();

                if (!res)
                {
                    Toast.MakeText(this, "Storage permission denied.", ToastLength.Short).Show();

                    return;
                }

                var config = _configStore.ReadClientOrDefault();
                if (config.Pairs == null || config.Pairs.Count == 0)
                {
                    Toast.MakeText(this, "No sync pair found.", ToastLength.Short).Show();

                    return;
                }

                var pair = config.Pairs[0];

                AppendLog($"Starting sync with {pair.ServerAddress}:{pair.ServerPort}...");

                //const string dir = @"/mnt/sdcard";
                //const string dir = @"/storage/emulated/0/stest/";
                //const string dir = @"/storage/emulated/0/music/";
                //const string dir = @"/storage/emulated/0/DCIM/";

                var baseDir = pair.BaseDir;
                var dbDir   = pair.DbDir;

                var client = SyncClientFactory.GetTwoWay(pair.ServerAddress, int.Parse(pair.ServerPort), baseDir, dbDir);

                client.Log += AppendLog;

                await client.Sync();
            }
            finally
            {
                _syncBtn.Enabled = true;
            }
        }