示例#1
0
        public static void Synchronize(EndpointAddress remoteAddress)
        {
            SyncServiceClient serviceClient = serviceProxy(remoteAddress);

            downloadDatabase(serviceClient);

            using (var localDbConnection = new SqlCeConnection(Constants.LocalConnectionString))
            {
                using (var remoteDbConnection = new SqlCeConnection(Constants.RemoteConnectionString))
                {
                    var syncOrchestrator = new SyncOrchestrator
                    {
                        Direction      = SyncDirectionOrder.DownloadAndUpload,
                        RemoteProvider =
                            new SqlCeSyncProvider("SyncScope", remoteDbConnection),
                        LocalProvider = new SqlCeSyncProvider("SyncScope", localDbConnection)
                    };

                    syncOrchestrator.Synchronize();

                    uploadDatabase(serviceClient);
                }
            }

            ContactsManager.Current.RefreshCache();
            CompaniesManager.Current.RefreshCache();
        }
示例#2
0
        public DirSyncroForm()
        {
            InitializeComponent();
            ssc = new SyncServiceClient();

            config = Utility.ReadFromXML <DirSyncro.DirSyncro>(configurationFile);

            watcherGrid.Rows.Add(config.Watcher.Length);
            for (int i = 0; i < config.Watcher.Length; i++)
            {
                watcherGrid.Rows[i].Cells["enabled"].Value = new DataGridViewImageCell();
                watcherGrid.Rows[i].Cells["watcher"].Value = new DataGridViewTextBoxCell();
            }
            for (int i = 0; i < config.Watcher.Length; i++)
            {
                if (config.Watcher[i].Enabled)
                {
                    watcherGrid.Rows[i].Cells["enabled"].Tag   = true;
                    watcherGrid.Rows[i].Cells["enabled"].Value = Resources.On;
                }
                else
                {
                    watcherGrid.Rows[i].Cells["enabled"].Tag   = false;
                    watcherGrid.Rows[i].Cells["enabled"].Value = Resources.Off;
                }
                watcherGrid.Rows[i].Cells["watcher"].Value = config.Watcher[i].Name;
                watcherGrid.Rows[i].Tag = i;
            }
        }
示例#3
0
        private static void downloadDatabase(SyncServiceClient serviceClient)
        {
            // create output folder, if does not exist
            if (!Directory.Exists(Constants.DOWNLOAD_FOLDER))
            {
                Directory.CreateDirectory(Constants.DOWNLOAD_FOLDER);
            }

            // kill target file, if already exists
            string filePath = Path.Combine(Constants.DOWNLOAD_FOLDER, Constants.REMOTE_DB_NAME);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            // get stream from server
            Stream inputStream;
            string fileName = "";
            long   length   = serviceClient.DownloadFile(ref fileName, out inputStream);

            // write server stream to disk
            using (var writeStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write))
            {
                const int chunkSize = 2048;
                var       buffer    = new byte[chunkSize];

                do
                {
                    // read bytes from input stream
                    int bytesRead = inputStream.Read(buffer, 0, chunkSize);
                    if (bytesRead == 0)
                    {
                        break;
                    }

                    // write bytes to output stream
                    writeStream.Write(buffer, 0, bytesRead);

                    // report progress from time to time
                    //progressBar1.Value = (int)(writeStream.Position * 100 / length);
                } while (true);
            }

            // close service client
            inputStream.Dispose();
            // serviceClient.Close();
        }
示例#4
0
 public override void RunOnce()
 {
     try
     {
         using (var client = new SyncServiceClient())
         {
             var result = client.Sync();
             var obj    = DataObj2.Parse(result);
             if (Submit != null && obj != null)
             {
                 Submit(this, new ValueEventArgs <DataObj2>(obj));
             }
         }
     }
     catch (TimeoutException)
     {
         //No problems
         //Timeout every 10 minute
         Thread.Sleep(TimeSpan.FromSeconds(1));
     }
 }
示例#5
0
        public MainWindow()
        {
            InitializeComponent();

            // initialize client
            client = new SyncServiceClient(this);

            // create default project at start-up
            CreateNewPorject();

            // bind commands
            CommandBindings.Add(new CommandBinding(ApplicationCommands.New, New_Executed));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, Open_Executed));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, Save_Executed));

            Closing += MainWindow_Closing;

            #if DEBUG_ON
            // display console to help debug
            CMDConsole.ConsoleManager.Show();
            #endif
        }
示例#6
0
        public MainWindow()
        {
            InitializeComponent();

            // initialize client
            client = new SyncServiceClient(this);

            // create default project at start-up
            CreateNewPorject();

            // bind commands
            CommandBindings.Add(new CommandBinding(ApplicationCommands.New, New_Executed));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, Open_Executed));
            CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, Save_Executed));

            Closing += MainWindow_Closing;

#if DEBUG_ON
            // display console to help debug
            CMDConsole.ConsoleManager.Show();
#endif
        }
        private static void downloadDatabase(SyncServiceClient serviceClient)
        {
            // create output folder, if does not exist
            if (!Directory.Exists(Constants.DOWNLOAD_FOLDER)) Directory.CreateDirectory(Constants.DOWNLOAD_FOLDER);

            // kill target file, if already exists
            string filePath = Path.Combine(Constants.DOWNLOAD_FOLDER, Constants.REMOTE_DB_NAME);
            if (File.Exists(filePath)) File.Delete(filePath);

            // get stream from server
            Stream inputStream;
            string fileName = "";
            long length = serviceClient.DownloadFile(ref fileName, out inputStream);

            // write server stream to disk
            using (var writeStream = new FileStream(filePath, FileMode.CreateNew, FileAccess.Write))
            {
                const int chunkSize = 2048;
                var buffer = new byte[chunkSize];

                do
                {
                    // read bytes from input stream
                    int bytesRead = inputStream.Read(buffer, 0, chunkSize);
                    if (bytesRead == 0) break;

                    // write bytes to output stream
                    writeStream.Write(buffer, 0, bytesRead);

                    // report progress from time to time
                    //progressBar1.Value = (int)(writeStream.Position * 100 / length);
                } while (true);
            }

            // close service client
            inputStream.Dispose();
            // serviceClient.Close();
        }
示例#8
0
        private static void uploadDatabase(SyncServiceClient serviceClient)
        {
            string dbPath = Path.Combine(Constants.GetCurrentDirectoryPath, Constants.DOWNLOAD_FOLDER,
                                         Constants.REMOTE_DB_NAME);

            // get some info about the input file
            var fileInfo = new FileInfo(dbPath);

            FileStream stream = null;

            try
            {
                // open input stream
                stream = new FileStream(dbPath, FileMode.Open, FileAccess.Read);

                using (var uploadStreamWithProgress = new StreamWithProgress(stream))
                {
                    stream = null;
                    uploadStreamWithProgress.ProgressChanged += onUploadStreamWithProgressProgressChanged;

                    // upload file
                    serviceClient.UploadFile(fileInfo.Name, fileInfo.Length, uploadStreamWithProgress);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
        }
 public TestClientServiceDemo(string endPoint)
 {
     service = new SyncServiceClient();
       ConfigureEndPoint(endPoint);
 }
示例#10
0
 public SoapClient(ITokenService tokenService)
 {
     syncServiceClient = new SyncServiceClient();
     _tokenService     = tokenService;
 }
        private static void uploadDatabase(SyncServiceClient serviceClient)
        {
            string dbPath = Path.Combine(Constants.GetCurrentDirectoryPath, Constants.DOWNLOAD_FOLDER,
                                         Constants.REMOTE_DB_NAME);

            // get some info about the input file
            var fileInfo = new FileInfo(dbPath);

            FileStream stream = null;
            try
            {
                // open input stream
                stream = new FileStream(dbPath, FileMode.Open, FileAccess.Read);

                using (var uploadStreamWithProgress = new StreamWithProgress(stream))
                {
                    stream = null;
                    uploadStreamWithProgress.ProgressChanged += onUploadStreamWithProgressProgressChanged;

                    // upload file
                    serviceClient.UploadFile(fileInfo.Name, fileInfo.Length, uploadStreamWithProgress);
                }
            }
            catch (Exception e)
            {
                MessageBox.Show(e.Message);
            }
            finally
            {
                if (stream != null)
                    stream.Dispose();
            }
        }