Esempio n. 1
0
 /// <summary>
 /// 获取对象值
 /// </summary>
 /// <param name="key">关键字</param>
 /// <returns>返回关键字对应的值</returns>
 public static PersistenceResolver GetPersistenceResolvers(string key)
 {
     try
     {
         readerWriterLockSlim.EnterReadLock();
         if (persistenceResolvers == null)
         {
             persistenceResolvers = new Dictionary <string, PersistenceResolver>();
             return(null);
         }
         PersistenceResolver value = null;
         if (persistenceResolvers.TryGetValue(key, out value))
         {
             return(value);
         }
         return(null);
     }
     finally
     {
         if (readerWriterLockSlim.IsReadLockHeld)
         {
             readerWriterLockSlim.ExitReadLock();
         }
     }
 }
Esempio n. 2
0
        /// <summary>
        /// 写入对象值
        /// </summary>
        /// <param name="key">关键字</param>
        /// <param name="value">关键字值</param>
        public static void SetPersistenceResolvers(string key, PersistenceResolver value)
        {
            try
            {
                readerWriterLockSlim.EnterUpgradeableReadLock();

                if (persistenceResolvers == null)
                {
                    persistenceResolvers = new Dictionary <string, PersistenceResolver>();
                }
                if (persistenceResolvers.ContainsKey(key))
                {
                    throw new ArgumentException(string.Format("{0} is exists in Persistence Cache."));
                }
                try
                {
                    readerWriterLockSlim.EnterWriteLock();
                    persistenceResolvers.Add(key, value);
                }
                finally
                {
                    if (readerWriterLockSlim.IsWriteLockHeld)
                    {
                        readerWriterLockSlim.ExitWriteLock();
                    }
                }
            }
            finally
            {
                if (readerWriterLockSlim.IsUpgradeableReadLockHeld)
                {
                    readerWriterLockSlim.ExitUpgradeableReadLock();
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// 获取PersistenceResolve
        /// </summary>
        public static PersistenceResolver CreateResolver(Type entityType)
        {
            string key = string.Format("PersistenceResolver_{0}", entityType.ToString());
            PersistenceResolver resolver = PersistenceCache.GetPersistenceResolvers(key);

            if (resolver == null)
            {
                string[] temps = DbHelper.ProviderName.Split(new char[] { '.' });
                if (temps.Length > 0)
                {
                    Type type = Type.GetType(string.Format("EasySoft.Core.Persistence.RepositoryImplement.{0}PersistenceResolver", temps[temps.Length - 1]));
                    resolver            = (PersistenceResolver)Activator.CreateInstance(type);
                    resolver.EntityType = entityType;
                }
                if (resolver == null)
                {
                    throw new ArgumentNullException("PersistenceResolve");
                }
                PersistenceCache.SetPersistenceResolvers(key, resolver);
            }

            return(resolver);
        }