Ejemplo n.º 1
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or
 /// resetting unmanaged resources.
 /// </summary>
 void IDisposable.Dispose()
 {
     if (_dsWriter != null)
     {
         lock (_dsWriter)
         {
             try
             {
                 _dsWriter.Dispose();
             }
             catch (Exception e)
             {
                 NCacheLog.Error("WriteThruProviderMgr", "User code threw " + e.ToString());
             }
             _dsWriter = null;
         }
     }
 }
 /// <summary>
 /// Libera a instancia.
 /// </summary>
 void IDisposable.Dispose()
 {
     if (_dsWriter != null)
     {
         lock (_dsWriter)
         {
             try
             {
                 _dsWriter.Stop();
             }
             catch (Exception exception)
             {
                 this.Logger.Error("WriteThruProviderMgr".GetFormatter(), ("User code threw " + exception.GetType().Name).GetFormatter());
             }
             _dsWriter = null;
         }
     }
 }
Ejemplo n.º 3
0
        /// <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 write-thru option");
                }
                if (!properties.Contains("class-name"))
                {
                    throw new ConfigurationException("Missing class name for write-thru option");
                }

                string      assembly      = Convert.ToString(properties["assembly-name"]);
                string      classname     = Convert.ToString(properties["class-name"]);
                IDictionary startupparams = properties["parameters"] as IDictionary;

                //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"]));
                }

                if (startupparams == null)
                {
                    startupparams = new Hashtable();
                }

                try
                {
                    if (extension.Equals(".dll") || extension.Equals(".exe"))
                    {
                        AuthenticateFeature.Authenticate(LanguageContext.DOTNET);

                        _languageContext = LanguageContext.DOTNET;

                        if (classname.Contains("Alachisoft.NCache.Web.ClientCache.ClientCacheWriteThru") && InternalProviderFactory.Instance != null)
                        {
                            _dsWriter = InternalProviderFactory.Instance.CreateWriteThruProvider();
                        }
                        else
                        {
                            string path = AppUtil.DeployedAssemblyDir + _cacheName + GetWriteThruAssemblyPath(assembly) + extension;

                            if (DatasourceMgr.AssemblyCache.ContainsKey(assembly))
                            {
                                asm = DatasourceMgr.AssemblyCache[assembly];
                            }
                            else
                            {
                                try
                                {
                                    asm = Assembly.LoadFrom(path);
                                }
                                catch (Exception e)
                                {
                                    try
                                    {
                                        asm = Assembly.Load(assembly);
                                    }
                                    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") + GetWriteThruAssemblyPath(assembly) + extension;
                                            }
                                            else
                                            {
                                                path = Path.Combine(path, "2.0") + GetWriteThruAssemblyPath(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)
                            {
                                _dsWriter = (IWriteThruProvider)asm.CreateInstance(classname);
                            }

                            if (_dsWriter == null)
                            {
                                throw new Exception("Unable to instantiate " + classname);
                            }

                            if (asm != null)
                            {
                                DatasourceMgr.AssemblyCache[assembly] = asm;
                            }
                        }

                        _dsWriter.Init(startupparams, _cacheName);
                    }
                }
                catch (InvalidCastException)
                {
                    throw new ConfigurationException("The class specified in write-thru does not implement IDatasourceWriter");
                }
                catch (Exception e)
                {
                    throw new ConfigurationException(e.Message, e);
                }
            }
            catch (ConfigurationException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ConfigurationException("Configuration Error: " + e.ToString(), e);
            }
        }
        private void Initialize(IDictionary properties)
        {
            Assembly assembly = null;

            if (properties == null)
            {
                throw new ArgumentNullException("properties");
            }
            try
            {
                if (!properties.Contains("assembly-name"))
                {
                    throw new Colosoft.Caching.Exceptions.ConfigurationException("Missing assembly name for write-thru option");
                }
                if (!properties.Contains("class-name"))
                {
                    throw new Colosoft.Caching.Exceptions.ConfigurationException("Missing class name for write-thru option");
                }
                string      asm        = Convert.ToString(properties["assembly-name"]);
                string      typeName   = Convert.ToString(properties["class-name"]);
                IDictionary parameters = properties["parameters"] as IDictionary;
                string      extension  = ".dll";
                if (properties.Contains("full-name"))
                {
                    extension = System.IO.Path.GetExtension(Convert.ToString(properties["full-name"]));
                }
                if (parameters == null)
                {
                    parameters = new Hashtable();
                }
                if (properties.Contains("async-mode"))
                {
                    _asyncWrites = Convert.ToBoolean(properties["async-mode"]);
                }
                try
                {
                    if (extension.Equals(".dll") || extension.Equals(".exe"))
                    {
                        string assemblyFile = CachingUtils.DeployedAssemblyDir + _cacheName + this.GetWriteThruAssemblyPath(asm) + extension;
                        try
                        {
                            assembly = Assembly.LoadFrom(assemblyFile);
                        }
                        catch (Exception exception)
                        {
                            throw new Exception(string.Format("Could not load assembly " + assemblyFile + ". Error {0}", exception.Message));
                        }
                        if (assembly != null)
                        {
                            _dsWriter = (IWriteThruProvider)assembly.CreateInstance(typeName);
                        }
                        if (_dsWriter == null)
                        {
                            throw new Exception("Unable to instantiate " + typeName);
                        }
                        _dsWriter.Start(parameters);
                    }
                }
                catch (InvalidCastException)
                {
                    throw new ConfigurationException("The class specified in write-thru does not implement IDatasourceWriter");
                }
                catch (Exception exception2)
                {
                    throw new ConfigurationException(exception2.Message, exception2);
                }
            }
            catch (ConfigurationException)
            {
                throw;
            }
            catch (Exception exception3)
            {
                throw new ConfigurationException("Configuration Error: " + exception3.ToString(), exception3);
            }
        }