Пример #1
0
        public bool AnyChanges(FsSyncInfo syncInfo)
        {
            if (string.IsNullOrEmpty(syncInfo.Filters))
                syncInfo.Filters = "*";
            var fs = GetFileSystemEntries(syncInfo.Source, syncInfo.Filters, SearchOption.AllDirectories);
            foreach (var item in fs)
            {
                if (IsExcludedFromSync(item, syncInfo.Excludes.Split(','))) continue;
                if ((File.GetAttributes(item) & FileAttributes.Directory) == FileAttributes.Directory)
                {
                    var destinationFolder = item.Replace(syncInfo.Source, syncInfo.Target);
                    if (!Directory.Exists(destinationFolder))
                        return true;
                }
                else
                {
                    var destinationFile = item.Replace(syncInfo.Source, syncInfo.Target);
                    if (!File.Exists(destinationFile) || !AreTheyTheSameFile(item, destinationFile))
                        return true;
                }

            }

            if (!Directory.Exists(syncInfo.Target))
                return false;

            var fsEntries = GetFileSystemEntries(syncInfo.Target, syncInfo.Filters, SearchOption.AllDirectories);
            foreach (var item in fsEntries)
            {
                if (IsExcludedFromSync(item, syncInfo.Excludes.Split(','))) continue;
                try
                {
                    if ((File.GetAttributes(item) & FileAttributes.Directory) == FileAttributes.Directory)
                    {
                        var sourceFolder = item.Replace(syncInfo.Target, syncInfo.Source);
                        if (!Directory.Exists(sourceFolder))
                            return true;
                    }
                    else
                    {
                        var sourceFile = item.Replace(syncInfo.Target, syncInfo.Source);
                        if (!File.Exists(sourceFile))
                            return true;
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }

            }

            //if (doPurge)
            //    RemoveRedundantFiles(source, target, filters, excludes);
            return false;
        }
        public void ShouldRunFileSystemSyncWhenStarted()
        {
            //Arrange
            var isOnRunStartRaised = false;
            var isRunCompleteRaised = false;
            var syncInfo = new FsSyncInfo {Source = "A", Target = "B"};
            var oneWaySynchronizerMock = new Mock<IOneWaySynchronizer>();
            oneWaySynchronizerMock.Setup(x => x.Run(syncInfo));

            //Act
            var fileSystemSyncWhenStartup = new FileSystemSyncWhenStartup(oneWaySynchronizerMock.Object) { Name = "TestWhenStarted", SyncInfo = syncInfo };
            fileSystemSyncWhenStartup.OnRunStart += name => { isOnRunStartRaised = true; };
            fileSystemSyncWhenStartup.OnRunComplete += name => { isRunCompleteRaised = true; };
            fileSystemSyncWhenStartup.Start();

            //Assert
            Assert.IsTrue(isOnRunStartRaised);
            Assert.IsTrue(isRunCompleteRaised);
            oneWaySynchronizerMock.Verify(x => x.Run(syncInfo));
        }
Пример #3
0
 public void Run(FsSyncInfo syncInfo)
 {
     if (string.IsNullOrEmpty(syncInfo.Filters))
         syncInfo.Filters = "*";
     SynchronizeDirectory(syncInfo.Source, syncInfo.Target, syncInfo.Filters, syncInfo.Excludes);
     if (syncInfo.DoPurge)
         RemoveRedundantFiles(syncInfo.Source, syncInfo.Target, syncInfo.Filters, syncInfo.Excludes);
 }