コード例 #1
0
        /// <summary>
        /// This method to initialize the SDK.
        /// </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="store">A TokenStore class instance containing the token store information.</param>
        /// <param name="sdkConfig">A SDKConfig class instance containing the configuration.</param>
        /// <param name="sdkConfig">A SDKConfig class instance containing the configuration.</param>
        /// <param name="logger">A Logger class instance containing the log file path and Logger type.</param>
        /// <param name="proxy">An RequestProxy class instance containing the proxy properties of the user.</param>
        private static void Initialize(UserSignature user, Dc.DataCenter.Environment environment, Token token, TokenStore store, SDKConfig sdkConfig, string resourcePath, Logger.Logger logger, RequestProxy proxy)
        {
            try
            {
                SDKLogger.Initialize(logger);

                try
                {
                    string result = "";

                    using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Constants.JSON_DETAILS_FILE_PATH))
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            result = reader.ReadToEnd();
                        }
                    }

                    jsonDetails = JObject.Parse(result);
                }
                catch (System.Exception e)
                {
                    throw new SDKException(Constants.JSON_DETAILS_ERROR, e);
                }

                initializer = new Initializer();

                initializer.user = user;

                initializer.environment = environment;

                initializer.token = token;

                initializer.store = store;

                initializer.sdkConfig = sdkConfig;

                initializer.resourcePath = resourcePath;

                initializer.requestProxy = proxy;

                SDKLogger.LogInfo(Constants.INITIALIZATION_SUCCESSFUL + initializer.ToString());
            }
            catch (SDKException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new SDKException(Constants.INITIALIZATION_EXCEPTION, e);
            }
        }
コード例 #2
0
        /// <summary>
        /// This method to initialize the SDK.
        /// </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="store">A TokenStore class instance containing the token store information.</param>
        /// <param name="sdkConfig">A SDKConfig class instance containing the configuration.</param>
        /// <param name="sdkConfig">A SDKConfig class instance containing the configuration.</param>
        /// <param name="logger">A Logger class instance containing the log file path and Logger type.</param>
        /// <param name="proxy">An RequestProxy class instance containing the proxy properties of the user.</param>
        public static void Initialize(UserSignature user, Dc.DataCenter.Environment environment, Token token, TokenStore store, SDKConfig sdkConfig, string resourcePath, Logger.Logger logger, RequestProxy proxy)
        {
            try
            {
                if (user == null)
                {
                    throw new SDKException(Constants.INITIALIZATION_ERROR, Constants.USERSIGNATURE_ERROR_MESSAGE);
                }

                if (environment == null)
                {
                    throw new SDKException(Constants.INITIALIZATION_ERROR, Constants.ENVIRONMENT_ERROR_MESSAGE);
                }

                if (token == null)
                {
                    throw new SDKException(Constants.INITIALIZATION_ERROR, Constants.TOKEN_ERROR_MESSAGE);
                }

                if (store == null)
                {
                    throw new SDKException(Constants.INITIALIZATION_ERROR, Constants.STORE_ERROR_MESSAGE);
                }

                if (sdkConfig == null)
                {
                    throw new SDKException(Constants.INITIALIZATION_ERROR, Constants.SDK_CONFIG_ERROR_MESSAGE);
                }

                if (string.IsNullOrEmpty(resourcePath) || string.IsNullOrWhiteSpace(resourcePath))
                {
                    throw new SDKException(Constants.INITIALIZATION_ERROR, Constants.RESOURCE_PATH_ERROR_MESSAGE);
                }

                if (!Directory.Exists(resourcePath))
                {
                    throw new SDKException(Constants.INITIALIZATION_ERROR, Constants.RESOURCE_PATH_INVALID_ERROR_MESSAGE);
                }

                if (logger == null)
                {
                    logger = Logger.Logger.GetInstance(Logger.Logger.Levels.INFO, Path.GetDirectoryName(Assembly.GetCallingAssembly().Location) + Path.DirectorySeparatorChar + Constants.LOG_FILE_NAME);
                }

                SDKLogger.Initialize(logger);

                try
                {
                    string result = "";

                    using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(Constants.JSON_DETAILS_FILE_PATH))
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            result = reader.ReadToEnd();
                        }
                    }

                    jsonDetails = JObject.Parse(result);
                }
                catch (System.Exception e)
                {
                    throw new SDKException(Constants.JSON_DETAILS_ERROR, e);
                }

                initializer = new Initializer();

                initializer.user = user;

                initializer.environment = environment;

                initializer.token = token;

                initializer.store = store;

                initializer.sdkConfig = sdkConfig;

                initializer.resourcePath = resourcePath;

                initializer.requestProxy = proxy;

                SDKLogger.LogInfo(Constants.INITIALIZATION_SUCCESSFUL + initializer.ToString());
            }
            catch (SDKException e)
            {
                throw e;
            }
            catch (Exception e)
            {
                throw new SDKException(Constants.INITIALIZATION_EXCEPTION, e);
            }
        }