public static void RunSingleThreadWithMultiUser() { Logger logger = Logger.GetInstance(Logger.Levels.ALL, "/Users/Documents/GitLab/csharp_sdk_log.log"); DataCenter.Environment env = USDataCenter.PRODUCTION; UserSignature user1 = new UserSignature("*****@*****.**"); TokenStore tokenstore = new FileStore("/Users/Documents/GitLab/csharp_sdk_token.txt"); Token token1 = new OAuthToken("1000.xxxxxx", "xxxxxx", "1000.xxxxxx.xxxxxx", TokenType.REFRESH, "https://www.zoho.com"); string resourcePath = "/Users/Documents/GitLab/SampleApp/zohocrm-csharp-sdk-sample-application"; DataCenter.Environment environment = USDataCenter.PRODUCTION; UserSignature user2 = new UserSignature("*****@*****.**"); Token token2 = new OAuthToken("1000.xxxxxx", "xxxxxx", "1000.xxxxxx.xxxxxx", TokenType.REFRESH); SDKConfig config = new SDKConfig.Builder().SetAutoRefreshFields(true).Build(); SDKInitializer.Initialize(user1, env, token1, tokenstore, config, resourcePath, logger); new SingleThread().GetRecords("Leads"); SDKInitializer.SwitchUser(user2, environment, token2, config); new SingleThread().GetRecords("Quotes"); }
/// <summary> /// The method to switch the different user in SDK environment. /// </summary> /// <param name="user">A User class instance represents the CRM user.</param> /// <param name="environment">A Environment class instance containing the CRM API base URL and Accounts URL.</param> /// <param name="token">A Token class instance containing the OAuth client application information.</param> /// <param name="sdkConfig">A SDKConfig class instance containing the configuration.</param> public static void SwitchUser(UserSignature user, Dc.DataCenter.Environment environment, Token token, SDKConfig sdkConfig) { Initializer.SwitchUser(user, environment, token, sdkConfig, null); }
public void GetRecords() { try { SDKConfig config = new SDKConfig.Builder().SetAutoRefreshFields(true).Build(); SDKInitializer.SwitchUser(this.user, this.environment, this.token, config); Console.WriteLine("Fetching Cr's for user - " + SDKInitializer.GetInitializer().User.Email); RecordOperations recordOperation = new RecordOperations(); APIResponse <ResponseHandler> response = recordOperation.GetRecords(this.moduleAPIName, null, null); if (response != null) { //Get the status code from response Console.WriteLine("Status Code: " + response.StatusCode); if (new List <int>() { 204, 304 }.Contains(response.StatusCode)) { Console.WriteLine(response.StatusCode == 204 ? "No Content" : "Not Modified"); return; } //Check if expected response is received if (response.IsExpected) { //Get object from response ResponseHandler responseHandler = response.Object; if (responseHandler is ResponseWrapper) { //Get the received ResponseWrapper instance ResponseWrapper responseWrapper = (ResponseWrapper)responseHandler; //Get the list of obtained Record instances List <API.Record.Record> records = responseWrapper.Data; foreach (API.Record.Record record in records) { Console.WriteLine(JsonConvert.SerializeObject(record)); } } //Check if the request returned an exception else if (responseHandler is APIException) { //Get the received APIException instance APIException exception = (APIException)responseHandler; //Get the Status Console.WriteLine("Status: " + exception.Status.Value); //Get the Code Console.WriteLine("Code: " + exception.Code.Value); Console.WriteLine("Details: "); //Get the details map foreach (KeyValuePair <string, object> entry in exception.Details) { //Get each value in the map Console.WriteLine(entry.Key + ": " + JsonConvert.SerializeObject(entry.Value)); } //Get the Message Console.WriteLine("Message: " + exception.Message.Value); } } } } catch (System.Exception ex) { Console.WriteLine(JsonConvert.SerializeObject(ex)); } }
public void SwitchUser() { Utility.AssertNotNull(Initializer.initializer, Constants.SDK_UNINITIALIZATION_ERROR, Constants.SDK_UNINITIALIZATION_MESSAGE); Initializer.SwitchUser(this.user, this.environment, this.token, this.sdkConfig, this.requestProxy); }