Ejemplo n.º 1
0
        public virtual string GenerateSqlString(IConditionGroup conditionGroup)
        {
            var conditionString = string.Empty;

            ConcatConditionGroup(ref conditionString, LogicalOperator.And, conditionGroup, string.Empty, string.Empty);
            return(string.IsNullOrEmpty(conditionString) ? null : GetCheckedConditionString(conditionString));
        }
        /// <summary>
        /// Evaluates the file type expressions within a condition group to determine whether they are all valid.
        /// For now, we assume that the conditionGroup.Conditions collection contains only ICondition objects. If there
        /// are any IPolicyObject objects within the collection that are not ICondition, these will not be validated.
        /// Validation is only performed on ConditionGroups with AND logic.
        /// </summary>
        /// <param name="conditionGroup">The condition group to evaluae</param>
        /// <returns></returns>
        private static bool ValidateIntraPolicyConditionGroup(IConditionGroup conditionGroup)
        {
            //For now, we only validate on AND logic
            if (ConditionLogic.AND == conditionGroup.Logic)
            {
                List<Workshare.Policy.FileType> fileTypesInConditionGroup = new List<Workshare.Policy.FileType>();

                foreach (IPolicyObject policyObject in conditionGroup.Conditions)
                {
                    if (policyObject is ICondition)
                    {
                        if (!ValidateIntraPolicyCondition((ICondition)policyObject, fileTypesInConditionGroup))
                        {
                            return false;
                        }
                    }
                    else
                    {
                        //the following is for the developer - we are only expecting to find expressions in a 
                        //Policy -> ConditionGroup -> Condition structure. You're in this code because presumably
                        //we have now changed the way we structure expressions
                        System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("Workshare.Policy.Properties.Resources", typeof(PolicySuites).Assembly);
                        string message = resourceManager.GetString("VALIDATION_INTRAPOLICY_EXPRESSIONS_UNSUPPORTEDSTRUCTURE", System.Globalization.CultureInfo.InvariantCulture);
                        Logger.LogError(message);
                        System.Diagnostics.Debug.Assert(false, message);
                    }
                }
            }

            return true;
        }
Ejemplo n.º 3
0
        private void ConcatConditionGroup(ref string conditionString, LogicalOperator concatOperator,
                                          IConditionGroup conditionGroup, string groupPrefix = "(", string groupPostfix = ")")
        {
            var groupString = string.Empty;

            foreach (var condition in conditionGroup.Conditions)
            {
                if (condition is IConditionGroup)
                {
                    ConcatConditionGroup(ref groupString, conditionGroup.ConcatOperator, (IConditionGroup)condition);
                }
                else if (condition is IFieldCondition)
                {
                    ConcatFieldCondition(ref groupString, conditionGroup.ConcatOperator, (IFieldCondition)condition);
                }
                else if (condition is IConditionString)
                {
                    ConcatConditionString(ref groupString, conditionGroup.ConcatOperator, (IConditionString)condition);
                }
            }

            if (string.IsNullOrEmpty(groupString))
            {
                return;
            }

            conditionString = string.Concat(conditionString, GetOperatorStringIfStringIsNotEmpty(conditionString, concatOperator), groupPrefix, groupString, groupPostfix);
        }
Ejemplo n.º 4
0
 // ReSharper disable MemberCanBePrivate.Global
 // ReSharper disable UnusedMethodReturnValue.Global
 public IConditionGroup Add(IConditionGroup group)
 // ReSharper restore UnusedMethodReturnValue.Global
 // ReSharper restore MemberCanBePrivate.Global
 {
     base.Add(group);
     return(this);
 }
        /// <summary>
        /// Evaluates the filesize expressions within a condition group to determine whether they are valid.
        /// For now, we assume that ConditionGroup.Conditions will contain only ICondition objects. Any other
        /// IPolicyObject objects in the collection will not be validated.
        /// </summary>
        /// <param name="conditionGroup">The condition group to evaluate</param>
        /// <returns></returns>
        private static bool ValidateIntraPolicyConditionGroup(IConditionGroup conditionGroup)
        {
            ValidRangeCollection validFileSizeRanges = new ValidRangeCollection();

            if (ConditionLogic.AND == conditionGroup.Logic)
            {
                //only need to validate on condition groups with AND logic
                foreach (IPolicyObject policyObject in conditionGroup.Conditions)
                {
                    if (policyObject is ICondition)
                    {
                        validFileSizeRanges.Remove(GetInvalidRangesFromExpression((ICondition)policyObject));
                    }
                    else
                    {
                        //the following is for the developer - we are only expecting to find expressions in a 
                        //Policy -> ConditionGroup -> Condition structure. You're in this code because presumably
                        //we have now changed the way we structure expressions
                        System.Resources.ResourceManager resourceManager = new System.Resources.ResourceManager("Workshare.Policy.Properties.Resources", typeof(PolicySuites).Assembly);
                        string message = resourceManager.GetString("VALIDATION_INTRAPOLICY_EXPRESSIONS_UNSUPPORTEDSTRUCTURE", System.Globalization.CultureInfo.InvariantCulture);
                        Logger.LogError(message);
                        System.Diagnostics.Debug.Assert(false, message);
                    }
                }
            }

            return (validFileSizeRanges.ValidRanges.Count != 0);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// 物理删除数据库中已经标记删除的数据
        /// </summary>
        /// <param name="condition"></param>
        public void PhysicalDelete(ICondition condition)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            session.CreateQuery(string.Format("DELETE FROM {0} WHERE {1}", entityType.Name, group.ToHql())).
            SetParameters(group.Parameters).ExecuteUpdate();
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 按条件查询结果集
        /// </summary>
        /// <param name="condition">条件</param>
        /// <returns>返回的结果集</returns>
        public IList <TEntity> Query(ICondition condition)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            return
                (session.CreateQuery(string.Format("FROM {0} WHERE {1}", entityType.Name, group.ToHql())).SetParameters(
                     group.Parameters).List <TEntity>());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 得到指定条件的查询结果
        /// 如果条件可返回多条记录,则只返回第一条
        /// </summary>
        /// <param name="condition">条件</param>
        /// <returns>返回的对象</returns>
        public TEntity Get(ICondition condition)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            return
                (session.CreateQuery(string.Format("FROM {0} where {1}", entityType.Name, group.ToHql())).SetParameters(
                     group.Parameters).SetMaxResults(1).UniqueResult <TEntity>());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 得到指定条件记录的数量
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <returns></returns>
        public int Count(ICondition condition)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            return
                (session.CreateQuery(string.Format("SELECT COUNT(ID) FROM {0} where {1}", entityType.Name, group.ToHql()))
                 .SetParameters(group.Parameters).UniqueResult <int>());
        }
Ejemplo n.º 10
0
        /// <summary>
        /// 得到指定条件记录的数量
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public int Count(ICondition condition)
        {
            IConditionGroup cg = RepositoryHelper.ToConditionGroup(condition);

            return
                (session.CreateQuery(string.Format("Select COUNT(ID) From {0} WHERE {1}", entityType.Name, cg.ToHql())).
                 SetParameters(cg.Parameters).UniqueResult <int>());
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="condition">条件</param>
        /// <param name="orderBy">排序条件</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageNum">页码</param>
        /// <returns></returns>
        public IList <TEntity> QueryPage(ICondition condition, OrderByGroup orderBy, int pageSize, int pageNum)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition).Add(isLogicDeleteCondition);

            return
                (session.CreateQuery(string.Format("FROM  {0} where {1} Order By {2}", entityType.Name, group.ToHql(),
                                                   orderBy.ToHql())).SetParameters(group.Parameters).SetFirstResult(
                     (pageNum - 1) * pageSize).SetMaxResults(pageNum).List <TEntity>());
        }
Ejemplo n.º 12
0
        public string GenerateConditionString(IConditionGroup conditionGroup)
        {
            if (conditionGroup == null)
            {
                return(string.Empty);
            }

            var conditionString = ConditionConverter.GenerateSqlString(conditionGroup);

            return(string.IsNullOrEmpty(conditionString) ? string.Empty : conditionString);
        }
Ejemplo n.º 13
0
        public ConditionGroup(ConditionGroup conditionGroup, IPolicyObjectCollection<IPolicyObject> conditions)
            : base(conditionGroup)
		{            
            if (null == conditionGroup)
				throw new Workshare.Policy.Exceptions.ArgumentNullException("conditionGroup", "Input condition group is null");

            m_parent = conditionGroup.m_parent;
            m_logic = conditionGroup.Logic;
			m_exitOnFirstPass = conditionGroup.ExitOnFirstPass;
            m_conditions = new PolicyObjectCollection<IPolicyObject>(conditions as PolicyObjectCollection<IPolicyObject>);
		}
Ejemplo n.º 14
0
        /// <summary>
        /// 按条件查询结果集
        /// </summary>
        /// <param name="condition">条件</param>
        /// <param name="orderBy">排序条件</param>
        /// <param name="includeLogicDelete">是否包含逻辑删除的数据</param>
        /// <returns>返回的结果集</returns>
        public IList <TEntity> Query(ICondition condition, OrderByGroup orderBy, bool includeLogicDelete)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition);

            if (!includeLogicDelete)
            {
                group = group.Add(isLogicDeleteCondition);
            }
            return
                (session.CreateQuery(string.Format("FROM {0} WHERE {1} ORDER BY {2}", entityType.Name, group.ToHql(),
                                                   orderBy.ToHql())).List <TEntity>());
        }
        private static void AddForensicCategoryIDs(IConditionGroup conditionGroup, Dictionary<Guid, bool> categoryIDs)
        {
            if (conditionGroup == null ||
                 conditionGroup.Conditions == null)
            {
                return;
            }

            foreach (ICondition condition in conditionGroup.Conditions)
            {
                AddForensicCategoryIDs(condition, categoryIDs);
            }
        }
Ejemplo n.º 16
0
        /// <summary>
        /// 分布查询
        /// </summary>
        /// <param name="condition">查询条件</param>
        /// <param name="orderBy">排序条件</param>
        /// <param name="includeLogicDelete">是否包含逻辑删除数据</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageNum">页码</param>
        /// <returns></returns>
        public IList <TEntity> QueryPage(ICondition condition, OrderByGroup orderBy, bool includeLogicDelete,
                                         int pageSize, int pageNum)
        {
            IConditionGroup group = RepositoryHelper.ToConditionGroup(condition);

            if (!includeLogicDelete)
            {
                group = group.Add(isLogicDeleteCondition);
            }
            return
                (session.CreateQuery(string.Format("FROM {0} WHERE {1} ORDER BY {2}", entityType.Name, group.ToHql(),
                                                   orderBy.ToHql())).SetFirstResult((pageNum - 1) * pageSize).SetMaxResults
                     (pageSize).List <TEntity>());
        }
Ejemplo n.º 17
0
        private void CopyConditionGroup(ConditionGroup conditionGroup)
        {            
            if (null == conditionGroup)
				throw new Workshare.Policy.Exceptions.ArgumentNullException("conditionGroup", "Input condition group is null");

            m_parent = conditionGroup.m_parent;
            m_logic = conditionGroup.Logic;
            m_exitOnFirstPass = conditionGroup.ExitOnFirstPass;
            m_policySetObserver = conditionGroup.PolicySetObserver;

            if (null != conditionGroup.Conditions)
            {
                m_conditions = new PolicyObjectCollection<IPolicyObject>(conditionGroup.Conditions as PolicyObjectCollection<IPolicyObject>);
                (m_conditions as PolicyObjectCollection<IPolicyObject>).PolicySetObserver = m_policySetObserver;
            }
        }
Ejemplo n.º 18
0
        public Condition(Condition condition, bool readOnly, bool createNewId)
            : base(condition, readOnly, createNewId)
        {
            if (null == condition)
            {
                Utilities.ErrorMessage errorMessage = new Utilities.ErrorMessage(
                    "INPUT_CONDITION_NULL",
                    "Workshare.Policy.Properties.Resources",
                    Assembly.GetExecutingAssembly());
				Logger.LogError(errorMessage.LogString);
                throw new Workshare.Policy.Exceptions.ArgumentNullException("condition", errorMessage.DisplayString);
            }

            m_parent = condition.m_parent;
            m_policySetObserver = condition.m_policySetObserver;
            m_isNegated = condition.m_isNegated;
            SetDefaults(condition.Class, condition.Operator, condition.m_dataLeft, createNewId);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Removes a ConditionGroup from a policy set's master catalogue
        /// </summary>
        /// <param name="policySet">The policy set from whose catalogue we will remove the ConditionGroup</param>
        /// <param name="conditionGroup">The ConditionGroup to remove</param>
        private static void RemoveConditionGroup(IPolicySet policySet, IConditionGroup conditionGroup)
        {
            if ((null == policySet) || (null == conditionGroup))
            {
                return;
            }

            foreach(IPolicyObject conditionOrGroup in conditionGroup.Conditions)
            {
                if (conditionOrGroup is ICondition)
                {
                    RemoveCondition(policySet, conditionOrGroup as ICondition);
                }
                else if (conditionOrGroup is IConditionGroup)
                {
                    RemoveConditionGroup(policySet, conditionOrGroup as IConditionGroup);
                }
            }

            //do extra processing on the IActionConditionGroup specialization
            if (conditionGroup is IActionConditionGroup)
            {
                RemoveActionGroup(policySet, ((IActionConditionGroup)conditionGroup).ActionGroup);
            }

            policySet.MasterCatalogue.ConditionGroups.Remove(conditionGroup);
        }
Ejemplo n.º 20
0
 public void WriteConditionGroup(IPolicySet policySet, IPolicyObject parent, IConditionGroup group)
 {
     for (int i = 0; i < group.Conditions.Count; ++i)
     {
         if (group.Conditions[i] is ICondition)
         {
             WriteCondition(policySet, group, group.Conditions[i] as ICondition, group.Logic);
         }
         else if (group.Conditions[i] is IConditionGroup)
         {
             WriteConditionGroup(policySet, parent, group.Conditions[i] as IConditionGroup);
         }
     }
 }
Ejemplo n.º 21
0
        public void WriteConditionGroup(IConditionGroup conditionGroup)
        {
            if (null == conditionGroup)
                return;

            CollectionInserter<IConditionGroup>.Insert(m_conditionGroups, conditionGroup);
        }
Ejemplo n.º 22
0
 public IConditionGroup Add(IConditionGroup group)
 {
     EmbeddedStatements.Add(group);
     return(this);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// 增加一个条件组
 /// </summary>
 /// <param name="conditionGroup"></param>
 /// <returns></returns>
 public IConditionGroup Add(IConditionGroup conditionGroup)
 {
     conditions.Add(conditionGroup);
     return(this);
 }
Ejemplo n.º 24
0
		/// <summary>
		/// Recursively searches for a condition, or condition group, in a condition group
		/// </summary>
		/// <param name="conditionGroup">The condition group to search</param>
		/// <param name="policyObject">The object to find</param>
		/// <returns>true if an object is found with GUID that matches that of the object to find</returns>
		public static bool ContainsConditionOrConditionGroup(IConditionGroup conditionGroup, IPolicyObject policyObject)
		{
			if (!((policyObject is ICondition) || (policyObject is IConditionGroup)))
			{
				throw new ArgumentException("Unexpected data type");
			}

			foreach (IPolicyObject childPolicyObject in conditionGroup.Conditions)
			{
				if (childPolicyObject is IConditionGroup)
				{
					if (ContainsConditionOrConditionGroup((IConditionGroup) childPolicyObject, policyObject))
					{
						return true;
					}
				}
				else if (childPolicyObject is ICondition)
				{
					if (childPolicyObject.Identifier == policyObject.Identifier)
					{
						return true;
					}
				}
			}

			if (conditionGroup.Identifier == policyObject.Identifier)
			{
				return true;
			}

			return false;
		}
Ejemplo n.º 25
0
		/// <summary>
		/// Recursively changes the condition logic on all condition groups
		/// </summary>
		/// <param name="conditionGroup">Condition group to change</param>
		/// <param name="logic">Condition Group logic</param>
		public static void ChangeConditionGroupLogic(IConditionGroup conditionGroup, ConditionLogic logic)
		{
			foreach (IPolicyObject policyObject in conditionGroup.Conditions)
			{
				if (policyObject is IConditionGroup)
				{
					ChangeConditionGroupLogic((IConditionGroup) policyObject, logic);
				}
			}
			conditionGroup.Logic = logic;
		}
Ejemplo n.º 26
0
        /// <summary>
        /// Adds a condition to a condition group 
        /// </summary>
        /// <param name="condition">The condition, or condition group, to add</param>
        /// <returns>True if the condition, or condition group, is successfully added, otherwise false</returns>
        protected bool AddCondition(IConditionGroup conditionGroup, IPolicyObject condition)
        {
            if (!((condition is ICondition) || (condition is IConditionGroup)))
            {
                ArgumentException ex = new ArgumentException("Object to add is not a condition or condition group");
				Logger.LogError(ex.Message);
                throw ex;
            }

            if (ConditionUnitFactory.ContainsConditionOrConditionGroup(conditionGroup, condition))
            {
                return false;
            }

            m_conditionGroup.Conditions.Add(condition);
            if (condition is ICondition)
            {
                ((ICondition)condition).Parent = m_conditionGroup;
            }
            else
            {
                ((IConditionGroup)condition).Parent = m_conditionGroup;
            }

            SetChildFormModifiedFlag();
            return true;

        }
Ejemplo n.º 27
0
 public ConditionEventArgs(IConditionGroup conditionGroup, IHyperlinkObject hyperlinkObject)
 {
     m_conditionGroup = conditionGroup;
     m_hyperlinkObject = hyperlinkObject;
 }
Ejemplo n.º 28
0
 public ConditionEventArgs(IConditionGroup conditionGroup, ConditionDisplayBase conditionMethodDisplay, IHyperlinkObject hyperlinkObject)
 {
     m_conditionGroup = conditionGroup;
     m_hyperlinkObject = hyperlinkObject;
     Add(conditionMethodDisplay);
 }
Ejemplo n.º 29
0
		public void WriteConditionGroup(IPolicySet policySet, IPolicyObject parent, IConditionGroup group)
		{
			ICataloguePolicy parentCataloguePolicy = parent as ICataloguePolicy;
			if (null == parentCataloguePolicy)
				return;

			IPolicy policy = new P5Policy(policySet, parentCataloguePolicy.Identifier, parentCataloguePolicy.Name, parentCataloguePolicy.Status);
			policy.Conditions.Add(group);
			WriteChildCollection(policySet, policy, parentCataloguePolicy.Name.Value, policy.Conditions);
		}