public IList <Approach> GetApproaches()
        {
            IList <NHApproachDto> approaches = new List <NHApproachDto>();

            using (ISession session = this.sessionFactory.OpenSession())
            {
                using (ITransaction transaction = session.BeginTransaction())
                {
                    approaches = session.QueryOver <NHApproachDto>().List();

                    transaction.Commit();
                }
            }

            IList <Approach> results = new List <Approach>();

            foreach (NHApproachDto approach in approaches)
            {
                Approach model = this.approachFactory.CreateApproach(approach.Id, approach.Name, approach.Criteria);
                if (approach.EsaId.HasValue)
                {
                    IEsaRepository repository = this.esaRepositoryFactory.Invoke(this.sessionFactory);
                    Esa            esa        = repository.GetEsa(approach.EsaId.Value);
                    if (esa != null)
                    {
                        model.AddEsa(esa);
                    }
                }
                results.Add(model);
            }

            return(results);
        }
Exemplo n.º 2
0
        internal ApproachService(
            Func <ISessionFactory, IApproachRepository> approachRepositoryFactory,
            Func <ISessionFactory, IEsaRepository> esaRepositoryFactory,
            ISessionFactoryProvider sessionFactoryProvider,
            IDeviationObserver deviationObserver,
            IDeviationFactory deviationFactory,
            IEsaDtoBuilder builder,
            IEsaFactory factory)
        {
            if (approachRepositoryFactory == null)
            {
                throw new ArgumentNullException("approachRepositoryFactory");
            }
            if (esaRepositoryFactory == null)
            {
                throw new ArgumentNullException("esaRepositoryFactory");
            }
            if (sessionFactoryProvider == null)
            {
                throw new ArgumentNullException("sessionFactoryProvider");
            }
            if (deviationObserver == null)
            {
                throw new ArgumentNullException("deviationObserver");
            }
            if (deviationFactory == null)
            {
                throw new ArgumentNullException("deviationFactory");
            }
            if (builder == null)
            {
                throw new ArgumentNullException("builder");
            }
            if (factory == null)
            {
                throw new ArgumentNullException("factory");
            }

            ISessionFactory sessionFactory = sessionFactoryProvider.ForWorkspace();

            this.approachRepository = approachRepositoryFactory.Invoke(sessionFactory);
            this.esaRepository      = esaRepositoryFactory.Invoke(sessionFactory);
            this.deviationFactory   = deviationFactory;
            this.deviationObserver  = deviationObserver;
            this.builder            = builder;
            this.factory            = factory;
        }