Webserver: Edit profiles (server part)
This commit is contained in:
1 parent
5432676c08
commit
c782ba3862
6 files changed
+371
-16
No files matched your search
@@ -96,6 +96,60 @@ namespace ServerLib
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region playlist
|
||||
|
||||
private static GetPlaylistsDelegate _GetPlaylists;
|
||||
public static GetPlaylistsDelegate GetPlaylists
|
||||
{
|
||||
get { return _GetPlaylists; }
|
||||
set { _GetPlaylists = value; }
|
||||
}
|
||||
|
||||
|
||||
private static GetPlaylistDelegate _GetPlaylist;
|
||||
public static GetPlaylistDelegate GetPlaylist
|
||||
{
|
||||
get { return _GetPlaylist; }
|
||||
set { _GetPlaylist = value; }
|
||||
}
|
||||
|
||||
private static AddSongToPlaylistDelegate _AddSongToPlaylist;
|
||||
public static AddSongToPlaylistDelegate AddSongToPlaylist
|
||||
{
|
||||
get { return _AddSongToPlaylist; }
|
||||
set { _AddSongToPlaylist = value; }
|
||||
}
|
||||
|
||||
private static RemoveSongFromPlaylistDelegate _RemoveSongFromPlaylist;
|
||||
public static RemoveSongFromPlaylistDelegate RemoveSongFromPlaylist
|
||||
{
|
||||
get { return _RemoveSongFromPlaylist; }
|
||||
set { _RemoveSongFromPlaylist = value; }
|
||||
}
|
||||
|
||||
private static MoveSongInPlaylistDelegate _MoveSongInPlaylist;
|
||||
public static MoveSongInPlaylistDelegate MoveSongInPlaylist
|
||||
{
|
||||
get { return _MoveSongInPlaylist; }
|
||||
set { _MoveSongInPlaylist = value; }
|
||||
}
|
||||
|
||||
private static PlaylistContainsSongDelegate _PlaylistContainsSong;
|
||||
public static PlaylistContainsSongDelegate PlaylistContainsSong
|
||||
{
|
||||
get { return _PlaylistContainsSong; }
|
||||
set { _PlaylistContainsSong = value; }
|
||||
}
|
||||
|
||||
private static GetPlaylistSongsDelegate _GetPlaylistSongs;
|
||||
public static GetPlaylistSongsDelegate GetPlaylistSongs
|
||||
{
|
||||
get { return _GetPlaylistSongs; }
|
||||
set { _GetPlaylistSongs = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region user management
|
||||
@@ -135,8 +189,8 @@ namespace ServerLib
|
||||
set { CServer._GetUserIdFromUsername = value; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#endregion
|
||||
public CServer(int port, bool encrypted)
|
||||
{
|
||||
_Init(port, encrypted);
|
||||
@@ -163,7 +217,7 @@ namespace ServerLib
|
||||
MaxReceivedMessageSize = 10485760,
|
||||
MaxBufferSize = 10485760,
|
||||
MaxBufferPoolSize = 10485760,
|
||||
ReaderQuotas = {MaxStringContentLength = 10485760, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760}
|
||||
ReaderQuotas = { MaxStringContentLength = 10485760, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760 }
|
||||
};
|
||||
if (encrypted)
|
||||
{
|
||||
|
||||
@@ -333,7 +333,7 @@ namespace ServerLib
|
||||
|
||||
#region songs
|
||||
|
||||
public SOngInfo GetSong(int songId)
|
||||
public SSongInfo GetSong(int songId)
|
||||
{
|
||||
return CServer.GetSong(songId);
|
||||
}
|
||||
@@ -343,11 +343,63 @@ namespace ServerLib
|
||||
return CServer.GetCurrentSongId();
|
||||
}
|
||||
|
||||
public SOngInfo[] GetAllSongs()
|
||||
public SSongInfo[] GetAllSongs()
|
||||
{
|
||||
return CServer.GetAllSongs();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region playlist
|
||||
|
||||
public SPlaylistInfo[] GetPlaylists()
|
||||
{
|
||||
return CServer.GetPlaylists();
|
||||
}
|
||||
|
||||
public SPlaylistInfo GetPlaylist(int playlistId)
|
||||
{
|
||||
return CServer.GetPlaylist(playlistId);
|
||||
}
|
||||
|
||||
public void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
|
||||
{
|
||||
if (_CheckRight(EUserRights.AddSongToPlaylist)||_CheckRight(EUserRights.EditPlaylists))
|
||||
{
|
||||
CServer.AddSongToPlaylist(songId, playlistId, allowDuplicates);
|
||||
}
|
||||
}
|
||||
|
||||
public void RemoveSongFromPlaylist(int position, int playlistId, int songId)
|
||||
{
|
||||
if (_CheckRight(EUserRights.EditPlaylists))
|
||||
{
|
||||
CServer.RemoveSongFromPlaylist(position, playlistId, songId);
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveSongInPlaylist(int oldPosition, int newPosition, int playlistId, int songId)
|
||||
{
|
||||
if (_CheckRight(EUserRights.EditPlaylists))
|
||||
{
|
||||
CServer.MoveSongInPlaylist(oldPosition, newPosition, playlistId, songId);
|
||||
}
|
||||
}
|
||||
|
||||
public bool PlaylistContainsSong(int songId, int playlistId)
|
||||
{
|
||||
return CServer.PlaylistContainsSong(songId, playlistId);
|
||||
}
|
||||
|
||||
public SPlaylistSongInfo[] GetPlaylistSongs(int playlistId)
|
||||
{
|
||||
return CServer.GetPlaylistSongs(playlistId);
|
||||
}
|
||||
|
||||
public bool IsPlaylistEditable(int playlistId)
|
||||
{
|
||||
return _CheckRight(EUserRights.EditPlaylists);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region user management
|
||||
@@ -362,7 +414,8 @@ namespace ServerLib
|
||||
Guid sessionKey = _GetSession();
|
||||
if (sessionKey == Guid.Empty)
|
||||
{
|
||||
if (WebOperationContext.Current != null) {
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||
}
|
||||
@@ -370,7 +423,8 @@ namespace ServerLib
|
||||
}
|
||||
if (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles))
|
||||
{
|
||||
if (WebOperationContext.Current != null) {
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
||||
}
|
||||
@@ -379,6 +433,32 @@ namespace ServerLib
|
||||
CServer.SetUserRole(profileId, userRole);
|
||||
}
|
||||
|
||||
private static bool _CheckRight(EUserRights requestedRight)
|
||||
{
|
||||
Guid sessionKey = _GetSession();
|
||||
|
||||
if (sessionKey == Guid.Empty)
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!CSessionControl.RequestRight(sessionKey, requestedRight))
|
||||
{
|
||||
if (WebOperationContext.Current != null)
|
||||
{
|
||||
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
|
||||
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -109,6 +109,20 @@ namespace ServerLib
|
||||
|
||||
public delegate int GetCurrentSongIdDelegate();
|
||||
|
||||
public delegate SPlaylistInfo[] GetPlaylistsDelegate();
|
||||
|
||||
public delegate SPlaylistInfo GetPlaylistDelegate(int playlistId);
|
||||
|
||||
public delegate void AddSongToPlaylistDelegate(int songId, int playlistId, bool allowDuplicates);
|
||||
|
||||
public delegate void RemoveSongFromPlaylistDelegate(int position, int playlistId, int songId);
|
||||
|
||||
public delegate void MoveSongInPlaylistDelegate(int oldPosition, int newPosition, int playlistId, int songId);
|
||||
|
||||
public delegate bool PlaylistContainsSongDelegate(int songId, int playlistId);
|
||||
|
||||
public delegate SPlaylistSongInfo[] GetPlaylistSongsDelegate(int playlistId);
|
||||
|
||||
[DataContract]
|
||||
public struct SSongInfo
|
||||
{
|
||||
@@ -130,6 +144,30 @@ namespace ServerLib
|
||||
public int SongId { get; set; }
|
||||
}
|
||||
|
||||
public struct SPlaylistSongInfo
|
||||
{
|
||||
[DataMember]
|
||||
public SSongInfo Song;
|
||||
[DataMember]
|
||||
public int PlaylistId;
|
||||
[DataMember]
|
||||
public int PlaylistPosition;
|
||||
[DataMember]
|
||||
public int GameMode;
|
||||
}
|
||||
|
||||
public struct SPlaylistInfo
|
||||
{
|
||||
[DataMember]
|
||||
public int PlaylistId;
|
||||
[DataMember]
|
||||
public string PlaylistName;
|
||||
[DataMember]
|
||||
public int SongCount;
|
||||
[DataMember]
|
||||
public string LastChanged;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region user management
|
||||
|
||||
@@ -105,7 +105,7 @@ namespace ServerLib
|
||||
[WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/getSong?songId={songId}")]
|
||||
SOngInfo GetSong(int songId);
|
||||
SSongInfo GetSong(int songId);
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(Method = "GET",
|
||||
@@ -117,7 +117,58 @@ namespace ServerLib
|
||||
[WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/getAllSongs")]
|
||||
SOngInfo[] GetAllSongs();
|
||||
SSongInfo[] GetAllSongs();
|
||||
|
||||
#endregion
|
||||
|
||||
#region playlist
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/getPlaylists")]
|
||||
SPlaylistInfo[] GetPlaylists();
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/getPlaylist?id={playlistId}")]
|
||||
SPlaylistInfo GetPlaylist(int playlistId);
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/addSongToPlaylist?songId={songId}&playlistId={playlistId}&duplicates={allowDuplicates}")]
|
||||
void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates);
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/removeSongFromPlaylist?position={position}&playlistId={playlistId}&songId={songId}")]
|
||||
void RemoveSongFromPlaylist(int position, int playlistId, int songId);
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/moveSongInPlaylist?oldPosition={oldPosition}&newPosition={newPosition}&playlistId={playlistId}&songId={songId}")]
|
||||
void MoveSongInPlaylist(int oldPosition, int newPosition, int playlistId, int songId);
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/playlistContainsSong?songId={songId}&playlistId={playlistId}")]
|
||||
bool PlaylistContainsSong(int songId, int playlistId);
|
||||
|
||||
[OperationContract]
|
||||
[WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/getPlaylistSongs?playlistId={playlistId}")]
|
||||
SPlaylistSongInfo[] GetPlaylistSongs(int playlistId);
|
||||
|
||||
[OperationContract, WebInvoke(Method = "GET",
|
||||
ResponseFormat = WebMessageFormat.Json,
|
||||
UriTemplate = "/isPlaylistEditable?playlistId={playlistId}")]
|
||||
bool IsPlaylistEditable(int playlistId);
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ namespace ServerLib
|
||||
EditAllProfiles = 0x01,
|
||||
UploadPhotos = 0x02,
|
||||
ViewOtherProfiles = 0x04,
|
||||
UseKeyboard = 0x08
|
||||
UseKeyboard = 0x08,
|
||||
EditPlaylists = 0x16,
|
||||
AddSongToPlaylist = 0x32
|
||||
}
|
||||
}
|
||||
@@ -24,8 +24,10 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using ServerLib;
|
||||
using Vocaluxe.Lib.Input;
|
||||
using Vocaluxe.Lib.Playlist;
|
||||
using VocaluxeLib;
|
||||
using VocaluxeLib.Draw;
|
||||
using VocaluxeLib.Menu;
|
||||
using VocaluxeLib.Profile;
|
||||
using VocaluxeLib.Songs;
|
||||
using System.Security.Cryptography;
|
||||
@@ -307,7 +309,7 @@ namespace Vocaluxe.Base.Server
|
||||
photosOfThisRound.Add(filePath);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -383,17 +385,17 @@ namespace Vocaluxe.Base.Server
|
||||
|
||||
#region songs
|
||||
|
||||
private static SOngInfo _GetSong(int songId)
|
||||
private static SSongInfo _GetSong(int songId)
|
||||
{
|
||||
CSong song = CSongs.GetSong(songId);
|
||||
return _GetSongInfo(song, true);
|
||||
}
|
||||
|
||||
private static SOngInfo[] _GetAllSongs()
|
||||
private static SSongInfo[] _GetAllSongs()
|
||||
{
|
||||
var songs = CSongs.Songs;
|
||||
return (from s in songs
|
||||
select _GetSongInfo(s, false)).ToArray<SOngInfo>();
|
||||
select _GetSongInfo(s, false)).ToArray<SSongInfo>();
|
||||
}
|
||||
|
||||
private static int _GetCurrentSongId()
|
||||
@@ -406,9 +408,9 @@ namespace Vocaluxe.Base.Server
|
||||
return song.ID;
|
||||
}
|
||||
|
||||
private static SOngInfo _GetSongInfo(CSong song, bool includeCover)
|
||||
private static SSongInfo _GetSongInfo(CSong song, bool includeCover)
|
||||
{
|
||||
SOngInfo result = new SOngInfo();
|
||||
SSongInfo result = new SSongInfo();
|
||||
if (song != null)
|
||||
{
|
||||
result.Title = song.Title;
|
||||
@@ -428,6 +430,134 @@ namespace Vocaluxe.Base.Server
|
||||
|
||||
#endregion
|
||||
|
||||
#region playlist
|
||||
|
||||
public static SPlaylistInfo[] GetPlaylists()
|
||||
{
|
||||
return (from p in CPlaylists.Playlists
|
||||
select _GetPlaylistInfo(p)).ToArray();
|
||||
}
|
||||
|
||||
public static SPlaylistInfo GetPlaylist(int playlistId)
|
||||
{
|
||||
if (CPlaylists.Playlists.Length <= playlistId)
|
||||
{
|
||||
throw new ArgumentException("invalid playlistId");
|
||||
}
|
||||
return _GetPlaylistInfo(CPlaylists.Playlists[playlistId]);
|
||||
}
|
||||
|
||||
public static void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
|
||||
{
|
||||
if (CPlaylists.Playlists.Length <= playlistId)
|
||||
{
|
||||
throw new ArgumentException("invalid playlistId");
|
||||
}
|
||||
|
||||
if (allowDuplicates || PlaylistContainsSong(songId, playlistId))
|
||||
{
|
||||
CPlaylists.AddPlaylistSong(playlistId, songId);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException("song exists in this playlist");
|
||||
}
|
||||
}
|
||||
|
||||
public static void RemoveSongFromPlaylist(int position, int playlistId, int songId)
|
||||
{
|
||||
if (CPlaylists.Playlists.Length <= playlistId)
|
||||
{
|
||||
throw new ArgumentException("invalid playlistId");
|
||||
}
|
||||
if (!PlaylistContainsSong(songId, playlistId))
|
||||
{
|
||||
throw new ArgumentException("invalid songId");
|
||||
}
|
||||
if (CPlaylists.Playlists[playlistId].Songs.Count <= position || CPlaylists.Playlists[playlistId].Songs[position].SongID != songId)
|
||||
{
|
||||
throw new ArgumentException("invalid position");
|
||||
}
|
||||
CPlaylists.Playlists[playlistId].DeleteSong(position);
|
||||
}
|
||||
|
||||
public static void MoveSongInPlaylist(int oldPosition, int newPosition, int playlistId, int songId)
|
||||
{
|
||||
if (CPlaylists.Playlists.Length <= playlistId)
|
||||
{
|
||||
throw new ArgumentException("invalid playlistId");
|
||||
}
|
||||
if (!PlaylistContainsSong(songId, playlistId))
|
||||
{
|
||||
throw new ArgumentException("invalid songId");
|
||||
}
|
||||
if (CPlaylists.Playlists[playlistId].Songs.Count <= oldPosition || CPlaylists.Playlists[playlistId].Songs[oldPosition].SongID != songId)
|
||||
{
|
||||
throw new ArgumentException("invalid oldPosition");
|
||||
}
|
||||
if (CPlaylists.Playlists[playlistId].Songs.Count < newPosition )
|
||||
{
|
||||
throw new ArgumentException("invalid newPosition");
|
||||
}
|
||||
|
||||
CPlaylists.MovePlaylistSong(playlistId,oldPosition, newPosition);
|
||||
}
|
||||
|
||||
public static bool PlaylistContainsSong(int songId, int playlistId)
|
||||
{
|
||||
if (CPlaylists.Playlists.Length <= playlistId)
|
||||
{
|
||||
throw new ArgumentException("invalid playlistId");
|
||||
}
|
||||
return CPlaylists.Playlists[playlistId].Songs.Any(s => s.SongID == songId);
|
||||
}
|
||||
|
||||
public static SPlaylistSongInfo[] GetPlaylistSongs(int playlistId)
|
||||
{
|
||||
if (CPlaylists.Playlists.Length <= playlistId)
|
||||
{
|
||||
throw new ArgumentException("invalid playlistId");
|
||||
}
|
||||
|
||||
return _GetPlaylistSongInfos(CPlaylists.Playlists[playlistId]);
|
||||
}
|
||||
|
||||
private static SPlaylistSongInfo _GetPlaylistSongInfo(CPlaylistSong playlistSong, int playlistId, int playlistPos)
|
||||
{
|
||||
SPlaylistSongInfo result = new SPlaylistSongInfo();
|
||||
if (playlistSong != null)
|
||||
{
|
||||
result.PlaylistId = playlistId;
|
||||
result.GameMode = (int)playlistSong.GameMode;
|
||||
result.PlaylistPosition = playlistPos;
|
||||
result.Song = _GetSongInfo(CSongs.GetSong(playlistSong.SongID), true);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static SPlaylistSongInfo[] _GetPlaylistSongInfos(CPlaylistFile playlist)
|
||||
{
|
||||
SPlaylistSongInfo[] result = new SPlaylistSongInfo[playlist.Songs.Count];
|
||||
for (int i = 0; i < playlist.Songs.Count; i++)
|
||||
{
|
||||
result[i] = _GetPlaylistSongInfo(playlist.Songs[i], 1 /*TODO:PlaylistID???*/, i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static SPlaylistInfo _GetPlaylistInfo(CPlaylistFile playlist)
|
||||
{
|
||||
return new SPlaylistInfo
|
||||
{
|
||||
PlaylistId = 1, /*TODO: PlaylistId*/
|
||||
PlaylistName = playlist.PlaylistName,
|
||||
SongCount = playlist.Songs.Count,
|
||||
LastChanged = DateTime.Now.ToLongDateString()
|
||||
};
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region user management
|
||||
|
||||
private static void _SetPassword(int profileId, string newPassword)
|
||||
@@ -554,7 +684,7 @@ namespace Vocaluxe.Base.Server
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private static string _SaveImage(CBase64Image imageDate, string name, string folder)
|
||||
{
|
||||
Image avatarImage = imageDate.GetImage();
|
||||
|
||||
Reference in new issue
Block a user