IEnumerable <HttpClientHandler> GetStableTests() { yield return(new HttpClientHandler( "Get string", HttpClientOperation.GetString, null, HttpContent.HelloWorld)); yield return(new HttpClientHandler( "Post string", HttpClientOperation.PostString, HttpContent.HelloWorld)); yield return(new HttpClientHandler( "Post string with result", HttpClientOperation.PostString, HttpContent.HelloWorld, new StringContent("Returned body"))); yield return(new HttpClientHandler( "Put", HttpClientOperation.PutString, HttpContent.HelloWorld)); if ((Flags & HttpServerFlags.HttpListener) == 0) { yield return(new HttpClientHandler( "Bug #20583", HttpClientOperation.PostString, HttpContent.HelloWorld, new Bug20583Content())); } yield return(new HttpClientHandler( "Bug #41206", HttpClientOperation.PutDataAsync, BinaryContent.CreateRandom(102400))); yield return(new HttpClientHandler( "Bug #41206 odd size", HttpClientOperation.PutDataAsync, BinaryContent.CreateRandom(102431))); }
public async Task Integration_VimeoClient_UploadEntireFile_UploadsFile_ByPath() { long length; IUploadRequest completedRequest; var tempFilePath = Path.GetTempFileName() + ".mp4"; using (var fs = new FileStream(tempFilePath, FileMode.CreateNew)) { GetFileFromEmbeddedResources(Testfilepath).CopyTo(fs); } using (var file = new BinaryContent(tempFilePath)) { file.ContentType.ShouldBe("video/mp4"); length = file.Data.Length; var client = CreateAuthenticatedClient(); completedRequest = await client.UploadEntireFileAsync(file); Debug.Assert(completedRequest.ClipId != null, "completedRequest.ClipId != null"); await client.DeleteVideoAsync(completedRequest.ClipId.Value); } completedRequest.ShouldNotBeNull(); completedRequest.AllBytesWritten.ShouldBeTrue(); completedRequest.IsVerifiedComplete.ShouldBeTrue(); completedRequest.BytesWritten.ShouldBe(length); completedRequest.ClipUri.ShouldNotBeNull(); completedRequest.ClipId.ShouldNotBeNull(); completedRequest.ClipId?.ShouldBeGreaterThan(0); if (Exists(tempFilePath)) { Delete(tempFilePath); } }
public async Task Integration_VimeoClient_DeleteTextTrack() { // arrange TextTrack completedRequest; VimeoClient client = CreateAuthenticatedClient(); using (var file = new BinaryContent(GetFullPath(TESTTEXTTRACKFILEPATH))) { completedRequest = await client.UploadTextTrackFileAsync( file, vimeoSettings.VideoId, new TextTrack { active = false, name = "DeleteTest", language = "en", type = "captions" }); } completedRequest.ShouldNotBeNull(); completedRequest.uri.ShouldNotBeNull(); var uri = completedRequest.uri; var trackId = System.Convert.ToInt64(uri.Substring(uri.LastIndexOf('/') + 1)); // act await client.DeleteTextTrackAsync(vimeoSettings.VideoId, trackId); //assert var texttrack = await client.GetTextTrackAsync(vimeoSettings.VideoId, trackId); texttrack.ShouldBeNull(); }
public void Integration_VimeoClient_UploadEntireFile_UploadsFile() { // arrange long length; IUploadRequest completedRequest; using (var file = new BinaryContent(GetFullPath(TESTFILEPATH))) { length = file.Data.Length; VimeoClient client = CreateAuthenticatedClient(); // act completedRequest = client.UploadEntireFile(file); Debug.Assert(completedRequest.ClipId != null, "completedRequest.ClipId != null"); client.DeleteVideo(completedRequest.ClipId.Value); } // assert completedRequest.ShouldNotBeNull(); completedRequest.AllBytesWritten.ShouldBeTrue(); completedRequest.IsVerifiedComplete.ShouldBeTrue(); completedRequest.BytesWritten.ShouldEqual(length); completedRequest.ClipUri.ShouldNotBeNull(); completedRequest.ClipId.ShouldBeGreaterThan(0); }
public async Task Integration_VimeoClient_DeleteTextTrack() { // arrange TextTrack completedRequest; var client = CreateAuthenticatedClient(); var fileStream = GetFileFromEmbeddedResources(Testtexttrackfilepath); fileStream.ShouldNotBeNull(); using (var file = new BinaryContent(fileStream, "application/octet-stream")) { completedRequest = await client.UploadTextTrackFileAsync( file, _vimeoSettings.VideoId, new TextTrack { active = false, name = "DeleteTest", language = "en", type = "captions" }); } completedRequest.ShouldNotBeNull(); completedRequest.uri.ShouldNotBeNull(); var uri = completedRequest.uri; var trackId = Convert.ToInt64(uri.Substring(uri.LastIndexOf('/') + 1)); // act await client.DeleteTextTrackAsync(_vimeoSettings.VideoId, trackId); //assert var texttrack = await client.GetTextTrackAsync(_vimeoSettings.VideoId, trackId); texttrack.ShouldBeNull(); }
/// <summary> /// Execute method with test video /// </summary> /// <param name="client">Vimeo client</param> /// <param name="action">Test action with Clip Id</param> /// <returns>The result task</returns> public static async Task WithTempVideo(this IVimeoClient client, Func <long, Task> action) { long?tempVideoId = null; try { using (var file = new BinaryContent(GetFileFromEmbeddedResources(TestFilePath), "video/mp4")) { var length = file.Data.Length; var completedRequest = await client.UploadEntireFileAsync(file); completedRequest.ShouldNotBeNull(); completedRequest.IsVerifiedComplete.ShouldBeTrue(); completedRequest.BytesWritten.ShouldBe(length); completedRequest.ClipUri.ShouldNotBeNull(); completedRequest.ClipId.HasValue.ShouldBeTrue(); completedRequest.ClipId.ShouldNotBeNull(); tempVideoId = completedRequest.ClipId; } await action(tempVideoId.Value); } finally { if (tempVideoId != null) { await client.DeleteVideoAsync(tempVideoId.Value); } } }
public override void LoadDataAsync(LoadCommand cmd, LoadDataAsyncParameters cmdParam, Action <PaneViewModelBase> success = null, Action <PaneViewModelBase, Exception> error = null) { base.LoadDataAsync(cmd, cmdParam, success, error); switch (cmd) { case LoadCommand.Load: WorkHandler.Run( () => { _packageContent = (BinaryContent)cmdParam.Payload; FileManager.LoadPackage(_packageContent); return(true); }, result => { IsLoaded = true; Initialize(); Drive = Drives.First(); if (success != null) { success.Invoke(this); } }, exception => { if (error != null) { error.Invoke(this, exception); } }); break; } }
public override BinaryContent CreateBinaryContent(byte[] data) { BinaryContent content = DataContext.BinaryContentSet.Create(); content.Data = data; return(DataContext.BinaryContentSet.Add(content)); }
public override void LoadDataAsync(LoadCommand cmd, LoadDataAsyncParameters cmdParam, Action <PaneViewModelBase> success = null, Action <PaneViewModelBase, Exception> error = null) { base.LoadDataAsync(cmd, cmdParam, success, error); switch (cmd) { case LoadCommand.Load: WorkHandler.Run( () => { _packageContent = (BinaryContent)cmdParam.Payload; _stfs = ModelFactory.GetModel <StfsPackage>(_packageContent.Content); return(true); }, result => { IsLoaded = true; Tabs.Add(new ProfileRebuilderTabItemViewModel(Resx.FileStructure, ParseStfs(_stfs))); SelectedTab = Tabs.First(); if (success != null) { success.Invoke(this); } }, exception => { if (error != null) { error.Invoke(this, exception); } }); break; } }
protected BinaryContent /*!*/ WrapContent(byte[] /*!*/ bytes) { var result = new BinaryContent(_owner, new List <byte>(bytes)); // TODO: do not copy _owner.SetContent(result); return(result); }
public static IFunctionSettings BuildFunctionSettings(IConfiguration configuration) { var moduleName = Environment.GetEnvironmentVariable("MOD_NAME"); if (string.IsNullOrEmpty(moduleName)) { throw new ArgumentNullException("MOD_NAME"); } var functionHandler = Environment.GetEnvironmentVariable("FUNC_HANDLER"); if (string.IsNullOrEmpty(moduleName)) { throw new ArgumentNullException("FUNC_HANDLER"); } var assemblyPathConfiguration = configuration["Compiler:FunctionAssemblyPath"]; if (string.IsNullOrEmpty(assemblyPathConfiguration)) { throw new ArgumentNullException("Compiler:FunctionAssemblyPath"); } var assemblyPath = string.Concat(assemblyPathConfiguration, "project", ".dll"); var assembly = new BinaryContent(assemblyPath); return(new FunctionSettings(moduleName, functionHandler, assembly)); }
protected BinaryContent /*!*/ WrapContent(byte[] /*!*/ bytes, int count) { BinaryContent result = _owner._encoding.IsKCoding ? new KBinaryContent(bytes, count, _owner) : new BinaryContent(bytes, count, _owner); _owner.SetContent(result); return(result); }
/// <summary> /// 载入binary显示数据 /// </summary> private void loadShowBinaryData() { try { int showLen = dataFile.BinaryData.Count;//configFile.RowSampleRateInformation.EndSampleCount; for (int index = 0; index < showLen; index++) { var binaryOrigin = new BinaryContent(dataFile.BinaryData[index], configFile.RowChannelNumType.AnalogChannelCount, configFile.RowChannelNumType.DigitalChannelCount); var ascii = new ASCIIContent(binaryOrigin); LoadCurvePoint(ascii); } foreach (var m in plotCollect) { m.MplotModel.InvalidatePlot(true); } } catch (Exception ex) { MessageBox.Show(ex.Message, "载入显示数据"); } }
public async Task ShouldCorrectlyUploadFileByPath() { long length; IUploadRequest completedRequest; var tempFilePath = Path.GetTempFileName() + ".mp4"; using (var fs = new FileStream(tempFilePath, FileMode.CreateNew)) { TestHelper.GetFileFromEmbeddedResources(TestHelper.TestFilePath).CopyTo(fs); } using (var file = new BinaryContent(tempFilePath)) { file.ContentType.ShouldBe("video/mp4"); length = file.Data.Length; var client = CreateAuthenticatedClient(); completedRequest = await client.UploadEntireFileAsync(file); completedRequest.ClipId.ShouldNotBeNull(); await client.DeleteVideoAsync(completedRequest.ClipId.Value); } completedRequest.ShouldNotBeNull(); completedRequest.IsVerifiedComplete.ShouldBeTrue(); completedRequest.BytesWritten.ShouldBe(length); completedRequest.ClipUri.ShouldNotBeNull(); completedRequest.ClipId.ShouldNotBeNull(); completedRequest.ClipId?.ShouldBeGreaterThan(0); if (File.Exists(tempFilePath)) { File.Delete(tempFilePath); } }
protected BinaryContent /*!*/ WrapContent(byte[] /*!*/ bytes, int count) { BinaryContent result = new BinaryContent(bytes, count, _owner); _owner.SetContent(result); return(result); }
public async Task ShouldCorretlyUploadFileByByteArray() { long length; IUploadRequest completedRequest; var stream = TestHelper.GetFileFromEmbeddedResources(TestHelper.TestFilePath); var buffer = new byte[stream.Length]; await stream.ReadAsync(buffer, 0, (int)stream.Length); using (var file = new BinaryContent(buffer, "video/mp4")) { length = file.Data.Length; var client = CreateAuthenticatedClient(); completedRequest = await client.UploadEntireFileAsync(file); completedRequest.ClipId.ShouldNotBeNull(); await client.DeleteVideoAsync(completedRequest.ClipId.Value); } completedRequest.ShouldNotBeNull(); completedRequest.IsVerifiedComplete.ShouldBeTrue(); completedRequest.BytesWritten.ShouldBe(length); completedRequest.ClipUri.ShouldNotBeNull(); completedRequest.ClipId.ShouldNotBeNull(); completedRequest.ClipId?.ShouldBeGreaterThan(0); }
public (UploadResult Result, Response Response) Upload(Core.Services.UploadRequest request) { try { var client = new VimeoClient(config.VideoSettings.Token); var ticket = client.GetUploadTicketAsync().Result; IBinaryContent file = new BinaryContent(request.Stream, request.ContentType); var uploadRequest = client.UploadEntireFileAsync(file).Result; var verificationResult = client.VerifyUploadFileAsync(uploadRequest).Result; Task.WaitAll(client.UpdateVideoMetadataAsync(uploadRequest.ClipId.Value, new VideoUpdateMetadata { Description = request.Description, Name = request.Title, Privacy = VideoPrivacyEnum.Password, AllowDownloadVideo = false, Password = config.VideoSettings.Password }) ); var albumResult = client.AddToAlbumAsync(4877366, uploadRequest.ClipId.Value).Result; Task.WaitAll(client.CompleteFileUploadAsync(uploadRequest)); var video = client.GetVideoAsync(uploadRequest.ClipId.Value).Result; string thumbnailUrl = null; if (video?.pictures?.sizes != null && video.pictures.sizes.Count > 0) { thumbnailUrl = video.pictures.sizes[0].link; } return(new UploadResult(uploadRequest.ClipId.ToString(), video.StandardVideoLink, thumbnailUrl), Response.CreateSuccessResponse()); }catch (Exception ex) { return(null, Response.CreateResponse(ex)); } }
public async Task Integration_VimeoClient_UploadEntireFile_UploadsFile_ByArray() { long length; IUploadRequest completedRequest; var stream = GetFileFromEmbeddedResources(Testfilepath); var buffer = new byte[stream.Length]; await stream.ReadAsync(buffer, 0, (int)stream.Length); using (var file = new BinaryContent(buffer, "video/mp4")) { length = file.Data.Length; var client = CreateAuthenticatedClient(); completedRequest = await client.UploadEntireFileAsync(file); Debug.Assert(completedRequest.ClipId != null, "completedRequest.ClipId != null"); await client.DeleteVideoAsync(completedRequest.ClipId.Value); } completedRequest.ShouldNotBeNull(); completedRequest.AllBytesWritten.ShouldBeTrue(); completedRequest.IsVerifiedComplete.ShouldBeTrue(); completedRequest.BytesWritten.ShouldBe(length); completedRequest.ClipUri.ShouldNotBeNull(); completedRequest.ClipId.ShouldNotBeNull(); completedRequest.ClipId?.ShouldBeGreaterThan(0); }
public void RoundTripBinaryData() { byte[] rawData = new byte[1024]; Random random = new Random(); random.NextBytes(rawData); BinaryContent data = new BinaryContent() { Content = rawData, ContentType = "na", }; ContentCore core = new ContentCore(); var returned = core.Store(data); Assert.IsNotNull(returned, "Nothing returned"); Assert.AreNotEqual <Guid>(Guid.Empty, returned.Id, "Identifier not set."); var returnedData = core.Get(returned); Assert.IsNotNull(returnedData); Assert.AreEqual <int>(data.Content.Length, returnedData.Content.Length, "Data is inconsistant."); for (int i = 0; i < data.Content.Length; i++) { if (data.Content[i] != returnedData.Content[i]) { Assert.Fail("Data is inconsistant."); } } }
BinaryContent CreateBinaryContent(DocumentsDb context, string filePath) { BinaryContent content = new BinaryContent(); content.Data = File.ReadAllBytes(filePath); context.BinaryContentSet.Add(content); return(content); }
public async Task ShouldCorrectlyReadPartOfFile() { using (var file = new BinaryContent(TestHelper.GetFileFromEmbeddedResources(TestHelper.TestFilePath), "video/mp4")) { (await file.ReadAsync(17, 20)).Length.ShouldBe(3); (await file.ReadAsync(17000, 17020)).Length.ShouldBe(20); } }
public async Task ShouldCorrectlyDoubleRead() { using (var file = new BinaryContent(TestHelper.GetFileFromEmbeddedResources(TestHelper.TestFilePath), "video/mp4")) { (await file.ReadAllAsync()).Length.ShouldBe(5510872); (await file.ReadAllAsync()).Length.ShouldBe(5510872); } }
public async Task Integration_VimeoClient_UploadEntireFile_UploadsFile_ReadPartOfFile() { using (var file = new BinaryContent(GetFileFromEmbeddedResources(Testfilepath), "video/mp4")) { (await file.ReadAsync(17, 20)).Length.ShouldBe(3); (await file.ReadAsync(17000, 17020)).Length.ShouldBe(20); } }
public async Task Integration_VimeoClient_UploadEntireFile_UploadsFile_DoubleRead() { using (var file = new BinaryContent(GetFileFromEmbeddedResources(Testfilepath), "video/mp4")) { (await file.ReadAllAsync()).Length.ShouldBe(818086); (await file.ReadAllAsync()).Length.ShouldBe(818086); } }
public void Integration_VimeoClient_UploadEntireFile_UploadsFile_InvalidStreams() { var nonReadablefile = new BinaryContent(new NonReadableStream(), "video/mp4"); var nonSeekablefile = new BinaryContent(new NonSeekableStream(), "video/mp4"); Should.ThrowAsync <InvalidOperationException>(async() => await nonReadablefile.ReadAllAsync(), "Content should be a readable Stream"); Should.ThrowAsync <InvalidOperationException>(async() => await nonSeekablefile.ReadAsync(10, 20), "Content cannot be advanced to the specified start index: 10"); }
// content.bytes + this.bytes[start, count] public override void AppendTo(BinaryContent /*!*/ content, int start, int count) { if (start > _count - count) { throw new ArgumentOutOfRangeException("start"); } content.Append(_data, start, count); }
public void Integration_VimeoClient_UploadEntireFile_UploadsFile_DisposedStreamAccess() { var file = new BinaryContent(GetFileFromEmbeddedResources(Testfilepath), "video/mp4"); file.Dispose(); Should.Throw <ObjectDisposedException>(() => file.Dispose()); Should.Throw <ObjectDisposedException>(() => file.Data.Length.ShouldBe(0)); Should.ThrowAsync <ObjectDisposedException>(async() => await file.ReadAllAsync()); }
private static IFunctionSettings BuildFunctionSettings(string functionFile, string moduleName, string functionHandler, string requirementsFile = "") { var basePath = Path.GetDirectoryName(functionFile); var baseName = Path.GetFileNameWithoutExtension(functionFile); var assembly = new BinaryContent(Path.Combine(basePath, $"{baseName}.dll")); return(new FunctionSettings(moduleName, functionHandler, assembly)); }
public void ShouldFireExceptionWhenDisposedStreamAccess() { var file = new BinaryContent(TestHelper.GetFileFromEmbeddedResources(TestHelper.TestFilePath), "video/mp4"); file.Dispose(); Should.Throw <ObjectDisposedException>(() => file.Dispose()); Should.Throw <ObjectDisposedException>(() => file.Data.Length.ShouldBe(0)); Should.ThrowAsync <ObjectDisposedException>(async() => await file.ReadAllAsync()); }
public void Content() { var random = new Random(); var content = new BinaryContent(); var data = new byte[1024]; random.NextBytes(data); content.Content = data; Assert.AreEqual <byte[]>(data, content.Content); }
// binary + string -> binary public override Content/*!*/ ConcatTo(BinaryContent/*!*/ content) { return content.Concatenate(this); }
// content.bytes <=> this.bytes public override int ReverseOrdinalCompareTo(BinaryContent/*!*/ content) { return content.OrdinalCompareTo(_data, _count); }
// binary + binary(self) -> binary public override Content/*!*/ ConcatTo(BinaryContent/*!*/ content) { return Create(Utils.Concatenate(content._data, content._count, _data, _count), null); }
/// <summary> /// Loads the content of the Log from binary serialized entries. /// </summary> /// <param name="binaryContent">The entries serialized in binary format.</param> public void LoadBinary(BinaryContent binaryContent) { if (binaryContent == null) { throw new ArgumentNullException("binaryContent"); } GenericBinaryFormatter formatter = new GenericBinaryFormatter(); using (MemoryStream stream = new MemoryStream(binaryContent)) { while (stream.Position < binaryContent.Size) { var logEntries = formatter.Deserialize<LogEntries>(stream); Entries.AddRange(logEntries); } } }
public abstract int ReverseOrdinalCompareTo(BinaryContent/*!*/ content);
public abstract void AppendTo(BinaryContent/*!*/ content, int start, int count);
public abstract Content/*!*/ ConcatTo(BinaryContent/*!*/ content);
protected BinaryContent/*!*/ WrapContent(byte[]/*!*/ bytes) { var result = new BinaryContent(_owner, new List<byte>(bytes)); // TODO: do not copy _owner.SetContent(result); return result; }
// content.bytes <=> this.chars public override int ReverseOrdinalCompareTo(BinaryContent/*!*/ content) { return SwitchToBinary().ReverseOrdinalCompareTo(content); }
// content.bytes + this.chars[start, count] public override void AppendTo(BinaryContent/*!*/ content, int start, int count) { if (start > _count - count) { throw new ArgumentOutOfRangeException("start"); } content.AppendBytes(_data, start, count); }
/// <summary> /// Initializes a new Logger with the specified log entries. /// </summary> /// <param name="logEntries">The serialized entries to initialize the logger.</param> public Log(BinaryContent logEntries) : this() { if (logEntries == null) throw new ArgumentNullException("logEntries"); LoadBinary(logEntries); }
protected BinaryContent/*!*/ WrapContent(byte[]/*!*/ bytes, int count) { var result = new BinaryContent(bytes, count, _owner); _owner.SetContent(result); return result; }
// content.bytes + this.chars[start, count] public override void AppendTo(BinaryContent/*!*/ content, int start, int count) { content.AppendBytes(_data, start, count); }
public void AddToBinaryContents(BinaryContent binaryContent) { base.AddObject("BinaryContents", binaryContent); }
public static BinaryContent CreateBinaryContent(int binaryId, string variantId, int publicationId) { BinaryContent binaryContent = new BinaryContent(); binaryContent.BinaryId = binaryId; binaryContent.VariantId = variantId; binaryContent.PublicationId = publicationId; return binaryContent; }