Esempio n. 1
0
 void IPlugIn.PreProcessArguments(ActionArgs args, ActionResult result, ViewPage page)
 {
     _annotations = new List <FieldValue>();
     if (args.Values != null)
     {
         foreach (FieldValue v in args.Values)
         {
             if (v.Name.StartsWith("_Annotation_") && v.Modified)
             {
                 _annotations.Add(v);
                 v.Modified = false;
             }
         }
     }
 }
        protected virtual void ExecuteMethod(ActionArgs args, ActionResult result, ActionPhase phase)
        {
            bool match = InternalExecuteMethod(args, result, phase, true, true);

            if (!(match))
            {
                match = InternalExecuteMethod(args, result, phase, true, false);
            }
            if (!(match))
            {
                match = InternalExecuteMethod(args, result, phase, false, true);
            }
            if (!(match))
            {
                InternalExecuteMethod(args, result, phase, false, false);
            }
        }
Esempio n. 3
0
        public static int ExecuteNonQuery(ActionArgs args, ActionResult result, ViewPage page, DbCommand command)
        {
            TransactionManager tm = Create(args.Transaction);

            if (tm == null)
            {
                return(command.ExecuteNonQuery());
            }
            else
            if (tm.Status == "complete")
            {
                return(command.ExecuteNonQuery());
            }
            int rowsAffected = tm.ExecuteAction(args, result, page);

            tm.Arguments.Add(args);
            return(rowsAffected);
        }
Esempio n. 4
0
        protected virtual string GenerateOutputFileName(ActionArgs args, string outputFileName)
        {
            args.CommandArgument = args.CommandName;
            args.CommandName     = "FileName";
            List <FieldValue> values = new List <FieldValue>();

            values.Add(new FieldValue("FileName", outputFileName));
            args.Values = values.ToArray();
            ActionResult result = ControllerFactory.CreateDataController().Execute(args.Controller, args.View, args);

            foreach (FieldValue v in result.Values)
            {
                if (v.Name == "FileName")
                {
                    outputFileName = Convert.ToString(v.Value);
                    break;
                }
            }
            return(outputFileName);
        }
 void IActionHandler.ExecuteAction(ActionArgs args, ActionResult result)
 {
     ExecuteMethod(args, result, ActionPhase.Execute);
     ExecuteAction(args, result);
 }
 void IActionHandler.AfterSqlAction(ActionArgs args, ActionResult result)
 {
     ExecuteMethod(args, result, ActionPhase.After);
     AfterSqlAction(args, result);
 }
 void IActionHandler.BeforeSqlAction(ActionArgs args, ActionResult result)
 {
     ExecuteMethod(args, result, ActionPhase.Before);
     BeforeSqlAction(args, result);
 }
 protected virtual void ExecuteAction(ActionArgs args, ActionResult result)
 {
 }
 protected virtual void AfterSqlAction(ActionArgs args, ActionResult result)
 {
 }
 protected virtual void BeforeSqlAction(ActionArgs args, ActionResult result)
 {
 }
        private bool InternalExecuteMethod(ActionArgs args, ActionResult result, ActionPhase phase, bool viewMatch, bool argumentMatch)
        {
            _arguments = args;
            _result    = result;
            bool success = false;

            MethodInfo[] methods = GetType().GetMethods((BindingFlags.Public | (BindingFlags.NonPublic | BindingFlags.Instance)));
            foreach (MethodInfo method in methods)
            {
                object[] filters = method.GetCustomAttributes(typeof(ControllerActionAttribute), true);
                foreach (ControllerActionAttribute action in filters)
                {
                    if (((action.Controller == args.Controller) || (!(String.IsNullOrEmpty(args.Controller)) && Regex.IsMatch(args.Controller, action.Controller))) && ((!(viewMatch) && String.IsNullOrEmpty(action.View)) || (action.View == args.View)))
                    {
                        if ((action.CommandName == args.CommandName) && ((!(argumentMatch) && String.IsNullOrEmpty(action.CommandArgument)) || (action.CommandArgument == args.CommandArgument)))
                        {
                            if (action.Phase == phase)
                            {
                                ParameterInfo[] parameters = method.GetParameters();
                                if ((parameters.Length == 2) && ((parameters[0].ParameterType == typeof(ActionArgs)) && (parameters[1].ParameterType == typeof(ActionResult))))
                                {
                                    method.Invoke(this, new object[] {
                                        args,
                                        result
                                    });
                                }
                                else
                                {
                                    object[] arguments = new object[parameters.Length];
                                    for (int i = 0; (i < parameters.Length); i++)
                                    {
                                        ParameterInfo p = parameters[i];
                                        FieldValue    v = SelectFieldValueObject(p.Name);
                                        if (v != null)
                                        {
                                            if (p.ParameterType.Equals(typeof(FieldValue)))
                                            {
                                                arguments[i] = v;
                                            }
                                            else
                                            {
                                                try
                                                {
                                                    arguments[i] = DataControllerBase.ConvertToType(p.ParameterType, v.Value);
                                                }
                                                catch (Exception)
                                                {
                                                }
                                            }
                                        }
                                    }
                                    method.Invoke(this, arguments);
                                    success = true;
                                }
                            }
                        }
                    }
                }
            }
            return(success);
        }
Esempio n. 12
0
        private void ExecuteDataExport(ActionArgs args, ActionResult result)
        {
            if (!(String.IsNullOrEmpty(args.CommandArgument)))
            {
                string[] arguments = args.CommandArgument.Split(',');
                if (arguments.Length > 0)
                {
                    bool sameController = (args.Controller == arguments[0]);
                    args.Controller = arguments[0];
                    if (arguments.Length == 1)
                    {
                        args.View = "grid1";
                    }
                    else
                    {
                        args.View = arguments[1];
                    }
                    if (sameController)
                    {
                        args.SortExpression = null;
                    }
                    SelectView(args.Controller, args.View);
                }
            }
            PageRequest request = new PageRequest(-1, -1, null, null);

            request.SortExpression = args.SortExpression;
            request.Filter         = args.Filter;
            request.ContextKey     = null;
            request.PageIndex      = 0;
            request.PageSize       = Int32.MaxValue;
            request.View           = args.View;
            if (args.CommandName.EndsWith("Template"))
            {
                request.PageSize = 0;
                args.CommandName = "ExportCsv";
            }
            // store export data to a temporary file
            string       fileName = Path.GetTempFileName();
            StreamWriter writer   = File.CreateText(fileName);

            try
            {
                ViewPage page = new ViewPage(request);
                page.ApplyDataFilter(_config.CreateDataFilter(), args.Controller, args.View, null, null, null);
                if (_serverRules == null)
                {
                    _serverRules = _config.CreateBusinessRules();
                    if (_serverRules == null)
                    {
                        _serverRules = CreateBusinessRules();
                    }
                }
                _serverRules.Page = page;
                _serverRules.ExecuteServerRules(request, ActionPhase.Before);
                using (DbConnection connection = CreateConnection())
                {
                    DbCommand selectCommand = CreateCommand(connection);
                    if ((selectCommand == null) && _serverRules.EnableResultSet)
                    {
                        PopulatePageFields(page);
                        EnsurePageFields(page, null);
                    }
                    ConfigureCommand(selectCommand, page, CommandConfigurationType.Select, null);
                    DbDataReader reader = ExecuteResultSetReader(page);
                    if (reader == null)
                    {
                        reader = selectCommand.ExecuteReader();
                    }
                    if (args.CommandName.EndsWith("Csv"))
                    {
                        ExportDataAsCsv(page, reader, writer);
                    }
                    if (args.CommandName.EndsWith("Rss"))
                    {
                        ExportDataAsRss(page, reader, writer);
                    }
                    if (args.CommandName.EndsWith("Rowset"))
                    {
                        ExportDataAsRowset(page, reader, writer);
                    }
                    reader.Close();
                }
                _serverRules.ExecuteServerRules(request, ActionPhase.After);
            }
            finally
            {
                writer.Close();
            }
            result.Values.Add(new FieldValue("FileName", null, fileName));
        }
Esempio n. 13
0
        public int ExecuteAction(ActionArgs args, ActionResult result, ViewPage page)
        {
            DataTable t = GetTable(args.Controller, null);

            if (args.CommandName == "Insert")
            {
                DataRow r = t.NewRow();
                foreach (FieldValue v in args.Values)
                {
                    DataField f = page.FindField(v.Name);
                    if (f.IsPrimaryKey && f.ReadOnly)
                    {
                        object key = null;
                        if (f.Type == "Guid")
                        {
                            key = Guid.NewGuid();
                        }
                        else
                        if (!(PrimaryKeys.TryGetValue(args.Controller, out key)))
                        {
                            key = -1;
                            PrimaryKeys.Add(args.Controller, key);
                        }
                        else
                        {
                            key = (Convert.ToInt32(key) - 1);
                            PrimaryKeys[args.Controller] = key;
                        }
                        r[v.Name] = key;
                        result.Values.Add(new FieldValue(v.Name, key));
                        FieldValue fv = args.SelectFieldValueObject(v.Name);
                        fv.NewValue = key;
                        fv.Modified = true;
                    }
                    else
                    if (v.Modified)
                    {
                        if (v.NewValue == null)
                        {
                            r[v.Name] = DBNull.Value;
                        }
                        else
                        {
                            r[v.Name] = v.NewValue;
                        }
                    }
                }
                t.Rows.Add(r);
                return(1);
            }
            else
            {
                DataRow targetRow = null;
                foreach (DataRow r in t.Rows)
                {
                    bool matched = true;
                    foreach (DataField f in page.Fields)
                    {
                        if (f.IsPrimaryKey)
                        {
                            object kv  = r[f.Name];
                            object kv2 = args.SelectFieldValueObject(f.Name).OldValue;
                            if (((kv == null) || (kv2 == null)) || !((kv.ToString() == kv2.ToString())))
                            {
                                matched = false;
                                break;
                            }
                        }
                    }
                    if (matched)
                    {
                        targetRow = r;
                        break;
                    }
                }
                if (targetRow == null)
                {
                    return(0);
                }
                if (args.CommandName == "Delete")
                {
                    t.Rows.Remove(targetRow);
                }
                else
                {
                    foreach (FieldValue v in args.Values)
                    {
                        if (v.Modified)
                        {
                            if (v.NewValue == null)
                            {
                                targetRow[v.Name] = DBNull.Value;
                            }
                            else
                            {
                                targetRow[v.Name] = v.NewValue;
                            }
                        }
                    }
                }
                return(1);
            }
        }
Esempio n. 14
0
 public static bool InTransaction(ActionArgs args)
 {
     return(!(String.IsNullOrEmpty(args.Transaction)) && !(args.Transaction.EndsWith(":complete")));
 }