// save public override async Task Save(Uri resourceUri, StorageContent content) { SaveCount++; string name = GetName(resourceUri); if (Verbose) { Console.WriteLine("save {0}", name); } if (_directory.Container.CreateIfNotExists()) { _directory.Container.SetPermissions(new BlobContainerPermissions { PublicAccess = BlobContainerPublicAccessType.Blob }); if (Verbose) { Console.WriteLine("Created '{0}' publish container", _directory.Container.Name); } } CloudBlockBlob blob = _directory.GetBlockBlobReference(name); blob.Properties.ContentType = content.ContentType; blob.Properties.CacheControl = content.CacheControl; using (Stream stream = content.GetContentStream()) { await blob.UploadFromStreamAsync(stream); } }
protected override Task OnSave(Uri resourceUri, StorageContent content, CancellationToken cancellationToken) { var tasks = new List<Task>(); tasks.Add(_primaryStorage.Save(resourceUri, content, cancellationToken)); foreach (var storage in _secondaryStorage) { var secondaryResourceUri = new Uri(resourceUri.ToString() .Replace(_primaryStorage.BaseAddress.ToString(), storage.BaseAddress.ToString())); var secondaryContent = content; if (_writeSecondaryStorageContentInterceptor != null) { secondaryContent = _writeSecondaryStorageContentInterceptor( _primaryStorage.BaseAddress, resourceUri, storage.BaseAddress, secondaryResourceUri, content); } tasks.Add(storage.Save(secondaryResourceUri, secondaryContent, cancellationToken)); } return Task.WhenAll(tasks); }
public Task OnSave(Uri resourceUri, StorageContent content, CancellationToken cancellationToken) { _store[resourceUri] = new MemoryStorageEntry(content, content.ContentType, content.CacheControl); var tcs = new TaskCompletionSource<int>(); tcs.SetResult(0); return tcs.Task; }
// save protected override async Task OnSave(Uri resourceUri, StorageContent content, CancellationToken cancellationToken) { string name = GetName(resourceUri); CloudBlockBlob blob = _directory.GetBlockBlobReference(name); blob.Properties.ContentType = content.ContentType; blob.Properties.CacheControl = content.CacheControl; using (Stream stream = content.GetContentStream()) { await blob.UploadFromStreamAsync(stream, cancellationToken); } }
public StorageContent Rewrite( Uri primaryStorageBaseUri, Uri primaryResourceUri, Uri secondaryStorageBaseUri, Uri secondaryResourceUri, StorageContent content) { JTokenReader tokenReader = null; var storageContent = content as JTokenStorageContent; if (storageContent != null) { // Production code should always have JTokenStorageContent tokenReader = storageContent.Content.CreateReader() as JTokenReader; } else { // Test code may end up here - we need to make sure we have a JTokenReader at our disposal using (var streamReader = new StreamReader(content.GetContentStream())) { using (var jsonTextReader = new JsonTextReader(streamReader)) { tokenReader = JToken.Load(jsonTextReader).CreateReader() as JTokenReader; } } } if (tokenReader != null) { // Create a rewriting reader var rewritingReader = new RegistrationBaseUrlRewritingJsonReader(tokenReader, _replacements.Union(new List<KeyValuePair<string, string>> { new KeyValuePair<string, string>(primaryStorageBaseUri.ToString(), secondaryStorageBaseUri.ToString()), new KeyValuePair<string, string>(GetParentUriString(primaryResourceUri), GetParentUriString(secondaryResourceUri)) }).ToList()); // Clone the original token (passing through our intercepting reader) var updatedJson = JToken.Load(rewritingReader); // Create new content return new JTokenStorageContent(updatedJson, content.ContentType, content.CacheControl); } return content; }
public async Task Save(Uri resourceUri, StorageContent content, CancellationToken cancellationToken) { SaveCount++; TraceMethod("SAVE", resourceUri); try { await OnSave(resourceUri, content, cancellationToken); } catch (Exception e) { string message = String.Format("SAVE EXCEPTION: {0} {1}", resourceUri, e.Message); Trace.WriteLine(message); throw new Exception(message, e); } }
// save protected override async Task OnSave(Uri resourceUri, StorageContent content, CancellationToken cancellationToken) { SaveCount++; TraceMethod("SAVE", resourceUri); string name = GetName(resourceUri); string path = Path.Trim('\\') + '\\'; string[] t = name.Split('/'); name = t[t.Length - 1]; if (t.Length > 1) { for (int i = 0; i < t.Length - 1; i++) { string folder = t[i]; if (folder != string.Empty) { if (!(new DirectoryInfo(path + folder)).Exists) { DirectoryInfo directoryInfo = new DirectoryInfo(path); directoryInfo.CreateSubdirectory(folder); } path = path + folder + '\\'; } } } using (FileStream stream = File.Create(path + name)) { await content.GetContentStream().CopyToAsync(stream,4096, cancellationToken); } }
protected abstract Task OnSave(Uri resourceUri, StorageContent content, CancellationToken cancellationToken);
protected override Task OnSave(Uri resourceUri, StorageContent content, CancellationToken cancellationToken) { return _factory.OnSave(resourceUri, content, cancellationToken); }
protected abstract Task OnSave(Uri resourceUri, StorageContent content);
public Task Save(Uri resourceUri, StorageContent content, CancellationToken cancellationToken) { Task result = _innerStorage.Save(resourceUri, content, cancellationToken); Saved.Add(resourceUri); return result; }
// save protected override async Task OnSave(Uri resourceUri, StorageContent content, CancellationToken cancellationToken) { string name = GetName(resourceUri); CloudBlockBlob blob = _directory.GetBlockBlobReference(name); blob.Properties.ContentType = content.ContentType; blob.Properties.CacheControl = content.CacheControl; if (CompressContent) { blob.Properties.ContentEncoding = "gzip"; using (Stream stream = content.GetContentStream()) { MemoryStream destinationStream = new MemoryStream(); using (GZipStream compressionStream = new GZipStream(destinationStream, CompressionMode.Compress, true)) { await stream.CopyToAsync(compressionStream); } destinationStream.Seek(0, SeekOrigin.Begin); await blob.UploadFromStreamAsync(destinationStream, cancellationToken); } } else { using (Stream stream = content.GetContentStream()) { await blob.UploadFromStreamAsync(stream, cancellationToken); } } }
protected void AssertContentDoesNotContain(StorageContent content, string value) { var contentValue = content.GetContentString(); Assert.DoesNotContain(contentValue, value, StringComparison.OrdinalIgnoreCase); }
protected abstract Task OnSaveAsync(Uri resourceUri, StorageContent content, CancellationToken cancellationToken);
protected override Task OnSave(Uri resourceUri, StorageContent content, CancellationToken cancellationToken) { Content[resourceUri] = content; return Task.FromResult(true); }
/// <summary> /// Expands the package file to the temp directory. /// </summary> void ExpandPackage(StorageContent packageStorage, string tempDirectory) { Trace.TraceInformation("#StartActivity ExpandPackage"); Trace.TraceInformation("Decompressing package to temp directory."); FastZip fastZip = new FastZip(); fastZip.ExtractZip(packageStorage.GetContentStream(), tempDirectory, FastZip.Overwrite.Always, null, ".*", ".*", true, true); Trace.TraceInformation("#StopActivity ExpandPackage"); }