Exemplo n.º 1
0
        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");
        }
Exemplo n.º 2
0
        public static void RunMultiThreadWithSingleUser()
        {
            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 DBStore(null, null, null, null, null);

            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";

            SDKConfig config = new SDKConfig.Builder().SetAutoRefreshFields(true).Build();

            SDKInitializer.Initialize(user1, env, token1, tokenstore, config, resourcePath, logger);

            MultiThread multiThread1 = new MultiThread();

            Thread thread1 = new Thread(() => multiThread1.GetRecords("Quotes"));

            thread1.Start();

            Thread thread2 = new Thread(() => multiThread1.GetContactRoles());

            thread2.Start();

            thread1.Join();

            thread2.Join();
        }
Exemplo n.º 3
0
        public void GetRecords(string moduleAPIName)
        {
            try
            {
                Console.WriteLine("Fetching Cr's for user - " + SDKInitializer.GetInitializer().User.Email);

                RecordOperations recordOperation = new RecordOperations();

                APIResponse <ResponseHandler> response = recordOperation.GetRecords(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));
            }
        }
Exemplo n.º 4
0
            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);
            }
Exemplo n.º 5
0
        public static void SDKInitialize()
        {
            /*
             * Create an instance of Logger Class that takes two parameters
             * 1 -> Level of the log messages to be logged. Can be configured by typing Levels "." and choose any level from the list displayed.
             * 2 -> Absolute file path, where messages need to be logged.
             */
            Logger logger = Logger.GetInstance(Logger.Levels.ALL, "/Users/Documents/GitLab/csharp_sdk_log.log");

            //Create an UserSignature instance that takes user Email as parameter
            UserSignature user = new UserSignature("*****@*****.**");

            /*
             * Configure the environment
             * which is of the pattern Domain.Environment
             * Available Domains: USDataCenter, EUDataCenter, INDataCenter, CNDataCenter, AUDataCenter
             * Available Environments: PRODUCTION, DEVELOPER, SANDBOX
             */
            Environment environment = USDataCenter.PRODUCTION;

            /*
             * Create a Token instance
             * 1 -> OAuth client id.
             * 2 -> OAuth client secret.
             * 3 -> OAuth redirect URL.
             * 4 -> REFRESH/GRANT token.
             * 5 -> token type.
             */
            //Token token = new OAuthToken("1000.xxxxx", "xxxxxx", "1000.xxxxxx.xxxxxx", TokenType.REFRESH, "https://www.zoho.com");

            //Token token = new OAuthToken("1000.xxxx", "xxxxxx", "1000.xxxxxx.xxxxxx", TokenType.GRANT, "https://www.zoho.com");

            Token token = new OAuthToken("1000.xxxxxx", "xxxxxx", "1000.xxxxxx.xxxxxx", TokenType.GRANT, "https://www.zoho.com");

            /*
             * Create an instance of TokenStore.
             * 1 -> DataBase host name. Default "jdbc:mysql://localhost"
             * 2 -> DataBase name. Default "zohooauth"
             * 3 -> DataBase user name. Default "root"
             * 4 -> DataBase password. Default ""
             * 5 -> DataBase port number. Default "3306"
             */
            //TokenStore tokenstore = new DBStore();

            TokenStore tokenstore = new DBStore(null, null, null, null, null);

            //TokenStore tokenstore = new FileStore("/Users/Documents/GitLab/csharp_sdk_token.txt");

            /*
             * autoRefreshFields
             * if true - all the modules' fields will be auto-refreshed in the background, every    hour.
             * if false - the fields will not be auto-refreshed in the background. The user can manually delete the file(s) or refresh the fields using methods from ModuleFieldsHandler(com.zoho.crm.api.util.ModuleFieldsHandler)
             *
             * pickListValidation
             * if true - value for any picklist field will be validated with the available values.
             * if false - value for any picklist field will not be validated, resulting in creation of a new value.
             */
            SDKConfig config = new SDKConfig.Builder().SetAutoRefreshFields(true).SetPickListValidation(false).Build();

            string resourcePath = "/Users/Documents/GitLab/SampleApp/zohocrm-csharp-sdk-sample-application";

            /**
             * Create an instance of RequestProxy class that takes the following parameters
             * 1 -> Host
             * 2 -> Port Number
             * 3 -> User Name
             * 4 -> Password
             * 5 -> User Domain
             */
            //RequestProxy requestProxy = new RequestProxy("http://171.0.0.1", 3128, "", "", "");

            //RequestProxy requestProxy = new RequestProxy("http://171.0.0.1", 3128, "", null);

            /*
             * Call static initialize method of Initializer class that takes the arguments
             * 1 -> UserSignature instance
             * 2 -> Environment instance
             * 3 -> Token instance
             * 4 -> TokenStore instance
             * 5 -> SDKConnfig
             * 6 -> The path containing the absolute directory path to store user specific JSON files containing module fields information.
             * 7 -> Logger instance
             * 8 -> RequestProxy instance
             */

            // The following are the available initialize methods

            //SDKInitializer.Initialize(user, environment, token, tokenstore, config, resourcePath);

            SDKInitializer.Initialize(user, environment, token, tokenstore, config, resourcePath, logger);

            //SDKInitializer.Initialize(user, environment, token, tokenstore, config, resourcePath, requestProxy);

            //SDKInitializer.Initialize(user, environment, token, tokenstore, config, resourcePath, logger, requestProxy);

            //foreach (Token token1 in ((DBStore)tokenstore).GetTokens())
            //{
            //    OAuthToken authToken = (OAuthToken)token1;

            //    Console.WriteLine(authToken.AccessToken);

            //    Console.WriteLine(authToken.RefreshToken);

            //    Console.WriteLine(authToken.ExpiresIn);

            //    Console.WriteLine(authToken.GrantToken);
            //}
        }