Ejemplo n.º 1
0
        public static void RunSingleThreadWithMultiUser()
        {
            Logger logger = new Logger.Builder()
                            .Level(Logger.Levels.ALL)
                            .FilePath("/Users/Documents/csharp_sdk_log.log")
                            .Build();

            DataCenter.Environment env = USDataCenter.PRODUCTION;

            UserSignature user1 = new UserSignature("*****@*****.**");

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

            Token token1 = new OAuthToken.Builder()
                           .ClientId("1.xxxxx")
                           .ClientSecret("xxxxx")
                           //.GrantToken("1.xxxx.xxxx")
                           .RefreshToken("1.xxxx.xxx")
                           .RedirectURL("https://www.zoho.com")
                           .Build();

            string resourcePath = "/Users/Documents";

            DataCenter.Environment environment = USDataCenter.PRODUCTION;

            UserSignature user2 = new UserSignature("*****@*****.**");

            Token token2 = new OAuthToken.Builder()
                           .ClientId("1.xxxx")
                           .ClientSecret("xxxx")
                           //.GrantToken("1.xxxx.xxxx")
                           .RefreshToken("1.xxx.xxx")
                           .RedirectURL("https://www.zoho.com")
                           .Build();

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

            new SDKInitializer.Builder()
            .User(user1)
            .Environment(env)
            .Token(token1)
            .Store(tokenstore)
            .SDKConfig(config)
            .ResourcePath(resourcePath)
            .Logger(logger)
            .Initialize();

            new SingleThread().GetRecords("Leads");

            new SDKInitializer.Builder()
            .User(user2)
            .Environment(environment)
            .Token(token2)
            .SDKConfig(config).SwitchUser();

            new SingleThread().GetRecords("Quotes");
        }
Ejemplo n.º 2
0
        public static void RunMultiThreadWithSingleUser()
        {
            Logger logger = new Logger.Builder()
                            .Level(Logger.Levels.ALL)
                            .FilePath("/Users/Documents/csharp_sdk_log.log")
                            .Build();

            DataCenter.Environment env = USDataCenter.PRODUCTION;

            UserSignature user1 = new UserSignature("*****@*****.**");

            //TokenStore tokenstore = new DBStore.Builder()
            //    .Host("host")
            //    .TableName("tablename")
            //    .Password("password")
            //    .Build();

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

            Token token1 = new OAuthToken.Builder()
                           .ClientId("1.xxxx")
                           .ClientSecret("xxxx")
                           //.GrantToken("1.xxxx.xxxx")
                           .RefreshToken("1.xxxx.xxxx")
                           .RedirectURL("https://www.zoho.com")
                           .Build();

            string resourcePath = "/Users/Documents";

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

            new SDKInitializer.Builder()
            .User(user1)
            .Environment(env)
            .Token(token1)
            .Store(tokenstore)
            .SDKConfig(config)
            .ResourcePath(resourcePath)
            .Logger(logger)
            .Initialize();

            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();
        }
Ejemplo n.º 3
0
        public List <Token> GetTokens()
        {
            List <Token> tokens = new List <Token>();

            try
            {
                using (MySqlConnection connection = new MySqlConnection(this.connectionString))
                {
                    connection.Open();

                    string query = "select * from " + this.tableName + ";";

                    using (MySqlCommand statement = new MySqlCommand(query, connection))
                    {
                        using (MySqlDataReader result = statement.ExecuteReader())
                        {
                            while (result.Read())
                            {
                                string grantToken = result[Constants.GRANT_TOKEN] != null && !result[Constants.GRANT_TOKEN].ToString().Equals(Constants.NULL_VALUE, System.StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(result[Constants.GRANT_TOKEN].ToString()) ? result[Constants.GRANT_TOKEN].ToString() : null;

                                string redirectURL = result[Constants.REDIRECT_URL] != null && !result[Constants.REDIRECT_URL].ToString().Equals(Constants.NULL_VALUE, System.StringComparison.OrdinalIgnoreCase) && !string.IsNullOrEmpty(result[Constants.REDIRECT_URL].ToString()) ? result[Constants.REDIRECT_URL].ToString() : null;

                                OAuthToken token = new OAuthToken.Builder().ClientId(result[Constants.CLIENT_ID].ToString()).ClientSecret(result[Constants.CLIENT_SECRET].ToString()).RefreshToken(result[Constants.REFRESH_TOKEN].ToString()).Build();

                                token.Id = result[Constants.ID].ToString();

                                token.GrantToken = grantToken;

                                token.UserMail = result[Constants.USER_MAIL].ToString();

                                token.AccessToken = result[Constants.ACCESS_TOKEN].ToString();

                                token.ExpiresIn = result[Constants.EXPIRY_TIME].ToString();

                                token.RedirectURL = redirectURL;

                                tokens.Add(token);
                            }
                        }
                    }
                }
            }
            catch (System.Exception ex)
            {
                throw new SDKException(Constants.TOKEN_STORE, Constants.GET_TOKENS_DB_ERROR, ex);
            }

            return(tokens);
        }
Ejemplo n.º 4
0
        public List <Token> GetTokens()
        {
            List <Token> tokens = new List <Token>();

            try
            {
                string[] allContents = File.ReadAllLines(this.filePath);

                if (allContents == null || allContents.Length < 1)
                {
                    return(null);
                }

                for (int index = 1; index < allContents.Length; index++)
                {
                    string line = allContents[index];

                    string[] nextRecord = line.Split(',');

                    string grantToken = !string.IsNullOrEmpty(nextRecord[6]) ? nextRecord[6] : null;

                    string redirectURL = !string.IsNullOrEmpty(nextRecord[8]) ? nextRecord[8] : null;

                    OAuthToken token = new OAuthToken.Builder().ClientId(nextRecord[2]).ClientSecret(nextRecord[3]).RefreshToken(nextRecord[4]).Build();

                    token.Id = nextRecord[0];

                    token.UserMail = nextRecord[1];

                    token.AccessToken = nextRecord[5];

                    token.ExpiresIn = nextRecord[7];

                    token.RedirectURL = redirectURL;

                    token.GrantToken = grantToken;

                    tokens.Add(token);
                }
            }
            catch (System.Exception ex)
            {
                throw new SDKException(Constants.TOKEN_STORE, Constants.GET_TOKENS_FILE_ERROR, ex);
            }

            return(tokens);
        }
Ejemplo 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 = new Logger.Builder()
                            .Level(Logger.Levels.ALL)
                            .FilePath("/Users/Documents/csharp_sdk_log.log")
                            .Build();

            //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.Builder()
                          //.Id("csharp_abc_us_prd_aec1")
                          .ClientId("ClientId")
                          .ClientSecret("ClientSecret")
                          .GrantToken("GrantToken")
                          .RefreshToken("RefreshToken")
                          .RedirectURL("RedirectURL")
                          .AccessToken("AccessToken")
                          .Build();

            /*
             * Create an instance of TokenStore.
             * 1 -> DataBase host name. Default "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.Builder().Build();

            //    TokenStore tokenstore = new DBStore.Builder()
            //      .Host("Host")
            //      .DatabaseName("DatabaseName")
            //      .TableName("TableName")
            //      .UserName("UserName")
            //      .Password("Password")
            //      .PortNumber("PortNumber")
            //      .Build();

            TokenStore tokenstore = new FileStore("/Users/Documents/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()
                               .AutoRefreshFields(true)
                               .PickListValidation(false)
                               .Build();

            string resourcePath = "/Users/Documents";

            /**
             * 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.Builder()
                                        .Host("Host")
                                        .Port(Port)
                                        .User("User")
                                        .Password("")
                                        .UserDomain("UserDomain")
                                        .Build();

            /*
             * 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
            new SDKInitializer.Builder()
            .User(user)
            .Environment(environment)
            .Token(token)
            .Store(tokenstore)
            .SDKConfig(config)
            .ResourcePath(resourcePath)
            .Logger(logger)
            .Initialize();

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

            //    Console.WriteLine(JsonConvert.SerializeObject(authToken));
            // }
        }