/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or /// resetting unmanaged resources. /// </summary> void IDisposable.Dispose() { if (_dsReader != null) { lock (_dsReader) { try { _dsReader.Dispose(); } catch (Exception e) { NCacheLog.Error("ReadThruProviderMgr", "User code threw " + e.ToString()); } } _dsReader = null; } }
/// <summary> /// Libera a instancia. /// </summary> void IDisposable.Dispose() { if (_provider != null) { IReadThruProvider provider; Monitor.Enter(provider = _provider); try { _provider.Stop(); } catch (Exception exception) { this.Logger.Error(("ReadThruProviderMgr: User code threw " + exception.GetType().Name).GetFormatter()); } finally { Monitor.Exit(provider); } _provider = null; } }
/// <summary> /// Inicializa a instancia. /// </summary> /// <param name="properties">Propriedades de configuração.</param> private void Initialize(IDictionary properties) { properties.Require("properties").NotNull(); Assembly assembly = null; try { if (!properties.Contains("assembly-name")) { throw new ConfigurationException(ResourceMessageFormatter.Create(() => Properties.Resources.ConfigurationException_MissingAssemblyNameForReadThru).Format()); } if (!properties.Contains("class-name")) { throw new ConfigurationException(ResourceMessageFormatter.Create(() => Properties.Resources.ConfigurationException_MissingClassNameForReadThru).Format()); } string assemblyName = Convert.ToString(properties["assembly-name"]); string typeName = Convert.ToString(properties["class-name"]); string extension = ".dll"; if (properties.Contains("full-name")) { extension = Path.GetExtension(Convert.ToString(properties["full-name"])); } var parameters = (properties["parameters"] as IDictionary) ?? new Hashtable(); if (extension.EndsWith(".dll") || extension.EndsWith(".exe")) { try { string assemblyFile = CachingUtils.DeployedAssemblyDir + _cacheName + this.GetReadThruAssemblyPath(assemblyName) + extension; try { assembly = Assembly.LoadFrom(assemblyFile); } catch (Exception exception) { throw new Exception(string.Format("Could not load assembly \"" + assemblyFile + "\". {0}", exception.Message)); } if (assembly != null) { _provider = (IReadThruProvider)assembly.CreateInstance(typeName); } if (_provider == null) { throw new Exception("Unable to instantiate " + typeName); } _provider.Start(parameters); return; } catch (InvalidCastException) { throw new ConfigurationException("The class specified in read-thru does not implement IDatasourceReader"); } catch (Exception exception2) { throw new ConfigurationException(exception2.Message, exception2); } } } catch (ConfigurationException) { throw; } catch (Exception exception3) { throw new ConfigurationException(exception3.GetFormatter().Format(), exception3); } }
/// <summary> /// Method that allows the object to initialize itself. Passes the property map down /// the object hierarchy so that other objects may configure themselves as well.. /// sample config string /// /// backing-source /// ( /// read-thru /// ( /// assembly='Diyatech.Sample'; /// class='mySync.DB.Reader' /// ); /// write-thru /// ( /// assembly='Diyatech.Sample'; /// class='mySync.DB.Writer' /// ) /// ) /// </summary> /// <param name="properties">properties collection for this cache.</param> private void Initialize(IDictionary properties) { Assembly asm = null; if (properties == null) { throw new ArgumentNullException("properties"); } try { if (!properties.Contains("assembly-name")) { throw new ConfigurationException("Missing assembly name for read-thru option"); } if (!properties.Contains("class-name")) { throw new ConfigurationException("Missing class name for read-thru option"); } string assembly = Convert.ToString(properties["assembly-name"]); string classname = Convert.ToString(properties["class-name"]); //This is added to load the .exe and .dll providers //to keep previous provider running this bad chunk of code is written //later on you can directly provide the provider name read from config. string extension = ".dll"; if (properties.Contains("full-name")) { extension = Path.GetExtension(Convert.ToString(properties["full-name"])); } IDictionary startupparams = properties["parameters"] as IDictionary; if (startupparams == null) { startupparams = new Hashtable(); } if (extension.EndsWith(".dll") || extension.EndsWith(".exe")) { AuthenticateFeature.Authenticate(LanguageContext.DOTNET); _languageContext = LanguageContext.DOTNET; try { //for client cache read-thru provider if (classname.Contains("Alachisoft.NCache.Web.ClientCache.ClientCacheReadThru") && InternalProviderFactory.Instance != null) { _dsReader = InternalProviderFactory.Instance.CreateReadThruProvider(); } else { string path = AppUtil.DeployedAssemblyDir + _cacheName + GetReadThruAssemblyPath(assembly) + extension; if (DatasourceMgr.AssemblyCache.ContainsKey(assembly)) { asm = DatasourceMgr.AssemblyCache[assembly]; } else { try { asm = Assembly.LoadFrom(path); } catch (Exception e) { try { AssemblyName nameOfAssembly = new AssemblyName(); nameOfAssembly.Name = assembly; asm = Assembly.Load(nameOfAssembly); } catch (Exception) { try { string version = Assembly.GetExecutingAssembly().ImageRuntimeVersion; path = Path.Combine(AppUtil.InstallDir, "bin"); path = Path.Combine(path, "assembly"); if (version.Contains("v4")) { path = Path.Combine(path, "4.0") + GetReadThruAssemblyPath(assembly) + extension; } else { path = Path.Combine(path, "2.0") + GetReadThruAssemblyPath(assembly) + extension; } asm = Assembly.LoadFrom(path); } catch (Exception) { string message = string.Format("Could not load assembly \"" + assembly + "\". {0}", e.Message); throw new Exception(message); } } } } if (asm != null) { _dsReader = (IReadThruProvider)asm.CreateInstance(classname); } if (_dsReader == null) { throw new Exception("Unable to instantiate " + classname); } if (asm != null) { DatasourceMgr.AssemblyCache[assembly] = asm; } } _dsReader.Init(startupparams, _cacheName); } catch (InvalidCastException) { throw new ConfigurationException("The class specified in read-thru does not implement IDatasourceReader"); } catch (TargetInvocationException e) { throw e; } catch (Exception e) { throw new ConfigurationException(e.Message, e); } } } catch (ConfigurationException e) { throw; } catch (Exception e) { throw new ConfigurationException("Configuration Error: " + e.ToString(), e); } }