Example #1
0
        public void ExpandSimpleAttributeMVStringWithTransforms()
        {
            AcmaSchemaAttribute   attribute    = ActiveConfig.DB.GetAttribute("mailAlternateAddresses");
            AcmaSchemaObjectClass schemaObject = ActiveConfig.DB.GetObjectClass("person");
            string declarationString           = "{mailAlternateAddresses>>ToUpperCase}";
            AttributeDeclarationParser p       = new AttributeDeclarationParser(declarationString);
            AttributeDeclaration       target  = p.GetAttributeDeclaration();

            CSEntryChange sourceObject = CSEntryChange.Create();

            sourceObject.ObjectModificationType = ObjectModificationType.Add;
            sourceObject.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, new List <object>()
            {
                "*****@*****.**", "*****@*****.**", "*****@*****.**"
            }));

            object value = target.Expand(sourceObject);

            if (value == null)
            {
                Assert.Fail("The declaration string did not return a value");
            }
            else if (!(value is IList <object>))
            {
                Assert.Fail("The declaration string returned the wrong data type");
            }
            else if (!((IList <object>)value).SequenceEqual(new List <object>()
            {
                "*****@*****.**", "*****@*****.**", "*****@*****.**"
            }))
            {
                Assert.Fail("The declaration string did not return the expected value");
            }
        }
Example #2
0
 public static List <string> ParseStringList(this AttributeDeclaration attr)
 {
     return(attr.Parameters
            .Select(p => p?.Value as string)
            .Where(s => !string.IsNullOrWhiteSpace(s))
            .ToList());
 }
Example #3
0
        private void AttachXmlElementAttributes(PropertyDeclaration p, FieldInfo f)
        {
            string customName = null;

            // if array is type add element
            if (f.FieldType.IsArray && f.FieldType.GetElementType() != typeof(Object))
            {
                AttributeDeclaration attr = p.CustomAttributes.Add(typeof(XmlElementAttribute));
                attr.Arguments.Add("ElementName", Expr.Prim(f.Name));
                //MMI:attr.Arguments.Add("Type",Expr.Prim(MapType(f.FieldType.GetElementType()).Name));
                attr.Arguments.Add("Type", Expr.TypeOf(MapType(f.FieldType.GetElementType())));
                customName = f.Name;
            }

            // attach xml elements
            foreach (XmlElementAttribute el in f.GetCustomAttributes(typeof(XmlElementAttribute), true))
            {
                if (customName == el.ElementName)
                {
                    continue;
                }
                AttributeDeclaration attr = p.CustomAttributes.Add(typeof(XmlElementAttribute));
                attr.Arguments.Add("ElementName", Expr.Prim(el.ElementName));
                if (el.Type != null)
                {
                    //MMI:attr.Arguments.Add("Type",Expr.Prim(MapType(el.Type).Name));
                    attr.Arguments.Add("Type", Expr.TypeOf(MapType(el.Type)));
                }
            }
        }
Example #4
0
        public override object VisitColumnDefinition([NotNull] MiniSQLParser.ColumnDefinitionContext context)
        {
            AttributeDeclaration declaration = (AttributeDeclaration)Visit(context.fieldDefinition());

            declaration.AttributeName = context.columnName().GetText();
            return(declaration);
        }
Example #5
0
        private void GenerateEnumType(Type t)
        {
            EnumDeclaration e = this.ns.Enums[this.conformer.ToCapitalized(t.Name)];

            e.CustomAttributes.Add(typeof(SerializableAttribute));

            if (e == null)
            {
                throw new Exception();
            }
            // generate fields and properties
            foreach (FieldInfo f in t.GetFields())
            {
                if (f.Name == "Value__")
                {
                    continue;
                }

                FieldDeclaration field = e.AddField(f.Name);
                // add XmlEnum attribute
                AttributeDeclaration xmlEnum = field.CustomAttributes.Add(typeof(XmlEnumAttribute));
                AttributeArgument    arg     = xmlEnum.Arguments.Add(
                    "Name",
                    Expr.Prim(f.Name)
                    );
            }
        }
Example #6
0
        public override object VisitDataType([NotNull] MiniSQLParser.DataTypeContext context)
        {
            AttributeDeclaration attribute = new AttributeDeclaration();
            string type = context.type.Text.ToLower();

            switch (type)
            {
            case "int":
                attribute.Type = AttributeTypes.Int;
                break;

            case "float":
                attribute.Type = AttributeTypes.Float;
                break;

            case "char":
                attribute.Type = AttributeTypes.Char;
                if (context.fieldLength() != null)
                {
                    attribute.CharLimit = (int)Visit(context.fieldLength());
                }
                break;
            }
            return(attribute);
        }
Example #7
0
        public void ExpandSimpleAttributeSVStringWithTransforms()
        {
            AcmaSchemaAttribute   attribute    = ActiveConfig.DB.GetAttribute("mail");
            AcmaSchemaObjectClass schemaObject = ActiveConfig.DB.GetObjectClass("person");
            string declarationString           = "{mail>>ToUpperCase}";
            AttributeDeclarationParser p       = new AttributeDeclarationParser(declarationString);
            AttributeDeclaration       target  = p.GetAttributeDeclaration();

            CSEntryChange sourceObject = CSEntryChange.Create();

            sourceObject.ObjectModificationType = ObjectModificationType.Add;
            sourceObject.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, "*****@*****.**"));

            object value = target.Expand(sourceObject).First();

            if (value == null)
            {
                Assert.Fail("The declaration string did not return a value");
            }
            else if (!(value is string))
            {
                Assert.Fail("The declaration string returned the wrong data type");
            }
            else if ((string)value != "*****@*****.**")
            {
                Assert.Fail("The declaration string did not return the expected value");
            }
        }
Example #8
0
        public void ExpandSimpleAttributeSVBoolean()
        {
            AcmaSchemaAttribute   attribute    = ActiveConfig.DB.GetAttribute("connectedToCallista");
            AcmaSchemaObjectClass schemaObject = ActiveConfig.DB.GetObjectClass("person");
            string declarationString           = "{connectedToCallista}";
            AttributeDeclarationParser p       = new AttributeDeclarationParser(declarationString);
            AttributeDeclaration       target  = p.GetAttributeDeclaration();

            CSEntryChange sourceObject = CSEntryChange.Create();

            sourceObject.ObjectModificationType = ObjectModificationType.Add;
            sourceObject.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, true));

            object value = target.Expand(sourceObject).First();

            if (value == null)
            {
                Assert.Fail("The declaration string did not return a value");
            }
            else if (!(value is bool))
            {
                Assert.Fail("The declaration string returned the wrong data type");
            }
            else if ((bool)value != true)
            {
                Assert.Fail("The declaration string did not return the expected value");
            }
        }
Example #9
0
        public void ExpandSimpleAttributeSVBinary()
        {
            AcmaSchemaAttribute   attribute    = ActiveConfig.DB.GetAttribute("objectSid");
            AcmaSchemaObjectClass schemaObject = ActiveConfig.DB.GetObjectClass("person");
            string declarationString           = "{objectSid}";
            AttributeDeclarationParser p       = new AttributeDeclarationParser(declarationString);
            AttributeDeclaration       target  = p.GetAttributeDeclaration();

            CSEntryChange sourceObject = CSEntryChange.Create();

            sourceObject.ObjectModificationType = ObjectModificationType.Add;
            sourceObject.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, new byte[] { 0, 1, 2, 3, 4 }));

            object value = target.Expand(sourceObject).First();

            if (value == null)
            {
                Assert.Fail("The declaration string did not return a value");
            }
            else if (!(value is byte[]))
            {
                Assert.Fail("The declaration string returned the wrong data type");
            }
            else if (!((byte[])value).SequenceEqual(new byte[] { 0, 1, 2, 3, 4 }))
            {
                Assert.Fail("The declaration string did not return the expected value");
            }
        }
        public static AttributeDeclaration GetAttributeDeclaration(Attribute attribute, ClientCodeGenerator textTemplateClientCodeGenerator, bool forcePropagation)
        {
            Type attributeType = attribute.GetType();

            // Check if this attribute should be blocked
            if (IsAttributeBlocked(attributeType))
            {
                return(null);
            }

            ICustomAttributeBuilder cab = GetCustomAttributeBuilder(attributeType);
            AttributeDeclaration    attributeDeclaration = null;

            if (cab != null)
            {
                try
                {
                    attributeDeclaration = cab.GetAttributeDeclaration(attribute);
                }
                catch (AttributeBuilderException)
                {
                    return(null);
                }
                if (attributeDeclaration != null)
                {
                    if (!forcePropagation)
                    {
                        // Verify attribute's shared type|property|method requirements are met
                        ValidateAttributeDeclarationRequirements(attributeDeclaration, textTemplateClientCodeGenerator);
                    }
                }
            }

            return(attributeDeclaration);
        }
Example #11
0
 public IType checkAttribute(Context context, CategoryDeclaration decl, String name)
 {
     if (decl.Storable && "dbId" == name)
     {
         return(AnyType.Instance);
     }
     else if (decl.hasAttribute(context, name))
     {
         AttributeDeclaration ad = context.getRegisteredDeclaration <AttributeDeclaration>(name);
         if (ad == null)
         {
             throw new SyntaxError("Unknown atttribute:" + name);
         }
         else
         {
             return(ad.GetIType(context));
         }
     }
     else if ("text" == name)
     {
         return(TextType.Instance);
     }
     else if (decl.hasMethod(context, name))
     {
         IMethodDeclaration method = decl.getMemberMethods(context, name).GetFirst();
         return(new MethodType(method));
     }
     else
     {
         throw new SyntaxError("No attribute:" + name + " in category:" + GetTypeName());
     }
 }
Example #12
0
        public void ExpandSimpleAttributeMVReference()
        {
            AcmaSchemaAttribute   attribute    = ActiveConfig.DB.GetAttribute("directReports");
            AcmaSchemaObjectClass schemaObject = ActiveConfig.DB.GetObjectClass("person");
            string declarationString           = "{directReports}";
            AttributeDeclarationParser p       = new AttributeDeclarationParser(declarationString);
            AttributeDeclaration       target  = p.GetAttributeDeclaration();

            CSEntryChange sourceObject = CSEntryChange.Create();

            sourceObject.ObjectModificationType = ObjectModificationType.Add;
            sourceObject.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, new List <object>()
            {
                new Guid("fb116a90-35e3-47e9-92b7-679c4821e648"), new Guid("352285df-3fdc-468e-9412-70d62a62cefe"), new Guid("50ac8dbb-15fe-485c-8f02-87a77ab68a7b")
            }));

            object value = target.Expand(sourceObject);

            if (value == null)
            {
                Assert.Fail("The declaration string did not return a value");
            }
            else if (!(value is IList <object>))
            {
                Assert.Fail("The declaration string returned the wrong data type");
            }
            else if (!((IList <object>)value).SequenceEqual(new List <object>()
            {
                new Guid("fb116a90-35e3-47e9-92b7-679c4821e648"), new Guid("352285df-3fdc-468e-9412-70d62a62cefe"), new Guid("50ac8dbb-15fe-485c-8f02-87a77ab68a7b")
            }))
            {
                Assert.Fail("The declaration string did not return the expected value");
            }
        }
Example #13
0
        public void ExpandSimpleAttributeMVLongWithTransforms()
        {
            AcmaSchemaAttribute   attribute    = ActiveConfig.DB.GetAttribute("expiryDates");
            AcmaSchemaObjectClass schemaObject = ActiveConfig.DB.GetObjectClass("person");
            string declarationString           = "{expiryDates>>Add30Days}";
            AttributeDeclarationParser p       = new AttributeDeclarationParser(declarationString);
            AttributeDeclaration       target  = p.GetAttributeDeclaration();

            CSEntryChange sourceObject = CSEntryChange.Create();

            sourceObject.ObjectModificationType = ObjectModificationType.Add;
            sourceObject.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, new List <object>()
            {
                1L, 2L, 3L, 4L
            }));

            object value = target.Expand(sourceObject);

            if (value == null)
            {
                Assert.Fail("The declaration string did not return a value");
            }
            else if (!(value is IList <object>))
            {
                Assert.Fail("The declaration string returned the wrong data type");
            }
            else if (!((IList <object>)value).SequenceEqual(new List <object>()
            {
                25920000000001L, 25920000000002L, 25920000000003L, 25920000000004L
            }))
            {
                Assert.Fail("The declaration string did not return the expected value");
            }
        }
Example #14
0
        public void ExpandSimpleAttributeSVLong()
        {
            AcmaSchemaAttribute attribute     = ActiveConfig.DB.GetAttribute("unixGid");
            string declarationString          = "{unixGid}";
            AttributeDeclarationParser p      = new AttributeDeclarationParser(declarationString);
            AttributeDeclaration       target = p.GetAttributeDeclaration();

            CSEntryChange sourceObject = CSEntryChange.Create();

            sourceObject.ObjectModificationType = ObjectModificationType.Add;
            sourceObject.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, 99L));

            object value = target.Expand(sourceObject).First();

            if (value == null)
            {
                Assert.Fail("The declaration string did not return a value");
            }
            else if (!(value is long))
            {
                Assert.Fail("The declaration string returned the wrong data type");
            }
            else if ((long)value != 99L)
            {
                Assert.Fail("The declaration string did not return the expected value");
            }
        }
Example #15
0
        public void interpretQuery(Context context, IQueryBuilder builder)
        {
            AttributeDeclaration decl = left.CheckAttribute(context);

            if (decl == null || !decl.Storable)
            {
                throw new SyntaxError("Unable to interpret predicate");
            }
            IValue        value = right.interpret(context);
            AttributeInfo info  = decl.getAttributeInfo();

            if (value is IInstance)
            {
                value = ((IInstance)value).GetMemberValue(context, "dbId", false);
            }
            MatchOp matchOp = getMatchOp();

            builder.Verify(info, matchOp, value == null ? null : value.GetStorableData());
            switch (oper)
            {
            case CmpOp.GTE:
            case CmpOp.LTE:
                builder.Not();
                break;
            }
        }
Example #16
0
        public void ExpandSimpleAttributeSVLongWithTransforms()
        {
            AcmaSchemaAttribute   attribute    = ActiveConfig.DB.GetAttribute("sapExpiryDate");
            AcmaSchemaObjectClass schemaObject = ActiveConfig.DB.GetObjectClass("person");
            string declarationString           = "{sapExpiryDate>>Add30Days}";
            AttributeDeclarationParser p       = new AttributeDeclarationParser(declarationString);
            AttributeDeclaration       target  = p.GetAttributeDeclaration();

            CSEntryChange sourceObject = CSEntryChange.Create();

            sourceObject.ObjectModificationType = ObjectModificationType.Add;
            sourceObject.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, 1L));

            object value = target.Expand(sourceObject).First();

            if (value == null)
            {
                Assert.Fail("The declaration string did not return a value");
            }
            else if (!(value is long))
            {
                Assert.Fail("The declaration string returned the wrong data type");
            }
            else if ((long)value != 25920000000001L)
            {
                Assert.Fail("The declaration string did not return the expected value");
            }
        }
Example #17
0
        public void ExpandSimpleAttributeSVReference()
        {
            AcmaSchemaAttribute   attribute    = ActiveConfig.DB.GetAttribute("supervisor");
            AcmaSchemaObjectClass schemaObject = ActiveConfig.DB.GetObjectClass("person");
            string declarationString           = "{supervisor}";
            AttributeDeclarationParser p       = new AttributeDeclarationParser(declarationString);
            AttributeDeclaration       target  = p.GetAttributeDeclaration();


            CSEntryChange sourceObject = CSEntryChange.Create();

            sourceObject.ObjectModificationType = ObjectModificationType.Add;
            sourceObject.AttributeChanges.Add(AttributeChange.CreateAttributeAdd(attribute.Name, new Guid("8c3cbf4e-5216-4a04-9140-b0b11020fa4c")));

            object value = target.Expand(sourceObject).First();

            if (value == null)
            {
                Assert.Fail("The declaration string did not return a value");
            }
            else if (!(value is Guid))
            {
                Assert.Fail("The declaration string returned the wrong data type");
            }
            else if ((Guid)value != new Guid("8c3cbf4e-5216-4a04-9140-b0b11020fa4c"))
            {
                Assert.Fail("The declaration string did not return the expected value");
            }
        }
Example #18
0
 private IValue autocast(AttributeDeclaration decl, IValue value)
 {
     if (value != null && value is prompto.value.IntegerValue && decl.getIType() == DecimalType.Instance)
     {
         value = new DecimalValue(((prompto.value.IntegerValue)value).DoubleValue);
     }
     return(value);
 }
Example #19
0
        public override void check(Context context)
        {
            AttributeDeclaration actual = context.getRegisteredDeclaration <AttributeDeclaration>(name);

            if (actual == null)
            {
                throw new SyntaxError("Unknown attribute: \"" + name + "\"");
            }
        }
Example #20
0
        /// <summary>
        /// Returns a representative <see cref="AttributeDeclaration"/> for a given <see cref="Attribute"/> instance.
        /// </summary>
        /// <param name="attribute">An attribute instance to create a <see cref="AttributeDeclaration"/> for.</param>
        /// <returns>A <see cref="AttributeDeclaration"/> representing the <paramref name="attribute"/>.</returns>
        public override AttributeDeclaration GetAttributeDeclaration(Attribute attribute)
        {
            ValidationAttribute  validationAttribute  = (ValidationAttribute)attribute;
            AttributeDeclaration attributeDeclaration = base.GetAttributeDeclaration(attribute);

            RegisterSharedResources(validationAttribute, attributeDeclaration);

            return(attributeDeclaration);
        }
Example #21
0
        public AttributeDeclaration Visit(AttributeDeclaration attribute)
        {
            if (XenkoAttributes.AvailableAttributes.Contains(attribute.Name))
            {
                return(null);
            }

            return(attribute);
        }
Example #22
0
        public override Node Visit(AttributeDeclaration attribute)
        {
            if (StrideAttributes.AvailableAttributes.Contains(attribute.Name))
            {
                return(null);
            }

            return(attribute);
        }
Example #23
0
 public static bool ParseBool(this AttributeDeclaration attr, int index = 0)
 {
     if (attr.Parameters.Count > index)
     {
         if (bool.TryParse(attr.Parameters[index].Text, out var value))
         {
             return(value);
         }
     }
     return(default);
Example #24
0
 public static List <string> ParseStringAsCommaSeparatedList(this AttributeDeclaration attr)
 {
     return(attr.Parameters
            .Select(p => p?.Value as string)
            .SelectMany(s => s.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            .Where(s => !string.IsNullOrWhiteSpace(s))
            .Select(s => s.Trim())
            .Distinct()
            .ToList());
 }
Example #25
0
        public void parsesArrayAttribute()
        {
            String               statement = "attribute id : Integer[]; ";
            OTestParser          parser    = new OTestParser(statement);
            AttributeDeclaration ad        = parser.parse_attribute_declaration();

            Assert.IsNotNull(ad);
            Assert.AreEqual("id", ad.GetName());
            Assert.AreEqual("Integer[]", ad.getIType().GetTypeName());
        }
Example #26
0
        public void testArrayAttribute()
        {
            String               statement = "define id as Integer[] attribute";
            ETestParser          parser    = new ETestParser(statement, false);
            AttributeDeclaration ad        = parser.parse_attribute_declaration();

            Assert.IsNotNull(ad);
            Assert.AreEqual("id", ad.GetName());
            Assert.AreEqual("Integer[]", ad.getIType().GetTypeName());
        }
Example #27
0
        public override object VisitFieldDefinition([NotNull] MiniSQLParser.FieldDefinitionContext context)
        {
            AttributeDeclaration declaration = (AttributeDeclaration)Visit(context.dataType());

            // workaround
            if (context.columnAttribute(0) != null)
            {
                declaration.IsUnique = true;
            }
            return(declaration);
        }
Example #28
0
 public override void check(Context context)
 {
     type.checkExists(context);
     foreach (String attribute in attributes)
     {
         AttributeDeclaration actual = context.getRegisteredDeclaration <AttributeDeclaration>(attribute);
         if (actual == null && attribute != "text")
         {
             throw new SyntaxError("Unknown attribute: \"" + attribute + "\"");
         }
     }
 }
Example #29
0
        public override IQueryElement VisitAttribute_dec_stm([NotNull] QueryGrammarParser.Attribute_dec_stmContext context)
        {
            AttributeDeclaration attribute = new AttributeDeclaration();

            attribute.Name = context.NAME().GetText();

            IQueryElement dateType = Visit(context.dataType());

            attribute.Add(dateType);

            return(attribute);
        }
Example #30
0
 private static IType fieldType(Context context, String name, Object data)
 {
     if ("dbId".Equals(name))
     {
         return(typeToIType(data.GetType()));
     }
     else
     {
         AttributeDeclaration decl = context.getRegisteredDeclaration <AttributeDeclaration>(name);
         return(decl.getIType());
     }
 }