Example #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);
        }
Example #2
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);
        }