public static async Task Test1Async() { string path = "c:\\data\\test"; DirectoryInfo directoryInfo = new DirectoryInfo(path); if (directoryInfo.Exists) { directoryInfo.Delete(true); } directoryInfo.Create(); FileStorageFactory factory = new FileStorageFactory(new Uri("http://tempuri.org"), path); await RegistrationMaker.Process(new RegistrationKey("mypackage"), CreateTestSingleEntryBatch("mypackage", "1.0.0"), factory, new Uri("http://content/"), 2, 3); await RegistrationMaker.Process(new RegistrationKey("mypackage"), CreateTestSingleEntryBatch("mypackage", "2.0.0"), factory, new Uri("http://content/"), 2, 3); await RegistrationMaker.Process(new RegistrationKey("mypackage"), CreateTestSingleEntryBatch("mypackage", "3.0.0"), factory, new Uri("http://content/"), 2, 3); await RegistrationMaker.Process(new RegistrationKey("mypackage"), CreateTestSingleEntryBatch("mypackage", "4.0.0"), factory, new Uri("http://content/"), 2, 3); await RegistrationMaker.Process(new RegistrationKey("mypackage"), CreateTestSingleEntryBatch("mypackage", "5.0.0"), factory, new Uri("http://content/"), 2, 3); await RegistrationMaker.Process(new RegistrationKey("mypackage"), CreateTestSingleEntryBatch("mypackage", "6.0.0"), factory, new Uri("http://content/"), 2, 3); }
/// <summary> /// Get the file names with link on it /// </summary> /// <returns>The file names with link</returns> public List <FileLink> GetFiles() { List <FileLink> files = new List <FileLink>(); IFileStorage storage = FileStorageFactory.CreateFileStorage(); List <string> fileNames = storage.GetFileNames(); foreach (string fileName in fileNames) { FileLink fileLink = new FileLink(); fileLink.Name = fileName; if (fileName == ".wopitest") { fileLink.Url = string.Format("http://{0}/WopiValidator/Index/{1}", ConfigurationManager.AppSettings["WOPIServerName"], fileName); } else { fileLink.Url = string.Format("http://{0}/wopiframe/Index/{1}", ConfigurationManager.AppSettings["WOPIServerName"], fileName); } files.Add(fileLink); } return(files); }
public StorageTest() { FileStorageFactory.Initialize(new FileStorageOption { FileServer = "http://localhost:5000" }); }
public static async Task Test4Async() { StorageFactory storageFactory = new FileStorageFactory(new Uri("http://*****:*****@"c:\data\site\reg2"); //StorageCredentials credentials = new StorageCredentials("", ""); //CloudStorageAccount account = new CloudStorageAccount(credentials, true); //StorageFactory storageFactory = new AzureStorageFactory(account, "reg38", "registration"); storageFactory.Verbose = true; Uri index = new Uri("https://*****:*****@"c:\data\site", InnerHandler = new HttpClientHandler() }); }; RegistrationCatalogCollector collector = new RegistrationCatalogCollector(index, storageFactory, handlerFunc); collector.ContentBaseAddress = new Uri("http://az320820.vo.msecnd.net"); //collector.PackageCountThreshold = 50; //CollectorCursor cursor = new CollectorCursor(new DateTime(2014, 10, 01, 03, 27, 35, 360, DateTimeKind.Utc)); await collector.Run(); Console.WriteLine("http requests: {0} batch count: {1}", collector.RequestCount); }
public void Amazon_Source_Provider_Test() { var provider = new FileStorageFactory(new Options { AwsSourceEndpoint = "us-east-1" }).Get("source-aws"); Assert.IsInstanceOf <S3>(provider); }
public void Amazon_Destination_Provider_Test() { var provider = new FileStorageFactory(new Options { AwsDestinationEndpoint = "us-east-1" }).Get("dest-aws"); Assert.IsInstanceOf <S3>(provider); }
public AsyncStore(string name) { var serializerFactory = new MsgPckSerializerFactory(); var storageFactory = new FileStorageFactory(serializerFactory); _engine = new Engine(storageFactory); _collection = _engine.GetCollection <string, TValue>(name); }
/// <summary> /// Processes a CheckFileInfo request /// </summary> /// <remarks> /// For full documentation on CheckFileInfo, see /// https://wopi.readthedocs.io/projects/wopirest/en/latest/files/CheckFileInfo.html /// </remarks> private void HandleCheckFileInfoRequest(HttpContext context, WopiRequest requestData) { if (!ValidateAccess(requestData, writeAccessRequired: false)) { ReturnInvalidToken(context.Response); return; } IFileStorage storage = FileStorageFactory.CreateFileStorage(); long size = storage.GetFileSize(requestData.Id); if (size == -1) { ReturnFileUnknown(context.Response); return; } bool bRO = storage.GetReadOnlyStatus(requestData.Id); try { CheckFileInfoResponse responseData = new CheckFileInfoResponse() { // required CheckFileInfo properties BaseFileName = Path.GetFileName(requestData.Id), OwnerId = "documentOwnerId", Size = Convert.ToInt32(size), Version = storage.GetFileVersion(requestData.Id), UserId = "WOPITestUser", // optional CheckFileInfo properties BreadcrumbBrandName = "LocalStorage WOPI Host", //BreadcrumbFolderName = fileInfo.Directory != null ? fileInfo.Directory.Name : "", BreadcrumbFolderName = "", BreadcrumbDocName = Path.GetFileNameWithoutExtension(requestData.Id), BreadcrumbBrandUrl = "http://" + context.Request.Url.Host, BreadcrumbFolderUrl = "http://" + context.Request.Url.Host, UserFriendlyName = "A WOPI User", SupportsLocks = true, SupportsUpdate = true, UserCanNotWriteRelative = true, /* Because this host does not support PutRelativeFile */ ReadOnly = bRO, UserCanWrite = !bRO }; string jsonString = JsonConvert.SerializeObject(responseData); context.Response.Write(jsonString); ReturnSuccess(context.Response); } catch (UnauthorizedAccessException) { ReturnFileUnknown(context.Response); } }
public void DoesParseTheUSGSResponse() { var fac = new FileStorageFactory("data"); var response = fac.Get <USGSRiverResponse>("riverdata.json"); var flows = response.ParseTimeSeriesData(TimeSeriesTypes.CubicFeet); Assert.Empty(flows); }
public void DoesParse_USGSResponse_HasGaugeHeightData() { var fac = new FileStorageFactory("data"); var response = fac.Get <USGSRiverResponse>("riverdata.json"); var levels = response.ParseTimeSeriesData(TimeSeriesTypes.GuageHeight); Assert.NotEmpty(levels); }
/// <summary> /// Processes a Lock request /// </summary> /// <remarks> /// For full documentation on Lock, see /// https://wopi.readthedocs.io/projects/wopirest/en/latest/files/Lock.html /// </remarks> private void HandleLockRequest(HttpContext context, WopiRequest requestData) { if (!ValidateAccess(requestData, writeAccessRequired: true)) { ReturnInvalidToken(context.Response); return; } IFileStorage storage = FileStorageFactory.CreateFileStorage(); long size = storage.GetFileSize(requestData.Id); if (size == -1) { ReturnFileUnknown(context.Response); return; } string newLock = context.Request.Headers[WopiHeaders.Lock]; lock (Locks) { LockInfo existingLock; bool fLocked = TryGetLock(requestData.Id, out existingLock); if (fLocked && existingLock.Lock != newLock) { // There is a valid existing lock on the file and it doesn't match the requested lockstring. // This is a fairly common case and shouldn't be tracked as an error. Office Online can store // information about a current session in the lock value and expects to conflict when there's // an existing session to join. ReturnLockMismatch(context.Response, existingLock.Lock); } else { // The file is not currently locked or the lock has already expired if (fLocked) { Locks.Remove(requestData.Id); } // Create and store new lock information // TODO: In a real implementation the lock should be stored in a persisted and shared system. Locks[requestData.Id] = new LockInfo() { DateCreated = DateTime.UtcNow, Lock = newLock }; context.Response.AddHeader(WopiHeaders.ItemVersion, storage.GetFileVersion(requestData.FullPath)); // Return success ReturnSuccess(context.Response); } } }
static async Task Test0Async() { StorageFactory factory = new FileStorageFactory(new Uri("https://tempuri.org/test"), @"c:\\data\\test"); Console.WriteLine(factory); Storage storage = factory.Create(); StorageContent content = new StringStorageContent("TEST"); await storage.Save(new Uri(storage.BaseAddress, "doc1.txt"), content); }
public BaseForecastRepositoryTests() { FactoryMock = new Mock <IHttpClientFactory>(); fac = new FileStorageFactory("data"); config = new WeatherRepositoryConfig { BaseNWSURL = "https://api.weather.gov", UserAgent = "SomeAgentDescriptor" }; repository = new ForecastRepository(FactoryMock.Object, config); }
/// <summary> /// Processes a UnlockAndRelock request /// </summary> /// <remarks> /// For full documentation on UnlockAndRelock, see /// https://wopi.readthedocs.io/projects/wopirest/en/latest/files/UnlockAndRelock.html /// </remarks> private void HandleUnlockAndRelockRequest(HttpContext context, WopiRequest requestData) { if (!ValidateAccess(requestData, writeAccessRequired: true)) { ReturnInvalidToken(context.Response); return; } IFileStorage storage = FileStorageFactory.CreateFileStorage(); long size = storage.GetFileSize(requestData.Id); if (size == -1) { ReturnFileUnknown(context.Response); return; } string newLock = context.Request.Headers[WopiHeaders.Lock]; string oldLock = context.Request.Headers[WopiHeaders.OldLock]; lock (Locks) { LockInfo existingLock; if (TryGetLock(requestData.Id, out existingLock)) { if (existingLock.Lock == oldLock) { // There is a valid lock on the file and the existing lock matches the provided one // Replace the existing lock with the new one Locks[requestData.Id] = new LockInfo() { DateCreated = DateTime.UtcNow, Lock = newLock }; context.Response.Headers[WopiHeaders.OldLock] = newLock; ReturnSuccess(context.Response); } else { // The existing lock doesn't match the requested one. Return a lock mismatch error // along with the current lock ReturnLockMismatch(context.Response, existingLock.Lock); } } else { // The requested lock does not exist. That's also a lock mismatch error. ReturnLockMismatch(context.Response, reason: "File not locked"); } } }
static void Main(string[] args) { Mirror mirror = new Mirror(); string uri = "https://social.msdn.microsoft.com/Forums/en-US/e7279f10-fad4-4a9f-b7e2-c2e1d52c86aa/get-page-source-with-httpclient?forum=winappswithcsharp"; string savePath = @"D:\EPAM\Laba\Days\Day10(Async)\Homework\TestHomwork"; //TODO move this in Inject, but how pass argument to ctor if it will be known after user will enter the path IStorageFactory storageFactory = new FileStorageFactory(savePath); var result = mirror.GetSiteCopy(uri, storageFactory, 1, PathLinkRestriction.CurrentDomen, "png, gif, js"); Task.WaitAll(result); }
/// <summary> /// Processes a GetFile request /// </summary> /// <remarks> /// For full documentation on GetFile, see /// https://wopi.readthedocs.io/projects/wopirest/en/latest/files/GetFile.html /// </remarks> private void HandleGetFileRequest(HttpContext context, WopiRequest requestData) { if (!ValidateAccess(requestData, writeAccessRequired: false)) { ReturnInvalidToken(context.Response); return; } IFileStorage storage = FileStorageFactory.CreateFileStorage(); Stream stream = storage.GetFile(requestData.Id); if (null == stream) { ReturnFileUnknown(context.Response); return; } try { int i = 0; List <byte> bytes = new List <byte>(); do { byte[] buffer = new byte[1024]; i = stream.Read(buffer, 0, 1024); if (i > 0) { byte[] data = new byte[i]; Array.Copy(buffer, data, i); bytes.AddRange(data); } }while (i > 0); context.Response.OutputStream.Write(bytes.ToArray(), 0, bytes.Count); stream.Close(); stream.Dispose(); //context.Response.AddHeader(WopiHeaders.ItemVersion, storage.GetFileVersion(requestData.FullPath)); ReturnSuccess(context.Response); } catch (UnauthorizedAccessException) { ReturnFileUnknown(context.Response); } catch (FileNotFoundException) { ReturnFileUnknown(context.Response); } }
public async Task UploadAndDelete() { var storage = FileStorageFactory.Create(); foreach (var file in GetFiles()) { var result = await storage.UploadAsync(file); Assert.True(result.Success); Assert.Equal(1, result.Data.Length); var delete = await storage.TryDeleteAsync(result.Data[0]); Assert.True(delete); } }
/// <summary> /// Processes a Unlock request /// </summary> /// <remarks> /// For full documentation on Unlock, see /// https://wopi.readthedocs.io/projects/wopirest/en/latest/files/Unlock.html /// </remarks> private void HandleUnlockRequest(HttpContext context, WopiRequest requestData) { if (!ValidateAccess(requestData, writeAccessRequired: true)) { ReturnInvalidToken(context.Response); return; } IFileStorage storage = FileStorageFactory.CreateFileStorage(); long size = storage.GetFileSize(requestData.Id); if (size == -1) { ReturnFileUnknown(context.Response); return; } string newLock = context.Request.Headers[WopiHeaders.Lock]; lock (Locks) { LockInfo existingLock; if (TryGetLock(requestData.Id, out existingLock)) { if (existingLock.Lock == newLock) { // There is a valid lock on the file and the existing lock matches the provided one // Remove the current lock Locks.Remove(requestData.Id); context.Response.AddHeader(WopiHeaders.ItemVersion, storage.GetFileVersion(requestData.FullPath)); ReturnSuccess(context.Response); } else { // The existing lock doesn't match the requested one. Return a lock mismatch error // along with the current lock ReturnLockMismatch(context.Response, existingLock.Lock); } } else { // The requested lock does not exist. That's also a lock mismatch error. ReturnLockMismatch(context.Response, reason: "File not locked"); } } }
public async Task UploadPakcageAndDelete() { var storage = FileStorageFactory.Create(); foreach (var file in Directory.GetFiles("zip")) { var result = await storage.UploadPackageAsync(file); Assert.True(result.Success); Assert.Equal(2, result.Data.Length); //压缩包内有两个文件 foreach (var uploadOutput in result.Data) { var delete = await storage.TryDeleteAsync(uploadOutput.FileUrl); Assert.True(delete); } } }
public static async Task Test0Async() { Func <HttpMessageHandler> handlerFunc = () => { return(new FileSystemEmulatorHandler { BaseAddress = new Uri("http://*****:*****@"c:\data\site", InnerHandler = new HttpClientHandler() }); }; StorageFactory storageFactory = new FileStorageFactory(new Uri("http://*****:*****@"c:\data\site\nuspec"); CommitCollector collector = new ReindexCatalogCollector(new Uri("http://localhost:8000/full/index.json"), storageFactory, handlerFunc); await collector.Run(); Console.WriteLine("http requests: {0}", collector.RequestCount); }
public static async Task Test4Async() { Uri catalogUri = new Uri("https://nugetdevstorage.blob.core.windows.net/catalog/index.json"); string path = "c:\\data\\registration20150417"; DirectoryInfo directoryInfo = new DirectoryInfo(path); if (directoryInfo.Exists) { directoryInfo.Delete(true); } directoryInfo.Create(); FileStorageFactory factory = new FileStorageFactory(new Uri("http://tempuri.org"), path); CollectorBase collector = new RegistrationCollector(catalogUri, factory); await collector.Run(); }
protected override void ConfigureJobServices(IServiceCollection services, IConfigurationRoot configurationRoot) { services.Configure <PackageHashConfiguration>(configurationRoot.GetSection(PackageHashConfigurationSectionName)); services.AddTransient <IEntityRepository <Package>, EntityRepository <Package> >(); services.AddTransient <IPackageHashCalculator, PackageHashCalculator>(); services.AddTransient <IBatchProcessor, BatchProcessor>(); services.AddTransient <IResultRecorder, ResultRecorder>(); services.AddTransient <IPackageHashProcessor, PackageHashProcessor>(); services.AddTransient(s => { var address = new Uri("http://localhost"); var fileStorageFactory = new FileStorageFactory( address, Directory.GetCurrentDirectory(), s.GetRequiredService <ILogger <FileStorage> >()); return(new DurableCursor( new Uri(address, $"cursor_{_bucketNumber}_of_{_bucketCount}.json"), fileStorageFactory.Create(), DateTimeOffset.MinValue)); }); }
public static async Task Test0Async() { string path = "c:\\data\\test"; DirectoryInfo directoryInfo = new DirectoryInfo(path); if (directoryInfo.Exists) { directoryInfo.Delete(true); } directoryInfo.Create(); IDictionary <string, IGraph> catalog = new Dictionary <string, IGraph>(); //catalog.Add(CreateTestCatalogEntry("mypackage", "1.0.0")); //catalog.Add(CreateTestCatalogEntry("mypackage", "2.0.0")); catalog.Add(CreateTestCatalogEntry("mypackage", "3.0.0")); catalog.Add(CreateTestCatalogEntry("mypackage", "4.0.0")); catalog.Add(CreateTestCatalogEntry("mypackage", "5.0.0")); FileStorageFactory factory = new FileStorageFactory(new Uri("http://tempuri.org"), path); await RegistrationMaker.Process(new RegistrationKey("mypackage"), catalog, factory, new Uri("http://content/"), 2, 3); }
/// <summary> /// Get the file names with link on it /// </summary> /// <returns>The file names with link</returns> public List <FileLink> GetFiles() { List <FileLink> files = new List <FileLink>(); IFileStorage storage = FileStorageFactory.CreateFileStorage(); List <string> fileNames = storage.GetFileNames(); foreach (string fileName in fileNames) { string ext = string.Empty; FileLink fileLink = new FileLink(); fileLink.Name = fileName; if (Path.HasExtension(fileName)) { ext = Path.GetExtension(fileName); } // WOPI Validator now requires the wopi test file to have a filename, "." and the "wopitest" extenstion. if ((!string.IsNullOrEmpty(ext)) && (ext == ".wopitest")) { fileLink.Url = string.Format("http://{0}/WopiValidator/Index/{1}", ConfigurationManager.AppSettings["WOPIServerName"], fileName); } else { fileLink.Url = string.Format("http://{0}/wopiframe/Index/{1}", ConfigurationManager.AppSettings["WOPIServerName"], fileName); } files.Add(fileLink); } return(files); }
public async Task ExecuteAsync(bool restart) { var fileSystemStorage = new FileStorageFactory( new Uri("http://localhost/"), Directory.GetCurrentDirectory(), verbose: false); var front = new DurableCursor( new Uri("http://localhost/cursor.json"), fileSystemStorage.Create(), DateTime.MinValue); if (restart) { await front.LoadAsync(CancellationToken.None); front.Value = DateTime.MinValue; await front.SaveAsync(CancellationToken.None); } var back = MemoryCursor.CreateMax(); await _collector.RunAsync(front, back, CancellationToken.None); }
public void Google_Destination_Provider_Test() { var provider = new FileStorageFactory(new Options()).Get("dest-google"); Assert.IsInstanceOf <GoogleCloudStorage>(provider); }
/// <summary> /// Processes a PutFile request /// </summary> /// <remarks> /// For full documentation on PutFile, see /// https://wopi.readthedocs.io/projects/wopirest/en/latest/files/PutFile.html /// </remarks> private void HandlePutFileRequest(HttpContext context, WopiRequest requestData) { if (!ValidateAccess(requestData, writeAccessRequired: true)) { ReturnInvalidToken(context.Response); return; } IFileStorage storage = FileStorageFactory.CreateFileStorage(); long size = storage.GetFileSize(requestData.Id); if (size == -1) { ReturnFileUnknown(context.Response); return; } string newLock = context.Request.Headers[WopiHeaders.Lock]; LockInfo existingLock; bool hasExistingLock; lock (Locks) { hasExistingLock = TryGetLock(requestData.Id, out existingLock); } if (hasExistingLock && existingLock.Lock != newLock) { // lock mismatch/locked by another interface ReturnLockMismatch(context.Response, existingLock.Lock); return; } // The WOPI spec allows for a PutFile to succeed on a non-locked file if the file is currently zero bytes in length. // This allows for a more efficient Create New File flow that saves the Lock roundtrips. if (!hasExistingLock && size != 0) { // With no lock and a non-zero file, a PutFile could potentially result in data loss by clobbering // existing content. Therefore, return a lock mismatch error. ReturnLockMismatch(context.Response, reason: "PutFile on unlocked file with current size != 0"); } // Either the file has a valid lock that matches the lock in the request, or the file is unlocked // and is zero bytes. Either way, proceed with the PutFile. try { // TODO: Should be replaced with proper file save logic to a real storage system and ensures write atomicity int result = storage.UploadFile(requestData.Id, context.Request.InputStream); if (result != 0) { ReturnServerError(context.Response); return; } context.Response.AddHeader(WopiHeaders.ItemVersion, storage.GetFileVersion(requestData.FullPath)); ReturnSuccess(context.Response); } catch (UnauthorizedAccessException) { ReturnFileUnknown(context.Response); } catch (IOException) { ReturnServerError(context.Response); } }