-
Notifications
You must be signed in to change notification settings - Fork 42
/
Copy pathDownloadReport.cs
67 lines (58 loc) · 2.45 KB
/
DownloadReport.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Xml;
using System.Xml.Serialization;
using CyberSource.Api;
using CyberSource.Model;
namespace Cybersource_rest_samples_dotnet.Samples.Reporting
{
public class DownloadReport
{
public static void Run()
{
const string fileName = "DownloadedReport.csv";
const string downloadFilePath = @".\Resource\" + fileName;
string organizationId = "testrest";
var reportDate = DateTime.ParseExact("2018-09-30", "yyyy-MM-dd", CultureInfo.InvariantCulture);
string reportName = "testrest_subcription_v2989";
try
{
var configDictionary = new Configuration().GetConfiguration();
var clientConfig = new CyberSource.Client.Configuration(merchConfigDictObj: configDictionary);
var apiInstance = new ReportDownloadsApi(clientConfig);
var content = apiInstance.DownloadReportWithHttpInfo(reportDate, reportName, organizationId);
// START : FILE DOWNLOAD FUNCTIONALITY
File.WriteAllText(downloadFilePath, CreateXml(content.Data));
Console.WriteLine("\nFile Downloaded at the following location : ");
Console.WriteLine($"{Path.GetFullPath(downloadFilePath)}\n");
// END : FILE DOWNLOAD FUNCTIONALITY
}
catch (FileNotFoundException)
{
Console.WriteLine("File Not Found : Kindly verify the path.");
}
catch (Exception e)
{
Console.WriteLine("Exception on calling the API : " + e.Message);
}
}
// START : STREAM SERIALIZER METHOD
private static string CreateXml(object obj)
{
var xmlDoc = new XmlDocument(); // Represents an XML Document
var xmlSerializer = new XmlSerializer(obj.GetType()); // Initializes a new instance of the XmlDocument class
// Creates a stream whose backing store is memory
using (var xmlStream = new MemoryStream())
{
xmlSerializer.Serialize(xmlStream, obj);
xmlStream.Position = 0;
// Loads the XML document from the specified string
xmlDoc.Load(xmlStream);
return xmlDoc.InnerText;
}
}
// END : STREAM SERIALIZER METHOD
}
}