|
From: <pop...@us...> - 2015-02-08 12:35:52
|
Revision: 4945
http://sourceforge.net/p/mp-plugins/code/4945
Author: popy2007
Date: 2015-02-08 12:35:39 +0000 (Sun, 08 Feb 2015)
Log Message:
-----------
Added Paths:
-----------
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalDatabaseFactory.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalMovingPicturesDatabase.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalMovingPicturesDatabaseSQLite.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalTVSeriesDatabase.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalTVSeriesDatabaseSQLite.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalVideoDatabase.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalVideoDatabaseSQLite.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/CentralizedDatabase.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/CentralizedDatabase.csproj
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/CentralizedDatabaseConfig.Designer.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/CentralizedDatabaseConfig.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/CentralizedDatabaseConfig.resx
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Classes/EnumUtil.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Classes/FolderSync.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Classes/TaskCompletionSourceExtensions.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Classes/TaskExtrasExtensions.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Classes/UNCTools.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Configuration/Utils.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Properties/AssemblyInfo.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Properties/Resources.Designer.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Properties/Resources.resx
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Resources/CentralizedDatabaseDisabled.png
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Resources/CentralizedDatabaseEnabled.png
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Resources/language/de.xml
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Resources/language/en-US.xml
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/SQLiteResultCacheItem.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/Translation.cs
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase.sln
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase.suo
trunk/plugins/CentralizedDatabase/Trunk/Extension_MPEI/CentralizedDatabase.xmp2
trunk/plugins/CentralizedDatabase/Trunk/Extension_MPEI/CentralizedDatabase_0.6.0.3.mpe1
trunk/plugins/CentralizedDatabase/Trunk/Extension_MPEI/Resources/MPEI_install_header.png
trunk/plugins/CentralizedDatabase/Trunk/Extension_MPEI/Resources/MPEI_left_picture.PNG
trunk/plugins/CentralizedDatabase/Trunk/Extension_MPEI/update.xml
trunk/plugins/CentralizedDatabase/Trunk/license.gpl
Property Changed:
----------------
trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/
Index: trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase
===================================================================
--- trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase 2015-02-08 12:33:37 UTC (rev 4944)
+++ trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase 2015-02-08 12:35:39 UTC (rev 4945)
Property changes on: trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase
___________________________________________________________________
Modified: svn:ignore
## -1,2 +1,3 ##
*/bin */obj */Release */Debug *.suo *.err *.log *.obj *.bin *.dll *.exe *.LOG *.user *.pdb [tT]emp [tT]empPE Ankh.Load thumbs.db *.resharper *.vspscc *.vsssccc *.scc */_ReSharper* */_ReSharper.* bin obj *.resharperoptions *.db *.bak *_ReSharper* *.snk logs output TestResults *.crunchsolution.* *.crunchproject.*
bin
+obj
Added: trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalDatabaseFactory.cs
===================================================================
--- trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalDatabaseFactory.cs (rev 0)
+++ trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalDatabaseFactory.cs 2015-02-08 12:35:39 UTC (rev 4945)
@@ -0,0 +1,60 @@
+#region GPL License
+
+//Mediaportal (http://www.team-mediaportal.com/) Plugin - CentralizedDatabase
+//Copyright (C) 2015 Max Wimmelbacher
+//
+//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
+//of the License, 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 this program; if not, write to the Free Software
+//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MediaPortal.Video.Database;
+
+namespace CentralizedDatabase
+{
+ /// <summary>
+ /// The class CentralizedDatabase.AdditionalDatabaseFactory is providing static methods to get database objects.
+ /// These returned objects are mapped to the database residing on the path provided in the input parameter strDatabaseFile.
+ /// </summary>
+ class AdditionalDatabaseFactory
+ {
+
+ #region Public Methods
+
+ public static IVideoDatabase GetVideoDatabase(string strDatabaseFile)
+ {
+ var objAdditionalDatabase = new AdditionalVideoDatabaseSQLite(strDatabaseFile);
+ return objAdditionalDatabase.Instance;
+ }
+
+ public static AdditionalTVSeriesDatabaseSQLite GetTVSeriesDatabase(string strDataBaseFile)
+ {
+ var objAdditionalDatabase = new AdditionalTVSeriesDatabaseSQLite(strDataBaseFile);
+ return objAdditionalDatabase;
+ }
+
+ public static AdditionalMovingPicturesDatabaseSQLite GetMovingPicturesDatabase(string strDataBaseFile)
+ {
+ var objAdditionalDatabase = new AdditionalMovingPicturesDatabaseSQLite(strDataBaseFile);
+ return objAdditionalDatabase;
+ }
+
+ #endregion
+
+ }
+}
\ No newline at end of file
Added: trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalMovingPicturesDatabase.cs
===================================================================
--- trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalMovingPicturesDatabase.cs (rev 0)
+++ trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalMovingPicturesDatabase.cs 2015-02-08 12:35:39 UTC (rev 4945)
@@ -0,0 +1,104 @@
+#region GPL License
+
+//Mediaportal (http://www.team-mediaportal.com/) Plugin - CentralizedDatabase
+//Copyright (C) 2015 Max Wimmelbacher
+//
+//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
+//of the License, 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 this program; if not, write to the Free Software
+//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MediaPortal.GUI.Library;
+
+namespace CentralizedDatabase
+{
+
+ /// <summary>
+ /// The class CentralizedDatabase.AdditionalMovingPicturesDatabase provides all necessary properties/methods to interact with a moving pictures database.
+ /// </summary>
+
+ class AdditionalMovingPicturesDatabase
+ {
+ #region Declaration
+
+ private string mDatabaseFile;
+ private AdditionalMovingPicturesDatabaseSQLite mDatabase;
+
+ #endregion Declaration;
+
+ #region Constructors
+
+ public AdditionalMovingPicturesDatabase(string strDatabaseFile)
+ {
+ mDatabaseFile = strDatabaseFile;
+ mDatabase = AdditionalDatabaseFactory.GetMovingPicturesDatabase(mDatabaseFile);
+ }
+
+ #endregion
+
+ #region Properties
+
+ public string DatabaseName
+ {
+ get
+ {
+ if (mDatabase != null)
+ {
+ return mDatabase.DatabaseName;
+ }
+ return string.Empty;
+ }
+ }
+
+ #endregion
+
+ #region Public methods
+
+ public void ReOpen()
+ {
+ Dispose();
+ mDatabase = AdditionalDatabaseFactory.GetMovingPicturesDatabase(mDatabaseFile);
+ }
+
+ public void Dispose()
+ {
+ if (mDatabase != null)
+ {
+ mDatabase.Dispose();
+ Log.Info("CentralizedDatabase: MovingPictures database closed.");
+ }
+ mDatabase = null;
+ }
+
+ //UpdateDBUserMovieSettings, set the current watch state
+ public int UpdateDBUserMovieSettings(int? intnullID, int? intnullUserID, int? intnullUserRating, int intWatched, int intResumePart, int intResumeTime, byte[] bteResumeData, int intResume_BDTitle)
+ {
+ return mDatabase.UpdateDBUserMovieSettings(intnullID, intnullUserID, intnullUserRating, intWatched, intResumePart, intResumeTime, bteResumeData, intResume_BDTitle);
+ }
+
+ //InsertDBWatchedHistory, insert an watch history entry into the database
+ public int InsertDBWatchedHistory(int? intnullUserID, int? intnullMovieID, DateTime dtDateWatched)
+ {
+ return mDatabase.InsertDBWatchedHistory(intnullUserID, intnullMovieID, dtDateWatched);
+ }
+
+ #endregion
+
+ }
+}
Added: trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalMovingPicturesDatabaseSQLite.cs
===================================================================
--- trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalMovingPicturesDatabaseSQLite.cs (rev 0)
+++ trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalMovingPicturesDatabaseSQLite.cs 2015-02-08 12:35:39 UTC (rev 4945)
@@ -0,0 +1,233 @@
+#region GPL License
+
+//Mediaportal (http://www.team-mediaportal.com/) Plugin - CentralizedDatabase
+//Copyright (C) 2015 Max Wimmelbacher
+//
+//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
+//of the License, 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 this program; if not, write to the Free Software
+//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MediaPortal.GUI.Library;
+using MediaPortal.Database;
+using SQLite.NET;
+using WindowPlugins.GUITVSeries;
+using System.Globalization;
+using Cornerstone.Database.CustomTypes;
+using System.Reflection;
+
+namespace CentralizedDatabase
+{
+
+ /// <summary>
+ /// The class CentralizedDatabase.AdditionalMovingPicturesDatabaseSQLite provides all necessary properties/methods which do the real communication with a moving pictures database.
+ /// Objects created from this class are returned by calls to methods of the class AdditionalDatabaseFactory,
+ /// </summary>
+
+ class AdditionalMovingPicturesDatabaseSQLite : IDisposable
+ {
+
+ #region Declaration
+
+ private Dictionary<string, SQLiteResultCacheItem> mCache;
+ private SQLiteClient mDatabase;
+ private string mDatabaseFile;
+
+ #endregion
+
+ #region Constructors
+
+ public AdditionalMovingPicturesDatabaseSQLite(string strDatabaseFile)
+ {
+ mDatabaseFile = strDatabaseFile;
+ Open();
+ }
+
+ #endregion
+
+ #region Properties
+
+ public string DatabaseName
+ {
+ get
+ {
+ return mDatabaseFile;
+ }
+ }
+
+ #endregion Properties
+
+ #region Public methods
+
+ public void Dispose()
+ {
+ mDatabase.Close();
+ mDatabase = null;
+ }
+
+ //UpdateDBUserMovieSettings, set the current watch state
+ public int UpdateDBUserMovieSettings(int? intnullID, int? intnullUserID, int? intnullUserRating, int intWatched, int intResumePart, int intResumeTime, byte[] bteResumeData, int intResume_BDTitle)
+ {
+ string strID = "0";
+ string strUserID = "1";
+ string strUserRating= "NULL";
+ string strSQL;
+ try
+ {
+ //Check if we have the id from the row we want to update
+ if (intnullID == null)
+ {
+ return -1;
+ }else{
+ strID = intnullID.ToString();
+ }
+
+ //Check if we have a userID int value, otherwise use the default value of "1" (multiuser support isnt implemented in MovingPictures)
+ if (intnullUserID != null) strUserID = intnullUserID.ToString();
+
+ //Check if we have a UserRating int value, otherwise use the default value of "NULL"
+ if (intnullUserRating != null) strUserRating = intnullUserRating.ToString();
+
+ //Convert bteResumeData to CornerStone ByteArray and then to string
+ ByteArray ResumeData = new ByteArray(bteResumeData);
+ if (ResumeData.ToString() == "")
+ {
+ strSQL = String.Format("UPDATE user_movie_settings SET user = {0}, user_rating = {1}, watched = {2}, resume_part = {3}, resume_time = {4}, resume_data = NULL, resume_titlebd = {5} WHERE id = '{6}'", strUserID, strUserRating, intWatched.ToString(), intResumePart.ToString(), intResumeTime.ToString(), intResume_BDTitle.ToString(), strID);
+ }
+ else
+ {
+ strSQL = String.Format("UPDATE user_movie_settings SET user = {0}, user_rating = {1}, watched = {2}, resume_part = {3}, resume_time = {4}, resume_data = '{5}', resume_titlebd = {6} WHERE id = '{7}'", strUserID, strUserRating, intWatched.ToString(), intResumePart.ToString(), intResumeTime.ToString(), ResumeData.ToString(), intResume_BDTitle.ToString(), strID);
+ }
+
+ Log.Debug("CentralizedDatabase: (UpdateDBUserMovieSettings) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: UpdateDBUserMovieSettings: MovingPictures database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ return -2;
+ }
+
+ //OK
+ return 1;
+ }
+
+ //InsertDBWatchedHistory, insert an watch history entry into the database
+ public int InsertDBWatchedHistory(int? intnullUserID, int? intnullMovieID, DateTime dtDateWatched)
+ {
+ string strUserID = "1";
+ string strMovieID = "0";
+ string strSQL;
+ try
+ {
+ //Check if we have a userID int value, otherwise use the default value of "1" (multiuser support isnt implemented in MovingPictures)
+ if (intnullUserID != null) strUserID = intnullUserID.ToString();
+
+ //Check if we have a Movie id, if not -> error return
+ if (intnullMovieID == null)
+ {
+ return -1;
+ }
+ else
+ {
+ strMovieID = intnullMovieID.ToString();
+ }
+
+ strSQL = String.Format("INSERT INTO watched_history VALUES (NULL, {0}, {1}, '{2}Z')", strUserID, strMovieID, TimeZone.CurrentTimeZone.ToUniversalTime(dtDateWatched).ToString("yyyy-MM-dd HH:mm:ss"));
+ Log.Debug("CentralizedDatabase: (InsertDBWatchedHistory) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+
+ //insert id of movie and watchhistory in table movie_info__watched_history
+ strSQL = String.Format("INSERT INTO movie_info__watched_history VALUES (NULL, {0}, {1})", strMovieID, mDatabase.LastInsertID().ToString());
+ Log.Debug("CentralizedDatabase: (InsertDBWatchedHistory) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: InsertDBWatchedHistory: MovingPictures database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ return -2;
+ }
+
+ //OK
+ return 1;
+ }
+
+ #endregion
+
+ #region Private methods
+
+ private void Open()
+ {
+ mCache = new Dictionary<string, SQLiteResultCacheItem>();
+ Log.Info("CentralizedDatabase: Opening MovingPictures database " + mDatabaseFile);
+ try
+ {
+ if (mDatabase != null)
+ {
+ Log.Info("CentralizedDatabase: MovingPictures database already opened.");
+ return;
+ }
+ mDatabase = new SQLiteClient(mDatabaseFile);
+ DatabaseUtility.SetPragmas(mDatabase);
+ Log.Info("CentralizedDatabase: MovingPictures database opened.");
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: MovingPictures database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ private bool CheckCache(string strTableName, string strKey, string strField, ref string strValue)
+ {
+ if (mCache.ContainsKey(strTableName) == true)
+ {
+ if (mCache[strTableName].Key == strKey && mCache[strTableName].IsDirty == false)
+ {
+ if (strValue == string.Empty)
+ {
+ strValue = (string)DatabaseUtility.Get(mCache[strTableName].ResultSet, 0, strField);
+ return true;
+ }
+ else if (strValue == (string)DatabaseUtility.Get(mCache[strTableName].ResultSet, 0, strField))
+ {
+ return true;
+ }
+ else
+ {
+ mCache[strTableName].IsDirty = true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void AddToCache(string strTableName, string strKey, SQLiteResultSet objResultSet)
+ {
+ if (mCache.ContainsKey(strTableName) == true)
+ {
+ mCache.Remove(strTableName);
+ }
+ SQLiteResultCacheItem objCacheItem = new SQLiteResultCacheItem(strKey, objResultSet);
+ mCache.Add(strTableName, objCacheItem);
+ }
+
+ #endregion
+
+ }
+}
\ No newline at end of file
Added: trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalTVSeriesDatabase.cs
===================================================================
--- trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalTVSeriesDatabase.cs (rev 0)
+++ trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalTVSeriesDatabase.cs 2015-02-08 12:35:39 UTC (rev 4945)
@@ -0,0 +1,211 @@
+#region GPL License
+
+//Mediaportal (http://www.team-mediaportal.com/) Plugin - CentralizedDatabase
+//Copyright (C) 2015 Max Wimmelbacher
+//
+//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
+//of the License, 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 this program; if not, write to the Free Software
+//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MediaPortal.GUI.Library;
+
+namespace CentralizedDatabase
+{
+
+ /// <summary>
+ /// The class CentralizedDatabase.AdditionalTVSeriesDatabase provides all necessary properties/methods to interact with a tvseries database.
+ /// </summary>
+
+ class AdditionalTVSeriesDatabase
+ {
+ #region Declaration
+
+ private string mDatabaseFile;
+ private AdditionalTVSeriesDatabaseSQLite mDatabase;
+
+ #endregion Declaration;
+
+ #region Constructors
+
+ public AdditionalTVSeriesDatabase(string strDatabaseFile)
+ {
+ mDatabaseFile = strDatabaseFile;
+ mDatabase = AdditionalDatabaseFactory.GetTVSeriesDatabase(mDatabaseFile);
+ }
+
+ #endregion
+
+ #region Properties
+
+ public string DatabaseName
+ {
+ get
+ {
+ if (mDatabase != null)
+ {
+ return mDatabase.DatabaseName;
+ }
+ return string.Empty;
+ }
+ }
+
+ #endregion
+
+ #region Public methods
+
+ public void ReOpen()
+ {
+ Dispose();
+ mDatabase = AdditionalDatabaseFactory.GetTVSeriesDatabase(mDatabaseFile);
+ }
+
+ public void Dispose()
+ {
+ if (mDatabase != null)
+ {
+ mDatabase.Dispose();
+ Log.Info("CentralizedDatabase: Tv series database closed.");
+ }
+ mDatabase = null;
+ }
+
+ //Gets the CompositeId (unique key to identify an episode) based on the path and filename.
+
+ public string GetCompositeId(string strFilenameAndPath)
+ {
+ return mDatabase.GetCompositeId(strFilenameAndPath);
+ }
+
+ //Gets the CompositeId2 based on the CompositeId if a media file contains two episodes. Seems currently unused.
+
+ public void GetCompositeIdsForEpisode(string strCompositeId, ref ArrayList alsCompositeIds)
+ {
+ string strCompositeId2 = mDatabase.GetCompositeId2(strCompositeId);
+ if (strCompositeId2 == string.Empty)
+ {
+ alsCompositeIds.Add(strCompositeId);
+ }
+ else
+ {
+ mDatabase.GetCompositeIds(strCompositeId2, ref alsCompositeIds);
+ }
+ }
+
+ //Sets the StopTime of the episode if it wasn't watched to the end.
+
+ public void SetEpisodeStopTime(string strCompositeId, int intStopTime)
+ {
+ mDatabase.SetEpisodeStopTime(strCompositeId, intStopTime);
+ }
+
+ //Gets the WatchedStatus of the episode.
+
+ public void GetEpisodeWatchedStatus(string strCompositeId, out bool bolWatched, out string strWatchedDate, out int intStopTime)
+ {
+ bolWatched = mDatabase.GetEpisodeWatchedStatus(strCompositeId);
+ strWatchedDate = mDatabase.GetEpisodeWatchedDate(strCompositeId);
+ intStopTime = mDatabase.GetEpisodeStopTime(strCompositeId);
+ }
+
+ //Sets the WatchedStatus of the episode.
+
+ public void SetEpisodeWatchedStatus(string strCompositeId, bool bolWatched, string strWatchedDate, int intStopTime, bool bolFirstWatched = false)
+ {
+ if (bolWatched == true && bolFirstWatched == true)
+ {
+ mDatabase.SetEpisodeFirstWatchedDate(strCompositeId, strWatchedDate);
+ mDatabase.SetEpisodeLastWatchedDate(strCompositeId, strWatchedDate);
+ }
+ else if (bolWatched == true)
+ {
+ mDatabase.SetEpisodeLastWatchedDate(strCompositeId, strWatchedDate);
+ }
+ mDatabase.SetEpisodeWatchedStatus(strCompositeId, bolWatched);
+ mDatabase.SetEpisodeWatchedDate(strCompositeId, strWatchedDate);
+ mDatabase.SetEpisodeStopTime(strCompositeId, intStopTime);
+ }
+
+ //Gets WatchedStatus of the season.
+
+ public void GetSeasonWatchedStatus(string strCompositeId, out string strSeasonId, out bool bolSeasonWatched)
+ {
+ strSeasonId = mDatabase.GetSeasonId(strCompositeId);
+ bolSeasonWatched = mDatabase.GetSeasonWatchedStatus(strSeasonId);
+ }
+
+ //Gets the WatchedStatus of the series.
+
+ public void GetSeriesWatchedStatus(string strCompositeId, out string strSeriesId, out bool bolSeasonWatched)
+ {
+ strSeriesId = mDatabase.GetSeriesId(strCompositeId);
+ bolSeasonWatched = mDatabase.GetSeriesWatchedStatus(strSeriesId);
+ }
+
+ //Increases the number of the episode plays considering if it was not toggled watched in the MediaPortal menu.
+
+ public void EpisodePlayCountIncrease(string strCompositeId, bool bolToggledEpisode = false)
+ {
+ int intEpisodePlayCount = mDatabase.GetEpisodePlayCount(strCompositeId);
+ if (bolToggledEpisode && intEpisodePlayCount > 0)
+ {
+ mDatabase.SetEpisodePlayCount(strCompositeId, intEpisodePlayCount);
+ }
+ else
+ {
+ mDatabase.SetEpisodePlayCount(strCompositeId, intEpisodePlayCount + 1);
+ }
+ }
+
+ //Decreases the number of the unwatched episodes of a season.
+
+ public void SeasonUnWatchedCountDecrease(string strSeasonId)
+ {
+ int intUnwatchedEpisodes = mDatabase.GetSeasonUnwatchedEpisodes(strSeasonId);
+ if (intUnwatchedEpisodes == 1)
+ {
+ mDatabase.SetSeasonUnwatchedEpisodes(strSeasonId, 0);
+ mDatabase.SetSeasonWatchedStatus(strSeasonId, true);
+ }
+ else
+ {
+ mDatabase.SetSeasonUnwatchedEpisodes(strSeasonId, intUnwatchedEpisodes - 1);
+ }
+ }
+
+ //Decreases the number of the unwatched episodes of a series.
+
+ public void SeriesUnWatchedCountDecrease(string strSeriesId)
+ {
+ int intUnwatchedEpisodes = mDatabase.GetSeriesUnwatchedEpisodes(strSeriesId);
+ if (intUnwatchedEpisodes == 1)
+ {
+ mDatabase.SetSeriesUnwatchedEpisodes(strSeriesId, 0);
+ mDatabase.SetSeriesWatchedStatus(strSeriesId, true);
+ }
+ else
+ {
+ mDatabase.SetSeriesUnwatchedEpisodes(strSeriesId, intUnwatchedEpisodes - 1);
+ }
+ }
+
+ #endregion
+
+ }
+}
Added: trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalTVSeriesDatabaseSQLite.cs
===================================================================
--- trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalTVSeriesDatabaseSQLite.cs (rev 0)
+++ trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalTVSeriesDatabaseSQLite.cs 2015-02-08 12:35:39 UTC (rev 4945)
@@ -0,0 +1,729 @@
+#region GPL License
+
+//Mediaportal (http://www.team-mediaportal.com/) Plugin - CentralizedDatabase
+//Copyright (C) 2015 Max Wimmelbacher
+//
+//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
+//of the License, 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 this program; if not, write to the Free Software
+//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MediaPortal.GUI.Library;
+using MediaPortal.Database;
+using SQLite.NET;
+using WindowPlugins.GUITVSeries;
+
+namespace CentralizedDatabase
+{
+
+ /// <summary>
+ /// The class CentralizedDatabase.AdditionalTVSeriesDatabaseSQLite provides all necessary properties/methods which do the real communication with a tvseries database.
+ /// Objects created from this class are returned by calls to methods of the class AdditionalDatabaseFactory,
+ /// </summary>
+
+ class AdditionalTVSeriesDatabaseSQLite : IDisposable
+ {
+
+ #region Declaration
+
+ private Dictionary<string, SQLiteResultCacheItem> mCache;
+ private SQLiteClient mDatabase;
+ private string mDatabaseFile;
+
+ #endregion
+
+ #region Constructors
+
+ public AdditionalTVSeriesDatabaseSQLite(string strDatabaseFile)
+ {
+ mDatabaseFile = strDatabaseFile;
+ Open();
+ }
+
+ #endregion
+
+ #region Properties
+
+ public string DatabaseName
+ {
+ get
+ {
+ return mDatabaseFile;
+ }
+ }
+
+ #endregion Properties
+
+ #region Public methods
+
+ public void Dispose()
+ {
+ mDatabase.Close();
+ mDatabase = null;
+ }
+
+ public string GetCompositeId(string strFilenameAndPath)
+ {
+ try
+ {
+ string strCompositeID = string.Empty;
+ strFilenameAndPath = strFilenameAndPath.Trim();
+ DatabaseUtility.RemoveInvalidChars(ref strFilenameAndPath);
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBEpisode.cTableName, DBEpisode.cFilename, strFilenameAndPath);
+ Log.Debug("CentralizedDatabase: (GetCompositeId) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strCompositeID = DatabaseUtility.Get(objResults, 0, DBEpisode.cCompositeID);
+ AddToCache(DBEpisode.cTableName, strCompositeID, objResults);
+ }
+ return strCompositeID;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return string.Empty;
+ }
+
+ public void GetCompositeIds(string strCompositeId2, ref ArrayList alsCompositeIds)
+ {
+ try
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBEpisode.cTableName, DBEpisode.cCompositeID2, strCompositeId2);
+ Log.Debug("CentralizedDatabase: (GetCompositeIds) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count == 0)
+ {
+ return;
+ }
+ for (int intLoop = 0; intLoop < objResults.Rows.Count; ++intLoop)
+ {
+ string strFile = DatabaseUtility.Get(objResults, intLoop, DBEpisode.cCompositeID);
+ alsCompositeIds.Add(strFile);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public string GetCompositeId2(string strCompositeId)
+ {
+ try
+ {
+ string strCompositeId2 = string.Empty;
+ if (CheckCache(DBEpisode.cTableName, strCompositeId, DBEpisode.cCompositeID2, ref strCompositeId2) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBEpisode.cTableName, DBEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (GetCompositeId2) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strCompositeId2 = DatabaseUtility.Get(objResults, 0, DBEpisode.cCompositeID2);
+ AddToCache(DBEpisode.cTableName, strCompositeId, objResults);
+ }
+ }
+ return strCompositeId2;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return string.Empty;
+ }
+
+ public int GetEpisodeStopTime(string strCompositeId)
+ {
+ try
+ {
+ string strEpisodeStopTime = string.Empty;
+ if (CheckCache(DBEpisode.cTableName, strCompositeId, DBEpisode.cStopTime, ref strEpisodeStopTime) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBEpisode.cTableName, DBEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (GetEpisodeStopTime) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strEpisodeStopTime = DatabaseUtility.Get(objResults, 0, DBEpisode.cStopTime);
+ AddToCache(DBEpisode.cTableName, strCompositeId, objResults);
+ }
+ }
+ int intStopTime;
+ Int32.TryParse(strEpisodeStopTime, out intStopTime);
+ return intStopTime;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return 0;
+ }
+
+ public void SetEpisodeStopTime(string strCompositeId, int intStopTime)
+ {
+ try
+ {
+ string strEpisodeStopTime = intStopTime.ToString();
+ if (CheckCache(DBEpisode.cTableName, strCompositeId, DBEpisode.cStopTime, ref strEpisodeStopTime) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = {2} WHERE {3} = '{4}'", DBEpisode.cTableName, DBEpisode.cStopTime, intStopTime, DBEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (SetEpisodeStopTime) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public bool GetEpisodeWatchedStatus(string strCompositeId)
+ {
+ try
+ {
+ string strEpisodeWatchedStatus = string.Empty;
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cWatched, ref strEpisodeWatchedStatus) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (GetEpisodeWatchedStatus) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strEpisodeWatchedStatus = DatabaseUtility.Get(objResults, 0, DBOnlineEpisode.cWatched);
+ AddToCache(DBOnlineEpisode.cTableName, strCompositeId, objResults);
+ }
+ }
+ return (strEpisodeWatchedStatus == "1");
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return true;
+ }
+
+ public void SetEpisodeWatchedStatus(string strCompositeId, bool bolWatchedStatus)
+ {
+ try
+ {
+ int intWatchedStatus;
+ if (bolWatchedStatus == true)
+ {
+ intWatchedStatus = 1;
+ }
+ else
+ {
+ intWatchedStatus = 0;
+ }
+ string strEpisodeWatchedStatus = intWatchedStatus.ToString();
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cWatched, ref strEpisodeWatchedStatus) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = {2} WHERE {3} = '{4}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cWatched, intWatchedStatus, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (SetEpisodeWatchedStatus) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public int GetEpisodePlayCount(string strCompositeId)
+ {
+ try
+ {
+ string strEpisodePlayCount = string.Empty;
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cPlayCount, ref strEpisodePlayCount) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (GetEpisodePlayCount) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strEpisodePlayCount = DatabaseUtility.Get(objResults, 0, DBOnlineEpisode.cPlayCount);
+ AddToCache(DBOnlineEpisode.cTableName, strCompositeId, objResults);
+ }
+ }
+ int intUnwatchedEpisodes;
+ Int32.TryParse(strEpisodePlayCount, out intUnwatchedEpisodes);
+ return intUnwatchedEpisodes;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return 0;
+ }
+
+ public void SetEpisodePlayCount(string strCompositeId, int intPlayCount)
+ {
+ try
+ {
+ string strPlayCount = intPlayCount.ToString();
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cPlayCount, ref strPlayCount) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cPlayCount, strPlayCount, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (SetEpisodePlayCount) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public string GetEpisodeWatchedDate(string strCompositeId)
+ {
+ try
+ {
+ string strEpisodeWatchedDate = string.Empty;
+ if (CheckCache(DBEpisode.cTableName, strCompositeId, DBEpisode.cDateWatched, ref strEpisodeWatchedDate) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBEpisode.cTableName, DBEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (GetEpisodeWatchedDate) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strEpisodeWatchedDate = DatabaseUtility.Get(objResults, 0, DBEpisode.cDateWatched);
+ AddToCache(DBEpisode.cTableName, strCompositeId, objResults);
+ }
+ }
+ return strEpisodeWatchedDate;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return string.Empty;
+ }
+
+ public void SetEpisodeWatchedDate(string strCompositeId, string strWatchedDate)
+ {
+ try
+ {
+ if (CheckCache(DBEpisode.cTableName, strCompositeId, DBEpisode.cDateWatched, ref strWatchedDate) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", DBEpisode.cTableName, DBEpisode.cDateWatched, strWatchedDate, DBEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (SetEpisodeWatchedDate) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public string GetEpisodeFirstWatchedDate(string strCompositeId)
+ {
+ try
+ {
+ string strEpisodeFirstWatchedDate = string.Empty;
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cFirstWatchedDate, ref strEpisodeFirstWatchedDate) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (GetEpisodeWatchedDate) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strEpisodeFirstWatchedDate = DatabaseUtility.Get(objResults, 0, DBOnlineEpisode.cFirstWatchedDate);
+ AddToCache(DBOnlineEpisode.cTableName, strCompositeId, objResults);
+ }
+ }
+ return strEpisodeFirstWatchedDate;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return string.Empty;
+ }
+
+ public void SetEpisodeFirstWatchedDate(string strCompositeId, string strFirstWatchedDate)
+ {
+ try
+ {
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cFirstWatchedDate, ref strFirstWatchedDate) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cFirstWatchedDate, strFirstWatchedDate, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (SetEpisodeWatchedDate) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public string GetEpisodeLastWatchedDate(string strCompositeId)
+ {
+ try
+ {
+ string strEpisodeLastWatchedDate = string.Empty;
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cLastWatchedDate, ref strEpisodeLastWatchedDate) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (GetEpisodeWatchedDate) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strEpisodeLastWatchedDate = DatabaseUtility.Get(objResults, 0, DBOnlineEpisode.cLastWatchedDate);
+ AddToCache(DBOnlineEpisode.cTableName, strCompositeId, objResults);
+ }
+ }
+ return strEpisodeLastWatchedDate;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return string.Empty;
+ }
+
+ public void SetEpisodeLastWatchedDate(string strCompositeId, string strLastWatchedDate)
+ {
+ try
+ {
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cLastWatchedDate, ref strLastWatchedDate) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = '{2}' WHERE {3} = '{4}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cLastWatchedDate, strLastWatchedDate, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (SetEpisodeWatchedDate) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public string GetSeasonId(string strCompositeId)
+ {
+ try
+ {
+ string strSeriesId = string.Empty;
+ string strSeasonId = string.Empty;
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cSeriesID, ref strSeriesId) == false || CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cSeasonIndex, ref strSeasonId))
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (GetSeasonId) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strSeriesId = (string)DatabaseUtility.Get(objResults, 0, DBOnlineEpisode.cSeriesID);
+ strSeasonId = (string)DatabaseUtility.Get(objResults, 0, DBOnlineEpisode.cSeasonIndex);
+ AddToCache(DBOnlineEpisode.cTableName, strCompositeId, objResults);
+ }
+ }
+ return (strSeriesId + "_s" + strSeasonId);
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return string.Empty;
+ }
+
+ public bool GetSeasonWatchedStatus(string strSeasonId)
+ {
+ try
+ {
+ string strSeasonWatchedStatus = string.Empty;
+ if (CheckCache(DBSeason.cTableName, strSeasonId, DBSeason.cUnwatchedItems, ref strSeasonWatchedStatus) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBSeason.cTableName, DBSeason.cID, strSeasonId);
+ Log.Debug("CentralizedDatabase: (GetSeasonWatchedStatus) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strSeasonWatchedStatus = DatabaseUtility.Get(objResults, 0, DBSeason.cUnwatchedItems);
+ AddToCache(DBSeason.cTableName, strSeasonId, objResults);
+ }
+ }
+ return (strSeasonWatchedStatus == "0");
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return true;
+ }
+
+ public void SetSeasonWatchedStatus(string strSeasonId, bool bolWatchedStatus)
+ {
+ try
+ {
+ int intUnwatchedItems;
+ if (bolWatchedStatus == true)
+ {
+ intUnwatchedItems = 0;
+ }
+ else
+ {
+ intUnwatchedItems = 1;
+ }
+ string strSeasonWatchedStatus = intUnwatchedItems.ToString();
+ if (CheckCache(DBSeason.cTableName, strSeasonId, DBSeason.cUnwatchedItems, ref strSeasonWatchedStatus) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = {2} WHERE {3} = '{4}'", DBSeason.cTableName, DBSeason.cUnwatchedItems, intUnwatchedItems, DBSeason.cID, strSeasonId);
+ Log.Debug("CentralizedDatabase: (SetSeasonWatchedStatus) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public int GetSeasonUnwatchedEpisodes(string strSeasonId)
+ {
+ try
+ {
+ string strSeasonUnwatchedEpisodes = string.Empty;
+ if (CheckCache(DBSeason.cTableName, strSeasonId, DBSeason.cEpisodesUnWatched, ref strSeasonUnwatchedEpisodes) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBSeason.cTableName, DBSeason.cID, strSeasonId);
+ Log.Debug("CentralizedDatabase: (GetSeasonUnwatchedEpisodes) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strSeasonUnwatchedEpisodes = DatabaseUtility.Get(objResults, 0, DBSeason.cEpisodesUnWatched);
+ AddToCache(DBSeason.cTableName, strSeasonId, objResults);
+ }
+ }
+ int intUnwatchedEpisodes;
+ Int32.TryParse(strSeasonUnwatchedEpisodes, out intUnwatchedEpisodes);
+ return intUnwatchedEpisodes;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return 0;
+ }
+
+ public void SetSeasonUnwatchedEpisodes(string strSeasonId, int intUnwatchedEpisodes)
+ {
+ try
+ {
+ string strSeasonUnwatchedEpisodes = intUnwatchedEpisodes.ToString();
+ if (CheckCache(DBSeason.cTableName, strSeasonId, DBSeason.cEpisodesUnWatched, ref strSeasonUnwatchedEpisodes) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = {2} WHERE {3} = '{4}'", DBSeason.cTableName, DBSeason.cEpisodesUnWatched, intUnwatchedEpisodes, DBSeason.cID, strSeasonId);
+ Log.Debug("CentralizedDatabase: (SetSeasonUnwatchedEpisodes) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public string GetSeriesId(string strCompositeId)
+ {
+ try
+ {
+ string strSeriesId = string.Empty;
+ if (CheckCache(DBOnlineEpisode.cTableName, strCompositeId, DBOnlineEpisode.cSeriesID, ref strSeriesId) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBOnlineEpisode.cTableName, DBOnlineEpisode.cCompositeID, strCompositeId);
+ Log.Debug("CentralizedDatabase: (GetSeriesId) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strSeriesId = DatabaseUtility.Get(objResults, 0, DBOnlineEpisode.cSeriesID);
+ AddToCache(DBOnlineEpisode.cTableName, strCompositeId, objResults);
+ }
+ }
+ return strSeriesId;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return string.Empty;
+ }
+
+ public bool GetSeriesWatchedStatus(string strSeriesId)
+ {
+ try
+ {
+ string strSeriesWatchedStatus = string.Empty;
+ if (CheckCache(DBOnlineSeries.cTableName, strSeriesId, DBOnlineSeries.cUnwatchedItems, ref strSeriesWatchedStatus) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBOnlineSeries.cTableName, DBOnlineSeries.cID, strSeriesId);
+ Log.Debug("CentralizedDatabase: (GetSeriesWatchedStatus) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strSeriesWatchedStatus = DatabaseUtility.Get(objResults, 0, DBOnlineSeries.cUnwatchedItems);
+ AddToCache(DBOnlineSeries.cTableName, strSeriesId, objResults);
+ }
+ }
+ return (strSeriesWatchedStatus == "0");
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return true;
+ }
+
+ public void SetSeriesWatchedStatus(string strSeriesId, bool bolWatchedStatus)
+ {
+ try
+ {
+ int intUnwatchedItems;
+ if (bolWatchedStatus == true)
+ {
+ intUnwatchedItems = 0;
+ }
+ else
+ {
+ intUnwatchedItems = 1;
+ }
+ string strSeriesWatchedStatus = intUnwatchedItems.ToString();
+ if (CheckCache(DBOnlineSeries.cTableName, strSeriesId, DBOnlineSeries.cUnwatchedItems, ref strSeriesWatchedStatus) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = {2} WHERE {3} = '{4}'", DBOnlineSeries.cTableName, DBOnlineSeries.cUnwatchedItems, intUnwatchedItems, DBOnlineSeries.cID, strSeriesId);
+ Log.Debug("CentralizedDatabase: (SetSeriesWatchedStatus) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ public int GetSeriesUnwatchedEpisodes(string strSeriesId)
+ {
+ try
+ {
+ string strSeriesUnwatchedEpisodes = string.Empty;
+ if (CheckCache(DBOnlineSeries.cTableName, strSeriesId, DBOnlineSeries.cEpisodesUnWatched, ref strSeriesUnwatchedEpisodes) == false)
+ {
+ string strSQL = String.Format("SELECT * FROM {0} WHERE {1} = '{2}'", DBOnlineSeries.cTableName, DBOnlineSeries.cID, strSeriesId);
+ Log.Debug("CentralizedDatabase: (GetSeriesUnwatchedEpisodes) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ SQLiteResultSet objResults = mDatabase.Execute(strSQL);
+ if (objResults.Rows.Count > 0)
+ {
+ strSeriesUnwatchedEpisodes = DatabaseUtility.Get(objResults, 0, DBOnlineSeries.cEpisodesUnWatched);
+ AddToCache(DBOnlineSeries.cTableName, strSeriesId, objResults);
+ }
+ }
+ int intUnwatchedEpisodes;
+ Int32.TryParse(strSeriesUnwatchedEpisodes, out intUnwatchedEpisodes);
+ return intUnwatchedEpisodes;
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ return 0;
+ }
+
+ public void SetSeriesUnwatchedEpisodes(string strSeriesId, int intUnwatchedEpisodes)
+ {
+ try
+ {
+ string strSeriesUnwatchedEpisodes = intUnwatchedEpisodes.ToString();
+ if (CheckCache(DBOnlineSeries.cTableName, strSeriesId, DBOnlineSeries.cEpisodesUnWatched, ref strSeriesUnwatchedEpisodes) == false)
+ {
+ string strSQL = String.Format("UPDATE {0} SET {1} = {2} WHERE {3} = '{4}'", DBOnlineSeries.cTableName, DBOnlineSeries.cEpisodesUnWatched, intUnwatchedEpisodes, DBOnlineSeries.cID, strSeriesId);
+ Log.Debug("CentralizedDatabase: (SetSeriesUnwatchedEpisodes) SQL statement '" + strSQL + "' is going to be executed in database '" + mDatabase.DatabaseName + "'.");
+ mDatabase.Execute(strSQL);
+ }
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: TVSeries database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ #endregion
+
+ #region Private methods
+
+ private void Open()
+ {
+ mCache = new Dictionary<string, SQLiteResultCacheItem>();
+ Log.Info("CentralizedDatabase: Opening tv series database " + mDatabaseFile);
+ try
+ {
+ if (mDatabase != null)
+ {
+ Log.Info("CentralizedDatabase: Tv series database already opened.");
+ return;
+ }
+ mDatabase = new SQLiteClient(mDatabaseFile);
+ DatabaseUtility.SetPragmas(mDatabase);
+ Log.Info("CentralizedDatabase: Tv series database opened.");
+ }
+ catch (Exception ex)
+ {
+ Log.Error("CentralizedDatabase: Tv series database exception err:{0} stack:{1}", ex.Message, ex.StackTrace);
+ }
+ }
+
+ private bool CheckCache(string strTableName, string strKey, string strField, ref string strValue)
+ {
+ if (mCache.ContainsKey(strTableName) == true)
+ {
+ if (mCache[strTableName].Key == strKey && mCache[strTableName].IsDirty == false)
+ {
+ if (strValue == string.Empty)
+ {
+ strValue = (string)DatabaseUtility.Get(mCache[strTableName].ResultSet, 0, strField);
+ return true;
+ }
+ else if (strValue == (string)DatabaseUtility.Get(mCache[strTableName].ResultSet, 0, strField))
+ {
+ return true;
+ }
+ else
+ {
+ mCache[strTableName].IsDirty = true;
+ }
+ }
+ }
+ return false;
+ }
+
+ private void AddToCache(string strTableName, string strKey, SQLiteResultSet objResultSet)
+ {
+ if (mCache.ContainsKey(strTableName) == true)
+ {
+ mCache.Remove(strTableName);
+ }
+ SQLiteResultCacheItem objCacheItem = new SQLiteResultCacheItem(strKey, objResultSet);
+ mCache.Add(strTableName, objCacheItem);
+ }
+
+ #endregion
+
+ }
+}
\ No newline at end of file
Added: trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalVideoDatabase.cs
===================================================================
--- trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalVideoDatabase.cs (rev 0)
+++ trunk/plugins/CentralizedDatabase/Trunk/CentralizedDatabase/AdditionalVideoDatabase.cs 2015-02-08 12:35:39 UTC (rev 4945)
@@ -0,0 +1,198 @@
+#region GPL License
+
+//Mediaportal (http://www.team-mediaportal.com/) Plugin - CentralizedDatabase
+//Copyright (C) 2015 Max Wimmelbacher
+//
+//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
+//of the License, 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 this program; if not, write to the Free Software
+//Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+#endregion
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using MediaPortal.GUI.Library;
+usin...
[truncated message content] |