コード例 #1
0
        public ActionResponse Execute()
        {
            var response = new ActionResponse();

            using (var cn = _cf.GetConnection()) {
                cn.Open();
                try {
                    if (_node.Command == string.Empty)
                    {
                        var logger = new Cfg.Net.Loggers.MemoryLogger();
                        _node.Command = _commandReader.Read(_node.Url == string.Empty ? _node.File : _node.Url, new Dictionary <string, string>(), logger);
                        foreach (var warning in logger.Warnings())
                        {
                            _context.Warn(warning);
                        }
                        foreach (var error in logger.Errors())
                        {
                            _context.Error(error);
                        }
                    }
                    _node.RowCount = cn.Execute(_node.Command, commandTimeout: _node.TimeOut);
                    var message = $"{(_node.Description == string.Empty ? _node.Type + " action" : "'" + _node.Description + "'")} affected {(_node.RowCount == -1 ? 0 : _node.RowCount)} row{_node.RowCount.Plural()}.";
                    response.Message = message;
                    _context.Info(message);
                } catch (Exception ex) {
                    response.Code    = 500;
                    response.Message = ex.Message + " " + ex.StackTrace + " " + _node.Command.Replace("{", "{{").Replace("}", "}}");
                }
            }
            return(response);
        }
コード例 #2
0
        public ActionResponse Execute()
        {
            var response = new ActionResponse {
                Action = _node
            };

            using (var cn = _cf.GetConnection()) {
                cn.Open();
                try {
                    if (_node.Command == string.Empty)
                    {
                        var logger = new Cfg.Net.Loggers.MemoryLogger();
                        _node.Command = _commandReader.Read(_node.Url == string.Empty ? _node.File : _node.Url, new Dictionary <string, string>(), logger);
                        foreach (var warning in logger.Warnings())
                        {
                            _context.Warn(warning);
                        }
                        foreach (var error in logger.Errors())
                        {
                            _context.Error(error);
                        }
                    }

                    if (_node.Command.Contains("@"))
                    {
                        var parameters = new ExpandoObject();
                        var editor     = (IDictionary <string, object>)parameters;
                        var active     = _context.Process.GetActiveParameters();
                        foreach (var parameter in active)
                        {
                            if (parameter.Name.Contains("."))
                            {
                                parameter.Name = parameter.Name.Replace(".", "_");
                            }
                        }
                        foreach (var name in new AdoParameterFinder().Find(_node.Command).Distinct().ToList())
                        {
                            var match = active.FirstOrDefault(p => p.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
                            if (match != null)
                            {
                                editor[match.Name] = match.Convert(match.Value);
                            }
                        }
                        _node.RowCount = cn.Execute(_node.Command, parameters, commandTimeout: _node.TimeOut);
                    }
                    else
                    {
                        _node.RowCount = cn.Execute(_node.Command, commandTimeout: _node.TimeOut);
                    }
                    var message = $"{(_node.Description == string.Empty ? _node.Type + " action" : "'" + _node.Description + "'")} affected {(_node.RowCount == -1 ? 0 : _node.RowCount)} row{_node.RowCount.Plural()}.";
                    response.Message = message;
                    _context.Info(message);
                } catch (Exception ex) {
                    response.Code    = 500;
                    response.Message = ex.Message + " " + ex.StackTrace + " " + _node.Command.Replace("{", "{{").Replace("}", "}}");
                }
            }
            return(response);
        }