Beispiel #1
0
        /// <summary>
        /// Renders the list entity object description.
        /// </summary>
        /// <param name="listMetaClass">The list meta class.</param>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        private string RenderListEntityObjectDescription(MetaClass listMetaClass, EntityObject item)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("<table cellpadding='5'>");
            foreach (string fieldName in this.CurrentProfile.FieldSet)
            {
                if (listMetaClass.Fields.Contains(fieldName))
                {
                    BaseEntityType ctrl = (BaseEntityType)GetColumn(this.Page, listMetaClass.Fields[fieldName]);
                    ctrl.DataItem  = item;
                    ctrl.FieldName = fieldName;
                    ctrl.DataBind();
                    StringBuilder  sb2 = new StringBuilder();
                    StringWriter   tw  = new StringWriter(sb2);
                    HtmlTextWriter hw  = new HtmlTextWriter(tw);
                    ctrl.RenderControl(hw);

                    if (item.Properties.Contains(fieldName))
                    {
                        sb.AppendFormat("<tr><td><b>{0}:</b></td><td>{1}</td></tr>", listMetaClass.Fields[fieldName].FriendlyName,
                                        sb2.ToString());
                    }
                }
            }
            sb.Append("</table>");
            //sb.Append("TODO: Description Here");

            return(sb.ToString());
        }
 public IEnumerable <IPropertyMetadata> GetAllProperties()
 {
     if (BaseEntityType == null)
     {
         return(GetDirectProperties());
     }
     return(BaseEntityType.GetAllProperties().Union(GetDirectProperties()));
 }
Beispiel #3
0
        /// <summary>
        /// 获取指定基类实体的属性字典
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List <PropertyEntity> Get(BaseEntityType type)
        {
            switch (type)
            {
            case BaseEntityType.EntityBaseString:
                return(GetEntityBaseProperties(PropertyType.String));
            }

            return(new List <PropertyEntity>());
        }
Beispiel #4
0
        /// <summary>
        /// 获取指定基类实体的属性字典
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public List <PropertyEntity> Get(BaseEntityType type)
        {
            switch (type)
            {
            case BaseEntityType.EntityInt:
                return(GetEntityProperties(PropertyType.Int));

            case BaseEntityType.EntityLong:
                return(GetEntityProperties(PropertyType.Long));

            case BaseEntityType.EntityGuid:
                return(GetEntityProperties(PropertyType.Guid));

            case BaseEntityType.EntityString:
                return(GetEntityProperties(PropertyType.String));

            case BaseEntityType.EntityBaseInt:
                return(GetEntityBaseProperties(PropertyType.Int));

            case BaseEntityType.EntityBaseLong:
                return(GetEntityBaseProperties(PropertyType.Long));

            case BaseEntityType.EntityBaseGuid:
                return(GetEntityBaseProperties(PropertyType.Guid));

            case BaseEntityType.EntityBaseString:
                return(GetEntityBaseProperties(PropertyType.String));

            case BaseEntityType.EntityWithSoftDeleteInt:
                return(GetEntityWithSoftDeleteProperties(PropertyType.Int));

            case BaseEntityType.EntityWithSoftDeleteLong:
                return(GetEntityWithSoftDeleteProperties(PropertyType.Long));

            case BaseEntityType.EntityWithSoftDeleteGuid:
                return(GetEntityWithSoftDeleteProperties(PropertyType.Guid));

            case BaseEntityType.EntityWithSoftDeleteString:
                return(GetEntityWithSoftDeleteProperties(PropertyType.String));

            case BaseEntityType.EntityBaseWithSoftDeleteInt:
                return(GetEntityBaseWithSoftDeleteProperties(PropertyType.Int));

            case BaseEntityType.EntityBaseWithSoftDeleteLong:
                return(GetEntityBaseWithSoftDeleteProperties(PropertyType.Long));

            case BaseEntityType.EntityBaseWithSoftDeleteGuid:
                return(GetEntityBaseWithSoftDeleteProperties(PropertyType.Guid));

            case BaseEntityType.EntityBaseWithSoftDeleteString:
                return(GetEntityBaseWithSoftDeleteProperties(PropertyType.String));
            }

            return(new List <PropertyEntity>());
        }
 public IPropertyMetadata GetProperty(string propertyName)
 {
     if (_properties.TryGetValue(propertyName, out var prop))
     {
         return(prop);
     }
     if (BaseEntityType == null)
     {
         return(null);
     }
     return(BaseEntityType.GetProperty(propertyName));
 }
Beispiel #6
0
        /// <summary>
        /// 是否包含属性
        /// </summary>
        /// <param name="propertyName">属性名</param>
        /// <returns>是否</returns>
        public bool ContainsProperty(string propertyName)
        {
            if (_properties.Contains(propertyName))
            {
                return(true);
            }
            else
            {
                if (!string.IsNullOrEmpty(_baseEntityName))
                {
                    return(BaseEntityType.ContainsProperty(propertyName));
                }

                return(false);
            }
        }
        private void baseEntityComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            derivedEntityComboBox.Items.Clear();
            foreach (var entityType in _entityTypes)
            {
                if (entityType != BaseEntityType &&
                    entityType.BaseType.Target == null)
                {
                    if (BaseEntityType == null ||
                        (BaseEntityType != null && !BaseEntityType.IsDerivedFrom(entityType)))
                    {
                        derivedEntityComboBox.Items.Add(entityType);
                    }
                }
            }
            if (derivedEntityComboBox.Items.Count > 0)
            {
                derivedEntityComboBox.SelectedIndex = 0;
            }

            CheckOkButtonEnabled();
        }
Beispiel #8
0
        public DynPropertyConfiguration GetProperty(string propertyName)
        {
            if (_properties.Contains(propertyName))
            {
                return(_properties[propertyName]);
            }
            else
            {
                if (!string.IsNullOrEmpty(_baseEntityName) && BaseEntityType != null)
                {
                    DynPropertyConfiguration inheritedProperty = BaseEntityType.GetProperty(propertyName);
                    inheritedProperty.IsInherited = true;
                    if (inheritedProperty.InheritEntityMappingName == null)
                    {
                        inheritedProperty.InheritEntityMappingName = BaseEntityType.Name;
                    }
                    return(inheritedProperty);
                }

                throw new ApplicationException("当前类或基类没有名称为" + propertyName + "的属性!");
            }
        }
Beispiel #9
0
        public DynPropertyConfigurationCollection GetProperties()
        {
            DynPropertyConfigurationCollection properties = new DynPropertyConfigurationCollection(this);

            properties.AddRange(_properties);

            if (!string.IsNullOrEmpty(_baseEntityName) && BaseEntityType != null)
            {
                DynPropertyConfigurationCollection inheritedProperties = BaseEntityType.GetProperties();

                foreach (DynPropertyConfiguration inheritedProperty in inheritedProperties)
                {
                    inheritedProperty.IsInherited = true;
                    if (inheritedProperty.InheritEntityMappingName == null)
                    {
                        inheritedProperty.InheritEntityMappingName = BaseEntityType.Name;
                    }
                }

                properties.AddRange(inheritedProperties);
            }

            return(properties);
        }
Beispiel #10
0
        /// <summary>Materializes the specified <paramref name="entry"/>.</summary>
        /// <param name="entry">Entry with object to materialize.</param>
        /// <param name="includeLinks">Whether links that are expanded for navigation property should be materialized.</param>
        /// <remarks>This is a payload-driven materialization process.</remarks>
        private void MaterializeResolvedEntry(MaterializerEntry entry, bool includeLinks)
        {
            Debug.Assert(entry.Entry != null, "entry != null");
            Debug.Assert(entry.ResolvedObject != null, "entry.ResolvedObject != null -- otherwise not resolved/created!");

            ClientTypeAnnotation actualType = entry.ActualType;

            // While materializing entities, we need to make sure the payload that came in the wire is also an entity.
            // Otherwise we need to fail.
            // This is a breaking change from V1/V2 where we allowed materialization of entities into non-entities and vice versa
            if (!actualType.IsStructuredType)
            {
                throw DSClient.Error.InvalidOperation(DSClient.Strings.AtomMaterializer_InvalidNonEntityType(actualType.ElementTypeName));
            }

            // Note that even if ShouldUpdateFromPayload is false, we will still be creating
            // nested instances (but not their links), so they show up in the data context
            // entries. This keeps this code compatible with V1 behavior.
            this.MaterializeDataValues(actualType, entry.Properties, this.MaterializerContext.UndeclaredPropertyBehavior);

            if (entry.NestedResourceInfos?.Any() == true)
            {
                foreach (ODataNestedResourceInfo link in entry.NestedResourceInfos)
                {
                    var prop = actualType.GetProperty(link.Name, UndeclaredPropertyBehavior.Support);
                    if (prop != null)
                    {
                        ValidatePropertyMatch(prop, link, this.MaterializerContext.Model, true /*performEntityCheck*/);
                    }
                }

                foreach (ODataNestedResourceInfo link in entry.NestedResourceInfos)
                {
                    MaterializerNavigationLink linkState = MaterializerNavigationLink.GetLink(link);

                    if (linkState == null)
                    {
                        continue;
                    }

                    var prop = actualType.GetProperty(link.Name, this.MaterializerContext.UndeclaredPropertyBehavior);

                    if (prop == null)
                    {
                        if (entry.ShouldUpdateFromPayload)
                        {
                            this.MaterializeDynamicProperty(entry, link);
                        }

                        continue;
                    }

                    // includeLinks is for Navigation property, so we should handle complex property when includeLinks equals false;
                    if (!includeLinks && (prop.IsEntityCollection || prop.EntityCollectionItemType != null))
                    {
                        continue;
                    }

                    if (linkState.Feed != null)
                    {
                        this.ApplyFeedToCollection(entry, prop, linkState.Feed, includeLinks);
                    }
                    else if (linkState.Entry != null)
                    {
                        MaterializerEntry linkEntry = linkState.Entry;

                        if (linkEntry.Entry != null)
                        {
                            this.Materialize(linkEntry, prop.PropertyType, includeLinks);
                        }

                        if (entry.ShouldUpdateFromPayload)
                        {
                            prop.SetValue(entry.ResolvedObject, linkEntry.ResolvedObject, link.Name, true /* allowAdd? */);

                            if (!this.MaterializerContext.Context.DisableInstanceAnnotationMaterialization && linkEntry.ShouldUpdateFromPayload)
                            {
                                // Apply instance annotation for navigation property
                                this.InstanceAnnotationMaterializationPolicy.SetInstanceAnnotations(
                                    prop.PropertyName, linkEntry.Entry, entry.ActualType.ElementType, entry.ResolvedObject);

                                // Apply instance annotation for entity of the navigation property
                                this.InstanceAnnotationMaterializationPolicy.SetInstanceAnnotations(linkEntry.Entry, linkEntry.ResolvedObject);
                            }

                            this.EntityTrackingAdapter.MaterializationLog.SetLink(entry, prop.PropertyName, linkEntry.ResolvedObject);
                        }
                    }
                }
            }

            foreach (var e in entry.Properties)
            {
                if (e.Value is ODataStreamReferenceValue)
                {
                    continue;
                }

                var prop = actualType.GetProperty(e.Name, this.MaterializerContext.UndeclaredPropertyBehavior);
                if (prop == null)
                {
                    if (entry.ShouldUpdateFromPayload)
                    {
                        this.MaterializeDynamicProperty(e, entry.ResolvedObject);
                    }

                    continue;
                }

                if (entry.ShouldUpdateFromPayload)
                {
                    ValidatePropertyMatch(prop, e, this.MaterializerContext.Model, true /*performEntityCheck*/);

                    this.ApplyDataValue(actualType, e, entry.ResolvedObject);
                }
            }

            // apply link values if present
            ApplyLinkProperties(actualType, entry);

            Debug.Assert(entry.ResolvedObject != null, "entry.ResolvedObject != null -- otherwise we didn't do any useful work");

            BaseEntityType entity = entry.ResolvedObject as BaseEntityType;

            if (entity != null)
            {
                entity.Context = this.EntityTrackingAdapter.Context;

                if (!entry.IsTracking)
                {
                    int?           streamDescriptorsCount = entry.EntityDescriptor.StreamDescriptors?.Count;
                    IEdmEntityType entityType             =
                        this.EntityTrackingAdapter.Model.FindDeclaredType(entry.Entry.TypeName) as IEdmEntityType;

                    if (streamDescriptorsCount > 0 || entityType?.HasStream == true)
                    {
                        entity.EntityDescriptor = entry.EntityDescriptor;
                    }
                }
            }

            this.MaterializerContext.ResponsePipeline.FireEndEntryEvents(entry);
        }
Beispiel #11
0
        /// <summary>Materializes the specified <paramref name="entry"/>.</summary>
        /// <param name="entry">Entry with object to materialize.</param>
        /// <param name="includeLinks">Whether links that are expanded should be materialized.</param>
        /// <remarks>This is a payload-driven materialization process.</remarks>
        private void MaterializeResolvedEntry(MaterializerEntry entry, bool includeLinks)
        {
            Debug.Assert(entry.Entry != null, "entry != null");
            Debug.Assert(entry.ResolvedObject != null, "entry.ResolvedObject != null -- otherwise not resolved/created!");

            ClientTypeAnnotation actualType = entry.ActualType;

            // While materializing entities, we need to make sure the payload that came in the wire is also an entity.
            // Otherwise we need to fail.
            if (!actualType.IsEntityType)
            {
                throw DSClient.Error.InvalidOperation(DSClient.Strings.AtomMaterializer_InvalidNonEntityType(actualType.ElementTypeName));
            }

            // Note that even if ShouldUpdateFromPayload is false, we will still be creating
            // nested instances (but not their links), so they show up in the data context
            // entries. This keeps this code compatible with V1 behavior.
            this.MaterializeDataValues(actualType, entry.Properties, this.MaterializerContext.IgnoreMissingProperties);

            if (entry.NavigationLinks != null)
            {
                foreach (ODataNavigationLink link in entry.NavigationLinks)
                {
                    var prop = actualType.GetProperty(link.Name, true);
                    if (prop != null)
                    {
                        ValidatePropertyMatch(prop, link, this.MaterializerContext.Model, true /*performEntityCheck*/);
                    }
                }

                if (includeLinks)
                {
                    foreach (ODataNavigationLink link in entry.NavigationLinks)
                    {
                        MaterializerNavigationLink linkState = MaterializerNavigationLink.GetLink(link);

                        // Ignore...
                        if (linkState == null)
                        {
                            continue;
                        }

                        var prop = actualType.GetProperty(link.Name, this.MaterializerContext.IgnoreMissingProperties);

                        if (prop == null)
                        {
                            continue;
                        }

                        if (linkState.Feed != null)
                        {
                            this.ApplyFeedToCollection(entry, prop, linkState.Feed, includeLinks);
                        }
                        else if (linkState.Entry != null)
                        {
                            MaterializerEntry linkEntry = linkState.Entry;

                            if (linkEntry.Entry != null)
                            {
                                Debug.Assert(includeLinks, "includeLinks -- otherwise we shouldn't be materializing this entry");
                                this.Materialize(linkEntry, prop.PropertyType, includeLinks);
                            }

                            if (entry.ShouldUpdateFromPayload)
                            {
                                prop.SetValue(entry.ResolvedObject, linkEntry.ResolvedObject, link.Name, true /* allowAdd? */);
                                this.EntityTrackingAdapter.MaterializationLog.SetLink(entry, prop.PropertyName, linkEntry.ResolvedObject);
                            }
                        }
                    }
                }
            }

            foreach (var e in entry.Properties)
            {
                if (e.Value is ODataStreamReferenceValue)
                {
                    continue;
                }

                var prop = actualType.GetProperty(e.Name, this.MaterializerContext.IgnoreMissingProperties);
                if (prop == null)
                {
                    continue;
                }

                if (entry.ShouldUpdateFromPayload)
                {
                    ValidatePropertyMatch(prop, e, this.MaterializerContext.Model, true /*performEntityCheck*/);

                    this.ApplyDataValue(actualType, e, entry.ResolvedObject);
                }
            }

            // apply link values if present
            ApplyLinkProperties(actualType, entry);

            Debug.Assert(entry.ResolvedObject != null, "entry.ResolvedObject != null -- otherwise we didn't do any useful work");

            BaseEntityType entity = entry.ResolvedObject as BaseEntityType;

            if (entity != null)
            {
                entity.Context = this.EntityTrackingAdapter.Context;
            }

            this.MaterializerContext.ResponsePipeline.FireEndEntryEvents(entry);
        }
Beispiel #12
0
        /// <summary>
        /// Creates the next object from the stream.
        /// </summary>
        /// <returns>false if stream is finished</returns>
        private bool MoveNextInternal()
        {
            // For empty results using ResultsWrapper, just return false.
            if (this.materializer == null)
            {
                Debug.Assert(this.current == null, "this.current == null -- otherwise this.materializer should have some value.");
                return(false);
            }

            this.current = null;
            this.materializer.ClearLog();

            bool result = false;
            Type implementationType;

            GetTypeForMaterializer(this.expectingPrimitiveValue, this.elementType, this.responseInfo.Model, out implementationType);

            // if implementationType is not null this is a collection of entities
            if (implementationType != null)
            {
                // this is for CreateQuery/Execute<Collection<T>>
                // We should only "move" once in here, in the first iteration we will load everything and return true
                // Second iteration we will always return false.

                if (this.moved)
                {
                    return(false);
                }

                Type expectedType = implementationType.GetGenericArguments()[0]; // already know its IList<>
                implementationType = this.elementType;
                if (implementationType.IsInterface())
                {
                    implementationType = typeof(System.Collections.ObjectModel.Collection <>).MakeGenericType(expectedType);
                }

                IList list = (IList)Activator.CreateInstance(implementationType);

                while (this.materializer.Read())
                {
                    list.Add(this.materializer.CurrentValue);
                }

                this.moved = true;

                this.current = list;
                result       = true;
            }

            if (this.current == null)
            {
                if (this.expectingPrimitiveValue && this.moved)
                {
                    result = false;
                }
                else
                {
                    result = this.materializer.Read();
                    if (result)
                    {
                        BaseEntityType entity = this.materializer.CurrentValue as BaseEntityType;
                        if (entity != null)
                        {
                            entity.Context = this.responseInfo.Context;
                        }

                        this.current = this.materializer.CurrentValue;
                    }

                    this.moved = true;
                }
            }

            this.materializer.ApplyLogToContext();

            return(result);
        }