Пример #1
0
 public static void serialize <T>(T serializeObject)
 {
     //this is fine...
     SerializableEntity <T> entity =
         new SerializableEntity <T>(serializeObject);
 }
Пример #2
0
        /// <summary>
        /// Creates new instance of
        /// <see cref="Apache.Http.HttpEntity">Apache.Http.HttpEntity</see>
        /// based on the current state.
        /// </summary>
        public virtual HttpEntity Build()
        {
            AbstractHttpEntity e;

            if (this.text != null)
            {
                e = new StringEntity(this.text, GetContentOrDefault(ContentType.DefaultText));
            }
            else
            {
                if (this.binary != null)
                {
                    e = new ByteArrayEntity(this.binary, GetContentOrDefault(ContentType.DefaultBinary
                                                                             ));
                }
                else
                {
                    if (this.stream != null)
                    {
                        e = new InputStreamEntity(this.stream, 1, GetContentOrDefault(ContentType.DefaultBinary
                                                                                      ));
                    }
                    else
                    {
                        if (this.parameters != null)
                        {
                            e = new UrlEncodedFormEntity(this.parameters, this.contentType != null ? this.contentType
                                                         .GetCharset() : null);
                        }
                        else
                        {
                            if (this.serializable != null)
                            {
                                e = new SerializableEntity(this.serializable);
                                e.SetContentType(ContentType.DefaultBinary.ToString());
                            }
                            else
                            {
                                if (this.file != null)
                                {
                                    e = new FileEntity(this.file, GetContentOrDefault(ContentType.DefaultBinary));
                                }
                                else
                                {
                                    e = new BasicHttpEntity();
                                }
                            }
                        }
                    }
                }
            }
            if (e.GetContentType() != null && this.contentType != null)
            {
                e.SetContentType(this.contentType.ToString());
            }
            e.SetContentEncoding(this.contentEncoding);
            e.SetChunked(this.chunked);
            if (this.gzipCompress)
            {
                return(new GzipCompressingEntity(e));
            }
            return(e);
        }
Пример #3
0
 private EntityDataKey GetEntityKey(QueryStructuralType type, SerializableEntity entity)
 {
     ExceptionUtilities.CheckArgumentNotNull(type, "type");
     ExceptionUtilities.CheckArgumentNotNull(entity, "entity");
     return(EntityDataKey.CreateFromValues(entity.Properties.Where(p => type.Properties.Any(k => k.IsPrimaryKey && k.Name == p.Name)).Select(p => this.DataOracleConverter.Convert(p))));
 }
        private void ConvertEntityProperty(SerializableEntity entity, EntityContainerData data, Dictionary<SerializableEntity, EntitySetDataRow> rowMap)
        {
            var row = rowMap[entity];

            foreach (var prop in entity.Properties)
            {
                var relatedRows = prop.Value as IEnumerable<SerializableEntity>;
                var relatedRow = prop.Value as SerializableEntity;
                if (relatedRows == null)
                {
                    if (relatedRow != null)
                    {
                        relatedRows = new[] { relatedRow };
                    }
                }

                if (relatedRows != null)
                {
                    var type = row.EntityType;
                    var navprop = type.AllNavigationProperties.Single(c => c.Name == prop.Name);

                    // handle MEST scenario where there are multiple association sets corresponding to a navigation property
                    var assocSets = data.EntityContainer.AssociationSets.Where(c => c.AssociationType == navprop.Association);
                    var assocSet = assocSets.Single(set => set.Ends.Any(end => end.AssociationEnd == navprop.FromAssociationEnd && end.EntitySet.Name == entity.EntitySetName));

                    var associationSetData = data[assocSet];

                    foreach (var rr in relatedRows)
                    {
                        if (!associationSetData.Rows.Where(c => c.GetRoleKey(navprop.FromAssociationEnd.RoleName) == row.Key && c.GetRoleKey(navprop.ToAssociationEnd.RoleName) == rowMap[rr].Key).Any())
                        {
                            var associationRow = associationSetData.AddNewRow();
                            associationRow.SetRoleKey(navprop.FromAssociationEnd.RoleName, row.Key);
                            associationRow.SetRoleKey(navprop.ToAssociationEnd.RoleName, rowMap[rr].Key);
                        }
                    }
                }
                else
                {
                    // it could still be a null navigation property
                    var navigation = row.EntityType.AllNavigationProperties.SingleOrDefault(p => p.Name == prop.Name);
                    if (navigation == null)
                    {
                        var namedValue = this.Convert(prop);
                        row.SetValue(namedValue.Name, namedValue.Value);
                    }
                }
            }
        }
Пример #5
0
        /// <summary>
        /// Finds the structural value for the given serializable entity and updates it, or create it if it does not exist
        /// </summary>
        /// <param name="baseType">The base type of the entity's set</param>
        /// <param name="entity">The entity to find and synchronize</param>
        /// <param name="existingEntityGraph">The existing entities in the set, mapped by key</param>
        /// <returns>The synchronized entity</returns>
        private QueryStructuralValue FindAndSynchronizeEntity(QueryEntityType baseType, SerializableEntity entity, IDictionary <EntityDataKey, QueryStructuralValue> existingEntityGraph)
        {
            QueryStructuralValue alreadySynchronized;

            if (this.synchronizationCache.TryGetValue(entity, out alreadySynchronized))
            {
                return(alreadySynchronized);
            }

            // if the type does not match, it must be a derived type
            var type = baseType;

            if (type.EntityType.FullName != entity.EntityType)
            {
                type = type.DerivedTypes.Cast <QueryEntityType>().SingleOrDefault(t => t.EntityType.FullName == entity.EntityType);
                ExceptionUtilities.CheckObjectNotNull(type, "Could not find a type named '{0}'", entity.EntityType);
            }

            // compute the key for the entity
            var key = this.GetEntityKey(type, entity);
            QueryStructuralValue structural;
            bool isNewInstance = !existingEntityGraph.TryGetValue(key, out structural);

            // if we don't find it, create it
            if (isNewInstance)
            {
                structural = type.CreateNewInstance();
                InitMemberStreamTypes(type, structural);
            }

            this.synchronizationCache[entity] = structural;
            this.SynchronizeProperties(baseType, entity, type, structural, existingEntityGraph);
            this.SynchronizeStreams(entity, structural);

            structural.MarkDynamicPropertyValues();

            // if its a new instance, add it to the top-level collection
            if (isNewInstance)
            {
                this.QueryDataSet[type.EntitySet.Name].Elements.Add(structural);
                existingEntityGraph[this.GetEntityKey(structural)] = structural;
            }

            return(structural);
        }