Example #1
0
		static async Task<CompareResult> compareFilesWithSameSize(IReadFileSystem rfs, string source, string target)
		{
			const int BufSize = 0x10000;
			var sBuf = new byte[BufSize];
			var tBuf = new byte[BufSize];

			using (var sFile = rfs.open(source))
			using (var tFile = rfs.open(target))
			{

				for (; ; )
				{
					var t1 = sFile.readAsync(sBuf, 0, sBuf.Length);
					var t2 = tFile.readAsync(tBuf, 0, tBuf.Length);

					var readBytes = await Task.WhenAll(t1, t2);
					var read = readBytes[0];
					if (read != readBytes[1])
						return CompareResult.Differ;

					if (read == 0)
						return CompareResult.Equal;

					for (int i = 0; i != read; ++i)
						if (sBuf[i] != tBuf[i])
							return CompareResult.Differ;
				}
				
			}
		}
Example #2
0
		static async Task<CompareResult> compareFile(IReadFileSystem rfs, string source, string target)
		{
			var sourceInfo = rfs.query(source);
			var targetInfo = rfs.query(target);

			var sType = sourceInfo.Type;
			var tType = targetInfo.Type;
			if (sType != PathType.File || tType != PathType.File)
				return CompareResult.Unknown;

			if (sourceInfo.Length != targetInfo.Length)
				return CompareResult.Differ;

			return await compareFilesWithSameSize(rfs, source, target);
		}
Example #3
0
		static IDisposable beginWatching(
			IReadFileSystem rfs, 
			string sourcePath, 
			string targetPath,
			Action<string> sourceChange, 
			Action<string> targetChange)
		{
			var src = rfs.beginWatch(sourcePath, sourceChange);
			var target = rfs.beginWatch(targetPath, targetChange);

			return new DisposeAction(() =>
				{
					target.Dispose();
					src.Dispose();
				});
		}
Example #4
0
        public PathChange(
            Configuration configuration,
            ChangeMode mode,
            ChangeLocation location,
            string relativePath,
            IReadFileSystem readFileSystem,
            IWriteFileSystem writeFileSystem)
        {
            Configuration = configuration;
            Mode = mode;
            Location = location;
            RelativePath = relativePath;
            ReadFileSystem = readFileSystem;
            WriteFileSystem = writeFileSystem;

            Source = Path.Combine(Configuration.SourcePath, RelativePath);
            Target = Path.Combine(Configuration.TargetPath, RelativePath);
        }
Example #5
0
		static async Task deepSynchronization(Configuration Configuration, IReadFileSystem reader, IWriteFileSystem writer)
		{
			var pc = new PathChange(Configuration, ChangeMode.Deep, ChangeLocation.Unknown, "", reader, writer);
			await Synchronizer.sync(pc);
		}