/// <inheritdoc /> public Task <CopyFileResult> CopyToAsync(OperationContext context, ContentLocation sourceLocation, Stream destinationStream, CopyOptions options) { CopyAttempts++; if (CustomResults != null) { return(Task.FromResult(CustomResults[CopyAttempts - 1])); } return(Task.FromResult(CopyToAsyncResult)); }
public Task <CopyFileResult> CopyToAsync(OperationContext context, ContentLocation sourceLocation, Stream destinationStream, CopyOptions options) { var sourcePath = PathUtilities.GetContentPath(sourceLocation.Machine.Path, sourceLocation.Hash); var result = CopyToAsyncCore(context, sourcePath, destinationStream, options); CopyToAsyncTask = result; return(result); }
//sets the content page public void setContentPage(UIElement contentPanel, ContentLocation location) { if (location == ContentLocation.Left) { panelLeft.Children.Clear(); panelLeft.Children.Add(contentPanel); } if (location == ContentLocation.Right) { panelRight.Children.Clear(); panelRight.Children.Add(contentPanel); } }
/// <summary> /// Sets the notification message top additional content. /// </summary> /// <param name="builder">The builder.</param> /// <param name="additionalContent">The additional content.</param> /// <param name="contentLocation">The location of the content.</param> /// <returns>Returns the notification message builder.</returns> public static NotificationMessageBuilder WithAdditionalContent( this NotificationMessageBuilder builder, ContentLocation contentLocation, object additionalContent) { switch (contentLocation) { case ContentLocation.Top: { builder.SetAdditionalContentTop(additionalContent); break; } case ContentLocation.Bottom: { builder.SetAdditionalContentBottom(additionalContent); break; } case ContentLocation.Left: { builder.SetAdditionalContentLeft(additionalContent); break; } case ContentLocation.Right: { builder.SetAdditionalContentRight(additionalContent); break; } case ContentLocation.Main: { builder.SetAdditionalContentMain(additionalContent); break; } case ContentLocation.AboveBadge: { builder.SetAdditionalContentOverBadge(additionalContent); break; } default: { break; } } return(builder); }
protected override async Task <CopyFileResult> CopyFileAsync( OperationContext context, IRemoteFileCopier copier, ContentLocation sourcePath, AbsolutePath destinationPath, long expectedContentSize, bool overwrite, CopyOptions options, CancellationToken cancellationToken) { // TODO: why the destination str using var destinationStream = FileSystem.OpenForWrite(destinationPath, sourcePath.Size, FileMode.Create, FileShare.None, FileOptions.None, 1024); return(await copier.CopyToAsync(context, sourcePath, destinationStream, options)); }
private void ParseManifest(DirectoryInfo contentPackageDirectory) { string productName = contentPackageDirectory.Name; string manifestPath = Path.Combine(contentPackageDirectory.FullName, "Manifest.dsx"); if (!File.Exists(manifestPath)) { string directoryPath = contentPackageDirectory.FullName; FileInfo[] contentFiles = contentPackageDirectory.GetFiles("*", SearchOption.AllDirectories); foreach (FileInfo contentFile in contentFiles) { string fullPath = contentFile.FullName; if (!fullPath.StartsWith(contentPackageDirectory.FullName)) { throw new InvalidOperationException("unexpected content file not inside content directory: " + fullPath); } string relativePath = fullPath.Substring(contentPackageDirectory.FullName.Length).Replace("\\", "/").ToLowerInvariant(); contentLocations[relativePath] = new ContentLocation(productName, contentFile); } return; } Manifest manifest = (Manifest)Manifest.Serializer.Deserialize(File.OpenRead(manifestPath)); foreach (ManifestFile file in manifest.Files) { string path = file.Path; int indexOfSlash = path.IndexOf('/'); string prefix = path.Substring(0, indexOfSlash); string suffix = path.Substring(indexOfSlash + 1); if (prefix != "Content") { throw new InvalidOperationException("unexpected folder in manifest: " + prefix); } contentLocations["/" + suffix.ToLowerInvariant()] = new ContentLocation(productName, contentPackageDirectory.File(path)); } }
/// <inheritdoc /> public async Task <CopyFileResult> CopyToAsync( OperationContext context, ContentLocation sourceLocation, Stream destinationStream, CopyOptions options) { // Extract host and port from machine location (string host, int port) = ExtractHostInfo(sourceLocation.Machine); // Contact hard-coded port on source try { // ResourcePoolV2 may throw TimeoutException if the connection fails. // Wrapping this error and converting it to an "error code". return(await _clientCache.UseWithInvalidationAsync(context, host, port, async (nestedContext, clientWrapper) => { var result = await clientWrapper.Value.CopyToAsync(nestedContext, sourceLocation.Hash, destinationStream, options); InvalidateResourceIfNeeded(nestedContext, options, result, clientWrapper); return result; })); } catch (ResultPropagationException e) { if (e.Result.Exception != null) { return(GrpcCopyClient.CreateResultFromException(e.Result.Exception)); } return(new CopyFileResult(CopyResultCode.Unknown, e.Result)); } catch (Exception e) { return(new CopyFileResult(CopyResultCode.Unknown, e)); } }
/// <inheritdoc /> public virtual async Task <CopyFileResult> CopyToAsync(OperationContext context, ContentLocation sourceLocation, Stream destinationStream, CopyOptions options) { var sourcePath = new AbsolutePath(sourceLocation.Machine.Path) / FileSystemContentStoreInternal.GetPrimaryRelativePath(sourceLocation.Hash, includeSharedFolder: false); if (!FileUtilities.Exists(sourcePath.Path)) { return(new CopyFileResult(CopyResultCode.FileNotFoundError, $"Source file {sourcePath} doesn't exist.")); } long startPosition = destinationStream.Position; using (Stream s = FileUtilities.CreateAsyncFileStream(sourcePath.Path, FileMode.Open, FileAccess.Read, FileShare.Read, FileOptions.Asynchronous | FileOptions.SequentialScan)) { return(await s.CopyToAsync(destinationStream, 81920, context.Token).ContinueWith(_ => CopyFileResult.SuccessWithSize(destinationStream.Position - startPosition))); } }
/// <inheritdoc /> public virtual Task <FileExistenceResult> CheckFileExistsAsync(OperationContext context, ContentLocation sourceLocation) { var path = new AbsolutePath(sourceLocation.Machine.Path) / FileSystemContentStoreInternal.GetPrimaryRelativePath(sourceLocation.Hash, includeSharedFolder: false); var resultCode = FileUtilities.Exists(path.Path) ? FileExistenceResult.ResultCode.FileExists : FileExistenceResult.ResultCode.FileNotFound; return(Task.FromResult(new FileExistenceResult(resultCode))); }
Content(ContentLocation contentLocation, string property, string value) { ContentLocation = contentLocation; Property = property; Value = value; }
public Task <FileExistenceResult> CheckFileExistsAsync(OperationContext context, ContentLocation sourceLocation) { var path = PathUtilities.GetContentPath(sourceLocation.Machine.Path, sourceLocation.Hash); if (FileExistenceByReturnCode.TryGetValue(path, out var resultQueue) && resultQueue.TryDequeue(out var result)) { return(Task.FromResult(new FileExistenceResult(result))); } if (File.Exists(path.Path)) { return(Task.FromResult(new FileExistenceResult(FileExistenceResult.ResultCode.FileExists))); } return(Task.FromResult(new FileExistenceResult(FileExistenceResult.ResultCode.Error))); }
/// <inheritdoc /> public Task <FileExistenceResult> CheckFileExistsAsync(OperationContext context, ContentLocation sourceLocation) { // Extract host and port from machine location (string host, int port) = ExtractHostInfo(sourceLocation.Machine); return(_clientCache.UseAsync(context, host, port, (nestedContext, client) => client.CheckFileExistsAsync(nestedContext, sourceLocation.Hash))); }
#pragma warning restore 649 /// <inheritdoc /> public Task <FileExistenceResult> CheckFileExistsAsync(OperationContext context, ContentLocation sourceLocation) => Task.FromResult(CheckFileExistsAsyncResult);