Ejemplo n.º 1
0
        private SyncResult CopyFiles(string srcRoot, HttpClient client, SyncDirDirectory nodeDir)
        {
            var message = new HttpRequestMessage();
            var content = new MultipartSyncDirContent();

            var clientDir = new DirectoryInfo(srcRoot);

            Logger.Verbose("Diffing server file structure with client...");
            var diffs = nodeDir.Diff(clientDir);

            var files = diffs.MissingAndChangedPaths;

            foreach (var file in files)
            {
                if (file.IsDirectory)
                {
                    continue;
                }

                Logger.Verbose(string.Format("File {0} is missing or changed on server. Adding to upload queue.", file.RelativePath));
                var fileInfo   = new FileInfo(file.Path);
                var fileStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
                content.Add(new StreamContent(fileStream), "file", file.RelativePath, fileInfo.Attributes, fileInfo.LastWriteTimeUtc);
            }

            var postProcContent = new SyncPostProcContent
            {
                DeletedFiles       = diffs.DeletedFiles,
                DeletedDirectories = diffs.DeletedDirectories,
                ChangedDirectories = diffs.ChangedDirectories
            };

            content.Add(new ObjectContent <SyncPostProcContent>(postProcContent, new JsonMediaTypeFormatter()));

            var link = nodeDir.Links.GetByRel("http://www.con-dep.net/rels/sync/directory");

            Logger.Verbose(string.Format("Using url {0} to {1} missing or changed files.", link.Href, link.HttpMethod));
            message.Method     = link.HttpMethod;
            message.Content    = content;
            message.RequestUri = new Uri(link.Href);

            Logger.Verbose("Copying files now...");
            var result = client.SendAsync(message)
                         .ContinueWith(task =>
            {
                if (task.Result.IsSuccessStatusCode)
                {
                    var syncResult = task.Result.Content.ReadAsAsync <SyncResult>().Result;
                    return(syncResult);
                }
                return(null);
            });

            result.Wait();
            return(result.Result);
        }
Ejemplo n.º 2
0
        private SyncResult CopyFiles(string srcRoot, HttpClient client, SyncDirDirectory nodeDir)
        {
            var message = new HttpRequestMessage();
            var content = new MultipartSyncDirContent();

            var clientDir = new DirectoryInfo(srcRoot);

            Logger.Verbose("Diffing server file structure with client...");
            var diffs = nodeDir.Diff(clientDir);

            var files = diffs.MissingAndChangedPaths;

            foreach (var file in files)
            {
                if (file.IsDirectory) continue;

                Logger.Verbose(string.Format("File {0} is missing or changed on server. Adding to upload queue.", file.RelativePath));
                var fileInfo = new FileInfo(file.Path);
                var fileStream = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read, FileShare.Read);
                content.Add(new StreamContent(fileStream), "file", file.RelativePath, fileInfo.Attributes, fileInfo.LastWriteTimeUtc);
            }

            var postProcContent = new SyncPostProcContent
            {
                DeletedFiles = diffs.DeletedFiles,
                DeletedDirectories = diffs.DeletedDirectories,
                ChangedDirectories = diffs.ChangedDirectories
            };
            content.Add(new ObjectContent<SyncPostProcContent>(postProcContent, new JsonMediaTypeFormatter()));

            var link = nodeDir.Links.GetByRel("http://www.con-dep.net/rels/sync/directory");

            Logger.Verbose(string.Format("Using url {0} to {1} missing or changed files.", link.Href, link.HttpMethod));
            message.Method = link.HttpMethod;
            message.Content = content;
            message.RequestUri = new Uri(link.Href);

            Logger.Verbose("Copying files now...");
            var result = client.SendAsync(message)
                .ContinueWith(task =>
                {
                    if (task.Result.IsSuccessStatusCode)
                    {
                        var syncResult = task.Result.Content.ReadAsAsync<SyncResult>().Result;
                        return syncResult;
                    }
                    return null;
                });
            result.Wait();
            return result.Result;
        }