public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var dataType = member.DataType; if (dataType.IsGenericType) { dataType = dataType.GetGenericArguments()[0]; } bool isDateTime = dataType == typeof(DateTime) || dataType == typeof(DateTimeOffset); if (!isDateTime) { context.Log.Error("Property {0}.{1}: DateOnly attribute may be specified only on DataTime or DateTimeOffset properties. ", member.Entity.Name, member.MemberName); return; } //Inject interceptor _defaultSetter = member.SetValueRef; if (dataType == typeof(DateTime)) { member.SetValueRef = this.SetValueDateTime; } else { member.SetValueRef = this.SetValueDateTimeOffset; } }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { if (this.MethodClass != null && this.MethodName != null) { _customMethodInfo = MethodClass.GetMethod(MethodName); if (_customMethodInfo == null) { context.Log.Error("Method {0} specified as Display method for entity {1} not found in type {2}", MethodName, entity.EntityType, MethodClass); return; } entity.DisplayMethod = InvokeCustomDisplay; return; } //Check if Format provided if (string.IsNullOrEmpty(Format)) { context.Log.Error("Invalid Display attribute on entity {0}. You must provide method reference or non-empty Format value.", entity.EntityType); return; } //Parse Format value, build argIndexes from referenced property names StringHelper.TryParseTemplate(Format, out _adjustedFormat, out _propNames); //verify and build arg indexes foreach (var prop in _propNames) { //it might be dotted sequence of props; we check only first property var propSeq = prop.SplitNames('.'); var member = entity.GetMember(propSeq[0]); if (member == null) { context.Log.Error("Invalid Format expression in Display attribute on entity {0}. Property {1} not found.", entity.EntityType, propSeq[0]); } }//foreach entity.DisplayMethod = GetDisplayString; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var entity = member.Entity; var namesArr = StringHelper.SplitNames(this.MemberNames); foreach (var name in namesArr) { var targetMember = entity.GetMember(name); if (targetMember == null) { context.Log.Error("Member {0} referenced in DependsOn attribute on member {1}.{2} not found.", name, entity.Name, member.MemberName); continue; } //add this member to DependentMembers array of targetMember if (targetMember.DependentMembers == null) { targetMember.DependentMembers = new EntityMemberInfo[] { member } } ; else { var mList = targetMember.DependentMembers.ToList(); mList.Add(member); targetMember.DependentMembers = mList.ToArray(); } } //foreach name } // method
/// <summary> /// Print the object's definition to the given text writer. /// </summary> /// <param name="writer">The writer of indented text.</param> public void Print(IndentedTextWriter writer) { writer.WriteLine("object {"); writer.Indent += 2; foreach (string key in constructedAttributeGetters.Keys) { writer.Write(key); writer.Write(" = "); Value value = constructedAttributeGetters[key](this); writer.WriteLine(value); } foreach (string key in attributes.Keys) { writer.Write(key); writer.Write(" : "); Value value = attributes[key]; try { AttributeContext context = dc.GetAttributeContext(key); writer.WriteLine(context.syntax.Unparse(context, value)); } catch { writer.WriteLine(value); } } foreach (ModelObject obj in childs.Values) { obj.Print(writer); } writer.Indent -= 2; writer.WriteLine("}"); }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { base.Apply(context, attribute, member); _member = member; _hashedMember = member.Entity.GetMember(this.PropertyName); if (string.IsNullOrEmpty(PropertyName)) { context.Log.Error("HashFor attribute - PropertyName must be specified. Entity/property: {0}.{1}.", member.Entity.Name, member.MemberName); return; } if (_member.DataType != typeof(int)) { context.Log.Error("HashFor attribute can be used only on int properties. Entity/property: {0}.{1}.", member.Entity.Name, member.MemberName); return; } if (_hashedMember == null) { context.Log.Error("Property {0} referenced in HashFor attribute on property {1} not found on entity {2}.", PropertyName, member.MemberName, member.Entity.Name); return; } if (_hashedMember.DataType != typeof(string)) { context.Log.Error("HashFor attribute on property {0}.{1}: target property must be of string type.", member.Entity.Name, member.MemberName); return; } _oldSetter = _hashedMember.SetValueRef; _hashedMember.SetValueRef = OnSettingValue; }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { if (string.IsNullOrWhiteSpace(this.MemberNames)) { context.Log.Error("Entity {0}: primary key must specify property name(s) when used on Entity interface.", entity.FullName); return; } if (!CreatePrimaryKey(context, entity)) { return; } var error = false; var pkMembers = EntityAttributeHelper.ParseMemberNames(entity, this.MemberNames, errorAction: mn => { context.Log.Error("Entity {0}: property {1} listed in PrimaryKey attribute not found.", entity.FullName, mn); error = true; }); if (error) { return; } foreach (var km in pkMembers) { km.Member.Flags |= EntityMemberFlags.PrimaryKey; entity.PrimaryKey.KeyMembers.Add(km); } }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { // Check size code and lookup in tables if (!string.IsNullOrEmpty(this.SizeCode)) { var sizeTable = context.Model.App.SizeTable; //If there is size code, look it up in SizeTable; first check module-specific value, then global value for the code int size; var fullCode = Sizes.GetFullSizeCode(member.Entity.EntityType.Namespace, this.SizeCode); if (sizeTable.TryGetValue(fullCode, out size)) //check full code with module's namespace prefix { member.Size = size; return; } if (sizeTable.TryGetValue(this.SizeCode, out size)) //check global value, non-module-specific { member.Size = size; return; } } //If size is specified explicitly, use it if (this.Size > 0) { member.Size = Size; if ((this.Options & SizeOptions.AutoTrim) != 0) { member.Flags |= EntityMemberFlags.AutoTrim; } return; } //If no Size code and no value, it is an error, lookup in module settings context.Log.Error("Property {0}.{1}: invalid Size attribute, must specify size code or value", member.Entity.Name, member.MemberName); }
/// <summary> /// Adds an object to DC at parent location. /// The objects content is specified by a sequence of strings where each string /// consists of a pair of attribute name and value. /// </summary> /// <param name="parentDN">The DN of parent.</param> /// <param name="attributes">All attributes of model object.</param> public ModelResult Add(string parentDN, params string[] attributes) { ModelObject parent = TryFindObject(parentDN); if (parent == null) { return(new ModelResult(ResultCode.NoSuchObject, "cannot find '{0}'", parentDN)); } ModelObject obj = new ModelObject(); obj.dc = this; foreach (string line in attributes) { string attr, valueString; string[] splits = line.Split(new char[] { ':' }, 2); if (splits == null || splits.Length != 2) { return(new ModelResult(ResultCode.InvalidAttributeSyntax)); } attr = splits[0].Trim(); valueString = splits[1].Trim(); ModelObject attrObj; if (!TryGetAttribute(splits[0], out attrObj)) { return(new ModelResult(ResultCode.NoSuchAttribute, attr)); } AttributeContext parsingContext = GetAttributeContext(attr); obj[attr] = parsingContext.Parse(valueString); if (Checks.HasDiagnostics) { return(new ModelResult(ResultCode.InvalidAttributeSyntax, Checks.GetAndClearDiagnostics())); } } string rdnName = GetRDNAttributeName(obj); if (rdnName != null) { string rdn = (string)obj[rdnName]; if (parent.childs.ContainsKey(rdn)) { return(new ModelResult(ResultCode.EntryAlreadyExists)); } AddChild(parent, obj); Consistency.Check(new Sequence <ModelObject>(obj)); } if (Checks.HasDiagnostics) { return(new ModelResult(ResultCode.ConstraintViolation, Checks.GetAndClearDiagnostics())); } else { return(ModelResult.Success); } }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { if (string.IsNullOrWhiteSpace(this.MemberNames)) { context.Log.Error("Entity {0}: Index attribute on entity may not have empty member list.", entity.Name); return; } }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { if (entity.DefaultOrderBy != null) { context.Log.Error("More than one OrderBy attribute in entity {0}.", entity.Name); } ConstructOrderBy(context, entity); }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { if (!string.IsNullOrWhiteSpace(this.Name)) { entity.Name = this.Name; } entity.TableName = this.TableName; }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { var srv = context.Model.App.GetService <IDataHistoryService>(); if (srv != null) { srv.RegisterToKeepHistoryData(entity.EntityType); } }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { if (member.Kind != MemberKind.EntityRef) { context.Log.Error("CascadeDelete attribute may be used only on properties that are references to other entities. Property: {0}.{1}", member.Entity.Name, member.MemberName); return; } member.Flags |= EntityMemberFlags.CascadeDelete; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { member.Flags |= EntityMemberFlags.Nullable; if (member.DataType.IsValueType) { member.Flags |= EntityMemberFlags.ReplaceDefaultWithNull; member.GetValueRef = MemberValueGettersSetters.GetValueTypeReplaceNullWithDefault; member.SetValueRef = MemberValueGettersSetters.SetValueTypeReplaceDefaultWithNull; } }
public override void Apply(AttributeContext context, Attribute attribute, EntityInfo entity) { _method = MethodClass.GetMethod(MethodName); if (_method == null) { context.Log.Error("Method {0} specified as Validation method for entity {1} not found in type {2}", MethodName, entity.EntityType, MethodClass); } entity.Events.ValidatingChanges += Events_Validating; }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var entity = member.Entity; if (!CreatePrimaryKey(context, entity)) { return; } entity.PrimaryKey.KeyMembers.Add(new EntityKeyMemberInfo(member, false)); member.Flags |= EntityMemberFlags.PrimaryKey; }
private static bool TryResolveInsertText(string baseInsertText, AttributeContext context, [NotNullWhen(true)] out string?snippetText) { if (context == AttributeContext.FullSnippet) { snippetText = $"{baseInsertText}=\"$0\""; return(true); } snippetText = null; return(false); }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { member.Flags |= EntityMemberFlags.IsOwner; if (member.Entity.OwnerMember == null) { member.Entity.OwnerMember = member; } else { context.Log.Error("More than one Owner attribute is specified on entity {0}.", member.Entity.FullName); } }
// Token: 0x060021C2 RID: 8642 RVA: 0x000A8D80 File Offset: 0x000A6F80 private void WriteProperties(ArrayList xamlNodes, ArrayList list, int listIndex, DefAttributeData data) { if (list != null && listIndex < list.Count) { ArrayList arrayList = new ArrayList(list.Count / 4); for (int i = listIndex; i < list.Count; i += 4) { if (i > list.Count - 3 || list[i + 1] is string || (char)list[i + 1] != '=') { this.ThrowException("ParserMarkupExtensionNoNameValue", data.Args, data.LineNumber, data.LinePosition); } string text = list[i] as string; text = text.Trim(); if (arrayList.Contains(text)) { this.ThrowException("ParserDuplicateMarkupExtensionProperty", text, data.LineNumber, data.LinePosition); } arrayList.Add(text); int num = text.IndexOf(':'); string text2 = (num < 0) ? text : text.Substring(num + 1); string prefix = (num < 0) ? string.Empty : text.Substring(0, num); string attributeNamespaceUri = this.ResolveAttributeNamespaceURI(prefix, text2, data.TargetNamespaceUri); object info; string text3; string text4; Type type; string text5; AttributeContext attributeContext = this.GetAttributeContext(data.TargetType, data.TargetNamespaceUri, attributeNamespaceUri, text2, out info, out text3, out text4, out type, out text5); string value = list[i + 2] as string; AttributeData attributeData = this.IsMarkupExtensionAttribute(data.TargetType, text, ref value, data.LineNumber, data.LinePosition, data.Depth, info); list[i + 2] = value; if (data.IsUnknownExtension) { return; } if (attributeData != null) { if (attributeData.IsSimple) { this.CompileProperty(xamlNodes, text, attributeData.Args, data.TargetType, data.TargetNamespaceUri, attributeData, attributeData.LineNumber, attributeData.LinePosition, attributeData.Depth); } else { this.CompileAttribute(xamlNodes, attributeData); } } else { this.CompileProperty(xamlNodes, text, (string)list[i + 2], data.TargetType, data.TargetNamespaceUri, null, data.LineNumber, data.LinePosition, data.Depth); } } } }
/// <summary> /// Mathc method. /// </summary> /// <param name="obj">The second value.</param> /// <returns>On success it returns true.</returns> public override bool Match(ModelObject obj) { Value assignedValue = obj[attributeForEqual]; if (assignedValue == null) { return(false); } AttributeContext context = obj.dc.GetAttributeContext(attributeForEqual); Value parsedValue = context.Parse(valueForEqual); return(context.Equals(parsedValue, assignedValue)); }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { if (member.Kind != MemberKind.EntityRef) { context.Log.Error( "GrantAccessTo attribute may be used only on properties that are references to other entities. Property: {0}.{1}", member.Entity.Name, member.MemberName); return; } _member = member; //Delay until model construction must be completed - we need all member properties assigned to properly create member masks member.Entity.Module.App.AppEvents.Initializing += AppEvents_Initializing; }
// Token: 0x060021C5 RID: 8645 RVA: 0x000A8FFC File Offset: 0x000A71FC private void CompileProperty(ArrayList xamlNodes, string name, string value, Type parentType, string parentTypeNamespaceUri, AttributeData data, int lineNumber, int linePosition, int depth) { MarkupExtensionParser.RemoveEscapes(ref name); MarkupExtensionParser.RemoveEscapes(ref value); int num = name.IndexOf(':'); string text = (num < 0) ? name : name.Substring(num + 1); string text2 = (num < 0) ? string.Empty : name.Substring(0, num); string text3 = this.ResolveAttributeNamespaceURI(text2, text, parentTypeNamespaceUri); if (string.IsNullOrEmpty(text3)) { this.ThrowException("ParserPrefixNSProperty", text2, name, lineNumber, linePosition); } object obj; string assemblyName; string typeFullName; Type type; string propertyName; AttributeContext attributeContext = this.GetAttributeContext(parentType, parentTypeNamespaceUri, text3, text, out obj, out assemblyName, out typeFullName, out type, out propertyName); if (attributeContext != AttributeContext.Property) { this.ThrowException("ParserMarkupExtensionUnknownAttr", text, parentType.FullName, lineNumber, linePosition); } MemberInfo memberInfo = obj as MemberInfo; if (data == null || !data.IsSimple) { XamlPropertyNode value2 = new XamlPropertyNode(lineNumber, linePosition, depth, obj, assemblyName, typeFullName, propertyName, value, BamlAttributeUsage.Default, true); xamlNodes.Add(value2); return; } if (data.IsTypeExtension) { string valueTypeFullName = value; string valueAssemblyName = null; Type typeFromBaseString = this._parserContext.XamlTypeMapper.GetTypeFromBaseString(value, this._parserContext, true); if (typeFromBaseString != null) { valueTypeFullName = typeFromBaseString.FullName; valueAssemblyName = typeFromBaseString.Assembly.FullName; } XamlPropertyWithTypeNode value3 = new XamlPropertyWithTypeNode(data.LineNumber, data.LinePosition, data.Depth, obj, assemblyName, typeFullName, text, valueTypeFullName, valueAssemblyName, typeFromBaseString, string.Empty, string.Empty); xamlNodes.Add(value3); return; } XamlPropertyWithExtensionNode value4 = new XamlPropertyWithExtensionNode(data.LineNumber, data.LinePosition, data.Depth, obj, assemblyName, typeFullName, text, value, data.ExtensionTypeId, data.IsValueNestedExtension, data.IsValueTypeExtension); xamlNodes.Add(value4); }
private void RetrieveEntryPoints() { RestRequest request = new RestRequest(); request.Resource = "/v2"; var response = RestClient.Execute <EntryPoint>(request); EntryPoints = response.Data; EntityCollection = new EntityCollection(this, EntryPoints.Entities); EntityContext = new EntityContext(this, EntryPoints.Entities); EntityIngestion = new EntityIngestion(this, EntryPoints.Entities); AttributeContext = new AttributeContext(this, EntryPoints.Entities); Initialized = true; }
private bool CreatePrimaryKey(AttributeContext context, EntityInfo entity) { if (entity.PrimaryKey != null) { context.Log.Error("More than one primary key specified on entity {0}", entity.FullName); return(false); } entity.PrimaryKey = new EntityKeyInfo("PK_" + entity.Name, KeyType.PrimaryKey, entity); if (IsClustered) { entity.PrimaryKey.KeyType |= KeyType.Clustered; } return(true); }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var dataType = member.DataType; member.Flags |= EntityMemberFlags.Utc; if (member.DataType != typeof(DateTime) && member.DataType != typeof(DateTime?)) { context.Log.Error("Utc attribute may be specified only on DataTime properties. Entity.Member: {0}.{1}", member.Entity.Name, member.MemberName); return; } //Inject interceptor _defaultGetter = member.GetValueRef; _defaultSetter = member.SetValueRef; //member.GetValueRef = this.GetValueInterceptor; member.SetValueRef = this.SetValueInterceptor; }
private bool CheckDataType(AttributeContext context, params Type[] types) { var dt = _member.DataType; if (dt.IsGenericType) { dt = dt.GetGenericArguments()[0]; // check for DateTime? } if (types.Contains(dt)) { return(true); } context.Log.Error("Entity member {0}.{1}: Auto({2}) attribute may be set only on member of type(s): {3}. ", _member.Entity, _member.MemberName, this.Type, string.Join(", ", types.Select(t => t.Name))); return(false); }
/// <summary> /// Constructs a new replica. /// </summary> /// <param name="dc">Domain controller</param> /// <param name="kind">Replica kind.</param> /// <param name="dn">Distinguished name.</param> /// <param name="partial">Is it partial replica</param> public Replica(ModelDomainController dc, ReplicaKind kind, string dn, bool partial) { this.dc = dc; this.kind = kind; this.dn = dn; this.partial = partial; this.root = new ModelObject(); root.dc = dc; AttributeContext objectClassContext = new AttributeContext( null, StandardNames.objectClass, Syntax.StringObjectIdentifier, false, null); AttributeContext cnContext = new AttributeContext( null, StandardNames.cn, Syntax.StringUnicode); switch (kind) { case ReplicaKind.Domain: root[StandardNames.objectClass] = objectClassContext.Parse(StandardNames.top + ";" + StandardNames.domainDNS); break; case ReplicaKind.Application: root[StandardNames.objectClass] = objectClassContext.Parse(StandardNames.top + ";" + StandardNames.domainDNS); break; case ReplicaKind.Configuration: root[StandardNames.cn] = cnContext.Parse("Configuration"); root[StandardNames.objectClass] = objectClassContext.Parse(StandardNames.top + ";" + StandardNames.configuration); break; case ReplicaKind.Schema: root[StandardNames.cn] = cnContext.Parse("Schema"); root[StandardNames.objectClass] = objectClassContext.Parse(StandardNames.top + ";" + StandardNames.dMD); break; } }
//This is a special case - OrderBy attribute specifies the order of entities in list property. public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { var entity = member.Entity; if (member.Kind != MemberKind.EntityList) { context.Log.Error("OrderBy attribute may be used only on entities or list properties. Entity: {0}, property: {1}", entity.Name, member.MemberName); return; } var fromKey = member.ChildListInfo.ParentRefMember.ReferenceInfo.FromKey; fromKey.OrderByForSelect = EntityAttributeHelper.ParseMemberNames(member.ChildListInfo.TargetEntity, this.OrderByList, ordered: true, errorAction: spec => { context.Log.Error("Invalid member/spec: {0} in {1} attribute, property {2}.{3}", spec, this.GetAttributeName(), entity.Name, member.MemberName); }); }
public override void Apply(AttributeContext context, Attribute attribute, EntityMemberInfo member) { base.Apply(context, attribute, member); if (member.Kind != MemberKind.EntityRef) { context.Log.Error( "PropagateUpdatedOn attribute may be used only on properties that are references to other entities. Property: {0}.{1}", member.Entity.Name, member.MemberName); return; } _member = member; //Set interceptors member.Entity.Events.Modified += Events_ModifyingDeleting; member.Entity.Events.Deleting += Events_ModifyingDeleting; _defaultValueSetter = member.SetValueRef; member.SetValueRef = SetMemberValue; }
public AttributeContext attribute() { AttributeContext _localctx = new AttributeContext(Context, State); EnterRule(_localctx, 6, RULE_attribute); try { State = 69; ErrorHandler.Sync(this); switch (Interpreter.AdaptivePredict(TokenStream, 8, Context)) { case 1: EnterOuterAlt(_localctx, 1); { State = 57; Match(Name); State = 58; Match(EQUALS); State = 59; Match(T__3); State = 60; Match(STRING); State = 61; Match(T__3); } break; case 2: EnterOuterAlt(_localctx, 2); { State = 62; Match(Name); State = 63; Match(EQUALS); State = 64; Match(FIGO); State = 65; Match(Name); State = 66; Match(EQUALS); State = 67; Match(STRING); State = 68; Match(FIGCL); } break; } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return(_localctx); }
private void IterateNodes(DependencyNode node, AttributeContext<DependsOnAttribute> context, IModule item, ref bool added) { if (node.Nodes.ContainsKey(context.AttributeInstance.DependencyType)) { node.Nodes[context.AttributeInstance.DependencyType].Nodes.Add(item.GetType(), new DependencyNode(item)); added = true; } else if (node.Nodes.Count == 0) { added = false; } else { foreach (var child in node.Nodes.Values) { IterateNodes(child, context, item, ref added); } } }