How can I send files / pictures to Report Portal with .net client? - reportportal

I'd like to send a binary attachment to Report Portal with .net client. How can I do it?

Example is in Tests project.
https://github.com/reportportal/client-net/blob/master/ReportPortal.Client.Tests/LogItem/LogItem.cs
Find CreateLogWithAttach test and see code.
var data = new byte[] { 1, 2, 3 };
var log = Service.AddLogItem(new AddLogItemRequest
{
TestItemId = _testId,
Text = "Log1",
Time = DateTime.UtcNow,
Level = LogLevel.Info,
Attach = new Attach("file1", "application/octet-stream", data)
});
Related documentation: Log Data in ReportPortal

Related

NLog configuration from both code and config file

I have NLog code currently reading from NLog.config to set up logging to text files and then I'd like to add logging fatal errors to email. However, the email settings are in my appsettings.json file.
What I tried so far is this in my Startup.cs
var emailConfig = Configuration
.GetSection("EmailConfiguration")
.Get<EmailConfiguration>();
services.AddSingleton(emailConfig);
var mailTarget = new MailTarget()
{
SmtpServer = emailConfig.SmtpServer,
SmtpUserName = emailConfig.UserName,
SmtpPort = emailConfig.Port,
SmtpPassword = services.BuildServiceProvider().CreateScope().ServiceProvider.GetService<IEmailSender>().Decrypt(emailConfig.Password),
To = emailConfig.To
};
NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(mailTarget, LogLevel.Fatal);
However I have 2 problems when I try to _logger.Fatal("testing, please ignore");:
Under _logger.Factory.Configuration.AllTargets I now only see the mail settings I configured above, which I understand is due to SimpleConfigurator overwriting (yet I'm not sure what I need to do so that I add rather than overwrite).
I still didn't receive an email despite and I'm not sure how I can debug this now.
I fixed both issues.
var mailTarget = new MailTarget()
{
SmtpServer = emailConfig.SmtpServer,
SmtpUserName = emailConfig.UserName,
SmtpPort = emailConfig.Port,
SmtpPassword = services.BuildServiceProvider().CreateScope().ServiceProvider.GetService<IEmailSender>().Decrypt(emailConfig.Password),
From = emailConfig.UserName,
To = emailConfig.To,
EnableSsl = true,
SmtpAuthentication = SmtpAuthenticationMode.Basic,
Html = true
};
var configuration = LogManager.Configuration;
configuration.AddRuleForOneLevel(LogLevel.Fatal, mailTarget);
LogManager.ReconfigExistingLoggers();
The first problem related to the last 3 lines, whereas the second issue was related to the SMTP configuration.

Download Proof of Delivery as PDF in UPS API

UPS provided DeveloperKit to find delivery status. Below is an example for .Net:
TrackService track = new TrackService();
TrackRequest tr = new TrackRequest();
UPSSecurity upss = new UPSSecurity();
UPSSecurityServiceAccessToken upssSvcAccessToken = new UPSSecurityServiceAccessToken();
upssSvcAccessToken.AccessLicenseNumber = "Your access license number";
upss.ServiceAccessToken = upssSvcAccessToken;
UPSSecurityUsernameToken upssUsrNameToken = new UPSSecurityUsernameToken();
upssUsrNameToken.Username = "Your username";
upssUsrNameToken.Password = "Your password";
upss.UsernameToken = upssUsrNameToken;
track.UPSSecurityValue = upss;
RequestType request = new RequestType();
String[] requestOption = { "15" };
request.RequestOption = requestOption;
tr.Request = request;
tr.InquiryNumber = "Your track inquiry number";
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls | System.Net.SecurityProtocolType.Tls11; //This line will ensure the latest security protocol for consuming the web service call.
TrackResponse trackResponse = track.ProcessTrack(tr);
//ResponseType loResponse = trackResponse.Response;
Console.WriteLine("The transaction was a " + trackResponse.Response.ResponseStatus.Description);
Console.WriteLine("Shipment Service " + trackResponse.Shipment[0].Service.Description);
Console.ReadKey();
This code works fine, and returns shipment details as text. I need to download Proof of Delivery (POD) as PDF.
The manual shows that loading such PDF is possible via object /TrackResponse/Shipment/Document/Content.
However, the object Document is not available under trackResponse.Shipment. Response option 15 used in the request means that Signature Tracking only is ON.
Any ideas how to get the Proof of Delivery as a PDF file?
UPS sends Proof of Delivery (POD) in HTML format only. Conversion to PDF needs to be done by the developer.
HTML code comes in:
trackResponse.Shipment[0].Package[0].Activity[0].Document[0].Content
That value needs to be decoded:
byte[] data = Convert.FromBase64String(trackResponse.Shipment[0].Package[0].Activity[0].Document[0].Content);
string decodedString = Encoding.UTF8.GetString(data);
Then decoded string needs to be converted to PDF. I used a third-party library, available through NuGet.

Can i send data from one website’s console to another?

So im trying to automate a task at work, and im wondering if theres anyway to send data from the console of one webpage to the console of another web page.
The task i am trying to automate consists of a website that has a prefilled form. I need to get elements from this form, and then copy them into another totally different website. Ive already written a script that pulls the data i need from the form and displays it in the console. Now I need to find a way to send the data (which is simply variables) to the other page’s console. Is this possible?
Keep in mind this is in a work computer, not allowed to download anything on it.
Are you an admin of the webpages and are these pages from the same site? if the answer is yes, i would recommend you use localStorage for saving and retrieving the data then display it to the console.
If it's not your website and you want it to work anyway just create a simple browser extension.
Here are some links to help you get started with extensions
MDN doc
Chrome doc
The idea is for you to target webpage A collect the data and post it to Github
Then target webpage B to read data from your github gist and you dispaly it in the console.
Cheers, i hope it was helpfull
Which server side language are you using ?
Usually for these, you could just have a form which is posting data to another website's form.
Look at this php example :
https://www.ostraining.com/blog/coding/retrieve-html-form-data-with-php/
Correct me If I did not understand your question correctly.
//Store the logs in following way
console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function(){
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
}
//copying the logs into a json file
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
}
var blob = new Blob([data], {type: 'text/json'}),
e = document.createEvent('MouseEvents'),
a = document.createElement('a')
a.download = filename
a.href = window.URL.createObjectURL(blob)
a.dataset.downloadurl = ['text/json', a.download, a.href].join(':')
e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
a.dispatchEvent(e)
}
})(console)
console.save(console.logs) //prints the logs in console.json file
// from the console.json file, you can use log information from another page
//Store the logs in following way
console.stdlog = console.log.bind(console);
console.logs = [];
console.log = function(){
console.logs.push(Array.from(arguments));
console.stdlog.apply(console, arguments);
}
localStorage.setItem('Logs', console.logs);
localStorage.getItem('Logs'); // from any browser

Extension/File type of uploaded Word Document

I am trying to upload a Word Document to my personal box account using Box Windows SDK V2 using the following code.
using (Stream s = new FileStream("C:\\word.docx",
FileMode.Open, FileAccess.Read,
FileShare.ReadWrite))
{
MemoryStream memStream = new MemoryStream();
memStream.SetLength(s.Length);
s.Read(memStream.GetBuffer(), 0, (int)s.Length);
BoxFileRequest request = new BoxFileRequest()
{
Parent = new BoxRequestEntity() { Id = "0" },
Name = TxtSaveAS.Text
};
BoxFile f = await Client.FilesManager.UploadAsync(request, memStream)
The document gets uploaded successfully in root folder but the problem is, the extension of document is set to "File" (which is not previewed by Box because of having unsupported extension, neither it gets the icon of word document) rather than "docx" though it still gets open correctly in Microsoft word.
How to upload file using box windows sdk with respective extensions.
suggestions are greatly welcomed.
In order to upload the file with the correct extension, simply append the extension to the Name.
BoxFileRequest request = new BoxFileRequest()
{
Parent = new BoxRequestEntity() { Id = "0" },
Name = TxtSaveAS.Text + ".docx"
};

Gererating report ondemand to a directory

Normally people need to view report on report viewer.
But I need to just generate report in a directory.
What should i do for this?
You can use the SSRS built-in subscriptions to write to a directory/fileshare. With Enterprise edition, you could use data-driven subscriptions to write the report out only when needed by some other criteria.
But to truly make this on demand, then you'll need to do a little bit of coding. The simplest method is just to retrieve the filestream from a request created using URL Access and write that to a file.
Just throwing together a sample that will give the general idea:
string sTargetURL = System.Configuration.ConfigurationManager.AppSettings["ReportingServicesURL"]
+ "/ProductReports/ProductDetails&rs:Command=Render&rs:format=PDF&ProductID=" + ProductID;
HttpWebRequest req =
(HttpWebRequest)WebRequest.Create( sTargetURL );
req.PreAuthenticate = true;
// req.Credentials = new System.Net.NetworkCredential( strReportUser, strReportUserPW, strReportUserDomain );
HttpWebResponse HttpWResp = (HttpWebResponse)req.GetResponse();
using (var fileStream = File.Create("C:\\Path\\To\\File"))
{
HttpWResp.GetResponseStream().CopyTo(fileStream);
}
HttpWResp.Close();