Esempio n. 1
0
        void SyncDir(SyncStack sync, Drive.Page page)
        {
            while (page != null)
            {
                Thread.Sleep(300); // Give the processor a time to breath

                foreach (var item in page.Items)
                {
                    var syncItem = sync.GetItemById(item.ID);
                    if (syncItem == null ||
                        ((syncItem.State != SynchronizingItem.SyncState.None ||
                          syncItem.Task == SynchronizingItem.TaskState.Done)))
                    {
                        sync.SyncWithState(item, SynchronizingItem.SyncState.CheckDownloadOrUpload);
                    }
                }

                sync.SyncSync();
                // Give a time for breathing
                System.Threading.Thread.Sleep(300);

                var dirs = page.GetDirectories();
                foreach (var dir in dirs)
                {
                    SyncDir(sync, drive.GetDirectoryContent(dir.ItemIdentifier));
                }

                if (page.NextPageID != null)
                {
                    page = page.Next(drive);
                }
                else
                {
                    page = null;
                }
            }
        }
Esempio n. 2
0
        public void Run()
        {
            stack = new SyncStack(
                config.SyncFolder,
                drive
                );

            if (!Directory.Exists(config.SyncFolder))
            {
                Directory.CreateDirectory(config.SyncFolder);
            }


            stack.Start();

            var absRoot = PathNormalizer.Normalize(
                Path.Combine(config.SyncFolder,
                             drive.GetFileById(config.RootFolderID.ID).GetFullName()));

            if (!Directory.Exists(absRoot))
            {
                Directory.CreateDirectory(absRoot);
            }

            scanner = new ChangesScanner(
                absRoot,
                stack, OnFileChanged);
            scanner.StartAsync();

            while (true)
            {
                Drive.Page currentPage = drive.GetDirectoryContent(
                    config.RootFolderID, 100);

                SyncDir(stack, currentPage);
            }
        }
Esempio n. 3
0
 public ChangesScanner(string root, SyncStack syncStack, FileChangedEvent callback)
 {
     this.syncStack = syncStack;
     this.callback  = callback;
     this.root      = root;
 }