Exemplo n.º 1
0
        private AzureEntity(string partitionKey, string rowKey, AzureFieldCollection fields)
        {
            Validate
            .Begin()
            .IsNotNullOrEmpty(partitionKey)
            .IsNotNullOrEmpty(rowKey)
            .Check();

            if ((partitionKey.IndexOfAny(DisallowedKeyCharacters) >= 0) || (rowKey.IndexOfAny(DisallowedKeyCharacters) >= 0))
            {
                var message = "Key Values cannot contain any of the following characters: ";
                for (int i = 0; i < DisallowedKeyCharacters.Length; i++)
                {
                    message += string.Format("'{0}' ", DisallowedKeyCharacters[i]);
                }

                throw new ArgumentException(message);
            }

            PartitionKey = partitionKey;
            RowKey       = rowKey;

            if (fields == null)
            {
                Fields = new AzureFieldCollection();
            }
            else
            {
                Fields = fields;
            }
        }
Exemplo n.º 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);
        }