public static void Init(Container container) { ICacheLoader cacheLoader = container.GetInstance <ICacheLoader>(); cacheLoader.Init(); cacheLoader.Refresh(); }
/// <summary> /// Inicializa a instancia com as propriedades informadas. /// </summary> /// <param name="properties"></param> private void Initialize(IDictionary properties) { properties.Require("properties").NotNull(); try { if (!properties.Contains("assembly")) { throw new ConfigurationException(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.ConfigurationException_MissingAssemblyName).Format()); } if (!properties.Contains("classname")) { throw new ConfigurationException(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.ConfigurationException_MissingClassName).Format()); } var assemblyName = Convert.ToString(properties["assembly"]); string typeName = Convert.ToString(properties["classname"]); string path = Convert.ToString(properties["full-name"]); string extension = ".dll"; if (properties.Contains("full-name")) { extension = System.IO.Path.GetExtension(path); } IDictionary parameters = properties["parameters"] as IDictionary; if (parameters == null) { parameters = new Hashtable(); } try { if (!string.IsNullOrEmpty(path) && extension.EndsWith(".dll") || extension.EndsWith(".exe")) { System.Reflection.Assembly assembly = null; string assemblyFile = CachingUtils.DeployedAssemblyDir + _cache.Name + @"\" + path; try { assembly = System.Reflection.Assembly.LoadFrom(assemblyFile); } catch (Exception exception) { throw new Exception(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.Exception_CouldNotLoadAssembly, assemblyFile, exception.Message).Format()); } if (assembly != null) { _cacheLoader = (ICacheLoader)assembly.CreateInstance(typeName); } } else { var type = Type.GetType(string.Format("{0}, {1}", typeName, assemblyName), false); if (type != null) { _cacheLoader = (ICacheLoader)Activator.CreateInstance(type); } } if (_cacheLoader == null) { throw new Exception(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.Exception_UnableToInstantiate, typeName).Format()); } _cacheLoader.Init(parameters); } catch (InvalidCastException) { throw new ConfigurationException(ResourceMessageFormatter.Create(() => global::Colosoft.Caching.Properties.Resources.ConfigurationException_ICacheLoaderNotImplemented).Format()); } catch (Exception exception2) { throw new ConfigurationException(exception2.Message, exception2); } } catch (ConfigurationException) { throw; } catch (Exception exception3) { throw new ConfigurationException("Configuration Error: " + exception3.ToString(), exception3); } }