protected override object DeserializeCore(LoadContext context, XElement xml, Type objectType, Stream stream) { // <photos page="2" pages="89" perpage="10" total="881"> // <photo id="2636" owner="47058503995@N01" // secret="a123456" server="2" title="test_04" // ispublic="1" isfriend="0" isfamily="0" /> // <photo id="2635" owner="47058503995@N01" // secret="b123456" server="2" title="test_03" // ispublic="0" isfriend="1" isfamily="1" /> // <photo id="2633" owner="47058503995@N01" // secret="c123456" server="2" title="test_01" // ispublic="1" isfriend="0" isfamily="0" /> // <photo id="2610" owner="12037949754@N01" // secret="d123456" server="2" title="00_tall" // ispublic="1" isfriend="0" isfamily="0" /> //</photos> var vm = new T(); vm.LoadContext = (PhotoCollectionLoadContext)context; bool success; vm.PageSize = Int32.Parse(TryGetValue(xml, "perpage", "10", out success)); vm.TotalPhotos = Int32.Parse(TryGetValue(xml, "total", "0", out success)); vm.Pages = Int32.Parse(TryGetValue(xml, "pages", "0", out success)); vm.Page = Int32.Parse(TryGetValue(xml, "page", "0", out success)); int index = 0; List <PhotoVm> photos = new List <PhotoVm>(); foreach (var ps in xml.Elements("photo")) { string id = TryGetValue(ps, "id", "", out success); PhotoVm psvm = new PhotoVm(id); psvm.Title = TryGetValue(ps, "title", null, out success); psvm.OwnerId = TryGetValue(ps, "owner", null, out success); psvm.CollectionIdentifier = String.Format("{0}\t{1}", vm.LoadContext.Identity.ToString(), index++); photos.Add(psvm); } photos.Sort((x, y) => { return(DateTime.Compare(y.LastUpdated, x.LastUpdated)); }); photos.ForEach(p => vm.Photos.Add(p)); return(vm); }
public override object DeserializeOptimizedData(object identifier, Type objectType, Stream stream) { StreamReader sr = new StreamReader(stream); PhotostreamVm vm = new PhotostreamVm(sr.ReadLine()); int count = Int32.Parse(sr.ReadLine()); List <PhotoVm> _photos = new List <PhotoVm>(); for (int i = 0; i < count; i++) { PhotoVm photo = new PhotoVm(sr.ReadLine()); photo.Title = sr.ReadLine(); } return(vm); }
protected override object DeserializeCore(LoadContext context, XElement xml, Type objectType, Stream stream) { // <photo id="2733" secret="123456" server="12" // isfavorite="0" license="3" rotation="90" // originalsecret="1bc09ce34a" originalformat="png"> // <owner nsid="12037949754@N01" username="******" // realname="Cal Henderson" location="Bedford, UK" /> // <title>orford_castle_taster</title> // <description>hello!</description> // <visibility ispublic="1" isfriend="0" isfamily="0" /> // <dates posted="1100897479" taken="2004-11-19 12:51:19" // takengranularity="0" lastupdate="1093022469" /> // <permissions permcomment="3" permaddmeta="2" /> // <editability cancomment="1" canaddmeta="1" /> // <comments>1</comments> // <notes> // <note id="313" author="12037949754@N01" // authorname="Bees" x="10" y="10" // w="50" h="50">foo</note> // </notes> // <tags> // <tag id="1234" author="12037949754@N01" raw="woo yay">wooyay</tag> // <tag id="1235" author="12037949754@N01" raw="hoopla">hoopla</tag> // </tags> // <urls> // <url type="photopage">http://www.flickr.com/photos/bees/2733/</url> // </urls> //</photo> var vm = new PhotoVm(context.Identity); bool s; vm.Title = TryGetValue(xml, "title", null, out s); vm.Description = TryGetValue(xml, "description", null, out s); var owner = xml.Element("owner"); vm.OwnerId = TryGetValue(owner, "nsid", null, out s); var dates = xml.Element("dates"); vm.Posted = FromUnixTime(TryGetValue(dates, "posted", null, out s)); var taken = TryGetValue(dates, "taken", null, out s); if (taken != null) { vm.Taken = taken; } vm.Updated = FromUnixTime(TryGetValue(dates, "lastupdate", null, out s)); ObservableCollection <PhotoTag> tags = new ObservableCollection <PhotoTag>(); foreach (var tag in xml.Element("tags").Elements("tag")) { bool success; PhotoTag pt = new PhotoTag { Tag = TryGetValue(tag, "raw", "", out success), RawTag = tag.Value, ID = TryGetValue(tag, "id", null, out success) }; tags.Add(pt); } vm.Tags = tags; return(vm); }
protected override object DeserializeCore(LoadContext context, XElement xml, Type objectType, Stream stream) { // <photo id="2733" secret="123456" server="12" // isfavorite="0" license="3" rotation="90" // originalsecret="1bc09ce34a" originalformat="png"> // <owner nsid="12037949754@N01" username="******" // realname="Cal Henderson" location="Bedford, UK" /> // <title>orford_castle_taster</title> // <description>hello!</description> // <visibility ispublic="1" isfriend="0" isfamily="0" /> // <dates posted="1100897479" taken="2004-11-19 12:51:19" // takengranularity="0" lastupdate="1093022469" /> // <permissions permcomment="3" permaddmeta="2" /> // <editability cancomment="1" canaddmeta="1" /> // <comments>1</comments> // <notes> // <note id="313" author="12037949754@N01" // authorname="Bees" x="10" y="10" // w="50" h="50">foo</note> // </notes> // <tags> // <tag id="1234" author="12037949754@N01" raw="woo yay">wooyay</tag> // <tag id="1235" author="12037949754@N01" raw="hoopla">hoopla</tag> // </tags> // <urls> // <url type="photopage">http://www.flickr.com/photos/bees/2733/</url> // </urls> //</photo> var vm = new PhotoVm(context.Identity); bool s; vm.Title = TryGetValue(xml, "title", null, out s); vm.Description = TryGetValue(xml, "description", null, out s); var owner = xml.Element("owner"); vm.OwnerId = TryGetValue(owner, "nsid", null, out s); var dates = xml.Element("dates"); vm.Posted = FromUnixTime(TryGetValue(dates, "posted", null, out s)); var taken = TryGetValue(dates, "taken", null, out s); if (taken != null) { vm.Taken = taken; } vm.Updated = FromUnixTime(TryGetValue(dates, "lastupdate", null, out s)); ObservableCollection<PhotoTag> tags = new ObservableCollection<PhotoTag>(); foreach (var tag in xml.Element("tags").Elements("tag")) { bool success; PhotoTag pt = new PhotoTag { Tag = TryGetValue(tag, "raw", "", out success), RawTag = tag.Value, ID = TryGetValue(tag, "id", null, out success) }; tags.Add(pt); } vm.Tags = tags; return vm; }