using System;
using System.Xml;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Globalization;
using System.Text;
using System.Diagnostics;
using IReaper.Properties;
using IReaper.FileData;
using IReaper.Running;
using IReaper.Initializer;
namespace IReaper.CourseData{
/// <summary>
/// XML
/// </summary>
public class InfoXMLParser:CourseXmlParser
{
static string downloadpathBase = Settings.Default.DownloadBaseUrl;
static Uri microsoftBase = new Uri(IReaper.Properties.Settings.Default.Microsoft, UriKind.Absolute);
/// <summary>
///
/// </summary>
public InfoXMLParser()
: base(CheckInfoXMLTask.InfoXmlPath)
{
this.xmlName = "R";
}
protected override Course ProcessCourse(XmlReader xReader,Dictionary<string,Course> dict)
{
Course course = null;
bool isNew = false;
//
if (xReader.ReadToFollowing("newsID"))
{
string id = xReader.ReadString().Trim();//ID
if (dict.ContainsKey(id))//
{
course = dict[id];
}
else//
{
course = new Course();
course.Id = id;
isNew = true;
}
}
//
if (xReader.ReadToNextSibling("headline"))
course.Headline = xReader.ReadString().Trim();
//
if (xReader.ReadToNextSibling("description"))
course.Description = xReader.ReadString().Trim();
//URL
if (xReader.ReadToNextSibling("url"))
{
string oUriText = xReader.ReadString().Trim();
Uri uri;
if(Uri.TryCreate(oUriText,UriKind.RelativeOrAbsolute,out uri))
{
if (uri.IsAbsoluteUri)
{
course.CourseUrl = uri.AbsoluteUri;
}
else
{
Uri nUri;
if (Uri.TryCreate(microsoftBase, uri, out nUri))
{
course.CourseUrl = nUri.AbsoluteUri;
}
}
}
}
//
while (xReader.ReadToNextSibling("a"))
{
string id,value;
id = xReader.GetAttribute("attCatID").Trim();
value = xReader.GetAttribute("attValue").Trim();
if (value == null)
value = "";
switch (id)
{
case "level"://
course.Level = value;
break;
case "speaker"://speaker
course.Speaker = value;
break;
case "date"://
course.Time = DateTime.Parse(value);
break;
case "resume"://
course.Resume =value;
break;
case "title"://
course.Title = value;
break;
case "series"://
if (!String.IsNullOrEmpty(value))
course.Series = value;
break;
case "products"://
if (!String.IsNullOrEmpty(value))
course.Products = value;
break;
case "tech"://
if (!String.IsNullOrEmpty(value))
course.Technology = value;
break;
case "slides":
if (value == "1" && course.PPT == null)
{
course.PPT = new CourseFileData(course);
course.PPT.FileType = FileType.PPT;
course.PPT.RemotePath = downloadpathBase + "?id=" + course.Id + "&type=" + id;
}
break;
case "video":
if (value == "1" && course.Video == null)
{
course.Video = new CourseFileData(course);
course.Video.FileType = FileType.Video;
course.Video.RemotePath = downloadpathBase + "?id=" + course.Id + "&type=" + id;
}
break;
case "code":
if(value == "1" && course.Code == null)
{
course.Code = new CourseFileData(course);
course.Code.FileType = FileType.Code;
course.Code.RemotePath = downloadpathBase + "?id=" + course.Id + "&type=" + id;
}
break;
case "qa":
if (value == "1" && course.QA == null)
{
course.QA = new CourseFileData(course);
course.QA.FileType = FileType.QA;
course.QA.RemotePath = downloadpathBase + "?id=" + course.Id + "&type=" + id;
}
break;
case "mp3":
if (value == "1" && course.MP3 == null)
{
course.MP3 = new CourseFileData(course);
course.MP3.FileType = FileType.MP3;
course.MP3.RemotePath = downloadpathBase + "?id=" + course.Id + "&type=" + id;
}
break;
case "mp4":
if (value == "1" && course.MP4 == null)
{
course.MP4 = new CourseFileData(course);
course.MP4.FileType = FileType.MP4;
course.MP4.RemotePath = downloadpathBase + "?id=" + course.Id + "&type=" + id;
}
break;
case "wmv":
if (value == "1" && course.WMV == null)
{
course.WMV = new CourseFileData(course);
course.WMV.FileType = FileType.Zune;
course.WMV.RemotePath = downloadpathBase + "?id=" + course.Id + "&type=" + id;
}
break;
case "rating":
if (value.Length != 0)
course.Rate = float.Parse(value);
else
course.Rate = 0;
break;
}
}
return isNew ? course : null;
}
}
}
|