Beispiel #1
0
        async Task Save <TEntity>(TEntity entity, TypeDescriptor declaringTypeDescriptor, bool @async)
        {
            await this.Insert(entity, null, @async);

            TypeDescriptor typeDescriptor = EntityTypeContainer.GetDescriptor(typeof(TEntity));

            for (int i = 0; i < typeDescriptor.ComplexPropertyDescriptors.Count; i++)
            {
                //entity.TOther
                ComplexPropertyDescriptor navPropertyDescriptor = typeDescriptor.ComplexPropertyDescriptors[i];

                if (declaringTypeDescriptor != null && navPropertyDescriptor.PropertyType == declaringTypeDescriptor.Definition.Type)
                {
                    continue;
                }

                await this.SaveOneToOne(navPropertyDescriptor, entity, typeDescriptor, @async);
            }

            for (int i = 0; i < typeDescriptor.CollectionPropertyDescriptors.Count; i++)
            {
                //entity.List
                CollectionPropertyDescriptor collectionPropertyDescriptor = typeDescriptor.CollectionPropertyDescriptors[i];
                await this.SaveCollection(collectionPropertyDescriptor, entity, typeDescriptor, @async);
            }
        }
Beispiel #2
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptor[] array = null;
            ICollection          list  = value as ICollection;

            if (list != null)
            {
                array = new PropertyDescriptor[list.Count];
                Type type = typeof(ICollection);
                int  i    = 0;
                foreach (object o in list)
                {
                    string name = string.Format(CultureInfo.InvariantCulture,
                                                "[{0}]", i.ToString("d" + list.Count.ToString
                                                                        (NumberFormatInfo.InvariantInfo).Length, null) +
                                                ":" + Midi.MidiManager.GetNoteName((SevenBitNumber)i));
                    switch (o)
                    {
                    case TimbreBase tim:
                        name += " " + tim.TimbreName;
                        break;

                    case DrumTimbre dtim:
                        name += " " + dtim.TimbreName;
                        break;
                    }
                    CollectionPropertyDescriptor cpd = new CollectionPropertyDescriptor(context, type, name, o.GetType(), i);
                    array[i] = cpd;
                    i++;
                }
            }
            return(new PropertyDescriptorCollection(array));
        }
Beispiel #3
0
 /// <summary>
 /// Constructor
 /// </summary>
 public CollectionPropertyMetadata(
     CollectionPropertyDescriptor desc,
     Func <string> display,
     Func <Entity, object, IEnumerable <ValidationResult> > validate,
     Func <TypeMetadata> getCollectionTargetTypeMetadata) : base(desc, display, validate, null, null)
 {
     _getCollectionTargetTypeMetadata = getCollectionTargetTypeMetadata;
 }
Beispiel #4
0
 public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
 {
     PropertyDescriptor[] array = null;
     ICollection list = value as ICollection;
     if (list != null)
     {
         array = new PropertyDescriptor[list.Count];
         Type type = typeof(ICollection);
         int i = 0;
         foreach (object o in list)
         {
             string name = string.Format(CultureInfo.InvariantCulture,
                 "[{0}]", i.ToString("d" + list.Count.ToString
                 (NumberFormatInfo.InvariantInfo).Length, null));
             CollectionPropertyDescriptor cpd = new CollectionPropertyDescriptor(context, type, name, o.GetType(), i);
             array[i] = cpd;
             i++;
         }
     }
     return new PropertyDescriptorCollection(array);
 }
Beispiel #5
0
        async Task SaveCollection(CollectionPropertyDescriptor collectionPropertyDescriptor, object owner, TypeDescriptor ownerTypeDescriptor, bool @async)
        {
            PrimitivePropertyDescriptor ownerKeyPropertyDescriptor = ownerTypeDescriptor.PrimaryKeys.FirstOrDefault();

            if (ownerKeyPropertyDescriptor == null)
            {
                return;
            }

            //T.Elements
            IList elementList = collectionPropertyDescriptor.GetValue(owner) as IList;

            if (elementList == null || elementList.Count == 0)
            {
                return;
            }

            TypeDescriptor elementTypeDescriptor = EntityTypeContainer.GetDescriptor(collectionPropertyDescriptor.ElementType);
            //Element.T
            ComplexPropertyDescriptor elementDotT = elementTypeDescriptor.ComplexPropertyDescriptors.Where(a => a.PropertyType == ownerTypeDescriptor.Definition.Type).FirstOrDefault();

            object     ownerKeyValue = ownerKeyPropertyDescriptor.GetValue(owner);
            MethodInfo saveMethod    = GetSaveMethod(collectionPropertyDescriptor.ElementType);

            for (int i = 0; i < elementList.Count; i++)
            {
                object element = elementList[i];
                if (element == null)
                {
                    continue;
                }

                //element.ForeignKey = T.Id
                elementDotT.ForeignKeyProperty.SetValue(element, ownerKeyValue);
                //DbContext.Save(element, ownerTypeDescriptor, @async);
                Task  task = (Task)saveMethod.Invoke(this, element, ownerTypeDescriptor, @async);
                await task;
            }
        }
Beispiel #6
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            PropertyDescriptor[] array = null;
            ICollection          list  = value as ICollection;

            if (list != null)
            {
                array = new PropertyDescriptor[list.Count];
                Type type = typeof(ICollection);
                int  i    = 0;
                foreach (object o in list)
                {
                    string name = string.Format(CultureInfo.InvariantCulture,
                                                "[{0}]", i.ToString("d" + list.Count.ToString
                                                                        (NumberFormatInfo.InvariantInfo).Length, null));
                    switch (o)
                    {
                    case ProgramAssignmentNumber pan:
                        break;

                    case CombinedTimbreSettings cts:
                        name += " " + cts.TimbreNumber;
                        break;

                    case CombinedTimbre ctim:
                        name += " " + ctim.TimbreName;
                        break;

                    case TimbreBase tim:
                        name += " " + tim.TimbreName;
                        break;

                    case DrumTimbre dtim:
                        name += " " + dtim.TimbreName;
                        break;

                    case Object obj:
                        //dynamic dobj = obj;
                        //try
                        //{
                        //    name += " " + dobj.TimbreName;
                        //}
                        //catch
                        //{
                        //    try
                        //    {
                        //        name += " " + dobj.Memo;
                        //    }
                        //    catch
                        //    {
                        //    }
                        //}
                        break;
                    }
                    CollectionPropertyDescriptor cpd = new CollectionPropertyDescriptor(context, type, name, o.GetType(), i);
                    array[i] = cpd;
                    i++;
                }
            }
            return(new PropertyDescriptorCollection(array));
        }