Example #1
0
        public SsdsEntity <T> Deserialize(XElement node)
        {
            //Ryan - commenting out this XmlSerializer code - the issue is that
            //Deserialization of Generic types requires Full Trust for some reason
            //so we have to skirt around this issue by manually constructing the SsdsEntity
            //and then only calling Deserialize for the T.  Full Trust kills this from
            //running in Windows Azure

            // we have an issue here caching
            //the serializers... var xs = GetSerializer(node.Name.LocalName);

            ////xml.CreateReader() cannot be used as it won't support base64 content
            //XmlTextReader reader = new XmlTextReader(node.ToString(), XmlNodeType.Document, null);
            //SsdsEntity<T> result = (SsdsEntity<T>)xs.Deserialize(reader);
            //if (result != null)
            //{
            //    result.Kind = node.Name.LocalName;
            //}

            var result = new SsdsEntity <T>
            {
                Id         = node.Element(Constants.ns + "Id").Value,
                Version    = Int64.Parse(node.Element(Constants.ns + "Version").Value, CultureInfo.InvariantCulture),
                Attributes = node.Elements().Where(f => f.Name.Namespace != Constants.ns).ToArray()
            };

            return(result);
        }
Example #2
0
        /// <summary>
        /// Serializes an entity to a string in the payload format required by SSDS
        /// </summary>
        /// <param name="entity">SsdsEntity wrapping the actual object</param>
        /// <returns></returns>
        public string Serialize(SsdsEntity <T> entity)
        {
            //add a bunch of namespaces and override the default ones too
            XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces();

            namespaces.Add("s", Constants.ns.NamespaceName);
            namespaces.Add("x", Constants.x.NamespaceName);
            namespaces.Add("xsi", Constants.xsi.NamespaceName);

            //use the cached serializer for performance
            XmlSerializer xs = GetSerializer();

            XmlWriterSettings xws = new XmlWriterSettings();

            xws.Indent             = true;
            xws.OmitXmlDeclaration = true;

            using (var ms = new MemoryStream())
            {
                using (XmlWriter writer = XmlWriter.Create(ms, xws))
                {
                    xs.Serialize(writer, entity, namespaces);

                    ms.Position = 0; //reset to beginning

                    using (var sr = new StreamReader(ms))
                    {
                        return(sr.ReadToEnd());
                    }
                }
            }
        }
Example #3
0
        public void Insert <T>(SsdsEntity <T> entity) where T : class
        {
            SsdsEntitySerializer <T> serializer = new SsdsEntitySerializer <T>();
            string         payload = serializer.Serialize(entity);
            SsdsRestFacade facade  = this.CreateFacade();

            facade.Insert(payload);
        }
Example #4
0
        /// <summary>
        /// Updates the item on the container.
        /// </summary>
        /// <param name="entity">The item with the information to be updated.</param>
        public void Update <T>(SsdsEntity <T> entity, ConcurrencyPattern concurrencyPattern) where T : class, new()
        {
            Uri                      updateLocation = HttpRestUriTemplates.UpdateTemplate.BindByPosition(this.authority, this.container, entity.Id);
            SsdsRestFacade           facade         = this.CreateFacade(updateLocation);
            SsdsEntitySerializer <T> serializer     = new SsdsEntitySerializer <T>();
            string                   payload        = serializer.Serialize(entity);

            facade.Update(payload, concurrencyPattern, entity.Version.ToString());
        }
Example #5
0
 /// <summary>
 /// Updates entity using concurrency
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="entity"></param>
 public void Update <T>(SsdsEntity <T> entity) where T : class, new()
 {
     Update(entity, ConcurrencyPattern.IfMatch);
 }
Example #6
0
 public void Delete <T>(SsdsEntity <T> entity, ConcurrencyPattern concurrencyPattern) where T : class, new()
 {
     this.Delete(entity.Id, concurrencyPattern, entity.Version.ToString());
 }