From: <sam...@us...> - 2006-05-24 09:26:27
|
Revision: 5 Author: samuel337 Date: 2006-05-24 02:25:46 -0700 (Wed, 24 May 2006) ViewCVS: http://svn.sourceforge.net/mp-webinterface/?rev=5&view=rev Log Message: ----------- Added exclusion folders (e.g. bin and obj folders) so they don't get uploaded to SVN. Modified Paths: -------------- trunk/source/MPW.sln trunk/source/MPW.suo trunk/source/MPWApplication/MPWApplication.csproj Property Changed: ---------------- trunk/source/ECP2Assembly/bin/ trunk/source/ECP2Assembly/obj/ trunk/source/ECP2Plugin/bin/ trunk/source/ECP2Plugin/obj/ trunk/source/ECP2WebService/Bin/ trunk/source/MPWApplication/bin/ trunk/source/MPWApplication/obj/ trunk/source/MPWPathFix/bin/ trunk/source/MPWPathFix/obj/ Property changes on: trunk/source/ECP2Assembly/bin ___________________________________________________________________ Name: svn:ignore + Debug Release Property changes on: trunk/source/ECP2Assembly/obj ___________________________________________________________________ Name: svn:ignore + Debug Release ECP2Assembly.csproj.FileList.txt Property changes on: trunk/source/ECP2Plugin/bin ___________________________________________________________________ Name: svn:ignore + Debug Release Property changes on: trunk/source/ECP2Plugin/obj ___________________________________________________________________ Name: svn:ignore + Debug Release Property changes on: trunk/source/ECP2WebService/Bin ___________________________________________________________________ Name: svn:ignore + AxInterop.MOZILLACONTROLLib.dll AxInterop.WMPLib.dll Communications.dll Core.dll Core.pdb Databases.dll Databases.pdb Dialogs.dll Dialogs.pdb DirectShowLib.dll DirectShowLib.pdb ECP2Assembly.dll ECP2Assembly.pdb edtftpnet-1.2.2.dll ICSharpCode.SharpZipLib.dll Interop.MOZILLACONTROLLib.dll Interop.TunerLib.dll Interop.WMPLib.dll KCS.Utilities.dll MediaPortal.Support.dll MediaPortal.Support.pdb TVCapture.dll TVCapture.pdb Utils.dll Utils.pdb WebEPG.dll WebEPG.pdb WindowPlugins.dll WindowPlugins.pdb X10Unified.dll xAPMessage.dll xAPTransport.dll XihSolutions.DotMSN.dll Modified: trunk/source/MPW.sln =================================================================== --- trunk/source/MPW.sln 2006-05-23 12:33:12 UTC (rev 4) +++ trunk/source/MPW.sln 2006-05-24 09:25:46 UTC (rev 5) @@ -11,6 +11,7 @@ EndProject Project("{E24C65DC-7377-472B-9ABA-BC803B73C61A}") = "C:\...\ECP2WebService\", "ECP2WebService\", "{D3032E9F-FA75-4898-897F-D8182A2DF9FC}" ProjectSection(WebsiteProperties) = preProject + ProjectReferences = "{718EDE2B-7FB8-4C40-8D32-0EED5C289B0F}|ECP2Assembly.dll;" Debug.AspNetCompiler.VirtualPath = "/ECP2WebService" Debug.AspNetCompiler.PhysicalPath = "ECP2WebService\" Debug.AspNetCompiler.TargetPath = "PrecompiledWeb\ECP2WebService\" Modified: trunk/source/MPW.suo =================================================================== (Binary files differ) Modified: trunk/source/MPWApplication/MPWApplication.csproj =================================================================== --- trunk/source/MPWApplication/MPWApplication.csproj 2006-05-23 12:33:12 UTC (rev 4) +++ trunk/source/MPWApplication/MPWApplication.csproj 2006-05-24 09:25:46 UTC (rev 5) @@ -91,10 +91,10 @@ <WebReferences Include="Web References\" /> </ItemGroup> <ItemGroup> - <WebReferenceUrl Include="http://localhost/ECP2WebService/service.asmx"> + <WebReferenceUrl Include="http://localhost:4452/ECP2WebService/Service.asmx"> <UrlBehavior>Dynamic</UrlBehavior> <RelPath>Web References\ECP2WebService\</RelPath> - <UpdateFromURL>http://localhost/ECP2WebService/service.asmx</UpdateFromURL> + <UpdateFromURL>http://localhost:4452/ECP2WebService/Service.asmx</UpdateFromURL> <ServiceLocationURL> </ServiceLocationURL> <CachedDynamicPropName> Property changes on: trunk/source/MPWApplication/bin ___________________________________________________________________ Name: svn:ignore + Debug Release Property changes on: trunk/source/MPWApplication/obj ___________________________________________________________________ Name: svn:ignore + Release MPWApplication.csproj.FileList.txt Debug Property changes on: trunk/source/MPWPathFix/bin ___________________________________________________________________ Name: svn:ignore + Debug Release Property changes on: trunk/source/MPWPathFix/obj ___________________________________________________________________ Name: svn:ignore + Debug Release This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sam...@us...> - 2006-08-13 12:40:33
|
Revision: 17 Author: samuel337 Date: 2006-08-13 05:40:07 -0700 (Sun, 13 Aug 2006) ViewCVS: http://svn.sourceforge.net/mp-webinterface/?rev=17&view=rev Log Message: ----------- Fixed minor bug in LaunchMP function in WS; updated setup scripts and files Modified Paths: -------------- trunk/MPWebControl Setup Project/compress MPWebControl.bat trunk/MPWebControl Setup Project/install generation checklist.txt trunk/MPWebControl Setup Project/readme.txt trunk/MPWebControl Setup Project/setup.iss trunk/source/ECP2Plugin/ECP2Plugin.csproj trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs trunk/source/ECP2WebService/App_Code/Service.cs trunk/source/ECP2WebService/Web.config trunk/source/MPW.suo Modified: trunk/MPWebControl Setup Project/compress MPWebControl.bat =================================================================== --- trunk/MPWebControl Setup Project/compress MPWebControl.bat 2006-06-19 12:31:08 UTC (rev 16) +++ trunk/MPWebControl Setup Project/compress MPWebControl.bat 2006-08-13 12:40:07 UTC (rev 17) @@ -1 +1 @@ -"c:\Program Files\7-Zip\7z" a -t7z -mx=7 -sfx"C:\Program Files\7-Zip\7zCon.sfx" ".\MPWebControl.exe" ".\MPWebControl\*" \ No newline at end of file +"c:\Program Files\7-Zip\7z" a -t7z -mx=7 -sfx"C:\Program Files\7-Zip\7zCon.sfx" -i!"MPWebControl\*" -xr!*\.svn\* ".\MPWebControl.exe" \ No newline at end of file Modified: trunk/MPWebControl Setup Project/install generation checklist.txt =================================================================== --- trunk/MPWebControl Setup Project/install generation checklist.txt 2006-06-19 12:31:08 UTC (rev 16) +++ trunk/MPWebControl Setup Project/install generation checklist.txt 2006-08-13 12:40:07 UTC (rev 17) @@ -2,6 +2,7 @@ - remove all MP assemblies from MPECP2WS's bin folder except DirectShowLib.dll (for GetChannel functions) - ensure latest versions of webscheduler, MPECP2WS, MPWApplication and MPWPathFix are in the MPWebControl folder - ensure httpd,conf, ssl,conf, php.ini, ECP2Assembly.dll.config have the PathFix variables in them +- swap over web.config in MPExtControlWS for release version? - compress MPWebControl using batch file (requires 7-Zip) - update readme file - build setup using Inno Setup 5.1.5 (check version details) Modified: trunk/MPWebControl Setup Project/readme.txt =================================================================== --- trunk/MPWebControl Setup Project/readme.txt 2006-06-19 12:31:08 UTC (rev 16) +++ trunk/MPWebControl Setup Project/readme.txt 2006-08-13 12:40:07 UTC (rev 17) @@ -1,6 +1,10 @@ -MediaPortal Webinterface by Maschine and Sam - Release 4 -======================================================== +MediaPortal Webinterface by Maschine and Sam - Release 5 Beta +============================================================= +The readme file below has not been edited for this new version - please ignore. + +------------------------------------------------------------------------------- + PLEASE NOTE: This release only works with MP 0.1.0.10 or above as the TVDatabase has changed. ALSO PLEASE NOTE: The default port has changed from port 80 to port 81. Therefore, to access the web interface, you need to goto http://<MP computer name>:81/ , e.g. if the MP computer name was MPComputer, then you would go to http://MPComputer:81 for the web interface. Modified: trunk/MPWebControl Setup Project/setup.iss =================================================================== --- trunk/MPWebControl Setup Project/setup.iss 2006-06-19 12:31:08 UTC (rev 16) +++ trunk/MPWebControl Setup Project/setup.iss 2006-08-13 12:40:07 UTC (rev 17) @@ -10,7 +10,7 @@ [Dirs] Name: {app}\MPWebControl [Run] -Filename: {app}\MPWebControl\MPWebControl.exe; WorkingDir: {app}\MPWebControl; StatusMsg: Extracting MediaPortal Web Control Files...; Flags: runminimized +Filename: {app}\MPWebControl\MPWebControl.exe; WorkingDir: {app}; StatusMsg: Extracting MediaPortal Web Control Files...; Flags: runminimized Filename: {app}\MPWebControl\passwordconfig.bat; WorkingDir: {app}\MPWebControl; StatusMsg: Adding password security to web server config file...; Flags: runminimized; Tasks: usepassword Filename: {app}\MPWebControl\resetpwd.bat; WorkingDir: {app}\MPWebControl; StatusMsg: Setting MP web interface security...; Tasks: usepassword; Flags: runmaximized Filename: {app}\MPWebControl\MPWPathFix.exe; Parameters: 81; WorkingDir: {app}\MPWebControl; StatusMsg: Configuring web server configuration files...; Flags: runminimized @@ -25,7 +25,7 @@ ReadyMemoDir=MediaPortal location: ConfirmUninstall=Are you sure you want to completely remove %1 and all of its components? Note that all files in the MPWebControl folder will be removed - so any changes would be lost (e.g. any alternate tv logos). [Setup] -OutputDir=C:\Documents and Settings\Sam\Desktop\MediaPortal stuff\MPWebControl Setup Project\Final +OutputDir=C:\Documents and Settings\Sam\Desktop\MediaPortal stuff\MPW\trunk\MPWebControl Setup Project\Final VersionInfoVersion=1.5.0 VersionInfoCompany=Maschine & Sam VersionInfoDescription=MediaPortal Web-Interface R5 Beta Modified: trunk/source/ECP2Plugin/ECP2Plugin.csproj =================================================================== --- trunk/source/ECP2Plugin/ECP2Plugin.csproj 2006-06-19 12:31:08 UTC (rev 16) +++ trunk/source/ECP2Plugin/ECP2Plugin.csproj 2006-08-13 12:40:07 UTC (rev 17) @@ -32,10 +32,6 @@ <SpecificVersion>False</SpecificVersion> <HintPath>..\..\..\..\MediaPortal Source\mediaportal\Core\bin\Debug\Core.dll</HintPath> </Reference> - <Reference Include="ECP2Assembly, Version=1.1.2.43068, Culture=neutral, processorArchitecture=MSIL"> - <SpecificVersion>False</SpecificVersion> - <HintPath>..\..\ECP2Assembly\ECP2Assembly\bin\Debug\ECP2Assembly.dll</HintPath> - </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Drawing" /> @@ -61,6 +57,12 @@ <DependentUpon>frmSetup.cs</DependentUpon> </EmbeddedResource> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\ECP2Assembly\ECP2Assembly.csproj"> + <Project>{718EDE2B-7FB8-4C40-8D32-0EED5C289B0F}</Project> + <Name>ECP2Assembly</Name> + </ProjectReference> + </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <!-- To modify your build process, add your task inside one of the targets below and uncomment it. Other similar extension points exist, see Microsoft.Common.targets. Modified: trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs =================================================================== --- trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs 2006-06-19 12:31:08 UTC (rev 16) +++ trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs 2006-08-13 12:40:07 UTC (rev 17) @@ -31,5 +31,5 @@ // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.1.2.*")] -[assembly: AssemblyFileVersion("1.1.2.*")] +[assembly: AssemblyVersion("1.1.2.0")] +[assembly: AssemblyFileVersion("1.1.2.0")] Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-06-19 12:31:08 UTC (rev 16) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-08-13 12:40:07 UTC (rev 17) @@ -40,7 +40,7 @@ try { - xmlDoc.Load(ECP2Assembly.MPHandler.ConfigFileName); + xmlDoc.Load(Server.MapPath(@"config/ECP2Assembly.dll.config")); System.Xml.XmlNodeList xmlNodeList = xmlDoc.SelectNodes(@"configuration/appSettings/add[@key='MPDirectory']"); if (xmlNodeList.Count > 0) Modified: trunk/source/ECP2WebService/Web.config =================================================================== --- trunk/source/ECP2WebService/Web.config 2006-06-19 12:31:08 UTC (rev 16) +++ trunk/source/ECP2WebService/Web.config 2006-08-13 12:40:07 UTC (rev 17) @@ -27,7 +27,8 @@ <add assembly="System.Management, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> <add assembly="Microsoft.VisualC, Version=8.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> - <add assembly="System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation> + <add assembly="System.ServiceProcess, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/> + <add assembly="Microsoft.mshtml, Version=7.0.3300.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/></assemblies></compilation> <!-- The <authentication> section enables configuration of the security authentication mode used by Modified: trunk/source/MPW.suo =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sam...@us...> - 2006-09-09 17:41:37
|
Revision: 19 http://svn.sourceforge.net/mp-webinterface/?rev=19&view=rev Author: samuel337 Date: 2006-09-09 10:41:13 -0700 (Sat, 09 Sep 2006) Log Message: ----------- added coverart features, alternate RemovePlaylistItem method, fixed asynchronous usage bugs, updated Playlist & music methods, plus more that I can't remember ;-) Modified Paths: -------------- trunk/source/ECP2Assembly/AssemblySettings.cs trunk/source/ECP2Assembly/clsMPHandler.cs trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs trunk/source/ECP2Plugin/clsMain.cs trunk/source/ECP2WebService/App_Code/Service.cs Added Paths: ----------- trunk/source/ECP2Assembly/clsCustomMPObjects.cs trunk/source/ECP2WebService/CoverArtHandler.ashx Modified: trunk/source/ECP2Assembly/AssemblySettings.cs =================================================================== --- trunk/source/ECP2Assembly/AssemblySettings.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2Assembly/AssemblySettings.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -47,29 +47,32 @@ //initialize the apps config file, create it if it doesn't exist private void InitializeConfigFile(string configFileName) { - //if the file name that was passed is blank, then run another overloaded method - if (configFileName == null) + lock (this) { - InitializeConfigFile(); - return; - } + //if the file name that was passed is blank, then run another overloaded method + if (configFileName == null) + { + InitializeConfigFile(); + return; + } - _configFileName = configFileName; + _configFileName = configFileName; - //if the file doesn't exist, create a blank xml - if (!System.IO.File.Exists(_configFileName)) - { - System.IO.StreamWriter fn = new System.IO.StreamWriter(System.IO.File.Open(_configFileName, System.IO.FileMode.Create)); - fn.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?>"); - fn.WriteLine(@"<configuration>"); - fn.WriteLine(@" <appSettings>"); - fn.WriteLine(@" <!-- User application and configured property settings go here.-->"); - fn.WriteLine(@" <!-- Example: <add key=""settingName"" value=""settingValue""/> -->"); - fn.WriteLine(@" <add key=""MPComputerAddress"" value=""localhost"" />"); - fn.WriteLine(@" <add key=""MPDirectory"" value="""" />"); - fn.WriteLine(@" </appSettings>"); - fn.WriteLine(@"</configuration>"); - fn.Close(); //all done + //if the file doesn't exist, create a blank xml + if (!System.IO.File.Exists(_configFileName)) + { + System.IO.StreamWriter fn = new System.IO.StreamWriter(System.IO.File.Open(_configFileName, System.IO.FileMode.Create)); + fn.WriteLine(@"<?xml version=""1.0"" encoding=""utf-8""?>"); + fn.WriteLine(@"<configuration>"); + fn.WriteLine(@" <appSettings>"); + fn.WriteLine(@" <!-- User application and configured property settings go here.-->"); + fn.WriteLine(@" <!-- Example: <add key=""settingName"" value=""settingValue""/> -->"); + fn.WriteLine(@" <add key=""MPComputerAddress"" value=""localhost"" />"); + fn.WriteLine(@" <add key=""MPDirectory"" value="""" />"); + fn.WriteLine(@" </appSettings>"); + fn.WriteLine(@"</configuration>"); + fn.Close(); //all done + } } } @@ -97,58 +100,62 @@ } //save an application setting, takes a key and a value - public void SaveSetting(string key, string value) - { - //xml document object - System.Xml.XmlDocument xd = new System.Xml.XmlDocument(); + public void SaveSetting(string key, string value) + { + lock (this) + { - //load the xml file - xd.Load(_configFileName); + //xml document object + System.Xml.XmlDocument xd = new System.Xml.XmlDocument(); - //get the value - System.Xml.XmlElement Node = (System.Xml.XmlElement)xd.DocumentElement.SelectSingleNode(@"/configuration/appSettings/add[@key=""" + key + @"""]"); - if (!(Node==null)) - { - //key found, set the value - Node.Attributes.GetNamedItem("value").Value = value; - } - else - { - //key not found, create it - Node = xd.CreateElement("add"); - Node.SetAttribute("key", key); - Node.SetAttribute("value", value); + //load the xml file + xd.Load(_configFileName); - //look for the appsettings node - System.Xml.XmlNode Root = xd.DocumentElement.SelectSingleNode(@"/configuration/appSettings"); - - //add the new child node (this key) - if (!(Root==null)) - { - Root.AppendChild(Node); - } - else - { - try + //get the value + System.Xml.XmlElement Node = (System.Xml.XmlElement)xd.DocumentElement.SelectSingleNode(@"/configuration/appSettings/add[@key=""" + key + @"""]"); + if (!(Node == null)) { - //appsettings node didn't exist, add it before adding the new child - Root = xd.DocumentElement.SelectSingleNode("/configuration"); - Root.AppendChild(xd.CreateElement("appSettings")); - Root = xd.DocumentElement.SelectSingleNode("/configuration/appSettings"); - Root.AppendChild(Node); + //key found, set the value + Node.Attributes.GetNamedItem("value").Value = value; } - catch (Exception ex) + else { - //failed adding node, throw an error - throw new Exception("Could not set value", ex); + //key not found, create it + Node = xd.CreateElement("add"); + Node.SetAttribute("key", key); + Node.SetAttribute("value", value); + + //look for the appsettings node + System.Xml.XmlNode Root = xd.DocumentElement.SelectSingleNode(@"/configuration/appSettings"); + + //add the new child node (this key) + if (!(Root == null)) + { + Root.AppendChild(Node); + } + else + { + try + { + //appsettings node didn't exist, add it before adding the new child + Root = xd.DocumentElement.SelectSingleNode("/configuration"); + Root.AppendChild(xd.CreateElement("appSettings")); + Root = xd.DocumentElement.SelectSingleNode("/configuration/appSettings"); + Root.AppendChild(Node); + } + catch (Exception ex) + { + //failed adding node, throw an error + throw new Exception("Could not set value", ex); + } + } } + + //finally, save the new version of the config file + xd.Save(_configFileName); } } - //finally, save the new version of the config file - xd.Save(_configFileName); - } - } } \ No newline at end of file Added: trunk/source/ECP2Assembly/clsCustomMPObjects.cs =================================================================== --- trunk/source/ECP2Assembly/clsCustomMPObjects.cs (rev 0) +++ trunk/source/ECP2Assembly/clsCustomMPObjects.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -0,0 +1,204 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ECP2Assembly.CustomMPObjects +{ + [Serializable()] + public class MusicArtist + { + private int m_artistID; + private string m_artistName; + //private MediaPortal.Music.Database.ArtistInfo m_artistInfo; + + + public MusicArtist() + { + + } + + public int ArtistID + { + get + { + return m_artistID; + } + set + { + m_artistID = value; + } + } + + public string ArtistName + { + get + { + return m_artistName; + } + set + { + m_artistName = value; + } + } + + //public MediaPortal.Music.Database.ArtistInfo ArtistInfo + //{ + // get + // { + // return m_artistInfo; + // } + // set + // { + // m_artistInfo = value; + // } + //} + } + + [Serializable()] + public class MusicAlbum + { + private int m_albumID; + private string m_albumName; + private int m_artistID; + private int m_numOfArtists; + //private MediaPortal.Music.Database.AlbumInfo m_albumInfo; + + + public MusicAlbum() + { + + } + + public int AlbumID + { + get + { + return m_albumID; + } + set + { + m_albumID = value; + } + } + + public string AlbumName + { + get + { + return m_albumName; + } + set + { + m_albumName = value; + } + } + + public int ArtistID + { + get + { + return m_artistID; + } + set + { + m_artistID = value; + } + } + + public int NumOfArtists + { + get + { + return m_numOfArtists; + } + set + { + m_numOfArtists = value; + } + } + + //public MediaPortal.Music.Database.AlbumInfo AlbumInfo + //{ + // get + // { + // return m_albumInfo; + // } + // set + // { + // m_albumInfo = value; + // } + //} + } + + [Serializable()] + public class MusicGenre + { + private int m_genreID; + private string m_genreName; + + public MusicGenre() + { + + } + + public int GenreID + { + get + { + return m_genreID; + } + set + { + m_genreID = value; + } + } + + public string GenreName + { + get + { + return m_genreName; + } + set + { + m_genreName = value; + } + } + } + + [Serializable()] + public class PlayList + { + private string m_PlayListName; + private List<MediaPortal.Playlists.PlayListItem> m_PlayListItems; + + public PlayList() + { + m_PlayListItems = new List<MediaPortal.Playlists.PlayListItem>(); + } + + public string PlayListName + { + get + { + return m_PlayListName; + } + set + { + m_PlayListName = value; + } + } + + public List<MediaPortal.Playlists.PlayListItem> PlayListItems + { + get + { + return m_PlayListItems; + } + set + { + m_PlayListItems = value; + } + } + } +} Modified: trunk/source/ECP2Assembly/clsMPHandler.cs =================================================================== --- trunk/source/ECP2Assembly/clsMPHandler.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2Assembly/clsMPHandler.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -312,48 +312,48 @@ public object GetgPlayerProps(string PropName) { - switch(PropName) + switch(PropName.ToLower()) { - case "CurrentFile": + case "currentfile": return MediaPortal.Player.g_Player.CurrentFile; - case "CurrentPosition": + case "currentposition": return MediaPortal.Player.g_Player.CurrentPosition; - case "Duration": + case "duration": return MediaPortal.Player.g_Player.Duration; - case "FullScreen": + case "fullscreen": return MediaPortal.Player.g_Player.FullScreen; - case "HasVideo": + case "hasvideo": return MediaPortal.Player.g_Player.HasVideo; - case "IsDVD": + case "isdvd": return MediaPortal.Player.g_Player.IsDVD; - case "IsRadio": + case "isradio": return MediaPortal.Player.g_Player.IsRadio; - case "IsTV": + case "istv": return MediaPortal.Player.g_Player.IsTV; - case "IsVideo": + case "isvideo": return MediaPortal.Player.g_Player.IsVideo; - case "Paused": + case "paused": return MediaPortal.Player.g_Player.Paused; - case "Playing": + case "playing": return MediaPortal.Player.g_Player.Playing; - case "Speed": + case "speed": return MediaPortal.Player.g_Player.Speed; - case "Stopped": + case "stopped": return MediaPortal.Player.g_Player.Stopped; - case "Volume": + case "volume": return MediaPortal.Player.g_Player.Volume; //if not one of the currently defined ones, use reflection to find it @@ -1023,7 +1023,7 @@ #region Playlist commands - public string CurrentPlaylistName + public string CurrentPlaylistType { get { @@ -1031,7 +1031,7 @@ } } - public int CurrentSongNo + public int CurrentItemNo { get { @@ -1058,7 +1058,20 @@ for (int i = 0; i < pl.Count; i++) { - ECP2PlayList.PlayListItems.Add(pl[i]); + //make a copy of the playlist item so it doesn't affect the actual playlist + MediaPortal.Playlists.PlayListItem OriginalPli; + MediaPortal.Playlists.PlayListItem NewPli; + OriginalPli = pl[i]; + NewPli = new MediaPortal.Playlists.PlayListItem(); + + NewPli.Description = OriginalPli.Description; + NewPli.Duration = OriginalPli.Duration; + NewPli.FileName = OriginalPli.FileName; + NewPli.Played = OriginalPli.Played; + NewPli.Type = OriginalPli.Type; + //ignore the MusicTag property as it can't be serialized properly + + ECP2PlayList.PlayListItems.Add(NewPli); } return ECP2PlayList; @@ -1138,14 +1151,31 @@ return false; } - public bool PlayPlaylistItem(MediaPortal.Playlists.PlayListType playlistType, int songNum) + public bool RemovePlaylistItem(MediaPortal.Playlists.PlayListType playlistType, int itemNum) { + MediaPortal.Playlists.PlayList pl = MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.GetPlaylist(playlistType); + + if (pl == null) { return false; } + + if (itemNum >= pl.Count){ return false; } + + if (pl.Remove(pl[itemNum].FileName) > 0) + { + return true; + } + + return false; + } + + //has bugs - COM call related - FIX ASAP! + public bool PlayPlaylistItem(MediaPortal.Playlists.PlayListType playlistType, int itemNum) + { if (playlistType != MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.CurrentPlaylistType) { MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.CurrentPlaylistType = playlistType; } - MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.Play(songNum); + MediaPortal.Playlists.PlayListPlayer.SingletonPlayer.Play(itemNum); return true; } @@ -1820,6 +1850,105 @@ return albumList; } + + public byte[] GetCoverArtForSong(int SongID) + { + //get song + MediaPortal.Music.Database.Song song = GetSong(SongID); + if (song == null) + { + return null; + } + + return GetCoverArtForSong(song); + } + + public byte[] GetCoverArtForSong(MediaPortal.Music.Database.Song song) + { + //build MusicTag + MediaPortal.TagReader.MusicTag tag = new MediaPortal.TagReader.MusicTag(); + tag.Album = song.Album; + tag.Artist = song.Artist; + tag.Duration = song.Duration; + tag.Genre = song.Genre; + tag.Rating = song.Rating; + tag.TimesPlayed = song.TimesPlayed; + tag.Title = song.Title; + tag.Track = song.Track; + tag.Year = song.Year; + + string artFilename = string.Empty ; + artFilename = MediaPortal.GUI.Music.GUIMusicFiles.GetCoverArt(false, song.FileName, tag); + + if (artFilename == string.Empty) + { + //get default icons + //make GUIListItem to get default icons (no other method available) + MediaPortal.GUI.Library.GUIListItem listItem = new GUIListItem(); + listItem.IsFolder = false; + listItem.Label = "dummy listItem to get default icons"; + listItem.Path = song.FileName; + MediaPortal.Util.Utils.SetDefaultIcons(listItem); + + artFilename = listItem.IconImageBig; + } + + //get absolute path if needed + artFilename= System.IO.Path.GetFullPath(artFilename); + + if (System.IO.File.Exists(artFilename)) + { + //turn file into byte array via fileStream as System.Drawing.Image has serialization issues + System.IO.FileStream fs = new System.IO.FileStream(artFilename, System.IO.FileMode.Open); + byte[] artFile = new byte[fs.Length]; + fs.Read(artFile, 0, (int)fs.Length); + fs.Close(); + fs.Dispose(); + return artFile; + } + + return null; + } + + public byte[] GetCoverArtForFolder(string path) + { + if (!System.IO.Directory.Exists(path)) + { + return null; + } + + string artFilename = string.Empty; + artFilename = MediaPortal.GUI.Music.GUIMusicFiles.GetCoverArt(true, path, null); + + if (artFilename == string.Empty) + { + //get default icons + //make GUIListItem to get default icons (no other method available) + MediaPortal.GUI.Library.GUIListItem listItem = new GUIListItem(); + listItem.IsFolder = true; + listItem.Label = "dummy listItem to get default icons"; + listItem.Path = path; + MediaPortal.Util.Utils.SetDefaultIcons(listItem); + + artFilename = listItem.IconImageBig; + } + + //get absolute path if needed + artFilename = System.IO.Path.GetFullPath(artFilename); + + if (System.IO.File.Exists(artFilename)) + { + //turn file into byte array via fileStream as System.Drawing.Image has serialization issues + System.IO.FileStream fs = new System.IO.FileStream(artFilename, System.IO.FileMode.Open); + byte[] artFile = new byte[fs.Length]; + fs.Read(artFile, 0, (int)fs.Length); + fs.Close(); + fs.Dispose(); + return artFile; + } + + return null; + } #endregion #region Volume commands @@ -1858,7 +1987,7 @@ } #endregion - #region ECP2 Version commands +#region ECP2 Version commands public string MPECP2Version { get Modified: trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs =================================================================== --- trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2Plugin/Properties/AssemblyInfo.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -31,5 +31,5 @@ // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("1.1.2.0")] -[assembly: AssemblyFileVersion("1.1.2.0")] +[assembly: AssemblyVersion("1.1.2.1")] +[assembly: AssemblyFileVersion("1.1.2.1")] Modified: trunk/source/ECP2Plugin/clsMain.cs =================================================================== --- trunk/source/ECP2Plugin/clsMain.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2Plugin/clsMain.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -17,21 +17,23 @@ void MediaPortal.GUI.Library.IPlugin.Start() { - //define HTTPchannel and setup remoting - System.Runtime.Remoting.RemotingConfiguration.Configure("MediaPortal.exe.config", false); - System.Runtime.Remoting.Channels.Tcp.TcpServerChannel channel = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel("MediaPortal ECP2", 3334, new ServerActivitySinkProvider()); - System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false); - System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(ECP2Assembly.MPHandler), "MPHandler", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); - System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(ECP2Assembly.MPLaunchInfo), "MPLaunchInfo", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); + //define HTTPchannel and setup remoting + System.Runtime.Remoting.RemotingConfiguration.Configure("MediaPortal.exe.config", false); + //turn to RemoteOnly for production version! + System.Runtime.Remoting.RemotingConfiguration.CustomErrorsMode = System.Runtime.Remoting.CustomErrorsModes.Off; + System.Runtime.Remoting.Channels.Tcp.TcpServerChannel channel = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel("MediaPortal ECP2", 3334, new ServerActivitySinkProvider()); + System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(channel, false); + System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(ECP2Assembly.MPHandler), "MPHandler", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); + System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(ECP2Assembly.MPLaunchInfo), "MPLaunchInfo", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); - //get settings - MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings("mediaportal.xml"); - shutdownDelay = MPSettings.GetValueAsInt("ECP2", "ShutdownDelay", 10); + //get settings + MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings("mediaportal.xml"); + shutdownDelay = MPSettings.GetValueAsInt("ECP2", "ShutdownDelay", 10); - ResetLastActivityTime(); + ResetLastActivityTime(); - MediaPortal.GUI.Library.Log.Write("ECP2: Remoting initialised."); - } + MediaPortal.GUI.Library.Log.Write("ECP2: Remoting initialised."); + } void MediaPortal.GUI.Library.IPlugin.Stop() { Modified: trunk/source/ECP2WebService/App_Code/Service.cs =================================================================== --- trunk/source/ECP2WebService/App_Code/Service.cs 2006-08-19 17:27:28 UTC (rev 18) +++ trunk/source/ECP2WebService/App_Code/Service.cs 2006-09-09 17:41:13 UTC (rev 19) @@ -1142,16 +1142,16 @@ #endregion #region playlist commands - [WebMethod(Description="This command returns the name of the current playlist.")] + [WebMethod(Description="This command returns the type of the current playlist.")] public string GetCurrentPlaylistName() { - return GetEMPH().CurrentPlaylistName; + return GetEMPH().CurrentPlaylistType; } - [WebMethod(Description="This command returns song number that's currently playing in the current playlist.")] + [WebMethod(Description="This command returns the item number that's currently playing in the current playlist.")] public int GetCurrentSongNo() { - return GetEMPH().CurrentSongNo; + return GetEMPH().CurrentItemNo ; } [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.")] @@ -1214,7 +1214,7 @@ return System.Text.Encoding.UTF8.GetString(xwMem.ToArray()); } - [WebMethod(Description="This command adds an item to the nominated playlist.")] + [WebMethod(Description = "This command adds an item to the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] public bool AddPlaylistItem(string playlistType, string fileName, string description, int duration, string itemType) { if (fileName=="") {return false;} @@ -1241,7 +1241,7 @@ return GetEMPH().AddPlaylistItem(playlistTypeResolve,fileName,description,duration,itemTypeResolve); } - [WebMethod(Description="This command adds an item to the nominated playlist.")] + [WebMethod(Description = "This command adds an item to the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] public bool AddPlaylistItemUsingDB(string playlistType, string itemType, string fileName) { if (fileName=="") {return false;} @@ -1267,8 +1267,8 @@ return GetEMPH().AddPlaylistItem(playlistTypeResolve,itemTypeResolve,fileName ); } - [WebMethod(Description="This command removes an item from the nominated playlist.")] - public bool RemovePlaylistItem(string playlistType, string fileName) + [WebMethod(Description = "This command removes an item from the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] + public bool RemovePlaylistItemByFileName(string playlistType, string fileName) { if (fileName=="") {return false;} @@ -1284,7 +1284,22 @@ return GetEMPH().RemovePlaylistItem(playlistTypeResolve,fileName); } - [WebMethod(Description="This command plays an item from the nominated playlist.")] + [WebMethod(Description = "This command removes an item specified by its location in the playlist from the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] + public bool RemovePlaylistItem(string playlistType, int itemNum) + { + //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().RemovePlaylistItem(playlistTypeResolve,itemNum); + } + + [WebMethod(Description = "This command plays an item from the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] public bool PlayPlaylistItem(string playlistType, int songNum) { //resolve playlistType @@ -1299,8 +1314,8 @@ return GetEMPH().PlayPlaylistItem(playlistTypeResolve,songNum); } - [WebMethod(Description="This command clears a playlist.")] - public bool ClearPlaylistItem(string playlistType) + [WebMethod(Description = "This command clears the nominated playlist (PLAYLIST_MUSIC, PLAYLIST_MUSIC_TEMP, PLAYLIST_VIDEO, PLAYLIST_VIDEO_TEMP).")] + public bool ClearPlaylist(string playlistType) { //resolve playlistType MediaPortal.Playlists.PlayListType playlistTypeResolve; Added: trunk/source/ECP2WebService/CoverArtHandler.ashx =================================================================== --- trunk/source/ECP2WebService/CoverArtHandler.ashx (rev 0) +++ trunk/source/ECP2WebService/CoverArtHandler.ashx 2006-09-09 17:41:13 UTC (rev 19) @@ -0,0 +1,125 @@ +<%@ WebHandler Language="C#" Class="ECP2WebService.CoverArtHandler" %> + +using System; +using System.Web; + +namespace ECP2WebService +{ + public class CoverArtHandler : IHttpHandler + { + + public ECP2Assembly.MPHandler GetEMPH() + { + ECP2Assembly.MPHandler.ConfigFileName = System.Web.HttpRuntime.AppDomainAppPath + "config" + System.IO.Path.DirectorySeparatorChar + "ECP2Assembly.dll.config"; + ECP2Assembly.MPHandler.MPComputerName = System.Configuration.ConfigurationManager.AppSettings.Get("MPComputerAddress"); + + return ECP2Assembly.MPHandler.Instance; + } + + //based on code from http://msdn.microsoft.com/asp.net/whidbey/beta2changes.aspx + public void ProcessRequest(HttpContext context) + { + byte[] imageBytes; + string cacheId = string.Empty; + + if (context.Request.QueryString["SongID"] != null) + { + int songId = 0; + int.TryParse(context.Request.QueryString["SongID"], out songId); + if (songId==0) + { + //parameter not an integer + context.Response.ContentType = "text/plain"; + context.Response.Write("The SongID parameter must be an integer."); + return; + } + + cacheId = songId.ToString(); + + //check to see if cache contains image + Object cachedImageBytes = context.Cache.Get(cacheId); + + if (cachedImageBytes != null) + { + imageBytes = (Byte[])cachedImageBytes; + } + else + { + imageBytes = GetEMPH().GetCoverArtForSong(songId); + if (imageBytes == null) + { + //image not found + context.Response.ContentType = "text/plain"; + context.Response.Write("No image found for the specified SongID."); + return; + } + + // store image in cache for later requests, expire after 2 hrs (above average length of album) + context.Cache.Add(cacheId, imageBytes, null, DateTime.MaxValue, new TimeSpan(2, 0, 0),System.Web.Caching.CacheItemPriority.Normal, null); + } + } + + else if (context.Request.QueryString["FolderPath"] != null) + { + string folderPath = string.Empty; + folderPath = context.Request.QueryString["FolderPath"]; + if (folderPath == string.Empty) + { + //parameter empty + context.Response.ContentType = "text/plain"; + context.Response.Write("The FolderPath parameter must not be empty."); + return; + } + + //convert folderPath from HTML encoding + folderPath = System.Web.HttpUtility.HtmlDecode(folderPath); + + cacheId = folderPath; + + //check to see if cache contains image + Object cachedImageBytes = context.Cache.Get(cacheId); + + if (cachedImageBytes != null) + { + imageBytes = (Byte[])cachedImageBytes; + } + else + { + imageBytes = GetEMPH().GetCoverArtForFolder(folderPath); + if (imageBytes == null) + { + //image not found + context.Response.ContentType = "text/plain"; + context.Response.Write("No image found for the specified folder path."); + return; + } + + // store image in cache for later requests, expire after 2 hrs (above average length of album) + context.Cache.Add(cacheId, imageBytes, null, DateTime.MaxValue, new TimeSpan(2, 0, 0), System.Web.Caching.CacheItemPriority.Normal, null); + } + } + else + { + //no parameters specified + context.Response.ContentType = "text/plain"; + context.Response.Write("no parameters specified - please specify either SongID or FolderPath."); + return; + } + + // return image + context.Response.ContentType = "image/jpeg"; + context.Response.Cache.SetCacheability(HttpCacheability.Public); + context.Response.BufferOutput = false; + context.Response.OutputStream.Write(imageBytes, 0, imageBytes.Length); + } + + public bool IsReusable + { + get + { + return false; + } + } + + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sam...@us...> - 2007-02-20 13:40:55
|
Revision: 20 http://svn.sourceforge.net/mp-webinterface/?rev=20&view=rev Author: samuel337 Date: 2007-02-20 05:40:41 -0800 (Tue, 20 Feb 2007) Log Message: ----------- Added client discovery code to ECP2Assembly; removed and recoded bits in preparation for client/server configuration. Modified Paths: -------------- trunk/source/ECP2Assembly/ECP2Assembly.csproj trunk/source/ECP2Assembly/clsMPHandler.cs trunk/source/ECP2Plugin/ECP2Plugin.csproj trunk/source/ECP2Plugin/clsMain.cs trunk/source/ECP2Plugin/frmSetup.cs Added Paths: ----------- trunk/source/ECP2Assembly/clsClientDiscovery.cs trunk/source/ECP2Assembly/clsUdpCommunication.cs trunk/source/ECP2Assembly/clsUdpMCHelper.cs Modified: trunk/source/ECP2Assembly/ECP2Assembly.csproj =================================================================== --- trunk/source/ECP2Assembly/ECP2Assembly.csproj 2006-09-09 17:41:13 UTC (rev 19) +++ trunk/source/ECP2Assembly/ECP2Assembly.csproj 2007-02-20 13:40:41 UTC (rev 20) @@ -38,6 +38,7 @@ </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> + <Reference Include="System.Drawing" /> <Reference Include="System.Runtime.Remoting" /> <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> @@ -45,15 +46,23 @@ <SpecificVersion>False</SpecificVersion> <HintPath>..\..\..\..\MediaPortal Source\mediaportal\TVCapture\bin\Debug\TVCapture.dll</HintPath> </Reference> + <Reference Include="Utils, Version=1.0.2563.41060, Culture=neutral, processorArchitecture=x86"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\..\MediaPortal Source\mediaportal\Utils\bin\Debug\Utils.dll</HintPath> + </Reference> <Reference Include="WindowPlugins, Version=1.0.2231.40336, Culture=neutral, processorArchitecture=MSIL"> <SpecificVersion>False</SpecificVersion> <HintPath>..\..\..\..\MediaPortal Source\mediaportal\WindowPlugins\bin\Debug\WindowPlugins.dll</HintPath> </Reference> </ItemGroup> <ItemGroup> - <Compile Include="AssemblyResolve.cs" /> - <Compile Include="AssemblySettings.cs" /> + <None Include="AssemblyResolve.cs" /> + <None Include="AssemblySettings.cs" /> + <Compile Include="clsClientDiscovery.cs" /> + <Compile Include="clsCustomMPObjects.cs" /> + <Compile Include="clsUdpCommunication.cs" /> <Compile Include="clsMPHandler.cs" /> + <Compile Include="clsUdpMCHelper.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> Added: trunk/source/ECP2Assembly/clsClientDiscovery.cs =================================================================== --- trunk/source/ECP2Assembly/clsClientDiscovery.cs (rev 0) +++ trunk/source/ECP2Assembly/clsClientDiscovery.cs 2007-02-20 13:40:41 UTC (rev 20) @@ -0,0 +1,75 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ECP2Assembly +{ + class ClientDiscovery : IDisposable + { + public List<string> ClientList; + private UdpMCHelper udpComm; + + private System.Net.IPAddress GroupIP = System.Net.IPAddress.Parse("225.2.100.1"); + private int GroupUdpPort = 3333; + private int GroupTTL = 2; + + public ClientDiscovery() + { + } + + public ClientDiscovery(System.Net.IPAddress groupIP, int groupUdpPort, int groupTTL) + { + GroupIP = groupIP; + GroupUdpPort = groupUdpPort; + GroupTTL = groupTTL; + } + + public void IssueClientPing() + { + if (udpComm != null) + { + udpComm = new UdpMCHelper(GroupIP, GroupTTL); + udpComm.Start(GroupUdpPort); + + udpComm.ReceiveEvent += new UdpMCHelper.ReceiveEventHandler(UdpComm_ReceiveEvent); + } + + ClientList.Clear(); + + udpComm.Send(GroupUdpPort, UdpCommunication.MessageTypes.PING_REQUEST, "", DateTime.Now); + } + + private void UdpComm_ReceiveEvent(UdpMCHelper.ReceiveEventArgs e) + { + if (e.Type == UdpCommunication.MessageTypes.PING_RESPONSE) + { + lock (ClientList) + { + ClientList.Add(e.HostName); + } + } + } + + public void StopWaitingForResponses() + { + if (udpComm != null) + { + udpComm.Stop(); + udpComm = null; + } + } + + #region IDisposable Members + + void IDisposable.Dispose() + { + if (udpComm != null) + { + udpComm.Stop(); + udpComm = null; + } + } + + #endregion + } +} Modified: trunk/source/ECP2Assembly/clsMPHandler.cs =================================================================== --- trunk/source/ECP2Assembly/clsMPHandler.cs 2006-09-09 17:41:13 UTC (rev 19) +++ trunk/source/ECP2Assembly/clsMPHandler.cs 2007-02-20 13:40:41 UTC (rev 20) @@ -35,55 +35,58 @@ #endregion #region Global variables, settings and instance code - static string sMPComputerName; - static string sConfigFileName; - static bool ResolveEventAttached = false; + //CLEANUP: remove commented code below when satisfied with changes + // AssemblySettings & AssemblyResolve already disabled, remove when done - public static string ConfigFileName - { - get - { - if (sConfigFileName==null) - { - sConfigFileName = AssemblySettings.GetDefaultConfigPath(); - } + //static string sMPComputerName; + //static string sConfigFileName; + //static bool ResolveEventAttached = false; - return sConfigFileName; - } - set - { - sConfigFileName = value; - } - } + //public static string ConfigFileName + //{ + // get + // { + // if (sConfigFileName==null) + // { + // sConfigFileName = AssemblySettings.GetDefaultConfigPath(); + // } - public static string MPComputerName - { - get - { - if (sMPComputerName==null) - { - AssemblySettings AssemblyConfig = new AssemblySettings(ConfigFileName); - sMPComputerName = AssemblyConfig.GetSetting("MPComputerAddress"); - } + // return sConfigFileName; + // } + // set + // { + // sConfigFileName = value; + // } + //} - return sMPComputerName; - } - set - { - //prevent unnecessary writing to file and also fixes web service errors - if (sMPComputerName!=value) - { - sMPComputerName = value; - AssemblySettings AssemblyConfig = new AssemblySettings(ConfigFileName); - AssemblyConfig.SaveSetting("MPComputerAddress", sMPComputerName ); - } - } - } + //public static string MPComputerName + //{ + // get + // { + // if (sMPComputerName==null) + // { + // AssemblySettings AssemblyConfig = new AssemblySettings(ConfigFileName); + // sMPComputerName = AssemblyConfig.GetSetting("MPComputerAddress"); + // } + // return sMPComputerName; + // } + // set + // { + // //prevent unnecessary writing to file and also fixes web service errors + // if (sMPComputerName!=value) + // { + // sMPComputerName = value; + // AssemblySettings AssemblyConfig = new AssemblySettings(ConfigFileName); + // AssemblyConfig.SaveSetting("MPComputerAddress", sMPComputerName ); + // } + // } + //} + public static void WriteLog(string msg) { string logFileName; - logFileName = ConfigFileName + ".log"; + logFileName = System.Reflection.Assembly.GetExecutingAssembly().FullName + ".log"; System.IO.FileStream Wfs = new System.IO.FileStream(logFileName, System.IO.FileMode.Append, System.IO.FileAccess.Write); System.IO.StreamWriter w = new System.IO.StreamWriter(Wfs); @@ -94,49 +97,62 @@ Wfs.Close(); } - public static MPHandler Instance - { - get - { - if (ResolveEventAttached == false) - { - AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ECP2Assembly.AssemblyResolve.MyResolveEventHandler); - ResolveEventAttached = true; - } + //public static MPHandler Instance + //{ + // get + // { + // if (ResolveEventAttached == false) + // { + // AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(ECP2Assembly.AssemblyResolve.MyResolveEventHandler); + // ResolveEventAttached = true; + // } - try - { - System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel(),false); - } - catch - {} + // try + // { + // System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel(),false); + // } + // catch + // {} - AssemblySettings AssemblyConfig = new AssemblySettings(ConfigFileName); + // AssemblySettings AssemblyConfig = new AssemblySettings(ConfigFileName); - string AssemblyDir = AssemblyConfig.GetSetting("MPDirectory"); + // string AssemblyDir = AssemblyConfig.GetSetting("MPDirectory"); - //see if can connect to MPLaunchInfo to get MP path, if not, the return nothing and exit sub - try - { - ECP2Assembly.MPLaunchInfo eMPLI; - eMPLI = (MPLaunchInfo)Activator.GetObject(typeof(MPLaunchInfo), "tcp://" + MPComputerName + ":3334/MPLaunchInfo"); + // //see if can connect to MPLaunchInfo to get MP path + // try + // { + // ECP2Assembly.MPLaunchInfo eMPLI; + // eMPLI = (MPLaunchInfo)Activator.GetObject(typeof(MPLaunchInfo), "tcp://" + MPComputerName + ":3334/MPLaunchInfo"); - //save the path if it doesn't match the currently saved path - if (AssemblyDir!=eMPLI.MediaPortalDir) - { - AssemblyDir = eMPLI.MediaPortalDir; - if (System.IO.Directory.Exists(AssemblyDir) == true) - { - AssemblyConfig.SaveSetting("MPDirectory",AssemblyDir); - } - } - } - catch - {} + // //save the path if it doesn't match the currently saved path + // if (AssemblyDir!=eMPLI.MediaPortalDir) + // { + // AssemblyDir = eMPLI.MediaPortalDir; + // if (System.IO.Directory.Exists(AssemblyDir) == true) + // { + // AssemblyConfig.SaveSetting("MPDirectory",AssemblyDir); + // } + // } + // } + // catch + // {} - //otherwise, return an instance of the remoted assembly - return (MPHandler)Activator.GetObject(typeof(MPHandler), "tcp://" + MPComputerName + ":3334/MPHandler"); + // //otherwise, return an instance of the remoted assembly + // return (MPHandler)Activator.GetObject(typeof(MPHandler), "tcp://" + MPComputerName + ":3334/MPHandler"); + // } + //} + + public static MPHandler Instance(string clientAddress) + { + try + { + System.Runtime.Remoting.Channels.ChannelServices.RegisterChannel(new System.Runtime.Remoting.Channels.Tcp.TcpClientChannel(), false); } + catch + { } + + //return an instance of the remoted assembly + return (MPHandler)Activator.GetObject(typeof(MPHandler), "tcp://" + clientAddress + ":3334/MPHandler"); } //variable to hold BurnerThread for transcoding @@ -150,7 +166,7 @@ MediaPortal.GUI.Library.Action act = new MediaPortal.GUI.Library.Action(); act.wID = (MediaPortal.GUI.Library.Action.ActionType)aID; - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log,"ECP2: SendActionByID actionID {0}", act.wID.ToString()); + MediaPortal.GUI.Library.Log.Debug("ECP2: SendActionByID actionID {0}", act.wID.ToString()); //check that action is valid in the current window if (MediaPortal.GUI.Library.ActionTranslator.GetActionDetail(MediaPortal.GUI.Library.GUIWindowManager.ActiveWindow, act) == false) @@ -174,7 +190,7 @@ msg.Message = (MediaPortal.GUI.Library.GUIMessage.MessageType)mID; msg.Label = label; - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log,"ECP2: SendMessageByID messageID {0}, Label {1}", msg.Message.ToString(), msg.Label); + MediaPortal.GUI.Library.Log.Debug("ECP2: SendMessageByID messageID {0}, Label {1}", msg.Message.ToString(), msg.Label); //send message MediaPortal.GUI.Library.GUIWindowManager.SendMessage(msg); @@ -188,7 +204,7 @@ msg.Message = (MediaPortal.GUI.Library.GUIMessage.MessageType)Enum.Parse(typeof(MediaPortal.GUI.Library.GUIMessage.MessageType), mEnum); msg.Label = label; - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log,"ECP2: SendThreadMessageByID messageID {0}, Label {1}", msg.Message.ToString(), msg.Label); + MediaPortal.GUI.Library.Log.Debug("ECP2: SendThreadMessageByID messageID {0}, Label {1}", msg.Message.ToString(), msg.Label); //send message MediaPortal.GUI.Library.GUIWindowManager.SendThreadMessage(msg); @@ -275,19 +291,19 @@ if (methodInfo==null) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log,"ECP2Assembly - GetRecorderProps: Method/Property, {0}, not found",PropName); + MediaPortal.GUI.Library.Log.Warn("ECP2Assembly - GetRecorderProps: Method/Property, {0}, not found", PropName); return null; } if (methodInfo.ReturnType == System.Type.GetType("System.Void")) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log,"ECP2Assembly - GetRecorderProps: Method {0} does not return anything - not a property; ", PropName); + MediaPortal.GUI.Library.Log.Warn("ECP2Assembly - GetRecorderProps: Method {0} does not return anything - not a property; ", PropName); return null; } if (methodInfo.GetParameters().Length > 0) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2Assembly - GetRecorderProps: Method {0} has parameters, thus cannot be accessed.", PropName); + MediaPortal.GUI.Library.Log.Warn("ECP2Assembly - GetRecorderProps: Method {0} has parameters, thus cannot be accessed.", PropName); throw new Exception("ECP2Assembly - GetRecorderProps; This method cannot be accessed because it has parameters"); } @@ -297,7 +313,7 @@ { if (propInfo.GetIndexParameters().Length > 0) { - MediaPortal.GUI.Library.Log.Write("ECP2Assembly - GetRecorderProps: Property {0} has parameters so it cannot be accessed.", PropName); + MediaPortal.GUI.Library.Log.Warn("ECP2Assembly - GetRecorderProps: Property {0} has parameters so it cannot be accessed.", PropName); throw new Exception("ECP2Assembly - GetRecorderProps; This property cannot be accessed because it has parameters."); } @@ -306,6 +322,7 @@ } catch (Exception ex) { + MediaPortal.GUI.Library.Log.Error("ECP2Assembly - GetRecorderProps exception: {0}", ex.ToString()); throw new Exception("ECP2Assembly - GetRecorderProps exception: " + ex.ToString()); } } @@ -365,14 +382,14 @@ //if not found, exit if (propInfo==null) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log,"ECP2Assembly - GetgPlayerProps: No property found with the name {0}", PropName); + MediaPortal.GUI.Library.Log.Warn("ECP2Assembly - GetgPlayerProps: No property found with the name {0}", PropName); return null; } //exit if it contains parameters if (propInfo.GetIndexParameters().Length>0) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2Assembly - GetgPlayerProps: Properties with parameters cannot be accessed; {0}", PropName); + MediaPortal.GUI.Library.Log.Warn("ECP2Assembly - GetgPlayerProps: Properties with parameters cannot be accessed; {0}", PropName); throw new Exception("ECP2Assembly - GetgPlayerProps; This property cannot be accessed because it has parameters"); } @@ -380,6 +397,7 @@ } catch (Exception ex) { + MediaPortal.GUI.Library.Log.Error("ECP2Assembly - GetgPlayerProps exception: {0}", ex.ToString()); throw new Exception("ECP2Assembly - GetgPlayerProps exception: " + ex.ToString()); } } @@ -470,7 +488,7 @@ } finally { - MediaPortal.GUI.Library.Log.Write("ECP2Assembly - RefreshRecordings executed."); + MediaPortal.GUI.Library.Log.Debug("ECP2Assembly - RefreshRecordings executed."); } } @@ -487,12 +505,12 @@ try { MediaPortal.TV.Database.TVDatabase.AddRecording(ref rec); - MediaPortal.GUI.Library.Log.Write("ECP2 - AddRecording: recording ({0}, {1}, {2}) added.", rec.Title, rec.Channel, rec.StartTime.ToString()); + MediaPortal.GUI.Library.Log.Debug("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 - AddRecording: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Error("ECP2 - AddRecording: " + ex.ToString()); return false; } } @@ -502,12 +520,12 @@ try { MediaPortal.TV.Database.TVDatabase.UpdateRecording(rec, changeReason); - MediaPortal.GUI.Library.Log.Write("ECP2 - UpdateRecording: recording ({0}, {1}, {2}) updated.", rec.Title, rec.Channel, rec.StartTime.ToString()); + MediaPortal.GUI.Library.Log.Debug("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 - UpdateRecording: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Error("ECP2 - UpdateRecording: " + ex.ToString()); return false; } } @@ -536,13 +554,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()); + MediaPortal.GUI.Library.Log.Debug("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: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Error("ECP2 - DelRecording: " + ex.ToString()); } return false; @@ -573,14 +591,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()); + MediaPortal.GUI.Library.Log.Debug("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: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Error("ECP2 - DelRecording: " + ex.ToString()); } return false; @@ -617,7 +635,7 @@ } catch (Exception ex) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log,"ECP2 - DelRecording: exception - " + ex.ToString()); + MediaPortal.GUI.Library.Log.Error("ECP2 - DelRecording: exception - " + ex.ToString()); } return false; @@ -769,12 +787,12 @@ } MediaPortal.TV.Database.TVDatabase.AddNotify(notify); - MediaPortal.GUI.Library.Log.Write("ECP2 - AddTVNotify: TVNotify ({0}, {1}) added.",notify.Program.Title,notify.Program.StartTime.ToString()); + MediaPortal.GUI.Library.Log.Debug("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()); + MediaPortal.GUI.Library.Log.Error("ECP2 - AddTVNotify: " + ex.ToString()); return false; } } @@ -791,12 +809,12 @@ } MediaPortal.TV.Database.TVDatabase.DeleteNotify(notify); - MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: TVNotify ({0}, {1}) deleted.", notify.Program.Title, notify.Program.StartTime.ToString()); + MediaPortal.GUI.Library.Log.Debug("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()); + MediaPortal.GUI.Library.Log.Error("ECP2 - DeleteTVNotify: " + ex.ToString()); return false; } } @@ -813,12 +831,12 @@ } MediaPortal.TV.Database.TVDatabase.DeleteNotify(notify); - MediaPortal.GUI.Library.Log.Write("ECP2 - DeleteTVNotify: TVNotify ({0}, {1}) deleted.", notify.Program.Title, notify.Program.StartTime.ToString()); + MediaPortal.GUI.Library.Log.Debug("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()); + MediaPortal.GUI.Library.Log.Error("ECP2 - DeleteTVNotify: " + ex.ToString()); return false; } } @@ -840,7 +858,7 @@ } catch (Exception ex) { - MediaPortal.GUI.Library.Log.Write("ECP2 - GetNotify: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Error("ECP2 - GetNotify: " + ex.ToString()); return null; } } @@ -875,7 +893,7 @@ } catch (Exception ex) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - GetTVNotify: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Error("ECP2 - GetTVNotify: " + ex.ToString()); return null; } } @@ -926,7 +944,7 @@ } catch (Exception ex) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - GetTVGroup: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Error("ECP2 - GetTVGroup: " + ex.ToString()); return null; } } @@ -961,7 +979,7 @@ } catch (Exception ex) { - MediaPortal.GUI.Library.Log.WriteFile(Log.LogType.Log, "ECP2 - GetTVGroup: " + ex.ToString()); + MediaPortal.GUI.Library.Log.Error("ECP2 - GetTVGroup: " + ex.ToString()); return null; } } Added: trunk/source/ECP2Assembly/clsUdpCommunication.cs =================================================================== --- trunk/source/ECP2Assembly/clsUdpCommunication.cs (rev 0) +++ trunk/source/ECP2Assembly/clsUdpCommunication.cs 2007-02-20 13:40:41 UTC (rev 20) @@ -0,0 +1,46 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace ECP2Assembly +{ + public class UdpCommunication + { + public static UdpMCHelper GetDefaultUdpMCHelper() + { + System.Net.IPAddress GroupIP = System.Net.IPAddress.Parse("225.2.100.1"); + int GroupUdpPort = 3333; + int GroupTTL = 2; + + UdpMCHelper udpComm; + udpComm = new UdpMCHelper(GroupIP, GroupTTL); + udpComm.Start(GroupUdpPort); + + return udpComm; + } + + //class to hold message type values + public class MessageTypes + { + public static string PLUGIN_START + { + get { return "PLUGIN_START"; } + } + + public static string PLUGIN_STOP + { + get { return "PLUGIN_STOP"; } + } + + public static string PING_REQUEST + { + get { return "PING_REQUEST"; } + } + + public static string PING_RESPONSE + { + get { return "PING_RESPONSE"; } + } + } + } +} Added: trunk/source/ECP2Assembly/clsUdpMCHelper.cs =================================================================== --- trunk/source/ECP2Assembly/clsUdpMCHelper.cs (rev 0) +++ trunk/source/ECP2Assembly/clsUdpMCHelper.cs 2007-02-20 13:40:41 UTC (rev 20) @@ -0,0 +1,279 @@ +//UDP unicast code taken from MP; modified to multicast and redirected calls to use UdpClient. + +#region Copyright (C) 2005-2007 Team MediaPortal + +/* + * Copyright (C) 2005-2007 Team MediaPortal + * http://www.team-mediaportal.com + * + * This Program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This Program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNU Make; see the file COPYING. If not, write to + * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. + * http://www.gnu.org/copyleft/gpl.html + * + */ + +#endregion + +using System; +using System.Collections.Generic; +using System.Net; +using System.Net.Sockets; +using System.Net.NetworkInformation; +using System.Text; + +namespace ECP2Assembly +{ + public class UdpMCHelper : IDisposable + { + UdpClient udpClient; + + IPAddress groupIP = null; + int TTL = 2; + + #region Logging + public delegate void LogEventHandler(LogEventArgs e); + public event LogEventHandler LogEvent; + + public class LogEventArgs : EventArgs + { + string m_LogLevel; + string m_LogMessage; + + public LogEventArgs() + { + } + + public LogEventArgs(string logLevel, string logMessage) + { + LogLevel = logLevel; + LogMessage = logMessage; + } + + public string LogLevel + { + get { return m_LogLevel; } + set { m_LogLevel = value; } + } + + public string LogMessage + { + get { return m_LogMessage; } + set { m_LogMessage = value; } + } + } + + private void Log(string logLabel, string logMessageFormat, params string[] logMessageParams) + { + if (LogEvent == null) return; + + string logMessage; + logMessage = string.Format(logMessageFormat, logMessageParams); + + LogEventArgs e = new LogEventArgs(logLabel, logMessage); + LogEvent(e); + } + + #endregion + + #region ReceiveEvent + public delegate void ReceiveEventHandler(ReceiveEventArgs e); + public event ReceiveEventHandler ReceiveEvent; + + public class ReceiveEventArgs : EventArgs + { + string m_Type; + string m_Message; + string m_HostName; + string m_Timestamp; + + public ReceiveEventArgs() + { + } + + public ReceiveEventArgs(string type, string message, string hostName, string timestamp) + { + Type = type; + Message = message; + HostName = hostName; + Timestamp = timestamp; + } + + public string Type + { + get { return m_Type; } + set { m_Type = value; } + } + + public string Message + { + get { return m_Message; } + set { m_Message = value; } + } + + public string HostName + { + get { return m_HostName; } + set { m_HostName = value; } + } + + public string Timestamp + { + get { return m_Timestamp; } + set { m_Timestamp = value; } + } + + } + + protected virtual void OnReceive(string strReceive) + { + //check to see if entire message is received + if (!strReceive.EndsWith("~")) + { + //if not, ignore message + return; + } + + if (ReceiveEvent != null) + { + ReceiveEventArgs e = new ReceiveEventArgs(); + + //strip off check character + strReceive = strReceive.Remove(strReceive.Length - 2); + + string[] strReceiveArray = strReceive.Split("|".ToCharArray()); + + if (strReceiveArray.Length < 4) { return; } + + e.Type = strReceiveArray[0]; + e.Message = strReceiveArray[1]; + e.HostName = strReceiveArray[2]; + e.Timestamp = strReceiveArray[3]; + + ReceiveEvent(e); + } + } + #endregion + + class UdpState + { + public IPEndPoint EndPoint; + public UdpClient UdpClient; + } + + public UdpMCHelper(IPAddress groupAddress) + { + groupIP = groupAddress; + } + + public UdpMCHelper(IPAddress groupAddress, int timeToLive) + { + groupIP = groupAddress; + TTL = timeToLive; + } + + public bool Start(int udpPort) + { + try + { + Log("Info","UDPHelper: Starting listener on port {0}", udpPort.ToString()); + + // Port already used? + IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); + TcpConnectionInformation[] connections = properties.GetActiveTcpConnections(); + foreach (TcpConnectionInformation c in connections) + { + if (c.RemoteEndPoint.Port == udpPort) + { + Log("Error", "UDPHelper: UDP port {0} is already in use", udpPort.ToString()); + return false; + } + } + + IPEndPoint endPoint = new IPEndPoint(groupIP, udpPort); + udpClient = new UdpClient(udpPort, AddressFamily.InterNetwork); + udpClient.JoinMulticastGroup(groupIP, TTL); + + UdpState state = new UdpState(); + state.EndPoint = endPoint; + state.UdpClient = udpClient; + udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), state); + Log("Info","UDPHelper: Listening for messages on port {0}", udpPort.ToString()); + return true; + } + catch (SocketException se) + { + Log("Error","UDPHelper: Start port {0}: {1} - {2}", udpPort.ToString(), se.ErrorCode.ToString(), se.Message); + return false; + } + } + + public void Stop() + { + try + { + udpClient.DropMulticastGroup(groupIP); + udpClient.Close(); + } + catch (System.NullReferenceException) + { } + udpClient = null; + } + + public bool Send(int udpPort, string strType, string strSend, DateTime timeStamp) + { + try + { + byte[] sendbuf = Encoding.UTF8.GetBytes(string.Format("{0}|{1}|{2}|{3}~", strType, strSend, System.Net.Dns.GetHostName(), timeStamp.ToBinary())); + + IPEndPoint endPoint = new IPEndPoint(groupIP, udpPort); + udpClient.Send(sendbuf, sendbuf.Length, endPoint); + return true; + } + catch (SocketException se) + { + Log("Error","UDPHelper: Send port {0}: {1} - {2}", udpPort.ToString(), se.ErrorCode.ToString(), se.Message); + return false; + } + } + + public void ReceiveCallback(IAsyncResult ar) + { + UdpClient udpClientLoc = (UdpClient)((UdpState)(ar.AsyncState)).UdpClient; + IPEndPoint endPoint = (IPEndPoint)((UdpState)(ar.AsyncState)).EndPoint; + + try + { + Byte[] bytesReceived = udpClientLoc.EndReceive(ar, ref endPoint); + string strReceived = Encoding.UTF8.GetString(bytesReceived); + OnReceive(strReceived); + udpClientLoc.BeginReceive(new AsyncCallback(ReceiveCallback), (UdpState)(ar.AsyncState)); + } + catch (System.ObjectDisposedException) + { + } + catch (SocketException) + { + } + } + + #region IDisposable Members + + void IDisposable.Dispose() + { + Stop(); + } + + #endregion +} +} Modified: trunk/source/ECP2Plugin/ECP2Plugin.csproj =================================================================== --- trunk/source/ECP2Plugin/ECP2Plugin.csproj 2006-09-09 17:41:13 UTC (rev 19) +++ trunk/source/ECP2Plugin/ECP2Plugin.csproj 2007-02-20 13:40:41 UTC (rev 20) @@ -38,6 +38,10 @@ <Reference Include="System.Runtime.Remoting" /> <Reference Include="System.Windows.Forms" /> <Reference Include="System.Xml" /> + <Reference Include="Utils, Version=1.0.2423.4606, Culture=neutral, processorArchitecture=x86"> + <SpecificVersion>False</SpecificVersion> + <HintPath>..\..\..\..\MediaPortal Source\mediaportal\Utils\bin\Debug\Utils.dll</HintPath> + </Reference> </ItemGroup> <ItemGroup> <Compile Include="clsCustomSink.cs" /> Modified: trunk/source/ECP2Plugin/clsMain.cs =================================================================== --- trunk/source/ECP2Plugin/clsMain.cs 2006-09-09 17:41:13 UTC (rev 19) +++ trunk/source/ECP2Plugin/clsMain.cs 2007-02-20 13:40:41 UTC (rev 20) @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using ECP2Assembly; namespace ECP2Plugin { @@ -13,12 +14,17 @@ //track activity and disallows shutdown depending on time lapsed private static DateTime lastActivity; + private UdpMCHelper UdpComm; + private int UdpCommPort; + #region IPlugin Members void MediaPortal.GUI.Library.IPlugin.Start() { //define HTTPchannel and setup remoting - System.Runtime.Remoting.RemotingConfiguration.Configure("MediaPortal.exe.config", false); + //removed config file parameter as it was causing issues (not needed anyway) + //System.Runtime.Remoting.RemotingConfiguration.Configure("MediaPortal.exe.config", false); + System.Runtime.Remoting.RemotingConfiguration.Configure(null, false); //turn to RemoteOnly for production version! System.Runtime.Remoting.RemotingConfiguration.CustomErrorsMode = System.Runtime.Remoting.CustomErrorsModes.Off; System.Runtime.Remoting.Channels.Tcp.TcpServerChannel channel = new System.Runtime.Remoting.Channels.Tcp.TcpServerChannel("MediaPortal ECP2", 3334, new ServerActivitySinkProvider()); @@ -27,17 +33,37 @@ System.Runtime.Remoting.RemotingConfiguration.RegisterWellKnownServiceType(typeof(ECP2Assembly.MPLaunchInfo), "MPLaunchInfo", System.Runtime.Remoting.WellKnownObjectMode.SingleCall); //get settings - MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings("mediaportal.xml"); + MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Config, "MediaPortal.xml")); shutdownDelay = MPSettings.GetValueAsInt("ECP2", "ShutdownDelay", 10); ResetLastActivityTime(); - MediaPortal.GUI.Library.Log.Write("ECP2: Remoting initialised."); + MediaPortal.GUI.Library.Log.Info("ECP2: Remoting initialised."); + + //load UDP communication + System.Net.IPAddress GroupAddress = System.Net.IPAddress.Parse(MPSettings.GetValueAsString("ECP2", "GroupAddress", "225.2.100.1")); + UdpComm = new UdpMCHelper(GroupAddress, MPSettings.GetValueAsInt("ECP2", "GroupTTL", 2)); + + UdpComm.LogEvent += new UdpMCHelper.LogEventHandler(UdpComm_LogEvent); + + UdpCommPort = MPSettings.GetValueAsInt("ECP2", "GroupPort", 3333); + UdpComm.Start(UdpCommPort); + + UdpComm.ReceiveEvent += new UdpMCHelper.ReceiveEventHandler(UdpComm_ReceiveEvent); + + //send startup message + UdpComm.Send(UdpCommPort, UdpCommunication.MessageTypes.PLUGIN_START, "", DateTime.Now); + } void MediaPortal.GUI.Library.IPlugin.Stop() { - + //send shutdown message + UdpComm.Send(UdpCommPort, UdpCommunication.MessageTypes.PLUGIN_STOP, "", DateTime.Now); + + //stop udpcomm + UdpComm.Stop(); + UdpComm = null; } #endregion @@ -126,6 +152,34 @@ { //MediaPortal.GUI.Library.Log.Write("ECP2: LastActivityTimer resetted."); lastActivity = DateTime.Now; - } + } + + #region UdpComm + private void UdpComm_LogEvent(UdpMCHelper.LogEventArgs e) + { + switch (e.LogLevel) + { + case "Error": + MediaPortal.GUI.Library.Log.Error(e.LogMessage); + break; + + default: + MediaPortal.GUI.Library.Log.Info(e.LogMessage); + break; + } + } + + private void UdpComm_ReceiveEvent(UdpMCHelper.ReceiveEventArgs e) + { + //respond to PING requests + if (e.Type == UdpCommunication.MessageTypes.PING_REQUEST) + { + lock (UdpComm) + { + UdpComm.Send(UdpCommPort, UdpCommunication.MessageTypes.PING_RESPONSE, "", DateTime.Now); + } + } + } + #endregion } } Modified: trunk/source/ECP2Plugin/frmSetup.cs =================================================================== --- trunk/source/ECP2Plugin/frmSetup.cs 2006-09-09 17:41:13 UTC (rev 19) +++ trunk/source/ECP2Plugin/frmSetup.cs 2007-02-20 13:40:41 UTC (rev 20) @@ -22,14 +22,14 @@ private void cmdSaveSettings_Click(object sender, EventArgs e) { - MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings("mediaportal.xml"); + MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Config, "MediaPortal.xml")); MPSettings.SetValue("ECP2", "ShutdownDelay", NUDShutdownDelay.Value); this.Close(); } private void frmSetup_Load(object sender, EventArgs e) { - MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings("mediaportal.xml"); + MediaPortal.Profile.Settings MPSettings = new MediaPortal.Profile.Settings(MediaPortal.Configuration.Config.GetFile(MediaPortal.Configuration.Config.Dir.Config, "MediaPortal.xml")); NUDShutdownDelay.Value = MPSettings.GetValueAsInt("ECP2", "ShutdownDelay", 10); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |