Пример #1
0
        /// <summary>
        /// To activate the rule.
        /// </summary>
        /// <param name="container">The rules container.</param>
        /// <param name="rule">Rule.</param>
        /// <param name="process">The handler.</param>
        public static void ActiveRule(this IMarketRuleContainer container, IMarketRule rule, Func <bool> process)
        {
            if (process == null)
            {
                throw new ArgumentNullException(nameof(process));
            }

            container.AddRuleLog(LogLevels.Debug, rule, LocalizedStrings.Str1082);

            List <IMarketRule> removedRules = null;

            // mika
            // проверяем правило, так как оно могло быть удалено параллельным потоком
            if (!rule.IsReady)
            {
                return;
            }

            rule.IsActive = true;

            try
            {
                if (process())
                {
                    container.Rules.Remove(rule);
                    removedRules = new List <IMarketRule> {
                        rule
                    };
                }
            }
            finally
            {
                rule.IsActive = false;
            }

            if (removedRules == null)
            {
                return;
            }

            if (rule.ExclusiveRules.Count > 0)
            {
                foreach (var exclusiveRule in rule.ExclusiveRules.SyncGet(c => c.CopyAndClear()))
                {
                    container.TryRemoveRule(exclusiveRule, false);
                    removedRules.Add(exclusiveRule);
                }
            }

            foreach (var removedRule in removedRules)
            {
                container.AddRuleLog(LogLevels.Debug, removedRule, LocalizedStrings.Str1083);
            }
        }
Пример #2
0
        /// <summary>
        /// To delete a rule. If a rule is executed at the time when this method is called, it will not be deleted.
        /// </summary>
        /// <param name="container">The rules container.</param>
        /// <param name="rule">Rule.</param>
        /// <param name="checkCanFinish">To check the possibility of rule suspension.</param>
        /// <returns><see langword="true" />, if a rule was successfully deleted, <see langword="false" />, if a rule cannot be currently deleted.</returns>
        public static bool TryRemoveRule(this IMarketRuleContainer container, IMarketRule rule, bool checkCanFinish = true)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            if (rule == null)
            {
                throw new ArgumentNullException(nameof(rule));
            }

            var isRemoved = false;

            if ((!checkCanFinish && !rule.IsActive && rule.IsReady) || rule.CanFinish())
            {
                container.Rules.Remove(rule);
                isRemoved = true;
            }

            if (isRemoved)
            {
                container.AddRuleLog(LogLevels.Debug, rule, LocalizedStrings.Str1084, rule);
            }

            return(isRemoved);
        }
Пример #3
0
		/// <summary>
		/// Release resources.
		/// </summary>
		protected override void DisposeManaged()
		{
			_container.AddRuleLog(LogLevels.Debug, this, LocalizedStrings.Str1092);
			_container = null;

			base.DisposeManaged();

			Holder.RuleStat.Remove(this);
		}