Thanks Teemu,
I've checked the attributes and all of them are serializable, so, I don't know what the error might be... Here you are User class (sorry, it is quite long, but not sure what is important...). Hope this helps to fix the problem.
Thanks again,
Javier.
/// <summary>
/// User class
/// </summary>
///
[Serializable()]
public class User
{
/// <summary>
/// Constructor 1: Build an empty instance (all attributes equal to null) of User class
/// </summary>
public User()
{
login = null;
name = null;
surname = null;
password = null;
email = null;
lastAccess = null;
role = null;
motionActivated = false;
cam = new Camera();
motionEpisodes = new ArrayList();
livImage = new liveImage();
}
/// <summary>
/// Constructor 2: Build an instance of User class given the parameters
/// </summary>
/// <param name="loginU">user's login</param>
/// <param name="nameU">user's name</param>
/// <param name="surnameU">user's surname</param>
/// <param name="passwordU">user's password</param>
/// <param name="emailU">user's e-mail</param>
/// <param name="lastAccessU">user's last Access to the system</param>
/// <param name="roleU">user's role: administrator or client</param>
/// <param name="motionActivatedU">user's motion activated: yes/no</param>
public User(String loginU, String nameU, String surnameU, String passwordU, String emailU, String lastAccessU, String roleU,Boolean motionActivatedU)
{
login = loginU;
name = nameU;
surname = surnameU;
password = passwordU;
email = emailU;
lastAccess = lastAccessU;
role = roleU;
motionActivated = motionActivatedU;
cam = new Camera();
motionEpisodes = new ArrayList();
livImage = new liveImage();
}
/// <summary>
/// Get user's login
/// </summary>
/// <returns>user's login</returns>
public String getLogin()
{
return login;
}
/// <summary>
/// Get user's name
/// </summary>
/// <returns>user's name</returns>
public String getName()
{
return name;
}
/// <summary>
/// Get user's surname
/// </summary>
/// <returns>user's surname</returns>
public String getSurname()
{
return surname;
}
/// <summary>
/// Get user's password
/// </summary>
/// <returns>user's password</returns>
public String getPassword()
{
return password;
}
/// <summary>
/// Get user's e-mail
/// </summary>
/// <returns>user's e-mail</returns>
public String getEmail()
{
return email;
}
/// <summary>
/// Get user's role
/// </summary>
/// <returns>user's role</returns>
public String getRole()
{
return role;
}
/// <summary>
/// Get user's motion activated attribute
/// </summary>
/// <returns>user's motion activated attribute</returns>
public Boolean getMotion()
{
return motionActivated;
}
/// <summary>
/// Get camera object that is being used by current user
/// </summary>
/// <returns>camera object</returns>
public Camera getCamera()
{
return cam;
}
/// <summary>
/// Check if the user is registered in the system
/// </summary>
/// <param name="loginU">user's login</param>
/// <param name="passwordU">user's password</param>
public void logInUser(String loginU, String passwordU)
{
// Retrieve the information from database
fetchUser(loginU, passwordU);
if (login != null) // The user exists in the system
registerConnectedUser(); // The user is connected to the system.
}
/// <summary>
/// Retrieve User information from the DataBase
/// </summary>
/// <param name="loginU">user's login</param>
/// <param name="passwordU">user's password</param>
private void fetchUser(String loginU, String passwordU)
{
SqlDataReader reader;
// Get DB parameters from web.config file
string serverIP = WebConfigurationManager.AppSettings["serverIP"];
string TCPPort = WebConfigurationManager.AppSettings["TCPPort"];
string DBName = WebConfigurationManager.AppSettings["DBName"];
string DBLogin = WebConfigurationManager.AppSettings["DBLogin"];
string DBPassword = WebConfigurationManager.AppSettings["DBPassword"];
// New DBConnection instance
DBConnection connection = new DBConnection(serverIP, TCPPort, DBName, DBLogin, DBPassword);
// To set the SQL query: select all user data given the name and login introduced
connection.setQueryToCommand("SELECT * FROM USERM WHERE login='" + loginU + "' AND password='" + encryptSHA1(passwordU) + "';");
// Get reader
reader = connection.getReader();
reader.Read();
if (reader.HasRows == true) // The user exists. Fill object attributes
{
login = reader[0].ToString();
name = reader[1].ToString();
surname = reader[2].ToString();
password = reader[3].ToString();
email = reader[4].ToString();
lastAccess = reader[5].ToString();
role = reader[6].ToString();
if (reader[7].ToString().Equals("yes"))
motionActivated = true;
else
motionActivated = false;
}
reader.Close();
if (connection != null)
if (connection.getConnection().State == ConnectionState.Open)
connection.closeConnection();
}
/// <summary>
/// Register connected user in the system
/// </summary>
private void registerConnectedUser()
{
updateUser(DateTime.Now);
}
/// <summary>
/// Register connected user in the DB: update lastAccess
/// </summary>
/// <param name="currentTime"></param>
private void updateUser(DateTime currentTime)
{
DataRow[] foundRow;
// Get DB parameters from web.config file
string serverIP = WebConfigurationManager.AppSettings["serverIP"];
string TCPPort = WebConfigurationManager.AppSettings["TCPPort"];
string DBName = WebConfigurationManager.AppSettings["DBName"];
string DBLogin = WebConfigurationManager.AppSettings["DBLogin"];
string DBPassword = WebConfigurationManager.AppSettings["DBPassword"];
// New ADO.NET database instance. This object manages with ACTIVE_USERS table
ADODBConnection connection = new ADODBConnection(serverIP, TCPPort,DBName,DBLogin, DBPassword, "SELECT * from ACTIVE_USERS;");
// Found rows whose login is current user in ACTIVE_USERS table
foundRow = connection.getDataTable().Select("login='" + login + "'");
if (foundRow.Length == 1) // The user exists in ACTIVE_USERS table already
connection.updateRow(login,currentTime.ToString()); // Update user
else // Insert new register in ACTIVE_USERS
connection.addNewRow(login,currentTime.ToString());
// New DBConnection instance
DBConnection connection2 = new DBConnection(serverIP, TCPPort, DBName, DBLogin, DBPassword);
// To set the SQL query: update lastAccess attribute in USERM table for current user
connection2.setQueryToCommand("UPDATE USERM set lastAccess='" + currentTime + "' WHERE login='" +login +"';");
connection2.executeSqlSentence();
if (connection2 != null)
if (connection2.getConnection().State == ConnectionState.Open)
connection2.closeConnection();
// Update lastAccess attribute in current object
lastAccess = currentTime.ToString();
}
/// <summary>
/// Encrypt a string using SHA1 hash algorithm
/// </summary>
/// <param name="vsValue">string to encrypt</param>
/// <returns>encrypted string</returns>
///
private string encryptSHA1(string vsValue)
{
HashAlgorithm hashValue = new SHA1CryptoServiceProvider();
// Convert the original string to array of Bytes
byte[] byteValue = Encoding.UTF8.GetBytes(vsValue);
Decoder dec = Encoding.UTF8.GetDecoder();
// Compute the Hash, returns an array of Bytes
byte[] byteHash = hashValue.ComputeHash(byteValue);
hashValue.Clear();
// Return a base 64 encoded string of the Hash value
return (Convert.ToBase64String(byteHash));
}
/// <summary>
/// Set camera object values in current user instance
/// </summary>
public void viewCameraConfiguration()
{
// Get camera object from camera class
cam.getCameraConfiguration();
}
/// <summary>
/// Change personal details. In this case, password is also changed
/// </summary>
/// <param name="newName">new user's name</param>
/// <param name="newSurname">new user's surname</param>
/// <param name="newEmail">new user's e-mail</param>
/// <param name="newPassword">new user's password</param>
/// <param name="motionActivatedU">new user's motion activated value</param>
public void changePersonalDetails(string newName, string newSurname, string newEmail, string newPassword,Boolean motionActivatedU)
{
//Update new personal details on DB
updateUser(newName, newSurname, newEmail, newPassword, motionActivatedU);
}
/// <summary>
/// Update new personal details on DB. Password has been changed
/// </summary>
/// <param name="newName">new user's name</param>
/// <param name="newSurname">new user's surname</param>
/// <param name="newEmail">new user's e-mail</param>
/// <param name="newPassword">new user's password</param>
/// <param name="motionActivatedU">new user's motion activated value</param>
private void updateUser(string newName, string newSurname, string newEmail, string newPassword, Boolean motionActivatedU)
{
string motionActivatedString = "no";
// Get DB parameters from web.config file
string serverIP = WebConfigurationManager.AppSettings["serverIP"];
string TCPPort = WebConfigurationManager.AppSettings["TCPPort"];
string DBName = WebConfigurationManager.AppSettings["DBName"];
string DBLogin = WebConfigurationManager.AppSettings["DBLogin"];
string DBPassword = WebConfigurationManager.AppSettings["DBPassword"];
string encryptedNewPassword = encryptSHA1(newPassword);
// New DBConnection instance
DBConnection connection = new DBConnection(serverIP, TCPPort, DBName, DBLogin, DBPassword);
if (motionActivatedU)
motionActivatedString = "yes";
// To set the SQL sentence:update motionActivated attribute in ACTIVE_USERS table
connection.setQueryToCommand("UPDATE ACTIVE_USERS set motionActivated='" + motionActivatedString + "'WHERE login='" + login + "';");
connection.executeSqlSentence();
// To set the SQL sentence:update name,surname,password and email address given the login in USERM table
connection.setQueryToCommand("UPDATE USERM set name='" + newName + "',surname='" + newSurname + "',email='" + newEmail + "',password='" + encryptedNewPassword + "',motionActivated='" + motionActivatedString + "'WHERE login='" + login + "';");
connection.executeSqlSentence();
// To update user object
name = newName;
surname = newSurname;
email = newEmail;
password = encryptedNewPassword;
motionActivated = motionActivatedU;
if (connection != null)
if (connection.getConnection().State == ConnectionState.Open)
connection.closeConnection();
}
/// <summary>
/// Change personal details. In this case, password is not changed
/// </summary>
/// <param name="newName">new user's name</param>
/// <param name="newSurname">new user's surname</param>
/// <param name="newEmail">new user's e-mail</param>
/// <param name="motionActivatedU">new user's motion activated value</param>
public void changePersonalDetails(string newName, string newSurname, string newEmail,Boolean motionActivatedU)
{
//Update new data on DB
updateUser(newName, newSurname, newEmail,motionActivatedU);
}
/// <summary>
/// Update new personal details on DB. Password is not changed
/// </summary>
/// <param name="newName">new user's name</param>
/// <param name="newSurname">new user's surname</param>
/// <param name="newEmail">new user's e-mail</param>
/// <param name="motionActivatedU">new user's motion activated value</param>
private void updateUser(string newName, string newSurname, string newEmail, Boolean motionActivatedU)
{
string motionActivatedString = "no";
// Get DB parameters from web.config file
string serverIP = WebConfigurationManager.AppSettings["serverIP"];
string TCPPort = WebConfigurationManager.AppSettings["TCPPort"];
string DBName = WebConfigurationManager.AppSettings["DBName"];
string DBLogin = WebConfigurationManager.AppSettings["DBLogin"];
string DBPassword = WebConfigurationManager.AppSettings["DBPassword"];
// New DBConnection instance
DBConnection connection = new DBConnection(serverIP, TCPPort, DBName, DBLogin, DBPassword);
if (motionActivatedU)
motionActivatedString = "yes";
// To set the SQL sentence:update motionActivated attribute in ACTIVE_USERS table
connection.setQueryToCommand("UPDATE ACTIVE_USERS set motionActivated='" + motionActivatedString + "'WHERE login='" + login + "';");
connection.executeSqlSentence();
// To set the SQL sentence:update name,surname,password and email address given the login in USERM table
connection.setQueryToCommand("UPDATE USERM set name='" + newName + "',surname='" + newSurname + "',email='" + newEmail + "',motionActivated='" + motionActivatedString + "'WHERE login='" + login + "';");
connection.executeSqlSentence();
// To update user object
name = newName;
surname = newSurname;
email = newEmail;
motionActivated = motionActivatedU;
if (connection != null)
if (connection.getConnection().State == ConnectionState.Open)
connection.closeConnection();
}
public void logOut()
{
String input;
// Get DB parameters from web.config file
string serverIP = WebConfigurationManager.AppSettings["serverIP"];
string TCPPort = WebConfigurationManager.AppSettings["TCPPort"];
string DBName = WebConfigurationManager.AppSettings["DBName"];
string DBLogin = WebConfigurationManager.AppSettings["DBLogin"];
string DBPassword = WebConfigurationManager.AppSettings["DBPassword"];
// New DBConnection instance
DBConnection connection = new DBConnection(serverIP,TCPPort,DBName,DBLogin,DBPassword);
if (motionActivated)
// To update the user from the ACTIVE_USERS table: set isConnected ="No" and accessAt= "null"
connection.setQueryToCommand("UPDATE ACTIVE_USERS SET isConnected='no',accessAt=NULL,permissionToMove='no',servoTime='-1',firstServoTime='-1' WHERE login='" + login + "';");
else
// To delete the user from the ACTIVE_USERS table because motion detection is not activated
connection.setQueryToCommand("DELETE FROM ACTIVE_USERS WHERE login='" + login + "';");
connection.executeSqlSentence();
if (connection != null)
if (connection.getConnection().State == ConnectionState.Open)
connection.closeConnection();
}
/// <summary>
/// Select motion episodes happened in the selected day in the calendar
/// </summary>
/// <param name="selectedDay">selected day</param>
public void pickDay(DateTime selectedDay)
{
motionEpisode motionEpisodeAux = new motionEpisode();
ArrayList motionEpisodesAux = new ArrayList();
/* An ArrayList of motionEpisodes has been chosen instead of creating
* a motionEpisode for each episode existing in the DB. The reason is because
* with an arraylist, there is just one access to the DB. In the other case
* a new DB connection is needed for each motionEpisode*/
/* Using an empty motionEpisode object, we get an array which contains all motion episodes
* happenned in the selected day*/
motionEpisodesAux = motionEpisodeAux.getMotionEpisodes(selectedDay);
// The user's attribute motionEpisodes has now all motion episodes happenned in "selectedDay"
motionEpisodes = null;
motionEpisodes = new ArrayList();
motionEpisodes = (ArrayList)motionEpisodesAux.Clone();
}
/// <summary>
/// Get motion images related to the motion episode seleceted in the drowdownlist
/// </summary>
/// <param name="episodeNumber">episode number</param>
public void pickEpisode(int episodeNumber)
{
// Get motion images related to the motion episode selected
((motionEpisode)motionEpisodes[episodeNumber]).getMotionImages();
}
/// <summary>
/// Delete motion episode selected in the drop down list
/// </summary>
/// <param name="episodeNumber">episode number</param>
public void deleteEpisode(int episodeNumber)
{
// Get motionEpisodes[episodeNumber] from motionEpisodes ArrayList
((motionEpisode)motionEpisodes[episodeNumber]).deleteMotionImages();
// motion episode equals to null in motion episode array attribute for current user
//motionEpisodes[episodeNumber] = null;
}
// REturn motionEpisodes array
/// <summary>
/// Returns an array of motion episode objects related to the current user object
/// </summary>
/// <returns>array of motion episode objects related to the current user object</returns>
public ArrayList getmotionEpisodes()
{
return motionEpisodes;
}
/// <summary>
/// Fill live Image object in current user instance with the most recent live image
/// </summary>
public void receiveLiveImages()
{
// Get live image from live image class
livImage.getLiveImage();
}
/// <summary>
/// Get live Image object un current user instance with the most recent live image
/// </summary>
/// <returns>most recent live image object </returns>
public liveImage getLiveImage()
{
return livImage;
}
/// <summary>
/// Request new camera position in ACTIVE_USERS table. The user wants to move the camera upwards,downwards,to the right or
/// to the left
/// </summary>
/// <param name="direction">up,down,right,left</param>
public void setServoPosition(string direction)
{
// Get DB parameters from web.config file
string serverIP = WebConfigurationManager.AppSettings["serverIP"];
string TCPPort = WebConfigurationManager.AppSettings["TCPPort"];
string DBName = WebConfigurationManager.AppSettings["DBName"];
string DBLogin = WebConfigurationManager.AppSettings["DBLogin"];
string DBPassword = WebConfigurationManager.AppSettings["DBPassword"];
// New DBConnection instance
DBConnection connection = new DBConnection(serverIP, TCPPort, DBName, DBLogin, DBPassword);
// Insert new requested position for the current user. To insert the new direction, the user must have permission to move
if (direction.Equals("down"))
connection.setQueryToCommand("UPDATE ACTIVE_USERS SET servoDirection='down' ,servoTime='" + DateTime.Now.ToString() + "' WHERE login='" + login + "' AND permissionToMove='yes';");
else if (direction.Equals("up"))
connection.setQueryToCommand("UPDATE ACTIVE_USERS SET servoDirection='up' ,servoTime='" + DateTime.Now.ToString() + "' WHERE login='" + login + "' AND permissionToMove='yes';");
else if (direction.Equals("left"))
connection.setQueryToCommand("UPDATE ACTIVE_USERS SET servoDirection='left' ,servoTime='" + DateTime.Now.ToString() + "' WHERE login='" + login + "' AND permissionToMove='yes';");
else
connection.setQueryToCommand("UPDATE ACTIVE_USERS SET servoDirection='right' ,servoTime='" + DateTime.Now.ToString() + "' WHERE login='" + login + "' AND permissionToMove='yes';");
// Execute SQL sentence
connection.executeSqlSentence();
if (connection != null)
if (connection.getConnection().State == ConnectionState.Open)
connection.closeConnection();
}
/// <summary>
/// Private attributes
/// </summary>
///
private String login; // User's login
private String name; // user's name
private String surname; // user's surname
private String password; // user's password
private String email; // user's e-mail
private String lastAccess; // user's last access to the system
private String role; // user's role: administrator or client
private Boolean motionActivated; // user's motion ACtivated value
private Camera cam; // user's camera reference
private ArrayList motionEpisodes; // user's motion Episodes reference
private liveImage livImage; // user's live Image reference
}