示例#1
0
        public void AssignContext(string controller, string view, ControllerConfiguration config)
        {
            _controller = controller;
            _view       = view;
            string referrer = String.Empty;

            if ((PageSize == 1000) && String.IsNullOrEmpty(this.SortExpression))
            {
                // we are processing a request to retrieve static lookup data
                XPathNavigator sortExpressionNode = config.SelectSingleNode("c:dataController/c:views/c:view[@id=\'{0}\']/@sortExpression", view);
                if ((sortExpressionNode != null) && !(String.IsNullOrEmpty(sortExpressionNode.Value)))
                {
                    this.SortExpression = sortExpressionNode.Value;
                }
            }
            if ((HttpContext.Current != null) && (HttpContext.Current.Request.UrlReferrer != null))
            {
                referrer = HttpContext.Current.Request.UrlReferrer.AbsolutePath;
            }
            this._contextKey = string.Format("{0}/{1}.{2}.{3}", referrer, controller, view, ContextKey);
        }
示例#2
0
 public void AssignContext(string controller, string view, ControllerConfiguration config)
 {
     _controller = controller;
     _view = view;
     string referrer = String.Empty;
     if (PageSize == 1000)
     {
         // we are processing a request to retrieve static lookup data
         XPathNavigator sortExpressionNode = config.SelectSingleNode("c:dataController/c:views/c:view[@id=\'{0}\']/@sortExpression", view);
         if ((sortExpressionNode != null) && !(String.IsNullOrEmpty(sortExpressionNode.Value)))
             this.SortExpression = sortExpressionNode.Value;
     }
     if ((HttpContext.Current != null) && (HttpContext.Current.Request.UrlReferrer != null))
         referrer = HttpContext.Current.Request.UrlReferrer.AbsolutePath;
     this._contextKey = string.Format("{0}/{1}.{2}.{3}", referrer, controller, view, ContextKey);
 }
示例#3
0
        public virtual ControllerConfiguration EnsureVitalElements()
        {
            // verify that the data controller has views and actions
            XPathNavigator root = SelectSingleNode("/c:dataController[c:views/c:view and c:actions/c:actionGroup]");

            if (root != null)
            {
                return(this);
            }
            // add missing configuration elements
            XmlDocument doc = new XmlDocument();

            doc.LoadXml(_navigator.OuterXml);
            ControllerConfiguration config     = new ControllerConfiguration(doc.CreateNavigator());
            XPathNavigator          fieldsNode = config.SelectSingleNode("/c:dataController/c:fields[not(c:field[@isPrimaryKey=\'true\'])]");

            if (fieldsNode != null)
            {
                fieldsNode.AppendChild("<field name=\"PrimaryKey\" type=\"Int32\" isPrimaryKey=\"true\" readOnly=\"true\"/>");
            }
            root = config.SelectSingleNode("/c:dataController");
            EnsureChildNode(root, "views");
            XPathNavigator viewsNode = config.SelectSingleNode("/c:dataController/c:views[not(c:view)]");

            if (viewsNode != null)
            {
                StringBuilder sb = new StringBuilder("<view id=\"view1\" type=\"Form\" label=\"Form\"><categories><category id=\"c1\" flow=\"New" +
                                                     "Column\"><dataFields>");
                XPathNodeIterator fieldIterator = config.Select("/c:dataController/c:fields/c:field");
                while (fieldIterator.MoveNext())
                {
                    string fieldName = fieldIterator.Current.GetAttribute("name", String.Empty);
                    bool   hidden    = (fieldName == "PrimaryKey");
                    string length    = fieldIterator.Current.GetAttribute("length", String.Empty);
                    if (String.IsNullOrEmpty(length) && (((bool)(fieldIterator.Current.Evaluate("not(c:items/@style!=\'\')", _resolver))) == true))
                    {
                        if (fieldIterator.Current.GetAttribute("type", String.Empty) == "String")
                        {
                            length = "50";
                        }
                        else
                        {
                            length = "20";
                        }
                    }
                    sb.AppendFormat("<dataField fieldName=\"{0}\" hidden=\"{1}\"", fieldName, hidden.ToString().ToLower());
                    if (!(String.IsNullOrEmpty(length)))
                    {
                        sb.AppendFormat(" columns=\"{0}\"", length);
                    }
                    sb.Append(" />");
                }
                sb.Append("</dataFields></category></categories></view>");
                viewsNode.AppendChild(sb.ToString());
            }
            EnsureChildNode(root, "actions");
            XPathNavigator actionsNode = config.SelectSingleNode("/c:dataController/c:actions[not(c:actionGroup)]");

            if (actionsNode != null)
            {
                actionsNode.AppendChild(@"<actionGroup id=""ag1"" scope=""Form"">
<action id=""a1"" commandName=""Confirm"" causesValidation=""true"" whenLastCommandName=""New"" />
<action id=""a2"" commandName=""Cancel"" whenLastCommandName=""New"" />
<action id=""a3"" commandName=""Confirm"" causesValidation=""true"" whenLastCommandName=""Edit"" />
<action id=""a4"" commandName=""Cancel"" whenLastCommandName=""Edit"" />
<action id=""a5"" commandName=""Edit"" causesValidation=""true"" />
</actionGroup>");
            }
            XPathNavigator plugIn = config.SelectSingleNode("/c:dataController/@plugIn");

            if (plugIn != null)
            {
                plugIn.DeleteSelf();
                config._plugIn = null;
            }
            return(config);
        }
 public virtual ControllerConfiguration EnsureVitalElements()
 {
     // verify that the data controller has views and actions
     XPathNavigator root = SelectSingleNode("/c:dataController[c:views/c:view and c:actions/c:actionGroup]");
     if (root != null)
         return this;
     // add missing configuration elements
     XmlDocument doc = new XmlDocument();
     doc.LoadXml(_navigator.OuterXml);
     ControllerConfiguration config = new ControllerConfiguration(doc.CreateNavigator());
     XPathNavigator fieldsNode = config.SelectSingleNode("/c:dataController/c:fields[not(c:field[@isPrimaryKey=\'true\'])]");
     if (fieldsNode != null)
         fieldsNode.AppendChild("<field name=\"PrimaryKey\" type=\"Int32\" isPrimaryKey=\"true\" readOnly=\"true\"/>");
     root = config.SelectSingleNode("/c:dataController");
     EnsureChildNode(root, "views");
     XPathNavigator viewsNode = config.SelectSingleNode("/c:dataController/c:views[not(c:view)]");
     if (viewsNode != null)
     {
         StringBuilder sb = new StringBuilder("<view id=\"view1\" type=\"Form\" label=\"Form\"><categories><category id=\"c1\" newColumn" +
                 "=\"true\"><dataFields>");
         XPathNodeIterator fieldIterator = config.Select("/c:dataController/c:fields/c:field");
         while (fieldIterator.MoveNext())
         {
             string fieldName = fieldIterator.Current.GetAttribute("name", String.Empty);
             bool hidden = (fieldName == "PrimaryKey");
             string length = fieldIterator.Current.GetAttribute("length", String.Empty);
             if (String.IsNullOrEmpty(length) && (((bool)(fieldIterator.Current.Evaluate("not(c:items/@style!=\'\')", _resolver))) == true))
                 if (fieldIterator.Current.GetAttribute("type", String.Empty) == "String")
                     length = "50";
                 else
                     length = "20";
             sb.AppendFormat("<dataField fieldName=\"{0}\" hidden=\"{1}\"", fieldName, hidden.ToString().ToLower());
             if (!(String.IsNullOrEmpty(length)))
                 sb.AppendFormat(" columns=\"{0}\"", length);
             sb.Append(" />");
         }
         sb.Append("</dataFields></category></categories></view>");
         viewsNode.AppendChild(sb.ToString());
     }
     EnsureChildNode(root, "actions");
     XPathNavigator actionsNode = config.SelectSingleNode("/c:dataController/c:actions[not(c:actionGroup)]");
     if (actionsNode != null)
         actionsNode.AppendChild(@"<actionGroup id=""ag1"" scope=""Form"">
     <action id=""a1"" commandName=""Confirm"" causesValidation=""true"" whenLastCommandName=""New"" />
     <action id=""a2"" commandName=""Cancel"" whenLastCommandName=""New"" />
     <action id=""a3"" commandName=""Confirm"" causesValidation=""true"" whenLastCommandName=""Edit"" />
     <action id=""a4"" commandName=""Cancel"" whenLastCommandName=""Edit"" />
     <action id=""a5"" commandName=""Edit"" causesValidation=""true"" />
     </actionGroup>");
     XPathNavigator plugIn = config.SelectSingleNode("/c:dataController/@plugIn");
     if (plugIn != null)
     {
         plugIn.DeleteSelf();
         config._plugIn = null;
     }
     return config;
 }
        public string ToJson()
        {
            ControllerConfiguration config = this.Virtualize(this.ControllerName);

            Complete();
            XPathNodeIterator ruleIterator = config.Select("/c:dataController/c:businessRules/c:rule");
            bool newOnServer       = false;
            bool calculateOnServer = false;

            while (ruleIterator.MoveNext())
            {
                string type        = ruleIterator.Current.GetAttribute("type", String.Empty);
                string commandName = ruleIterator.Current.GetAttribute("commandName", String.Empty);
                if (type != "JavaScript")
                {
                    if ((commandName == "New") && !(newOnServer))
                    {
                        newOnServer = true;
                        config.SelectSingleNode("/c:dataController").CreateAttribute(String.Empty, "newOnServer", null, "true");
                    }
                    else
                    if ((commandName == "Calculate") && !(calculateOnServer))
                    {
                        calculateOnServer = true;
                        config.SelectSingleNode("/c:dataController").CreateAttribute(String.Empty, "calculateOnServer", null, "true");
                    }
                }
            }
            string expressions = JArray.FromObject(this.Expressions).ToString();

            string[] exceptions = new string[] {
                "//comment()",
                "c:dataController/c:commands",
                "c:dataController/@handler",
                "//c:field/c:formula",
                "//c:businessRules/c:rule[@type=\"Code\" or @type=\"Sql\" or @type=\"Email\"]",
                "//c:businessRules/c:rule/text()",
                "//c:validate",
                "//c:styles",
                "//c:visibility",
                "//c:readOnly",
                "//c:expression"
            };
            foreach (string ex in exceptions)
            {
                List <XPathNavigator> toDelete = new List <XPathNavigator>();
                XPathNodeIterator     iterator = config.Select(ex);
                while (iterator.MoveNext())
                {
                    toDelete.Add(iterator.Current.Clone());
                }
                foreach (XPathNavigator node in toDelete)
                {
                    node.DeleteSelf();
                }
            }
            // special case of items/item serialization
            XPathNodeIterator itemsIterator = config.Select("//c:items[c:item]");

            while (itemsIterator.MoveNext())
            {
                StringBuilder     lovBuilder   = new StringBuilder("<list>");
                XPathNodeIterator itemIterator = itemsIterator.Current.SelectChildren(XPathNodeType.Element);
                while (itemIterator.MoveNext())
                {
                    lovBuilder.Append(itemIterator.Current.OuterXml);
                }
                lovBuilder.Append("</list>");
                itemsIterator.Current.InnerXml = lovBuilder.ToString();
            }
            // load custom view layouts
            XPathNodeIterator viewIterator = config.Select("//c:views/c:view");

            while (viewIterator.MoveNext())
            {
                string layout = LoadLayout(viewIterator.Current.GetAttribute("id", String.Empty));
                if (!(String.IsNullOrEmpty(layout)))
                {
                    viewIterator.Current.AppendChild(String.Format("<layout><![CDATA[{0}]]></layout>", layout));
                }
            }
            // extend JSON with "expressions"
            string json = XmlConverter.ToJson(config.Navigator, "dataController", true, "commands", "output", "fields", "views", "categories", "dataFields", "actions", "actionGroup", "businessRules", "list");
            Match  eof  = Regex.Match(json, "\\}\\s*\\}\\s*$");

            json = (json.Substring(0, eof.Index)
                    + (",\"expressions\":"
                       + (expressions + eof.Value)));
            return(json);
        }
        void IPlugIn.PreProcessPageRequest(PageRequest request, ViewPage page)
        {
            XPathNavigator view = _config.SelectSingleNode("//c:view[@id=\'{0}\' and @type=\'Form\']/c:categories", request.View);

            if ((view != null) && ((request.PageSize > 0) && (!(request.Inserting) && (_config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'_Annotation_NoteNew\']") == null))))
            {
                _requireProcessing = true;
                string ns = ControllerConfiguration.Namespace;
                List <DynamicExpression> expressions = new List <DynamicExpression>(_config.Expressions);
                // create NewXXX fields under "fields" node
                StringBuilder     sb       = new StringBuilder();
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.ConformanceLevel = ConformanceLevel.Fragment;
                XmlWriter writer = XmlWriter.Create(sb, settings);
                // NoteNew field
                writer.WriteStartElement("field", ns);
                writer.WriteAttributeString("name", "_Annotation_NoteNew");
                writer.WriteAttributeString("type", "String");
                writer.WriteAttributeString("allowSorting", "false");
                writer.WriteAttributeString("allowQBE", "false");
                writer.WriteAttributeString("label", Localizer.Replace("AnnotationNoteNewFieldLabel", "Notes"));
                writer.WriteAttributeString("computed", "true");
                writer.WriteElementString("formula", ns, "null");
                writer.WriteEndElement();
                DynamicExpression de = new DynamicExpression();
                de.Target = "_Annotation_NoteNew";
                de.Scope  = DynamicExpressionScope.DataFieldVisibility;
                de.Type   = DynamicExpressionType.ClientScript;
                de.Test   = "this.get_isEditing()";
                de.ViewId = request.View;
                expressions.Add(de);
                // AttachmentNew field
                writer.WriteStartElement("field", ns);
                writer.WriteAttributeString("name", "_Annotation_AttachmentNew");
                writer.WriteAttributeString("type", "Byte[]");
                writer.WriteAttributeString("onDemand", "true");
                writer.WriteAttributeString("sourceFields", this.KeyFields);
                writer.WriteAttributeString("onDemandHandler", "AnnotationPlugIn");
                writer.WriteAttributeString("allowQBE", "false");
                writer.WriteAttributeString("allowSorting", "false");
                writer.WriteAttributeString("label", Localizer.Replace("AnnotationAttachmentNewFieldLabel", "Attachment"));
                writer.WriteAttributeString("computed", "true");
                writer.WriteElementString("formula", ns, "null");
                writer.WriteEndElement();
                writer.Close();
                this.Fields.AppendChild(sb.ToString());
                DynamicExpression ade = new DynamicExpression();
                ade.Target = "_Annotation_AttachmentNew";
                ade.Scope  = DynamicExpressionScope.DataFieldVisibility;
                ade.Type   = DynamicExpressionType.ClientScript;
                ade.Test   = "this.get_isEditing()";
                ade.ViewId = request.View;
                expressions.Add(ade);
                // create NewXXX data fields under "view/dataFields" node
                sb     = new StringBuilder();
                writer = XmlWriter.Create(sb);
                writer.WriteStartElement("category", ns);
                writer.WriteAttributeString("id", "Annotations");
                writer.WriteAttributeString("headerText", Localizer.Replace("AnnotationCategoryHeaderText", "Notes and Attachments"));
                writer.WriteElementString("description", ns, Localizer.Replace("AnnotationCategoryDescription", "Enter optional notes and attach files."));
                writer.WriteStartElement("dataFields", ns);
                // _Annotation_NoteNew dataField
                writer.WriteStartElement("dataField", ns);
                writer.WriteAttributeString("fieldName", "_Annotation_NoteNew");
                writer.WriteAttributeString("columns", "50");
                writer.WriteAttributeString("rows", "7");
                writer.WriteEndElement();
                // _Annotation_AttachmentNew
                writer.WriteStartElement("dataField", ns);
                writer.WriteAttributeString("fieldName", "_Annotation_AttachmentNew");
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.WriteEndElement();
                writer.Close();
                view.AppendChild(sb.ToString());
                _retrieveAnnotations = !(request.Inserting);
                _config.Expressions  = expressions.ToArray();
            }
        }
 protected XPathNavigator SelectField(ControllerConfiguration config, string name)
 {
     return config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}\']", name);
 }
 protected XPathNavigator SelectView(ControllerConfiguration config, string viewId)
 {
     return config.SelectSingleNode("/c:dataController/c:views/c:view[@id=\'{0}\']", viewId);
 }
 protected XPathNavigator SelectDataField(ControllerConfiguration config, string viewId, string fieldName)
 {
     return config.SelectSingleNode("/c:dataController/c:views/c:view[@id=\'{0}\']/.//c:dataField[@fieldName=\'{1}\' or @a" +
             "liasFieldName=\'{1}\']", viewId, fieldName);
 }
 protected XPathNavigator SelectActionGroup(ControllerConfiguration config, string actionGroupId)
 {
     return config.SelectSingleNode("/c:dataController/c:actions/c:actionGroup[@id=\'{0}\']", actionGroupId);
 }
 public static List<UriRestConfig> Enumerate(ControllerConfiguration config)
 {
     List<UriRestConfig> list = new List<UriRestConfig>();
     XPathNavigator restConfigNode = config.SelectSingleNode("/c:dataController/c:restConfig");
     if (restConfigNode != null)
     {
         UriRestConfig urc = null;
         // configuration regex: ^\s*(?'Property'\w+)\s*(:|=)\s*(?'Value'.+?)\s*$
         Match m = Regex.Match(restConfigNode.Value, "^\\s*(?\'Property\'\\w+)\\s*(:|=)\\s*(?\'Value\'.+?)\\s*$", (RegexOptions.IgnoreCase | RegexOptions.Multiline));
         while (m.Success)
         {
             string propertyName = m.Groups["Property"].Value;
             string propertyValue = m.Groups["Value"].Value;
             if (propertyName.Equals("Uri", StringComparison.CurrentCultureIgnoreCase))
                 try
                 {
                     urc = new UriRestConfig(propertyValue);
                     list.Add(urc);
                 }
                 catch (Exception )
                 {
                 }
             else
                 if (urc != null)
                     urc[propertyName] = propertyValue;
             m = m.NextMatch();
         }
     }
     return list;
 }
示例#12
0
        protected virtual void ProcessArguments(ControllerConfiguration config, ActionArgs args)
        {
            if (args.Values == null)
            {
                return;
            }
            var values = new FieldValueDictionary(args);

            _pk = null;
            // detect negative primary keys
            var pkNav = config.SelectSingleNode("/c:dataController/c:fields/c:field[@isPrimaryKey=\'true\']");

            if (pkNav != null)
            {
                FieldValue fvo = null;
                if (values.TryGetValue(pkNav.GetAttribute("name", string.Empty), out fvo))
                {
                    var value = 0;
                    if ((fvo.Value != null) && int.TryParse(Convert.ToString(fvo.Value), out value))
                    {
                        if (value < 0)
                        {
                            if (args.CommandName == "Insert")
                            {
                                // request a new row from business rules
                                var newRowRequest = new PageRequest();
                                newRowRequest.Controller       = args.Controller;
                                newRowRequest.View             = args.View;
                                newRowRequest.Inserting        = true;
                                newRowRequest.RequiresMetaData = true;
                                newRowRequest.MetadataFilter   = new string[] {
                                    "fields"
                                };
                                var page = ControllerFactory.CreateDataController().GetPage(newRowRequest.Controller, newRowRequest.View, newRowRequest);
                                if (page.NewRow != null)
                                {
                                    for (var i = 0; (i < page.NewRow.Length); i++)
                                    {
                                        var newValue = page.NewRow[i];
                                        if (newValue != null)
                                        {
                                            var field = page.Fields[i];
                                            if (field.IsPrimaryKey)
                                            {
                                                // resolve the value of the primary key
                                                ResolvePrimaryKey(args.Controller, fvo.Name, value, newValue);
                                                value        = 0;
                                                fvo.NewValue = newValue;
                                            }
                                            else
                                            {
                                                // inject a missing default value in the arguments
                                                FieldValue newFieldValue = null;
                                                if (values.TryGetValue(field.Name, out newFieldValue))
                                                {
                                                    if (!newFieldValue.Modified)
                                                    {
                                                        newFieldValue.NewValue = newValue;
                                                        newFieldValue.Modified = true;
                                                    }
                                                }
                                                else
                                                {
                                                    var newValues = new List <FieldValue>(args.Values);
                                                    newFieldValue = new FieldValue(field.Name, newValue);
                                                    newValues.Add(newFieldValue);
                                                    args.Values        = newValues.ToArray();
                                                    values[field.Name] = newFieldValue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            // resolve the primary key after the command execution
                            if (value < 0)
                            {
                                if (args.CommandName == "Insert")
                                {
                                    if (pkNav.SelectSingleNode("c:items/@dataController", config.Resolver) == null)
                                    {
                                        _pk          = new FieldValue(fvo.Name, value);
                                        fvo.NewValue = null;
                                        fvo.Modified = false;
                                    }
                                }
                                else
                                {
                                    // otherwise try to resolve the primary key
                                    object resolvedKey = null;
                                    if (_resolvedKeys.TryGetValue(string.Format("{0}${1}", args.Controller, fvo.Value), out resolvedKey))
                                    {
                                        if (fvo.Modified)
                                        {
                                            fvo.NewValue = resolvedKey;
                                        }
                                        else
                                        {
                                            fvo.OldValue = resolvedKey;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            // resolve negative foreign keys
            if (_resolvedKeys.Count > 0)
            {
                var fkIterator = config.Select("/c:dataController/c:fields/c:field[c:items/@dataController]");
                while (fkIterator.MoveNext())
                {
                    FieldValue fvo = null;
                    if (values.TryGetValue(fkIterator.Current.GetAttribute("name", string.Empty), out fvo))
                    {
                        var    itemsDataControllerNav = fkIterator.Current.SelectSingleNode("c:items/@dataController", config.Resolver);
                        object resolvedKey            = null;
                        if (_resolvedKeys.TryGetValue(string.Format("{0}${1}", itemsDataControllerNav.Value, fvo.Value), out resolvedKey))
                        {
                            if (fvo.Modified)
                            {
                                fvo.NewValue = resolvedKey;
                            }
                            else
                            {
                                fvo.OldValue = resolvedKey;
                            }
                        }
                    }
                }
            }
            // scan resolved primary keys and look for the one that are matching the keys referenced in SelectedValues, ExternalFilter, or Filter of the action
            foreach (var resolvedKeyInfo in _resolvedKeys.Keys)
            {
                var    separatorIndex     = resolvedKeyInfo.IndexOf("$");
                var    resolvedController = resolvedKeyInfo.Substring(0, separatorIndex);
                var    unresolvedKeyValue = resolvedKeyInfo.Substring((separatorIndex + 1));
                object resolvedKeyValue   = null;
                if ((args.Controller == resolvedController) && _resolvedKeys.TryGetValue(resolvedKeyInfo, out resolvedKeyValue))
                {
                    var resolvedKeyValueAsString = resolvedKeyValue.ToString();
                    // resolve primary key references in SelectedValues
                    if (args.SelectedValues != null)
                    {
                        for (var selectedValueIndex = 0; (selectedValueIndex < args.SelectedValues.Length); selectedValueIndex++)
                        {
                            var selectedKey = Regex.Split(args.SelectedValues[selectedValueIndex], ",");
                            for (var keyValueIndex = 0; (keyValueIndex < selectedKey.Length); keyValueIndex++)
                            {
                                if (selectedKey[keyValueIndex] == unresolvedKeyValue)
                                {
                                    selectedKey[keyValueIndex] = resolvedKeyValueAsString;
                                    args.SelectedValues[selectedValueIndex] = string.Join(",", selectedKey);
                                    selectedKey = null;
                                    break;
                                }
                            }
                            if (selectedKey == null)
                            {
                                break;
                            }
                        }
                    }
                }
            }
        }
示例#13
0
        protected virtual void ProcessArguments(ControllerConfiguration config, ActionArgs args)
        {
            if (args.Values == null)
            {
                return;
            }
            FieldValueDictionary values = new FieldValueDictionary(args);

            _pk = null;
            // detect negative primary keys
            XPathNavigator pkNav = config.SelectSingleNode("/c:dataController/c:fields/c:field[@isPrimaryKey=\'true\']");

            if (pkNav != null)
            {
                FieldValue fv = null;
                if (values.TryGetValue(pkNav.GetAttribute("name", String.Empty), out fv))
                {
                    int value = 0;
                    if ((fv.NewValue != null) && int.TryParse(Convert.ToString(fv.NewValue), out value))
                    {
                        if (value < 0)
                        {
                            if (args.CommandName == "Insert")
                            {
                                // request a new row from business rules
                                PageRequest newRowRequest = new PageRequest();
                                newRowRequest.Controller       = args.Controller;
                                newRowRequest.View             = args.View;
                                newRowRequest.Inserting        = true;
                                newRowRequest.RequiresMetaData = true;
                                newRowRequest.MetadataFilter   = new string[] {
                                    "fields"
                                };
                                ViewPage page = ControllerFactory.CreateDataController().GetPage(newRowRequest.Controller, newRowRequest.View, newRowRequest);
                                if (page.NewRow != null)
                                {
                                    for (int i = 0; (i < page.NewRow.Length); i++)
                                    {
                                        object newValue = page.NewRow[i];
                                        if (newValue != null)
                                        {
                                            DataField field = page.Fields[i];
                                            if (field.IsPrimaryKey)
                                            {
                                                // resolve the value of the primary key
                                                ResolvePrimaryKey(args.Controller, fv.Name, value, newValue);
                                                value       = 0;
                                                fv.NewValue = newValue;
                                            }
                                            else
                                            {
                                                // inject a missing default value in the arguments
                                                FieldValue newFieldValue = null;
                                                if (values.TryGetValue(field.Name, out newFieldValue))
                                                {
                                                    if (!(newFieldValue.Modified))
                                                    {
                                                        newFieldValue.NewValue = newValue;
                                                        newFieldValue.Modified = true;
                                                    }
                                                }
                                                else
                                                {
                                                    List <FieldValue> newValues = new List <FieldValue>(args.Values);
                                                    newFieldValue = new FieldValue(field.Name, newValue);
                                                    newValues.Add(newFieldValue);
                                                    args.Values        = newValues.ToArray();
                                                    values[field.Name] = newFieldValue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            // resolve the primary key after the command execution
                            if (value < 0)
                            {
                                _pk         = new FieldValue(fv.Name, value);
                                fv.NewValue = null;
                                fv.Modified = false;
                            }
                        }
                    }
                }
            }
            // resolve negative foreign keys
            if (_resolvedKeys.Count > 0)
            {
                XPathNodeIterator fkIterator = config.Select("/c:dataController/c:fields/c:field[c:items/@dataController]");
                while (fkIterator.MoveNext())
                {
                    FieldValue fv = null;
                    if (values.TryGetValue(fkIterator.Current.GetAttribute("name", String.Empty), out fv))
                    {
                        XPathNavigator itemsDataControllerNav = fkIterator.Current.SelectSingleNode("c:items/@dataController", config.Resolver);
                        object         resolvedKey            = null;
                        if (_resolvedKeys.TryGetValue(String.Format("{0}${1}", itemsDataControllerNav.Value, fv.NewValue), out resolvedKey))
                        {
                            fv.NewValue = resolvedKey;
                        }
                    }
                }
            }
        }