/// <summary>
        /// Constructor of <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.MobileAnalyticsManagerConfig"/>
        /// </summary>
        public MobileAnalyticsManagerConfig()
        {
            SessionTimeout      = defaultSessionTimeout;
            MaxDBSize           = defaultMaxDBSize;
            DBWarningThreshold  = defaultDBWarningThreshold;
            MaxRequestSize      = defaultMaxRequestSize;
            AllowUseDataNetwork = defaultAllowUseDataNetwork;
#if BCL
            ClientContextConfiguration = new ClientContextConfig();
#endif
        }
        /// <summary>
        /// Gets the or creates Mobile Analytics Manager instance. If the instance already exists, returns the instance; otherwise
        /// creates new instance and returns it.
        /// </summary>
        /// <returns>Mobile Analytics Manager instance.</returns>
        /// <param name="credentials">AWS Credentials.</param>
        /// <param name="appId">Amazon Mobile Analytics Application ID.</param>
        public static MobileAnalyticsManager GetOrCreateInstance(AWSCredentials credential,
                                                                         string appId)
        {
            if (credential == null)
                throw new ArgumentNullException("credential");
            if (string.IsNullOrEmpty(appId))
                throw new ArgumentNullException("appId");

            ClientContextConfig config = new ClientContextConfig(appId);
            return MobileAnalyticsManager.GetOrCreateInstance(credential, null, config);
        }
        /// <summary>
        /// Gets the or creates Mobile Analytics Manager instance. If the instance already exists, returns the instance; otherwise
        /// creates new instance and returns it.
        /// </summary>
        /// <returns>Mobile Analytics Manager instance.</returns>
        /// <param name="credentials">AWS Credentials.</param>
        /// <param name="appId">Amazon Mobile Analytics Application ID.</param>
        public static MobileAnalyticsManager GetOrCreateInstance(AWSCredentials credential,
                                                                 string appId)
        {
            if (credential == null)
            {
                throw new ArgumentNullException("credential");
            }
            if (string.IsNullOrEmpty(appId))
            {
                throw new ArgumentNullException("appId");
            }

            ClientContextConfig config = new ClientContextConfig(appId);

            return(MobileAnalyticsManager.GetOrCreateInstance(credential, null, config));
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.MobileAnalyticsManager"/> class.
        /// </summary>
        /// <param name="clientContextConfig">Client context config.</param>
        /// <param name="regionEndpoint">Region endpoint.</param>
        /// <param name="credentials">AWS Credentials.</param>
        private MobileAnalyticsManager(ClientContextConfig clientContextConfig, RegionEndpoint regionEndpoint, AWSCredentials credentials)
        {
            if (clientContextConfig == null)
            {
                throw new ArgumentNullException("clientContextConfig");
            }
            ClientContext = new ClientContext(clientContextConfig);

            if (string.IsNullOrEmpty(clientContextConfig.AppId))
            {
                throw new ArgumentNullException("application id");
            }
            _appId = clientContextConfig.AppId;

            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }

            BackgroundDeliveryClient = new DeliveryClient(AWSConfigsMobileAnalytics.AllowUseDataNetwork, ClientContext, credentials, regionEndpoint);

            Session = new Session(_appId);
        }
        /// <summary>
        /// Gets the or create instance.
        /// </summary>
        /// <returns>The or create instance.</returns>
        /// <param name="clientContextConfig">Client context config.</param>
        /// <param name="regionEndpoint">Region endpoint.</param>
        /// <param name="credentials">Credentials.</param>
        private static MobileAnalyticsManager GetOrCreateInstance(AWSCredentials credential,
                                                                       RegionEndpoint regionEndpoint,
                                                                       ClientContextConfig clientContextConfig
                                                                       )
        {
            string appId = clientContextConfig.AppId;
            MobileAnalyticsManager managerInstance =null;
            bool isNewInstance = false;
            lock(_lock)
            {
                if(_instanceDictionary.ContainsKey(appId)){
                    managerInstance = _instanceDictionary[appId];
                }else{
                    managerInstance = new MobileAnalyticsManager(clientContextConfig,regionEndpoint,credential);
                    _instanceDictionary[appId] = managerInstance;
                    isNewInstance = true;
                }
            }
            
            if(isNewInstance)
                managerInstance.Session.Start();
            
            BackgroundRunner.StartWork();

            return managerInstance;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="Amazon.MobileAnalytics.MobileAnalyticsManager.MobileAnalyticsManager"/> class.
        /// </summary>
        /// <param name="clientContextConfig">Client context config.</param>
        /// <param name="regionEndpoint">Region endpoint.</param>
        /// <param name="credentials">AWS Credentials.</param>
        private MobileAnalyticsManager(ClientContextConfig clientContextConfig,RegionEndpoint regionEndpoint,AWSCredentials credentials)
        {        
            if(clientContextConfig == null)
                throw new ArgumentNullException("clientContextConfig");
            ClientContext = new ClientContext(clientContextConfig);
            
            if(string.IsNullOrEmpty(clientContextConfig.AppId))
                throw new ArgumentNullException("application id");
            _appId = clientContextConfig.AppId;
            
            if(credentials == null)
                throw new ArgumentNullException("credentials");

            BackgroundDeliveryClient = new DeliveryClient(AWSConfigsMobileAnalytics.AllowUseDataNetwork, ClientContext, credentials, regionEndpoint);
            
            Session = new Session(_appId);
        }