コード例 #1
0
ファイル: Configurator.cs プロジェクト: olegil/ConfORMSample
        public string GetAppSettingString(string key)
        {
            Contract.Requires(!string.IsNullOrEmpty(key), string.Format("Key with named {0} is null or empty", key));

            return(CatchExceptionHelper.TryCatchFunction(
                       () => ConfigurationManager.AppSettings[key],
                       Logger
                       ));
        }
コード例 #2
0
 public void Run(IInvocation invocation, bool isFirstCall)
 {
     if (AttributeRecognize(invocation.Method) && isFirstCall)
     {
         CatchExceptionHelper.TryCatchAction(
             () => LockMethod(invocation.Proceed, invocation.Method.Name, isFirstCall),
             _logger);
     }
 }
コード例 #3
0
ファイル: Configurator.cs プロジェクト: olegil/ConfORMSample
        public T GetSection <T>(string sectionName)
        {
            Contract.Requires(!string.IsNullOrEmpty(sectionName), "SectionName [" + sectionName + "] is null or empty");

            return(CatchExceptionHelper.TryCatchFunction(
                       () => (T)ConfigurationManager.GetSection(sectionName),
                       Logger
                       ));
        }
コード例 #4
0
        public void InvalidConstructorInputsTest()
        {
            // startCount < 0
            CatchExceptionHelper.VerifyExceptionCaught <ArgumentException>(() => new SimpleCountingSemaphore(100, -1));

            // startCount < maxCoutn
            CatchExceptionHelper.VerifyExceptionCaught <ArgumentException>(() => new SimpleCountingSemaphore(100, 1000));

            // Valid inputs
            var sem = new SimpleCountingSemaphore(10, 0);

            Assert.AreEqual(sem.Count, 0);
            Assert.AreEqual(sem.MaxCount, 10);
        }
コード例 #5
0
        public void Intercept(IInvocation invocation)
        {
            var attributes = _attributeEngine.AutoFindAttribute("");

            foreach (var attribute in attributes)
            {
                var nameTemp = GetAttributeName(GetScanTaskName(attribute.FullName));

                var type = Type.GetType(nameTemp);

                if (type != null)
                {
                    var existedMethod = Attribute.GetCustomAttribute(invocation.GetConcreteMethodInvocationTarget(), type, false);

                    if (existedMethod != null)
                    {
                        var localAttribute = attribute;
                        CatchExceptionHelper.TryCatchAction(() => _attributeEngine.Run(invocation, localAttribute), _logger);
                    }
                }
            }
        }
コード例 #6
0
        public Configuration BuildConfiguration(string connectionString, string sessionFactoryName)
        {
            Contract.Requires(!string.IsNullOrEmpty(connectionString), "ConnectionString is null or empty");
            Contract.Requires(!string.IsNullOrEmpty(sessionFactoryName), "SessionFactory name is null or empty");
            Contract.Requires(!string.IsNullOrEmpty(_databaseSchema), "Database Schema is null or empty");
            Contract.Requires(_configurator != null, "Configurator is null");

            return(CatchExceptionHelper.TryCatchFunction(
                       () =>
            {
                DomainTypes = GetTypeOfEntities(_assemblies);

                if (DomainTypes == null)
                {
                    throw new Exception("Type of domains is null");
                }

                var configure = new Configuration();
                configure.SessionFactoryName(sessionFactoryName);

                configure.Proxy(p => p.ProxyFactoryFactory <ProxyFactoryFactory>());
                configure.DataBaseIntegration(db => GetDatabaseIntegration(db, connectionString));

                if (_configurator.GetAppSettingString("IsCreateNewDatabase").ConvertToBoolean())
                {
                    configure.SetProperty("hbm2ddl.auto", "create-drop");
                }

                configure.Properties.Add("default_schema", _databaseSchema);
                configure.AddDeserializedMapping(GetMapping(),
                                                 _configurator.GetAppSettingString("DocumentFileName"));

                SchemaMetadataUpdater.QuoteTableAndColumns(configure);

                return configure;
            }, Logger));
        }
コード例 #7
0
        public void GiveTakeTest()
        {
            var sem = new SimpleCountingSemaphore(3, 0);

            sem.Take();
            Assert.AreEqual(sem.Count, 1);
            sem.Take();
            Assert.AreEqual(sem.Count, 2);
            sem.Take();
            Assert.AreEqual(sem.Count, 3);

            var result = sem.TryTake();

            Assert.IsFalse(result);
            Assert.AreEqual(sem.Count, 3);

            Timer timer = new Timer(200);

            timer.Elapsed += (sender, e) => sem.Give();
            timer.Start();

            sem.Take();
            Assert.AreEqual(sem.Count, 3);

            sem.Give();
            Assert.AreEqual(sem.Count, 2);
            sem.Give();
            Assert.AreEqual(sem.Count, 1);
            sem.Give();
            Assert.AreEqual(sem.Count, 0);
            sem.Give();
            Assert.AreEqual(sem.Count, 0);

            sem.Dispose();
            CatchExceptionHelper.VerifyExceptionCaught <ObjectDisposedException>(() => sem.Take());
        }