From: <sam...@us...> - 2006-06-19 12:31:24
|
Revision: 16 Author: samuel337 Date: 2006-06-19 05:31:08 -0700 (Mon, 19 Jun 2006) ViewCVS: http://svn.sourceforge.net/mp-webinterface/?rev=16&view=rev Log Message: ----------- implemented AddTVNotify, DeleteTVNotify, GetTVNotify, GetTVNotifies, GetTVGroups, GetTVGroup, GetProgramsByGenre, GetChannelsByGroupID, GetProgramsBySearch functions. TVNotify/TVGroup functions will not work until required MP changes are made and committed. LaunchMP has also been recoded. Modified Paths: -------------- trunk/source/ECP2Assembly/clsMPHandler.cs trunk/source/ECP2WebService/App_Code/Service.cs Modified: trunk/source/ECP2Assembly/clsMPHandler.cs =================================================================== --- trunk/source/ECP2Assembly/clsMPHandler.cs 2006-06-18 15:07:25 UTC (rev 15) +++ trunk/source/ECP2Assembly/clsMPHandler.cs 2006-06-19 12:31:08 UTC (rev 16) @@ -348,7 +348,7 @@ return MediaPortal.Player.g_Player.Playing; case "Speed": - return MediaPortal.Player.g_Player.Speed; + return MediaPortal.Player.g_Player.Speed; case "Stopped": return MediaPortal.Player.g_Player.Stopped; @@ -430,62 +430,17 @@ return recList; } - public bool AddRecording(string Title, string Channel, DateTime StartTime, DateTime EndTime, string RecType) - { - try - { - MediaPortal.TV.Database.TVRecording rec = new MediaPortal.TV.Database.TVRecording(); - string strRecType; - Array arrRecType; - bool recTypeFound = false; - - rec.Channel = Channel; - rec.Title = Title; - rec.Start = DateToLong(StartTime); - rec.End = DateToLong(EndTime); - - //resolve recording type string into the correct enum - arrRecType = Enum.GetValues(typeof(MediaPortal.TV.Database.TVRecording.RecordingType)); - - for (int i = arrRecType.GetLowerBound(0); i <= arrRecType.GetUpperBound(0); i++) - { - strRecType = Enum.GetName(typeof(MediaPortal.TV.Database.TVRecording.RecordingType), arrRecType.GetValue(i)); - if (strRecType == RecType) - { - rec.RecType = (MediaPortal.TV.Database.TVRecording.RecordingType)arrRecType.GetValue(i); - recTypeFound = true; - break; - } - } - - //if the specified rec-type string does not match one of the enum values, then set rectype to Once - if (recTypeFound == false) - { - rec.RecType = MediaPortal.TV.Database.TVRecording.RecordingType.Once; - } - - MediaPortal.TV.Database.TVDatabase.AddRecording(ref rec); - MediaPortal.GUI.Library.Log.Write("ECP2 - AddRecording: recording added."); - return true; - } - catch (Exception ex) - { - MediaPortal.GUI.Library.Log.Write("ECP2 Error: " + ex.ToString()); - return false; - } - } - public bool AddRecording(MediaPortal.TV.Database.TVRecording rec) { try { MediaPortal.TV.Database.TVDatabase.AddRecording(ref rec); - MediaPortal.GUI.Library.Log.Write("ECP2 - AddRecording: recording added."); + MediaPortal.GUI.Library.Log.Write("ECP2 - AddRecording: recording ({0}, {1}, {2}) added.", rec.Title, rec.Channel, rec.StartTime.ToString()); return true; } catch (Exception ex) { - MediaPortal.GUI.Library.Log.Write("ECP2 Error: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Write("ECP2 - AddRecording: " + ex.ToString()); return false; } } @@ -495,12 +450,12 @@ try { MediaPortal.TV.Database.TVDatabase.UpdateRecording(rec, changeReason); - MediaPortal.GUI.Library.Log.Write("ECP2 - UpdateRecording: recording updated."); + MediaPortal.GUI.Library.Log.Write("ECP2 - UpdateRecording: recording ({0}, {1}, {2}) updated.", rec.Title, rec.Channel, rec.StartTime.ToString()); return true; } catch (Exception ex) { - MediaPortal.GUI.Library.Log.Write("ECP2 Error: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Write("ECP2 - UpdateRecording: " + ex.ToString()); return false; } } @@ -529,12 +484,13 @@ if (ScheduleToDel ==true) { MediaPortal.TV.Database.TVDatabase.RemoveRecording(rec); + MediaPortal.GUI.Library.Log.Write("ECP2 - DelRecording: recording ({0}, {1}, {2}) deleted.", rec.Title, rec.Channel, rec.StartTime.ToString()); return true; } } catch (Exception ex) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - DelRecording: exception - " + ex.ToString()); + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - DelRecording: " + ex.ToString()); } return false; @@ -565,13 +521,14 @@ if (ScheduleToDel==true) { MediaPortal.TV.Database.TVDatabase.RemoveRecording(rec); + MediaPortal.GUI.Library.Log.Write("ECP2 - DelRecording: recording ({0}, {1}, {2}) deleted.", rec.Title, rec.Channel, rec.StartTime.ToString()); return true; } } catch (Exception ex) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - DelRecording: exception - " + ex.ToString()); + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - DelRecording: " + ex.ToString()); } return false; @@ -637,6 +594,14 @@ return chnList; } + public List<MediaPortal.TV.Database.TVChannel> GetChannels(int GroupID) + { + List<MediaPortal.TV.Database.TVChannel> chanList = new List<MediaPortal.TV.Database.TVChannel>(); + MediaPortal.TV.Database.TVDatabase.GetTVChannelsForGroup(GroupID, chanList); + + return chanList; + } + public MediaPortal.TV.Database.TVChannel GetChannel(int ChannelID) { return MediaPortal.TV.Database.TVDatabase.GetChannelById(ChannelID); @@ -658,6 +623,14 @@ return progList; } + public List<MediaPortal.TV.Database.TVProgram> GetPrograms(string GenreName) + { + List<MediaPortal.TV.Database.TVProgram> progList = new List<MediaPortal.TV.Database.TVProgram>(); + MediaPortal.TV.Database.TVDatabase.GetProgramsPerGenre(GenreName, progList); + + return progList; + } + public List<MediaPortal.TV.Database.TVProgram> GetPrograms(DateTime StartDateTime, DateTime EndDateTime) { List<MediaPortal.TV.Database.TVProgram> progList = new List<MediaPortal.TV.Database.TVProgram>(); @@ -666,6 +639,48 @@ return progList; } + public List<MediaPortal.TV.Database.TVProgram> GetPrograms(DateTime StartDateTime, DateTime EndDateTime, string SearchField, string SearchType, string SearchCriteria, string ChannelName) + { + int SearchKind; + + //convert SearchType to SearchKind + switch (SearchType.ToLower()) + { + case "wildcardatend": + SearchKind = 0; + break; + + case "wildcardatstartend": + SearchKind = 1; + break; + + case "wildcardatstart": + SearchKind = 2; + break; + + case "exact": + SearchKind = 3; + break; + + default: + SearchKind = 0; + break; + } + + List<MediaPortal.TV.Database.TVProgram> progList = new List<MediaPortal.TV.Database.TVProgram>(); + + if (SearchField.ToLower() == "description") + { + MediaPortal.TV.Database.TVDatabase.SearchProgramsByDescription(DateToLong(StartDateTime), DateToLong(EndDateTime), ref progList, SearchKind, SearchCriteria); + } + else //title + { + MediaPortal.TV.Database.TVDatabase.SearchPrograms(DateToLong(StartDateTime), DateToLong(EndDateTime), ref progList, SearchKind, SearchCriteria, ChannelName); + } + + return progList; + } + public List<MediaPortal.TV.Database.TVProgram> GetPrograms() { List<MediaPortal.TV.Database.TVProgram> progList = new List<MediaPortal.TV.Database.TVProgram>(); @@ -688,6 +703,216 @@ { return GetChannel(ChannelID).Name ; } + + public bool AddTVNotify(string ChannelName, DateTime StartDateTime) + { + try + { + MediaPortal.TV.Database.TVNotify notify = new MediaPortal.TV.Database.TVNotify(); + notify.Program = MediaPortal.TV.Database.TVDatabase.GetProgramByTime(ChannelName, StartDateTime); + + if (notify.Program == null) + { + throw new Exception("Could not locate a program matching the parameters given."); + } + + MediaPortal.TV.Database.TVDatabase.AddNotify(notify); + MediaPortal.GUI.Library.Log.Write("ECP2 - AddTVNotify: TVNotify ({0}, {1}) added.",notify.Program.Title,notify.Program.StartTime.ToString()); + return true; + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.Write("ECP2 - AddTVNotify: " + ex.ToString()); + return false; + } + } + + public bool DeleteTVNotify(string ChannelName, DateTime StartDateTime) + { + try + { + MediaPortal.TV.Database.TVNotify notify = GetTVNotify(ChannelName, StartDateTime); + + if (notify == null) + { + return false; + } + + MediaPortal.TV.Database.TVDatabase.DeleteNotify(notify); + MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: TVNotify ({0}, {1}) deleted.", notify.Program.Title, notify.Program.StartTime.ToString()); + return true; + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: " + ex.ToString()); + return false; + } + } + + public bool DeleteTVNotify(int TVNotifyID) + { + try + { + MediaPortal.TV.Database.TVNotify notify = GetTVNotify(TVNotifyID); + + if (notify == null) + { + return false; + } + + MediaPortal.TV.Database.TVDatabase.DeleteNotify(notify); + MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: TVNotify ({0}, {1}) deleted.", notify.Program.Title, notify.Program.StartTime.ToString()); + return true; + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: " + ex.ToString()); + return false; + } + } + + public MediaPortal.TV.Database.TVNotify GetTVNotify(string ChannelName, DateTime StartDateTime) + { + try + { + MediaPortal.TV.Database.TVNotify notify = new MediaPortal.TV.Database.TVNotify(); + notify.Program = MediaPortal.TV.Database.TVDatabase.GetProgramByTime(ChannelName, StartDateTime); + + if (notify.Program == null) + { + throw new Exception("Could not locate a program matching the parameters given."); + } + + MediaPortal.TV.Database.TVDatabase.GetNotify(notify); + return notify; + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.Write("ECP2 - GetNotify: " + ex.ToString()); + return null; + } + } + + public MediaPortal.TV.Database.TVNotify GetTVNotify(int TVNotifyID) + { + try + { + bool NotifyToDel = false; + + MediaPortal.TV.Database.TVNotify notify = new MediaPortal.TV.Database.TVNotify(); + List<MediaPortal.TV.Database.TVNotify> TVNotifyList = GetTVNotifies(); + + for (int i = 0; i < TVNotifyList.Count; i++) + { + notify = (MediaPortal.TV.Database.TVNotify)TVNotifyList[i]; + if (notify.ID == TVNotifyID) + { + NotifyToDel = true; + break; + } + } + + if (NotifyToDel == true) + { + return notify; + } + else + { + return null; + } + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - GetTVNotify: " + ex.ToString()); + return null; + } + } + + public List<MediaPortal.TV.Database.TVNotify> GetTVNotifies() + { + List<MediaPortal.TV.Database.TVNotify> TVNotifyList = new List<MediaPortal.TV.Database.TVNotify>(); + MediaPortal.TV.Database.TVDatabase.GetNotifies(TVNotifyList, true); + + return TVNotifyList; + } + + public List<MediaPortal.TV.Database.TVGroup> GetTVGroups() + { + List<MediaPortal.TV.Database.TVGroup> TVGroupList = new List<MediaPortal.TV.Database.TVGroup>(); + MediaPortal.TV.Database.TVDatabase.GetGroups(ref TVGroupList); + + return TVGroupList; + } + + public MediaPortal.TV.Database.TVGroup GetTVGroup(string GroupName) + { + try + { + bool foundTVGroup = false; + + MediaPortal.TV.Database.TVGroup group = new MediaPortal.TV.Database.TVGroup(); + List<MediaPortal.TV.Database.TVGroup> TVGroupList = GetTVGroups(); + + for (int i = 0; i < TVGroupList.Count; i++) + { + group = (MediaPortal.TV.Database.TVGroup)TVGroupList[i]; + if (group.GroupName == GroupName) + { + foundTVGroup = true; + break; + } + } + + if (foundTVGroup == true) + { + return group; + } + else + { + return null; + } + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - GetTVGroup: " + ex.ToString()); + return null; + } + } + + public MediaPortal.TV.Database.TVGroup GetTVGroup(int GroupID) + { + try + { + bool foundTVGroup=false; + + MediaPortal.TV.Database.TVGroup group = new MediaPortal.TV.Database.TVGroup(); + List<MediaPortal.TV.Database.TVGroup> TVGroupList = GetTVGroups(); + + for (int i = 0; i < TVGroupList.Count; i++) + { + group = (MediaPortal.TV.Database.TVGroup)TVGroupList[i]; + if (group.ID == GroupID) + { + foundTVGroup = true; + break; + } + } + + if (foundTVGroup == true) + { + return group; + } + else + { + return null; + } + } + catch (Exception ex) + { + MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - GetTVGroup: " + ex.ToString()); + return null; + } + } #endregion #region Recorded TV commands @@ -828,6 +1053,8 @@ { return false; } + + break; } } Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-18 15:07:25 UTC (rev 15) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-19 12:31:08 UTC (rev 16) @@ -7,7 +7,7 @@ namespace ECP2WebService { - [WebService(Name = "MediaPortal External Control II Web Service", Description = "This web service allows you to communicate and control MediaPortal. You will need to have MediaPortal running, and the External Control II plugin needs to be loaded.", Namespace = "http://www.team-mediaportal.com/ECP2WebService/")] + [WebService(Name = "MediaPortal External Control II Web Service", Description = "This web service allows you to communicate and control MediaPortal. You will need to have MediaPortal running, and the External Control II plugin needs to be loaded.<br><br>For all fields requiring date/time entry, use this format: yyyy-mm-ddThh:mm:ss.sssssss+tz:tz, e.g. 2006-06-19T21:40:00.0000000+10:00 for 19th June 2006 9:40:00.0000000 PM +10:00.", Namespace = "http://www.team-mediaportal.com/ECP2WebService/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class Service : System.Web.Services.WebService @@ -31,10 +31,9 @@ { string appPath = ""; - if (!System.IO.File.Exists(ECP2Assembly.MPHandler.ConfigFileName)) + if (!System.IO.File.Exists(Server.MapPath(@"config/ECP2Assembly.dll.config"))) { - throw new Exception(@"Could not access ECP2Assembly's config file expected at (" + ECP2Assembly.MPHandler.ConfigFileName + @") to get MP path."); - return false; + throw new Exception(@"Could not access ECP2Assembly's config file expected at (" + Server.MapPath(@"config/ECP2Assembly.dll.config") + @") to get MP path."); } System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); @@ -42,7 +41,7 @@ try { xmlDoc.Load(ECP2Assembly.MPHandler.ConfigFileName); - System.Xml.XmlNodeList xmlNodeList = xmlDoc.SelectNodes("configuration/appSettings/add[@key='MPPath']"); + System.Xml.XmlNodeList xmlNodeList = xmlDoc.SelectNodes(@"configuration/appSettings/add[@key='MPDirectory']"); if (xmlNodeList.Count > 0) { @@ -53,19 +52,16 @@ 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; + throw new Exception(@"Could not locate MediaPortal.exe based on MP path from ECP2Assembly's config file located at: " + ECP2Assembly.MPHandler.ConfigFileName); } } 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(@"\")); @@ -82,7 +78,6 @@ catch (Exception ex) { throw new Exception(@"ECP2 Web Service error: could not execute MediaPortal; inner exception: " + ex.ToString()); - return false; } } @@ -99,7 +94,7 @@ xwSettings.Indent = true; xwSettings.OmitXmlDeclaration = false; xwSettings.ConformanceLevel = System.Xml.ConformanceLevel.Auto; - + return xwSettings; } #endregion @@ -325,10 +320,10 @@ 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); + rec.RecType = (MediaPortal.TV.Database.TVRecording.RecordingType)Enum.Parse(typeof(MediaPortal.TV.Database.TVRecording.RecordingType), recType, true); + rec.KeepRecordingMethod = (MediaPortal.TV.Database.TVRecorded.KeepMethod)Enum.Parse(typeof(MediaPortal.TV.Database.TVRecorded.KeepMethod), keepMethod, true); - return GetEMPH().AddRecording(ref rec); + return GetEMPH().AddRecording(rec); } [WebMethod(Description = "This command tells MediaPortal to delete a particular recording by ID.")] @@ -442,12 +437,62 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } + [WebMethod(Description = "This command retrieves all the channels in the specified group ID in XML format.")] + public string GetChannelsByGroupID(int GroupID) + { + List<MediaPortal.TV.Database.TVChannel> chnList; + chnList = GetEMPH().GetChannels(GroupID); + + 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.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; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVChannels"); + + 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) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + [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); + if (chn == null) 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; @@ -500,6 +545,8 @@ List<string> genresList; genresList = GetEMPH().GetGenres(); + if (genresList.Count == 0) return ""; + System.IO.MemoryStream xwMem = new System.IO.MemoryStream(); System.Xml.XmlWriter xw = System.Xml.XmlWriter.Create(xwMem, GetXMLDocWriterSettings()); @@ -526,12 +573,14 @@ 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.")] + [WebMethod(Description="This command returns the list of TV programs within the given date boundaries in XML format.")] public string GetProgramsByDate(DateTime startDateTime, DateTime endDateTime) { List<MediaPortal.TV.Database.TVProgram> progList; progList = GetEMPH().GetPrograms(startDateTime,endDateTime); + if (progList.Count == 0) return ""; + 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 )); @@ -563,12 +612,53 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } + [WebMethod(Description = "This command returns the list of TV programs matching the specified genre in XML format.")] + public string GetProgramsByGenre(string GenreName) + { + List<MediaPortal.TV.Database.TVProgram> progList; + progList = GetEMPH().GetPrograms(GenreName); + + if (progList.Count == 0) return ""; + + 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++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + [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(); + if (progList.Count == 0) return ""; + 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 )); @@ -600,12 +690,14 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } - [WebMethod(Description="This command returns the list of TV program genres in XML format.")] + [WebMethod(Description="This command returns the list of TV programs on the specified channel and date/time boundaries 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); + if (progList.Count == 0) return ""; + 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 )); @@ -636,6 +728,322 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } + + [WebMethod(Description = "This command searches and returns the list of matching TV programs in XML format. The SearchField parameter can take: title, or description. The SearchType parameter can take: wildcardatend, wildcardatstartend, wildcardatstart, or exact. ChannelName can be left blank to search all channels.")] + public string GetProgramsBySearch(DateTime StartDateTime, DateTime EndDateTime, string SearchField, string SearchType, string SearchCriteria, string ChannelName) + { + List<MediaPortal.TV.Database.TVProgram> progList; + progList = GetEMPH().GetPrograms(StartDateTime, EndDateTime, SearchField, SearchType, SearchCriteria, ChannelName); + + if (progList.Count == 0) return ""; + + 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++) + { + prog = (MediaPortal.TV.Database.TVProgram)progList[i]; + xs.Serialize(xw, prog); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command adds a notification to the program matching the specified channel and start date/time.")] + public bool AddTVNotify(string ChannelName, DateTime StartDateTime) + { + if (ChannelName == null) + { + return false; + } + + if (ChannelName == "") + { + return false; + } + + return GetEMPH().AddTVNotify(ChannelName, StartDateTime); + } + + [WebMethod(Description = "This command deletes a notification to the program matching the specified channel and start date/time.")] + public bool DeleteTVNotifyByChannelNameAndStartDateTime(string ChannelName, DateTime StartDateTime) + { + if (ChannelName == null) + { + return false; + } + + if (ChannelName == "") + { + return false; + } + + return GetEMPH().DeleteTVNotify(ChannelName, StartDateTime); + } + + [WebMethod(Description = "This command deletes a notification to the program matching the specified notification ID.")] + public bool DeleteTVNotifyByID(int TVNotifyID) + { + return GetEMPH().DeleteTVNotify(TVNotifyID); + } + + [WebMethod(Description = "This command returns a list of all the program notifications in XML format.")] + public string GetAllTVNotifies() + { + List<MediaPortal.TV.Database.TVNotify> TVNotifyList; + TVNotifyList = GetEMPH().GetTVNotifies(); + + if (TVNotifyList.Count == 0) return ""; + + 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.TVNotify)); + MediaPortal.TV.Database.TVNotify notify; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVNotifies"); + + for (int i = 0; i <= TVNotifyList.Count - 1; i++) + { + notify = (MediaPortal.TV.Database.TVNotify)TVNotifyList[i]; + xs.Serialize(xw, notify); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves the specified program notification by TVNotifyID in XML format.")] + public string GetTVNotifyByTVNotifyID(int TVNotifyID) + { + MediaPortal.TV.Database.TVNotify notify; + notify = GetEMPH().GetTVNotify(TVNotifyID); + + if (notify == null) return ""; + + 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.TVNotify)); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVNotifies"); + + xs.Serialize(xw, notify); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves the specified program notification by channel name and start date/time in XML format.")] + public string GetTVNotifyByChannelNameAndStartDateTime(string ChannelName, DateTime StartDateTime) + { + MediaPortal.TV.Database.TVNotify notify; + notify = GetEMPH().GetTVNotify(ChannelName,StartDateTime); + + if (notify == null) return ""; + + 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.TVNotify)); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVNotifies"); + + xs.Serialize(xw, notify); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves all the TV channel groups in XML format.")] + public string GetTVGroups() + { + List<MediaPortal.TV.Database.TVGroup> TVGroupList; + TVGroupList = GetEMPH().GetTVGroups(); + + if (TVGroupList.Count == 0) return ""; + + // As channels is not wanted (too much info - can use GetChannels function for channels), 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.TVGroup), "TvChannels", 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.TVGroup), xmlOverrides); + MediaPortal.TV.Database.TVGroup group; + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVGroups"); + + for (int i = 0; i <= TVGroupList.Count - 1; i++) + { + group = (MediaPortal.TV.Database.TVGroup)TVGroupList[i]; + xs.Serialize(xw, group); + } + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves the specified TV channel group by group ID in XML format.")] + public string GetTVGroupByGroupID(int GroupID) + { + MediaPortal.TV.Database.TVGroup group; + group = GetEMPH().GetTVGroup(GroupID); + + if (group == null) return ""; + + // As channels is not wanted (too much info - can use GetChannels function for channels), 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.TVGroup), "TvChannels", 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.TVGroup), xmlOverrides); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVGroups"); + + xs.Serialize(xw, group); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + + [WebMethod(Description = "This command retrieves the specified TV channel group by group name in XML format.")] + public string GetTVGroupByGroupName(string GroupName) + { + MediaPortal.TV.Database.TVGroup group; + group = GetEMPH().GetTVGroup(GroupName); + + if (group == null) return ""; + + // As channels is not wanted (too much info - can use GetChannels function for channels), 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.TVGroup), "TvChannels", 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.TVGroup), xmlOverrides); + + try + { + xw.WriteStartDocument(); + xw.WriteStartElement("MPData"); + xw.WriteStartElement("TVGroups"); + + xs.Serialize(xw, group); + + xw.WriteEndElement(); + xw.WriteEndElement(); + xw.WriteEndDocument(); + + xw.Flush(); + } + catch (Exception ex) + { + return ex.ToString(); + } + + return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); + } + #endregion #region recorded TV commands This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |