Beispiel #1
0
        private void SetEpmValueForSegment(EntityPropertyMappingInfo epmInfo, int propertyValuePathIndex, IEdmStructuredTypeReference segmentStructuralTypeReference, List <ODataProperty> existingProperties, object propertyValue)
        {
            string propertyName = epmInfo.PropertyValuePath[propertyValuePathIndex].PropertyName;

            if (!epmInfo.Attribute.KeepInContent)
            {
                IEdmTypeReference type;
                ODataProperty     property = existingProperties.FirstOrDefault <ODataProperty>(p => string.CompareOrdinal(p.Name, propertyName) == 0);
                ODataComplexValue value2   = null;
                if (property != null)
                {
                    value2 = property.Value as ODataComplexValue;
                    if (value2 == null)
                    {
                        return;
                    }
                }
                IEdmProperty property2 = segmentStructuralTypeReference.FindProperty(propertyName);
                if ((property2 == null) && (propertyValuePathIndex != (epmInfo.PropertyValuePath.Length - 1)))
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.EpmReader_OpenComplexOrCollectionEpmProperty(epmInfo.Attribute.SourcePath));
                }
                if ((property2 == null) || (this.MessageReaderSettings.DisablePrimitiveTypeConversion && property2.Type.IsODataPrimitiveTypeKind()))
                {
                    type = EdmCoreModel.Instance.GetString(true);
                }
                else
                {
                    type = property2.Type;
                }
                switch (type.TypeKind())
                {
                case EdmTypeKind.Primitive:
                    object obj2;
                    if (type.IsStream())
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.EpmReader_SetEpmValueForSegment_StreamProperty));
                    }
                    if (propertyValue == null)
                    {
                        ReaderValidationUtils.ValidateNullValue(this.atomInputContext.Model, type, this.atomInputContext.MessageReaderSettings, true, this.atomInputContext.Version);
                        obj2 = null;
                    }
                    else
                    {
                        obj2 = AtomValueUtils.ConvertStringToPrimitive((string)propertyValue, type.AsPrimitive());
                    }
                    this.AddEpmPropertyValue(existingProperties, propertyName, obj2, segmentStructuralTypeReference.IsODataEntityTypeKind());
                    return;

                case EdmTypeKind.Complex:
                {
                    if (value2 == null)
                    {
                        value2 = new ODataComplexValue {
                            TypeName   = type.ODataFullName(),
                            Properties = new ReadOnlyEnumerable <ODataProperty>()
                        };
                        this.AddEpmPropertyValue(existingProperties, propertyName, value2, segmentStructuralTypeReference.IsODataEntityTypeKind());
                    }
                    IEdmComplexTypeReference reference2 = type.AsComplex();
                    this.SetEpmValueForSegment(epmInfo, propertyValuePathIndex + 1, reference2, ReaderUtils.GetPropertiesList(value2.Properties), propertyValue);
                    return;
                }

                case EdmTypeKind.Collection:
                {
                    ODataCollectionValue value4 = new ODataCollectionValue {
                        TypeName = type.ODataFullName(),
                        Items    = new ReadOnlyEnumerable((List <object>)propertyValue)
                    };
                    this.AddEpmPropertyValue(existingProperties, propertyName, value4, segmentStructuralTypeReference.IsODataEntityTypeKind());
                    return;
                }
                }
                throw new ODataException(Microsoft.Data.OData.Strings.General_InternalError(InternalErrorCodes.EpmReader_SetEpmValueForSegment_TypeKind));
            }
        }
Beispiel #2
0
        /// <summary>
        /// This method creates an reads the property from the input and
        /// returns an <see cref="ODataProperty"/> representing the read property.
        /// </summary>
        /// <param name="expectedProperty">The <see cref="IEdmProperty"/> producing the property to be read.</param>
        /// <param name="expectedPropertyTypeReference">The expected type reference of the property to read.</param>
        /// <returns>An <see cref="ODataProperty"/> representing the read property.</returns>
        internal ODataProperty ReadTopLevelProperty(IEdmStructuralProperty expectedProperty, IEdmTypeReference expectedPropertyTypeReference)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(this.JsonReader.NodeType == JsonNodeType.None, "Pre-Condition: expected JsonNodeType.None, the reader must not have been used yet.");
            Debug.Assert(
                expectedPropertyTypeReference == null || !expectedPropertyTypeReference.IsODataEntityTypeKind(),
                "If the expected type is specified it must not be an entity type.");
            this.JsonReader.AssertNotBuffering();

            if (!this.Model.IsUserModel())
            {
                throw new ODataException(ODataErrorStrings.ODataJsonPropertyAndValueDeserializer_TopLevelPropertyWithoutMetadata);
            }

            // Read the response wrapper "d" if expected.
            this.ReadPayloadStart(false /*isReadingNestedPayload*/);

            string expectedPropertyName = ReaderUtils.GetExpectedPropertyName(expectedProperty);

            string propertyName  = null;
            object propertyValue = null;

            // We have to support reading top-level complex values without the { "property": ... } wrapper for open properties
            // in WCF DS Server backward compat mode. (Open property == property without expected type for us).
            if (this.ShouldReadTopLevelPropertyValueWithoutPropertyWrapper(expectedPropertyTypeReference))
            {
                // We will report the value without property wrapper as a property with empty name (this is technically invalid, but it will only happen in WCF DS Server mode).
                propertyName = expectedPropertyName ?? string.Empty;

                // Read the value directly
                propertyValue = this.ReadNonEntityValue(
                    expectedPropertyTypeReference,
                    /*duplicatePropertyNamesChecker*/ null,
                    /*collectionValidator*/ null,
                    /*validateNullValue*/ true,
                    propertyName);
            }
            else
            {
                // Read the start of the object container around the property { "property": ... }
                this.JsonReader.ReadStartObject();

                // Read through all top-level properties, ignore the ones with reserved names (i.e., reserved
                // characters in their name) and throw if we find none or more than one properties without reserved name.
                bool   foundProperty     = false;
                string foundPropertyName = null;
                while (this.JsonReader.NodeType == JsonNodeType.Property)
                {
                    // Read once - this should be the property
                    propertyName = this.JsonReader.ReadPropertyName();

                    if (!ValidationUtils.IsValidPropertyName(propertyName))
                    {
                        // We ignore properties with an invalid name since these are extension points for the future.
                        this.JsonReader.SkipValue();
                    }
                    else
                    {
                        if (foundProperty)
                        {
                            // There should be only one property in the top-level property wrapper that does not have a reserved name.
                            throw new ODataException(ODataErrorStrings.ODataJsonPropertyAndValueDeserializer_InvalidTopLevelPropertyPayload);
                        }

                        foundProperty     = true;
                        foundPropertyName = propertyName;

                        // Now read the property value
                        propertyValue = this.ReadNonEntityValue(
                            expectedPropertyTypeReference,
                            /*duplicatePropertyNamesChecker*/ null,
                            /*collectionValidator*/ null,
                            /*validateNullValue*/ true,
                            propertyName);
                    }
                }

                if (!foundProperty)
                {
                    // No property found; there should be exactly one property in the top-level property wrapper that does not have a reserved name.
                    throw new ODataException(ODataErrorStrings.ODataJsonPropertyAndValueDeserializer_InvalidTopLevelPropertyPayload);
                }

                Debug.Assert(foundPropertyName != null, "foundPropertyName != null");
                ReaderValidationUtils.ValidateExpectedPropertyName(expectedPropertyName, foundPropertyName);
                propertyName = foundPropertyName;

                // Read over the end object - note that this might be the last node in the input (in case there's no response wrapper)
                this.JsonReader.Read();
            }

            // Read the end of the response wrapper "d" if expected.
            this.ReadPayloadEnd(false /*isReadingNestedPayload*/);

            Debug.Assert(this.JsonReader.NodeType == JsonNodeType.EndOfInput, "Post-Condition: expected JsonNodeType.EndOfInput");
            this.JsonReader.AssertNotBuffering();

            Debug.Assert(propertyName != null, "propertyName != null");

            return(new ODataProperty
            {
                Name = propertyName,
                Value = propertyValue
            });
        }
Beispiel #3
0
 protected void SetEntryEpmValue(EntityPropertyMappingInfo epmInfo, object propertyValue)
 {
     this.SetEpmValue(ReaderUtils.GetPropertiesList(this.entryState.Entry.Properties), this.entryState.EntityType.ToTypeReference(), epmInfo, propertyValue);
 }
Beispiel #4
0
        private void SetEpmValueForSegment(
            EntityPropertyMappingInfo epmInfo,
            int propertyValuePathIndex,
            IEdmStructuredTypeReference segmentStructuralTypeReference,
            List <ODataProperty> existingProperties,
            object propertyValue)
        {
            Debug.Assert(epmInfo != null, "epmInfo != null");
            Debug.Assert(propertyValuePathIndex < epmInfo.PropertyValuePath.Length, "The propertyValuePathIndex is out of bounds.");
            Debug.Assert(existingProperties != null, "existingProperties != null");

            string propertyName = epmInfo.PropertyValuePath[propertyValuePathIndex].PropertyName;

            // Do not set out-of-content values if the EPM is defined as KeepInContent=true.
            if (epmInfo.Attribute.KeepInContent)
            {
                return;
            }

            // Try to find the property in the existing properties
            // If the property value is atomic from point of view of EPM (non-streaming collection or primitive) then if it already exists
            // it must have been in-content, and thus we leave it as is (note that two EPMs can't map to the same property, we verify that upfront).
            // If the property value is non-atomic, then it is a complex value, we might want to merge the new value comming from EPM with it.
            ODataProperty     existingProperty     = existingProperties.FirstOrDefault(p => string.CompareOrdinal(p.Name, propertyName) == 0);
            ODataComplexValue existingComplexValue = null;

            if (existingProperty != null)
            {
                // In case the property exists and it's a complex value we will try to merge.
                // Note that if the property is supposed to be complex, but it already has a null value, then the null wins.
                // Since in-content null complex value wins over any EPM complex value.
                existingComplexValue = existingProperty.Value as ODataComplexValue;
                if (existingComplexValue == null)
                {
                    return;
                }
            }

            IEdmProperty propertyMetadata = segmentStructuralTypeReference.FindProperty(propertyName);

            Debug.Assert(propertyMetadata != null || segmentStructuralTypeReference.IsOpen(), "We should have verified that if the property is not declared the type must be open.");

            if (propertyMetadata == null && propertyValuePathIndex != epmInfo.PropertyValuePath.Length - 1)
            {
                throw new ODataException(o.Strings.EpmReader_OpenComplexOrCollectionEpmProperty(epmInfo.Attribute.SourcePath));
            }

            // Open properties in EPM are by default of type Edm.String - there's no way to specify a typename in EPM
            // consumer is free to do the conversion later on if it needs to.
            // Note that this effectively means that ODataMessageReaderSettings.DisablePrimitiveTypeConversion is as if it's turned on for open EPM properties.
            IEdmTypeReference propertyType;

            if (propertyMetadata == null ||
                (this.MessageReaderSettings.DisablePrimitiveTypeConversion && propertyMetadata.Type.IsODataPrimitiveTypeKind()))
            {
                propertyType = EdmCoreModel.Instance.GetString(/*nullable*/ true);
            }
            else
            {
                propertyType = propertyMetadata.Type;
            }

            // NOTE: WCF DS Server only applies the values when
            // - It's an open property
            // - It's not a key property
            // - It's a key property and it's a POST operation
            // ODataLib here will always set the property though.
            switch (propertyType.TypeKind())
            {
            case EdmTypeKind.Primitive:
            {
                if (propertyType.IsStream())
                {
                    throw new ODataException(o.Strings.General_InternalError(InternalErrorCodes.EpmReader_SetEpmValueForSegment_StreamProperty));
                }

                object primitiveValue;
                if (propertyValue == null)
                {
                    ReaderValidationUtils.ValidateNullValue(this.atomInputContext.Model, propertyType, this.atomInputContext.MessageReaderSettings, /*validateNullValue*/ true, this.atomInputContext.Version);
                    primitiveValue = null;
                }
                else
                {
                    // Convert the value to the desired target type
                    primitiveValue = AtomValueUtils.ConvertStringToPrimitive((string)propertyValue, propertyType.AsPrimitive());
                }

                this.AddEpmPropertyValue(existingProperties, propertyName, primitiveValue, segmentStructuralTypeReference.IsODataEntityTypeKind());
            }

            break;

            case EdmTypeKind.Complex:
                // Note: Unlike WCF DS we don't have a preexisting instance to override (since complex values are atomic, so we should not updated them)
                // In our case the complex value either doesn't exist yet on the entry being reported (easy, create it)
                // or it exists, but then it was created during reading of previous normal or EPM properties for this entry. It never exists before
                // we ever get to see the entity. So in our case we will never recreate the complex value, we always start with new one
                // and update it with new properties as they come. (Next time we will start over with a new complex value.)
                Debug.Assert(
                    existingComplexValue == null || (existingProperty != null && existingProperty.Value == existingComplexValue),
                    "If we have existing complex value, we must have an existing property as well.");
                Debug.Assert(
                    epmInfo.PropertyValuePath.Length > propertyValuePathIndex + 1,
                    "Complex value can not be a leaf segment in the source property path. We should have failed constructing the EPM trees for it.");

                if (existingComplexValue == null)
                {
                    Debug.Assert(existingProperty == null, "If we don't have an existing complex value, then we must not have an existing property at all.");

                    // Create a new complex value and set its type name to the type name of the property type (in case of EPM we never have type name from the payload)
                    existingComplexValue = new ODataComplexValue
                    {
                        TypeName   = propertyType.ODataFullName(),
                        Properties = new ReadOnlyEnumerable <ODataProperty>()
                    };

                    this.AddEpmPropertyValue(existingProperties, propertyName, existingComplexValue, segmentStructuralTypeReference.IsODataEntityTypeKind());
                }

                // Get the properties list of the complex value and recursively set the next EPM segment value to it.
                // Note that on inner complex value we don't need to check for duplicate properties
                // because EPM will never add a property which already exists (see the start of this method).
                IEdmComplexTypeReference complexPropertyTypeReference = propertyType.AsComplex();
                Debug.Assert(complexPropertyTypeReference != null, "complexPropertyTypeReference != null");
                this.SetEpmValueForSegment(
                    epmInfo,
                    propertyValuePathIndex + 1,
                    complexPropertyTypeReference,
                    ReaderUtils.GetPropertiesList(existingComplexValue.Properties),
                    propertyValue);

                break;

            case EdmTypeKind.Collection:
                Debug.Assert(propertyType.IsNonEntityODataCollectionTypeKind(), "Collection types in EPM must be atomic.");

                // In this case the property value is the internal list of items.
                // Create a new collection value and set the list as the list of items on it.
                ODataCollectionValue collectionValue = new ODataCollectionValue
                {
                    TypeName = propertyType.ODataFullName(),
                    Items    = new ReadOnlyEnumerable((List <object>)propertyValue)
                };

                this.AddEpmPropertyValue(existingProperties, propertyName, collectionValue, segmentStructuralTypeReference.IsODataEntityTypeKind());

                break;

            default:
                throw new ODataException(o.Strings.General_InternalError(InternalErrorCodes.EpmReader_SetEpmValueForSegment_TypeKind));
            }
        }
        public List <Comment> GetCommentByPostId(int id)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();
                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"
                        SELECT c.Id, c.PostId, c.UserProfileId, c.Subject, c.Content, c.CreateDateTime,
                               p.Id, p.Title, p.Content, p.ImageLocation, p.CreateDateTime, p.PublishDateTime,
                               p.IsApproved, p.CategoryId, p.UserProfileId,
                               u.Id, u.DisplayName, u.FirstName, u.LastName, u.Email, 
                               u.CreateDateTime, u.ImageLocation, u.UserTypeId,
                               ut.Id, ut.Name
                        FROM Comment c
                        LEFT JOIN Post p  ON p.Id = c.PostId
                        LEFT JOIN UserProfile u ON u.Id = p.UserProfileId
                        LEFT JOIN UserType ut ON ut.Id = u.UserTypeId
                        WHERE c.PostId = @id
                    ";
                    cmd.Parameters.AddWithValue("@id", id);
                    SqlDataReader reader = cmd.ExecuteReader();

                    List <Comment> comments = new List <Comment>();
                    while (reader.Read())
                    {
                        Comment comment = new Comment
                        {
                            Id             = reader.GetInt32(reader.GetOrdinal("Id")),
                            PostId         = reader.GetInt32(reader.GetOrdinal("PostId")),
                            UserProfileId  = reader.GetInt32(reader.GetOrdinal("UserProfileId")),
                            Subject        = reader.GetString(reader.GetOrdinal("Subject")),
                            Content        = reader.GetString(reader.GetOrdinal("Content")),
                            CreateDataTime = reader.GetDateTime(reader.GetOrdinal("CreateDateTime")),
                            Post           = new Post()
                            {
                                Id              = reader.GetInt32(reader.GetOrdinal("PostId")),
                                Title           = reader.GetString(reader.GetOrdinal("Title")),
                                Content         = reader.GetString(reader.GetOrdinal("Content")),
                                ImageLocation   = ReaderUtils.GetNullableString(reader, "ImageLocation"),
                                CreateDateTime  = reader.GetDateTime(reader.GetOrdinal("CreateDateTime")),
                                PublishDateTime = ReaderUtils.GetNullableDateTime(reader, "PublishDateTime"),
                                IsApproved      = reader.GetBoolean(reader.GetOrdinal("IsApproved")),
                                CategoryId      = reader.GetInt32(reader.GetOrdinal("CategoryId")),
                            },
                            UserProfile = new UserProfile()
                            {
                                Id             = reader.GetInt32(reader.GetOrdinal("UserProfileId")),
                                DisplayName    = reader.GetString(reader.GetOrdinal("DisplayName")),
                                FirstName      = reader.GetString(reader.GetOrdinal("FirstName")),
                                LastName       = reader.GetString(reader.GetOrdinal("LastName")),
                                Email          = reader.GetString(reader.GetOrdinal("Email")),
                                CreateDateTime = reader.GetDateTime(reader.GetOrdinal("CreateDateTime")),
                                ImageLocation  = ReaderUtils.GetNullableString(reader, "ImageLocation"),
                                UserTypeId     = reader.GetInt32(reader.GetOrdinal("UserTypeId")),
                                UserType       = new UserType()
                                {
                                    Id   = reader.GetInt32(reader.GetOrdinal("UserTypeId")),
                                    Name = reader.GetString(reader.GetOrdinal("Name"))
                                }
                            }
                        };


                        comments.Add(comment);
                    }

                    reader.Close();

                    return(comments);
                }
            }
        }
Beispiel #6
0
        private void LoadAtom(TextReader rdr)
        {
            // "aai" = (/obj/structure/sign/securearea{desc = "A warning sign which reads 'HIGH VOLTAGE'"; icon_state = "shock"; name = "HIGH VOLTAGE"; pixel_y = -32},/turf/space,/area)
            // Move to ID.

            ReaderUtils.ReadUntil(rdr, '"');

            Tile t = new Tile();

            // Get ID contents
            t.origID = ReaderUtils.ReadUntil(rdr, '"');
            idlen    = t.origID.Length;
            //log.InfoFormat("Reading tile {0}", t.origID);

            ReaderUtils.ReadUntil(rdr, '(');

            uint atomID = 0; // Which atom we're currently on IN THIS TILEDEF.

            // Read atomdefs.
            bool finishedReadingAtoms = false;

            while (!finishedReadingAtoms)
            {
                char nextChar = ReaderUtils.GetNextChar(rdr);
                if (nextChar == ')')
                {
                    break;
                }

                ReaderUtils.ReadUntil(rdr, '/');

                string atomType = ReaderUtils.ReadCharRange(rdr, ATOM_NAME_CHARS);
                if (string.IsNullOrWhiteSpace(atomType))
                {
                    throw new InvalidDataException(string.Format("atomType is \"{0}\"", atomType));
                }

                Atom a = new Atom(atomType, false);

                nextChar = ReaderUtils.GetNextChar(rdr);
                switch (nextChar)
                {
                case '{':
                    // We're in a propertygroup.  Read the properties.
                    rdr.Read();
                    LoadPropertyGroup(rdr, a);
                    //rdr.Read();
                    break;

                case ',':
                    rdr.Read();
                    break;

                case ')':
                    finishedReadingAtoms = true;
                    rdr.Read();
                    break;

                default:
                    //log.FatalFormat(
                    Console.WriteLine("UNKNOWN CHARACTER {0} IN TILEDEF {1}, ATOMDEF #{2}. EXPECTING: '{{),'", nextChar, t.origID, atomID);
                    break;
                }
                t.Atoms.Add(a);
                atomID++;
            }

            Tiles[t.origID] = t;

            string read           = ReaderUtils.ReadCharRange(rdr, WHITESPACE);
            int    numLineReturns = read.Count((char c) => {
                return(c == '\n');
            });

            //Console.WriteLine("{1}",read,numLineReturns);
            if (numLineReturns > 1)
            {
                section = DMMSection.Map;
                Console.WriteLine("Finished reading Tile List section:  {0} tiles loaded.", Tiles.Count);
            }
        }
 void cb_LoadDefaultDLLs_Click(object sender, RoutedEventArgs e)
 {
     ReaderUtils.LoadDefaultDlls();
 }
Beispiel #8
0
 public void TestInit()
 {
     this.entry      = ReaderUtils.CreateNewEntry();
     this.entityType = new EdmEntityType("TestNamespace", "EntityType");
 }
Beispiel #9
0
 private void StartEntry()
 {
     this.EnterScope(ODataReaderState.EntryStart, ReaderUtils.CreateNewEntry(), base.CurrentEntityType);
     this.CurrentJsonScope.DuplicatePropertyNamesChecker = this.jsonInputContext.CreateDuplicatePropertyNamesChecker();
 }
Beispiel #10
0
 private CIwVec3 GetVec3Fixed(ReaderUtils.Vector3 vector3)
 {
     return new CIwVec3(
         (int)(vector3.X * AirplaySDKMath.IW_GEOM_ONE),
         (int)(vector3.Y * AirplaySDKMath.IW_GEOM_ONE),
         (int)(vector3.Z * AirplaySDKMath.IW_GEOM_ONE)
         );
 }
Beispiel #11
0
        private void ReadOperationsMetadata(ODataEntry entry, bool isActions)
        {
            string str = isActions ? "actions" : "functions";

            if (base.JsonReader.NodeType != JsonNodeType.StartObject)
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_PropertyInEntryMustHaveObjectValue(str, base.JsonReader.NodeType));
            }
            base.JsonReader.ReadStartObject();
            HashSet <string> set = new HashSet <string>(StringComparer.Ordinal);

            while (base.JsonReader.NodeType == JsonNodeType.Property)
            {
                ODataOperation operation;
                string         item = base.JsonReader.ReadPropertyName();
                if (set.Contains(item))
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_RepeatMetadataValue(str, item));
                }
                set.Add(item);
                if (base.JsonReader.NodeType != JsonNodeType.StartArray)
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MetadataMustHaveArrayValue(str, base.JsonReader.NodeType));
                }
                base.JsonReader.ReadStartArray();
                if (base.JsonReader.NodeType == JsonNodeType.StartObject)
                {
                    goto Label_0227;
                }
                throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_OperationMetadataArrayExpectedAnObject(str, base.JsonReader.NodeType));
Label_00E1:
                base.JsonReader.ReadStartObject();
                if (isActions)
                {
                    operation = new ODataAction();
                    ReaderUtils.AddActionToEntry(entry, (ODataAction)operation);
                }
                else
                {
                    operation = new ODataFunction();
                    ReaderUtils.AddFunctionToEntry(entry, (ODataFunction)operation);
                }
                operation.Metadata = base.ResolveUri(item);
                while (base.JsonReader.NodeType == JsonNodeType.Property)
                {
                    string str3 = base.JsonReader.ReadPropertyName();
                    string str6 = str3;
                    if (str6 == null)
                    {
                        goto Label_01E5;
                    }
                    if (!(str6 == "title"))
                    {
                        if (str6 == "target")
                        {
                            goto Label_019D;
                        }
                        goto Label_01E5;
                    }
                    if (operation.Title != null)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MultipleOptionalPropertiesInOperation(str3, item, str));
                    }
                    string propertyValue = base.JsonReader.ReadStringValue("title");
                    ODataJsonReaderUtils.ValidateOperationJsonProperty(propertyValue, str3, item, str);
                    operation.Title = propertyValue;
                    continue;
Label_019D:
                    if (operation.Target != null)
                    {
                        throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_MultipleTargetPropertiesInOperation(item, str));
                    }
                    string str5 = base.JsonReader.ReadStringValue("target");
                    ODataJsonReaderUtils.ValidateOperationJsonProperty(str5, str3, item, str);
                    operation.Target = base.ProcessUriFromPayload(str5);
                    continue;
Label_01E5:
                    base.JsonReader.SkipValue();
                }
                if (operation.Target == null)
                {
                    throw new ODataException(Microsoft.Data.OData.Strings.ODataJsonEntryAndFeedDeserializer_OperationMissingTargetProperty(item, str));
                }
                base.JsonReader.ReadEndObject();
Label_0227:
                if (base.JsonReader.NodeType == JsonNodeType.StartObject)
                {
                    goto Label_00E1;
                }
                base.JsonReader.ReadEndArray();
            }
            base.JsonReader.ReadEndObject();
        }
Beispiel #12
0
        public Dog GetDogById(int id)
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();

                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT d.Id, 
                                        d.Name AS DogName, 
                                        OwnerId, 
                                        Breed, 
                                        Notes, 
                                        ImageUrl, 
                                        Email, 
                                        o.Name AS OwnerName, 
                                        Address, 
                                        NeighborhoodId, 
                                        Phone, 
                                        n.Name AS NeighborhoodName
                                        FROM Dog d
                                        LEFT JOIN Owner o ON o.Id = d.OwnerId
                                        LEFT JOIN Neighborhood n ON n.Id = o.NeighborhoodId
                                        WHERE d.Id = @id";
                    cmd.Parameters.AddWithValue("@id", id);

                    SqlDataReader reader = cmd.ExecuteReader();

                    Dog dog = null;

                    if (reader.Read())
                    {
                        dog = new Dog()
                        {
                            Id      = id,
                            Name    = reader.GetString(reader.GetOrdinal("DogName")),
                            OwnerId = reader.GetInt32(reader.GetOrdinal("OwnerId")),
                            Owner   = new Owner()
                            {
                                Id             = reader.GetInt32(reader.GetOrdinal("OwnerId")),
                                Email          = reader.GetString(reader.GetOrdinal("Email")),
                                Name           = reader.GetString(reader.GetOrdinal("OwnerName")),
                                Address        = reader.GetString(reader.GetOrdinal("Address")),
                                NeighborhoodId = reader.GetInt32(reader.GetOrdinal("NeighborhoodId")),
                                Neighborhood   = new Neighborhood()
                                {
                                    Id   = reader.GetInt32(reader.GetOrdinal("NeighborhoodId")),
                                    Name = reader.GetString(reader.GetOrdinal("NeighborhoodName"))
                                },
                                Phone = reader.GetString(reader.GetOrdinal("Phone"))
                            },
                            Breed    = reader.GetString(reader.GetOrdinal("Breed")),
                            Notes    = ReaderUtils.GetNullableString(reader, "Notes"),
                            ImageUrl = ReaderUtils.GetNullableString(reader, "ImageUrl")
                        };
                    }

                    reader.Close();

                    return(dog);
                }
            }
        }
Beispiel #13
0
        public List <Dog> GetAllDogs()
        {
            using (SqlConnection conn = Connection)
            {
                conn.Open();

                using (SqlCommand cmd = conn.CreateCommand())
                {
                    cmd.CommandText = @"SELECT d.Id, 
                                        d.Name AS DogName, 
                                        OwnerId, 
                                        Breed, 
                                        Notes, 
                                        ImageUrl, 
                                        Email, 
                                        o.Name AS OwnerName, 
                                        Address, 
                                        NeighborhoodId, 
                                        Phone, 
                                        n.Name AS NeighborhoodName
                                        FROM Dog d
                                        LEFT JOIN Owner o ON o.Id = d.OwnerId
                                        LEFT JOIN Neighborhood n ON n.Id = o.NeighborhoodId";

                    SqlDataReader reader = cmd.ExecuteReader();

                    List <Dog> dogs = new List <Dog>()
                    {
                    };

                    while (reader.Read())
                    {
                        Dog dog = new Dog()
                        {
                            Id      = reader.GetInt32(reader.GetOrdinal("Id")),
                            Name    = reader.GetString(reader.GetOrdinal("DogName")),
                            OwnerId = reader.GetInt32(reader.GetOrdinal("OwnerId")),
                            Owner   = new Owner()
                            {
                                Id             = reader.GetInt32(reader.GetOrdinal("OwnerId")),
                                Email          = reader.GetString(reader.GetOrdinal("Email")),
                                Name           = reader.GetString(reader.GetOrdinal("OwnerName")),
                                Address        = reader.GetString(reader.GetOrdinal("Address")),
                                NeighborhoodId = reader.GetInt32(reader.GetOrdinal("NeighborhoodId")),
                                Neighborhood   = new Neighborhood()
                                {
                                    Id   = reader.GetInt32(reader.GetOrdinal("NeighborhoodId")),
                                    Name = reader.GetString(reader.GetOrdinal("NeighborhoodName"))
                                },
                                Phone = reader.GetString(reader.GetOrdinal("Phone"))
                            },
                            Breed    = reader.GetString(reader.GetOrdinal("Breed")),
                            Notes    = ReaderUtils.GetNullableString(reader, "Notes"),
                            ImageUrl = ReaderUtils.GetNullableString(reader, "ImageUrl")
                        };

                        dogs.Add(dog);
                    }

                    reader.Close();

                    return(dogs);
                }
            }
        }
Beispiel #14
0
 private CIwVec3 GetVec3(ReaderUtils.Vector3 vector3)
 {
     return new CIwVec3(
         (int)(vector3.X),
         (int)(vector3.Y),
         (int)(vector3.Z)
         );
 }