private List <FieldValue> CreateActionValues(Stream stream, string contentType, string fileName, int contentLength) { bool deleting = (((contentType == "application/octet-stream") && (contentLength == 0)) && String.IsNullOrEmpty(fileName)); List <string> keyValues = CreateKeyValues(); int keyValueIndex = 0; List <FieldValue> actionValues = new List <FieldValue>(); ControllerConfiguration config = Controller.CreateConfigurationInstance(typeof(Controller), DataController); XPathNodeIterator keyFieldIterator = config.Select("/c:dataController/c:fields/c:field[@isPrimaryKey=\'true\']"); while (keyFieldIterator.MoveNext()) { FieldValue v = new FieldValue(keyFieldIterator.Current.GetAttribute("name", String.Empty)); if (keyValueIndex < keyValues.Count) { v.OldValue = keyValues[keyValueIndex]; v.Modified = false; keyValueIndex++; } actionValues.Add(v); } if (stream != null) { XPathNavigator lengthField = config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}Length\']", ControllerFieldName); if (lengthField != null) { actionValues.Add(new FieldValue(lengthField.GetAttribute("name", String.Empty), contentLength)); if (deleting) { ClearLastFieldValue(actionValues); } } XPathNavigator contentTypeField = config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}ContentType\']", ControllerFieldName); if (contentTypeField != null) { actionValues.Add(new FieldValue(contentTypeField.GetAttribute("name", String.Empty), contentType)); if (deleting) { ClearLastFieldValue(actionValues); } } XPathNavigator fileNameField = config.SelectSingleNode("/c:dataController/c:fields/c:field[@name=\'{0}FileName\']", ControllerFieldName); if (fileNameField != null) { actionValues.Add(new FieldValue(fileNameField.GetAttribute("name", String.Empty), Path.GetFileName(fileName))); if (deleting) { ClearLastFieldValue(actionValues); } } actionValues.Add(new FieldValue(ControllerFieldName, stream)); } return(actionValues); }
protected virtual void InternalEnsureTrackingFields(ViewPage page, ControllerConfiguration config) { bool hasCreatedByUserId = false; bool hasCreatedByUserName = false; bool hasCreatedOn = false; bool hasModifiedByUserId = false; bool hasModifiedByUserName = false; bool hasModifiedOn = false; // detect missing tracking fields foreach (DataField field in page.Fields) { if (!(field.ReadOnly)) { if (IsCreatedByUserIdPattern(field.Name)) { hasCreatedByUserId = true; } if (IsCreatedByUserNamePattern(field.Name)) { hasCreatedByUserName = true; } if (IsCreatedOnPattern(field.Name)) { hasCreatedOn = true; } if (IsModifiedByUserIdPattern(field.Name)) { hasModifiedByUserId = true; } if (IsModifiedByUserNamePattern(field.Name)) { hasModifiedByUserName = true; } if (IsModifiedOnPattern(field.Name)) { hasModifiedOn = true; } } } // Create DataField instances for missing tracking fields XPathNodeIterator fieldIterator = config.Select("/c:dataController/c:fields/c:field[not(@readOnly=\'true\')]"); while (fieldIterator.MoveNext()) { string fieldName = fieldIterator.Current.GetAttribute("name", String.Empty); // ensure that missing "created" data fields are declared if (!(hasCreatedByUserId) && IsCreatedByUserIdPattern(fieldName)) { page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver)); hasCreatedByUserId = true; } if (!(hasCreatedByUserName) && IsCreatedByUserNamePattern(fieldName)) { page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver)); hasCreatedByUserName = true; } if (!(hasCreatedOn) && IsCreatedOnPattern(fieldName)) { page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver)); hasCreatedOn = true; } // ensure that missing "modified" data fields are declared if (!(hasModifiedByUserId) && IsModifiedByUserIdPattern(fieldName)) { page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver)); hasModifiedByUserId = true; } if (!(hasModifiedByUserName) && IsModifiedByUserNamePattern(fieldName)) { page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver)); hasModifiedByUserName = true; } if (!(hasModifiedOn) && IsModifiedOnPattern(fieldName)) { page.Fields.Add(new DataField(fieldIterator.Current, config.Resolver)); hasModifiedOn = true; } } }
protected virtual void InternalProcess(ActionArgs args, ControllerConfiguration config) { bool hasCreatedByUserId = false; bool hasCreatedByUserName = false; bool hasCreatedOn = false; bool hasModifiedByUserId = false; bool hasModifiedByUserName = false; bool hasModifiedOn = false; // assign tracking values to field values passed from the client foreach (FieldValue v in args.Values) { if (!(v.ReadOnly)) { if (!(hasCreatedByUserId) && IsCreatedByUserIdPattern(v.Name)) { hasCreatedByUserId = true; if (v.Value == null) { v.NewValue = UserId; v.Modified = true; } } else if (!(hasCreatedByUserName) && IsCreatedByUserNamePattern(v.Name)) { hasCreatedByUserName = true; if (v.Value == null) { v.NewValue = UserName; v.Modified = true; } } else if (!(hasCreatedOn) && IsCreatedOnPattern(v.Name)) { hasCreatedOn = true; if (v.Value == null) { v.NewValue = DateTime.Now; v.Modified = true; } } else if (!(hasModifiedByUserId) && IsModifiedByUserIdPattern(v.Name)) { hasModifiedByUserId = true; v.NewValue = UserId; v.Modified = true; } else if (!(hasModifiedByUserName) && IsModifiedByUserNamePattern(v.Name)) { hasModifiedByUserName = true; v.NewValue = UserName; v.Modified = true; } else if (!(hasModifiedOn) && IsModifiedOnPattern(v.Name)) { hasModifiedOn = true; v.NewValue = DateTime.Now; v.Modified = true; } } } // assign missing tracking values List <FieldValue> values = new List <FieldValue>(args.Values); XPathNodeIterator fieldIterator = config.Select("/c:dataController/c:fields/c:field[not(@readOnly=\'true\')]"); while (fieldIterator.MoveNext()) { string fieldName = fieldIterator.Current.GetAttribute("name", String.Empty); // ensure that missing "created" values are provided if (args.CommandName == "Insert") { if (!(hasCreatedByUserId) && IsCreatedByUserIdPattern(fieldName)) { hasCreatedByUserId = true; FieldValue v = new FieldValue(fieldName, UserId); values.Add(v); } else if (!(hasCreatedByUserName) && IsCreatedByUserNamePattern(fieldName)) { hasCreatedByUserName = true; FieldValue v = new FieldValue(fieldName, UserName); values.Add(v); } else if (!(hasCreatedOn) && IsCreatedOnPattern(fieldName)) { hasCreatedOn = true; FieldValue v = new FieldValue(fieldName, DateTime.Now); values.Add(v); } } // ensure that missing "modified" values are provided if (!(hasModifiedByUserId) && IsModifiedByUserIdPattern(fieldName)) { hasModifiedByUserId = true; FieldValue v = new FieldValue(fieldName, UserId); values.Add(v); } else if (!(hasModifiedByUserName) && IsModifiedByUserNamePattern(fieldName)) { hasModifiedByUserName = true; FieldValue v = new FieldValue(fieldName, UserName); values.Add(v); } else if (!(hasModifiedOn) && IsModifiedOnPattern(fieldName)) { hasModifiedOn = true; FieldValue v = new FieldValue(fieldName, DateTime.Now); values.Add(v); } } args.Values = values.ToArray(); }