Beispiel #1
0
        private void GetOtmRealationValues(ref EntityBase entity, DataRow row,
                                           RelationAttribute relAttr, PropertyDescription property)
        {
            ObjectDescription od = ClassFactory.GetObjectDescription(ReflectedType, _ps);

            Cryptany.Core.DPO.Mapper m   = new Mapper(relAttr.RelatedType, _ps);
            DataRelation             rel = ForeignKeys[property];

            //foreach ( DataRelation r in UnderlyngDataSet.Tables[Mapper.TableName].ChildRelations )
            //{
            //    if ( r.ChildTable == UnderlyngDataSet.Tables[m.TableName] )
            //        rel = r;
            //}
            //if ( rel == null )
            //    throw new Exception("The child relation was not found");

            (property.GetValue(entity) as IList).Clear();

            string relatedTypeIdField = ClassFactory.GetObjectDescription(relAttr.RelatedType, _ps).IdField.Name;

            foreach (DataRow childrow in entity.SourceRow.GetChildRows(rel))
            {
                object childid = childrow[m[relatedTypeIdField]];
                if (childid == null || childid == DBNull.Value)
                {
                    continue;
                }
                EntityBase e = _ps.GetEntityById(relAttr.RelatedType, childid);
                (property.GetValue(entity) as IList).Add(e);
            }
        }
Beispiel #2
0
        public static string CreateMtmDelete(PropertyDescription pd, PersistentStorage ps, IList <EntityBase> entities)
        {
            RelationAttribute attr = pd.GetAttribute <RelationAttribute>();

            if (attr == null || attr.RelationType != RelationType.ManyToMany)
            {
                throw new Exception("A many-to-many relationship expected");
            }
            string script = "DELETE FROM " + (string.IsNullOrEmpty(attr.SchemaName) ? "" : attr.SchemaName + ".") +
                            attr.MamyToManyRelationTable + "\r\nWHERE ";

            script += attr.MtmRelationTableParentColumn + " IN (";
            string data = "";

            foreach (EntityBase entity in entities)
            {
                if (string.IsNullOrEmpty(data))
                {
                    data = ValueToString(entity.ID);
                }
                else
                {
                    data += ", " + ValueToString(entity.ID);
                }
            }
            script += data + ")\r\n";
            return(script);
        }
Beispiel #3
0
        private IEntity ProcessProperties(ref EntityBase entity, DataRow row)
        {
            ObjectDescription          od = ClassFactory.GetObjectDescription(ReflectedType, _ps);
            List <PropertyDescription> l  = new List <PropertyDescription>();

            foreach (PropertyDescription prop in od.Properties)
            {
                if (prop.GetAttribute <NonPersistentAttribute>() != null)
                {
                    continue;
                }
                if (prop.IsId)
                {
                    continue;
                }

                RelationAttribute relAttr = prop.GetAttribute <RelationAttribute>();
                if (relAttr != null)
                {
                    if (relAttr.RelationType == RelationType.ManyToMany)
                    {
                        l.Add(prop);
                        continue;
                    }
                    else if (relAttr.RelationType == RelationType.OneToOne)
                    {
                        SetOtoRelationValue(ref entity, row, relAttr, prop);
                        continue;
                    }
                    else if (relAttr.RelationType == RelationType.OneToMany)
                    {
                        l.Add(prop);
                        continue;
                    }
                }
                object val = prop.GetValue(entity);
                if (val != null)
                {
                    row[Mapper[prop.Name]] = val;
                }
                else
                {
                    row[Mapper[prop.Name]] = DBNull.Value;
                }
            }
            entity.AcceptChanges();
            foreach (PropertyDescription prop in l)
            {
                RelationAttribute relAttr = prop.GetAttribute <RelationAttribute>();
                if (relAttr.RelationType == RelationType.ManyToMany)
                {
                    SetMtmRelationValues(ref entity, row, relAttr, prop);
                }
                else if (relAttr.RelationType == RelationType.OneToMany)
                {
                    SetOtmRelationValues(ref entity, row, relAttr, prop);
                }
            }
            return(entity);
        }
Beispiel #4
0
        private void GetMtmRelationValues(ref EntityBase entity, DataRow row,
                                          RelationAttribute relAttr, PropertyDescription property)
        {
            DataRelation rel = ForeignKeys[property];

            //foreach ( DataRelation r in UnderlyngDataSet.Tables[Mapper.TableName].ChildRelations )
            //{
            //    if ( r.ChildTable == UnderlyngDataSet.Tables[relAttr.MamyToManyRelationTable] )
            //        rel = r;
            //}
            //if ( rel == null )
            //    throw new Exception("The child relation was not found");

            (property.GetValue(entity) as IList).Clear();
            foreach (DataRow childrow in entity.SourceRow.GetChildRows(rel))
            {
                object childid = childrow[relAttr.MtmRelationTableChildColumn];
                if (childid == null || childid == DBNull.Value)
                {
                    continue;
                }
                EntityBase e = _ps.GetEntityById(relAttr.RelatedType, childid);
                (property.GetValue(entity) as IList).Add(e);
            }
        }
Beispiel #5
0
        public void Can_Deserialize_RelationAttribute_Xml()
        {
            //Arrange
            var xml =
                new XElement("RelationAttribute",
                             new XAttribute("id", "31"),
                             new XAttribute("name", "Tillverkarrelation"),
                             new XAttribute("nameParserClass", "foo"),
                             new XElement("Value", new XCData("foo")),
                             new XElement("Value", new XCData("bar")));

            var expected = RelationAttribute.New("Tillverkarrelation", new[] { "foo", "bar" }, 31, "foo");

            var rad = new RelationAttributeDeserializer();

            //Act
            var actual = (RelationAttribute)rad.Deserialize(xml);

            //Assert
            Assert.That(actual.Name, Is.EqualTo(expected.Name));
            Assert.That(actual.DefinitionId, Is.EqualTo(expected.DefinitionId));
            Assert.That(actual.NameParserClass, Is.EqualTo(expected.NameParserClass));

            Assert.That(actual.Values.ElementAt(0), Is.EqualTo(expected.Values.ElementAt(0)));
            Assert.That(actual.Values.ElementAt(1), Is.EqualTo(expected.Values.ElementAt(1)));
        }
 public LexicalUnitToLexicalUnitRelation(LexicalUnit lexicalUnit, LexicalUnit relatedLecicalUnit, RelationAttribute attribute = RelationAttribute.None)
 {
     LexicalUnitId        = lexicalUnit.Id;
     LexicalUnit          = lexicalUnit;
     RelatedLexicalUnitId = relatedLecicalUnit.Id;
     LexicalUnit          = relatedLecicalUnit;
     Attribute            = attribute;
 }
        public void Can_Instantiate_New_RelationAttribute_With_FactoryMethod()
        {
            //Act
            var attribute = RelationAttribute.New("Tillverkarrelation", "foo", 31);

            //Assert
            Assert.That(attribute, Is.Not.Null);
        }
        public void Can_Instantiate_New_ContextAttribute()
        {
            //Act
            var attribute = new RelationAttribute("foo");

            //Assert
            Assert.That(attribute, Is.Not.Null);
        }
Beispiel #9
0
        //----------------------------------------------------------------------------------
        public CResultAErreur CreateTableSimpleInDataset(C2iTableExport tableExport, CContexteDonnee contexteDest, Type typeParent)
        {
            CResultAErreur result   = CResultAErreur.True;
            PropertyInfo   property = typeParent.GetProperty(tableExport.ChampOrigine.NomProprieteSansCleTypeChamp);

            if (property == null)
            {
                result.EmpileErreur(I.T("The property @1 was not found in the @2 type|105", tableExport.ChampOrigine.NomPropriete, typeParent.ToString()));
                return(result);
            }
            Object[]  attribs          = property.GetCustomAttributes(typeof(RelationAttribute), true);
            Type      typeObjet        = null;
            DataTable tableDestination = null;

            if (attribs.Length != 0)
            {
                RelationAttribute relParente = (RelationAttribute)attribs[0];
                tableDestination = contexteDest.GetTableSafe(relParente.TableMere);
                typeObjet        = CContexteDonnee.GetTypeForTable(relParente.TableMere);
            }
            else
            {
                attribs = property.GetCustomAttributes(typeof(RelationFilleAttribute), true);
                if (attribs.Length != 0)
                {
                    RelationFilleAttribute relFille = (RelationFilleAttribute)attribs[0];
                    tableDestination = contexteDest.GetTableSafe(CContexteDonnee.GetNomTableForType(relFille.TypeFille));
                    typeObjet        = relFille.TypeFille;
                }
                else
                {
                    result.EmpileErreur(I.T("The property @1 cannot be integrated into a simple export|106", tableExport.ChampOrigine.NomPropriete));
                    return(result);
                }
            }



            foreach (C2iChampExport champ in tableExport.Champs)
            //Crée les colonnes calculées
            {
                result = CreateChampInTable(champ, tableDestination);
                if (!result)
                {
                    result.EmpileErreur(I.T("Error during field @1 creation|104", champ.NomChamp));
                    return(result);
                }
            }
            foreach (C2iTableExport tableFille in tableExport.TablesFilles)
            {
                result &= CreateTableSimpleInDataset(tableFille, contexteDest, typeObjet);
                if (!result)
                {
                    return(result);
                }
            }
            return(result);
        }
Beispiel #10
0
        internal ModelPropertyDetail(MemberDetail memberDetail, bool declaringTypeIsDataSourceEntity)
        {
            this.MemberInfo = memberDetail.MemberInfo;

            this.Name          = memberDetail.Name;
            this.Type          = memberDetail.Type;
            this.CoreType      = memberDetail.TypeDetail.CoreType;
            this.IsNullable    = memberDetail.TypeDetail.IsNullable;
            this.IsEnumerable  = memberDetail.TypeDetail.IsIEnumerable;
            this.InnerType     = memberDetail.TypeDetail.InnerTypes?.Count > 0 ? memberDetail.TypeDetail.InnerTypes[0] : memberDetail.TypeDetail.Type;
            this.InnerCoreType = memberDetail.TypeDetail.InnerTypes?.Count > 0 ? memberDetail.TypeDetail.InnerTypeDetails[0].CoreType : memberDetail.TypeDetail.CoreType;

            var sourcePropertyAttribute = memberDetail.Attributes.Select(x => x as StoreNameAttribute).Where(x => x != null).FirstOrDefault();

            this.PropertySourceName = sourcePropertyAttribute?.StoreName;
            if (String.IsNullOrWhiteSpace(this.PropertySourceName))
            {
                this.PropertySourceName = memberDetail.Name;
            }
            if (!this.PropertySourceName.All(x => char.IsLetterOrDigit(x) || x == '_' || x == '`'))
            {
                throw new ArgumentException(String.Format("{0}.{1}={2}", nameof(StoreNameAttribute), nameof(StoreNameAttribute.StoreName), this.PropertySourceName));
            }

            IdentityAttribute identityAttribute        = null;
            RelationAttribute foreignIdentityAttribute = null;

            if (declaringTypeIsDataSourceEntity)
            {
                identityAttribute        = memberDetail.Attributes.Select(x => x as IdentityAttribute).Where(x => x != null).FirstOrDefault();
                foreignIdentityAttribute = memberDetail.Attributes.Select(x => x as RelationAttribute).Where(x => x != null).FirstOrDefault();
            }
            this.IsIdentity              = identityAttribute != null;
            this.ForeignIdentity         = foreignIdentityAttribute?.ForeignIdentity;
            this.IsIdentityAutoGenerated = identityAttribute != null && identityAttribute.AutoGenerated;
            this.IsRelated = foreignIdentityAttribute != null;

            var dataSourceEntityAttribute = memberDetail.TypeDetail.Attributes.Select(x => x as EntityAttribute).Where(x => x != null).FirstOrDefault();

            this.IsDataSourceEntity = dataSourceEntityAttribute != null;

            var dataSourceTypeAttribute = memberDetail.Attributes.Select(x => x as StorePropertiesAttribute).Where(x => x != null).FirstOrDefault();

            this.IsDataSourceNotNull       = dataSourceTypeAttribute != null ? dataSourceTypeAttribute.NotNull : (InnerType.IsValueType && !memberDetail.TypeDetail.IsNullable);
            this.DataSourcePrecisionLength = dataSourceTypeAttribute != null ? dataSourceTypeAttribute.PrecisionLength : null;
            this.DataSourceScale           = dataSourceTypeAttribute != null ? dataSourceTypeAttribute.Scale : null;

            if (!this.IsDataSourceNotNull && this.IsIdentity)
            {
                throw new Exception($"{this.Type.GetNiceName()} {this.Name} cannot be both an identity and nullable");
            }

            this.Getter = memberDetail.Getter;
            this.Setter = memberDetail.Setter;

            this.CoreTypeSetter = CoreTypeSetterGenerator.Get(this.MemberInfo, this.CoreType, this.Type.IsArray && this.InnerCoreType == Zerra.Reflection.CoreType.Byte);
        }
Beispiel #11
0
        public void AddRelatedLexicalUnit(LexicalUnit relatedLexicalUnit, RelationAttribute attribute = RelationAttribute.None)
        {
            if (Id <= 0)
            {
                throw new InvalidOperationException();
            }

            RelatedLexicalUnits.Add(new LexicalUnitToLexicalUnitRelation(this, relatedLexicalUnit, attribute));
        }
        public void Instantiation_Sets_Correct_Values_On_BaseType_Props()
        {
            //Act
            var attribute = new RelationAttribute("foo", 10, "foo");

            //Assert
            Assert.That(attribute.NameParserClass, Is.EqualTo("foo"));
            Assert.That(attribute.DefinitionId, Is.EqualTo(10));
            Assert.That(attribute.ElementName, Is.EqualTo("RelationAttribute"));
        }
Beispiel #13
0
        public void ReloadEntity(EntityBase entity)
        {
            if (!_compiled)
            {
                Compile();
            }

            ObjectDescription od = ClassFactory.GetObjectDescription(ReflectedType, _ps);
            DataView          dv = UnderlyngDataSet.Tables[Mapper.TableName].DefaultView;

            entity.BeginLoad();
            DataRow row = entity.SourceRow; //dv[0].Row;

            foreach (PropertyDescription prop in od.Properties)
            {
                if (prop.GetAttribute <NonPersistentAttribute>() != null)
                {
                    continue;
                }
                if (prop.IsId)
                {
                    continue;
                }

                RelationAttribute relAttr = prop.GetAttribute <RelationAttribute>();
                if (relAttr != null)
                {
                    if (relAttr.RelationType == RelationType.ManyToMany)
                    {
                        GetMtmRelationValues(ref entity, row, relAttr, prop);
                        continue;
                    }
                    else if (relAttr.RelationType == RelationType.OneToOne)
                    {
                        GetOtoRelationValue(ref entity, row, relAttr, prop);
                        continue;
                    }
                    else if (relAttr.RelationType == RelationType.OneToMany)
                    {
                        GetOtmRealationValues(ref entity, row, relAttr, prop);
                        continue;
                    }
                }
                //DateTime dt1 = DateTime.Now;
                //prop.SetValue(entity, row[Mapper[prop.Name]]);
                (entity as EntityBase)[prop.Name] = row[Mapper[prop.Name]];
                //DateTime dt2 = DateTime.Now;
                //TimeSpan ts = dt2 - dt1;
            }
            entity.EndLoad();
        }
Beispiel #14
0
        public Relation(Table parentTable, Table childTable,
                        MemberInfo member, string memberPath,
                        Type memberValueType, RelationAttribute relationAttribute) :
            base(member, memberPath, null)
        {
            ExceptionUtils.ThrowIfNull(parentTable, "parentTable");
            ExceptionUtils.ThrowIfNull(relationAttribute, "relationAttribute");

            m_ParentTable               = parentTable;
            m_ChildTable                = childTable;
            m_MemberValueType           = memberValueType;
            m_ChildForeignKeyColumnName = relationAttribute.ChildForeignKeyColumnName;
            m_ParentColumnName          = relationAttribute.ParentColumnName;
        }
 //---------------------------------
 public override CResultAErreur InsertDataInDataSet(
     IEnumerable list,
     DataSet ds,
     ITableExport tableParente,
     int[] nValeursCle,
     RelationAttribute relationToObjetParent,
     IElementAVariablesDynamiquesAvecContexteDonnee elementAVariablePourFiltres,
     CCacheValeursProprietes cacheValeurs,
     ITableExport tableFilleANePasCharger,
     bool bAvecOptimisation,
     CConteneurIndicateurProgression indicateur)
 {
     if (tableParente != null)
     {
         return(base.InsertDataInDataSet(
                    list,
                    ds,
                    tableParente,
                    nValeursCle,
                    relationToObjetParent,
                    elementAVariablePourFiltres,
                    cacheValeurs,
                    tableFilleANePasCharger,
                    bAvecOptimisation,
                    indicateur));
     }
     else
     {
         CResultAErreur result = CResultAErreur.True;
         foreach (ITableExport tableFille in TablesFilles)
         {
             result = tableFille.InsertDataInDataSet(
                 list,
                 ds,
                 tableParente,
                 nValeursCle,
                 relationToObjetParent,
                 elementAVariablePourFiltres,
                 cacheValeurs,
                 tableFilleANePasCharger,
                 bAvecOptimisation,
                 indicateur);
             if (!result)
             {
                 return(result);
             }
         }
         return(result);
     }
 }
        //--------------------------------------------
        /// <summary>
        /// Si succès, retourne le filtre correspondant à cet élément
        /// en tant que clé. le texte du filtre (format filtreData) est contenu dans le data du result
        /// avec le paramètre valeur = @n
        /// </summary>
        /// <param name="typeCible"></param>
        /// <returns></returns>
        public static CResultAErreur GetFiltreCle(
            Type typeCible,
            CDefinitionProprieteDynamique definition,
            int nNumeroParametre)
        {
            CResultAErreur result = CResultAErreur.True;
            CDefinitionProprieteDynamiqueDotNet def = definition as CDefinitionProprieteDynamiqueDotNet;
            PropertyInfo info = null;

            if (def != null)
            {
                info = typeCible.GetProperty(def.NomProprieteSansCleTypeChamp);
            }
            if (info != null)
            {
                object[] attribs = info.GetCustomAttributes(typeof(TableFieldPropertyAttribute), true);
                if (attribs.Length > 0)
                {
                    TableFieldPropertyAttribute attr = attribs[0] as TableFieldPropertyAttribute;
                    result.Data = attr.NomChamp + "=@" + nNumeroParametre;
                    return(result);
                }
                attribs = info.GetCustomAttributes(typeof(RelationAttribute), true);
                if (attribs.Length > 0)
                {
                    RelationAttribute attr = attribs[0] as RelationAttribute;
                    if (attr.ChampsFils.Length == 1)
                    {
                        result.Data = attr.ChampsFils[0] + "=@" + nNumeroParametre;
                        return(result);
                    }
                }
            }
            //Sinon, si ID d'un objet a id auto
            if (typeof(CObjetDonneeAIdNumerique).IsAssignableFrom(typeCible))
            {
                if (definition.NomPropriete == "#PP|Id")
                {
                    //Trouve le champ id
                    string strChampId = CObjetDonnee.GetChampsId(typeCible)[0];
                    result.Data = strChampId + "=@" + nNumeroParametre;
                    return(result);
                }
            }

            result.EmpileErreur(I.T("Can not use field @1 as key in imort|20044", definition.Nom));
            return(result);
        }
Beispiel #17
0
        public void Compile()
        {
            _mapper = new Mapper(ReflectedType, _ps);
            ObjectDescription od = ClassFactory.GetObjectDescription(ReflectedType, _ps);

            foreach (PropertyDescription prop in od.Relations)
            {
                if (prop.IsOneToOneRelation)
                {
                    continue;
                }
                Mapper            m         = new Mapper(prop.RelatedType, _ps);
                RelationAttribute attr      = prop.GetAttribute <RelationAttribute>();
                string            parentCol = null;
                string            childCol  = null;
                DataTable         table     = UnderlyngDataSet.Tables[Mapper.TableName];
                string            tableName = null;
                if (prop.IsOneToManyRelation)
                {
                    parentCol = _mapper[od.IdField.Name];
                    childCol  = m[attr.RelatedColumn];
                    tableName = m.TableName;
                }
                else // (prop.IsManyToManyRelation)
                {
                    parentCol = _mapper[od.IdField.Name];
                    childCol  = attr.MtmRelationTableParentColumn;
                    tableName = attr.MamyToManyRelationTable;
                }
                bool ok = false;
                foreach (DataRelation relation in table.ChildRelations)
                {
                    if (relation.ChildTable.TableName.ToLower() == tableName.ToLower() &&
                        relation.ParentColumns[0].ColumnName.ToLower() == parentCol.ToLower() &&
                        relation.ChildColumns[0].ColumnName.ToLower() == childCol.ToLower())
                    {
                        ForeignKeys.Add(prop, relation);
                        ok = true;
                        break;
                    }
                }
                if (!ok)
                {
                    throw new Exception("F**K");
                }
            }
            _compiled = true;
        }
Beispiel #18
0
        private void notifyFirstRelatedElement(MoodleXmlElement child, RelationAttribute relatedTo)
        {
            foreach (MoodleXmlElement parentElement in this.moodleXmlElementsStack)
            {
                Type parentType = parentElement.GetType();

                if (parentType.Equals(relatedTo.To) || parentType.IsSubclassOf(relatedTo.To))
                {
                    bool found = this.notifyRelatedElementProperties(parentType, parentElement, child);
                    if (found)
                    {
                        break;
                    }
                }
            }
        }
        /// /////////////////////////////////////////////////////////
        public CResultAErreur InsertDataInDataSet(
            IEnumerable list,
            DataSet ds,
            ITableExport tableParente,
            int[] nValeursCle,
            RelationAttribute relationToObjetParent,
            IElementAVariablesDynamiquesAvecContexteDonnee elementAVariablePourFiltres,
            CCacheValeursProprietes cacheValeurs,
            ITableExport tableFilleANeParCharger,
            bool bAvecOptimisation,
            CConteneurIndicateurProgression indicateur)
        {
            CResultAErreur result = CResultAErreur.True;

            result.EmpileErreur(I.T("Not supported function calling : C2iTableExportCalculée.InsertDataInDataset|124"));
            return(result);
        }
Beispiel #20
0
        private void GetOtoRelationValue(ref EntityBase entity, DataRow row,
                                         RelationAttribute relAttr, PropertyDescription property)
        {
            Cryptany.Core.DPO.Mapper m = new Mapper(relAttr.RelatedType, _ps);
            //DataView dvChild = new DataView(UnderlyngDataSet.Tables[m.TableName]);
            object id = row[Mapper[property.Name]];

            //CreateFilterString(m[relAttr.RelatedColumn], dvChild, id);
            //object oId = GetIdAsObject(id);
            if (id == null || id == DBNull.Value)
            {
                return;
            }
            IEntity e = _ps.GetEntityById(relAttr.RelatedType, id);

            property.SetValue(entity, e);
        }
Beispiel #21
0
        //---------------------------------------------------------------
        private bool IsChampCompatibleImport(Type typeObjet, CDefinitionProprieteDynamique def)
        {
            if (def is CDefinitionProprieteDynamiqueChampCustom)
            {
                return(true);
            }
            if (def is CDefinitionProprieteDynamiqueDotNet)
            {
                PropertyInfo info = typeObjet.GetProperty(def.NomProprieteSansCleTypeChamp);
                if (info != null)
                {
                    TableFieldPropertyAttribute attField = info.GetCustomAttribute <TableFieldPropertyAttribute>(true);
                    if (attField != null && attField.IsInDb)
                    {
                        return(true);
                    }

                    RelationAttribute attRel = info.GetCustomAttribute <RelationAttribute>(true);
                    if (attRel != null)
                    {
                        return(true);
                    }
                    RelationFilleAttribute attFille = info.GetCustomAttribute <RelationFilleAttribute>(true);
                    if (attFille != null)
                    {
                        return(true);
                    }
                }
            }
            if (def is CDefinitionProprieteDynamiqueRelationTypeId)
            {
                return(true);
            }
            if (def is CDefinitionProprieteDynamiqueRelationTypeIdToParent)
            {
                return(true);
            }
            if (def is CDefinitionProprieteDynamiqueChampCustomFils)
            {
                return(true);
            }
            return(false);
        }
        public void Can_Generate_Api_Xml()
        {
            //Arrange
            var expected = new XElement("RelationAttribute",
                                        new XAttribute("name", "Tillverkarrelation"),
                                        new XAttribute("nameParserClass", "foo"),
                                        new XAttribute("id", "31"),
                                        new XElement("Value", new XCData("foo"))).ToString();

            var attribute = RelationAttribute.New("Tillverkarrelation", "foo", 31, "foo");

            //Act
            var actual = attribute.ToAdsml().ToString();

            Console.WriteLine(actual);

            //Assert
            Assert.That(actual, Is.EqualTo(expected));
        }
Beispiel #23
0
        public void Can_Add_ModificationItems_With_ListFactory()
        {
            //Arrange
            var builder = new ModifyRequestBuilder();

            //Act
            builder.AddModifications(() => new List <ModificationItem> {
                ModificationItem.New(
                    Modifications.ReplaceAttribute,
                    SimpleAttribute.New(AttributeTypes.Integer, "foo", "bar")
                    ),
                ModificationItem.New(
                    Modifications.AddAttribute,
                    RelationAttribute.New("foo", "bar")
                    )
            });

            //Assert
            Assert.That(builder.Modifications.Count(), Is.EqualTo(2));
        }
        //------------------------------------------------
        private CResultAErreurType <CValeursImportFixe> GetValeursFixesPourFilles(CObjetDonnee parent)
        {
            CResultAErreurType <CValeursImportFixe> resVals = new CResultAErreurType <CValeursImportFixe>();

            if (Propriete is CDefinitionProprieteDynamiqueDotNet)
            {
                Type tp = MappagesEntitesFilles.ElementAt(0).ConfigMappage.TypeEntite;
                CDefinitionProprieteDynamique pDeFille = Propriete.GetDefinitionInverse(parent.GetType());
                PropertyInfo info = tp.GetProperty(pDeFille.NomProprieteSansCleTypeChamp);
                if (info != null)
                {
                    RelationAttribute relPar = info.GetCustomAttribute <RelationAttribute>(true);
                    if (relPar != null)
                    {
                        CValeursImportFixe vals = new CValeursImportFixe();
                        for (int nChamp = 0; nChamp < relPar.ChampsFils.Length; nChamp++)
                        {
                            vals.SetValeur(relPar.ChampsFils[nChamp], parent.Row[relPar.ChampsParent[nChamp]]);
                        }
                        resVals.DataType = vals;
                        return(resVals);
                    }
                }
            }
            if (Propriete is CDefinitionProprieteDynamiqueRelationTypeId && parent is CObjetDonneeAIdNumerique)
            {
                RelationTypeIdAttribute att = ((CDefinitionProprieteDynamiqueRelationTypeId)Propriete).Relation;
                if (att != null)
                {
                    CValeursImportFixe vals = new CValeursImportFixe();
                    vals.SetValeur(att.ChampType, parent.GetType().ToString());
                    vals.SetValeur(att.ChampId, ((CObjetDonneeAIdNumerique)parent).Id);
                    resVals.DataType = vals;
                    return(resVals);
                }
            }

            resVals.EmpileErreur(I.T("Can not define parent filter for property @1|20098", Propriete.Nom));
            return(resVals);
        }
Beispiel #25
0
        /// <summary>
        /// Creates one instance of the Relation Object from the PropertyInfo object of the reflected class
        /// </summary>
        /// <param name="propInfo"></param>
        /// <returns></returns>
        public static Relation CreateRelationObject(PropertyInfo propInfo)
        {
            Relation result = new VSPlugin.Relation();

            // get's the Relation Attribute in the class
            RelationAttribute relationAttribute = propInfo.GetCustomAttribute <RelationAttribute>();

            if (relationAttribute == null)
            {
                return(result);
            }

            Type elementType = null;

            //we need to discover the id of the relation and if it's a collection
            if (propInfo.PropertyType.IsArray)
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetElementType();
            }
            else if (propInfo.PropertyType.IsGenericType && propInfo.PropertyType.GetGenericTypeDefinition() == typeof(List <>))
            {
                result.Collection = true;

                elementType = propInfo.PropertyType.GetGenericArguments().Single();
            }
            else
            {
                elementType = propInfo.PropertyType;
            }

            result.Type        = GetResourceType(elementType);
            result.Required    = relationAttribute.Required;
            result.Requirement = relationAttribute.Requirement;
            result.Allocate    = relationAttribute.Allocate.ToString();

            return(result);
        }
Beispiel #26
0
        private void SetOtoRelationValue(ref EntityBase entity, DataRow row,
                                         RelationAttribute relAttr, PropertyDescription property)
        {
            if (entity.State == EntityState.Deleted)
            {
                return;
            }
            Cryptany.Core.DPO.Mapper m = new Mapper(relAttr.RelatedType, _ps);
            EntityBase e = (EntityBase)property.GetValue(entity);

            if (e != null)
            {
                //if (e.State == EntityState.New)
                _ps.SaveInner(e);
                object id = ClassFactory.GetObjectDescription(m.EntityType, _ps).IdField.GetValue(e);
                row[Mapper[property.Name]] = id;
            }
            else
            {
                row[Mapper[property.Name]] = DBNull.Value;
            }
        }
Beispiel #27
0
        /// /////////////////////////////////////////////////////////////
        /// <summary>
        /// Crée un attribut relation décrivant la relation qui lie la donnée cumulée au type demandé
        /// </summary>
        /// <param name="tp"></param>
        /// <returns></returns>
        public RelationAttribute GetRelationAttributeToType(Type tp)
        {
            int nCle = 0;

            foreach (CCleDonneeCumulee cle in Parametre.ChampsCle)
            {
                if (cle.TypeLie != null && cle.TypeLie == tp)
                {
                    CObjetDonneeAIdNumerique obj  = (CObjetDonneeAIdNumerique)Activator.CreateInstance(tp, new object[] { ContexteDonnee });
                    RelationAttribute        attr = new RelationAttribute(
                        obj.GetNomTable(),
                        obj.GetChampId(),
                        CDonneeCumulee.GetNomChampCle(nCle),
                        false,
                        true,
                        false);
                    return(attr);
                }
                nCle++;
            }
            return(null);
        }
Beispiel #28
0
        private void populateQuizByHtml()
        {
            HtmlNodeCollection nodes = this.html.DocumentNode.SelectNodes("//div/p");

            foreach (HtmlNode node in nodes)
            {
                MoodleXmlElement currentMoodleXmlElement = Factory.get(node);

                if (currentMoodleXmlElement != null)
                {
                    currentMoodleXmlElement.HtmlNode = node;
                    Type currentMoodleXmlElementType = currentMoodleXmlElement.GetType();

                    RelationAttribute ralatedTo = RelationAttribute.get(currentMoodleXmlElementType);
                    if (ralatedTo != null)
                    {
                        this.notifyFirstRelatedElement(currentMoodleXmlElement, ralatedTo);
                    }

                    this.moodleXmlElementsStack.Push(currentMoodleXmlElement);
                }
            }
        }
Beispiel #29
0
        public static string CreateMtmInsert(PropertyDescription pd, PersistentStorage ps, IList <EntityBase> entities)
        {
            RelationAttribute attr = pd.GetAttribute <RelationAttribute>();

            if (attr == null || attr.RelationType != RelationType.ManyToMany)
            {
                throw new Exception("A many-to-many relationship expected");
            }
            string script = "INSERT INTO " + (string.IsNullOrEmpty(attr.SchemaName) ? "" : attr.SchemaName + ".") +
                            attr.MamyToManyRelationTable + "(" + attr.MtmRelationTableChildColumn + "," + attr.MtmRelationTableParentColumn + ")\r\n";
            string data = "";

            foreach (EntityBase entity in entities)
            {
                foreach (EntityBase e in pd.GetValue <System.Collections.IList>(entity))
                {
                    if (string.IsNullOrEmpty(data))
                    {
                        data = "SELECT " + ValueToString(e.ID) + ", " + ValueToString(entity.ID) + "\r\n";
                    }
                    else
                    {
                        data += "UNION ALL\r\nSELECT " + ValueToString(e.ID) + ", " + ValueToString(entity.ID) + "\r\n";
                    }
                }
            }
            if (string.IsNullOrEmpty(data))
            {
                return("");
            }
            else
            {
                script += data;
            }
            return(script);
        }
Beispiel #30
0
 private void SetOtmRelationValues(ref EntityBase entity, DataRow row,
                                   RelationAttribute relAttr, PropertyDescription property)
 {
     if (entity.State == EntityState.Deleted)
     {
         if (relAttr.DeleteMode == DeleteMode.Single)
         {
         }
         else if (relAttr.DeleteMode == DeleteMode.Cascade)
         {
             foreach (EntityBase e in (IList)property.GetValue(entity))
             {
                 e.Delete();
                 _ps.SaveInner(e);
             }
         }
     }
     //else
     {
         IList    l    = ((IList)property.GetValue(entity));
         object[] objs = new object[l.Count];
         l.CopyTo(objs, 0);
         foreach (EntityBase e in objs)
         {
             ObjectDescription od = ClassFactory.GetObjectDescription(relAttr.RelatedType, _ps);
             od.Properties[relAttr.RelatedColumn].SetValue(e, entity);
             //if ( e.State == EntityState.Unchanged )
             //    e.State = EntityState.Changed;
             _ps.SaveInner(e);
             if (e.State == EntityState.NewDeleted || e.State == EntityState.Deleted)
             {
                 (property.GetValue(entity) as IList).Remove(e);
             }
         }
     }
 }
		public Relation CreateRelation(string name, string table, string foreigntable, RelationAttribute attributes)
		{
			return new Relation(db.CreateRelation(name, table, foreigntable, attributes));
		}