Esempio n. 1
0
 public void GetAllInterfacesWithNull()
 {
     Type[] interfaces = AopUtils.GetAllInterfaces(null);
     Assert.IsNotNull(interfaces,
                      "Must never return null, even if the argument is null.");
     Assert.AreEqual(0, interfaces.Length,
                     "Must return an empty array is the argument is null.");
 }
Esempio n. 2
0
        public void GetAllInterfacesWithObjectThatDoesntImpementAnything()
        {
            ImplementsNothing instance = new ImplementsNothing();

            Type[] interfaces = AopUtils.GetAllInterfaces(instance);
            Assert.IsNotNull(interfaces,
                             "Must never return null, even if the argument doesn't implement any interfaces.");
            Assert.AreEqual(0, interfaces.Length,
                            "Must return an empty array is the argument doesn't implement any interfaces.");
        }
Esempio n. 3
0
        public void GetAllInterfacesWithObjectThatInheritsInterfaces()
        {
            InheritsOneInterface instance = new InheritsOneInterface();

            Type[] interfaces = AopUtils.GetAllInterfaces(instance);
            Assert.IsNotNull(interfaces, "Must never return null.");
            Assert.AreEqual(1, interfaces.Length,
                            "Inherited one interface from superclass.");
            Type iface = interfaces[0];

            Assert.IsNotNull(iface, "Returned interface cannot be null.");
            Assert.AreEqual(typeof(IDisposable), iface, "Wrong interface returned.");
        }
Esempio n. 4
0
        /// <summary>
        /// Method run after all the properties have been set for this object.
        /// Responsible for actual proxy creation.
        /// </summary>
        public void AfterPropertiesSet()
        {
            _transactionInterceptor.AfterPropertiesSet();

            if (_target == null)
            {
                throw new ArgumentException("'target' is required.");
            }
            ProxyFactory proxyFactory = new ProxyFactory();

            if (_preInterceptors != null)
            {
                for (int i = 0; i < _preInterceptors.Length; i++)
                {
                    proxyFactory.AddAdvisor(_advisorAdapterRegistry.Wrap(_preInterceptors[i]));
                }
            }
            if (_pointcut != null)
            {
                IAdvisor advice = new DefaultPointcutAdvisor(_pointcut, _transactionInterceptor);
                proxyFactory.AddAdvisor(advice);
            }
            else
            {
                proxyFactory.AddAdvisor(new TransactionAttributeSourceAdvisor(_transactionInterceptor));
            }
            if (_postInterceptors != null)
            {
                for (int i = 0; i < _postInterceptors.Length; i++)
                {
                    proxyFactory.AddAdvisor(_advisorAdapterRegistry.Wrap(_postInterceptors[i]));
                }
            }
            proxyFactory.CopyFrom(this);
            proxyFactory.TargetSource = createTargetSource(_target);
            if (_proxyInterfaces != null)
            {
                proxyFactory.Interfaces = _proxyInterfaces;
            }
            else if (!ProxyTargetType)
            {
                if (_target is ITargetSource)
                {
                    throw new AopConfigException("Either 'ProxyInterfaces' or 'ProxyTargetType' is required " +
                                                 "when using an ITargetSource as 'target'");
                }
                proxyFactory.Interfaces = AopUtils.GetAllInterfaces(_target);
            }
            _proxy = proxyFactory.GetProxy();
        }
Esempio n. 5
0
        public void GetAllInterfacesSunnyDay()
        {
            ImplementsTwoInterfaces instance = new ImplementsTwoInterfaces();

            Type[] interfaces = AopUtils.GetAllInterfaces(instance);
            Assert.IsNotNull(interfaces, "Must never return null.");
            Assert.AreEqual(2, interfaces.Length,
                            "Implements two interfaces.");
            ISet ifaces = new ListSet(interfaces);

            Assert.IsTrue(
                ifaces.ContainsAll(
                    new Type [] { typeof(IDisposable), typeof(ICloneable) }),
                "Did not find the correct interfaces.");
        }
Esempio n. 6
0
        private void doJob()
        {
            short wait_bar_index = 0;

            char[] wait_bar = new char[] { '|', '/', '-', '\\' };
            bool   debug    = JobServiceConfig.Instance.Debug;

            if (debug)
            {
                if (_ef_logger == null)
                {
                    _ef_logger = new EntityFrameworkLogger(_logger);
                }
                DbInterception.Add(new EntityFrameworkLogger(_logger));
            }

            int delay_time = JobServiceConfig.Instance.DelayTime;
            var jobSrv     = StaticServiceFactory.Create <IBackstageJobService>();

            _logger.Info("start get all base info data from database");
            var baseInfoServices = ServiceFactory.CreateAll <IMemoryCachedService>();

            baseInfoServices.ForEachAction(x =>
            {
                x.IgnoreSecurity();
                try
                {
                    x.GetAll();
                }
                catch (Exception ex)
                {
                    var serviceType = AopUtils.GetAllInterfaces(x).First(y => y.Name.StartsWith("IService") && y.IsGenericType);
                    var messg       = String.Format("Invoking GetAll method on service {0} cause throw exception", serviceType.GetGenericArguments()[0].Name);
                    _logger.Error(messg);
                }
            });
            bool job_fetched = false;

            _queue = new ConcurrentDictionary <string, int>();
            string   server      = String.IsNullOrEmpty(JobServiceConfig.Instance.Server) ? Environment.MachineName : JobServiceConfig.Instance.Server;
            DateTime lastFixTime = DateTime.MinValue;

            do
            {
                if (Environment.UserInteractive)
                {
                    if (Console.CursorLeft > 0)
                    {
                        Console.WriteLine();
                    }

                    Console.Write(wait_bar[wait_bar_index++]);

                    if (wait_bar_index > wait_bar.Length - 1)
                    {
                        wait_bar_index = 0;
                    }

                    Console.CursorLeft = 0;
                }

                job_fetched = false;
                try
                {
                    BackstageJob job = null;
                    try
                    {
                        string[] ignore_queue_names = _queue.Where(x => x.Value >= JobServiceConfig.Instance.GetQueueCapacity(x.Key))
                                                      .Select(x => x.Key)
                                                      .Distinct()
                                                      .ToArray();

                        job = jobSrv.Pop(server, ignore_queue_names);
                    }
                    catch (Exception ex)
                    {
                        _logger.ErrorFormat("cannot pop backstage job because {0}", ex, ex.Message);
                        Thread.Sleep(delay_time);
                        continue;
                    }

                    if (job != null)
                    {
                        if (Environment.UserInteractive)
                        {
                            Console.WriteLine();
                        }

                        _queue.AddOrUpdate(job.Queue ?? Constants.BackstageJobs.Queue.Default, 1, (key, value) => value + 1);

                        job_fetched = true;
                        _logger.InfoFormat("a job {0} in service {1} candidated to run as {2} in queue {3}", job.Action, job.Service, job.RunAs, job.Queue);

                        ThreadPool.QueueUserWorkItem(new WaitCallback(run), job);
                    }

                    if ((DateTime.Now - lastFixTime).TotalMinutes > 10)
                    {
                        lastFixTime = DateTime.Now;
                        jobSrv.FixFetchedButNotRunJobs();
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine();
                    _logger.ErrorFormat("an exception occurred on executing job", ex);
                }

                TransactionContext.Current.Clear();

                if (!job_fetched)
                {
                    Thread.Sleep(delay_time);
                }
            } while (!_stop);
            canStop();
        }