/// <summary>
        /// Adds the rule to scheduler.
        /// </summary>
        /// <param name="process">The process.</param>
        /// <param name="rule">The rule.</param>
        public void AddRuleToScheduler(IProcessEdit process, ProcessActionRuleEdit rule)
        {
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;

                const string sql = @"DELETE FROM [dbo].[ScheduledActions] WHERE [RuleGuid] = @ruleGuid;";

                using (var command = new SqlCommand(sql, cn))
                {
                    command.Parameters.AddWithValue("@ruleGuid", rule.Guid);

                    command.ExecuteNonQuery();
                }
                
            }

            if (string.IsNullOrEmpty(rule.Expression) || !CheckRule(rule.Expression, process))
                return;


            using (var ctx = ConnectionManager<SqlConnection>.GetManager(Database.VeyronMeta, false))
            {
                var cn = ctx.Connection;

                const string sql = @"
INSERT INTO [dbo].[ScheduledActions]
(
     [ProcessSystemName]
    ,[RuleGuid]
)
VALUES
(
     @processSystemName
    ,@ruleGuid
);";

                using (var command = new SqlCommand(sql, cn))
                {
                    command.Parameters.AddWithValue("@processSystemName", process.SystemName);
                    command.Parameters.AddWithValue("@ruleGuid", rule.Guid);

                    command.ExecuteNonQuery();
                }
            }
        }
        /// <summary>
        /// Initiates expression editing.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="process">The process containing rule.</param>
        /// <param name="rule">The rule containing expression.</param>
        /// <param name="saveAction">The save action.</param>
        /// <param name="cancelAction">The cancel action.</param>
        /// <param name="removeAction">The remove action.</param>
        public async void EditExpression(
            ITopLevelWindow parentWindow,
            IProcessEdit process,
            ProcessActionRuleEdit rule,
            Action saveAction,
            Action cancelAction,
            Action removeAction)
        {
            WindowManager.Value.ShowStatus(new Status { IsBusy = true });

            SaveAction = saveAction;
            CancelAction = cancelAction;
            RemoveAction = removeAction;

            ProcessEdit = process;

            ExpressionDesigner.LoadFromExpressionObjects(new List<IExpressionObjectBase>());

            var expressions = new List<IExpressionObjectBase>();
            var newExpressions = new List<IExpressionObjectBase>();

            var syncContext = new NotifyClientAction(
                () =>
                {
                    ExpressionDesigner.LoadFromExpressionObjects(expressions);
                    WindowManager.Value.ShowStatus(new Status());

                    _itemHashes = ExpressionDesigner.Diagram.Items.Select(x => x.GetHashCode()).ToList();
                });

            syncContext.OperationStarted();

            var oldSourceName = string.Format("Old {0}", process.SystemName);
            var sourceName = process.SystemName;

            newExpressions.Add(CreateSourceItem(process, oldSourceName, OldSourceItemName, OldItemObjectName, 10, 10));
            newExpressions.Add(CreateSourceItem(process, sourceName, NewSourceItemName, NewItemObjectName, 10, 300));
            newExpressions.Add(CreateUserInfoSourceItem());
            newExpressions.Add(CreateDestinationItem());

            SourceFieldList systemParameters;

            try
            {
                systemParameters = await CreateSystemParametersItemAsync(SystemParametersItemName);
            }
            catch (Exception)
            {
                systemParameters = null;
            }

            if (systemParameters != null)
                newExpressions.Add(systemParameters);

            if (!string.IsNullOrWhiteSpace(rule.Expression))
            {
                try
                {
                    var expressionsContainer = Serializer.Deserialize(rule.Expression);
                    expressions.AddRange(expressionsContainer.Expressions);
                }
                catch
                {
                    // Do nothing, new expressions will be used.
                }
            }
            
            UpdateStateList(process);

            UpdateStoredExpressions(expressions, newExpressions, syncContext);
            syncContext.OperationCompleted();

            WindowManager.Value.ShowChildWindow(parentWindow, this);
        }