IMPORTANT: Format of all files with Resharper

NO functional changes. If you have problems merging your changes, merge/rebase on previous commit then merge this. Conflicts can easily be resolved (take yours if in doubt)
After that merge next commits
This commit is contained in:
Flamefire committed 2014-02-26 00:36:00 +01:00
1 parent 3a110804d8
commit 149026ec32
57 files changed
+1242 -1099

No files matched your search

+111 -95
View File
@@ -1,4 +1,21 @@
using System;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
@@ -10,116 +27,115 @@ using System.Timers;
namespace ServerLib
{
public delegate void OnServerDiscovered(string IPAddress, string Hostname);
public delegate void OnServerDiscovered(string IPAddress, string Hostname);
public class CDiscover
{
public static readonly string sTimeout = "Timeout";
public static readonly string sFinished = "Finished";
public class CDiscover
{
public static readonly string sTimeout = "Timeout";
public static readonly string sFinished = "Finished";
private string _Keyword;
private string _BroadcastAddress;
private int _Port;
private string _Keyword;
private string _BroadcastAddress;
private int _Port;
private Thread _DiscoverThread;
private bool _DiscoverRunning;
private OnServerDiscovered _OnDiscovered;
private Thread _DiscoverThread;
private bool _DiscoverRunning;
private OnServerDiscovered _OnDiscovered;
private System.Timers.Timer _BroadcastTimer;
private System.Timers.Timer _BroadcastTimer;
public CDiscover(int Port, string Keyword, string BroadcastAddress = "255.255.255.255")
{
_BroadcastAddress = BroadcastAddress;
_Port = Port;
_Keyword = Keyword;
public CDiscover(int Port, string Keyword, string BroadcastAddress = "255.255.255.255")
{
_BroadcastAddress = BroadcastAddress;
_Port = Port;
_Keyword = Keyword;
_DiscoverRunning = false;
_BroadcastTimer = new System.Timers.Timer();
_BroadcastTimer.Elapsed += OnBroadcastEvent;
_BroadcastTimer.Interval = 2500;
}
_DiscoverRunning = false;
_BroadcastTimer = new System.Timers.Timer();
_BroadcastTimer.Elapsed += new ElapsedEventHandler(OnBroadcastEvent);
_BroadcastTimer.Interval = 2500;
}
public void StartBroadcasting()
{
_BroadcastTimer.Start();
}
public void StartBroadcasting()
{
_BroadcastTimer.Start();
}
public void Stop()
{
_BroadcastTimer.Stop();
_DiscoverRunning = false;
}
public void Stop()
{
_BroadcastTimer.Stop();
_DiscoverRunning = false;
}
public void Discover(OnServerDiscovered OnDiscovered, int Timeout = 5000)
{
if (_DiscoverRunning)
return;
public void Discover(OnServerDiscovered OnDiscovered, int Timeout = 5000)
{
if (_DiscoverRunning)
return;
_DiscoverRunning = true;
_DiscoverThread = new Thread(() => _Discover(Timeout));
_OnDiscovered = OnDiscovered;
_DiscoverThread.Start();
}
_DiscoverRunning = true;
_DiscoverThread = new Thread(() => _Discover(Timeout));
_OnDiscovered = OnDiscovered;
_DiscoverThread.Start();
}
private void OnBroadcastEvent(object source, ElapsedEventArgs e)
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
s.EnableBroadcast = true;
IPAddress broadcast = IPAddress.Parse(_BroadcastAddress);
byte[] sendbuf = Encoding.UTF8.GetBytes(_Keyword);
IPEndPoint ep = new IPEndPoint(broadcast, _Port);
private void OnBroadcastEvent(object source, ElapsedEventArgs e)
{
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
s.EnableBroadcast = true;
IPAddress broadcast = IPAddress.Parse(_BroadcastAddress);
byte[] sendbuf = Encoding.UTF8.GetBytes(_Keyword);
IPEndPoint ep = new IPEndPoint(broadcast, _Port);
s.SendTo(sendbuf, ep);
s.Close();
}
s.SendTo(sendbuf, ep);
s.Close();
}
private void _Discover(int Timeout)
{
UdpClient listener = null;
Stopwatch timer = new Stopwatch();
private void _Discover(int Timeout)
{
UdpClient listener = null;
Stopwatch timer = new Stopwatch();
List<string> knownServer = new List<string>();
bool foundSomething = false;
timer.Start();
while (_DiscoverRunning && timer.ElapsedMilliseconds < Timeout * 2)
{
try
{
listener = new UdpClient(_Port);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, _Port);
listener.Client.ReceiveTimeout = Timeout;
List<string> knownServer = new List<string>();
bool foundSomething = false;
timer.Start();
while (_DiscoverRunning && timer.ElapsedMilliseconds < Timeout * 2)
{
try
{
listener = new UdpClient(_Port);
IPEndPoint groupEP = new IPEndPoint(IPAddress.Any, _Port);
listener.Client.ReceiveTimeout = Timeout;
byte[] bytes = listener.Receive(ref groupEP);
string message = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
byte[] bytes = listener.Receive(ref groupEP);
string message = Encoding.UTF8.GetString(bytes, 0, bytes.Length);
foundSomething = true;
if (!knownServer.Contains(groupEP.Address.ToString()))
{
knownServer.Add(groupEP.Address.ToString());
if (_OnDiscovered != null)
{
IPHostEntry e = Dns.GetHostEntry(groupEP.Address);
string hostname = e.HostName;
foundSomething = true;
if (!knownServer.Contains(groupEP.Address.ToString()))
{
knownServer.Add(groupEP.Address.ToString());
if (_OnDiscovered != null)
{
IPHostEntry e = Dns.GetHostEntry(groupEP.Address);
string hostname = e.HostName;
_OnDiscovered(groupEP.Address.ToString(), hostname);
}
}
_OnDiscovered(groupEP.Address.ToString(), hostname);
}
}
listener.Close();
}
catch (Exception)
{
if (listener != null)
listener.Close();
}
}
_DiscoverRunning = false;
listener.Close();
}
catch (Exception)
{
if (listener != null)
listener.Close();
}
}
_DiscoverRunning = false;
if (!foundSomething)
_OnDiscovered(sTimeout, String.Empty);
else
_OnDiscovered(sFinished, String.Empty);
}
}
}
if (!foundSomething)
_OnDiscovered(sTimeout, String.Empty);
else
_OnDiscovered(sFinished, String.Empty);
}
}
}
+18 -1
View File
@@ -1,4 +1,21 @@
using System;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Diagnostics;
+18 -1
View File
@@ -1,4 +1,21 @@
using System;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Net;
using System.ServiceModel;
using System.ServiceModel.Web;
+44 -61
View File
@@ -1,4 +1,21 @@
using System;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Linq;
using System.Runtime.Serialization;
using System.Drawing;
@@ -10,64 +27,49 @@ namespace ServerLib
{
public delegate bool SendKeyEventDelegate(string key);
#region profile
public delegate SProfileData GetProfileDataDelegate(int profileId, bool isReadonly);
public delegate bool SendProfileDataDelegate(SProfileData profile);
public delegate SProfileData[] GetProfileListDelegate();
[DataContract]
public struct SProfileData
{
[DataMember]
public CBase64Image Avatar;
[DataMember]
public string PlayerName;
[DataMember]
public int Type;
[DataMember]
public int Difficulty;
[DataMember]
public int ProfileId;
[DataMember]
public bool IsEditable;
[DataMember]
public string Password;
[DataMember] public CBase64Image Avatar;
[DataMember] public string PlayerName;
[DataMember] public int Type;
[DataMember] public int Difficulty;
[DataMember] public int ProfileId;
[DataMember] public bool IsEditable;
[DataMember] public string Password;
}
#endregion
#region photo
public delegate bool SendPhotoDelegate(SPhotoData photo);
[DataContract]
public struct SPhotoData
{
[DataMember]
public CBase64Image Photo;
[DataMember] public CBase64Image Photo;
//Add infomation about the user who took this image??
}
#endregion
#region website
public delegate byte[] GetSiteFileDelegate(string filename);
public delegate CBase64Image GetDelayedImageDelegate(string hashedFilename);
#endregion
[DataContract]
public class CBase64Image
{
[DataMember]
private string base64Data = "";
[DataMember] private string base64Data = "";
[DataMember]
private string imageId = "";
[DataMember] private string imageId = "";
public CBase64Image(Image img, ImageFormat format)
{
@@ -97,28 +99,21 @@ namespace ServerLib
Match match = Regex.Match(base64Data, "(?<=data:image/)[a-zA-Z]+(?=;base64)");
return match.Success ? match.Groups[0].Value : "";
}
}
#region songs
public delegate SSongInfo GetSongDelegate(int songId);
public delegate SSongInfo[] GetAllSongsDelegate();
public delegate int GetCurrentSongIdDelegate();
[DataContract]
public struct SSongInfo
{
[DataMember]
public string Title;
[DataMember]
public string Artist;
[DataMember]
public CBase64Image Cover;
[DataMember] public string Title;
[DataMember] public string Artist;
[DataMember] public CBase64Image Cover;
[DataMember]
public string Genre { get; set; }
[DataMember]
@@ -130,7 +125,6 @@ namespace ServerLib
[DataMember]
public int SongId { get; set; }
}
#endregion
#region playlists
@@ -155,33 +149,23 @@ namespace ServerLib
[DataContract]
public struct SPlaylistSongInfo
{
[DataMember]
public SSongInfo Song;
[DataMember]
public int PlaylistId;
[DataMember]
public int PlaylistPosition;
[DataMember]
public int GameMode;
[DataMember] public SSongInfo Song;
[DataMember] public int PlaylistId;
[DataMember] public int PlaylistPosition;
[DataMember] public int GameMode;
}
[DataContract]
public struct SPlaylistInfo
{
[DataMember]
public int PlaylistId;
[DataMember]
public string PlaylistName;
[DataMember]
public int SongCount;
[DataMember]
public string LastChanged;
[DataMember] public int PlaylistId;
[DataMember] public string PlaylistName;
[DataMember] public int SongCount;
[DataMember] public string LastChanged;
}
#endregion
#region user management
public delegate void SetPasswordDelegate(int profileId, string newPassword);
public delegate bool ValidatePasswordDelegate(int profileId, string password);
@@ -191,6 +175,5 @@ namespace ServerLib
public delegate void SetUserRoleDelegate(int profileId, int userRole);
public delegate int GetUserIdFromUsernameDelegate(string username);
#endregion
}
}
+78 -73
View File
@@ -1,4 +1,21 @@
using System;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.IO;
using System.ServiceModel;
using System.ServiceModel.Web;
@@ -8,207 +25,195 @@ namespace ServerLib
[ServiceContract]
public interface ICWebservice
{
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/sendKeyEvent?key={key}")]
void SendKeyEvent(string key);
#region profile
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getOwnProfileId")]
int GetOwnProfileId();
[OperationContract]
[WebInvoke(Method = "POST",
[OperationContract, WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/sendProfile")]
void SendProfile(SProfileData profile);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getProfile?profileId={profileId}")]
SProfileData GetProfile(int profileId);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getProfileList")]
SProfileData[] GetProfileList();
#endregion
#region photo
[OperationContract]
[WebInvoke(Method = "POST",
[OperationContract, WebInvoke(Method = "POST",
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/sendPhoto")]
void SendPhoto(SPhotoData photo);
#endregion
#region website
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/login?username={username}&password={password}")]
Guid Login(string username, string password);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "")]
Stream Index();
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/js/{filename}")]
Stream GetJsFile(String filename);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/css/{filename}")]
Stream GetCssFile(String filename);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/css/images/{filename}")]
Stream GetCssImageFile(String filename);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/img/{filename}")]
Stream GetImgFile(String filename);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/locales/{filename}")]
Stream GetLocaleFile(String filename);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/delayedImage?id={id}")]
CBase64Image GetDelayedImage(String id);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/isServerOnline")]
bool IsServerOnline();
#endregion
#region songs
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getSong?songId={songId}")]
SSongInfo GetSong(int songId);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getCurrentSongId")]
int GetCurrentSongId();
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getAllSongs")]
SSongInfo[] GetAllSongs();
#endregion
#region playlist
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getPlaylists")]
SPlaylistInfo[] GetPlaylists();
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getPlaylist?id={playlistId}")]
SPlaylistInfo GetPlaylist(int playlistId);
[OperationContract]
[WebInvoke(Method = "GET",
[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",
[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",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/moveSongInPlaylist?newPosition={newPosition}&playlistId={playlistId}&songId={songId}")]
void MoveSongInPlaylist(int newPosition, int playlistId, int songId);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/playlistContainsSong?songId={songId}&playlistId={playlistId}")]
bool PlaylistContainsSong(int songId, int playlistId);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getPlaylistSongs?playlistId={playlistId}")]
SPlaylistSongInfo[] GetPlaylistSongs(int playlistId);
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/removePlaylist?playlistId={playlistId}")]
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/removePlaylist?playlistId={playlistId}")]
void RemovePlaylist(int playlistId);
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/addPlaylist?playlistName={playlistName}")]
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/addPlaylist?playlistName={playlistName}")]
int AddPlaylist(string playlistName);
#endregion
#region user management
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getUserRole?profileId={profileId}")]
int GetUserRole(int profileId);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/setUserRole?profileId={profileId}&userRole={userRole}")]
void SetUserRole(int profileId, int userRole);
[OperationContract]
[WebInvoke(Method = "GET",
[OperationContract, WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/hasUserRight?right={right}")]
bool HasUserRight(int right);
#endregion
}
}
@@ -1,10 +1,28 @@
using System.Reflection;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Allgemeine Informationen über eine Assembly werden über die folgenden
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
// die mit einer Assembly verknüpft sind.
[assembly: AssemblyTitle("ClientServerLib")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
@@ -17,9 +35,11 @@ using System.Runtime.InteropServices;
// Durch Festlegen von ComVisible auf "false" werden die Typen in dieser Assembly unsichtbar
// für COM-Komponenten. Wenn Sie auf einen Typ in dieser Assembly von
// COM zugreifen müssen, legen Sie das ComVisible-Attribut für diesen Typ auf "true" fest.
[assembly: ComVisible(false)]
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
[assembly: Guid("53f89645-1948-420f-b64a-7dc705ca8820")]
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
@@ -32,5 +52,6 @@ using System.Runtime.InteropServices;
// Sie können alle Werte angeben oder die standardmäßigen Build- und Revisionsnummern
// übernehmen, indem Sie "*" eingeben:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
+26 -9
View File
@@ -1,22 +1,39 @@
using System;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
namespace ServerLib
{
internal class CSession
class CSession
{
readonly Guid _ID;
private readonly Guid _ID;
public Guid Id
{
get { return _ID; }
}
readonly int _ProfileId;
private readonly int _ProfileId;
public int ProfileId
{
get { return _ProfileId; }
}
readonly EUserRoles _Roles;
private readonly EUserRoles _Roles;
internal EUserRoles Roles
{
get { return _Roles; }
@@ -24,9 +41,9 @@ namespace ServerLib
public CSession(Guid id, int profileId, EUserRoles roles)
{
this._ID = id;
this._ProfileId = profileId;
this._Roles = roles;
_ID = id;
_ProfileId = profileId;
_Roles = roles;
}
}
}
}
@@ -1,19 +1,34 @@
using System;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
namespace ServerLib
{
internal static class CSessionControl
static class CSessionControl
{
private static readonly Dictionary<Guid, CSession> _ActiveSessions = new Dictionary<Guid, CSession>();
public static Guid OpenSession(string userName, string password)
{
if (!_ValidateUserAndPassword(userName, password))
{
return Guid.Empty;
}
Guid newId = Guid.NewGuid();
int id = _GetProfileIdFormUsername(userName);
@@ -42,27 +57,23 @@ namespace ServerLib
internal static void InvalidateSessions(int profileId)
{
foreach (var s in (from kv in _ActiveSessions
where kv.Value.ProfileId == profileId
select kv).ToList())
{
foreach (KeyValuePair<Guid, CSession> s in (from kv in _ActiveSessions
where kv.Value.ProfileId == profileId
select kv).ToList())
_ActiveSessions.Remove(s.Key);
}
}
internal static bool RequestRight(Guid sessionId, EUserRights requestedRight)
{
return ((CUserRoleControl.GetUserRightsFromUserRole(_ActiveSessions[sessionId].Roles)
.HasFlag(requestedRight)));
.HasFlag(requestedRight)));
}
internal static int GetUserIdFromSession(Guid sessionId)
{
if (!_ActiveSessions.ContainsKey(sessionId))
{
return -1;
}
return _ActiveSessions[sessionId].ProfileId;
}
}
}
}
+20 -3
View File
@@ -1,9 +1,26 @@
using System;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
namespace ServerLib
{
[Flags]
internal enum EUserRights
enum EUserRights
{
None = 0,
EditAllProfiles = 1,
@@ -16,4 +33,4 @@ namespace ServerLib
DeletePlaylists = 128,
RemoveSongsFromPlaylists = 256
}
}
}
@@ -1,46 +1,77 @@
using System.Collections.Generic;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System.Collections.Generic;
using System.Linq;
namespace ServerLib
{
internal static class CUserRoleControl
static class CUserRoleControl
{
private static readonly Dictionary<EUserRoles, EUserRights> _RoleRightsMapping = new Dictionary<EUserRoles, EUserRights> {
{EUserRoles.TR_USERROLE_ADMIN,
(EUserRights.EditAllProfiles|
EUserRights.UploadPhotos|
EUserRights.ViewOtherProfiles|
EUserRights.UseKeyboard|
EUserRights.AddSongToPlaylist|
EUserRights.ReorderPlaylists|
EUserRights.CreatePlaylists|
EUserRights.DeletePlaylists|
EUserRights.RemoveSongsFromPlaylists)},
{EUserRoles.TR_USERROLE_GUEST,
EUserRights.None},
{EUserRoles.TR_USERROLE_NORMAL,
(EUserRights.UploadPhotos|
EUserRights.ViewOtherProfiles)},
{EUserRoles.TR_USERROLE_KEYBOARDUSER,
EUserRights.UseKeyboard},
{EUserRoles.TR_USERROLE_ADDSONGSUSER,
EUserRights.AddSongToPlaylist},
{EUserRoles.TR_USERROLE_PLAYLISTEDITOR,
(EUserRights.AddSongToPlaylist|
EUserRights.ReorderPlaylists|
EUserRights.CreatePlaylists|
EUserRights.DeletePlaylists|
EUserRights.RemoveSongsFromPlaylists)},
{EUserRoles.TR_USERROLE_PROFILEEDITOR,
EUserRights.EditAllProfiles}
};
private static readonly Dictionary<EUserRoles, EUserRights> _RoleRightsMapping = new Dictionary<EUserRoles, EUserRights>
{
{
EUserRoles.TR_USERROLE_ADMIN,
(EUserRights.EditAllProfiles |
EUserRights.UploadPhotos |
EUserRights.ViewOtherProfiles |
EUserRights.UseKeyboard |
EUserRights.AddSongToPlaylist |
EUserRights.ReorderPlaylists |
EUserRights.CreatePlaylists |
EUserRights.DeletePlaylists |
EUserRights.RemoveSongsFromPlaylists)
},
{
EUserRoles.TR_USERROLE_GUEST,
EUserRights.None
},
{
EUserRoles.TR_USERROLE_NORMAL,
(EUserRights.UploadPhotos |
EUserRights.ViewOtherProfiles)
},
{
EUserRoles.TR_USERROLE_KEYBOARDUSER,
EUserRights.UseKeyboard
},
{
EUserRoles.TR_USERROLE_ADDSONGSUSER,
EUserRights.AddSongToPlaylist
},
{
EUserRoles.TR_USERROLE_PLAYLISTEDITOR,
(EUserRights.AddSongToPlaylist |
EUserRights.ReorderPlaylists |
EUserRights.CreatePlaylists |
EUserRights.DeletePlaylists |
EUserRights.RemoveSongsFromPlaylists)
},
{
EUserRoles.TR_USERROLE_PROFILEEDITOR,
EUserRights.EditAllProfiles
}
};
internal static EUserRights GetUserRightsFromUserRole(EUserRoles userRole)
{
return _RoleRightsMapping.Where(role => userRole.HasFlag(role.Key))
.Select(role => role.Value)
.Aggregate(EUserRights.None, (current, r) => current | r);
.Select(role => role.Value)
.Aggregate(EUserRights.None, (current, r) => current | r);
}
}
}
}
+20 -3
View File
@@ -1,9 +1,26 @@
using System;
#region license
// This file is part of Vocaluxe.
//
// Vocaluxe 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 3 of the License, or
// (at your option) any later version.
//
// Vocaluxe 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 Vocaluxe. If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
namespace ServerLib
{
[Flags]
internal enum EUserRoles
enum EUserRoles
{
TR_USERROLE_GUEST = 0,
TR_USERROLE_NORMAL = 1,
@@ -13,4 +30,4 @@ namespace ServerLib
TR_USERROLE_PLAYLISTEDITOR = 16,
TR_USERROLE_PROFILEEDITOR = 32
}
}
}