Exemple #1
0
        internal static AzureField FromATOMFeed(XElement propertyElement)
        {
            var field = new AzureField();

            field.Name = propertyElement.Name.LocalName;

            string edmType = string.Empty;

            var typeAttribute = propertyElement.Attribute(Namespaces.DataServicesMeta + "type");

            if (typeAttribute == null)
            {
                edmType = "Edm.String";
            }
            else
            {
                edmType = typeAttribute.Value;
            }

            switch (edmType)
            {
            case "Edm.Int32":
                field.Value = Convert.ToInt32(propertyElement.Value);
                break;

            case "Edm.Int64":
                field.Value = Convert.ToInt64(propertyElement.Value);
                break;

            case "Edm.DateTime":
                field.Value = Convert.ToDateTime(propertyElement.Value);
                break;

            case "Edm.Double":
                field.Value = Convert.ToDouble(propertyElement.Value);
                break;

            case "Edm.String":
                field.Value = propertyElement.Value;
                break;

            case "Edm.Boolean":
                field.Value = Convert.ToBoolean(propertyElement.Value);
                break;

            case "Edm.Binary":
                field.Value = Convert.FromBase64String(propertyElement.Value);
                break;

            default:
                throw new NotSupportedException();
            }

            return(field);
        }
Exemple #2
0
        internal static AzureEntity FromATOMFeed(XElement entryElement)
        {
            var id       = entryElement.Element(Namespaces.Atom + "id").Value;
            var updated  = DateTime.Parse(entryElement.Element(Namespaces.Atom + "updated").Value);
            var category = entryElement.Element(Namespaces.Atom + "category").Attribute("term").Value;

            var linkElement = entryElement.Element(Namespaces.Atom + "link");
            var link        = new Link();

            link.HRef  = (string)linkElement.Attribute("href");
            link.Rel   = (string)linkElement.Attribute("rel");
            link.Title = (string)linkElement.Attribute("title");

            var properties = entryElement.Element(Namespaces.Atom + "content").Element(Namespaces.DataServicesMeta + "properties");

            string partitionKey = null, rowKey = null;
            AzureFieldCollection fields = new AzureFieldCollection();

            foreach (var prop in properties.Elements())
            {
                if (prop.Name == Namespaces.DataServices + "PartitionKey")
                {
                    partitionKey = prop.Value;
                }
                else if (prop.Name == Namespaces.DataServices + "RowKey")
                {
                    rowKey = prop.Value;
                }
                else
                {
                    fields.Add(AzureField.FromATOMFeed(prop));
                }
            }

            var entity = new AzureEntity(partitionKey, rowKey, fields)
            {
                ID          = id,
                LastUpdated = updated,
                Category    = category,
                Link        = link
            };

            return(entity);
        }