当我使用对象实例化我的类时,我的网页无法加载

时间:2013-09-08 15:45:18

标签: c# spring

问题:当我使用对象实例化我的课程时,我的网页无法加载。不知道背后的原因。

计划详情 语言 - C# .net framework 3.5,使用Spring Framework。

       Class Instantiation.

    $$$ <object id="SecurityAnalysisService" type="SSA.Core.Service.SecurityAnalysis.SecurityAnalysisService, SSA.Core">
<constructor-arg name="clientDao" ref="ClientDao" />
<constructor-arg name="services">
  <dictionary key-type="string" value-type="SSA.Core.Service.SecurityAnalysis.IApplicationSecurityAnalysisService, SSA.Core">
    <entry key="SAP" value-ref="SapApplicationSecurityAnalyzer"/>
    <entry key="QAD" value-ref="QadApplicationSecurityAnalyzer"/>
  </dictionary>
</constructor-arg>
<constructor-arg name="applicationDao" ref="ApplicationDao" />
<constructor-arg name="activityTestDao" ref="ActivityTestDao" />
</object> $$$

班级定义

using System.Collections;
using System.Collections.Generic;
using log4net;
using Spring.Transaction;
using Spring.Transaction.Interceptor;
using SSA.Core.Dao;
using SSA.Core.Domain;

namespace SSA.Core.Service.SecurityAnalysis
{
    /// <summary>
    /// Implements core methods required for analyzing and identifying user activities and violations.
    /// </summary>
    public class SecurityAnalysisService : ISecurityAnalysisService
    {
        #region Fields

        /// <summary>
        /// Collection of security analysis implementations for different applications, indexed by application type.
        /// </summary>
        private Dictionary<string, IApplicationSecurityAnalysisService> _appServices;

        /// <summary>
        /// Application Data Access Object.
        /// </summary>
        private IApplicationDao _applicationDao;

        /// <summary>
        /// ActivityTest Data Access Object.
        /// </summary>
        private IActivityTestDao _activityTestDao;

        /// <summary>
        /// Client Data Access Object
        /// </summary>
        private IClientDao _clientDao;

        /// <summary>
        /// Collection of activitiy tests used for identifying user activities.
        /// </summary>
        private Dictionary<int, List<ActivityTest>> _activityTestCache;

        /// <summary>
        /// Object used for logging
        /// </summary>
        private static readonly ILog log = LogManager.GetLogger(typeof(SecurityAnalysisService));

        #endregion

        #region Members

        /// <summary>
        /// Gets the security analysis implementation for the given application type.
        /// </summary>
        /// <param name="type">The type of application e.g. SAP</param>
        /// <returns>Security analysis implementation for given application type</returns>
        private IApplicationSecurityAnalysisService GetServiceForApplicationType(string type)
        {
            if (_appServices != null && _appServices.ContainsKey(type))
                return _appServices[type];
            else
                return null;
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Class Constuctor, injected by Spring IoC container
        /// </summary>
        /// <param name="applicationDao">Application Data Access Object</param>
        /// <param name="services">Collection of security analysis services for different application types</param>
        /// <param name="activityTestDao">ActivityTest Data Access Object</param>
        /// <param name="clientDao">Client Data Access Object</param>
        public SecurityAnalysisService(IApplicationDao applicationDao, Dictionary<string, IApplicationSecurityAnalysisService> services,
                                       IActivityTestDao activityTestDao, IClientDao clientDao)
        {
            this._appServices = services;
            this._applicationDao = applicationDao;
            this._activityTestDao = activityTestDao;
            this._clientDao = clientDao;

            _activityTestCache = new Dictionary<int, List<ActivityTest>>();

            //foreach (Client client in _clientDao("from Client", new object[] {}))
            //{
            RefreshTestCache(_clientDao.FindById(1));
            //}
        }

        #endregion

        #region ISecurityAnalysisService Members


        /// <summary>
        /// Obtains the activity tests required for each application at a specified client
        /// </summary>
        /// <param name="client">Client</param>
        public void RefreshTestCache(Client client)
        {
            log.Debug("Start: RefreshTestCache");
            _activityTestCache.Clear();

            foreach (Application application in _applicationDao.FindAllForClient(client.Id))
            {
                if (!_activityTestCache.ContainsKey(application.Id))
                {
                    _activityTestCache.Add(application.Id, new List<ActivityTest>());
                }
                _activityTestCache[application.Id].AddRange(_activityTestDao.FindForApplicationType(application.ApplicationType));
                _activityTestCache[application.Id].AddRange(_activityTestDao.FindForApplication(application.Id));
            }
            log.Debug("End: RefreshTestCache");
        }

        /// <summary>
        /// Gets all the a users' activities on each application where they have active entitlement assigments.  The method assumes that
        /// only active assignments are passed.
        /// </summary>
        /// <param name="assignments">Collection of active assigments</param>
        /// <returns>A collection of the activities on each application account.</returns>
        public Dictionary<ApplicationUser, IList<UserActivity>> GetActivities(IList<UserEntitlementAssignment> assignments)
        {
            Dictionary<Application, ApplicationUser> appUser = new Dictionary<Application, ApplicationUser>();
            Dictionary<Application, IList<Entitlement>> appEntitlements = new Dictionary<Application, IList<Entitlement>>();
            Dictionary<ApplicationUser, IList<UserActivity>> appUserActivities = new Dictionary<ApplicationUser, IList<UserActivity>>();

            foreach (UserEntitlementAssignment assignment in assignments)
            {
                Application app = assignment.Entitlement.Application;

                if (!appUser.ContainsKey(app))
                    appUser.Add(app, assignment.User);

                if (!appEntitlements.ContainsKey(app))
                    appEntitlements.Add(app, new List<Entitlement>());

                appEntitlements[app].Add(assignment.Entitlement);
            }

            // Get the activities for each application
            foreach (Application app in appUser.Keys)
            {
                appUserActivities.Add(appUser[app], GetActivities(app, appUser[app], appEntitlements[app]));
            }
            return appUserActivities;
        }

        /// <summary>
        /// Gets the activities for an individual application user account, based on the collection of active entitlements the
        /// user has on the application.
        /// </summary>
        /// <param name="application">The application that the user account resides on.</param>
        /// <param name="user">The reference to the user account.</param>
        /// <param name="entitlements">Collection of active entitlements.</param>
        /// <returns>The list of activities that the user has.</returns>
        public IList<UserActivity> GetActivities(Application application, ApplicationUser user, IList<Entitlement> entitlements)
        {

            // Get the SecurityAnalysis Service required for this application.
            IApplicationSecurityAnalysisService analysisService = GetServiceForApplicationType(application.ApplicationType);
            IList<UserActivity> userActivities = analysisService.PerformActivityTests(application, user, entitlements, _activityTestCache[application.Id]);

            return userActivities;

        }


        /// <summary>
        /// Gets the Violations for Rules
        /// </summary>
        /// <param name="rules">Rules</param>
        /// <param name="idenity">The rules</param>
        /// <param name="userActivities">User activities</param>
        /// <returns>User Violations</returns>
        public IList<UserViolation> GetViolations(IList<Rule> rules, ApplicationUser user, IList<UserActivity> userActivities)
        {
            Dictionary<int, UserViolation> violations = new Dictionary<int, UserViolation>();

            List<int> activityKeys = new List<int>();

            // Identifies if a set or rules in a rule group is found
            bool groupFound = true;

            // Create a collection of the Activites a User has
            foreach (UserActivity userActivity in userActivities)
            {
                activityKeys.Add(userActivity.Activity.Id);
            }

            foreach (Rule rule in rules)
            {
                foreach (RuleGroup group in rule.RuleGroups)
                {
                    if (group.Activities.Count > 0)
                    {
                        groupFound = true;
                    }
                    else
                    {
                        groupFound = false;
                    }
                    foreach (Activity activity in group.Activities)
                    {

                        if (!activityKeys.Contains(activity.Id))
                        {
                            groupFound = false;
                            break;
                        }
                    }
                    if (!groupFound)
                    {
                        groupFound = true;
                        continue;
                    }
                    else
                    {
                        UserViolation userViolation = new UserViolation(rule, user);

                        if (!violations.ContainsKey(rule.Id))
                        {
                            violations.Add(rule.Id, userViolation);
                            IList<UserRuleGroup> userRuleGroups = new List<UserRuleGroup>();
                            violations[rule.Id].RuleGroups = userRuleGroups;
                        }
                        violations[rule.Id].addSource(new UserRuleGroup(group, userViolation));
                    }
                }
            }

            return new List<UserViolation>(violations.Values);
        }

        /// <summary>
        /// Gets the Violations for Rules
        /// </summary>
        /// <param name="rules">Rules</param>
        /// <param name="idenity">The rules</param>
        /// <param name="userActivities">User activities</param>
        /// <returns>User Violations</returns>
        public IList<PersonViolation> GetViolations(IList<Rule> rules, Person person, IList<UserActivity> userActivities)
        {
            Dictionary<int, PersonViolation> violations = new Dictionary<int, PersonViolation>();

            List<int> activityKeys = new List<int>();

            // Identifies if a set or rules in a rule group is found
            bool groupFound = true;

            // Create a collection of the Activites a User has
            foreach (UserActivity userActivity in userActivities)
            {
                activityKeys.Add(userActivity.Activity.Id);
            }

            foreach (Rule rule in rules)
            {
                foreach (RuleGroup group in rule.RuleGroups)
                {
                    if (group.Activities.Count > 0)
                    {
                        groupFound = true;
                    }
                    else
                    {
                        groupFound = false;
                    }
                    foreach (Activity activity in group.Activities)
                    {

                        if (!activityKeys.Contains(activity.Id))
                        {
                            groupFound = false;
                            break;
                        }
                    }
                    if (!groupFound)
                    {
                        groupFound = true;
                        continue;
                    }
                    else
                    {
                        PersonViolation userViolation = new PersonViolation(rule, person);

                        if (!violations.ContainsKey(rule.Id))
                        {
                            violations.Add(rule.Id, userViolation);
                            IList<UserRuleGroup> userRuleGroups = new List<UserRuleGroup>();
                            violations[rule.Id].RuleGroups = userRuleGroups;
                        }
                        violations[rule.Id].addSource(new UserRuleGroup(group, userViolation));
                    }
                }
            }

            return new List<PersonViolation>(violations.Values);
        }

        #endregion
    }
}

0 个答案:

没有答案