-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathForceConnection.cs
More file actions
56 lines (49 loc) · 1.61 KB
/
ForceConnection.cs
File metadata and controls
56 lines (49 loc) · 1.61 KB
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EmTrac2SF.EMSC2SF;
namespace EmTrac2SF.Salesforce
{
public class ForceConnection
{
public string SessionID { get; set; }
public string ServerUrl { get; set; }
public bool ConnectionFailed = false;
public string ErrorMessage = "";
public ForceConnection(string connectionString)
{
ForceConnectionStringBuilder connectionBuilder =
new ForceConnectionStringBuilder(connectionString);
if( Login( connectionBuilder.Username, connectionBuilder.Password, connectionBuilder.Token ) )
return;
else
ConnectionFailed = true;
}
public ForceConnection(string username, string password, string securityToken)
{
ErrorMessage = "";
ConnectionFailed = false;
Login(username, password, securityToken);
}
private bool Login(string username, string password, string securityToken)
{
try
{
using (SforceService service = new SforceService())
{
LoginResult loginResult =
service.login(username, String.Concat(password, securityToken));
this.SessionID = loginResult.sessionId;
this.ServerUrl = loginResult.serverUrl;
}
return true;
}
catch (Exception excpt)
{
ErrorMessage = excpt.Message;
return false;
}
}
}
}