Skip to content

Commit

Permalink
updated to latest and allow for TLS 1.2
Browse files Browse the repository at this point in the history
Latest
  • Loading branch information
jmoncada committed Oct 19, 2016
1 parent f9c37b5 commit 252823c
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 3 deletions.
6 changes: 5 additions & 1 deletion Classes/Address.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public string telephone
get;
set;
}

public string email
{
get;
set;
}
public string shipping
{
get;
Expand Down
10 changes: 10 additions & 0 deletions Classes/Document.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,15 @@ public int Quantity
get;
set;
}
public string pdfPath
{
get;
set;
}
public string pdfTemplate
{
get;
set;
}
}
}
9 changes: 9 additions & 0 deletions MimeoRestLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Dev|AnyCPU'">
<OutputPath>bin\Dev\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Prod|AnyCPU'">
<OutputPath>bin\Prod\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'QA|AnyCPU'">
<OutputPath>bin\QA\</OutputPath>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
41 changes: 39 additions & 2 deletions RestApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ public static RestApi GetInstance

#region Public Interface
public void Initialize(string user, string password)
{
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
this.Initialize(user, password, true);
}
public void Initialize(string user, string password, bool sandbox)
{
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
string inServer = (sandbox) ? serverSandbox : serverProduction;
this.Initialize(user, password, inServer);
}
public void Initialize(string user, string password, string serverEndPoint)
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
var userName_password = user + ":" + password;
byte[] encDataByte = System.Text.Encoding.UTF8.GetBytes(userName_password);
Expand Down Expand Up @@ -425,6 +428,39 @@ public XDocument createDocument(string newDocName, string newDocFolder, string f
}


public XDocument createNewDocument(string newDocName, string newDocFolder, string fileId, string templateId, string pages)
{

// Get Print File Information
var fileXML = GetStoreItem(fileId);
string printFileId = (from file in fileXML.Descendants(nsESLStorage + "StoreItem")
select file.Element(nsESLStorage + "Id").Value).FirstOrDefault();
string pageCount = (from file in fileXML.Descendants(nsESLStorage + "ItemDetails")
select file.Element(nsESLStorage + "PageCount").Value).FirstOrDefault();

// Get Document Information
string docFolderName = newDocFolder;

var documentXML = GetNewDocument(templateId);

var docName = documentXML.Descendants(nsOrder + "Name").FirstOrDefault();
docName.Value = newDocName;

XmlDocument inXml = new XmlDocument();
inXml.LoadXml(documentXML.ToString());
PopulateProductSections(inXml, printFileId, pages, "1");

// Create Document
string createDocument = string.Format("/Document/{0}", newDocFolder);
Uri storageEndpoint = new Uri(server + storageService + createDocument);
XmlDocument newDoc = HttpWebPost(inXml, storageEndpoint, "POST");

documentXML = XDocument.Parse(newDoc.OuterXml);
return documentXML;

}


public void PopulateProductSection(XmlDocument orderRequest, string printFileId, string pageCount, string copies)
{
var qty = orderRequest.GetElementsByTagName("Quantity")[0];
Expand Down Expand Up @@ -534,6 +570,7 @@ public XmlDocument HttpWebPost(XmlDocument doc, Uri ordersEndpoint, string actio
var webrequest = (HttpWebRequest)WebRequest.Create(ordersEndpoint);
webrequest.Headers.Add(HttpRequestHeader.Authorization, authorizationData);
webrequest.Method = action;
webrequest.ProtocolVersion = HttpVersion.Version11;
// Set the ContentType property of the WebRequest.
webrequest.ContentType = "application/xml";

Expand Down

0 comments on commit 252823c

Please sign in to comment.