コード例 #1
0
        protected override async Task <GetItemResult> ExecuteAsync(GetItemMessage message)
        {
            return(await Task.Run <GetItemResult> (() => {
                var targetPath = Path.GetFullPath(Path.Combine(
                                                      MessagingContext.GetBuildPath(),
                                                      message.AppName,
                                                      message.SessionId,
                                                      PlatformPath.GetPathForCurrentPlatform(message.ItemSpec)));

                var result = new GetItemResult();

                if (File.Exists(targetPath))
                {
                    result.FileExists = true;

                    // Avoiding sending the payload if the file is too large based on the defined limit by the the client
                    if (new System.IO.FileInfo(targetPath).Length > message.LimitLength)
                    {
                        result.FileLengthExceedsLimit = true;
                    }
                    else
                    {
                        result.Content = File.ReadAllBytes(targetPath);
                    }
                }

                return result;
            }).ConfigureAwait(continueOnCapturedContext: false));
        }
コード例 #2
0
        protected override async Task <CompareItemsResult> ExecuteAsync(CompareItemsMessage message)
        {
            return(await Task.Run(() => {
                var buildPath = Path.Combine(MessagingContext.GetBuildPath(), message.AppName, message.SessionId);
                var files = new List <string> ();

                using (var hashAlgorithm = Hash.GetAlgorithm()) {
                    foreach (var file in message.Items)
                    {
                        var targetPath = Path.Combine(buildPath, PlatformPath.GetPathForCurrentPlatform(file.ItemSpec));

                        if (!File.Exists(targetPath))
                        {
                            files.Add(file.ItemSpec);
                        }
                        else
                        {
                            using (var stream = File.OpenRead(targetPath)) {
                                var localHash = hashAlgorithm.ComputeHashAsString(stream);

                                if (file.Hash != localHash)
                                {
                                    files.Add(file.ItemSpec);
                                }
                            }
                        }
                    }
                }

                return new CompareItemsResult {
                    MissingFiles = files
                };
            }).ConfigureAwait(continueOnCapturedContext: false));
        }
コード例 #3
0
        protected override async Task ExecuteAsync(CopyItemMessage message)
        {
            await Task.Run(async() => {
                var targetPath = Path.GetFullPath(Path.Combine(
                                                      MessagingContext.GetBuildPath(),
                                                      message.AppName,
                                                      message.SessionId,
                                                      PlatformPath.GetPathForCurrentPlatform(message.ItemSpec)));

                if (File.Exists(targetPath))
                {
                    File.Delete(targetPath);
                }
                else if (!Directory.Exists(Path.GetDirectoryName(targetPath)))
                {
                    Directory.CreateDirectory(Path.GetDirectoryName(targetPath));
                }

                using (var file = File.Create(targetPath))
                    using (var stream = new MemoryStream(message.Content))
                        await stream.CopyToAsync(file).ConfigureAwait(continueOnCapturedContext: false);
            });
        }