private static async Task <int> GetRelyingPartyDocumentAsync(GetRelyingPartyDocumentOptions options) { Console.WriteLine("Obtaining relying party document."); Console.WriteLine(); DocumentsResponse response = await ConfigurationManager.GetRelyingPartyDocumentAsync(options.AccountId, options.Filename); ConfigFileStream document = response.Documents.First(); using (Stream stream = document.Stream) { if (string.IsNullOrEmpty(options.Destination)) { using (StreamReader sr = new StreamReader(stream)) { Console.WriteLine(sr.ReadToEnd()); } } else { EnsureDirectory(options.Destination); string path = Path.Combine(options.Destination, document.Name); using (StreamWriter sw = File.CreateText(path)) { await stream.CopyToAsync(sw.BaseStream); } Console.WriteLine($"Document saved as {path}"); } } return(0); }
/// <inheritdoc /> protected override void Process() { this.WriteVerbose("Obtaining relying party document."); DocumentsResponse response = ConfigurationManager.GetRelyingPartyDocumentAsync(this.AccountId, this.Filename).Result; ConfigFileStream document = response.Documents.First(); using (Stream stream = document.Stream) { if (string.IsNullOrEmpty(this.Destination)) { using (StreamReader sr = new StreamReader(stream)) { this.WriteObject(sr.ReadToEnd()); } } else { this.EnsureDirectory(this.Destination); string path = Path.Combine(this.Destination, document.Name); using (StreamWriter sw = File.CreateText(path)) { stream.CopyTo(sw.BaseStream); } this.WriteVerbose($"Document saved as {path}"); } } }
private static async Task <int> GetDocumentsAsync(GetDocumentsOptions options) { if (options.DocumentType == DocumentType.Sandbox && string.IsNullOrEmpty(options.Sandbox)) { throw new ArgumentException("Sandbox must be specified when obtaining sandbox documents."); } if (options.DocumentType == DocumentType.Sandbox && options.Scid == Guid.Empty) { throw new ArgumentException("SCID must be specified when obtaining sandbox documents."); } if (options.DocumentType == DocumentType.Account) { options.Sandbox = null; } EnsureDirectory(options.Destination); Task <DocumentsResponse> documentsTask; if (options.DocumentType == DocumentType.Sandbox) { Console.WriteLine("Obtaining sandbox documents."); documentsTask = ConfigurationManager.GetSandboxDocumentsAsync(options.Scid, options.Sandbox); } else { Console.WriteLine("Obtaining account documents."); documentsTask = ConfigurationManager.GetAccountDocumentsAsync(options.AccountId); } using (DocumentsResponse documents = await documentsTask) { Console.WriteLine($"ETag: {documents.ETag}"); Console.WriteLine($"Version: {documents.Version}"); Console.WriteLine("Files: "); foreach (ConfigFileStream file in documents.Documents) { string path = Path.Combine(options.Destination, file.Name); using (FileStream fileStream = File.Create(path)) { await file.Stream.CopyToAsync(fileStream); } Console.WriteLine($" - {file.Name}"); } SaveETag(documents.ETag, options.Destination, options.Sandbox); Console.WriteLine($"Saved {documents.Documents.Count()} files to {options.Destination}."); } return(0); }
public Task Consume(ConsumeContext <Document> context) { //vratiti var docs = _db.SearchFor(doc => doc.Type == context.Message.Type); DocumentsResponse response = new DocumentsResponse { Documents = docs.ToList() }; context.Respond(response); return(Task.CompletedTask); }
//public void SendDocument(Document doc) //{ // _bus.SendDocument(doc); //} public List <DocumentDTO> RequestDocument() { List <DocumentDTO> result = new List <DocumentDTO>(); List <Document> req = Activity.InputDocuments.Where(x => x.InputOperation == InputOperations.Request).ToList(); foreach (Document d in req) { // posalji request i stavi rezultat u operation DocumentsResponse response = _bus.SendRequest(d); if (response != null) { result.AddRange(Mapper.Map <List <DocumentDTO> >(response.Documents)); // dodaj u bazu // čisto da postoji kopija i evidencija o pročitanim dokumentima Test.dokumenta.AddRange(response.Documents); } } return(result); }
/// <inheritdoc /> protected override void Process() { if (!Enum.TryParse <DocumentType>(this.DocumentType, out DocumentType documentType)) { throw new ArgumentException("Invalid DocumentType. Must be either 'Sandbox' or 'Account'.", nameof(this.DocumentType)); } if (!Enum.TryParse(this.View, out View view)) { throw new ArgumentException("Invalid View. Must be either 'Working' or 'Published'.", nameof(this.View)); } if (documentType == Microsoft.Xbox.Services.DevTools.XblConfig.DocumentType.Sandbox && string.IsNullOrEmpty(this.Sandbox)) { throw new ArgumentException("Sandbox must be specified when obtaining sandbox documents."); } if (documentType == Microsoft.Xbox.Services.DevTools.XblConfig.DocumentType.Sandbox && this.Scid == Guid.Empty) { throw new ArgumentException("SCID must be specified when obtaining sandbox documents."); } if (documentType == Microsoft.Xbox.Services.DevTools.XblConfig.DocumentType.Account) { this.Sandbox = null; } this.EnsureDirectory(this.Destination); Task <DocumentsResponse> documentsTask; if (documentType == Microsoft.Xbox.Services.DevTools.XblConfig.DocumentType.Sandbox) { this.WriteVerbose("Obtaining sandbox documents."); documentsTask = ConfigurationManager.GetSandboxDocumentsAsync(this.Scid, this.Sandbox); } else { this.WriteVerbose("Obtaining account documents."); documentsTask = ConfigurationManager.GetAccountDocumentsAsync(this.AccountId); } using (DocumentsResponse documents = documentsTask.Result) { this.WriteVerbose($"ETag: {documents.ETag}"); this.WriteVerbose($"Version: {documents.Version}"); this.WriteVerbose("Files: "); foreach (ConfigFileStream file in documents.Documents) { string path = Path.Combine(this.Destination, file.Name); using (FileStream fileStream = File.Create(path)) { file.Stream.CopyTo(fileStream); } this.WriteVerbose($" - {file.Name}"); } this.SaveETag(documents.ETag, this.Destination, this.Sandbox); this.WriteVerbose($"Saved {documents.Documents.Count()} files to {this.Destination}."); } }
public void List_Documents() { // ARRANGE var response1 = new DocumentsResponse() { PaginatedDocuments = new DocumentInfoResponse() { PageIndex = 1, TotalPageCount = 2, Documents = new List <DocumentInfo>() { new DocumentInfo() { Name = "firstdoc", Id = 1, Languages = new List <TranslatorLanguage>() { new TranslatorLanguage() { DisplayName = "Test", LanguageCode = "ab", Id = 255 } } }, new DocumentInfo() { Name = "seconddoc", Id = 2, Languages = new List <TranslatorLanguage>() { new TranslatorLanguage() { DisplayName = "Test", LanguageCode = "cd", Id = 255 } } } } } }; var response2 = new DocumentsResponse() { PaginatedDocuments = new DocumentInfoResponse() { PageIndex = 2, TotalPageCount = 2, Documents = new List <DocumentInfo>() { new DocumentInfo() { Name = "thirddoc", Id = 3, Languages = new List <TranslatorLanguage>() { new TranslatorLanguage() { DisplayName = "Test", LanguageCode = "ef", Id = 255 } } }, new DocumentInfo() { Name = "fourthdoc", Id = 4, Languages = new List <TranslatorLanguage>() { new TranslatorLanguage() { DisplayName = "Test", LanguageCode = "gh", Id = 255 } } } } } }; var mock = new Mock <IMicrosoftCustomTranslatorAPIPreview10>(); mock .Setup( m => m.GetDocumentsWithHttpMessagesAsync(string.Empty, 1, It.IsAny <string>(), null, null, null, null, null, CancellationToken.None) ) .ReturnsAsync( new HttpOperationResponse <DocumentsResponse>() { Body = response1 } ); mock .Setup( m => m.GetDocumentsWithHttpMessagesAsync(string.Empty, 2, It.IsAny <string>(), null, null, null, null, null, CancellationToken.None) ) .ReturnsAsync( new HttpOperationResponse <DocumentsResponse>() { Body = response2 } ); var app = InitApp(mock.Object); // ACT var args = CommandIntoArgs($"document list -ws 00000000-0000-0000-0000-000000000000"); app.Execute(args); // ASSESS string expectedResult = @"Getting documents... 1 ab firstdoc 2 cd seconddoc 3 ef thirddoc 4 gh fourthdoc "; Assert.Equal(expectedResult, ((MockTestWriter)app.Out).ReadAsString()); }