Created
July 25, 2010 14:59
-
-
Save casparkleijne/489613 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** call it like **/ | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
Uri uri = new Uri("http://gmcdn.goldmail.com/robin/gmtiming.xml"); | |
Presentation presentation = Rdn.Bll.PresentationController.LoadFromXML(uri); | |
} | |
using System; | |
using Rdn.Bll.Bo; | |
namespace Rdn.Bll | |
{ | |
public sealed class PresentationController | |
{ | |
private PresentationController() | |
{ | |
} | |
public static Presentation LoadFromXML(Uri uri) | |
{ | |
Serializer<Presentation> serializer = new Serializer<Presentation>(); | |
Presentation presentation = serializer.Deserialize(uri); | |
return presentation; | |
} | |
} | |
} | |
using System; | |
using System.Xml; | |
using System.Xml.Serialization; | |
namespace Rdn.Bll | |
{ | |
public class Serializer<T> | |
{ | |
public T Deserialize(Uri url) | |
{ | |
T obj = default(T); | |
using (XmlReader reader = XmlReader.Create(url.OriginalString)) | |
{ | |
XmlSerializer serialzier = new XmlSerializer(typeof(T)); | |
obj = (T)serialzier.Deserialize(reader); | |
} | |
return obj; | |
} | |
} | |
} | |
using System.Collections.ObjectModel; | |
using System.Xml.Serialization; | |
namespace Rdn.Bll.Bo | |
{ | |
[XmlRoot("presentation")] | |
public class Presentation | |
{ | |
private Collection<Cue> cueCollection = new Collection<Cue>(); | |
public Presentation() | |
{ | |
// parameterless constructor needed for deserialization | |
} | |
[XmlAttribute("title")] | |
public string Title | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("path")] | |
public string Path | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("duration")] | |
public int Duration | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("size")] | |
public int Size | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("showlink")] | |
public bool ShowLink | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("linkurl")] | |
public string LinkUrl | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("linktext")] | |
public string LinkText | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("respond")] | |
public bool Respond | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("download")] | |
public bool Download | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("version")] | |
public string Version | |
{ | |
get; | |
set; | |
} | |
[XmlElement("audio")] | |
public Audio Audio | |
{ | |
get; | |
set; | |
} | |
[XmlElement("cue")] | |
public Collection<Cue> CueCollection | |
{ | |
get | |
{ | |
return cueCollection; | |
} | |
} | |
} | |
public class Audio | |
{ | |
public Audio() | |
{ | |
// parameterless constructor needed for deserialization | |
} | |
[XmlAttribute("size")] | |
public int Size | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("audiosamplefrequency")] | |
public int SampleFrequency | |
{ | |
get; | |
set; | |
} | |
[XmlText] | |
public string Source | |
{ | |
get; | |
set; | |
} | |
} | |
public class Cue | |
{ | |
public Cue() | |
{ | |
// parameterless constructor needed for deserialization | |
} | |
[XmlElement("time")] | |
public int Time | |
{ | |
get; | |
set; | |
} | |
[XmlElement("image")] | |
public Image Image | |
{ | |
get; | |
set; | |
} | |
} | |
public class Image | |
{ | |
public Image() | |
{ | |
// parameterless constructor needed for deserialization | |
} | |
[XmlAttribute("size")] | |
public int Size | |
{ | |
get; | |
set; | |
} | |
[XmlAttribute("bgcolor")] | |
public string BackgroundColor | |
{ | |
get; | |
set; | |
} | |
[XmlText] | |
public string Source | |
{ | |
get; | |
set; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment