Webserver: renaming

This commit is contained in:
lukeIam committed 2013-12-13 17:43:27 +01:00
1 parent 013fc1e846
commit 3344f05b58
9 files changed
+359 -367

No files matched your search

+81 -84
View File
@@ -1,11 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Web;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
using System.Net;
@@ -13,91 +8,91 @@ namespace ServerLib
{
public class CServer
{
private ServiceHost host;
private Uri baseAddress;
private bool encrypted = false;
private ServiceHost _Host;
private Uri _BaseAddress;
private bool _Encrypted = false;
private static SendKeyEventDelegate sendKeyEvent;
private static SendKeyEventDelegate _SendKeyEvent;
public static SendKeyEventDelegate SendKeyEvent
{
internal get { return CServer.sendKeyEvent; }
set { CServer.sendKeyEvent = value; }
internal get { return CServer._SendKeyEvent; }
set { CServer._SendKeyEvent = value; }
}
#region profile
private static GetProfileDataDelegate getProfileData;
private static GetProfileDataDelegate _GetProfileData;
public static GetProfileDataDelegate GetProfileData
{
internal get { return CServer.getProfileData; }
set { CServer.getProfileData = value; }
internal get { return CServer._GetProfileData; }
set { CServer._GetProfileData = value; }
}
private static SendProfileDataDelegate sendProfileData;
private static SendProfileDataDelegate _SendProfileData;
public static SendProfileDataDelegate SendProfileData
{
internal get { return CServer.sendProfileData; }
set { CServer.sendProfileData = value; }
internal get { return CServer._SendProfileData; }
set { CServer._SendProfileData = value; }
}
private static GetProfileListDelegate getProfileList;
private static GetProfileListDelegate _GetProfileList;
public static GetProfileListDelegate GetProfileList
{
internal get { return CServer.getProfileList; }
set { CServer.getProfileList = value; }
internal get { return CServer._GetProfileList; }
set { CServer._GetProfileList = value; }
}
#endregion
#region photo
private static SendPhotoDelegate sendPhoto;
private static SendPhotoDelegate _SendPhoto;
public static SendPhotoDelegate SendPhoto
{
get { return CServer.sendPhoto; }
set { CServer.sendPhoto = value; }
get { return CServer._SendPhoto; }
set { CServer._SendPhoto = value; }
}
#endregion
#region website
private static GetSiteFileDelegate getSiteFile;
private static GetSiteFileDelegate _GetSiteFile;
public static GetSiteFileDelegate GetSiteFile
{
internal get { return CServer.getSiteFile; }
set { CServer.getSiteFile = value; }
internal get { return CServer._GetSiteFile; }
set { CServer._GetSiteFile = value; }
}
private static GetDelayedImageDelegate getDelayedImage;
private static GetDelayedImageDelegate _GetDelayedImage;
public static GetDelayedImageDelegate GetDelayedImage
{
internal get { return CServer.getDelayedImage; }
set { CServer.getDelayedImage = value; }
internal get { return CServer._GetDelayedImage; }
set { CServer._GetDelayedImage = value; }
}
#endregion
#region songs
private static GetSongDelegate getSong;
private static GetSongDelegate _GetSong;
public static GetSongDelegate GetSong
{
internal get { return CServer.getSong; }
set { CServer.getSong = value; }
internal get { return CServer._GetSong; }
set { CServer._GetSong = value; }
}
private static GetAllSongsDelegate getAllSongs;
private static GetAllSongsDelegate _GetAllSongs;
public static GetAllSongsDelegate GetAllSongs
{
get { return CServer.getAllSongs; }
set { CServer.getAllSongs = value; }
get { return CServer._GetAllSongs; }
set { CServer._GetAllSongs = value; }
}
private static GetCurrentSongIdDelegate getCurrentSongId;
private static GetCurrentSongIdDelegate _GetCurrentSongId;
public static GetCurrentSongIdDelegate GetCurrentSongId
{
get { return CServer.getCurrentSongId; }
set { CServer.getCurrentSongId = value; }
get { return CServer._GetCurrentSongId; }
set { CServer._GetCurrentSongId = value; }
}
@@ -105,77 +100,77 @@ namespace ServerLib
#region user management
private static SetPasswordDelegate setPassword;
private static SetPasswordDelegate _SetPassword;
public static SetPasswordDelegate SetPassword
{
internal get { return CServer.setPassword; }
set { CServer.setPassword = value; }
internal get { return CServer._SetPassword; }
set { CServer._SetPassword = value; }
}
private static ValidatePasswordDelegate validatePassword;
private static ValidatePasswordDelegate _ValidatePassword;
public static ValidatePasswordDelegate ValidatePassword
{
internal get { return CServer.validatePassword; }
set { CServer.validatePassword = value; }
internal get { return CServer._ValidatePassword; }
set { CServer._ValidatePassword = value; }
}
private static GetUserRoleDelegate getUserRole;
private static GetUserRoleDelegate _GetUserRole;
public static GetUserRoleDelegate GetUserRole
{
internal get { return CServer.getUserRole; }
set { CServer.getUserRole = value; }
internal get { return CServer._GetUserRole; }
set { CServer._GetUserRole = value; }
}
private static SetUserRoleDelegate setUserRole;
private static SetUserRoleDelegate _SetUserRole;
public static SetUserRoleDelegate SetUserRole
{
internal get { return CServer.setUserRole; }
set { CServer.setUserRole = value; }
internal get { return CServer._SetUserRole; }
set { CServer._SetUserRole = value; }
}
private static GetUserIdFromUsernameDelegate getUserIdFromUsername;
private static GetUserIdFromUsernameDelegate _GetUserIdFromUsername;
public static GetUserIdFromUsernameDelegate GetUserIdFromUsername
{
internal get { return CServer.getUserIdFromUsername; }
set { CServer.getUserIdFromUsername = value; }
internal get { return CServer._GetUserIdFromUsername; }
set { CServer._GetUserIdFromUsername = value; }
}
#endregion
public CServer(int port, bool encrypted)
{
init(port, encrypted);
_Init(port, encrypted);
}
#region server control
private void init(int port, bool encrypted)
private void _Init(int port, bool encrypted)
{
string hostname = Dns.GetHostName();
if (encrypted)
{
baseAddress = new Uri("https://" + hostname + ":" + port + "/");
_BaseAddress = new Uri("https://" + hostname + ":" + port + "/");
}
else
{
baseAddress = new Uri("http://" + hostname + ":" + port + "/");
_BaseAddress = new Uri("http://" + hostname + ":" + port + "/");
}
this.encrypted = encrypted;
host = new WebServiceHost(typeof(CWebservice), baseAddress);
this._Encrypted = encrypted;
_Host = new WebServiceHost(typeof(CWebservice), _BaseAddress);
WebHttpBinding wb = new WebHttpBinding();
wb.MaxReceivedMessageSize = 10485760;
wb.MaxBufferSize = 10485760;
wb.MaxBufferPoolSize = 10485760;
wb.ReaderQuotas.MaxStringContentLength = 10485760;
wb.ReaderQuotas.MaxArrayLength = 10485760;
wb.ReaderQuotas.MaxBytesPerRead = 10485760;
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, "");
_Host.AddServiceEndpoint(typeof(ICWebservice), wb, "");
}
public void Start()
@@ -187,27 +182,27 @@ namespace ServerLib
smb.HttpGetEnabled = true;
host.Description.Behaviors.Add(smb);*/
host.Open();
_Host.Open();
}
catch (CommunicationException e)
{
if (e is AddressAccessDeniedException || e is AddressAlreadyInUseException)
{
registerUrlAndCert(baseAddress.Port);
_RegisterUrlAndCert(_BaseAddress.Port);
try
{
host.Abort();
init(baseAddress.Port, encrypted);
host.Open();
_Host.Abort();
_Init(_BaseAddress.Port, _Encrypted);
_Host.Open();
}
catch (CommunicationException e2)
{
host.Abort();
_Host.Abort();
}
}
else
{
host.Abort();
_Host.Abort();
}
}
}
@@ -216,25 +211,27 @@ namespace ServerLib
{
try
{
host.Close();
_Host.Close();
}
catch (CommunicationException e)
{
host.Abort();
_Host.Abort();
}
}
private void registerUrlAndCert(int port)
private void _RegisterUrlAndCert(int port)
{
#if WIN
ProcessStartInfo info = new ProcessStartInfo();
info.FileName = "WebserverInitalConfig.exe";
info.Arguments = port.ToString() + " " + encrypted.ToString();
info.UseShellExecute = true;
info.CreateNoWindow = true;
info.WindowStyle = ProcessWindowStyle.Hidden;
info.Verb = "runas";
ProcessStartInfo info = new ProcessStartInfo
{
FileName = "WebserverInitalConfig.exe",
Arguments = port.ToString() + " " + _Encrypted.ToString(),
UseShellExecute = true,
CreateNoWindow = true,
WindowStyle = ProcessWindowStyle.Hidden,
Verb = "runas"
};
Process p = Process.Start(info);
if (p != null)
{
+133 -100
View File
@@ -1,10 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.Text;
using System.ServiceModel.Web;
using System.Web.Services;
using System.IO;
using System.ServiceModel.Channels;
@@ -17,7 +13,7 @@ namespace ServerLib
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/sendKeyEvent?key={key}")]
void sendKeyEvent(string key);
void SendKeyEvent(string key);
#region profile
@@ -25,25 +21,25 @@ namespace ServerLib
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getOwnProfileId")]
int getOwnProfileId();
int GetOwnProfileId();
[OperationContract]
[WebInvoke(Method = "POST",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/sendProfile")]
void sendProfile(ProfileData profile);
void SendProfile(SProfileData profile);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getProfile?profileId={profileId}")]
ProfileData getProfile(int profileId);
SProfileData GetProfile(int profileId);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getProfileList")]
ProfileData[] getProfileList();
SProfileData[] GetProfileList();
#endregion
@@ -54,7 +50,7 @@ namespace ServerLib
RequestFormat = WebMessageFormat.Json,
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/sendPhoto")]
void sendPhoto(PhotoData photo);
void SendPhoto(SPhotoData photo);
#endregion
@@ -64,7 +60,7 @@ namespace ServerLib
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/login?username={username}&password={password}")]
Guid login(string username, string password);
Guid Login(string username, string password);
[OperationContract]
[WebInvoke(Method = "GET",
@@ -100,7 +96,7 @@ namespace ServerLib
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/delayedImage?id={id}")]
Base64Image GetDelayedImage(String id);
CBase64Image GetDelayedImage(String id);
#endregion
@@ -110,19 +106,19 @@ namespace ServerLib
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getSong?songId={songId}")]
SongInfo getSong(int songId);
SOngInfo GetSong(int songId);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getCurrentSongId")]
int getCurrentSongId();
int GetCurrentSongId();
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getAllSongs")]
SongInfo[] getAllSongs();
SOngInfo[] GetAllSongs();
#endregion
@@ -132,29 +128,25 @@ namespace ServerLib
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/getUserRole?profileId={profileId}")]
int getUserRole(int profileId);
int GetUserRole(int profileId);
[OperationContract]
[WebInvoke(Method = "GET",
ResponseFormat = WebMessageFormat.Json,
UriTemplate = "/setUserRole?profileId={profileId}&userRole={userRole}")]
void setUserRole(int profileId, int userRole);
void SetUserRole(int profileId, int userRole);
#endregion
}
class CWebservice : ICWebservice
{
public CWebservice()
{
}
private static Guid getSession()
private static Guid _GetSession()
{
Guid sessionKey = Guid.Empty;
string sessionHeader =
((HttpRequestMessageProperty)OperationContext.Current.IncomingMessageProperties["httpRequest"]).Headers["session"];
if (sessionHeader == null || sessionHeader == "")
if (string.IsNullOrEmpty(sessionHeader))
{
return sessionKey;
}
@@ -168,25 +160,33 @@ namespace ServerLib
return sessionKey;
}
public void sendKeyEvent(string key)
public void SendKeyEvent(string key)
{
Guid sessionKey = getSession();
Guid sessionKey = _GetSession();
if (sessionKey == Guid.Empty )
if (sessionKey == Guid.Empty)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
}
else if (!SessionControl.requestRight(sessionKey, UserRights.UseKeyboard))
else if (!CSessionControl.RequestRight(sessionKey, EUserRights.UseKeyboard))
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
}
else if (CServer.SendKeyEvent == null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
}
}
else
{
@@ -196,51 +196,66 @@ namespace ServerLib
#region profile
public int getOwnProfileId()
public int GetOwnProfileId()
{
Guid sessionKey = getSession();
Guid sessionKey = _GetSession();
if (sessionKey == Guid.Empty)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return -1;
}
int profileId = SessionControl.getUserIdFromSession(sessionKey);
int profileId = CSessionControl.GetUserIdFromSession(sessionKey);
if (profileId < 0)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return -1;
}
return profileId;
}
public void sendProfile(ProfileData profile)
public void SendProfile(SProfileData profile)
{
Guid sessionKey = getSession();
Guid sessionKey = _GetSession();
if (profile.ProfileId != -1) //-1 is the id for a new profile
{
if (sessionKey == Guid.Empty)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return;
}
if (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
SessionControl.getUserIdFromSession(sessionKey) != profile.ProfileId)
if (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) &&
CSessionControl.GetUserIdFromSession(sessionKey) != profile.ProfileId)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
return;
}
}
if (CServer.SendProfileData == null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not found";
}
return;
}
@@ -258,41 +273,47 @@ namespace ServerLib
}
}
public ProfileData getProfile(int profileId)
public SProfileData GetProfile(int profileId)
{
Guid sessionKey = getSession();
Guid sessionKey = _GetSession();
if (sessionKey == Guid.Empty)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
return new ProfileData();
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return new SProfileData();
}
if (!SessionControl.requestRight(sessionKey, UserRights.ViewOtherProfiles) &&
SessionControl.getUserIdFromSession(sessionKey) != profileId)
if (!CSessionControl.RequestRight(sessionKey, EUserRights.ViewOtherProfiles) &&
CSessionControl.GetUserIdFromSession(sessionKey) != profileId)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
return new ProfileData();
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
return new SProfileData();
}
if (CServer.GetProfileData == null)
{
return new ProfileData();
return new SProfileData();
}
bool isReadonly = (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles) &&
SessionControl.getUserIdFromSession(sessionKey) != profileId);
bool isReadonly = (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles) &&
CSessionControl.GetUserIdFromSession(sessionKey) != profileId);
return CServer.GetProfileData(profileId, isReadonly);
}
public ProfileData[] getProfileList()
public SProfileData[] GetProfileList()
{
if (CServer.GetProfileList == null)
{
return new ProfileData[] { };
return new SProfileData[] { };
}
return CServer.GetProfileList();
}
@@ -301,20 +322,26 @@ namespace ServerLib
#region photo
public void sendPhoto(PhotoData photo)
public void SendPhoto(SPhotoData photo)
{
Guid sessionKey = getSession();
Guid sessionKey = _GetSession();
if (sessionKey == Guid.Empty)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return;
}
if (!SessionControl.requestRight(sessionKey, UserRights.UploadPhotos))
if (!CSessionControl.RequestRight(sessionKey, EUserRights.UploadPhotos))
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
return;
}
@@ -325,13 +352,16 @@ namespace ServerLib
#region website
public Guid login(string username, string password)
public Guid Login(string username, string password)
{
Guid sessionId = SessionControl.openSession(username, password);
Guid sessionId = CSessionControl.OpenSession(username, password);
if (sessionId == Guid.Empty)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Wrong username or password";
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Wrong username or password";
}
}
return sessionId;
}
@@ -359,11 +389,12 @@ namespace ServerLib
{
return new MemoryStream(data);
}
else
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
return null;
}
return null;
}
public Stream GetCssFile(string filename)
@@ -379,13 +410,11 @@ namespace ServerLib
{
return new MemoryStream(data);
}
else
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
return null;
}
return null;
}
public Stream GetCssImageFile(string filename)
@@ -401,11 +430,11 @@ namespace ServerLib
{
return new MemoryStream(data);
}
else
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
return null;
}
return null;
}
public Stream GetImgFile(string filename)
@@ -421,14 +450,14 @@ namespace ServerLib
{
return new MemoryStream(data);
}
else
if (WebOperationContext.Current != null)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.NotFound;
return null;
}
return null;
}
public Base64Image GetDelayedImage(string id)
public CBase64Image GetDelayedImage(string id)
{
return CServer.GetDelayedImage(id);
}
@@ -437,43 +466,47 @@ namespace ServerLib
#region songs
public SongInfo getSong(int songId)
public SOngInfo GetSong(int songId)
{
return CServer.GetSong(songId);
}
public int getCurrentSongId()
public int GetCurrentSongId()
{
return CServer.GetCurrentSongId();
}
public SongInfo[] getAllSongs()
public SOngInfo[] GetAllSongs()
{
return CServer.GetAllSongs();
}
#endregion
#region user management
#region user management
public int getUserRole(int profileId)
public int GetUserRole(int profileId)
{
return CServer.GetUserRole(profileId);
}
public void setUserRole(int profileId, int userRole)
public void SetUserRole(int profileId, int userRole)
{
Guid sessionKey = getSession();
Guid sessionKey = _GetSession();
if (sessionKey == Guid.Empty)
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
if (WebOperationContext.Current != null) {
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "No session";
}
return;
}
if (!SessionControl.requestRight(sessionKey, UserRights.EditAllProfiles))
if (!CSessionControl.RequestRight(sessionKey, EUserRights.EditAllProfiles))
{
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
if (WebOperationContext.Current != null) {
WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.Forbidden;
WebOperationContext.Current.OutgoingResponse.StatusDescription = "Not allowed";
}
return;
}
CServer.SetUserRole(profileId, userRole);
+18 -20
View File
@@ -1,7 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Drawing;
using System.IO;
@@ -15,15 +13,15 @@ namespace ServerLib
#region profile
public delegate ProfileData GetProfileDataDelegate(int profileId, bool isReadonly);
public delegate bool SendProfileDataDelegate(ProfileData profile);
public delegate ProfileData[] GetProfileListDelegate();
public delegate SProfileData GetProfileDataDelegate(int profileId, bool isReadonly);
public delegate bool SendProfileDataDelegate(SProfileData profile);
public delegate SProfileData[] GetProfileListDelegate();
[DataContract]
public struct ProfileData
public struct SProfileData
{
[DataMember]
public Base64Image Avatar;
public CBase64Image Avatar;
[DataMember]
public string PlayerName;
[DataMember]
@@ -42,13 +40,13 @@ namespace ServerLib
#region photo
public delegate bool SendPhotoDelegate(PhotoData photo);
public delegate bool SendPhotoDelegate(SPhotoData photo);
[DataContract]
public struct PhotoData
public struct SPhotoData
{
[DataMember]
public Base64Image Photo;
public CBase64Image Photo;
//Add infomation about the user who took this image??
}
@@ -58,12 +56,12 @@ namespace ServerLib
public delegate byte[] GetSiteFileDelegate(string filename);
public delegate Base64Image GetDelayedImageDelegate(string hashedFilename);
public delegate CBase64Image GetDelayedImageDelegate(string hashedFilename);
#endregion
[DataContract]
public class Base64Image
public class CBase64Image
{
[DataMember]
private string base64Data = "";
@@ -71,7 +69,7 @@ namespace ServerLib
[DataMember]
private string imageId = "";
public Base64Image(Image img, ImageFormat format)
public CBase64Image(Image img, ImageFormat format)
{
MemoryStream ms = new MemoryStream();
img.Save(ms, format);
@@ -79,12 +77,12 @@ namespace ServerLib
base64Data = "data:image/" + formatString + ";base64," + Convert.ToBase64String(ms.ToArray());
}
public Base64Image(string imageId)
public CBase64Image(string imageId)
{
this.imageId = imageId;
}
public Image getImage()
public Image GetImage()
{
string onlyBase64Data = base64Data.Substring(base64Data.IndexOf(";base64,") + (";base64,").Length);
byte[] imageData = Convert.FromBase64String(onlyBase64Data);
@@ -94,7 +92,7 @@ namespace ServerLib
return image;
}
public string getImageType()
public string GetImageType()
{
Match match = Regex.Match(base64Data, "(?<=data:image/)[a-zA-Z]+(?=;base64)");
return match.Success ? match.Groups[0].Value : "";
@@ -105,21 +103,21 @@ namespace ServerLib
#region songs
public delegate SongInfo GetSongDelegate(int songId);
public delegate SOngInfo GetSongDelegate(int songId);
public delegate SongInfo[] GetAllSongsDelegate();
public delegate SOngInfo[] GetAllSongsDelegate();
public delegate int GetCurrentSongIdDelegate();
[DataContract]
public struct SongInfo
public struct SOngInfo
{
[DataMember]
public string Title;
[DataMember]
public string Artist;
[DataMember]
public Base64Image Cover;
public CBase64Image Cover;
[DataMember]
public string Genre { get; set; }
[DataMember]
+12 -15
View File
@@ -1,35 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ServerLib
{
internal class Session
internal class CSession
{
Guid id;
readonly Guid _ID;
public Guid Id
{
get { return id; }
get { return _ID; }
}
int profileId;
readonly int _ProfileId;
public int ProfileId
{
get { return profileId; }
get { return _ProfileId; }
}
UserRoles roles;
internal UserRoles Roles
readonly EUserRoles _Roles;
internal EUserRoles Roles
{
get { return roles; }
get { return _Roles; }
}
public Session(Guid id, int profileId, UserRoles roles)
public CSession(Guid id, int profileId, EUserRoles roles)
{
this.id = id;
this.profileId = profileId;
this.roles = roles;
this._ID = id;
this._ProfileId = profileId;
this._Roles = roles;
}
}
}
@@ -1,69 +1,68 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ServerLib
{
internal static class SessionControl
internal static class CSessionControl
{
private static Dictionary<Guid, Session> activeSessions = new Dictionary<Guid, Session>();
private static readonly Dictionary<Guid, CSession> _ActiveSessions = new Dictionary<Guid, CSession>();
public static Guid openSession(string userName, string password)
public static Guid OpenSession(string userName, string password)
{
if (!validateUserAndPassword(userName, password))
if (!_ValidateUserAndPassword(userName, password))
{
return Guid.Empty;
}
Guid newId = Guid.NewGuid();
int id = getProfileIdFormUsername(userName);
UserRoles roles = getUserRoles(id);
Session session = new Session(newId, id, roles);
invalidateSessions(id);
activeSessions.Add(newId, session);
int id = _GetProfileIdFormUsername(userName);
EUserRoles roles = _GetUserRoles(id);
CSession session = new CSession(newId, id, roles);
InvalidateSessions(id);
_ActiveSessions.Add(newId, session);
return newId;
}
private static bool validateUserAndPassword(string userName, string password)
private static bool _ValidateUserAndPassword(string userName, string password)
{
return CServer.ValidatePassword(getProfileIdFormUsername(userName), password);
return CServer.ValidatePassword(_GetProfileIdFormUsername(userName), password);
}
private static int getProfileIdFormUsername(string username)
private static int _GetProfileIdFormUsername(string username)
{
return CServer.GetUserIdFromUsername(username);
}
private static UserRoles getUserRoles(int profileId)
private static EUserRoles _GetUserRoles(int profileId)
{
return (UserRoles)CServer.GetUserRole(profileId);
return (EUserRoles)CServer.GetUserRole(profileId);
}
internal static void invalidateSessions(int profileId)
internal static void InvalidateSessions(int profileId)
{
foreach (var s in (from kv in activeSessions
foreach (var s in (from kv in _ActiveSessions
where kv.Value.ProfileId == profileId
select kv).ToList())
{
activeSessions.Remove(s.Key);
_ActiveSessions.Remove(s.Key);
}
}
internal static bool requestRight(Guid sessionId, UserRights requestedRight)
internal static bool RequestRight(Guid sessionId, EUserRights requestedRight)
{
return ((UserRoleControl.getUserRightsFromUserRole(activeSessions[sessionId].Roles) & requestedRight) != 0);
return ((CUserRoleControl.GetUserRightsFromUserRole(_ActiveSessions[sessionId].Roles) & requestedRight) != 0);
}
internal static int getUserIdFromSession(Guid sessionId)
internal static int GetUserIdFromSession(Guid sessionId)
{
if (!activeSessions.ContainsKey(sessionId))
if (!_ActiveSessions.ContainsKey(sessionId))
{
return -1;
}
return activeSessions[sessionId].ProfileId;
return _ActiveSessions[sessionId].ProfileId;
}
}
}
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ServerLib
{
[Flags]
internal enum UserRights
internal enum EUserRights
{
None = 0x00,
EditAllProfiles = 0x01,
@@ -1,35 +1,28 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ServerLib
{
internal static class UserRoleControl
internal static class CUserRoleControl
{
private static Dictionary<UserRoles, UserRights> roleRightsMapping = new Dictionary<UserRoles, UserRights> {
{UserRoles.Administrator,
(UserRights.EditAllProfiles|
UserRights.UploadPhotos|
UserRights.ViewOtherProfiles)|
UserRights.UseKeyboard},
{UserRoles.AuthenticatedUser,
(UserRights.UploadPhotos|
UserRights.ViewOtherProfiles|
UserRights.UseKeyboard)}
private static readonly Dictionary<EUserRoles, EUserRights> _RoleRightsMapping = new Dictionary<EUserRoles, EUserRights> {
{EUserRoles.Administrator,
(EUserRights.EditAllProfiles|
EUserRights.UploadPhotos|
EUserRights.ViewOtherProfiles)|
EUserRights.UseKeyboard},
{EUserRoles.AuthenticatedUser,
(EUserRights.UploadPhotos|
EUserRights.ViewOtherProfiles|
EUserRights.UseKeyboard)}
};
internal static UserRights getUserRightsFromUserRole(UserRoles userRole)
internal static EUserRights GetUserRightsFromUserRole(EUserRoles userRole)
{
UserRights resultRights = UserRights.None;
foreach (UserRights r in roleRightsMapping.Where(role => userRole.HasFlag(role.Key)).Select(role => role.Value))
{
resultRights |= r;
}
return resultRights;
return _RoleRightsMapping.Where(role => userRole.HasFlag(role.Key))
.Select(role => role.Value)
.Aggregate(EUserRights.None, (current, r) => current | r);
}
}
}
+1 -4
View File
@@ -1,12 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ServerLib
{
[Flags]
internal enum UserRoles
internal enum EUserRoles
{
AuthenticatedUser = 0x00,
Administrator = 0x01
+75 -94
View File
@@ -18,8 +18,6 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Runtime.InteropServices;
using System.Linq;
using System.IO;
using System.Text;
@@ -48,21 +46,21 @@ namespace Vocaluxe.Base.Server
_Server = new CServer(CConfig.ServerPort, CConfig.ServerEncryption == EOffOn.TR_CONFIG_ON);
//TODO: remove CConfig.ServerPassword
CServer.SendKeyEvent = sendKeyEvent;
CServer.GetProfileData = getProfileData;
CServer.SendProfileData = sendProfileData;
CServer.GetProfileList = getProfileList;
CServer.SendPhoto = sendPhoto;
CServer.GetSiteFile = getSiteFile;
CServer.GetSong = getSong;
CServer.GetAllSongs = getAllSongs;
CServer.GetCurrentSongId = getCurrentSongId;
CServer.SetPassword = setPassword;
CServer.ValidatePassword = validatePassword;
CServer.GetUserRole = getUserRole;
CServer.SetUserRole = setUserRole;
CServer.GetUserIdFromUsername = getUserIdFromUsername;
CServer.GetDelayedImage = getDelayedImage;
CServer.SendKeyEvent = _SendKeyEvent;
CServer.GetProfileData = _GetProfileData;
CServer.SendProfileData = _SendProfileData;
CServer.GetProfileList = _GetProfileList;
CServer.SendPhoto = _SendPhoto;
CServer.GetSiteFile = _GetSiteFile;
CServer.GetSong = _GetSong;
CServer.GetAllSongs = _GetAllSongs;
CServer.GetCurrentSongId = _GetCurrentSongId;
CServer.SetPassword = _SetPassword;
CServer.ValidatePassword = _ValidatePassword;
CServer.GetUserRole = _GetUserRole;
CServer.SetUserRole = _SetUserRole;
CServer.GetUserIdFromUsername = _GetUserIdFromUsername;
CServer.GetDelayedImage = _GetDelayedImage;
_Discover = new CDiscover(CConfig.ServerPort, CCommands.BroadcastKeyword);
Controller.Init();
@@ -84,7 +82,7 @@ namespace Vocaluxe.Base.Server
_Clients = new Dictionary<int, CClientHandler>();
}
private static bool sendKeyEvent(string key)
private static bool _SendKeyEvent(string key)
{
bool result = false;
if (key != null && key != "")
@@ -155,17 +153,17 @@ namespace Vocaluxe.Base.Server
#region profile
private static ProfileData getProfileData(int profileId, bool isReadonly)
private static SProfileData _GetProfileData(int profileId, bool isReadonly)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
{
return new ProfileData();
return new SProfileData();
}
return CreateProfileData(profile, isReadonly); ;
return _CreateProfileData(profile, isReadonly);
}
private static bool sendProfileData(ProfileData profile)
private static bool _SendProfileData(SProfileData profile)
{
CProfile newProfile;
CProfile existingProfile = CProfiles.GetProfile(profile.ProfileId);
@@ -206,11 +204,11 @@ namespace Vocaluxe.Base.Server
newProfile.Avatar = avatar;*/
}
if (profile.PlayerName != null && profile.PlayerName != "")
if (!string.IsNullOrEmpty(profile.PlayerName))
{
newProfile.PlayerName = profile.PlayerName;
}
else if (newProfile.PlayerName != null && newProfile.PlayerName != "")
else if (!string.IsNullOrEmpty(newProfile.PlayerName))
{
newProfile.PlayerName = "DummyName";
}
@@ -237,41 +235,39 @@ namespace Vocaluxe.Base.Server
return true;
}
private static ProfileData[] getProfileList()
private static SProfileData[] _GetProfileList()
{
List<ProfileData> result = new List<ProfileData>(CProfiles.NumProfiles);
List<SProfileData> result = new List<SProfileData>(CProfiles.NumProfiles);
foreach (CProfile profile in CProfiles.GetProfiles())
{
result.Add(CreateProfileData(profile, true));
}
result.AddRange(CProfiles.GetProfiles().Select(profile => _CreateProfileData(profile, true)));
return result.ToArray();
}
private static ProfileData CreateProfileData(CProfile profile, bool isReadonly)
private static SProfileData _CreateProfileData(CProfile profile, bool isReadonly)
{
ProfileData profileData = new ProfileData();
SProfileData profileData = new SProfileData
{
IsEditable = !isReadonly,
ProfileId = profile.ID,
PlayerName = profile.PlayerName,
Type = (int)profile.GuestProfile,
Difficulty = (int)profile.Difficulty
};
profileData.IsEditable = !isReadonly;
profileData.ProfileId = profile.ID;
profileData.PlayerName = profile.PlayerName;
profileData.Type = (int)profile.GuestProfile;
profileData.Difficulty = (int)profile.Difficulty;
CAvatar avatar = profile.Avatar;
if (avatar != null)
{
if (File.Exists(avatar.FileName))
{
profileData.Avatar = new Base64Image(createDelayedImage(avatar.FileName));
profileData.Avatar = new CBase64Image(_CreateDelayedImage(avatar.FileName));
}
}
return profileData;
}
private static CAvatar _AddAvatar(Base64Image avatarData)
private static CAvatar _AddAvatar(CBase64Image avatarData)
{
string result = String.Empty;
try
{
string filename = _SaveImage(avatarData, "snapshot", CSettings.FolderProfiles);
@@ -282,10 +278,7 @@ namespace Vocaluxe.Base.Server
CProfiles.AddAvatar(avatar);
return avatar;
}
else
{
return null;
}
return null;
}
catch
{
@@ -297,7 +290,7 @@ namespace Vocaluxe.Base.Server
#region photo
private static bool sendPhoto(PhotoData photoData)
private static bool _SendPhoto(SPhotoData photoData)
{
if (photoData.Photo == null)
{
@@ -307,16 +300,16 @@ namespace Vocaluxe.Base.Server
string name = DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
string filePath = _SaveImage(photoData.Photo, name, CSettings.FolderPhotos);
return (filePath != null && filePath != "");
return !string.IsNullOrEmpty(filePath);
}
#endregion
#region website
private static Dictionary<string, string> delayedImagePath = new Dictionary<string, string>();
private static readonly Dictionary<string, string> _DelayedImagePath = new Dictionary<string, string>();
private static byte[] getSiteFile(string filename)
private static byte[] _GetSiteFile(string filename)
{
string path = "Website/" + filename;
path = path.Replace("..", "");
@@ -336,7 +329,7 @@ namespace Vocaluxe.Base.Server
return File.ReadAllBytes(path);
}
private static string createDelayedImage(string filename)
private static string _CreateDelayedImage(string filename)
{
byte[] by = SHA1.Create().ComputeHash(Encoding.UTF8.GetBytes(filename));
var sb = new StringBuilder();
@@ -347,52 +340,48 @@ namespace Vocaluxe.Base.Server
string hashedFilename = sb.ToString();
if (!delayedImagePath.ContainsKey(hashedFilename))
if (!_DelayedImagePath.ContainsKey(hashedFilename))
{
delayedImagePath.Add(hashedFilename, filename);
_DelayedImagePath.Add(hashedFilename, filename);
}
return hashedFilename;
}
private static Base64Image getDelayedImage(string hashedFilename)
private static CBase64Image _GetDelayedImage(string hashedFilename)
{
if (!delayedImagePath.ContainsKey(hashedFilename))
if (!_DelayedImagePath.ContainsKey(hashedFilename))
{
throw new FileNotFoundException("Image not found");
}
string fileName = delayedImagePath[hashedFilename];
string fileName = _DelayedImagePath[hashedFilename];
if (File.Exists(fileName))
{
Image image = Image.FromFile(fileName);
return new Base64Image(image, image.RawFormat);
return new CBase64Image(image, image.RawFormat);
}
else
{
throw new FileNotFoundException("Image not found");
}
throw new FileNotFoundException("Image not found");
}
#endregion
#region songs
private static SongInfo getSong(int songId)
private static SOngInfo _GetSong(int songId)
{
CSong song = CSongs.GetSong(songId);
return getSongInfo(song, true);
return _GetSongInfo(song, true);
}
private static SongInfo[] getAllSongs()
private static SOngInfo[] _GetAllSongs()
{
var songs = CSongs.Songs;
return (from s in songs
select getSongInfo(s, false)).ToArray<SongInfo>();
select _GetSongInfo(s, false)).ToArray<SOngInfo>();
}
private static int getCurrentSongId()
private static int _GetCurrentSongId()
{
CSong song = CGame.GetSong();
if (song == null)
@@ -402,9 +391,9 @@ namespace Vocaluxe.Base.Server
return song.ID;
}
private static SongInfo getSongInfo(CSong song, bool includeCover)
private static SOngInfo _GetSongInfo(CSong song, bool includeCover)
{
SongInfo result = new SongInfo();
SOngInfo result = new SOngInfo();
if (song != null)
{
result.Title = song.Title;
@@ -416,7 +405,7 @@ namespace Vocaluxe.Base.Server
result.SongId = song.ID;
if (includeCover)
{
result.Cover = new Base64Image(createDelayedImage(song.Folder + "\\" + song.CoverFileName));
result.Cover = new CBase64Image(_CreateDelayedImage(song.Folder + "\\" + song.CoverFileName));
}
}
return result;
@@ -426,7 +415,7 @@ namespace Vocaluxe.Base.Server
#region user management
private static void setPassword(int profileId, string newPassword)
private static void _SetPassword(int profileId, string newPassword)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -438,13 +427,13 @@ namespace Vocaluxe.Base.Server
byte[] buffer = new byte[128];
rng.GetNonZeroBytes(buffer);
byte[] salt = buffer;
byte[] hashedPassword = hash((new System.Text.UTF8Encoding()).GetBytes(newPassword), salt);
byte[] hashedPassword = _Hash((new UTF8Encoding()).GetBytes(newPassword), salt);
profile.PasswordSalt = salt;
profile.PasswordHash = hashedPassword;
}
private static bool validatePassword(int profileId, string password)
private static bool _ValidatePassword(int profileId, string password)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -454,21 +443,18 @@ namespace Vocaluxe.Base.Server
if (profile.PasswordHash == null)
{
if (password == "" || password == null)
if (string.IsNullOrEmpty(password))
{
return true; //Allow emty passwords
}
else
{
return false;
}
return false;
}
byte[] salt = profile.PasswordSalt;
return hash((new System.Text.UTF8Encoding()).GetBytes(password), salt).SequenceEqual(profile.PasswordHash);
return _Hash((new UTF8Encoding()).GetBytes(password), salt).SequenceEqual(profile.PasswordHash);
}
private static bool validatePassword(int profileId, byte[] hashedPassword)
private static bool _ValidatePassword(int profileId, byte[] hashedPassword)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -482,17 +468,14 @@ namespace Vocaluxe.Base.Server
{
return true; //Allow emty passwords
}
else
{
return false;
}
return false;
}
byte[] salt = profile.PasswordSalt;
return hashedPassword.SequenceEqual(profile.PasswordHash);
}
private static byte[] getPassowordSalt(int profileId)
private static byte[] _GetPassowordSalt(int profileId)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -508,7 +491,7 @@ namespace Vocaluxe.Base.Server
return profile.PasswordSalt;
}
private static int getUserRole(int profileId)
private static int _GetUserRole(int profileId)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -519,7 +502,7 @@ namespace Vocaluxe.Base.Server
return profile.UserRoles;
}
private static void setUserRole(int profileId, int userRole)
private static void _SetUserRole(int profileId, int userRole)
{
CProfile profile = CProfiles.GetProfile(profileId);
if (profile == null)
@@ -530,12 +513,12 @@ namespace Vocaluxe.Base.Server
profile.UserRoles = userRole;
}
private static int getUserIdFromUsername(string username)
private static int _GetUserIdFromUsername(string username)
{
var playerIds = (from p in CProfiles.GetProfiles()
where String.Equals(p.PlayerName, username, StringComparison.OrdinalIgnoreCase)
select p.ID);
if (playerIds.Count() == 0)
if (!playerIds.Any())
{
throw new ArgumentException("Invalid playername");
}
@@ -543,7 +526,7 @@ namespace Vocaluxe.Base.Server
return playerIds.First();
}
private static byte[] hash(byte[] password, byte[] salt)
private static byte[] _Hash(byte[] password, byte[] salt)
{
HashAlgorithm hashAlgo = new SHA256Managed();
@@ -556,13 +539,11 @@ namespace Vocaluxe.Base.Server
}
#endregion
private static string _SaveImage(Base64Image imageDate, string name, string folder)
private static string _SaveImage(CBase64Image imageDate, string name, string folder)
{
Image avatarImage = imageDate.getImage();
string extension = imageDate.getImageType();
Image avatarImage = imageDate.GetImage();
string extension = imageDate.GetImageType();
string filename = Path.Combine(folder, name);
if (File.Exists(filename + "." + extension))