Esempio n. 1
0
        private void CreateDependencyEnlisters(CacheDependenciesElement dependencyConfig, string defaultConnectionName,
                                               string defaultConnectionString)
        {
            //dont do anything if there is no config
            if (dependencyConfig == null)
            {
                log.Debug("no data dependencies specified");
                return;
            }

            if (dependencyConfig.FileDependencies.Count > 0)
            {
                var paths = new List <string>();
                foreach (FileCacheDependencyElement fileConfig in dependencyConfig.FileDependencies)
                {
                    var path = fileConfig.Path;
                    if (!Path.IsPathRooted(path))
                    {
                        path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
                    }
                    if (File.Exists(path))
                    {
                        paths.Add(path);
                    }
                }
                _dependencyEnlisters.Add(new FileCacheDependencyEnlister(paths));
            }

            if (dependencyConfig.CommandDependencies.Count > 0)
            {
                foreach (CommandCacheDependencyElement commandConfig in dependencyConfig.CommandDependencies)
                {
                    IConnectionStringProvider connectionStringProvider;
                    string connectionName = null;

                    if (commandConfig.ConnectionStringProviderType != null)
                    {
                        connectionStringProvider = Activator.CreateInstance(commandConfig.ConnectionStringProviderType) as IConnectionStringProvider;
                        connectionName           = commandConfig.ConnectionName;
                    }
                    else
                    {
                        if (String.IsNullOrEmpty(defaultConnectionName) && String.IsNullOrEmpty(commandConfig.ConnectionName))
                        {
                            log.DebugFormat("no connection string provider specified using nhibernate configured connection string");

                            connectionStringProvider = new StaticConnectionStringProvider(defaultConnectionString);
                        }
                        else
                        {
                            connectionStringProvider = new ConfigConnectionStringProvider();

                            if (String.IsNullOrEmpty(commandConfig.ConnectionName) == false)
                            {
                                connectionName = commandConfig.ConnectionName;
                            }
                            else
                            {
                                connectionName = defaultConnectionName;
                            }
                        }
                    }

                    var commandEnlister = new SqlCommandCacheDependencyEnlister(commandConfig.Command, commandConfig.IsStoredProcedure,
                                                                                commandConfig.CommandTimeout, connectionName,
                                                                                connectionStringProvider);
                    _dependencyEnlisters.Add(commandEnlister);
                }
            }
        }
		private void CreateDependencyEnlisters(CacheDependenciesElement dependencyConfig, string defaultConnectionName,
		                                       string defaultConnectionString)
		{
			//dont do anything if there is no config
			if (dependencyConfig == null)
			{
				log.Debug("no data dependencies specified");
				return;
			}

			if (dependencyConfig.FileDependencies.Count > 0)
			{
				var paths = new List<string>();
				foreach (FileCacheDependencyElement fileConfig in dependencyConfig.FileDependencies)
				{
					var path = fileConfig.Path;
					if (!Path.IsPathRooted(path))
					{
						path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, path);
					}
                    if (File.Exists(path))
				    {
                        paths.Add(path);
				    }
				}
				_dependencyEnlisters.Add(new FileCacheDependencyEnlister(paths));
			}

			if (dependencyConfig.CommandDependencies.Count > 0)
			{
				foreach (CommandCacheDependencyElement commandConfig in dependencyConfig.CommandDependencies)
				{
					IConnectionStringProvider connectionStringProvider;
					string connectionName = null;

					if (commandConfig.ConnectionStringProviderType != null)
					{
						connectionStringProvider = Activator.CreateInstance(commandConfig.ConnectionStringProviderType) as IConnectionStringProvider;
						connectionName = commandConfig.ConnectionName;
					}
					else
					{
						if (String.IsNullOrEmpty(defaultConnectionName) && String.IsNullOrEmpty(commandConfig.ConnectionName))
						{
							log.DebugFormat("no connection string provider specified using nhibernate configured connection string");

							connectionStringProvider = new StaticConnectionStringProvider(defaultConnectionString);
						}
						else
						{
							connectionStringProvider = new ConfigConnectionStringProvider();

							if (String.IsNullOrEmpty(commandConfig.ConnectionName) == false)
							{
								connectionName = commandConfig.ConnectionName;
							}
							else
							{
								connectionName = defaultConnectionName;
							}
						}
					}

					var commandEnlister = new SqlCommandCacheDependencyEnlister(commandConfig.Command, commandConfig.IsStoredProcedure,
					                                                            commandConfig.CommandTimeout, connectionName, 
                                                                                connectionStringProvider);
					_dependencyEnlisters.Add(commandEnlister);
				}
			}
		}