Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
0
        public void ClientConfig_Test()
        {
            var store = new SyncServiceConfigStore(@"D:\Taras\stest\client.json");
            var conf  = store.ReadClientOrDefault();

            if (conf.Pairs == null)
            {
                conf.Pairs = new List <SyncPairConfigModel>();
            }

            conf.Pairs.Add(new SyncPairConfigModel
            {
                BaseDir       = @"/storage/emulated/0/stest",
                DbDir         = @"/storage/emulated/0/stest/.sync",
                SyncMode      = SyncMode.TwoWay,
                ServerAddress = "127.0.0.2",
                ServerPort    = "-111",
            });

            store.Save(conf);
        }