From: <sam...@us...> - 2006-06-01 07:02:09
|
Revision: 10 Author: samuel337 Date: 2006-06-01 00:02:01 -0700 (Thu, 01 Jun 2006) ViewCVS: http://svn.sourceforge.net/mp-webinterface/?rev=10&view=rev Log Message: ----------- Fixed problems with methods returning TV Channel related information Modified Paths: -------------- trunk/source/ECP2WebService/App_Code/Service.cs Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-05-29 07:36:04 UTC (rev 9) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-01 07:02:01 UTC (rev 10) @@ -269,12 +269,22 @@ List<MediaPortal.TV.Database.TVChannel> chnList; chnList = GetEMPH().GetChannels(); + if (chnList.Count == 0) return ""; + + // As CurrentProgram is not necessary, set its XMLIgnore attribute to true + System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); + System.Xml.Serialization.XmlAttributes xmlAttributes; + + xmlAttributes = new System.Xml.Serialization.XmlAttributes(); + xmlAttributes.XmlIgnore = true; + xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVChannel), "CurrentProgram", xmlAttributes); + System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(sb); System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel)); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel),xmlOverrides); MediaPortal.TV.Database.TVChannel chn; xw.WriteStartDocument(); @@ -283,7 +293,7 @@ for (int i = 0; i <= chnList.Count - 1; i++) { - chn = (MediaPortal.TV.Database.TVChannel)(chnList[i]); + chn = (MediaPortal.TV.Database.TVChannel)chnList[i]; xs.Serialize(sw, chn); xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); sb.Remove(0, sb.Length - 1); @@ -292,7 +302,7 @@ xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteEndDocument(); - + return sbXML.ToString(); } @@ -302,25 +312,34 @@ MediaPortal.TV.Database.TVChannel chn; chn = GetEMPH().GetChannel(channelID); + // As CurrentProgram is not necessary, set its XMLIgnore attribute to true + System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); + System.Xml.Serialization.XmlAttributes xmlAttributes; + + xmlAttributes = new System.Xml.Serialization.XmlAttributes(); + xmlAttributes.XmlIgnore = true; + xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVChannel), "CurrentProgram", xmlAttributes); + System.Text.StringBuilder sb = new System.Text.StringBuilder(); System.IO.StringWriter sw = new System.IO.StringWriter(sb); System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel)); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel), xmlOverrides); xw.WriteStartDocument(); xw.WriteStartElement("MPData"); xw.WriteStartElement("TVChannels"); xs.Serialize(sw, chn); + xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); sb.Remove(0, sb.Length - 1); xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteEndDocument(); - + return sbXML.ToString(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sam...@us...> - 2006-06-10 15:42:04
|
Revision: 12 Author: samuel337 Date: 2006-06-10 08:41:52 -0700 (Sat, 10 Jun 2006) ViewCVS: http://svn.sourceforge.net/mp-webinterface/?rev=12&view=rev Log Message: ----------- updated code on all XML-returning functions to return UTF8 encoded data (now more efficient too). Modified Paths: -------------- trunk/source/ECP2WebService/App_Code/Service.cs Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-01 07:03:28 UTC (rev 11) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-10 15:41:52 UTC (rev 12) @@ -33,7 +33,6 @@ return GetEMPH().SendActionByID(actionID); } - [WebMethod(Description="This command gets the current path to MediaPortal.")] public string GetMPPath() { @@ -263,6 +262,17 @@ return GetEMPH().ImportXMLTVGuide(); } + private System.Xml.XmlWriterSettings GetXMLDocWriterSettings() + { + System.Xml.XmlWriterSettings xwSettings = new System.Xml.XmlWriterSettings(); + xwSettings.Encoding = System.Text.Encoding.UTF8; + xwSettings.Indent = true; + xwSettings.OmitXmlDeclaration = false; + xwSettings.ConformanceLevel = System.Xml.ConformanceLevel.Auto; + + return xwSettings; + } + [WebMethod(Description="This command retrieves all the channels in MP in XML format.")] public string GetChannels() { @@ -279,31 +289,36 @@ xmlAttributes.XmlIgnore = true; xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVChannel), "CurrentProgram", xmlAttributes); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - System.IO.StringWriter sw = new System.IO.StringWriter(sb); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel),xmlOverrides); MediaPortal.TV.Database.TVChannel chn; - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVChannels"); + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVChannels"); - for (int i = 0; i <= chnList.Count - 1; i++) + for (int i = 0; i <= chnList.Count - 1; i++) + { + chn = (MediaPortal.TV.Database.TVChannel)chnList[i]; + + xs.Serialize(xw, chn); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) { - chn = (MediaPortal.TV.Database.TVChannel)chnList[i]; - xs.Serialize(sw, chn); - xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); - sb.Remove(0, sb.Length - 1); + return ex.ToString(); } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - return sbXML.ToString(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description = "This command retrieves the specified channel from MP in XML format.")] @@ -320,27 +335,30 @@ xmlAttributes.XmlIgnore = true; xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVChannel), "CurrentProgram", xmlAttributes); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - System.IO.StringWriter sw = new System.IO.StringWriter(sb); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel), xmlOverrides); - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVChannels"); + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVChannels"); - xs.Serialize(sw, chn); + xs.Serialize(xw, chn); - xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); - sb.Remove(0, sb.Length - 1); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - return sbXML.ToString(); + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description="This command converts a channelID into its corresponding channel name.")] @@ -385,9 +403,8 @@ List<string> genresList; genresList = GetEMPH().GetGenres(); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); xw.WriteStartDocument(); xw.WriteStartElement("MPData"); @@ -406,8 +423,10 @@ xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteEndDocument(); - - return sbXML.ToString(); + + xw.Flush(); + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description="This command returns the list of TV programs within the given date in XML format.")] @@ -416,35 +435,35 @@ List<MediaPortal.TV.Database.TVProgram> progList; progList = GetEMPH().GetPrograms(startDateTime,endDateTime); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - System.IO.StringWriter sw = new System.IO.StringWriter(sb); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); MediaPortal.TV.Database.TVProgram prog; - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVPrograms"); - - for (int i = 0; i <= progList.Count - 1; i++) + try { - prog = (MediaPortal.TV.Database.TVProgram)progList[i]; - xs.Serialize(sw, prog); + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVPrograms"); - //write serialisation to xmltextwriter, without XML declaration line - xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); + for (int i = 0; i <= progList.Count - 1; i++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } - //clear serialisation stringbuilder - sb.Remove(0, sb.Length - 1); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); } + catch (Exception ex) + { + return ex.ToString(); + } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - return sbXML.ToString(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description="This command returns a list of all the TV programs in XML format.")] @@ -453,35 +472,35 @@ List<MediaPortal.TV.Database.TVProgram> progList; progList = GetEMPH().GetPrograms(); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - System.IO.StringWriter sw = new System.IO.StringWriter(sb); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); MediaPortal.TV.Database.TVProgram prog; - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVPrograms"); - - for (int i = 0; i <= progList.Count - 1; i++) + try { - prog = (MediaPortal.TV.Database.TVProgram)progList[i]; - xs.Serialize(sw, prog); + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVPrograms"); - //write serialisation to xmltextwriter, without XML declaration line - xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); + for (int i = 0; i <= progList.Count - 1; i++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } - //clear serialisation stringbuilder - sb.Remove(0, sb.Length - 1); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); } + catch (Exception ex) + { + return ex.ToString(); + } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - return sbXML.ToString(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description="This command returns the list of TV program genres in XML format.")] @@ -490,35 +509,35 @@ List<MediaPortal.TV.Database.TVProgram> progList; progList = GetEMPH().GetPrograms(GetChannelName(channelID),startDateTime,endDateTime); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - System.IO.StringWriter sw = new System.IO.StringWriter(sb); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); MediaPortal.TV.Database.TVProgram prog; - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVPrograms"); - - for (int i = 0; i <= progList.Count - 1; i++) + try { - prog = (MediaPortal.TV.Database.TVProgram)progList[i]; - xs.Serialize(sw, prog); + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVPrograms"); - //write serialisation to xmltextwriter, without XML declaration line - xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); + for (int i = 0; i <= progList.Count - 1; i++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } - //clear serialisation stringbuilder - sb.Remove(0, sb.Length - 1); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); } + catch (Exception ex) + { + return ex.ToString(); + } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - return sbXML.ToString(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description="This command returns the list of TV recordings in XML format.")] @@ -527,35 +546,35 @@ List<MediaPortal.TV.Database.TVRecording > recList; recList = GetEMPH().GetRecordings(); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - System.IO.StringWriter sw = new System.IO.StringWriter(sb); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecording )); MediaPortal.TV.Database.TVRecording rec; - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVRecordings"); - - for (int i = 0; i <= recList.Count - 1; i++) + try { - rec = (MediaPortal.TV.Database.TVRecording)recList[i]; - xs.Serialize(sw, rec); + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVRecordings"); - //write serialisation to xmltextwriter, without XML declaration line - xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); + for (int i = 0; i <= recList.Count - 1; i++) + { + rec = (MediaPortal.TV.Database.TVRecording)recList[i]; + xs.Serialize(xw, rec); + } - //clear serialisation stringbuilder - sb.Remove(0, sb.Length - 1); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); } + catch (Exception ex) + { + return ex.ToString(); + } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - return sbXML.ToString(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description="This command returns the list of all recorded TV items in XML format.")] @@ -564,35 +583,35 @@ List<MediaPortal.TV.Database.TVRecorded> recdTVList; recdTVList = GetEMPH().GetAllRecordedTV(); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - System.IO.StringWriter sw = new System.IO.StringWriter(sb); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecorded )); MediaPortal.TV.Database.TVRecorded recdTV; - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVRecorded"); - - for (int i = 0; i <= recdTVList.Count - 1; i++) + try { - recdTV = (MediaPortal.TV.Database.TVRecorded)recdTVList[i]; - xs.Serialize(sw, recdTV); + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVRecorded"); - //write serialisation to xmltextwriter, without XML declaration line - xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); + for (int i = 0; i <= recdTVList.Count - 1; i++) + { + recdTV = (MediaPortal.TV.Database.TVRecorded)recdTVList[i]; + xs.Serialize(xw, recdTV); + } - //clear serialisation stringbuilder - sb.Remove(0, sb.Length - 1); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); } + catch (Exception ex) + { + return ex.ToString(); + } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - return sbXML.ToString(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description = "This command returns the specified recorded TV item in XML format.")] @@ -601,30 +620,30 @@ MediaPortal.TV.Database.TVRecorded recdTV; recdTV = GetEMPH().GetRecordedTV(recordedTVFileName); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - System.IO.StringWriter sw = new System.IO.StringWriter(sb); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecorded)); - - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVRecorded"); - xs.Serialize(sw, recdTV); + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVRecorded"); - //write serialisation to xmltextwriter, without XML declaration line - xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); + xs.Serialize(xw, recdTV); - //clear serialisation stringbuilder - sb.Remove(0, sb.Length - 1); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } - return sbXML.ToString(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description="This command returns the name of the current playlist.")] @@ -654,36 +673,36 @@ MediaPortal.Playlists.PlayList playlist; playlist = GetEMPH().GetPlaylist(playlistTypeResolve); - System.Text.StringBuilder sb = new System.Text.StringBuilder(); - System.IO.StringWriter sw = new System.IO.StringWriter(sb); - System.Text.StringBuilder sbXML = new System.Text.StringBuilder(); - System.IO.StringWriter swXML = new System.IO.StringWriter(sbXML); - System.Xml.XmlTextWriter xw = new System.Xml.XmlTextWriter(swXML); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.Playlists.PlayListItem )); MediaPortal.Playlists.PlayListItem playlistItem; - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("Playlist"); - xw.WriteAttributeString("type", playlistType ); - - for (int i = 0; i <= playlist.Count - 1; i++) + try { - playlistItem = (MediaPortal.Playlists.PlayListItem )playlist[i]; - xs.Serialize(sw, playlistItem); + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("Playlist"); + xw.WriteAttributeString("type", playlistType); - //write serialisation to xmltextwriter, without XML declaration line - xw.WriteRaw(sb.ToString().Substring(sb.ToString().IndexOf("?>") + 2)); + for (int i = 0; i <= playlist.Count - 1; i++) + { + playlistItem = (MediaPortal.Playlists.PlayListItem)playlist[i]; + xs.Serialize(xw, playlistItem); + } - //clear serialisation stringbuilder - sb.Remove(0, sb.Length - 1); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); } + catch (Exception ex) + { + return ex.ToString(); + } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - return sbXML.ToString(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } [WebMethod(Description="This command adds an item to the nominated playlist.")] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sam...@us...> - 2006-06-18 15:07:33
|
Revision: 15 Author: samuel337 Date: 2006-06-18 08:07:25 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/mp-webinterface/?rev=15&view=rev Log Message: ----------- moved some code groups around; no code changes Modified Paths: -------------- trunk/source/ECP2WebService/App_Code/Service.cs Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-18 15:00:12 UTC (rev 14) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-18 15:07:25 UTC (rev 15) @@ -86,83 +86,6 @@ } } - #region scheduled recording commands - [WebMethod(Description="This command tells MediaPortal to refresh its recordings list.")] - public bool RefreshRecordingsInMP() - { - return GetEMPH().RefreshRecordings(); - } - - [WebMethod(Description = "This command adds a recording to MP's recording list. No recordings refresh command is required after this action. Possible values for recType parameter are: Daily, EveryTimeOnEveryChannel, EveryTimeOnThisChannel, Once, WeekDays, WeekEnds, Weekly. Possible values for keepMethod parameters are: Always, UntilSpaceNeeded, UntilWatched.")] - public bool AddRecording(string title, string channelName, DateTime startDateTime, DateTime endDateTime, string recType, string keepMethod) - { - MediaPortal.TV.Database.TVRecording rec = new MediaPortal.TV.Database.TVRecording(); - rec.Title = title; - rec.Channel = channelName; - rec.Start = DateToLong(startDateTime); - rec.End = DateToLong(endDateTime); - rec.RecType = Enum.Parse(GetType(MediaPortal.TV.Database.TVRecording.RecordingType), recType, true); - rec.KeepRecordingMethod = Enum.Parse(GetType(MediaPortal.TV.Database.TVRecorded.KeepMethod), keepMethod, true); - - return GetEMPH().AddRecording(ref rec); - } - - [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by ID.")] - public bool DeleteRecordingByID(int recordingID) - { - return GetEMPH().DelRecording(recordingID); - } - - [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by starting time and channel name.")] - public bool DeleteRecordingByStartTimeAndChannelName(DateTime startDateTime, string channelName) - { - return GetEMPH().DelRecording(startDateTime, channelName); - } - - [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by starting time and channel number.")] - public bool DeleteRecordingByStartTimeAndChannelLCN(DateTime startDateTime, int channelLCN) - { - return GetEMPH().DelRecording(startDateTime, channelLCN); - } - - [WebMethod(Description = "This command returns the list of TV recordings in XML format.")] - public string GetRecordings() - { - List<MediaPortal.TV.Database.TVRecording> recList; - recList = GetEMPH().GetRecordings(); - - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecording)); - MediaPortal.TV.Database.TVRecording rec; - - try - { - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVRecordings"); - - for (int i = 0; i <= recList.Count - 1; i++) - { - rec = (MediaPortal.TV.Database.TVRecording)recList[i]; - xs.Serialize(xw, rec); - } - - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - xw.Flush(); - } - catch (Exception ex) - { - return ex.ToString(); - } - - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } - #endregion - #region private methods private long DateToLong(DateTime date) { @@ -387,6 +310,83 @@ } #endregion + #region scheduled recording commands + [WebMethod(Description = "This command tells MediaPortal to refresh its recordings list.")] + public bool RefreshRecordingsInMP() + { + return GetEMPH().RefreshRecordings(); + } + + [WebMethod(Description = "This command adds a recording to MP's recording list. No recordings refresh command is required after this action. Possible values for recType parameter are: Daily, EveryTimeOnEveryChannel, EveryTimeOnThisChannel, Once, WeekDays, WeekEnds, Weekly. Possible values for keepMethod parameters are: Always, UntilSpaceNeeded, UntilWatched.")] + public bool AddRecording(string title, string channelName, DateTime startDateTime, DateTime endDateTime, string recType, string keepMethod) + { + MediaPortal.TV.Database.TVRecording rec = new MediaPortal.TV.Database.TVRecording(); + rec.Title = title; + rec.Channel = channelName; + rec.Start = DateToLong(startDateTime); + rec.End = DateToLong(endDateTime); + rec.RecType = Enum.Parse(GetType(MediaPortal.TV.Database.TVRecording.RecordingType), recType, true); + rec.KeepRecordingMethod = Enum.Parse(GetType(MediaPortal.TV.Database.TVRecorded.KeepMethod), keepMethod, true); + + return GetEMPH().AddRecording(ref rec); + } + + [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by ID.")] + public bool DeleteRecordingByID(int recordingID) + { + return GetEMPH().DelRecording(recordingID); + } + + [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by starting time and channel name.")] + public bool DeleteRecordingByStartTimeAndChannelName(DateTime startDateTime, string channelName) + { + return GetEMPH().DelRecording(startDateTime, channelName); + } + + [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by starting time and channel number.")] + public bool DeleteRecordingByStartTimeAndChannelLCN(DateTime startDateTime, int channelLCN) + { + return GetEMPH().DelRecording(startDateTime, channelLCN); + } + + [WebMethod(Description = "This command returns the list of TV recordings in XML format.")] + public string GetRecordings() + { + List<MediaPortal.TV.Database.TVRecording> recList; + recList = GetEMPH().GetRecordings(); + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecording)); + MediaPortal.TV.Database.TVRecording rec; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVRecordings"); + + for (int i = 0; i <= recList.Count - 1; i++) + { + rec = (MediaPortal.TV.Database.TVRecording)recList[i]; + xs.Serialize(xw, rec); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + #endregion + #region TV Channel/Program commands [WebMethod(Description="This command tells MediaPortal to re-import the XMLTV data file.")] public bool ImportXMLTVGuide() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sam...@us...> - 2006-06-18 15:00:21
|
Revision: 14 Author: samuel337 Date: 2006-06-18 08:00:12 -0700 (Sun, 18 Jun 2006) ViewCVS: http://svn.sourceforge.net/mp-webinterface/?rev=14&view=rev Log Message: ----------- grouped methods together for easier reading Modified Paths: -------------- trunk/source/ECP2WebService/App_Code/Service.cs Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-18 05:37:49 UTC (rev 13) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-18 15:00:12 UTC (rev 14) @@ -26,13 +26,171 @@ return ECP2Assembly.MPHandler.Instance; } + [WebMethod(Description = @"This command launches MediaPortal.")] + public bool LaunchMP() + { + string appPath = ""; + + if (!System.IO.File.Exists(ECP2Assembly.MPHandler.ConfigFileName)) + { + throw new Exception(@"Could not access ECP2Assembly's config file expected at (" + ECP2Assembly.MPHandler.ConfigFileName + @") to get MP path."); + return false; + } + + System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); + + try + { + xmlDoc.Load(ECP2Assembly.MPHandler.ConfigFileName); + System.Xml.XmlNodeList xmlNodeList = xmlDoc.SelectNodes("configuration/appSettings/add[@key='MPPath']"); + + if (xmlNodeList.Count > 0) + { + System.Xml.XmlNode xmlNode = xmlNodeList[0]; + appPath = xmlNode.Attributes["value"].Value; + appPath += "MediaPortal.exe"; + } + else + { + throw new Exception(@"MPPath could not be located in the ECP2Assembly config file located at: " + ECP2Assembly.MPHandler.ConfigFileName); + return false; + } + + if (!System.IO.File.Exists(appPath)) + { + throw new Exception(@"Could not located MediaPortal.exe based on MP path from ECP2Assembly's config file located at: " + ECP2Assembly.MPHandler.ConfigFileName); + return false; + } + } + catch (Exception ex) + { + throw new Exception(@"ECP2 Web Service error: could not locate MediaPortal.exe; inner exception: " + ex.ToString()); + return false; + } + + string folder = appPath.Substring(0, appPath.LastIndexOf(@"\")); + + try + { + System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(); + si.FileName = appPath; + si.WorkingDirectory = folder; + System.Diagnostics.Process.Start(si); + + return true; + } + catch (Exception ex) + { + throw new Exception(@"ECP2 Web Service error: could not execute MediaPortal; inner exception: " + ex.ToString()); + return false; + } + } + + #region scheduled recording commands + [WebMethod(Description="This command tells MediaPortal to refresh its recordings list.")] + public bool RefreshRecordingsInMP() + { + return GetEMPH().RefreshRecordings(); + } + + [WebMethod(Description = "This command adds a recording to MP's recording list. No recordings refresh command is required after this action. Possible values for recType parameter are: Daily, EveryTimeOnEveryChannel, EveryTimeOnThisChannel, Once, WeekDays, WeekEnds, Weekly. Possible values for keepMethod parameters are: Always, UntilSpaceNeeded, UntilWatched.")] + public bool AddRecording(string title, string channelName, DateTime startDateTime, DateTime endDateTime, string recType, string keepMethod) + { + MediaPortal.TV.Database.TVRecording rec = new MediaPortal.TV.Database.TVRecording(); + rec.Title = title; + rec.Channel = channelName; + rec.Start = DateToLong(startDateTime); + rec.End = DateToLong(endDateTime); + rec.RecType = Enum.Parse(GetType(MediaPortal.TV.Database.TVRecording.RecordingType), recType, true); + rec.KeepRecordingMethod = Enum.Parse(GetType(MediaPortal.TV.Database.TVRecorded.KeepMethod), keepMethod, true); + + return GetEMPH().AddRecording(ref rec); + } + + [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by ID.")] + public bool DeleteRecordingByID(int recordingID) + { + return GetEMPH().DelRecording(recordingID); + } + + [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by starting time and channel name.")] + public bool DeleteRecordingByStartTimeAndChannelName(DateTime startDateTime, string channelName) + { + return GetEMPH().DelRecording(startDateTime, channelName); + } + + [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by starting time and channel number.")] + public bool DeleteRecordingByStartTimeAndChannelLCN(DateTime startDateTime, int channelLCN) + { + return GetEMPH().DelRecording(startDateTime, channelLCN); + } + + [WebMethod(Description = "This command returns the list of TV recordings in XML format.")] + public string GetRecordings() + { + List<MediaPortal.TV.Database.TVRecording> recList; + recList = GetEMPH().GetRecordings(); + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecording)); + MediaPortal.TV.Database.TVRecording rec; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVRecordings"); + + for (int i = 0; i <= recList.Count - 1; i++) + { + rec = (MediaPortal.TV.Database.TVRecording)recList[i]; + xs.Serialize(xw, rec); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + #endregion + + #region private methods + private long DateToLong(DateTime date) + { + return long.Parse(date.ToString("yyyyMMddHHmmss")); + } + + private System.Xml.XmlWriterSettings GetXMLDocWriterSettings() + { + System.Xml.XmlWriterSettings xwSettings = new System.Xml.XmlWriterSettings(); + xwSettings.Encoding = System.Text.Encoding.UTF8; + xwSettings.Indent = true; + xwSettings.OmitXmlDeclaration = false; + xwSettings.ConformanceLevel = System.Xml.ConformanceLevel.Auto; + + return xwSettings; + } + #endregion + + #region action commands [WebMethod(Description = "This command allows you to emulate key presses to the current window in MediaPortal. Enter in the ActionID. See <a href='ActionIDs.htm'>this page</a> for the action IDs of the various actions.")] public bool SendActionByID(int actionID) { //send action return GetEMPH().SendActionByID(actionID); } + #endregion + #region current state commands [WebMethod(Description="This command gets the current path to MediaPortal.")] public string GetMPPath() { @@ -132,737 +290,647 @@ return itemType + @"|" + description + @"|" + duration; } - [WebMethod(Description="This command gets the ID of the currently displayed window.")] - public int GetCurrentWindowID() - { - try + [WebMethod(Description="This command gets the ID of the currently displayed window.")] + public int GetCurrentWindowID() { - return GetEMPH().CurrentWindowID; + try + { + return GetEMPH().CurrentWindowID; + } + catch + { + return -2; + } } - catch + + [WebMethod(Description="This command gets the friendly name of the currently displayed window.")] + public string GetCurrentWindowName() { - return -2; + if (GetCurrentWindowID()!=-2) + { + return GetEMPH().CurrentWindowName; + } + else + { + return "MediaPortal is not running"; + } } - } - [WebMethod(Description="This command gets the friendly name of the currently displayed window.")] - public string GetCurrentWindowName() - { - if (GetCurrentWindowID()!=-2) + [WebMethod(Description="This command switches the current window to the specified window, using the WindowID.")] + public bool ActivateWindow(int windowID, bool replaceWindow) { - return GetEMPH().CurrentWindowName; + try + { + return GetEMPH().ActivateWindow(windowID,replaceWindow); + } + catch + { + return false; + } } - else + + [WebMethod(Description="This command switches the current window to previous window.")] + public bool ShowPreviousWindow() { - return "MediaPortal is not running"; + try + { + return GetEMPH().ShowPreviousWindow(); + } + catch + { + return false; + } } - } - [WebMethod(Description="This command switches the current window to the specified window, using the WindowID.")] - public bool ActivateWindow(int windowID, bool replaceWindow) - { - try + [WebMethod(Description="This command gets the property using the property tag given from MP's property manager.")] + public string get_MPPropertyManager(string propertyTag) { - return GetEMPH().ActivateWindow(windowID,replaceWindow); + return GetEMPH().get_GUIPropertyManager(propertyTag); } - catch + + [WebMethod(Description="This command sets the property using the property tag given from MP's property manager.")] + public bool set_MPPropertyManager(string propertyTag,string propertyValue) { - return false; + if (propertyTag=="") {return false;} + + try + { + GetEMPH().set_GUIPropertyManager(propertyTag,propertyValue); + return true; + } + catch + { + return false; + } } - } - [WebMethod(Description="This command switches the current window to previous window.")] - public bool ShowPreviousWindow() - { - try + [WebMethod(Description="This command gets the specified property from MP's recorder object.")] + public object GetRecorderProps(string propName) { - return GetEMPH().ShowPreviousWindow(); - } - catch - { - return false; - } - } + if (propName=="") + { + return false; + } - [WebMethod(Description="This command gets the property using the property tag given from MP's property manager.")] - public string get_MPPropertyManager(string propertyTag) - { - return GetEMPH().get_GUIPropertyManager(propertyTag); - } - - [WebMethod(Description="This command sets the property using the property tag given from MP's property manager.")] - public bool set_MPPropertyManager(string propertyTag,string propertyValue) - { - if (propertyTag=="") {return false;} - - try - { - GetEMPH().set_GUIPropertyManager(propertyTag,propertyValue); - return true; + return GetEMPH().GetRecorderProps(propName); } - catch - { - return false; - } - } - [WebMethod(Description=@"This command launches MediaPortal. The whole path to MediaPortal needs to be provided, e.g. C:\Program Files\Team MediaPortal\MediaPortal\MediaPortal.exe")] - public bool LaunchApplication(string appPath) - { - appPath = Server.UrlDecode(appPath); - - string folder = appPath.Substring(0,appPath.LastIndexOf(@"\")); - - try + [WebMethod(Description="This command gets the specified property from MP's g_Player object.")] + public object GetgPlayerProps(string propName) { - System.Diagnostics.ProcessStartInfo si = new System.Diagnostics.ProcessStartInfo(); - si.FileName = appPath; - si.WorkingDirectory = folder; - System.Diagnostics.Process.Start(si); + if (propName=="") + { + return false; + } - return true; + return GetEMPH().GetgPlayerProps(propName); } - catch - { - return false; - } - } + #endregion - [WebMethod(Description="This command gets the specified property from MP's recorder object.")] - public object GetRecorderProps(string propName) - { - if (propName=="") + #region TV Channel/Program commands + [WebMethod(Description="This command tells MediaPortal to re-import the XMLTV data file.")] + public bool ImportXMLTVGuide() { - return false; + return GetEMPH().ImportXMLTVGuide(); } - return GetEMPH().GetRecorderProps(propName); - } - - [WebMethod(Description="This command gets the specified property from MP's g_Player object.")] - public object GetgPlayerProps(string propName) - { - if (propName=="") + [WebMethod(Description="This command retrieves all the channels in MP in XML format.")] + public string GetChannels() { - return false; - } + List<MediaPortal.TV.Database.TVChannel> chnList; + chnList = GetEMPH().GetChannels(); - return GetEMPH().GetgPlayerProps(propName); - } + if (chnList.Count == 0) return ""; - [WebMethod(Description="This command tells MediaPortal to refresh its recordings list.")] - public bool RefreshRecordingsInMP() - { - return GetEMPH().RefreshRecordings(); - } + // As CurrentProgram is not necessary, set its XMLIgnore attribute to true + System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); + System.Xml.Serialization.XmlAttributes xmlAttributes; - [WebMethod(Description="This command tells MediaPortal to re-import the XMLTV data file.")] - public bool ImportXMLTVGuide() - { - return GetEMPH().ImportXMLTVGuide(); - } + xmlAttributes = new System.Xml.Serialization.XmlAttributes(); + xmlAttributes.XmlIgnore = true; + xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVChannel), "CurrentProgram", xmlAttributes); - private System.Xml.XmlWriterSettings GetXMLDocWriterSettings() - { - System.Xml.XmlWriterSettings xwSettings = new System.Xml.XmlWriterSettings(); - xwSettings.Encoding = System.Text.Encoding.UTF8; - xwSettings.Indent = true; - xwSettings.OmitXmlDeclaration = false; - xwSettings.ConformanceLevel = System.Xml.ConformanceLevel.Auto; + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel),xmlOverrides); + MediaPortal.TV.Database.TVChannel chn; - return xwSettings; - } + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVChannels"); - [WebMethod(Description="This command retrieves all the channels in MP in XML format.")] - public string GetChannels() - { - List<MediaPortal.TV.Database.TVChannel> chnList; - chnList = GetEMPH().GetChannels(); + for (int i = 0; i <= chnList.Count - 1; i++) + { + chn = (MediaPortal.TV.Database.TVChannel)chnList[i]; - if (chnList.Count == 0) return ""; + xs.Serialize(xw, chn); + } - // As CurrentProgram is not necessary, set its XMLIgnore attribute to true - System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); - System.Xml.Serialization.XmlAttributes xmlAttributes; + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); - xmlAttributes = new System.Xml.Serialization.XmlAttributes(); - xmlAttributes.XmlIgnore = true; - xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVChannel), "CurrentProgram", xmlAttributes); + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel),xmlOverrides); - MediaPortal.TV.Database.TVChannel chn; + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } - try + [WebMethod(Description = "This command retrieves the specified channel from MP in XML format.")] + public string GetChannel(int channelID) { - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVChannels"); + MediaPortal.TV.Database.TVChannel chn; + chn = GetEMPH().GetChannel(channelID); - for (int i = 0; i <= chnList.Count - 1; i++) + // As CurrentProgram is not necessary, set its XMLIgnore attribute to true + System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); + System.Xml.Serialization.XmlAttributes xmlAttributes; + + xmlAttributes = new System.Xml.Serialization.XmlAttributes(); + xmlAttributes.XmlIgnore = true; + xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVChannel), "CurrentProgram", xmlAttributes); + + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel), xmlOverrides); + + try { - chn = (MediaPortal.TV.Database.TVChannel)chnList[i]; + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVChannels"); xs.Serialize(xw, chn); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); } + catch (Exception ex) + { + return ex.ToString(); + } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } - xw.Flush(); + [WebMethod(Description="This command converts a channelID into its corresponding channel name.")] + public string GetChannelName(int channelID) + { + return GetEMPH().GetChannelName(channelID); } - catch (Exception ex) + + [WebMethod(Description="This command converts a channel name to its corresponding channelID.")] + public int GetChannelID(string channelName) { - return ex.ToString(); + return GetEMPH().GetChannelID(channelName); } - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } + [WebMethod(Description="This command returns the list of TV program genres in XML format.")] + public string GetGenres() + { + List<string> genresList; + genresList = GetEMPH().GetGenres(); - [WebMethod(Description = "This command retrieves the specified channel from MP in XML format.")] - public string GetChannel(int channelID) - { - MediaPortal.TV.Database.TVChannel chn; - chn = GetEMPH().GetChannel(channelID); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - // As CurrentProgram is not necessary, set its XMLIgnore attribute to true - System.Xml.Serialization.XmlAttributeOverrides xmlOverrides = new System.Xml.Serialization.XmlAttributeOverrides(); - System.Xml.Serialization.XmlAttributes xmlAttributes; - - xmlAttributes = new System.Xml.Serialization.XmlAttributes(); - xmlAttributes.XmlIgnore = true; - xmlOverrides.Add(typeof(MediaPortal.TV.Database.TVChannel), "CurrentProgram", xmlAttributes); - - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVChannel), xmlOverrides); - - try - { xw.WriteStartDocument(); xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVChannels"); + xw.WriteStartElement("Genres"); - xs.Serialize(xw, chn); + string s; + for (int i = 0; i <= genresList.Count - 1; i++) + { + xw.WriteStartElement("Genre"); + s = (string)genresList[i]; + xw.WriteElementString("GenreName", s); + xw.WriteEndElement(); + } + xw.WriteEndElement(); xw.WriteEndElement(); xw.WriteEndDocument(); xw.Flush(); + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } - catch (Exception ex) + + [WebMethod(Description="This command returns the list of TV programs within the given date in XML format.")] + public string GetProgramsByDate(DateTime startDateTime, DateTime endDateTime) { - return ex.ToString(); - } + List<MediaPortal.TV.Database.TVProgram> progList; + progList = GetEMPH().GetPrograms(startDateTime,endDateTime); - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); + MediaPortal.TV.Database.TVProgram prog; - [WebMethod(Description="This command converts a channelID into its corresponding channel name.")] - public string GetChannelName(int channelID) - { - return GetEMPH().GetChannelName(channelID); - } - - [WebMethod(Description="This command converts a channel name to its corresponding channelID.")] - public int GetChannelID(string channelName) - { - return GetEMPH().GetChannelID(channelName); - } + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVPrograms"); - [WebMethod(Description="This command adds a recording to MP's recording list. No recordings refresh command is required after this action.")] - public bool AddRecording(string title, string channelName, DateTime startDateTime, DateTime endDateTime, string recType) - { - return GetEMPH().AddRecording(title, channelName,startDateTime,endDateTime,recType); - } + for (int i = 0; i <= progList.Count - 1; i++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } - [WebMethod(Description="This command tells MediaPortal to delete a particular recording by ID.")] - public bool DeleteRecordingByID(int recordingID) - { - return GetEMPH().DelRecording(recordingID); - } + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); - [WebMethod(Description="This command tells MediaPortal to delete a particular recording by starting time and channel name.")] - public bool DeleteRecordingByStartTimeAndChannelName(DateTime startDateTime, string channelName) - { - return GetEMPH().DelRecording(startDateTime,channelName); - } + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } - [WebMethod(Description="This command tells MediaPortal to delete a particular recording by starting time and channel number.")] - public bool DeleteRecordingByStartTimeAndChannelLCN(DateTime startDateTime, int channelLCN) - { - return GetEMPH().DelRecording(startDateTime,channelLCN); - } + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } - [WebMethod(Description="This command returns the list of TV program genres in XML format.")] - public string GetGenres() - { - List<string> genresList; - genresList = GetEMPH().GetGenres(); - - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("Genres"); - - string s; - - for (int i = 0; i <= genresList.Count - 1; i++) + [WebMethod(Description="This command returns a list of all the TV programs in XML format.")] + public string GetAllPrograms() { - xw.WriteStartElement("Genre"); - s = (string)genresList[i]; - xw.WriteElementString("GenreName", s); - xw.WriteEndElement(); - } + List<MediaPortal.TV.Database.TVProgram> progList; + progList = GetEMPH().GetPrograms(); - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); + MediaPortal.TV.Database.TVProgram prog; - xw.Flush(); + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVPrograms"); - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } + for (int i = 0; i <= progList.Count - 1; i++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } - [WebMethod(Description="This command returns the list of TV programs within the given date in XML format.")] - public string GetProgramsByDate(DateTime startDateTime, DateTime endDateTime) - { - List<MediaPortal.TV.Database.TVProgram> progList; - progList = GetEMPH().GetPrograms(startDateTime,endDateTime); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); - MediaPortal.TV.Database.TVProgram prog; - - try - { - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVPrograms"); - - for (int i = 0; i <= progList.Count - 1; i++) + xw.Flush(); + } + catch (Exception ex) { - prog = (MediaPortal.TV.Database.TVProgram)progList[i]; - xs.Serialize(xw, prog); + return ex.ToString(); } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } - xw.Flush(); - } - catch (Exception ex) + [WebMethod(Description="This command returns the list of TV program genres in XML format.")] + public string GetProgramsByChannel(int channelID, DateTime startDateTime, DateTime endDateTime) { - return ex.ToString(); - } + List<MediaPortal.TV.Database.TVProgram> progList; + progList = GetEMPH().GetPrograms(GetChannelName(channelID),startDateTime,endDateTime); - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); + MediaPortal.TV.Database.TVProgram prog; - [WebMethod(Description="This command returns a list of all the TV programs in XML format.")] - public string GetAllPrograms() - { - List<MediaPortal.TV.Database.TVProgram> progList; - progList = GetEMPH().GetPrograms(); + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVPrograms"); - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); - MediaPortal.TV.Database.TVProgram prog; + for (int i = 0; i <= progList.Count - 1; i++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } - try - { - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVPrograms"); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); - for (int i = 0; i <= progList.Count - 1; i++) + xw.Flush(); + } + catch (Exception ex) { - prog = (MediaPortal.TV.Database.TVProgram)progList[i]; - xs.Serialize(xw, prog); + return ex.ToString(); } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + #endregion - xw.Flush(); - } - catch (Exception ex) + #region recorded TV commands + [WebMethod(Description="This command returns the list of all recorded TV items in XML format.")] + public string GetAllRecordedTV() { - return ex.ToString(); - } + List<MediaPortal.TV.Database.TVRecorded> recdTVList; + recdTVList = GetEMPH().GetAllRecordedTV(); - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecorded )); + MediaPortal.TV.Database.TVRecorded recdTV; - [WebMethod(Description="This command returns the list of TV program genres in XML format.")] - public string GetProgramsByChannel(int channelID, DateTime startDateTime, DateTime endDateTime) - { - List<MediaPortal.TV.Database.TVProgram> progList; - progList = GetEMPH().GetPrograms(GetChannelName(channelID),startDateTime,endDateTime); + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVRecorded"); - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVProgram )); - MediaPortal.TV.Database.TVProgram prog; + for (int i = 0; i <= recdTVList.Count - 1; i++) + { + recdTV = (MediaPortal.TV.Database.TVRecorded)recdTVList[i]; + xs.Serialize(xw, recdTV); + } - try - { - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVPrograms"); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); - for (int i = 0; i <= progList.Count - 1; i++) + xw.Flush(); + } + catch (Exception ex) { - prog = (MediaPortal.TV.Database.TVProgram)progList[i]; - xs.Serialize(xw, prog); + return ex.ToString(); } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } - xw.Flush(); - } - catch (Exception ex) + [WebMethod(Description = "This command returns the specified recorded TV item in XML format.")] + public string GetRecordedTV(string recordedTVFileName) { - return ex.ToString(); - } + MediaPortal.TV.Database.TVRecorded recdTV; + recdTV = GetEMPH().GetRecordedTV(recordedTVFileName); - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecorded)); - [WebMethod(Description="This command returns the list of TV recordings in XML format.")] - public string GetRecordings() - { - List<MediaPortal.TV.Database.TVRecording > recList; - recList = GetEMPH().GetRecordings(); + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVRecorded"); - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecording )); - MediaPortal.TV.Database.TVRecording rec; + xs.Serialize(xw, recdTV); - try - { - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVRecordings"); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); - for (int i = 0; i <= recList.Count - 1; i++) + xw.Flush(); + } + catch (Exception ex) { - rec = (MediaPortal.TV.Database.TVRecording)recList[i]; - xs.Serialize(xw, rec); + return ex.ToString(); } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + #endregion - xw.Flush(); + #region playlist commands + [WebMethod(Description="This command returns the name of the current playlist.")] + public string GetCurrentPlaylistName() + { + return GetEMPH().CurrentPlaylistName; } - catch (Exception ex) + + [WebMethod(Description="This command returns song number that's currently playing in the current playlist.")] + public int GetCurrentSongNo() { - return ex.ToString(); + return GetEMPH().CurrentSongNo; } - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } - - [WebMethod(Description="This command returns the list of all recorded TV items in XML format.")] - public string GetAllRecordedTV() - { - List<MediaPortal.TV.Database.TVRecorded> recdTVList; - recdTVList = GetEMPH().GetAllRecordedTV(); - - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecorded )); - MediaPortal.TV.Database.TVRecorded recdTV; - - try + [WebMethod(Description="This command returns the items in a playlist given the playlist name (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP) in XML format.")] + public string GetPlaylist(string playlistType) { - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVRecorded"); - - for (int i = 0; i <= recdTVList.Count - 1; i++) + //resolve playlistType + MediaPortal.Playlists.PlayListType playlistTypeResolve; + if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) { - recdTV = (MediaPortal.TV.Database.TVRecorded)recdTVList[i]; - xs.Serialize(xw, recdTV); + return ""; } + + playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType),playlistType); - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); + MediaPortal.Playlists.PlayList playlist; + playlist = GetEMPH().GetPlaylist(playlistTypeResolve); - xw.Flush(); - } - catch (Exception ex) - { - return ex.ToString(); - } + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); + System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); + System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.Playlists.PlayListItem )); + MediaPortal.Playlists.PlayListItem playlistItem; - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("Playlist"); + xw.WriteAttributeString("type", playlistType); - [WebMethod(Description = "This command returns the specified recorded TV item in XML format.")] - public string GetRecordedTV(string recordedTVFileName) - { - MediaPortal.TV.Database.TVRecorded recdTV; - recdTV = GetEMPH().GetRecordedTV(recordedTVFileName); + for (int i = 0; i <= playlist.Count - 1; i++) + { + playlistItem = (MediaPortal.Playlists.PlayListItem)playlist[i]; + xs.Serialize(xw, playlistItem); + } - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.TV.Database.TVRecorded)); + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); - try - { - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("TVRecorded"); + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } - xs.Serialize(xw, recdTV); + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); - - xw.Flush(); - } - catch (Exception ex) + [WebMethod(Description="This command adds an item to the nominated playlist.")] + public bool AddPlaylistItem(string playlistType, string fileName, string description, int duration, string itemType) { - return ex.ToString(); - } + if (fileName=="") {return false;} - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } - - [WebMethod(Description="This command returns the name of the current playlist.")] - public string GetCurrentPlaylistName() - { - return GetEMPH().CurrentPlaylistName; - } + //resolve playlistType + MediaPortal.Playlists.PlayListType playlistTypeResolve; + if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) + { + return false; + } + + playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType),playlistType); - [WebMethod(Description="This command returns song number that's currently playing in the current playlist.")] - public int GetCurrentSongNo() - { - return GetEMPH().CurrentSongNo; - } + //resolve itemType + MediaPortal.Playlists.PlayListItem.PlayListItemType itemTypeResolve; + if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListItem.PlayListItemType),itemType )==false) + { + return false; + } - [WebMethod(Description="This command returns the items in a playlist given the playlist name (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP) in XML format.")] - public string GetPlaylist(string playlistType) - { - //resolve playlistType - MediaPortal.Playlists.PlayListType playlistTypeResolve; - if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) - { - return ""; - } - - playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType),playlistType); + itemTypeResolve = (MediaPortal.Playlists.PlayListItem.PlayListItemType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListItem.PlayListItemType), itemType); - MediaPortal.Playlists.PlayList playlist; - playlist = GetEMPH().GetPlaylist(playlistTypeResolve); - System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); - System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); - System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(typeof(MediaPortal.Playlists.PlayListItem )); - MediaPortal.Playlists.PlayListItem playlistItem; + return GetEMPH().AddPlaylistItem(playlistTypeResolve,fileName,description,duration,itemTypeResolve); + } - try + [WebMethod(Description="This command adds an item to the nominated playlist.")] + public bool AddPlaylistItemUsingDB(string playlistType, string itemType, string fileName) { - xw.WriteStartDocument(); - xw.WriteStartElement("MPData"); - xw.WriteStartElement("Playlist"); - xw.WriteAttributeString("type", playlistType); + if (fileName=="") {return false;} - for (int i = 0; i <= playlist.Count - 1; i++) + //resolve playlistType + MediaPortal.Playlists.PlayListType playlistTypeResolve; + if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) { - playlistItem = (MediaPortal.Playlists.PlayListItem)playlist[i]; - xs.Serialize(xw, playlistItem); + return false; } - xw.WriteEndElement(); - xw.WriteEndElement(); - xw.WriteEndDocument(); + playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType), playlistType); - xw.Flush(); - } - catch (Exception ex) - { - return ex.ToString(); - } + //resolve itemType + MediaPortal.Playlists.PlayListItem.PlayListItemType itemTypeResolve; + if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListItem.PlayListItemType),itemType )==false) + { + return false; + } - return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); - } + itemTypeResolve = (MediaPortal.Playlists.PlayListItem.PlayListItemType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListItem.PlayListItemType), itemType); - [WebMethod(Description="This command adds an item to the nominated playlist.")] - public bool AddPlaylistItem(string playlistType, string fileName, string description, int duration, string itemType) - { - if (fileName=="") {return false;} - - //resolve playlistType - MediaPortal.Playlists.PlayListType playlistTypeResolve; - if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) - { - return false; + return GetEMPH().AddPlaylistItem(playlistTypeResolve,itemTypeResolve,fileName ); } - - playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType),playlistType); - //resolve itemType - MediaPortal.Playlists.PlayListItem.PlayListItemType itemTypeResolve; - if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListItem.PlayListItemType),itemType )==false) + [WebMethod(Description="This command removes an item from the nominated playlist.")] + public bool RemovePlaylistItem(string playlistType, string fileName) { - return false; - } + if (fileName=="") {return false;} - itemTypeResolve = (MediaPortal.Playlists.PlayListItem.PlayListItemType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListItem.PlayListItemType), itemType); + //resolve playlistType + MediaPortal.Playlists.PlayListType playlistTypeResolve; + if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) + { + return false; + } + playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType), playlistType); - return GetEMPH().AddPlaylistItem(playlistTypeResolve,fileName,description,duration,itemTypeResolve); - } + return GetEMPH().RemovePlaylistItem(playlistTypeResolve,fileName); + } - [WebMethod(Description="This command adds an item to the nominated playlist.")] - public bool AddPlaylistItemUsingDB(string playlistType, string itemType, string fileName) - { - if (fileName=="") {return false;} + [WebMethod(Description="This command plays an item from the nominated playlist.")] + public bool PlayPlaylistItem(string playlistType, int songNum) + { + //resolve playlistType + MediaPortal.Playlists.PlayListType playlistTypeResolve; + if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) + { + return false; + } - //resolve playlistType - MediaPortal.Playlists.PlayListType playlistTypeResolve; - if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) - { - return false; + playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType), playlistType); + + return GetEMPH().PlayPlaylistItem(playlistTypeResolve,songNum); } - playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType), playlistType); - - //resolve itemType - MediaPortal.Playlists.PlayListItem.PlayListItemType itemTypeResolve; - if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListItem.PlayListItemType),itemType )==false) + [WebMethod(Description="This command clears a playlist.")] + public bool ClearPlaylistItem(string playlistType) { - return false; - } + //resolve playlistType + MediaPortal.Playlists.PlayListType playlistTypeResolve; + if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) + { + return false; + } - itemTypeResolve = (MediaPortal.Playlists.PlayListItem.PlayListItemType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListItem.PlayListItemType), itemType); + playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType), playlistType); - return GetEMPH().AddPlaylistItem(playlistTypeResolve,itemTypeResolve,fileName ); - } + return GetEMPH().ClearPlaylist(playlistTypeResolve); + } + #endregion - [WebMethod(Description="This command removes an item from the nominated playlist.")] - public bool RemovePlaylistItem(string playlistType, string fileName) - { - if (fileName=="") {return false;} + #region settings commands + [WebMethod(Description="This command retrieves the relevant config setting from the MP XML Settings file.")] + public string GetMPSetting(string section, string entry) + { + if ((section=="") || (entry=="")) + { + return ""; + } - //resolve playlistType - MediaPortal.Playlists.PlayListType playlistTypeResolve; - if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) - { - return false; + return GetEMPH().GetMPSettingAsString(section,entry); } - playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType), playlistType); + [WebMethod(Description="This command sets the value into the relevant config setting from the MP XML Settings file.")] + public bool SetMPSetting(string section, string entry, string value) + { + if ((section=="") || (entry=="")) + { + return false; + } - return GetEMPH().RemovePlaylistItem(playlistTypeResolve,fileName); - } + return GetEMPH().SetMPSetting(section, entry, value); + } - [WebMethod(Description="This command plays an item from the nominated playlist.")] - public bool PlayPlaylistItem(string playlistType, int songNum) - { - //resolve playlistType - MediaPortal.Playlists.PlayListType playlistTypeResolve; - if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) + [WebMethod(Description="This command removes a particular entry from the relevant section in the MP XML Settings file.")] + public bool MPSettingsRemoveEntry(string section, string entry) { - return false; + if ((section=="") || (entry=="")) + { + return false; + } + + return GetEMPH().RemoveMPSetting(section, entry); } + #endregion - playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType), playlistType); - - return GetEMPH().PlayPlaylistItem(playlistTypeResolve,songNum); - } - - [WebMethod(Description="This command clears a playlist.")] - public bool ClearPlaylistItem(string playlistType) - { - //resolve playlistType - MediaPortal.Playlists.PlayListType playlistTypeResolve; - if (Enum.IsDefined(typeof(MediaPortal.Playlists.PlayListType),playlistType)==false) + #region version commands + [WebMethod(Description="This command returns the version of the ECP2Assembly.dll running within MediaPortal.")] + public string GetMPECP2AssemblyVersion() { - return false; + return GetEMPH().MPECP2Version; } - playlistTypeResolve = (MediaPortal.Playlists.PlayListType)Enum.Parse(typeof(MediaPortal.Playlists.PlayListType), playlistType); - - return GetEMPH().ClearPlaylist(playlistTypeResolve); - } - - [WebMethod(Description="This command retrieves the relevant config setting from the MP XML Settings file.")] - public string GetMPSetting(string section, string entry) - { - if ((section=="") || (entry=="")) + [WebMethod(Description="This command returns the version of the ECP2Assembly.dll running within this web service.")] + public string GetWSECP2AssemblyVersion() { - return ""; + return System.Reflection.Assembly.GetAssembly(GetEMPH().GetType()).GetName().Version.ToString(); } - return GetEMPH().GetMPSettingAsString(section,entry); - } - - [WebMethod(Description="This command sets the value into the relevant config setting from the MP XML Settings file.")] - public bool SetMPSetting(string section, string entry, string value) - { - if ((section=="") || (entry=="")) + [WebMethod(Description="This command returns the version of the web service.")] + public string GetWSVersion() { - return false; + return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); } - return GetEMPH().SetMPSetting(section, entry, value); - } - - [WebMethod(Description="This command removes a particular entry from the relevant section in the MP XML Settings file.")] - public bool MPSettingsRemoveEntry(string section, string entry) - { - if ((section=="") || (entry=="")) + [WebMethod(Description="This command returns the version of MediaPortal running.")] + public string GetMPVersion() { - return false; + return GetEMPH().MPVersion; } + #endregion +} - return GetEMPH().RemoveMPSetting(section, entry); - } - [WebMethod(Description="This command returns the version of the ECP2Assembly.dll running within MediaPortal.")] - public string GetMPECP2AssemblyVersion() - { - return GetEMPH().MPECP2Version; - } - - [WebMethod(Description="This command returns the version of the ECP2Assembly.dll running within this web service.")] - public string GetWSECP2AssemblyVersion() - { - return System.Reflection.Assembly.GetAssembly(GetEMPH().GetType()).GetName().Version.ToString(); - } - - [WebMethod(Description="This command returns the version of the web service.")] - public string GetWSVersion() - { - return System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); - } - - [WebMethod(Description="This command returns the version of MediaPortal running.")] - public string GetMPVersion() - { - return GetEMPH().MPVersion; - } - - } - - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |