diff --git a/ServerLib/CDiscover.cs b/ServerLib/CDiscover.cs
deleted file mode 100644
index 1fef7ac1..00000000
--- a/ServerLib/CDiscover.cs
+++ /dev/null
@@ -1,138 +0,0 @@
-#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 .
-#endregion
-
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Net;
-using System.Net.Sockets;
-using System.Text;
-using System.Threading;
-using System.Timers;
-
-namespace ServerLib
-{
- public delegate void OnServerDiscovered(string ipAddress, string hostname);
-
- public class CDiscover
- {
- public const string Timeout = "Timeout";
- public const string Finished = "Finished";
-
- private readonly string _Keyword;
- private readonly string _BroadcastAddress;
- private readonly int _Port;
-
- private Thread _DiscoverThread;
- private bool _DiscoverRunning;
- private OnServerDiscovered _OnDiscovered;
-
- private readonly System.Timers.Timer _BroadcastTimer;
-
- 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;
- }
-
- public void StartBroadcasting()
- {
- _BroadcastTimer.Start();
- }
-
- public void Stop()
- {
- _BroadcastTimer.Stop();
- _DiscoverRunning = false;
- }
-
- public void Discover(OnServerDiscovered onDiscovered, int timeout = 5000)
- {
- if (_DiscoverRunning)
- return;
-
- _DiscoverRunning = true;
- _DiscoverThread = new Thread(() => _Discover(timeout)) {Name = "Client discover"};
- _OnDiscovered = onDiscovered;
- _DiscoverThread.Start();
- }
-
- private void _OnBroadcastEvent(object source, ElapsedEventArgs e)
- {
- Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) {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();
- }
-
- private void _Discover(int timeout)
- {
- UdpClient listener = null;
- Stopwatch timer = new Stopwatch();
-
- List knownServer = new List();
- 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);
-
- 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);
- }
- }
-
- listener.Close();
- }
- catch (Exception)
- {
- if (listener != null)
- listener.Close();
- }
- }
- _DiscoverRunning = false;
-
- if (_OnDiscovered != null)
- _OnDiscovered(!foundSomething ? Timeout : Finished, String.Empty);
- }
- }
-}
\ No newline at end of file
diff --git a/ServerLib/CServer.cs b/ServerLib/CServer.cs
deleted file mode 100644
index 2971f7af..00000000
--- a/ServerLib/CServer.cs
+++ /dev/null
@@ -1,225 +0,0 @@
-#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 .
-#endregion
-
-using System;
-#if WIN
-using System.Diagnostics;
-#endif
-using System.ServiceModel;
-using System.ServiceModel.Web;
-using System.Net;
-using System.Windows.Forms;
-
-namespace ServerLib
-{
- public class CServer
- {
- private ServiceHost _Host;
- private Uri _BaseAddress;
- private bool _Encrypted;
-
- public static SendKeyEventDelegate SendKeyEvent { internal get; set; }
- public static SendKeyStringEventDelegate SendKeyStringEvent { internal get; set; }
-
- #region profile
- public static GetProfileDataDelegate GetProfileData { internal get; set; }
-
- public static SendProfileDataDelegate SendProfileData { internal get; set; }
-
- public static GetProfileListDelegate GetProfileList { internal get; set; }
- #endregion
-
- #region photo
- public static SendPhotoDelegate SendPhoto { get; set; }
- #endregion
-
- #region website
- public static GetSiteFileDelegate GetSiteFile { internal get; set; }
-
- public static GetDelayedImageDelegate GetDelayedImage { internal get; set; }
-
- public static GetServerVersionDelegate GetServerVersion { internal get; set; }
- #endregion
-
- #region songs
- public static GetSongDelegate GetSong { internal get; set; }
-
- public static GetAllSongsDelegate GetAllSongs { internal get; set; }
-
- public static GetCurrentSongIdDelegate GetCurrentSongId { internal get; set; }
-
- public static GetMp3PathDelegate GetMp3Path { internal get; set; }
- #endregion
-
- #region playlist
- public static GetPlaylistsDelegate GetPlaylists { internal get; set; }
-
- public static GetPlaylistDelegate GetPlaylist { internal get; set; }
-
- public static AddSongToPlaylistDelegate AddSongToPlaylist { internal get; set; }
-
- public static RemoveSongFromPlaylistDelegate RemoveSongFromPlaylist { internal get; set; }
-
- public static MoveSongInPlaylistDelegate MoveSongInPlaylist { internal get; set; }
-
- public static PlaylistContainsSongDelegate PlaylistContainsSong { internal get; set; }
-
- public static GetPlaylistSongsDelegate GetPlaylistSongs { internal get; set; }
-
- public static RemovePlaylistDelegate RemovePlaylist { internal get; set; }
-
- public static AddPlaylistDelegate AddPlaylist { internal get; set; }
- #endregion
-
- #region user management
- public static ValidatePasswordDelegate ValidatePassword { internal get; set; }
-
- public static GetUserRoleDelegate GetUserRole { internal get; set; }
-
- public static SetUserRoleDelegate SetUserRole { internal get; set; }
-
- public static GetUserIdFromUsernameDelegate GetUserIdFromUsername { internal get; set; }
- #endregion
-
- public CServer(int port, bool encrypted)
- {
- _Init(port, encrypted);
- }
-
- public string GetBaseAddress()
- {
- return _BaseAddress.AbsoluteUri;
-
- /*IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName());
- foreach (IPAddress ip in ips)
- {
- if (ip.AddressFamily == AddressFamily.InterNetwork)
- return ip.ToString();
- }
- return "";*/
- }
-
- public bool IsRunning()
- {
- return _Host.State == CommunicationState.Opened;
- }
-
- #region server control
- private void _Init(int port, bool encrypted)
- {
- string hostname = Dns.GetHostName();
- string protocol = (encrypted) ? "https" : "http";
- _BaseAddress = new Uri(protocol + "://" + hostname + ":" + port + "/");
- _Encrypted = encrypted;
- _Host = new WebServiceHost(typeof(CWebservice), _BaseAddress);
-
- WebHttpBinding wb = new WebHttpBinding
- {
- MaxReceivedMessageSize = 10485760,
- MaxBufferSize = 10485760,
- MaxBufferPoolSize = 10485760,
- ReaderQuotas = {MaxStringContentLength = 10485760, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760}
- };
- if (encrypted)
- {
- wb.Security.Mode = WebHttpSecurityMode.Transport;
- wb.Security.Transport = new HttpTransportSecurity {ClientCredentialType = HttpClientCredentialType.None};
- }
- _Host.AddServiceEndpoint(typeof(ICWebservice), wb, "");
- }
-
- public void Start()
- {
- try
- {
- /*ServiceMetadataBehavior smb = new ServiceMetadataBehavior();
- smb.MetadataExporter.PolicyVersion = PolicyVersion.Policy15;
- smb.HttpGetEnabled = true;
- host.Description.Behaviors.Add(smb);*/
- _RegisterUrlAndCert(_BaseAddress.Port, false);
- _Host.Open();
- }
- catch (CommunicationException e)
- {
- if (e is AddressAccessDeniedException || e is AddressAlreadyInUseException)
- {
- _RegisterUrlAndCert(_BaseAddress.Port, true);
- try
- {
- _Host.Abort();
- _Init(_BaseAddress.Port, _Encrypted);
- _Host.Open();
- }
- catch (CommunicationException)
- {
- _Host.Abort();
- MessageBox.Show("Problem while initialization of webserver. You may try a different port (Change it in config.xml)");
- }
- }
- else
- _Host.Abort();
- }
- }
-
- public void Stop()
- {
- try
- {
- _Host.Close();
- }
- catch (CommunicationException)
- {
- _Host.Abort();
- }
- }
-
- private void _RegisterUrlAndCert(int port, bool reserve)
- {
-#if WIN
-
- ProcessStartInfo info = new ProcessStartInfo
- {
- FileName = "VocaluxeServerConfig.exe",
- WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory,
- Arguments = AppDomain.CurrentDomain.FriendlyName + " " + port + " " + (_Encrypted ? "true" : "false") + (reserve ? " true" : ""),
- UseShellExecute = true,
- CreateNoWindow = true,
- WindowStyle = ProcessWindowStyle.Hidden,
- };
- try
- {
- using (Process p = Process.Start(info))
- {
- p.WaitForExit();
- if (p.ExitCode != 0)
- MessageBox.Show("Registering the Server failed (Code " + p.ExitCode + ")!\r\nThe Server might not work correctly.");
- p.Close();
- }
- }
- catch (Exception e)
- {
- MessageBox.Show("Registering the Server failed (" + e + ")!\r\nThe Server might not work correctly.");
- }
-#else
-
- //Required?
-
-#endif
- }
- #endregion
- }
-}
\ No newline at end of file
diff --git a/ServerLib/DataStructs.cs b/ServerLib/DataStructs.cs
deleted file mode 100644
index ebec95c9..00000000
--- a/ServerLib/DataStructs.cs
+++ /dev/null
@@ -1,186 +0,0 @@
-#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 .
-#endregion
-
-using System;
-using System.Linq;
-using System.Runtime.Serialization;
-using System.Drawing;
-using System.IO;
-using System.Drawing.Imaging;
-using System.Text.RegularExpressions;
-
-namespace ServerLib
-{
- public delegate bool SendKeyEventDelegate(string key);
-
- public delegate bool SendKeyStringEventDelegate(string keyString, bool isShiftPressed, bool isAltPressed, bool isCtrlPressed);
-
- #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;
- }
- #endregion
-
- #region photo
- public delegate bool SendPhotoDelegate(SPhotoData photo);
-
- [DataContract]
- public struct SPhotoData
- {
- [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);
-
- public delegate String GetServerVersionDelegate();
- #endregion
-
- [DataContract]
- public class CBase64Image
- {
- // ReSharper disable InconsistentNaming
- [DataMember] private string base64Data = "";
- [DataMember] private string imageId = "";
- // ReSharper restore InconsistentNaming
-
- public CBase64Image(Image img, ImageFormat format)
- {
- MemoryStream ms = new MemoryStream();
- img.Save(ms, format);
- string formatString = ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatID == format.Guid).FilenameExtension.Replace("*.", "").ToLower();
- base64Data = "data:image/" + formatString + ";base64," + Convert.ToBase64String(ms.ToArray());
- }
-
- public CBase64Image(string imageId)
- {
- this.imageId = imageId;
- }
-
- public Image GetImage()
- {
- string onlyBase64Data = base64Data.Substring(base64Data.IndexOf(";base64,") + (";base64,").Length);
- byte[] imageData = Convert.FromBase64String(onlyBase64Data);
- MemoryStream ms = new MemoryStream(imageData, 0, imageData.Length);
- ms.Write(imageData, 0, imageData.Length);
- Image image = Image.FromStream(ms, true);
- return image;
- }
-
- public string GetImageType()
- {
- 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();
-
- public delegate string GetMp3PathDelegate(int songId);
-
- [DataContract]
- public struct SSongInfo
- {
- [DataMember] public string Title;
- [DataMember] public string Artist;
- [DataMember] public CBase64Image Cover;
- [DataMember]
- public string Genre { get; set; }
- [DataMember]
- public string Language { get; set; }
- [DataMember]
- public string Year { get; set; }
- [DataMember]
- public bool IsDuet { get; set; }
- [DataMember]
- public int SongId { get; set; }
- }
- #endregion
-
- #region playlists
- public delegate SPlaylistData[] GetPlaylistsDelegate();
-
- public delegate SPlaylistData 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 newPosition, int playlistId, int songId);
-
- public delegate bool PlaylistContainsSongDelegate(int songId, int playlistId);
-
- public delegate SPlaylistSongInfo[] GetPlaylistSongsDelegate(int playlistId);
-
- public delegate void RemovePlaylistDelegate(int playlistId);
-
- public delegate int AddPlaylistDelegate(string playlistName);
-
- [DataContract]
- public struct SPlaylistSongInfo
- {
- [DataMember] public SSongInfo Song;
- [DataMember] public int PlaylistId;
- [DataMember] public int PlaylistPosition;
- [DataMember] public int GameMode;
- }
-
- [DataContract]
- public struct SPlaylistData
- {
- [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);
-
- public delegate int GetUserRoleDelegate(int profileId);
-
- public delegate void SetUserRoleDelegate(int profileId, int userRole);
-
- public delegate int GetUserIdFromUsernameDelegate(string username);
- #endregion
-}
\ No newline at end of file
diff --git a/ServerLib/Properties/AssemblyInfo.cs b/ServerLib/Properties/AssemblyInfo.cs
deleted file mode 100644
index 2acbaa9a..00000000
--- a/ServerLib/Properties/AssemblyInfo.cs
+++ /dev/null
@@ -1,56 +0,0 @@
-#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 .
-#endregion
-
-using System.Reflection;
-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("")]
-[assembly: AssemblyCompany("")]
-[assembly: AssemblyProduct("ClientServerLib")]
-[assembly: AssemblyCopyright("Copyright © 2013")]
-[assembly: AssemblyTrademark("")]
-[assembly: AssemblyCulture("")]
-
-// 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:
-//
-// Hauptversion
-// Nebenversion
-// Buildnummer
-// Revision
-//
-// 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")]
\ No newline at end of file
diff --git a/ServerLib/ServerLib.csproj b/ServerLib/ServerLib.csproj
deleted file mode 100644
index 9cb8022d..00000000
--- a/ServerLib/ServerLib.csproj
+++ /dev/null
@@ -1,89 +0,0 @@
-
-
-
- Debug
- AnyCPU
- 8.0.30703
- 2.0
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}
- Library
- Properties
- ServerLib
- ServerLib
- v4.0
- 512
-
-
-
-
- true
- ..\Output\
- TRACE;DEBUG;WIN;
- full
- AnyCPU
- prompt
- MinimumRecommendedRules.ruleset
-
-
- true
- ..\Output\
- TRACE;DEBUG;LINUX;
- full
- AnyCPU
- prompt
- MinimumRecommendedRules.ruleset
-
-
- ..\Output\
- TRACE;WIN;
- true
- pdbonly
- AnyCPU
- prompt
- MinimumRecommendedRules.ruleset
-
-
- ..\Output\
- TRACE;LINUX;
- true
- pdbonly
- AnyCPU
- prompt
- MinimumRecommendedRules.ruleset
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/ServerLib/bin/Newtonsoft.Json.dll b/ServerLib/bin/Newtonsoft.Json.dll
deleted file mode 100644
index a1c39382..00000000
Binary files a/ServerLib/bin/Newtonsoft.Json.dll and /dev/null differ
diff --git a/Vocaluxe.sln b/Vocaluxe.sln
index b3499d21..f8552419 100644
--- a/Vocaluxe.sln
+++ b/Vocaluxe.sln
@@ -1,11 +1,12 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 2012
+# Visual Studio 2013
+VisualStudioVersion = 12.0.31101.0
+MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vocaluxe", "Vocaluxe\Vocaluxe.csproj", "{2A1E0F2D-5392-4BB7-B0A1-A9DFA13E79FF}"
ProjectSection(ProjectDependencies) = postProject
{55F89808-4E79-4FFE-BC13-48258913F5C9} = {55F89808-4E79-4FFE-BC13-48258913F5C9}
{6F3E1874-F28A-40E9-AFBD-31934D593678} = {6F3E1874-F28A-40E9-AFBD-31934D593678}
{6F3E1874-F28A-40E9-AFBD-31934D593679} = {6F3E1874-F28A-40E9-AFBD-31934D593679}
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3} = {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}
{D2B6DDEF-E0E1-4DDF-A73A-E6ACEF5C95EC} = {D2B6DDEF-E0E1-4DDF-A73A-E6ACEF5C95EC}
{5A4053F1-5AD5-441F-B254-D97A088127B6} = {5A4053F1-5AD5-441F-B254-D97A088127B6}
{54A48AF7-515C-4EDD-B395-2BFFA096050A} = {54A48AF7-515C-4EDD-B395-2BFFA096050A}
@@ -19,8 +20,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PartyModeChallenge", "Party
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PartyModeChallengeMedley", "PartyModes\PartyModeChallengeMedley\PartyModeChallengeMedley.csproj", "{6F3E1874-F28A-40E9-AFBD-31934D593678}"
EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ServerLib", "ServerLib\ServerLib.csproj", "{EC5167E4-CCFB-4CEE-987C-CF816F1062A3}"
-EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WebserverInitalConfig", "WebserverInitalConfig\WebserverInitalConfig.csproj", "{55F89808-4E79-4FFE-BC13-48258913F5C9}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PitchTracker", "PitchTracker\PitchTracker.vcxproj", "{54A48AF7-515C-4EDD-B395-2BFFA096050A}"
@@ -146,26 +145,6 @@ Global
{6F3E1874-F28A-40E9-AFBD-31934D593678}.ReleaseWin|x64.Build.0 = ReleaseWin|Any CPU
{6F3E1874-F28A-40E9-AFBD-31934D593678}.ReleaseWin|x86.ActiveCfg = ReleaseWin|Any CPU
{6F3E1874-F28A-40E9-AFBD-31934D593678}.ReleaseWin|x86.Build.0 = ReleaseWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugLinux|x64.ActiveCfg = DebugLinux|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugLinux|x64.Build.0 = DebugLinux|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugLinux|x86.ActiveCfg = DebugLinux|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugLinux|x86.Build.0 = DebugLinux|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|x64.ActiveCfg = DebugWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|x64.Build.0 = DebugWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|x86.ActiveCfg = DebugWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.DebugWin|x86.Build.0 = DebugWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.InstallerWin|x64.ActiveCfg = ReleaseWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.InstallerWin|x64.Build.0 = ReleaseWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.InstallerWin|x86.ActiveCfg = ReleaseWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.InstallerWin|x86.Build.0 = ReleaseWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|x64.ActiveCfg = ReleaseLinux|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|x64.Build.0 = ReleaseLinux|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|x86.ActiveCfg = ReleaseLinux|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseLinux|x86.Build.0 = ReleaseLinux|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|x64.ActiveCfg = ReleaseWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|x64.Build.0 = ReleaseWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|x86.ActiveCfg = ReleaseWin|Any CPU
- {EC5167E4-CCFB-4CEE-987C-CF816F1062A3}.ReleaseWin|x86.Build.0 = ReleaseWin|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugLinux|x64.ActiveCfg = Debug|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugLinux|x86.ActiveCfg = Debug|Any CPU
{55F89808-4E79-4FFE-BC13-48258913F5C9}.DebugWin|x64.ActiveCfg = Debug|Any CPU
diff --git a/Vocaluxe.sln.DotSettings b/Vocaluxe.sln.DotSettings
index a260a4fb..04c102da 100644
--- a/Vocaluxe.sln.DotSettings
+++ b/Vocaluxe.sln.DotSettings
@@ -14,7 +14,9 @@
<?xml version="1.0" encoding="utf-16"?><Profile name="Simple Reformat"><CSOptimizeUsings><OptimizeUsings>False</OptimizeUsings><EmbraceInRegion>False</EmbraceInRegion><RegionName></RegionName></CSOptimizeUsings><CSReformatCode>True</CSReformatCode><StyleCop.Documentation><SA1600ElementsMustBeDocumented>False</SA1600ElementsMustBeDocumented><SA1604ElementDocumentationMustHaveSummary>False</SA1604ElementDocumentationMustHaveSummary><SA1609PropertyDocumentationMustHaveValueDocumented>False</SA1609PropertyDocumentationMustHaveValueDocumented><SA1611ElementParametersMustBeDocumented>False</SA1611ElementParametersMustBeDocumented><SA1615ElementReturnValueMustBeDocumented>False</SA1615ElementReturnValueMustBeDocumented><SA1617VoidReturnValueMustNotBeDocumented>False</SA1617VoidReturnValueMustNotBeDocumented><SA1618GenericTypeParametersMustBeDocumented>False</SA1618GenericTypeParametersMustBeDocumented><SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes>False</SA1626SingleLineCommentsMustNotUseDocumentationStyleSlashes><SA1628DocumentationTextMustBeginWithACapitalLetter>False</SA1628DocumentationTextMustBeginWithACapitalLetter><SA1629DocumentationTextMustEndWithAPeriod>False</SA1629DocumentationTextMustEndWithAPeriod><SA1633SA1641UpdateFileHeader>Ignore</SA1633SA1641UpdateFileHeader><SA1639FileHeaderMustHaveSummary>False</SA1639FileHeaderMustHaveSummary><SA1642ConstructorSummaryDocumentationMustBeginWithStandardText>False</SA1642ConstructorSummaryDocumentationMustBeginWithStandardText><SA1643DestructorSummaryDocumentationMustBeginWithStandardText>False</SA1643DestructorSummaryDocumentationMustBeginWithStandardText><SA1644DocumentationHeadersMustNotContainBlankLines>False</SA1644DocumentationHeadersMustNotContainBlankLines></StyleCop.Documentation><StyleCop.Spacing><SA1001CommasMustBeSpacedCorrectly>False</SA1001CommasMustBeSpacedCorrectly><SA1005SingleLineCommentsMustBeginWithSingleSpace>False</SA1005SingleLineCommentsMustBeginWithSingleSpace><SA1006PreprocessorKeywordsMustNotBePrecededBySpace>True</SA1006PreprocessorKeywordsMustNotBePrecededBySpace><SA1021NegativeSignsMustBeSpacedCorrectly>True</SA1021NegativeSignsMustBeSpacedCorrectly><SA1022PositiveSignsMustBeSpacedCorrectly>True</SA1022PositiveSignsMustBeSpacedCorrectly><SA1025CodeMustNotContainMultipleWhitespaceInARow>True</SA1025CodeMustNotContainMultipleWhitespaceInARow></StyleCop.Spacing><StyleCop.Readability><SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists>True</SA1100DoNotPrefixCallsWithBaseUnlessLocalImplementationExists><SA1106CodeMustNotContainEmptyStatements>True</SA1106CodeMustNotContainEmptyStatements><SA1108BlockStatementsMustNotContainEmbeddedComments>True</SA1108BlockStatementsMustNotContainEmbeddedComments><SA1109BlockStatementsMustNotContainEmbeddedRegions>True</SA1109BlockStatementsMustNotContainEmbeddedRegions><SA1120CommentsMustContainText>False</SA1120CommentsMustContainText><SA1121UseBuiltInTypeAlias>False</SA1121UseBuiltInTypeAlias><SA1122UseStringEmptyForEmptyStrings>False</SA1122UseStringEmptyForEmptyStrings><SA1123DoNotPlaceRegionsWithinElements>False</SA1123DoNotPlaceRegionsWithinElements><SA1124CodeMustNotContainEmptyRegions>True</SA1124CodeMustNotContainEmptyRegions></StyleCop.Readability><StyleCop.Layout><SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine>False</SA1500CurlyBracketsForMultiLineStatementsMustNotShareLine><SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine>True</SA1509OpeningCurlyBracketsMustNotBePrecededByBlankLine><SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine>True</SA1510ChainedStatementBlocksMustNotBePrecededByBlankLine><SA1511WhileDoFooterMustNotBePrecededByBlankLine>True</SA1511WhileDoFooterMustNotBePrecededByBlankLine><SA1512SingleLineCommentsMustNotBeFollowedByBlankLine>True</SA1512SingleLineCommentsMustNotBeFollowedByBlankLine><SA1513ClosingCurlyBracketMustBeFollowedByBlankLine>False</SA1513ClosingCurlyBracketMustBeFollowedByBlankLine><SA1514ElementDocumentationHeaderMustBePrecededByBlankLine>False</SA1514ElementDocumentationHeaderMustBePrecededByBlankLine><SA1515SingleLineCommentMustBeProceededByBlankLine>False</SA1515SingleLineCommentMustBeProceededByBlankLine></StyleCop.Layout><StyleCop.Ordering><AlphabeticalUsingDirectives>Ignore</AlphabeticalUsingDirectives><ExpandUsingDirectives>Ignore</ExpandUsingDirectives><SA1212PropertyAccessorsMustFollowOrder>True</SA1212PropertyAccessorsMustFollowOrder><SA1213EventAccessorsMustFollowOrder>True</SA1213EventAccessorsMustFollowOrder></StyleCop.Ordering><CSShortenReferences>True</CSShortenReferences><CSUseVar><BehavourStyle>CAN_CHANGE_TO_EXPLICIT</BehavourStyle><LocalVariableStyle>IMPLICIT_WHEN_INITIALIZER_HAS_TYPE</LocalVariableStyle><ForeachVariableStyle>ALWAYS_EXPLICIT</ForeachVariableStyle></CSUseVar><CSharpFormatDocComments>True</CSharpFormatDocComments></Profile>
Cleanup
Simple Reformat
+ 0
0
+ 0
0
TOGETHER_SAME_LINE
False
@@ -115,6 +117,8 @@ along with $SOLUTION$. If not, see <http://www.gnu.org/licenses/>.<Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private, Protected, ProtectedInternal, Internal, Public" Description="Classes"><ElementKinds><Kind Name="CLASS" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="C" Suffix="" Style="AaBb" /></Policy>
<Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private, Protected" Description="Fields (not public)"><ElementKinds><Kind Name="FIELD" /><Kind Name="READONLY_FIELD" /><Kind Name="METHOD" /><Kind Name="PROPERTY" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="_" Suffix="" Style="AaBb" /></Policy>
<Policy><Descriptor Staticness="Static, Instance" AccessRightKinds="Private, Protected, ProtectedInternal, Internal, Public" Description="Structs"><ElementKinds><Kind Name="STRUCT" /></ElementKinds></Descriptor><Policy Inspect="True" Prefix="S" Suffix="" Style="AaBb" /></Policy>
+ True
+ True
False
Vocaluxe.testsettings
True
diff --git a/Vocaluxe/Base/Server/CClientHandler.cs b/Vocaluxe/Base/Server/CClientHandler.cs
deleted file mode 100644
index 7f1bf734..00000000
--- a/Vocaluxe/Base/Server/CClientHandler.cs
+++ /dev/null
@@ -1,31 +0,0 @@
-#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 .
-#endregion
-
-namespace Vocaluxe.Base.Server
-{
- class CClientHandler
- {
- private int _ConnectionID;
- public bool LoggedIn;
-
- public CClientHandler(int connectionID)
- {
- _ConnectionID = connectionID;
- LoggedIn = false;
- }
- }
-}
\ No newline at end of file
diff --git a/Vocaluxe/Base/Server/CCommands.cs b/Vocaluxe/Base/Server/CCommands.cs
deleted file mode 100644
index 3d8b70d1..00000000
--- a/Vocaluxe/Base/Server/CCommands.cs
+++ /dev/null
@@ -1,129 +0,0 @@
-#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 .
-#endregion
-
-using System;
-using System.IO;
-using System.Text;
-using System.Security.Cryptography;
-using Newtonsoft.Json;
-
-namespace Vocaluxe.Base.Server
-{
- public static class CCommands
- {
- private static readonly UTF8Encoding _Encoder = new UTF8Encoding();
- private static readonly SHA256Managed _Sha256 = new SHA256Managed();
-
- public const string BroadcastKeyword = "I am a Vocaluxe Server";
-
- #region Commands
- // ReSharper disable UnusedMember.Global
- public const int ResponseOK = 1;
- public const int ResponseNOK = 2;
-
- public const int CommandLogin = 20;
- public const int ResponseLoginWrongPassword = 21;
- public const int ResponseLoginFailed = 22;
- public const int ResponseLoginOK = 23;
-
- public const int CommandSendKeyStroke = 100;
- public const int CommandSendKeyUp = 110;
- public const int CommandSendKeyDown = 111;
- public const int CommandSendKeyLeft = 112;
- public const int CommandSendKeyRight = 113;
-
- public const int CommandSendMouseMoveEvent = 200;
- public const int CommandSendMouseLBDownEvent = 220;
- public const int CommandSendMouseLBUpEvent = 221;
- public const int CommandSendMouseRBDownEvent = 230;
- public const int CommandSendMouseRBUpEvent = 231;
- public const int ComamndSendMouseMBDownEvent = 240;
- public const int ComamndSendMouseMBUpEvent = 241;
- public const int CommandSendMouseWheelEvent = 250;
-
- public const int CommandSendAvatarPicture = 500;
- public const int CommandSendAvatarPictureJpg = 501;
-
- public const int CommandSendProfile = 510;
- // ReSharper restore UnusedMember.Global
- #endregion Commands
-
- #region General
- public static byte[] CreateCommandWithoutParams(int command)
- {
- return BitConverter.GetBytes(command);
- }
- #endregion General
-
- #region Login
- public static byte[] CreateCommandLogin(string password)
- {
- var data = new SLoginData {Sha256 = _Sha256.ComputeHash(Encoding.UTF8.GetBytes(password))};
-
- return _Serialize(CommandLogin, data);
- }
-
- public static bool DecodeCommandLogin(byte[] message, out SLoginData loginData)
- {
- return _TryDeserialize(message, out loginData);
- }
- #endregion Login
-
- #region Serializing
- private static byte[] _Serialize(T obj)
- {
- return _Serialize(0, obj);
- }
-
- private static byte[] _Serialize(int command, T obj)
- {
- byte[] cmd = BitConverter.GetBytes(command);
-
- var stream = new MemoryStream();
- stream.Write(cmd, 0, cmd.Length);
-
- string json = JsonConvert.SerializeObject(obj);
- byte[] data = _Encoder.GetBytes(json);
- stream.Write(data, 0, data.Length);
- return stream.ToArray();
- }
-
- private static bool _TryDeserialize(byte[] message, out T obj)
- {
- obj = default(T);
-
- if (message == null)
- return false;
-
- if (message.Length < 5)
- return false;
-
- var data = new byte[message.Length - 4];
- Array.Copy(message, 4, data, 0, data.Length);
- try
- {
- obj = JsonConvert.DeserializeObject(_Encoder.GetString(data));
- return true;
- }
- catch
- {
- return false;
- }
- }
- #endregion Serializing
- }
-}
\ No newline at end of file
diff --git a/Vocaluxe/Base/Server/CVocaluxeServer.cs b/Vocaluxe/Base/Server/CVocaluxeServer.cs
index abc18556..3d3da689 100644
--- a/Vocaluxe/Base/Server/CVocaluxeServer.cs
+++ b/Vocaluxe/Base/Server/CVocaluxeServer.cs
@@ -17,14 +17,18 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
+using System.Net;
using System.Reflection;
using System.Security.Cryptography;
+using System.ServiceModel;
+using System.ServiceModel.Web;
using System.Text;
+using System.Threading.Tasks;
using System.Windows.Forms;
-using ServerLib;
using Vocaluxe.Lib.Input;
using Vocaluxe.Lib.Playlist;
using VocaluxeLib;
@@ -36,6 +40,11 @@ namespace Vocaluxe.Base.Server
{
static class CVocaluxeServer
{
+ private static ServiceHost _Host;
+ private static Uri _BaseAddress;
+ private static bool _Encrypted;
+ private static readonly Queue _ServerTaskQueue = new Queue();
+
private class CServerController : CControllerFramework
{
public override string GetName()
@@ -55,81 +64,232 @@ namespace Vocaluxe.Base.Server
public override void SetRumble(float duration) {}
}
- private static CServer _Server;
- //private static CDiscover _Discover;
-
public static readonly CControllerFramework Controller = new CServerController();
+
+ #region server control
+
public static void Init()
{
- _Server = new CServer(CConfig.Config.Server.ServerPort, CConfig.Config.Server.ServerEncryption == EOffOn.TR_CONFIG_ON);
+ int port = CConfig.Config.Server.ServerPort;
+ bool encrypted = CConfig.Config.Server.ServerEncryption == EOffOn.TR_CONFIG_ON;
+ string hostname = Dns.GetHostName();
+ string protocol = (encrypted) ? "https" : "http";
+ _BaseAddress = new Uri(protocol + "://" + hostname + ":" + port + "/");
+ _Encrypted = encrypted;
+ _Host = new WebServiceHost(typeof(CWebservice), _BaseAddress);
- CServer.SendKeyEvent = _SendKeyEvent;
- CServer.SendKeyStringEvent = _sendKeyStringEvent;
- CServer.GetProfileData = _GetProfileData;
- CServer.SendProfileData = _SendProfileData;
- CServer.GetProfileList = _GetProfileList;
- CServer.SendPhoto = _SendPhoto;
- CServer.GetSiteFile = _GetSiteFile;
- CServer.GetServerVersion = _GetServerVersion;
- CServer.GetSong = _GetSong;
- CServer.GetAllSongs = _GetAllSongs;
- CServer.GetCurrentSongId = _GetCurrentSongId;
- CServer.GetMp3Path = _GetMp3Path;
- CServer.ValidatePassword = _ValidatePassword;
- CServer.GetUserRole = _GetUserRole;
- CServer.SetUserRole = _SetUserRole;
- CServer.GetUserIdFromUsername = _GetUserIdFromUsername;
- CServer.GetDelayedImage = _GetDelayedImage;
- CServer.GetPlaylists = _GetPlaylists;
- CServer.GetPlaylist = _GetPlaylist;
- CServer.AddSongToPlaylist = _AddSongToPlaylist;
- CServer.RemoveSongFromPlaylist = _RemoveSongFromPlaylist;
- CServer.MoveSongInPlaylist = _MoveSongInPlaylist;
- CServer.PlaylistContainsSong = _PlaylistContainsSong;
- CServer.GetPlaylistSongs = _GetPlaylistSongs;
- CServer.RemovePlaylist = _RemovePlaylist;
- CServer.AddPlaylist = _AddPlaylist;
+ WebHttpBinding wb = new WebHttpBinding
+ {
+ MaxReceivedMessageSize = 10485760,
+ MaxBufferSize = 10485760,
+ MaxBufferPoolSize = 10485760,
+ ReaderQuotas = { MaxStringContentLength = 10485760, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760 }
+ };
+ if (encrypted)
+ {
+ wb.Security.Mode = WebHttpSecurityMode.Transport;
+ wb.Security.Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.None };
+ }
+ _Host.AddServiceEndpoint(typeof(ICWebservice), wb, "");
Start();
//_Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword);
}
-
public static void Start()
{
if (CConfig.Config.Server.ServerActive == EOffOn.TR_CONFIG_ON)
{
- _Server.Start();
- //_Discover.StartBroadcasting();
+ try
+ {
+ _RegisterUrlAndCert(_BaseAddress.Port, false);
+ _Host.Open();
+ }
+ catch (CommunicationException e)
+ {
+ if (e is AddressAccessDeniedException || e is AddressAlreadyInUseException)
+ {
+ _RegisterUrlAndCert(_BaseAddress.Port, true);
+ try
+ {
+ _Host.Abort();
+ Init();
+ _Host.Open();
+ }
+ catch (CommunicationException)
+ {
+ _Host.Abort();
+ MessageBox.Show("Problem while initialization of webserver. You may try a different port (Change it in config.xml)");
+ }
+ }
+ else
+ _Host.Abort();
+ }
}
}
public static void Close()
{
- if (_Server != null)
+ if (_Host != null)
{
- _Server.Stop();
- _Server = null;
- //_Discover.Stop();
+ try
+ {
+ _Host.Close();
+ }
+ catch (CommunicationException)
+ {
+ _Host.Abort();
+ }
}
}
+ private static void _RegisterUrlAndCert(int port, bool reserve)
+ {
+#if WIN
+
+ ProcessStartInfo info = new ProcessStartInfo
+ {
+ FileName = "VocaluxeServerConfig.exe",
+ WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory,
+ Arguments = AppDomain.CurrentDomain.FriendlyName + " " + port + " " + (_Encrypted ? "true" : "false") + (reserve ? " true" : ""),
+ UseShellExecute = true,
+ CreateNoWindow = true,
+ WindowStyle = ProcessWindowStyle.Hidden,
+ };
+ try
+ {
+ using (Process p = Process.Start(info))
+ {
+ p.WaitForExit();
+ if (p.ExitCode != 0)
+ MessageBox.Show("Registering the Server failed (Code " + p.ExitCode + ")!\r\nThe Server might not work correctly.");
+ p.Close();
+ }
+ }
+ catch (Exception e)
+ {
+ MessageBox.Show("Registering the Server failed (" + e + ")!\r\nThe Server might not work correctly.");
+ }
+#else
+
+ //Required?
+
+#endif
+ }
+
public static string GetServerAddress()
{
- return _Server == null ? "" : _Server.GetBaseAddress();
+ return _BaseAddress == null ? "" : _BaseAddress.AbsoluteUri;
}
public static bool IsServerRunning()
{
- if (_Server == null)
+ if (_Host == null)
return false;
- return _Server.IsRunning();
+ return _Host.State == CommunicationState.Opened;
}
- private static bool _SendKeyEvent(string key)
+ #endregion
+
+ #region task control
+
+ public static void ProcessServerTasks()
+ {
+ //Serial processing - one by one
+ while (_ServerTaskQueue.Count > 0)
+ {
+ //Get a task from the queue
+ Task task = _ServerTaskQueue.Dequeue();
+ //Start the task
+ task.RunSynchronously(TaskScheduler.FromCurrentSynchronizationContext());
+
+ task.Wait();
+ }
+ }
+
+
+ public static TReturnType DoTask(Func action)
+ {
+ var task = new Task(action);
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ return task.Result;
+ }
+
+ public static TReturnType DoTask(Func action, TParameterType parameter)
+ {
+ var task = new Task(() => action(parameter));
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ return task.Result;
+ }
+
+ public static TReturnType DoTask(Func action, TParameterType1 parameter1, TParameterType2 parmaeter2)
+ {
+ var task = new Task(() => action(parameter1, parmaeter2));
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ return task.Result;
+ }
+
+ public static TReturnType DoTask(Func action, TParameterType1 parameter1, TParameterType2 parmaeter2, TParameterType3 parmaeter3)
+ {
+ var task = new Task(() => action(parameter1, parmaeter2, parmaeter3));
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ return task.Result;
+ }
+
+ public static TReturnType DoTask(Func action, TParameterType1 parameter1, TParameterType2 parmaeter2, TParameterType3 parmaeter3, TParameterType4 parmaeter4)
+ {
+ var task = new Task(() => action(parameter1, parmaeter2, parmaeter3, parmaeter4));
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ return task.Result;
+ }
+
+
+ public static void DoTaskWithoutReturn(Action action)
+ {
+ var task = new Task(action);
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ }
+
+ public static void DoTaskWithoutReturn(Action action, TParameterType parameter)
+ {
+ var task = new Task(() => action(parameter));
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ }
+
+ public static void DoTaskWithoutReturn(Action action, TParameterType1 parameter1, TParameterType2 parmaeter2)
+ {
+ var task = new Task(() => action(parameter1, parmaeter2));
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ }
+
+ public static void DoTaskWithoutReturn(Action action, TParameterType1 parameter1, TParameterType2 parmaeter2, TParameterType3 parmaeter3)
+ {
+ var task = new Task(() => action(parameter1, parmaeter2, parmaeter3));
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ }
+
+ public static void DoTaskWithoutReturn(Action action, TParameterType1 parameter1, TParameterType2 parmaeter2, TParameterType3 parmaeter3, TParameterType4 parmaeter4)
+ {
+ var task = new Task(() => action(parameter1, parmaeter2, parmaeter3, parmaeter4));
+ _ServerTaskQueue.Enqueue(task);
+ task.Wait(); //wait until the task is completed
+ }
+
+ #endregion
+
+ public static bool SendKeyEvent(string key)
{
bool result = false;
string lowerKey = key.ToLower();
@@ -192,7 +352,7 @@ namespace Vocaluxe.Base.Server
return result;
}
- private static bool _sendKeyStringEvent(string keyString, bool isShiftPressed, bool isAltPressed, bool isCtrlPressed)
+ public static bool SendKeyStringEvent(string keyString, bool isShiftPressed, bool isAltPressed, bool isCtrlPressed)
{
bool result = false;
@@ -230,7 +390,7 @@ namespace Vocaluxe.Base.Server
}
#region profile
- private static SProfileData _GetProfileData(int profileId, bool isReadonly)
+ public static SProfileData GetProfileData(int profileId, bool isReadonly)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -238,7 +398,7 @@ namespace Vocaluxe.Base.Server
return _CreateProfileData(profile, isReadonly);
}
- private static bool _SendProfileData(SProfileData profile)
+ public static bool SendProfileData(SProfileData profile)
{
CProfile newProfile;
CProfile existingProfile = CProfiles.GetProfile(profile.ProfileId);
@@ -325,7 +485,7 @@ namespace Vocaluxe.Base.Server
return true;
}
- private static SProfileData[] _GetProfileList()
+ public static SProfileData[] GetProfileList()
{
List result = new List(CProfiles.NumProfiles);
@@ -379,7 +539,7 @@ namespace Vocaluxe.Base.Server
#region photo
private static readonly List _PhotosOfThisRound = new List();
- private static bool _SendPhoto(SPhotoData photoData)
+ public static bool SendPhoto(SPhotoData photoData)
{
if (photoData.Photo == null)
return false;
@@ -406,7 +566,7 @@ namespace Vocaluxe.Base.Server
#region website
private static readonly Dictionary _DelayedImagePath = new Dictionary();
- private static byte[] _GetSiteFile(string filename)
+ public static byte[] GetSiteFile(string filename)
{
string path = "Website/" + filename;
path = path.Replace("..", "");
@@ -438,7 +598,7 @@ namespace Vocaluxe.Base.Server
return hashedFilename;
}
- private static string _GetServerVersion()
+ public static string GetServerVersion()
{
var informationalVersion = Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault();
if (informationalVersion != null)
@@ -448,7 +608,7 @@ namespace Vocaluxe.Base.Server
return Assembly.GetExecutingAssembly().GetName().Version.ToString() + " (" + informationalVersion + ")";
}
- private static CBase64Image _GetDelayedImage(string hashedFilename)
+ public static CBase64Image GetDelayedImage(string hashedFilename)
{
if (!_DelayedImagePath.ContainsKey(hashedFilename))
throw new FileNotFoundException("Image not found");
@@ -465,25 +625,26 @@ namespace Vocaluxe.Base.Server
#endregion
#region songs
- private static SSongInfo _GetSong(int songId)
+ public static SSongInfo GetSong(int songId)
{
CSong song = CSongs.GetSong(songId);
return _GetSongInfo(song, true);
}
- private static SSongInfo[] _GetAllSongs()
+ public static SSongInfo[] GetAllSongs()
{
List songs = CSongs.Songs;
return (from s in songs
select _GetSongInfo(s, false)).ToArray();
}
- private static string _GetMp3Path(int songId)
+
+ public static string GetMp3Path(int songId)
{
CSong song = CSongs.GetSong(songId);
return song.GetMP3();
}
- private static int _GetCurrentSongId()
+ public static int GetCurrentSongId()
{
CSong song = CGame.GetSong();
if (song == null)
@@ -511,25 +672,25 @@ namespace Vocaluxe.Base.Server
#endregion
#region playlist
- private static SPlaylistData[] _GetPlaylists()
+ public static SPlaylistData[] GetPlaylists()
{
return (from p in CPlaylists.Playlists
select _GetPlaylistInfo(p)).ToArray();
}
- private static SPlaylistData _GetPlaylist(int playlistId)
+ public static SPlaylistData GetPlaylist(int playlistId)
{
if (CPlaylists.Get(playlistId) == null)
throw new ArgumentException("invalid playlistId");
return _GetPlaylistInfo(CPlaylists.Get(playlistId));
}
- private static void _AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
+ public static void AddSongToPlaylist(int songId, int playlistId, bool allowDuplicates)
{
if (CPlaylists.Get(playlistId) == null)
throw new ArgumentException("invalid playlistId");
- if (allowDuplicates || !_PlaylistContainsSong(songId, playlistId))
+ if (allowDuplicates || !PlaylistContainsSong(songId, playlistId))
{
CPlaylists.AddSong(playlistId, songId);
CPlaylists.Save(playlistId);
@@ -538,12 +699,12 @@ namespace Vocaluxe.Base.Server
throw new ArgumentException("song exists in this playlist");
}
- private static void _RemoveSongFromPlaylist(int position, int playlistId, int songId)
+ public static void RemoveSongFromPlaylist(int position, int playlistId, int songId)
{
CPlaylistFile pl = CPlaylists.Get(playlistId);
if (pl == null)
throw new ArgumentException("invalid playlistId");
- if (!_PlaylistContainsSong(songId, playlistId))
+ if (!PlaylistContainsSong(songId, playlistId))
throw new ArgumentException("invalid songId");
if (position < 0 || pl.Songs.Count <= position
|| pl.Songs[position].SongID != songId)
@@ -552,12 +713,12 @@ namespace Vocaluxe.Base.Server
pl.Save();
}
- private static void _MoveSongInPlaylist(int newPosition, int playlistId, int songId)
+ public static void MoveSongInPlaylist(int newPosition, int playlistId, int songId)
{
CPlaylistFile pl = CPlaylists.Get(playlistId);
if (pl == null)
throw new ArgumentException("invalid playlistId");
- if (!_PlaylistContainsSong(songId, playlistId))
+ if (!PlaylistContainsSong(songId, playlistId))
throw new ArgumentException("invalid songId");
if (pl.Songs.Count < newPosition)
@@ -568,7 +729,7 @@ namespace Vocaluxe.Base.Server
pl.Save();
}
- private static bool _PlaylistContainsSong(int songId, int playlistId)
+ public static bool PlaylistContainsSong(int songId, int playlistId)
{
CPlaylistFile pl = CPlaylists.Get(playlistId);
if (pl == null)
@@ -576,7 +737,7 @@ namespace Vocaluxe.Base.Server
return pl.Songs.Any(s => s.SongID == songId);
}
- private static SPlaylistSongInfo[] _GetPlaylistSongs(int playlistId)
+ public static SPlaylistSongInfo[] GetPlaylistSongs(int playlistId)
{
CPlaylistFile pl = CPlaylists.Get(playlistId);
if (pl == null)
@@ -617,14 +778,14 @@ namespace Vocaluxe.Base.Server
};
}
- private static void _RemovePlaylist(int playlistId)
+ public static void RemovePlaylist(int playlistId)
{
if (CPlaylists.Get(playlistId) == null)
throw new ArgumentException("invalid playlistId");
CPlaylists.Delete(playlistId);
}
- private static int _AddPlaylist(string playlistName)
+ public static int AddPlaylist(string playlistName)
{
int newPlaylistId = CPlaylists.NewPlaylist(playlistName);
CPlaylists.Save(newPlaylistId);
@@ -634,7 +795,7 @@ namespace Vocaluxe.Base.Server
#endregion
#region user management
- private static bool _ValidatePassword(int profileId, string password)
+ public static bool ValidatePassword(int profileId, string password)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -651,7 +812,7 @@ namespace Vocaluxe.Base.Server
return _Hash((new UTF8Encoding()).GetBytes(password), salt).SequenceEqual(profile.PasswordHash);
}
- private static bool _ValidatePassword(int profileId, byte[] hashedPassword)
+ public static bool ValidatePassword(int profileId, byte[] hashedPassword)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -680,7 +841,7 @@ namespace Vocaluxe.Base.Server
return profile.PasswordSalt;
}
- private static int _GetUserRole(int profileId)
+ public static int GetUserRole(int profileId)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -692,7 +853,7 @@ namespace Vocaluxe.Base.Server
return (int)(profile.UserRole);
}
- private static void _SetUserRole(int profileId, int userRole)
+ public static void SetUserRole(int profileId, int userRole)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -711,7 +872,7 @@ namespace Vocaluxe.Base.Server
CProfiles.SaveProfiles();
}
- private static int _GetUserIdFromUsername(string username)
+ public static int GetUserIdFromUsername(string username)
{
IEnumerable playerIds = (from p in CProfiles.GetProfiles()
where String.Equals(p.PlayerName, username, StringComparison.OrdinalIgnoreCase)
diff --git a/ServerLib/CWebservice.cs b/Vocaluxe/Base/Server/CWebservice.cs
similarity index 85%
rename from ServerLib/CWebservice.cs
rename to Vocaluxe/Base/Server/CWebservice.cs
index 785fdfb4..471caf34 100644
--- a/ServerLib/CWebservice.cs
+++ b/Vocaluxe/Base/Server/CWebservice.cs
@@ -16,13 +16,13 @@
#endregion
using System;
+using System.IO;
using System.Net;
using System.ServiceModel;
-using System.ServiceModel.Web;
-using System.IO;
using System.ServiceModel.Channels;
+using System.ServiceModel.Web;
-namespace ServerLib
+namespace Vocaluxe.Base.Server
{
class CWebservice : ICWebservice
{
@@ -48,33 +48,16 @@ namespace ServerLib
if (!_CheckRight(EUserRights.UseKeyboard))
return;
- if (CServer.SendKeyEvent == null)
- {
- if (WebOperationContext.Current != null)
- {
- WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
- WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
- }
- }
- else
- CServer.SendKeyEvent(key);
+
+ CVocaluxeServer.DoTask(CVocaluxeServer.SendKeyEvent,key);
}
public void SendKeyStringEvent(string keyString, bool isShiftPressed = false, bool isAltPressed = false, bool isCtrlPressed = false)
{
if (!_CheckRight(EUserRights.UseKeyboard))
return;
-
- if (CServer.SendKeyStringEvent == null)
- {
- if (WebOperationContext.Current != null)
- {
- WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
- WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
- }
- }
- else
- CServer.SendKeyStringEvent(keyString, isShiftPressed, isAltPressed, isCtrlPressed);
+
+ CVocaluxeServer.DoTask(CVocaluxeServer.SendKeyStringEvent, keyString, isShiftPressed, isAltPressed, isCtrlPressed);
}
#region profile
@@ -114,17 +97,7 @@ namespace ServerLib
return;
}
- if (CServer.SendProfileData == null)
- {
- if (WebOperationContext.Current != null)
- {
- WebOperationContext.Current.OutgoingResponse.StatusCode = HttpStatusCode.NotFound;
- WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
- }
- return;
- }
-
- CServer.SendProfileData(profile);
+ CVocaluxeServer.DoTask(CVocaluxeServer.SendProfileData, profile);
}
public SProfileData GetProfile(int profileId)
@@ -132,22 +105,18 @@ namespace ServerLib
Guid sessionKey = _GetSession();
if (CSessionControl.GetUserIdFromSession(sessionKey) == profileId || _CheckRight(EUserRights.ViewOtherProfiles))
{
- if (CServer.GetProfileData == null)
- return new SProfileData();
-
bool isReadonly = (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) &&
CSessionControl.GetUserIdFromSession(sessionKey) != profileId);
- return CServer.GetProfileData(profileId, isReadonly);
+
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetProfileData,profileId, isReadonly);
}
return new SProfileData();
}
public SProfileData[] GetProfileList()
{
- if (CServer.GetProfileList == null)
- return new SProfileData[] { };
- return CServer.GetProfileList();
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetProfileList);
}
#endregion
@@ -155,7 +124,7 @@ namespace ServerLib
public void SendPhoto(SPhotoData photo)
{
if (_CheckRight(EUserRights.UploadPhotos))
- CServer.SendPhoto(photo);
+ CVocaluxeServer.DoTask(CVocaluxeServer.SendPhoto, photo);
}
#endregion
@@ -185,7 +154,7 @@ namespace ServerLib
if (WebOperationContext.Current != null)
WebOperationContext.Current.OutgoingResponse.ContentType = "text/html";
- return new MemoryStream(CServer.GetSiteFile("index.html"));
+ return new MemoryStream(CVocaluxeServer.DoTask(CVocaluxeServer.GetSiteFile,"index.html"));
}
public Stream GetJsFile(string filename)
@@ -199,7 +168,7 @@ namespace ServerLib
DateTime.UtcNow.AddHours(4).ToString("r"));
}
- byte[] data = CServer.GetSiteFile("js/" + filename);
+ byte[] data = CVocaluxeServer.DoTask(CVocaluxeServer.GetSiteFile, "js/" + filename);
if (data != null)
return new MemoryStream(data);
@@ -220,7 +189,7 @@ namespace ServerLib
DateTime.UtcNow.AddHours(4).ToString("r"));
}
- byte[] data = CServer.GetSiteFile("css/" + filename);
+ byte[] data = CVocaluxeServer.DoTask(CVocaluxeServer.GetSiteFile, "css/" + filename);
if (data != null)
return new MemoryStream(data);
@@ -240,7 +209,7 @@ namespace ServerLib
DateTime.UtcNow.AddYears(1).ToString("r"));
}
- byte[] data = CServer.GetSiteFile("css\\images\\" + filename);
+ byte[] data = CVocaluxeServer.DoTask(CVocaluxeServer.GetSiteFile, "css\\images\\" + filename);
if (data != null)
return new MemoryStream(data);
@@ -260,7 +229,7 @@ namespace ServerLib
DateTime.UtcNow.AddYears(1).ToString("r"));
}
- byte[] data = CServer.GetSiteFile("img/" + filename);
+ byte[] data = CVocaluxeServer.DoTask(CVocaluxeServer.GetSiteFile, "img/" + filename);
if (data != null)
return new MemoryStream(data);
@@ -280,7 +249,7 @@ namespace ServerLib
DateTime.UtcNow.AddHours(4).ToString("r"));
}
- byte[] data = CServer.GetSiteFile("locales/" + filename);
+ byte[] data = CVocaluxeServer.DoTask(CVocaluxeServer.GetSiteFile, "locales/" + filename);
if (data != null)
return new MemoryStream(data);
@@ -292,7 +261,7 @@ namespace ServerLib
public CBase64Image GetDelayedImage(string id)
{
- return CServer.GetDelayedImage(id);
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetDelayedImage, id);
}
public bool IsServerOnline()
@@ -303,24 +272,24 @@ namespace ServerLib
public string GetServerVersion()
{
- return CServer.GetServerVersion();
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetServerVersion);
}
#endregion
#region songs
public SSongInfo GetSong(int songId)
{
- return CServer.GetSong(songId);
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetSong, songId);
}
public int GetCurrentSongId()
{
- return CServer.GetCurrentSongId();
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetCurrentSongId);
}
public SSongInfo[] GetAllSongs()
{
- return CServer.GetAllSongs();
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetAllSongs);
}
public Stream GetMp3File(int songId)
@@ -334,7 +303,7 @@ namespace ServerLib
}
- String path = CServer.GetMp3Path(songId);
+ String path = CVocaluxeServer.DoTask(CVocaluxeServer.GetMp3Path,songId);
path = path.Replace("..", "");
@@ -376,14 +345,14 @@ namespace ServerLib
#region playlist
public SPlaylistData[] GetPlaylists()
{
- return CServer.GetPlaylists();
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetPlaylists);
}
public SPlaylistData GetPlaylist(int playlistId)
{
try
{
- return CServer.GetPlaylist(playlistId);
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetPlaylist, playlistId);
}
catch (ArgumentException e)
{
@@ -405,7 +374,7 @@ namespace ServerLib
try
{
- CServer.AddSongToPlaylist(songId, playlistId, allowDuplicates);
+ CVocaluxeServer.DoTaskWithoutReturn(CVocaluxeServer.AddSongToPlaylist, songId, playlistId, allowDuplicates);
}
catch (ArgumentException e)
{
@@ -424,7 +393,7 @@ namespace ServerLib
try
{
- CServer.RemoveSongFromPlaylist(position, playlistId, songId);
+ CVocaluxeServer.DoTaskWithoutReturn(CVocaluxeServer.RemoveSongFromPlaylist, position, playlistId, songId);
}
catch (ArgumentException e)
{
@@ -443,7 +412,7 @@ namespace ServerLib
try
{
- CServer.MoveSongInPlaylist(newPosition, playlistId, songId);
+ CVocaluxeServer.DoTaskWithoutReturn(CVocaluxeServer.MoveSongInPlaylist, newPosition, playlistId, songId);
}
catch (ArgumentException e)
{
@@ -459,7 +428,7 @@ namespace ServerLib
{
try
{
- return CServer.PlaylistContainsSong(songId, playlistId);
+ return CVocaluxeServer.DoTask(CVocaluxeServer.PlaylistContainsSong, songId, playlistId);
}
catch (ArgumentException e)
{
@@ -477,7 +446,7 @@ namespace ServerLib
{
try
{
- return CServer.GetPlaylistSongs(playlistId);
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetPlaylistSongs, playlistId);
}
catch (ArgumentException e)
{
@@ -497,7 +466,7 @@ namespace ServerLib
try
{
- CServer.RemovePlaylist(playlistId);
+ CVocaluxeServer.DoTaskWithoutReturn(CVocaluxeServer.RemovePlaylist, playlistId);
}
catch (ArgumentException e)
{
@@ -516,7 +485,7 @@ namespace ServerLib
try
{
- return CServer.AddPlaylist(playlistName);
+ return CVocaluxeServer.DoTask(CVocaluxeServer.AddPlaylist, playlistName);
}
catch (ArgumentException e)
{
@@ -534,13 +503,13 @@ namespace ServerLib
#region user management
public int GetUserRole(int profileId)
{
- return CServer.GetUserRole(profileId);
+ return CVocaluxeServer.DoTask(CVocaluxeServer.GetUserRole, profileId);
}
public void SetUserRole(int profileId, int userRole)
{
if (_CheckRight(EUserRights.EditAllProfiles))
- CServer.SetUserRole(profileId, userRole);
+ CVocaluxeServer.DoTaskWithoutReturn(CVocaluxeServer.SetUserRole, profileId, userRole);
}
public bool HasUserRight(int right)
diff --git a/ServerLib/ICWebservice.cs b/Vocaluxe/Base/Server/ICWebservice.cs
similarity index 99%
rename from ServerLib/ICWebservice.cs
rename to Vocaluxe/Base/Server/ICWebservice.cs
index ea0e8a6e..c34c12de 100644
--- a/ServerLib/ICWebservice.cs
+++ b/Vocaluxe/Base/Server/ICWebservice.cs
@@ -20,7 +20,7 @@ using System.IO;
using System.ServiceModel;
using System.ServiceModel.Web;
-namespace ServerLib
+namespace Vocaluxe.Base.Server
{
[ServiceContract]
public interface ICWebservice
diff --git a/ServerLib/Session.cs b/Vocaluxe/Base/Server/Session.cs
similarity index 98%
rename from ServerLib/Session.cs
rename to Vocaluxe/Base/Server/Session.cs
index 416b34c9..b2493d4c 100644
--- a/ServerLib/Session.cs
+++ b/Vocaluxe/Base/Server/Session.cs
@@ -17,7 +17,7 @@
using System;
-namespace ServerLib
+namespace Vocaluxe.Base.Server
{
class CSession
{
diff --git a/ServerLib/SessionControl.cs b/Vocaluxe/Base/Server/SessionControl.cs
similarity index 93%
rename from ServerLib/SessionControl.cs
rename to Vocaluxe/Base/Server/SessionControl.cs
index 0fc80117..13d674b2 100644
--- a/ServerLib/SessionControl.cs
+++ b/Vocaluxe/Base/Server/SessionControl.cs
@@ -20,7 +20,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Timers;
-namespace ServerLib
+namespace Vocaluxe.Base.Server
{
static class CSessionControl
{
@@ -65,17 +65,17 @@ namespace ServerLib
private static bool _ValidateUserAndPassword(string userName, string password)
{
- return CServer.ValidatePassword(_GetProfileIdFormUsername(userName), password);
+ return CVocaluxeServer.ValidatePassword(_GetProfileIdFormUsername(userName), password);
}
private static int _GetProfileIdFormUsername(string username)
{
- return CServer.GetUserIdFromUsername(username);
+ return CVocaluxeServer.GetUserIdFromUsername(username);
}
private static EUserRoles _GetUserRoles(int profileId)
{
- return (EUserRoles)CServer.GetUserRole(profileId);
+ return (EUserRoles)CVocaluxeServer.GetUserRole(profileId);
}
internal static void InvalidateSessions(int profileId)
diff --git a/ServerLib/UserRights.cs b/Vocaluxe/Base/Server/UserRights.cs
similarity index 97%
rename from ServerLib/UserRights.cs
rename to Vocaluxe/Base/Server/UserRights.cs
index 56b42d81..85921333 100644
--- a/ServerLib/UserRights.cs
+++ b/Vocaluxe/Base/Server/UserRights.cs
@@ -17,7 +17,7 @@
using System;
-namespace ServerLib
+namespace Vocaluxe.Base.Server
{
[Flags]
enum EUserRights
diff --git a/ServerLib/UserRoleControl.cs b/Vocaluxe/Base/Server/UserRoleControl.cs
similarity index 98%
rename from ServerLib/UserRoleControl.cs
rename to Vocaluxe/Base/Server/UserRoleControl.cs
index a66212d3..febad3bd 100644
--- a/ServerLib/UserRoleControl.cs
+++ b/Vocaluxe/Base/Server/UserRoleControl.cs
@@ -18,7 +18,7 @@
using System.Collections.Generic;
using System.Linq;
-namespace ServerLib
+namespace Vocaluxe.Base.Server
{
static class CUserRoleControl
{
diff --git a/ServerLib/UserRoles.cs b/Vocaluxe/Base/Server/UserRoles.cs
similarity index 97%
rename from ServerLib/UserRoles.cs
rename to Vocaluxe/Base/Server/UserRoles.cs
index bc3c9d37..ed836433 100644
--- a/ServerLib/UserRoles.cs
+++ b/Vocaluxe/Base/Server/UserRoles.cs
@@ -17,7 +17,7 @@
using System;
-namespace ServerLib
+namespace Vocaluxe.Base.Server
{
[Flags]
enum EUserRoles
diff --git a/Vocaluxe/Base/Server/VocaluxeStructs.cs b/Vocaluxe/Base/Server/VocaluxeStructs.cs
index 1e826831..9cc5b327 100644
--- a/Vocaluxe/Base/Server/VocaluxeStructs.cs
+++ b/Vocaluxe/Base/Server/VocaluxeStructs.cs
@@ -15,6 +15,14 @@
// along with Vocaluxe. If not, see .
#endregion
+using System;
+using System.Drawing;
+using System.Drawing.Imaging;
+using System.IO;
+using System.Linq;
+using System.Runtime.Serialization;
+using System.Text.RegularExpressions;
+
namespace Vocaluxe.Base.Server
{
public struct SLoginData
@@ -35,4 +43,118 @@ namespace Vocaluxe.Base.Server
public string PlayerName;
public int Difficulty;
}
+
+ [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;
+ }
+
+ [DataContract]
+ public struct SPhotoData
+ {
+ [DataMember]
+ public CBase64Image Photo;
+ //Add infomation about the user who took this image??
+ }
+
+ [DataContract]
+ public class CBase64Image
+ {
+ // ReSharper disable InconsistentNaming
+ [DataMember]
+ private string base64Data = "";
+ [DataMember]
+ private string imageId = "";
+ // ReSharper restore InconsistentNaming
+
+ public CBase64Image(Image img, ImageFormat format)
+ {
+ MemoryStream ms = new MemoryStream();
+ img.Save(ms, format);
+ string formatString = ImageCodecInfo.GetImageEncoders().FirstOrDefault(x => x.FormatID == format.Guid).FilenameExtension.Replace("*.", "").ToLower();
+ base64Data = "data:image/" + formatString + ";base64," + Convert.ToBase64String(ms.ToArray());
+ }
+
+ public CBase64Image(string imageId)
+ {
+ this.imageId = imageId;
+ }
+
+ public Image GetImage()
+ {
+ string onlyBase64Data = base64Data.Substring(base64Data.IndexOf(";base64,") + (";base64,").Length);
+ byte[] imageData = Convert.FromBase64String(onlyBase64Data);
+ MemoryStream ms = new MemoryStream(imageData, 0, imageData.Length);
+ ms.Write(imageData, 0, imageData.Length);
+ Image image = Image.FromStream(ms, true);
+ return image;
+ }
+
+ public string GetImageType()
+ {
+ Match match = Regex.Match(base64Data, "(?<=data:image/)[a-zA-Z]+(?=;base64)");
+ return match.Success ? match.Groups[0].Value : "";
+ }
+ }
+
+ [DataContract]
+ public struct SSongInfo
+ {
+ [DataMember]
+ public string Title;
+ [DataMember]
+ public string Artist;
+ [DataMember]
+ public CBase64Image Cover;
+ [DataMember]
+ public string Genre { get; set; }
+ [DataMember]
+ public string Language { get; set; }
+ [DataMember]
+ public string Year { get; set; }
+ [DataMember]
+ public bool IsDuet { get; set; }
+ [DataMember]
+ public int SongId { get; set; }
+ }
+
+ [DataContract]
+ public struct SPlaylistSongInfo
+ {
+ [DataMember]
+ public SSongInfo Song;
+ [DataMember]
+ public int PlaylistId;
+ [DataMember]
+ public int PlaylistPosition;
+ [DataMember]
+ public int GameMode;
+ }
+
+ [DataContract]
+ public struct SPlaylistData
+ {
+ [DataMember]
+ public int PlaylistId;
+ [DataMember]
+ public string PlaylistName;
+ [DataMember]
+ public int SongCount;
+ [DataMember]
+ public string LastChanged;
+ }
}
\ No newline at end of file
diff --git a/Vocaluxe/Lib/Draw/CDrawBase.cs b/Vocaluxe/Lib/Draw/CDrawBase.cs
index eb72ad6d..d02dc520 100644
--- a/Vocaluxe/Lib/Draw/CDrawBase.cs
+++ b/Vocaluxe/Lib/Draw/CDrawBase.cs
@@ -21,6 +21,7 @@ using Vocaluxe.Base;
using VocaluxeLib;
using VocaluxeLib.Draw;
using System.Diagnostics;
+using Vocaluxe.Base.Server;
namespace Vocaluxe.Lib.Draw
{
@@ -329,6 +330,7 @@ namespace Vocaluxe.Lib.Draw
while (_Run)
{
_CheckQueue();
+ CVocaluxeServer.ProcessServerTasks();
//We want to begin drawing
_OnBeforeDraw();
diff --git a/Vocaluxe/Vocaluxe.csproj b/Vocaluxe/Vocaluxe.csproj
index c684ab1e..224c66a0 100644
--- a/Vocaluxe/Vocaluxe.csproj
+++ b/Vocaluxe/Vocaluxe.csproj
@@ -210,6 +210,9 @@
+
+
+
@@ -219,6 +222,13 @@
+
+
+
+
+
+
+
@@ -274,8 +284,6 @@
-
-
@@ -513,10 +521,6 @@
-
- {ec5167e4-ccfb-4cee-987c-cf816f1062a3}
- ServerLib
-
{D2B6DDEF-E0E1-4DDF-A73A-E6ACEF5C95EC}
VocaluxeLib