예제 #1
0
        public async Task RemoveChildItems_Floating_items()
        {
            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk3"){ IsDirectory = true });

            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk3/test.jpg"));

            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk3/test_dir"){ IsDirectory = true });

            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk3/test_dir/test.jpg"));

            var storage    = new FakeIStorage();
            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache(new Dictionary <string, object>()));

            var rootItem = await _query.GetObjectByFilePathAsync("/Folder_InDbButNotOnDisk3");

            var result = await syncFolder.RemoveChildItems(_query, rootItem);

            Assert.AreEqual("/Folder_InDbButNotOnDisk3", result.FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, result.Status);

            var data = await _query.GetAllRecursiveAsync("/Folder_InDbButNotOnDisk3");

            Assert.AreEqual(0, data.Count);
        }
예제 #2
0
        public async Task AddParentFolder_ExistingFolder()
        {
            var storage    = GetStorage();
            var folderPath = "/exist2";

            var query = new FakeIQuery(new List <FileIndexItem> {
                new FileIndexItem("/exist2")
                {
                    IsDirectory = true
                }
            });

            var syncFolder = new SyncFolder(_appSettings, query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.AddParentFolder(folderPath);

            Assert.IsNotNull(query.GetObjectByFilePathAsync(folderPath));
            Assert.AreEqual(folderPath, result.FilePath);

            // should not add duplicate content
            var allItems = await query.GetAllRecursiveAsync("/");

            Assert.AreEqual(1, allItems.Count);
            Assert.AreEqual(folderPath, allItems[0].FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, allItems[0].Status);
        }
예제 #3
0
        public void ReadAction_Export_Success(string resourceName, bool expectedIsEnabled,
                                              string expectedTransferLocationName, string expectedTransferLocationSubPath,
                                              SyncFolder expectedSyncFolder, string expectedFilterName, bool expectedAssumeExclusiveWriteAccess)

        {
            var mock = GetDefaultPathResolverMock();


            var configurationReader = new ConfigurationReader();
            var config = configurationReader.ReadConfiguration(LoadResource(resourceName), mock.Object);

            mock.Verify(m => m.GetAbsolutePath(It.IsAny <string>()), Times.Never());

            Assert.Single(config.Actions);

            var action = config.Actions.First() as ExportAction;

            Assert.NotNull(action);

            Assert.Equal(expectedIsEnabled, action.IsEnabled);
            Assert.Equal(expectedTransferLocationName, action.TransferLocationName);
            Assert.Equal(expectedTransferLocationSubPath, action.TransferLocationSubPath);
            Assert.Equal(expectedSyncFolder, action.SyncFolder);
            Assert.Equal(expectedFilterName, action.InputFilterName);
            Assert.Equal(expectedAssumeExclusiveWriteAccess, action.AssumeExclusiveWriteAccess);
        }
예제 #4
0
        public async Task Folder_DuplicateChildItems()
        {
            var storage = new FakeIStorage(
                new List <string>
            {
                "/",
                "/Folder_Duplicate"
            },
                new List <string>
            {
                "/Folder_Duplicate/test.jpg",
            },
                new List <byte[]>
            {
                CreateAnImage.Bytes,
            });

            // yes this is duplicate!
            await _query.AddItemAsync(new FileIndexItem("/Folder_Duplicate/test.jpg"));

            await _query.AddItemAsync(new FileIndexItem("/Folder_Duplicate/test.jpg"));             // yes this is duplicate!

            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.Folder("/Folder_Duplicate");

            Assert.AreEqual(2, result.Count);
            var queryResult = await _query.GetAllFilesAsync("/Folder_Duplicate");

            Assert.AreEqual(1, queryResult.Count);

            await _query.RemoveItemAsync(queryResult[0]);
        }
        public void AddItem(SyncFolder folder)
        {
            if (this.Items.Any(f => f.Name.Equals(folder.Name, StringComparison.CurrentCultureIgnoreCase)))
            {
                throw new DuplicateSyncFolderException(folder.Name);
            }            

            // add config file for the sync folder to the configuration directory
            using (var workingDirectory = new TemporaryWorkingDirectory(GitGroup.Repository.Info.Path, RepositoryInitHelper.ConfigurationBranchName.ToString()))
            {
                var syncFoldersPath = Path.Combine(workingDirectory.Location, s_SyncFolders);

                if (NativeDirectory.Exists(syncFoldersPath) == false)
                {
                    NativeDirectory.CreateDirectory(syncFoldersPath);
                }

                var filePath = Path.Combine(syncFoldersPath, $"{folder.Name}.{s_Json}");
                using (var stream = NativeFile.Open(filePath, FileMode.CreateNew, FileAccess.Write))
                {
                    folder.WriteTo(stream);
                }

                workingDirectory.Commit($"Added SyncFolder '{folder.Name}'");
                workingDirectory.Push();
            }
            
        }
예제 #6
0
        public async Task Folder_DuplicateFolders_Direct()
        {
            await _query.AddItemAsync(new FileIndexItem("/DuplicateFolder"){ IsDirectory = true });

            // yes this is duplicate
            await _query.AddItemAsync(new FileIndexItem("/DuplicateFolder"){ IsDirectory = true });

            var storage =
                new FakeIStorage(new List <string> {
                "/", "/DuplicateFolder"
            });
            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());

            await syncFolder.Folder("/DuplicateFolder");

            var allFolders = _query.GetAllFolders().Where(p => p.FilePath == "/DuplicateFolder");

            if (allFolders == null)
            {
                throw new NullReferenceException(
                          "all folder should not be null");
            }

            Assert.AreEqual("/DuplicateFolder", allFolders.FirstOrDefault(p => p.FilePath == "/DuplicateFolder")?.FilePath);
            Assert.AreEqual(1, allFolders.Count(p => p.FilePath == "/DuplicateFolder"));
        }
예제 #7
0
        public void Filter_returns_the_default_filter_configuration_instead_of_null()
        {            
            var syncFolder = new SyncFolder("folder1");
            Assert.Equal(FilterConfiguration.Empty, syncFolder.Filter);            

            var syncFolder2 = new SyncFolder("folder2") { Filter =  null };
            Assert.Equal(FilterConfiguration.Empty, syncFolder2.Filter);
        }
예제 #8
0
        void Count(SyncFolder lfolder, ref int files, ref int folders)
        {
            foreach (SyncFolder f in lfolder.Folders)
            {
                folders++;
                Count(f, ref files, ref folders);
            }

            files += lfolder.Files.Count;
        }
예제 #9
0
        public async Task Folder_Dir_NotFound()
        {
            var storage    = new FakeIStorage();
            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.Folder("/not_found");

            Assert.AreEqual("/not_found", result[0].FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, result[0].Status);
        }
예제 #10
0
        public async Task Folder_FolderWithNoContent()
        {
            var storage    = GetStorage();
            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.Folder("/folder_no_content");

            Assert.AreEqual("/folder_no_content", result[0].FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, result[0].Status);
        }
예제 #11
0
        public HistoryBuilder(IGroup group, string name)
        {
            m_Group = @group;
            m_Name = name;
            m_Group.GetHistoryService().CreateHistory(m_Name);

            SyncFolder = new SyncFolder(m_Name) { Path = "Irrelevant" };

            m_Group.GetConfigurationService().AddItem(SyncFolder);
        }
예제 #12
0
        public void PathsToUpdateInDatabase_InDbButNotOnDisk()
        {
            var results = SyncFolder.PathsToUpdateInDatabase(
                new List <FileIndexItem>
            {
                new FileIndexItem("/test.jpg")
            }, new string[0]);

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("/test.jpg", results[0]);
        }
예제 #13
0
        public void PathsToUpdateInDatabase_FilesOnDiskButNotInTheDb()
        {
            var results = SyncFolder.PathsToUpdateInDatabase(
                new List <FileIndexItem>(), new List <string>
            {
                "/test.jpg",
            });

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("/test.jpg", results[0]);
        }
예제 #14
0
        void Delete(ISync local, SyncFolder lfolder, string filterFolder, string filterFile)
        {
            if (lfolder == null)
            {
                return;
            }

            // Folder
            foreach (SyncFolder f in lfolder.Folders)
            {
                if (!StringHelper.Like(filterFolder, f.Name))
                {
                    continue;
                }

                if (f.Checked)
                {
                    // Esta, hacerlo recursivo
                    Delete(local, f, filterFolder, filterFile);
                }
                else
                {
                    try
                    {
                        local.DeleteFolder(f);
                        WriteInfo("Deleting folder: " + f.GetFullPath('/'));
                    }
                    catch (Exception e)
                    {
                        WriteError(e.Message);
                    }
                }
            }

            // Files
            foreach (SyncFile f in lfolder.Files)
            {
                if (f.Checked || !StringHelper.Like(filterFile, f.Name))
                {
                    continue;
                }

                try
                {
                    local.DeleteFile(f);
                    WriteInfo("Deleting file: " + f.GetFullPath('/'));
                }
                catch (Exception e)
                {
                    WriteError(e.Message);
                }
            }
        }
예제 #15
0
 public void AddSyncFolder(SyncFolder syncFolder)
 {
     using (SqlConnection connection = new SqlConnection(ConnectionString))
     {
         string     query   = @"insert into SyncFolder values(@id,@item,@username)";
         SqlCommand command = new SqlCommand(query, connection);
         command.Parameters.AddWithValue("@id", syncFolder.ID);
         command.Parameters.AddWithValue("@item", syncFolder.ItemID);
         command.Parameters.AddWithValue("@username", syncFolder.Username);
         connection.Open();
         command.ExecuteNonQuery();
     }
 }
예제 #16
0
        public void PathsToUpdateInDatabase_ExistBoth()
        {
            var results = SyncFolder.PathsToUpdateInDatabase(
                new List <FileIndexItem>
            {
                new FileIndexItem("/test.jpg")
            }, new List <string>
            {
                "/test.jpg",
            });

            Assert.AreEqual(1, results.Count);
            Assert.AreEqual("/test.jpg", results[0]);
        }
예제 #17
0
        public override bool Run()
        {
            ISync local;
            ISync remote = (ISync)Payload;

            if (Mode == EMode.Upload)
            {
                local  = remote;
                remote = new Payloads.Local.RSync.LocalPath()
                {
                    RemotePath = LocalPath
                };
            }
            else
            {
                local = new Payloads.Local.RSync.LocalPath()
                {
                    RemotePath = LocalPath
                };
            }

            WriteInfo("Fetching ...");

            Task <SyncFolder> taskA = new Task <SyncFolder>(() => local.GetTree());
            Task <SyncFolder> taskB = new Task <SyncFolder>(() => remote.GetTree());

            taskA.Start(); taskB.Start();
            taskA.Wait(); taskB.Wait();

            SyncFolder lfolder = taskA.Result;
            SyncFolder rfolder = taskB.Result;

            int files = 0, folders = 0;

            Count(rfolder, ref files, ref folders);

            WriteInfo("Total folders", files.ToString(), ConsoleColor.Green);
            WriteInfo("Total files", folders.ToString(), ConsoleColor.Green);

            WriteInfo("Checking write ...");
            Write(local, lfolder, remote, rfolder, FilterFolder, FilterFile, UseMd5);

            if (DeleteExtra)
            {
                WriteInfo("Checking delete ...");
                Delete(local, lfolder, FilterFolder, FilterFile);
            }

            return(true);
        }
예제 #18
0
        public async Task AddParentFolder_NewFolders()
        {
            var storage    = GetStorage();
            var folderPath = "/should_add_root2";

            storage.CreateDirectory(folderPath);

            var query      = new FakeIQuery();
            var syncFolder = new SyncFolder(_appSettings, query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.AddParentFolder(folderPath);

            Assert.IsNotNull(query.GetObjectByFilePathAsync("/"));
            Assert.IsNotNull(query.GetObjectByFilePathAsync(folderPath));
            Assert.AreEqual(folderPath, result.FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, result.Status);
        }
예제 #19
0
        public async Task CompareFolderListAndFixMissingFoldersTest_Ignored()
        {
            var storage = new FakeIStorage(new List <string> {
                "/", "/.git", "/test"
            });
            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache(new Dictionary <string, object>()));

            await syncFolder.CompareFolderListAndFixMissingFolders(
                new List <string> {
                "/", "/.git"
            },
                new List <FileIndexItem> {
                new FileIndexItem("/")
            });

            Assert.AreEqual(null, (await _query.GetObjectByFilePathAsync("/.git")));
        }
예제 #20
0
        public async Task Folder_InDbButNotOnDisk_Floating_directoriesWithinScanDir()
        {
            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk4/test.jpg"));

            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk4/test_dir"){ IsDirectory = true });

            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk4/test_dir/test.jpg"));

            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk4/test_dir/child"){ IsDirectory = true });

            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk4/test_dir/child/test.jpg"));

            var storage = new FakeIStorage(new List <string> {
                "/Folder_InDbButNotOnDisk4",
                "/Folder_InDbButNotOnDisk4/test_dir"
            });
            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.Folder("/Folder_InDbButNotOnDisk4");

            Assert.AreEqual("/Folder_InDbButNotOnDisk4/test.jpg",
                            result.FirstOrDefault(p => p.FilePath == "/Folder_InDbButNotOnDisk4/test.jpg").FilePath);
            Assert.AreEqual("/Folder_InDbButNotOnDisk4",
                            result.FirstOrDefault(p => p.FilePath == "/Folder_InDbButNotOnDisk4").FilePath);

            Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, result[0].Status);
            Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, result[1].Status);
            Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, result[2].Status);

            var data = await _query.GetAllRecursiveAsync("/Folder_InDbButNotOnDisk4");

            Assert.AreEqual(1, data.Count);

            // Check for database
            Assert.AreEqual("/Folder_InDbButNotOnDisk4",
                            (await _query.GetObjectByFilePathAsync("/Folder_InDbButNotOnDisk4")).FilePath);
            Assert.AreEqual("/Folder_InDbButNotOnDisk4/test_dir",
                            (await _query.GetObjectByFilePathAsync("/Folder_InDbButNotOnDisk4/test_dir")).FilePath);
            Assert.AreEqual(null,
                            await _query.GetObjectByFilePathAsync("/Folder_InDbButNotOnDisk4/test_dir/test.jpg"));
            Assert.AreEqual(null,
                            await _query.GetObjectByFilePathAsync("/Folder_InDbButNotOnDisk4/test.jpg"));
        }
예제 #21
0
        public async Task AddParentFolder_NotFound()
        {
            var storage    = GetStorage();
            var folderPath = "/not-found";

            var query = new FakeIQuery();

            var syncFolder = new SyncFolder(_appSettings, query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.AddParentFolder(folderPath);

            Assert.IsNotNull(query.GetObjectByFilePathAsync(folderPath));
            Assert.AreEqual(folderPath, result.FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, result.Status);

            // should not add content
            var allItems = await query.GetAllRecursiveAsync("/");

            Assert.AreEqual(0, allItems.Count);
        }
예제 #22
0
        public async Task Folder_InDbButNotOnDisk()
        {
            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk/test.jpg"));

            await _query.AddItemAsync(new FileIndexItem("/Folder_InDbButNotOnDisk/test2.jpg"));

            var storage    = new FakeIStorage();
            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.Folder("/Folder_InDbButNotOnDisk");

            Assert.AreEqual("/Folder_InDbButNotOnDisk/test.jpg", result[0].FilePath);
            Assert.AreEqual("/Folder_InDbButNotOnDisk/test2.jpg", result[1].FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, result[0].Status);
            Assert.AreEqual(FileIndexItem.ExifStatus.NotFoundSourceMissing, result[1].Status);

            Assert.AreEqual(null,
                            _query.SingleItem("/Folder_InDbButNotOnDisk/test.jpg"));
            Assert.AreEqual(null,
                            _query.SingleItem("/Folder_InDbButNotOnDisk/test2.jpg"));
        }
예제 #23
0
        public SyncFolderDefinition(string name, string rootPath, SyncFolder role)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (rootPath == null)
            {
                throw new ArgumentNullException(nameof(rootPath));
            }

            if (String.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("Value must not be empty", nameof(name));
            }

            Name     = name;
            RootPath = rootPath;
            Role     = role;
        }
예제 #24
0
        public async Task Folder_FileSizeIsChanged()
        {
            var subPath = "/change/test_change.jpg";
            await _query.AddItemAsync(new FileIndexItem(subPath)
            {
                Size = 123456
            });

            var storage = GetStorage();
            await storage.WriteStreamAsync(new MemoryStream(FakeCreateAn.CreateAnImage.Bytes),
                                           subPath);

            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.Folder("/change");

            Assert.AreEqual(subPath, result[0].FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, result[0].Status);
            Assert.IsTrue(result[0].Size != 123456);
            Assert.IsFalse(string.IsNullOrWhiteSpace(result[0].Tags));
        }
예제 #25
0
        public async Task Folder_FilesOnDiskButNotInTheDb()
        {
            var storage = new FakeIStorage(
                new List <string>
            {
                "/",
                "/Folder_FilesOnDiskButNotInTheDb"
            },
                new List <string>
            {
                "/Folder_FilesOnDiskButNotInTheDb/test1.jpg",
                "/Folder_FilesOnDiskButNotInTheDb/test2.jpg",
                "/Folder_FilesOnDiskButNotInTheDb/test3.jpg",
            },
                new List <byte[]>
            {
                CreateAnImage.Bytes,
                CreateAnImageColorClass.Bytes,
                CreateAnImageNoExif.Bytes,
            });

            var syncFolder = new SyncFolder(_appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.Folder("/Folder_FilesOnDiskButNotInTheDb");

            Assert.AreEqual("/Folder_FilesOnDiskButNotInTheDb/test1.jpg", result[0].FilePath);
            Assert.AreEqual("/Folder_FilesOnDiskButNotInTheDb/test2.jpg", result[1].FilePath);
            Assert.AreEqual("/Folder_FilesOnDiskButNotInTheDb/test3.jpg", result[2].FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, result[0].Status);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, result[1].Status);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, result[2].Status);

            var files = await _query.GetAllFilesAsync("/Folder_FilesOnDiskButNotInTheDb");

            Assert.AreEqual(3, files.Count);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, files[0].Status);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, files[1].Status);
            Assert.AreEqual(FileIndexItem.ExifStatus.Ok, files[2].Status);
        }
예제 #26
0
        public async Task Folder_ShouldIgnore()
        {
            var storage = new FakeIStorage(
                new List <string>
            {
                "/",
                "/test_ignore",
                "/test_ignore/ignore"
            },
                new List <string>
            {
                "/test_ignore/ignore/test1.jpg"
            },
                new List <byte[]>
            {
                CreateAnImage.Bytes,
                CreateAnImageColorClass.Bytes,
                CreateAnImageNoExif.Bytes,
            });

            var appSettings = new AppSettings {
                DatabaseType = AppSettings.DatabaseTypeList.InMemoryDatabase,
                Verbose      = true,
                SyncIgnore   = new List <string> {
                    "/test_ignore/ignore"
                }
            };

            var syncFolder = new SyncFolder(appSettings, _query, new FakeSelectorStorage(storage),
                                            new ConsoleWrapper(), new FakeIWebLogger(), new FakeMemoryCache());
            var result = await syncFolder.Folder("/test_ignore");

            Assert.AreEqual("/test_ignore/ignore/test1.jpg", result[0].FilePath);
            Assert.AreEqual(FileIndexItem.ExifStatus.OperationNotSupported, result[0].Status);

            var files = await _query.GetAllFilesAsync("/test_ignore");

            Assert.AreEqual(0, files.Count);
        }
예제 #27
0
 protected IOAction(bool isEnabled, ISyncConfiguration configuration, string inputFilterName, SyncFolder syncFolder)
     : base(isEnabled, configuration, inputFilterName)
 {
     SyncFolder = syncFolder;
 }
예제 #28
0
 public ExportDirectoryAction(bool isEnabled, ISyncConfiguration configuration, string inputFilterName, SyncFolder syncFolder)
     : base(isEnabled, configuration, inputFilterName, syncFolder)
 {
 }
        public void UpdateItem(SyncFolder folder)
        {
            if (folder == null)
            {
                throw new ArgumentNullException(nameof(folder));
            }

            if (!ItemExists(folder.Name))
            {
                throw new SyncFolderNotFoundException($"A sync folder named '{folder.Name}' could not be found");
            }

            using (var workingDirectory = new TemporaryWorkingDirectory(GitGroup.Repository.Info.Path, RepositoryInitHelper.ConfigurationBranchName.ToString()))
            {
                var syncFoldersPath = Path.Combine(workingDirectory.Location, s_SyncFolders);
                
                var filePath = Path.Combine(syncFoldersPath, $"{folder.Name}.{s_Json}");
                using (var stream = NativeFile.Open(filePath, FileMode.Open, FileAccess.Write))
                {
                    folder.WriteTo(stream);
                }

                if (workingDirectory.HasChanges)
                {
                    try
                    {
                        workingDirectory.Commit($"Updated SyncFolder '{folder.Name}'");
                        workingDirectory.Push();
                    }
                    catch (EmptyCommitException)
                    {
                        // no changes after all (HasChanges does not seem to be a 100% accurate)
                        // => ignore exception
                    }

                    
                }

            }
        }
예제 #30
0
        public void ReadAction_Copy_Success(string resourceName, bool expectedEnable, SyncFolder expectedSyncFolder, string expectedFilterName)
        {
            var mock = GetDefaultPathResolverMock();

            var configurationReader = new ConfigurationReader();
            var config = configurationReader.ReadConfiguration(LoadResource(resourceName), mock.Object);

            mock.Verify(m => m.GetAbsolutePath(It.IsAny <string>()), Times.Never());

            Assert.Single(config.Actions);

            var action = config.Actions.First() as CopyAction;

            Assert.NotNull(action);


            Assert.Equal(expectedEnable, action.IsEnabled);
            Assert.Equal(expectedSyncFolder, action.SyncFolder);
            Assert.Equal(expectedFilterName, action.InputFilterName);
        }
예제 #31
0
 protected ImportExportAction(bool isEnabled, ISyncConfiguration configuration, string inputFilterName, SyncFolder syncFolder)
     : base(isEnabled, configuration, inputFilterName, syncFolder)
 {
 }
예제 #32
0
        public bool ProcessCommandLineArgs()
        {
            bool success = true;

            string[] args  = Environment.GetCommandLineArgs();
            Int32    index = 1; //index 0 has the executable name

            while ((args != null) && (index < args.Length))
            {
                string current = args[index];
                switch (current)
                {
                case "/?":
                case "-?":
                    ShowHelp(null);
                    success = false;
                    break;

                case "/f":
                case "-f":
                    ForceSync = true;
                    break;

                case "/w":
                case "-w":
                    ClobberWriteable = true;
                    break;

                case "/a":
                case "-a":
                    AutoStart = true;
                    break;

                case "/v":
                case "-v":
                    ShowWindows = true;
                    break;

                default:
                    if (string.IsNullOrEmpty(SyncFolder) && string.IsNullOrEmpty(Revision))
                    {
                        try
                        {
                            int delim_index = current.IndexOf('@');
                            if (delim_index != -1)
                            {
                                Revision   = current.Substring(delim_index + 1);
                                SyncFolder = current.Substring(0, delim_index);
                            }
                            else
                            {
                                SyncFolder = current;
                            }

                            if (SyncFolder.StartsWith("//"))
                            {
                                ShowHelp("Please use local paths only for the sync.");
                                success = false;
                                break;
                            }

                            SyncFolder = SyncFolder.Replace("/", "\\");

                            if (SyncFolder.StartsWith("\\"))
                            {
                                ShowHelp("Invalid sync path specified.");
                                success = false;
                                break;
                            }
                            else if (SyncFolder.Contains(":"))
                            {
                                ShowHelp("Do not use absolute paths.");
                                success = false;
                                break;
                            }

                            if (SyncFolder == "..")
                            {
                                SyncFolder = Path.GetDirectoryName(Environment.CurrentDirectory);
                            }
                            else if (SyncFolder.StartsWith("..\\"))
                            {
                                string subPart = SyncFolder.Substring(3);
                                SyncFolder = Path.GetDirectoryName(Environment.CurrentDirectory);

                                if (!SyncFolder.EndsWith("\\"))
                                {
                                    SyncFolder += "\\";
                                }

                                SyncFolder += subPart;
                            }
                            else if ((SyncFolder == ".") ||
                                     (SyncFolder == "..."))
                            {
                                SyncFolder = Environment.CurrentDirectory;
                            }
                            else if (SyncFolder.StartsWith(".\\"))
                            {
                                string subPart = SyncFolder.Substring(2);
                                SyncFolder = Environment.CurrentDirectory;

                                if (!SyncFolder.EndsWith("\\"))
                                {
                                    SyncFolder += "\\";
                                }

                                SyncFolder += subPart;
                            }
                            else
                            {
                                string subPart = SyncFolder;
                                SyncFolder = Environment.CurrentDirectory;

                                if (!SyncFolder.EndsWith("\\"))
                                {
                                    SyncFolder += "\\";
                                }

                                SyncFolder += subPart;
                            }

                            if (!string.IsNullOrEmpty(SyncFolder) && !SyncFolder.EndsWith("..."))
                            {
                                if (!SyncFolder.EndsWith("\\"))
                                {
                                    SyncFolder += "\\";
                                }

                                SyncFolder += "...";
                            }

                            SyncFolder = SyncFolder.ToLower().Trim();
                        }
                        catch (Exception exp)
                        {
                            ShowHelp("Arguement - " + current + ". " + exp.Message);
                            success = false;
                        }
                    }
                    else
                    {
                        ShowHelp("Invalid arguement - " + current);
                        success = false;
                    }
                    break;
                }

                if (!success)
                {
                    break;
                }

                index++;
            }

            if (success)
            {
                MainWindow parent = App.Current.MainWindow as MainWindow;
                parent.UpdateSyncDetails(-2, -2);
                GetClientInfo();
            }

            return(success);
        }
예제 #33
0
        private async Task SynchronizeAsync(CancellationToken cancellationToken)
        {
            var flickr       = Singleton <FlickrService> .Instance.FlickrNet;
            var functionMode = Singleton <SettingsService> .Instance.Mode;

            try
            {
                CurrentOperationDescription = string.Format("Sync_ParsingFolderStatus".GetLocalized(), SyncFolder.Path);
                var queryOptions = new QueryOptions(CommonFileQuery.DefaultQuery, extensions)
                {
                    FolderDepth = FolderDepth.Deep
                };
                queryOptions.SetThumbnailPrefetch(ThumbnailModeSingle, ThumbnailSize, ThumbnailOptionResize);
                var queryResult = SyncFolder.CreateFileQueryWithOptions(queryOptions);
                var files       = await queryResult.GetFilesAsync();

                cancellationToken.ThrowIfCancellationRequested();
                ProgressMax = files.Count;

                var photosetsList = await flickr.RetryOnFailureAsync(f => f.PhotosetsGetListAsync());

                cancellationToken.ThrowIfCancellationRequested();
                var photosets = photosetsList.Where(ps => !string.IsNullOrWhiteSpace(ps.Description) && ps.Description[0] == '`')
                                .Distinct(new GenericEqualityComparer <Photoset>(ps => ps.Description)).ToDictionary(ps => ps.Description);
                var groupedFiles = files.GroupBy(f => Path.GetDirectoryName(f.Path));
                foreach (var group in groupedFiles)
                {
                    var photosetName        = Path.GetFileName(group.Key);
                    var photosetDescription = "`" + group.Key.Replace(SyncFolder.Path, ".");
                    Dictionary <string, Photo> photos;
                    if (photosets.TryGetValue(photosetDescription, out Photoset photoset))
                    {
                        var photosCollection = await flickr.RetryOnFailureAsync(f => f.PhotosetsGetPhotosAsync(photoset.PhotosetId));

                        photos = photosCollection.Distinct(new GenericEqualityComparer <Photo>(p => p.Title)).ToDictionary(p => p.Title);
                    }
                    else
                    {
                        photos = new Dictionary <string, Photo>();
                    }

                    foreach (var file in group)
                    {
                        if (photos.Remove(file.Name))
                        {
                            ProgressValue++;
                            continue;
                        }

                        if (functionMode != FunctionMode.DownloadOnly)
                        {
                            CurrentOperationDescription = string.Format("Sync_UploadingFileStatus".GetLocalized(), file.Path);
                            var thumbnail = await file.GetThumbnailAsync(ThumbnailModeSingle, ThumbnailSize, ThumbnailOptionResize);

                            using (var stream = thumbnail.AsStreamForRead().AsRandomAccessStream())
                            {
                                await PreviewImage.SetSourceAsync(stream);
                            }
                            try
                            {
                                string photoId = null;
                                using (var stream = (await file.OpenSequentialReadAsync()).AsStreamForRead())
                                {
                                    photoId = await flickr.RetryOnFailureAsync(f => f.UploadPictureAsync(stream, file.Name, file.Name, file.Path.Replace(SyncFolder.Path, "."), "", false, false, false, ContentType.Photo, SafetyLevel.None, HiddenFromSearch.Hidden));
                                }

                                if (photoset == null)
                                {
                                    CurrentOperationDescription = string.Format("Sync_CreatingPhotoSetStatus".GetLocalized(), photosetName);
                                    photoset = await flickr.RetryOnFailureAsync(f => f.PhotosetsCreateAsync(photosetName, photosetDescription, photoId));
                                }
                                else
                                {
                                    CurrentOperationDescription = string.Format("Sync_AddingFileToPhotoSet".GetLocalized(), file.Name, photosetName);
                                    await flickr.RetryOnFailureAsync(f => f.PhotosetsAddPhotoAsync(photoset.PhotosetId, photoId));
                                }
                            }
                            catch (FlickrException exception)
                            {
                                if (!exception.Message.Contains("Filetype was not recognised"))
                                {
                                    throw;
                                }
                            }
                        }

                        cancellationToken.ThrowIfCancellationRequested();
                        ProgressValue++;
                    }

                    if (photos.Count > 0 && functionMode != FunctionMode.UploadOnly)
                    {
                        var folder = await StorageFolder.GetFolderFromPathAsync(group.Key);
                        await DownloadPhotosAsync(flickr, folder, photos.Values, cancellationToken);
                    }
                    photosets.Remove(photosetDescription);
                }
                if (functionMode != FunctionMode.UploadOnly)
                {
                    foreach (var photoset in photosets.Values)
                    {
                        var folder = await CreateFolderRecursivelyAsync(SyncFolder, photoset.Description.Substring(1), cancellationToken);

                        var photos = await flickr.RetryOnFailureAsync(f => f.PhotosetsGetPhotosAsync(photoset.PhotosetId));
                        await DownloadPhotosAsync(flickr, folder, photos, cancellationToken);
                    }
                }

                ProgressValue = ProgressMax;
                CurrentOperationDescription = "Sync_FinishedStatus".GetLocalized();
            }
            catch (Exception exception)
            {
                if (!cancellationToken.IsCancellationRequested)
                {
                    var msg = new MessageDialog(exception.Message, "Error");
                    await msg.ShowAsync();

                    throw;
                }
            }
        }
예제 #34
0
        private void Sync(SyncFolder syncFolder, string dropPath)
        {
            //Try create the folder...
            var parentMeta = new MetaData { Path = dropPath };

            var tempMeta = new MetaData { Path = string.Format("{0}/{1}", dropPath, syncFolder.Name) };

            var folderMeta = Syncer.Instance.DropBox.GetItems(tempMeta);

            if (folderMeta == null)
            {
                //Doesnt exist on Dropbox
                //if its the Sync Root Create it anyway...
                if (syncFolder.Parent == null)
                {
                    folderMeta = Syncer.Instance.DropBox.CreateFolder(parentMeta, syncFolder.Name);
                }
                else
                {
                    //Not the root SyncFolder
                    if (syncFolder.LastSync == DateTime.MinValue)
                    {
                        //not been synced before (is new)
                        folderMeta = Syncer.Instance.DropBox.CreateFolder(parentMeta, syncFolder.Name);
                    }
                    else
                    {
                        //has been synced before
                        if (syncFolder.Created > syncFolder.LastSync)
                        {
                            //Created after last sync, new
                            folderMeta = Syncer.Instance.DropBox.CreateFolder(parentMeta, syncFolder.Name);
                        }
                        else
                        {
                            //Folder deleted from dropbox after last sync
                            try
                            {
                                Directory.Delete(syncFolder.Path);
                            }
                            catch { }
                            return; //End current loop
                        }
                    }
                }

                //if folderMeta is still null, data fail
                if (folderMeta == null)
                {
                    Form1.Instance.DoAction(() =>
                    {
                        MessageDialog.Show("Syncing failed" + Environment.NewLine + "Check Data Connection", "OK", null);
                    });
                    return;
                }
            }

            if (folderMeta.Contents == null) folderMeta.Contents = new List<MetaData>();

            var folders = syncFolder.GetSubFolders();

            foreach (SyncFolder subFolder in folders)
            {
                subFolder.Parent = syncFolder;
                Sync(subFolder, string.Format("{0}/{1}", dropPath, syncFolder.Name));
            }

            Syncer.Instance.CurrentFolderPath = syncFolder.Path;

            var files = syncFolder.GetFiles();

            foreach (SyncFile file in files)
            {
                try
                {
                    UpdateSyncStatuses(file.Name, SyncStatus.Checking);
                    //Check for extension and size exclusions
                    if (Settings.Instance.MaxSizeMB > 0)
                    {
                        if (Settings.Instance.MaxSizeMB < (file.Size / 1024.00 / 1024.00))
                        {
                            //File too big...
                            //Add to the Syncer thing
                            //Syncer.Instance.FilesSkipped.Add(file);
                            continue;
                        }
                    }
                    //Check file against the dropbox 1
                    var fileMeta = folderMeta.Contents.SingleOrDefault(f => f.Name == file.Name);
                    if (fileMeta != null)
                    {
                        //file exists on dropbox check if modified after last sync
                        if (syncFolder.LastSync == DateTime.MinValue)
                        {
                            //First Time syncing said folder and file exists on both...
                            if (fileMeta.Modified < TimeZone.CurrentTimeZone.ToUniversalTime(file.LastMod))
                            {
                                //phone file is newer (upload)
                                UpdateSyncStatuses(SyncStatus.Uploading);
                                Syncer.Instance.DropBox.UploadFile(new FileInfo(file.Path), folderMeta);
                                //Add to the Syncer thing
                                //Syncer.Instance.FilesUp.Add(file);
                            }
                            else
                            {
                                //update phone files (download)   new FileInfo(file.Path), folderMeta
                                UpdateSyncStatuses(SyncStatus.Downloading);
                                var downloadFile = Syncer.Instance.DropBox.GetFile(fileMeta);

                                if (downloadFile != null)
                                {
                                    downloadFile.SaveFile(file.Path);
                                    //Add to the Syncer thing
                                    //Syncer.Instance.FilesDown.Add(file);
                                }
                            }
                        }
                        else
                        {
                            //Not first time syncing folder
                            if (fileMeta.Modified > TimeZone.CurrentTimeZone.ToUniversalTime(file.LastMod))
                            {
                                if (fileMeta.Modified > TimeZone.CurrentTimeZone.ToUniversalTime(syncFolder.LastSync))
                                {
                                    //update phone files (download)   new FileInfo(file.Path), folderMeta
                                    UpdateSyncStatuses(SyncStatus.Downloading);
                                    var downloadFile = Syncer.Instance.DropBox.GetFile(fileMeta);

                                    if (downloadFile != null)
                                    {
                                        downloadFile.SaveFile(file.Path);
                                        //Add to the Syncer thing
                                        //Syncer.Instance.FilesDown.Add(file);
                                    }
                                }
                            }
                            else
                            {
                                if (file.LastMod > syncFolder.LastSync) //Both Local
                                {
                                    //phone file is newer (upload)
                                    UpdateSyncStatuses(SyncStatus.Uploading);
                                    Syncer.Instance.DropBox.UploadFile(new FileInfo(file.Path), folderMeta);
                                    //Add to the Syncer thing
                                    //Syncer.Instance.FilesUp.Add(file);
                                }
                            }

                        }
                    }
                    else
                    {
                        //File doesnt exist on Dropbox
                        //check if it was deleted
                        if (file.LastMod > syncFolder.LastSync) //Both Local
                        {
                            //file added after last sync (upload)
                            UpdateSyncStatuses(SyncStatus.Uploading);
                            Syncer.Instance.DropBox.UploadFile(new FileInfo(file.Path), folderMeta);
                            //Add to the Syncer thing
                            //Syncer.Instance.FilesUp.Add(file);
                        }
                        else
                        {
                            //Check for moved file...
                            if (file.LastAccess > syncFolder.LastSync)
                            {
                                //TODO - TESTING!

                                //File was moved? upload it to dropbox...
                                UpdateSyncStatuses(SyncStatus.Uploading);
                                Syncer.Instance.DropBox.UploadFile(new FileInfo(file.Path), folderMeta);
                            }
                            else
                            {
                                //Delete Local File
                                try
                                {
                                    File.Delete(file.Path);
                                }
                                catch
                                {
                                    //Failed to delete.
                                }
                            }
                        }
                    }
                }
                catch
                {
                    //Pokemon Exception handling...
                }
            }

            //reload files list for deletes
            files = syncFolder.GetFiles();

            //Now check for files the are on dropbox but not phone
            var syncFiles = new List<SyncFile>();
            foreach (SyncFile file in files)
            {
                syncFiles.Add(file);
            }

            var newFiles = from df in folderMeta.Contents
                join lf in syncFiles on df.Name equals lf.Name into nf
                from f in nf.DefaultIfEmpty()
                where f == null && (!df.Is_Dir)
                select df;

            foreach (MetaData dropMeta in newFiles)
            {
                UpdateSyncStatuses(dropMeta.Name, SyncStatus.Checking);
                //Check for extension and size exclusions
                if (Settings.Instance.MaxSizeMB > 0)
                {
                    if (Settings.Instance.MaxSizeMB < (dropMeta.Bytes / 1024.00 / 1024.00))
                    {
                        //File too big...
                        //Add to the Syncer thing
                        //Syncer.Instance.FilesSkippedD.Add(dropFile);
                        continue;
                    }
                }
                //check if dropbox file was added after last sync
                if (dropMeta.Modified > TimeZone.CurrentTimeZone.ToUniversalTime(syncFolder.LastSync))
                {
                    //new file (download)
                    UpdateSyncStatuses(SyncStatus.Downloading);
                    var downloadFile = Syncer.Instance.DropBox.GetFile(dropMeta);

                    if (downloadFile != null)
                    {
                        downloadFile.SaveFile(Path.Combine(syncFolder.Path, downloadFile.Name));
                        //Add to the Syncer thing
                        //Syncer.Instance.FilesNew.Add(dropFile);
                    }
                }
                else
                {
                    //file deleted (delete)
                    Syncer.Instance.DropBox.Delete(dropMeta);
                }
            }

            //now check for folders on dropbox but not the phone
            var syncFolders = new List<SyncFolder>();
            foreach (SyncFolder folder in folders)
            {
                syncFolders.Add(folder);
            }

            var newFolders = from df in folderMeta.Contents
                             join lf in syncFolders on df.Name equals lf.Name into nf
                             from f in nf.DefaultIfEmpty()
                             where f == null && df.Is_Dir
                             select df;

            foreach (MetaData dropMeta in newFolders)
            {
                //ITS A FOLDER! (exists on dropbox but not phone)

                //If folder was added to dropbox after last sync, download it
                if (dropMeta.Modified > TimeZone.CurrentTimeZone.ToUniversalTime(syncFolder.LastSync))
                {
                    //create local folder and download files in said folder
                    var newFolder = new DirectoryInfo(Path.Combine(syncFolder.Path, dropMeta.Name));
                    if (!newFolder.Exists) newFolder.Create();

                    var subFolder = new SyncFolder(newFolder);
                    subFolder.Parent = syncFolder;
                    Sync(subFolder, string.Format("{0}/{1}", dropPath, syncFolder.Name));
                }
                else
                {
                    //folder deleted (delete)
                    Syncer.Instance.DropBox.Delete(dropMeta);
                }
                continue;
            }
        }
예제 #35
0
        private void Sync(SyncFolder syncFolder, string dropPath)
        {
            //Try create the folder...
            var parentMeta = new MetaData {
                Path = dropPath
            };

            var tempMeta = new MetaData {
                Path = string.Format("{0}/{1}", dropPath, syncFolder.Name)
            };

            var folderMeta = Syncer.Instance.DropBox.GetItems(tempMeta);

            if (folderMeta == null)
            {
                //Doesnt exist on Dropbox
                //if its the Sync Root Create it anyway...
                if (syncFolder.Parent == null)
                {
                    folderMeta = Syncer.Instance.DropBox.CreateFolder(parentMeta, syncFolder.Name);
                }
                else
                {
                    //Not the root SyncFolder
                    if (syncFolder.LastSync == DateTime.MinValue)
                    {
                        //not been synced before (is new)
                        folderMeta = Syncer.Instance.DropBox.CreateFolder(parentMeta, syncFolder.Name);
                    }
                    else
                    {
                        //has been synced before
                        if (syncFolder.Created > syncFolder.LastSync)
                        {
                            //Created after last sync, new
                            folderMeta = Syncer.Instance.DropBox.CreateFolder(parentMeta, syncFolder.Name);
                        }
                        else
                        {
                            //Folder deleted from dropbox after last sync
                            try
                            {
                                Directory.Delete(syncFolder.Path);
                            }
                            catch { }
                            return; //End current loop
                        }
                    }
                }

                //if folderMeta is still null, data fail
                if (folderMeta == null)
                {
                    Form1.Instance.DoAction(() =>
                    {
                        MessageDialog.Show("Syncing failed" + Environment.NewLine + "Check Data Connection", "OK", null);
                    });
                    return;
                }
            }

            if (folderMeta.Contents == null)
            {
                folderMeta.Contents = new List <MetaData>();
            }

            var folders = syncFolder.GetSubFolders();

            foreach (SyncFolder subFolder in folders)
            {
                subFolder.Parent = syncFolder;
                Sync(subFolder, string.Format("{0}/{1}", dropPath, syncFolder.Name));
            }

            Syncer.Instance.CurrentFolderPath = syncFolder.Path;

            var files = syncFolder.GetFiles();

            foreach (SyncFile file in files)
            {
                try
                {
                    UpdateSyncStatuses(file.Name, SyncStatus.Checking);
                    //Check for extension and size exclusions
                    if (Settings.Instance.MaxSizeMB > 0)
                    {
                        if (Settings.Instance.MaxSizeMB < (file.Size / 1024.00 / 1024.00))
                        {
                            //File too big...
                            //Add to the Syncer thing
                            //Syncer.Instance.FilesSkipped.Add(file);
                            continue;
                        }
                    }
                    //Check file against the dropbox 1
                    var fileMeta = folderMeta.Contents.SingleOrDefault(f => f.Name == file.Name);
                    if (fileMeta != null)
                    {
                        //file exists on dropbox check if modified after last sync
                        if (syncFolder.LastSync == DateTime.MinValue)
                        {
                            //First Time syncing said folder and file exists on both...
                            if (fileMeta.Modified < TimeZone.CurrentTimeZone.ToUniversalTime(file.LastMod))
                            {
                                //phone file is newer (upload)
                                UpdateSyncStatuses(SyncStatus.Uploading);
                                Syncer.Instance.DropBox.UploadFile(new FileInfo(file.Path), folderMeta);
                                //Add to the Syncer thing
                                //Syncer.Instance.FilesUp.Add(file);
                            }
                            else
                            {
                                //update phone files (download)   new FileInfo(file.Path), folderMeta
                                UpdateSyncStatuses(SyncStatus.Downloading);
                                var downloadFile = Syncer.Instance.DropBox.GetFile(fileMeta);

                                if (downloadFile != null)
                                {
                                    downloadFile.SaveFile(file.Path);
                                    //Add to the Syncer thing
                                    //Syncer.Instance.FilesDown.Add(file);
                                }
                            }
                        }
                        else
                        {
                            //Not first time syncing folder
                            if (fileMeta.Modified > TimeZone.CurrentTimeZone.ToUniversalTime(file.LastMod))
                            {
                                if (fileMeta.Modified > TimeZone.CurrentTimeZone.ToUniversalTime(syncFolder.LastSync))
                                {
                                    //update phone files (download)   new FileInfo(file.Path), folderMeta
                                    UpdateSyncStatuses(SyncStatus.Downloading);
                                    var downloadFile = Syncer.Instance.DropBox.GetFile(fileMeta);

                                    if (downloadFile != null)
                                    {
                                        downloadFile.SaveFile(file.Path);
                                        //Add to the Syncer thing
                                        //Syncer.Instance.FilesDown.Add(file);
                                    }
                                }
                            }
                            else
                            {
                                if (file.LastMod > syncFolder.LastSync) //Both Local
                                {
                                    //phone file is newer (upload)
                                    UpdateSyncStatuses(SyncStatus.Uploading);
                                    Syncer.Instance.DropBox.UploadFile(new FileInfo(file.Path), folderMeta);
                                    //Add to the Syncer thing
                                    //Syncer.Instance.FilesUp.Add(file);
                                }
                            }
                        }
                    }
                    else
                    {
                        //File doesnt exist on Dropbox
                        //check if it was deleted
                        if (file.LastMod > syncFolder.LastSync) //Both Local
                        {
                            //file added after last sync (upload)
                            UpdateSyncStatuses(SyncStatus.Uploading);
                            Syncer.Instance.DropBox.UploadFile(new FileInfo(file.Path), folderMeta);
                            //Add to the Syncer thing
                            //Syncer.Instance.FilesUp.Add(file);
                        }
                        else
                        {
                            //Check for moved file...
                            if (file.LastAccess > syncFolder.LastSync)
                            {
                                //TODO - TESTING!

                                //File was moved? upload it to dropbox...
                                UpdateSyncStatuses(SyncStatus.Uploading);
                                Syncer.Instance.DropBox.UploadFile(new FileInfo(file.Path), folderMeta);
                            }
                            else
                            {
                                //Delete Local File
                                try
                                {
                                    File.Delete(file.Path);
                                }
                                catch
                                {
                                    //Failed to delete.
                                }
                            }
                        }
                    }
                }
                catch
                {
                    //Pokemon Exception handling...
                }
            }

            //reload files list for deletes
            files = syncFolder.GetFiles();

            //Now check for files the are on dropbox but not phone
            var syncFiles = new List <SyncFile>();

            foreach (SyncFile file in files)
            {
                syncFiles.Add(file);
            }

            var newFiles = from df in folderMeta.Contents
                           join lf in syncFiles on df.Name equals lf.Name into nf
                           from f in nf.DefaultIfEmpty()
                           where f == null && (!df.Is_Dir)
                           select df;

            foreach (MetaData dropMeta in newFiles)
            {
                UpdateSyncStatuses(dropMeta.Name, SyncStatus.Checking);
                //Check for extension and size exclusions
                if (Settings.Instance.MaxSizeMB > 0)
                {
                    if (Settings.Instance.MaxSizeMB < (dropMeta.Bytes / 1024.00 / 1024.00))
                    {
                        //File too big...
                        //Add to the Syncer thing
                        //Syncer.Instance.FilesSkippedD.Add(dropFile);
                        continue;
                    }
                }
                //check if dropbox file was added after last sync
                if (dropMeta.Modified > TimeZone.CurrentTimeZone.ToUniversalTime(syncFolder.LastSync))
                {
                    //new file (download)
                    UpdateSyncStatuses(SyncStatus.Downloading);
                    var downloadFile = Syncer.Instance.DropBox.GetFile(dropMeta);

                    if (downloadFile != null)
                    {
                        downloadFile.SaveFile(Path.Combine(syncFolder.Path, downloadFile.Name));
                        //Add to the Syncer thing
                        //Syncer.Instance.FilesNew.Add(dropFile);
                    }
                }
                else
                {
                    //file deleted (delete)
                    Syncer.Instance.DropBox.Delete(dropMeta);
                }
            }

            //now check for folders on dropbox but not the phone
            var syncFolders = new List <SyncFolder>();

            foreach (SyncFolder folder in folders)
            {
                syncFolders.Add(folder);
            }

            var newFolders = from df in folderMeta.Contents
                             join lf in syncFolders on df.Name equals lf.Name into nf
                             from f in nf.DefaultIfEmpty()
                             where f == null && df.Is_Dir
                             select df;

            foreach (MetaData dropMeta in newFolders)
            {
                //ITS A FOLDER! (exists on dropbox but not phone)

                //If folder was added to dropbox after last sync, download it
                if (dropMeta.Modified > TimeZone.CurrentTimeZone.ToUniversalTime(syncFolder.LastSync))
                {
                    //create local folder and download files in said folder
                    var newFolder = new DirectoryInfo(Path.Combine(syncFolder.Path, dropMeta.Name));
                    if (!newFolder.Exists)
                    {
                        newFolder.Create();
                    }

                    var subFolder = new SyncFolder(newFolder);
                    subFolder.Parent = syncFolder;
                    Sync(subFolder, string.Format("{0}/{1}", dropPath, syncFolder.Name));
                }
                else
                {
                    //folder deleted (delete)
                    Syncer.Instance.DropBox.Delete(dropMeta);
                }
                continue;
            }
        }