Esempio n. 1
0
        /// <summary>
        /// This method tries to look up the service configuration from the MetadataCache.
        /// For the first request, there will be no item in the cache and so, an object of type
        /// SyncServiceConfiguration is created, initialized and added to the MetadataCache.
        /// </summary>
        private void CreateConfiguration(string scope)
        {
            Type serviceType = base.GetType();

            // Check if we already have a configuration for the service in the metadata cache.

            //MetadataCacheItem item = MetadataCache.TryLookup(serviceType);
            MetadataCacheItem item = MetadataCache.TryLookup(serviceType);

            if (null == item)
            {
                SyncTracer.Info("Creating SyncServiceConfiguration for service type {0}", serviceType);

                item = new MetadataCacheItem(serviceType);

                // Initialize the private member since it will then have default values.
                // In case of an error in the static initializer, we can refer to the default values
                // of configuration.
                _syncConfiguration = new SyncServiceConfiguration(typeof(T));

                // This will invoke the static initialization method.
                _syncConfiguration.Initialize(serviceType, scope);

                String conflictPolicy = Common.Logon.GetConflictPolicy(scope);
                if (!String.IsNullOrEmpty(conflictPolicy))
                {
                    String p = conflictPolicy.ToLower();
                    switch (p)
                    {
                    case "serverwins":
                        _syncConfiguration.SetConflictResolutionPolicy(ConflictResolutionPolicy.ServerWins);
                        break;

                    case "clientwins":
                        _syncConfiguration.SetConflictResolutionPolicy(ConflictResolutionPolicy.ClientWins);
                        break;

                    default:
                        throw new Exception("Invalid conflictPolicy value");
                    }
                }

                item.Configuration = _syncConfiguration;

                //MetadataCache.AddCacheItem(serviceType, item);
                MetadataCache.AddCacheItem(serviceType, item);

                SyncTracer.Info("SyncServiceConfiguration for service type {0} created successfully!", serviceType);
            }
            else
            {
                _syncConfiguration = item.Configuration;
            }

            // Invoke the testhook Initialize method.
            // Note: This needs to be called regardless of whether we find the configuration in the
            // cache or not because this is on a per request basis.
            _syncConfiguration.InvokeTestHookInitializeMethod(serviceType);
        }
Esempio n. 2
0
        /// <summary>
        /// Add an MetadataCacheItem object to the cache for a given service.
        /// </summary>
        /// <param name="serviceType">Type of the service class</param>
        /// <param name="item">Item to be added to the cache</param>
        /// <returns>Item that was added to the cache</returns>
        internal static MetadataCacheItem AddCacheItem(Type serviceType, MetadataCacheItem item)
        {
            MetadataCacheItem item2;
            
            var key = new MetadataCacheKey(serviceType);
            
            // Use a double check lock for concurrency.
            if (!_cache.TryGetValue(key, out item2))
            {
                lock (_lockObject)
                {
                    if (!_cache.TryGetValue(key, out item2))
                    {
                        _cache.Add(key, item);

                        item2 = item;
                    }
                }
            }

            return item2;
        }
Esempio n. 3
0
        /// <summary>
        /// Add an MetadataCacheItem object to the cache for a given service.
        /// </summary>
        /// <param name="serviceType">Type of the service class</param>
        /// <param name="item">Item to be added to the cache</param>
        /// <returns>Item that was added to the cache</returns>
        internal static MetadataCacheItem AddCacheItem(Type serviceType, MetadataCacheItem item)
        {
            MetadataCacheItem item2;

            var key = new MetadataCacheKey(serviceType);

            // Use a double check lock for concurrency.
            if (!_cache.TryGetValue(key, out item2))
            {
                lock (_lockObject)
                {
                    if (!_cache.TryGetValue(key, out item2))
                    {
                        _cache.Add(key, item);

                        item2 = item;
                    }
                }
            }

            return(item2);
        }
Esempio n. 4
0
        /// <summary>
        /// This method tries to look up the service configuration from the MetadataCache.
        /// For the first request, there will be no item in the cache and so, an object of type
        /// SyncServiceConfiguration is created, initialized and added to the MetadataCache.
        /// </summary>
        private void CreateConfiguration()
        {
            Type serviceType = base.GetType();

            // Check if we already have a configuration for the service in the metadata cache.
            MetadataCacheItem item = MetadataCache.TryLookup(serviceType);

            if (null == item)
            {
                SyncTracer.Info("Creating SyncServiceConfiguration for service type {0}", serviceType);

                item = new MetadataCacheItem(serviceType);

                // Initialize the private member since it will then have default values.
                // In case of an error in the static initializer, we can refer to the default values
                // of configuration.
                _syncConfiguration = new SyncServiceConfiguration(typeof(T));

                // This will invoke the static initialization method.
                _syncConfiguration.Initialize(serviceType);

                item.Configuration = _syncConfiguration;

                MetadataCache.AddCacheItem(serviceType, item);

                SyncTracer.Info("SyncServiceConfiguration for service type {0} created successfully!", serviceType);
            }
            else
            {
                _syncConfiguration = item.Configuration;
            }

            // Invoke the testhook Initialize method.
            // Note: This needs to be called regardless of whether we find the configuration in the
            // cache or not because this is on a per request basis.
            _syncConfiguration.InvokeTestHookInitializeMethod(serviceType);
        }