Use autopropertys in server
This commit is contained in:
1 parent
b8629c1a74
commit
f3c713416c
1 file changed
+45
-181
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Net.Sockets;
|
||||||
using System.ServiceModel;
|
using System.ServiceModel;
|
||||||
using System.ServiceModel.Web;
|
using System.ServiceModel.Web;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -10,194 +11,66 @@ namespace ServerLib
|
|||||||
{
|
{
|
||||||
private ServiceHost _Host;
|
private ServiceHost _Host;
|
||||||
private Uri _BaseAddress;
|
private Uri _BaseAddress;
|
||||||
private bool _Encrypted = false;
|
private bool _Encrypted;
|
||||||
|
|
||||||
private static SendKeyEventDelegate _SendKeyEvent;
|
public static SendKeyEventDelegate SendKeyEvent { internal get; set; }
|
||||||
public static SendKeyEventDelegate SendKeyEvent
|
|
||||||
{
|
|
||||||
internal get { return CServer._SendKeyEvent; }
|
|
||||||
set { CServer._SendKeyEvent = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#region profile
|
#region profile
|
||||||
|
public static GetProfileDataDelegate GetProfileData { internal get; set; }
|
||||||
|
|
||||||
private static GetProfileDataDelegate _GetProfileData;
|
public static SendProfileDataDelegate SendProfileData { internal get; set; }
|
||||||
public static GetProfileDataDelegate GetProfileData
|
|
||||||
{
|
|
||||||
internal get { return CServer._GetProfileData; }
|
|
||||||
set { CServer._GetProfileData = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SendProfileDataDelegate _SendProfileData;
|
|
||||||
public static SendProfileDataDelegate SendProfileData
|
|
||||||
{
|
|
||||||
internal get { return CServer._SendProfileData; }
|
|
||||||
set { CServer._SendProfileData = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GetProfileListDelegate _GetProfileList;
|
|
||||||
public static GetProfileListDelegate GetProfileList
|
|
||||||
{
|
|
||||||
internal get { return CServer._GetProfileList; }
|
|
||||||
set { CServer._GetProfileList = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static GetProfileListDelegate GetProfileList { internal get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region photo
|
#region photo
|
||||||
private static SendPhotoDelegate _SendPhoto;
|
public static SendPhotoDelegate SendPhoto { get; set; }
|
||||||
public static SendPhotoDelegate SendPhoto
|
|
||||||
{
|
|
||||||
get { return CServer._SendPhoto; }
|
|
||||||
set { CServer._SendPhoto = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region website
|
#region website
|
||||||
|
public static GetSiteFileDelegate GetSiteFile { internal get; set; }
|
||||||
|
|
||||||
private static GetSiteFileDelegate _GetSiteFile;
|
public static GetDelayedImageDelegate GetDelayedImage { internal get; set; }
|
||||||
public static GetSiteFileDelegate GetSiteFile
|
|
||||||
{
|
|
||||||
internal get { return CServer._GetSiteFile; }
|
|
||||||
set { CServer._GetSiteFile = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GetDelayedImageDelegate _GetDelayedImage;
|
|
||||||
public static GetDelayedImageDelegate GetDelayedImage
|
|
||||||
{
|
|
||||||
internal get { return CServer._GetDelayedImage; }
|
|
||||||
set { CServer._GetDelayedImage = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region songs
|
#region songs
|
||||||
|
public static GetSongDelegate GetSong { internal get; set; }
|
||||||
|
|
||||||
private static GetSongDelegate _GetSong;
|
public static GetAllSongsDelegate GetAllSongs { internal get; set; }
|
||||||
public static GetSongDelegate GetSong
|
|
||||||
{
|
|
||||||
internal get { return CServer._GetSong; }
|
|
||||||
set { CServer._GetSong = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GetAllSongsDelegate _GetAllSongs;
|
|
||||||
public static GetAllSongsDelegate GetAllSongs
|
|
||||||
{
|
|
||||||
internal get { return CServer._GetAllSongs; }
|
|
||||||
set { CServer._GetAllSongs = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GetCurrentSongIdDelegate _GetCurrentSongId;
|
|
||||||
public static GetCurrentSongIdDelegate GetCurrentSongId
|
|
||||||
{
|
|
||||||
internal get { return CServer._GetCurrentSongId; }
|
|
||||||
set { CServer._GetCurrentSongId = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
public static GetCurrentSongIdDelegate GetCurrentSongId { internal get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region playlist
|
#region playlist
|
||||||
|
public static GetPlaylistsDelegate GetPlaylists { internal get; set; }
|
||||||
|
|
||||||
private static GetPlaylistsDelegate _GetPlaylists;
|
public static GetPlaylistDelegate GetPlaylist { internal get; set; }
|
||||||
public static GetPlaylistsDelegate GetPlaylists
|
|
||||||
{
|
|
||||||
internal get { return _GetPlaylists; }
|
|
||||||
set { _GetPlaylists = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static AddSongToPlaylistDelegate AddSongToPlaylist { internal get; set; }
|
||||||
|
|
||||||
private static GetPlaylistDelegate _GetPlaylist;
|
public static RemoveSongFromPlaylistDelegate RemoveSongFromPlaylist { internal get; set; }
|
||||||
public static GetPlaylistDelegate GetPlaylist
|
|
||||||
{
|
|
||||||
internal get { return _GetPlaylist; }
|
|
||||||
set { _GetPlaylist = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AddSongToPlaylistDelegate _AddSongToPlaylist;
|
public static MoveSongInPlaylistDelegate MoveSongInPlaylist { internal get; set; }
|
||||||
public static AddSongToPlaylistDelegate AddSongToPlaylist
|
|
||||||
{
|
|
||||||
internal get { return _AddSongToPlaylist; }
|
|
||||||
set { _AddSongToPlaylist = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static RemoveSongFromPlaylistDelegate _RemoveSongFromPlaylist;
|
public static PlaylistContainsSongDelegate PlaylistContainsSong { internal get; set; }
|
||||||
public static RemoveSongFromPlaylistDelegate RemoveSongFromPlaylist
|
|
||||||
{
|
|
||||||
internal get { return _RemoveSongFromPlaylist; }
|
|
||||||
set { _RemoveSongFromPlaylist = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MoveSongInPlaylistDelegate _MoveSongInPlaylist;
|
public static GetPlaylistSongsDelegate GetPlaylistSongs { internal get; set; }
|
||||||
public static MoveSongInPlaylistDelegate MoveSongInPlaylist
|
|
||||||
{
|
|
||||||
internal get { return _MoveSongInPlaylist; }
|
|
||||||
set { _MoveSongInPlaylist = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static PlaylistContainsSongDelegate _PlaylistContainsSong;
|
public static RemovePlaylistDelegate RemovePlaylist { internal get; set; }
|
||||||
public static PlaylistContainsSongDelegate PlaylistContainsSong
|
|
||||||
{
|
|
||||||
internal get { return _PlaylistContainsSong; }
|
|
||||||
set { _PlaylistContainsSong = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GetPlaylistSongsDelegate _GetPlaylistSongs;
|
|
||||||
public static GetPlaylistSongsDelegate GetPlaylistSongs
|
|
||||||
{
|
|
||||||
internal get { return _GetPlaylistSongs; }
|
|
||||||
set { _GetPlaylistSongs = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static RemovePlaylistDelegate _RemovePlaylist;
|
|
||||||
public static RemovePlaylistDelegate RemovePlaylist
|
|
||||||
{
|
|
||||||
internal get { return _RemovePlaylist; }
|
|
||||||
set { _RemovePlaylist = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static AddPlaylistDelegate _AddPlaylist;
|
|
||||||
public static AddPlaylistDelegate AddPlaylist
|
|
||||||
{
|
|
||||||
internal get { return _AddPlaylist; }
|
|
||||||
set { _AddPlaylist = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public static AddPlaylistDelegate AddPlaylist { internal get; set; }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region user management
|
#region user management
|
||||||
|
public static ValidatePasswordDelegate ValidatePassword { internal get; set; }
|
||||||
|
|
||||||
private static ValidatePasswordDelegate _ValidatePassword;
|
public static GetUserRoleDelegate GetUserRole { internal get; set; }
|
||||||
public static ValidatePasswordDelegate ValidatePassword
|
|
||||||
{
|
|
||||||
internal get { return CServer._ValidatePassword; }
|
|
||||||
set { CServer._ValidatePassword = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GetUserRoleDelegate _GetUserRole;
|
public static SetUserRoleDelegate SetUserRole { internal get; set; }
|
||||||
public static GetUserRoleDelegate GetUserRole
|
|
||||||
{
|
|
||||||
internal get { return CServer._GetUserRole; }
|
|
||||||
set { CServer._GetUserRole = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static SetUserRoleDelegate _SetUserRole;
|
public static GetUserIdFromUsernameDelegate GetUserIdFromUsername { internal get; set; }
|
||||||
public static SetUserRoleDelegate SetUserRole
|
|
||||||
{
|
|
||||||
internal get { return CServer._SetUserRole; }
|
|
||||||
set { CServer._SetUserRole = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
private static GetUserIdFromUsernameDelegate _GetUserIdFromUsername;
|
|
||||||
public static GetUserIdFromUsernameDelegate GetUserIdFromUsername
|
|
||||||
{
|
|
||||||
internal get { return CServer._GetUserIdFromUsername; }
|
|
||||||
set { CServer._GetUserIdFromUsername = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
public CServer(int port, bool encrypted)
|
public CServer(int port, bool encrypted)
|
||||||
{
|
{
|
||||||
_Init(port, encrypted);
|
_Init(port, encrypted);
|
||||||
@@ -206,43 +79,38 @@ namespace ServerLib
|
|||||||
public static string GetLocalAddress()
|
public static string GetLocalAddress()
|
||||||
{
|
{
|
||||||
return Dns.GetHostName();
|
return Dns.GetHostName();
|
||||||
|
|
||||||
/*IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName());
|
/*IPAddress[] ips = Dns.GetHostAddresses(Dns.GetHostName());
|
||||||
foreach (IPAddress ip in ips)
|
foreach (IPAddress ip in ips)
|
||||||
{
|
{
|
||||||
if (ip.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
|
if (ip.AddressFamily == AddressFamily.InterNetwork)
|
||||||
return ip.ToString();
|
return ip.ToString();
|
||||||
}
|
}
|
||||||
return "";*/
|
return "";*/
|
||||||
}
|
}
|
||||||
|
|
||||||
#region server control
|
#region server control
|
||||||
|
|
||||||
private void _Init(int port, bool encrypted)
|
private void _Init(int port, bool encrypted)
|
||||||
{
|
{
|
||||||
string hostname = Dns.GetHostName();
|
string hostname = Dns.GetHostName();
|
||||||
if (encrypted)
|
if (encrypted)
|
||||||
{
|
|
||||||
_BaseAddress = new Uri("https://" + hostname + ":" + port + "/");
|
_BaseAddress = new Uri("https://" + hostname + ":" + port + "/");
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
|
||||||
_BaseAddress = new Uri("http://" + hostname + ":" + port + "/");
|
_BaseAddress = new Uri("http://" + hostname + ":" + port + "/");
|
||||||
}
|
|
||||||
this._Encrypted = encrypted;
|
this._Encrypted = encrypted;
|
||||||
_Host = new WebServiceHost(typeof(CWebservice), _BaseAddress);
|
_Host = new WebServiceHost(typeof(CWebservice), _BaseAddress);
|
||||||
|
|
||||||
WebHttpBinding wb = new WebHttpBinding
|
WebHttpBinding wb = new WebHttpBinding
|
||||||
{
|
{
|
||||||
MaxReceivedMessageSize = 10485760,
|
MaxReceivedMessageSize = 10485760,
|
||||||
MaxBufferSize = 10485760,
|
MaxBufferSize = 10485760,
|
||||||
MaxBufferPoolSize = 10485760,
|
MaxBufferPoolSize = 10485760,
|
||||||
ReaderQuotas = { MaxStringContentLength = 10485760, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760 }
|
ReaderQuotas = {MaxStringContentLength = 10485760, MaxArrayLength = 10485760, MaxBytesPerRead = 10485760}
|
||||||
};
|
};
|
||||||
if (encrypted)
|
if (encrypted)
|
||||||
{
|
{
|
||||||
wb.Security.Mode = WebHttpSecurityMode.Transport;
|
wb.Security.Mode = WebHttpSecurityMode.Transport;
|
||||||
wb.Security.Transport = new HttpTransportSecurity { ClientCredentialType = HttpClientCredentialType.None };
|
wb.Security.Transport = new HttpTransportSecurity {ClientCredentialType = HttpClientCredentialType.None};
|
||||||
}
|
}
|
||||||
_Host.AddServiceEndpoint(typeof(ICWebservice), wb, "");
|
_Host.AddServiceEndpoint(typeof(ICWebservice), wb, "");
|
||||||
}
|
}
|
||||||
@@ -275,9 +143,7 @@ namespace ServerLib
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
|
||||||
_Host.Abort();
|
_Host.Abort();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -298,14 +164,14 @@ namespace ServerLib
|
|||||||
#if WIN
|
#if WIN
|
||||||
|
|
||||||
ProcessStartInfo info = new ProcessStartInfo
|
ProcessStartInfo info = new ProcessStartInfo
|
||||||
{
|
{
|
||||||
FileName = "VocaluxeServerConfig.exe",
|
FileName = "VocaluxeServerConfig.exe",
|
||||||
Arguments = port.ToString() + " " + (_Encrypted?"true":"false"),
|
Arguments = port.ToString() + " " + (_Encrypted ? "true" : "false"),
|
||||||
UseShellExecute = true,
|
UseShellExecute = true,
|
||||||
CreateNoWindow = true,
|
CreateNoWindow = true,
|
||||||
WindowStyle = ProcessWindowStyle.Hidden,
|
WindowStyle = ProcessWindowStyle.Hidden,
|
||||||
Verb = "runas"
|
Verb = "runas"
|
||||||
};
|
};
|
||||||
Process p = Process.Start(info);
|
Process p = Process.Start(info);
|
||||||
if (p != null)
|
if (p != null)
|
||||||
{
|
{
|
||||||
@@ -315,12 +181,10 @@ namespace ServerLib
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
//Required?
|
//Required?
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user