Last active
November 9, 2016 04:49
-
-
Save smarenich/88e97364efba1f1cbb0aaaef7d577ec4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ProxyScreen : Screen | |
{ | |
private readonly string _Login; | |
private readonly string _Pass; | |
private DateTime _LastOperation; | |
private Content _LastSchema; | |
public ProxyScreen(string url, string login, string pass) | |
{ | |
_Login = login; | |
_Pass = pass; | |
this.Url = url; | |
this.CookieContainer = new System.Net.CookieContainer(); | |
} | |
static ProxyScreen() | |
{ | |
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(ValidateRemoteCertificate); | |
} | |
public LoginResult Login() | |
{ | |
LoginResult lr = base.Login(_Login, _Pass); | |
if (lr.Code != ErrorCode.OK) | |
throw new Exception("Error during establishing connection to the remote site. Please check your credentials."); | |
_LastOperation = DateTime.Now; | |
return lr; | |
} | |
public new Content GetSchema() | |
{ | |
if (EnsureLogin() || _LastSchema == null) | |
{ | |
_LastSchema = base.GetSchema(); | |
} | |
return _LastSchema; | |
} | |
public new Content[] Submit(Command[] commands) | |
{ | |
EnsureLogin(); | |
Content[] graph = base.Submit(commands); | |
_LastOperation = DateTime.Now; | |
return graph; | |
} | |
private bool EnsureLogin() | |
{ | |
if (_LastOperation == null || (((TimeSpan)(DateTime.Now - _LastOperation)).TotalMinutes > 10)) | |
{ | |
Login(); | |
return true; | |
} | |
return false; | |
} | |
//Callback, which is used to validate the certificate of an Acumatica ERP website in an SSL conversation | |
private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors policyErrors) | |
{ | |
//For simplicity, this callback always returns true | |
//In a real integration application, you must check an SSL certificate here | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Program | |
{ | |
private static ProxyScreen context = new ProxyScreen("https://acusea.acumatica.com/Soap/AP301000.asmx", "admin@Demo", "123"); | |
static void Main(string[] args) | |
{ | |
Content invoiceSchema = context.GetSchema(); | |
var commands = new Command[] | |
{ | |
new Value { Value = "AAVENDOR", LinkedCommand = invoiceSchema.DocumentSummary.Vendor }, | |
new Value { Value = "123", LinkedCommand = invoiceSchema.DocumentSummary.VendorRef }, | |
new Value { Value = "Demo AP Invoice", LinkedCommand = invoiceSchema.DocumentSummary.Description, Commit = true }, | |
invoiceSchema.DocumentDetails.ServiceCommands.NewRow, | |
new Value { Value = "AACOMPUT01", LinkedCommand = invoiceSchema.DocumentDetails.InventoryID }, | |
new Value { Value = "2.0", LinkedCommand = invoiceSchema.DocumentDetails.Quantity, Commit = true }, | |
invoiceSchema.DocumentDetails.ServiceCommands.NewRow, | |
new Value { Value = "AALEGO500", LinkedCommand = invoiceSchema.DocumentDetails.InventoryID }, | |
new Value { Value = "1.0", LinkedCommand = invoiceSchema.DocumentDetails.Quantity, Commit = true }, | |
invoiceSchema.Actions.Save, | |
invoiceSchema.DocumentSummary.ReferenceNbr, | |
invoiceSchema.DocumentSummary.Status | |
}; | |
var invoice = context.Submit(commands)[0]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment