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); }
/// <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()); } } } }
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); }
/// <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()); }
/// <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); }
public void Delete <T>(SsdsEntity <T> entity, ConcurrencyPattern concurrencyPattern) where T : class, new() { this.Delete(entity.Id, concurrencyPattern, entity.Version.ToString()); }