/// <summary> /// Used to create a custom Profiles Session instance. This instance is used to track and store user activity as a form of Profiles Network. /// </summary> /// <param name="session">ref of Framework.Session object that stores the state of a Profiles user session</param> public void SessionUpdate(ref Session session) { string connstr = ConfigurationManager.ConnectionStrings["ProfilesDB"].ConnectionString; SessionManagement sm = new SessionManagement(); SqlConnection dbconnection = new SqlConnection(connstr); SqlParameter[] param; param = new SqlParameter[7]; SqlCommand dbcommand = new SqlCommand(); dbconnection.Open(); dbcommand.CommandTimeout = this.GetCommandTimeout(); param[0] = new SqlParameter("@SessionID", session.SessionID); param[1] = new SqlParameter("@UserID", session.UserID); param[2] = new SqlParameter("@LastUsedDate", DateTime.Now); param[3] = new SqlParameter("@SessionPersonNodeID", 0); param[3].Direction = ParameterDirection.Output; param[4] = new SqlParameter("@SessionPersonURI", SqlDbType.VarChar, 400); param[4].Direction = ParameterDirection.Output; // UCSF param[5] = new SqlParameter("@ShortDisplayName", SqlDbType.VarChar, 400); param[5].Direction = ParameterDirection.Output; if (session.LogoutDate > DateTime.Now.AddDays(-5)) { param[6] = new SqlParameter("@LogoutDate", session.LogoutDate.ToString()); } dbcommand.Connection = dbconnection; try { //For Output Parameters you need to pass a connection object to the framework so you can close it before reading the output params value. ExecuteSQLDataCommand(GetDBCommand(ref dbconnection, "[User.Session].[UpdateSession]", CommandType.StoredProcedure, CommandBehavior.CloseConnection, param)); } catch (Exception ex) { } try { dbcommand.Connection.Close(); session.NodeID = Convert.ToInt64(param[3].Value); session.PersonURI = param[4].Value.ToString(); } catch (Exception ex) { } }
public XmlDocument Search(Search.SearchOptions searchoptions, bool lookup) { string xmlstr = string.Empty; XmlDocument xmlrtn = new XmlDocument(); SessionManagement sm = new SessionManagement(); string sessionid = string.Empty; xmlstr = Utilities.SerializeXML.SerializeToString(searchoptions); xmlstr = xmlstr.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); xmlstr = xmlstr.Replace("<?xml version=\"1.0\" encoding=\"utf-16\"?>", ""); try { string connstr = ConfigurationManager.ConnectionStrings["ProfilesDB"].ConnectionString; bool secure = Convert.ToBoolean(ConfigurationManager.AppSettings["IsSecure"]); sessionid = sm.SessionCreate(); SqlConnection dbconnection = new SqlConnection(connstr); SqlCommand dbcommand = new SqlCommand(); SqlDataReader dbreader; dbconnection.Open(); dbcommand.CommandType = CommandType.StoredProcedure; dbcommand.CommandText = "[Search.].[GetNodes]"; dbcommand.CommandTimeout = this.GetCommandTimeout(); if (secure) { dbcommand.Parameters.Add(new SqlParameter("@UseCache", "Private")); User user = new User(); user.UserName = ConfigurationSettings.AppSettings["SecureGenericUserName"]; user.UserID = Convert.ToInt32(ConfigurationSettings.AppSettings["SecureGenericUserID"]); Session session = new Session(); session.UserID = user.UserID; session.SessionID = sessionid; this.SessionUpdate(ref session); } dbcommand.Parameters.Add(new SqlParameter("@SearchOptions", xmlstr)); dbcommand.Parameters.Add(new SqlParameter("@sessionid", sessionid)); if (lookup) dbcommand.Parameters.Add(new SqlParameter("@Lookup", 1)); dbcommand.Connection = dbconnection; dbreader = dbcommand.ExecuteReader(CommandBehavior.CloseConnection); xmlstr = string.Empty; while (dbreader.Read()) { xmlstr += dbreader[0].ToString(); } xmlrtn.LoadXml(xmlstr); if (!dbreader.IsClosed) dbreader.Close(); Utilities.DebugLogging.Log(xmlstr); } catch (Exception e) { Utilities.DebugLogging.Log(e.Message + " " + e.StackTrace); } return xmlrtn; }
/// <summary> /// Used to create a custom Profiles Session instance. This instance is used to track and store user activity as a form of Profiles Network. /// </summary> /// <param name="session">ref of Framework.Session object that stores the state of a Profiles user session</param> public void SessionCreate(ref Session session) { SqlDataReader dbreader; SqlParameter[] param = new SqlParameter[2]; param[0] = new SqlParameter("@RequestIP", session.RequestIP); param[1] = new SqlParameter("@UserAgent", session.UserAgent); dbreader = GetSQLDataReader(GetDBCommand("", "[User.Session].[CreateSession]", CommandType.StoredProcedure, CommandBehavior.CloseConnection, param)); if (dbreader != null) { if (dbreader.Read()) //Returns a data ready with one row of user Session Info. {Profiles Session Info, not IIS} { session.SessionID = dbreader["SessionID"].ToString(); session.CreateDate = dbreader["CreateDate"].ToString(); session.LastUsedDate = Convert.ToDateTime(dbreader["LastUsedDate"].ToString()); Utilities.DebugLogging.Log("Session object created:" + session.SessionID + " On " + session.CreateDate); } //Always close your readers if (!dbreader.IsClosed) dbreader.Close(); } else { session = null; } }
/// <summary> /// Public method used to create an instance of the custom Profiles session object. /// </summary> public string SessionCreate() { ProfilesSearchAPI.Utilities.DataIO dataio = new ProfilesSearchAPI.Utilities.DataIO(); Session session = new Session(); string hostname = System.Net.Dns.GetHostName(); string ipaddress = string.Empty; try { ipaddress = System.Net.Dns.GetHostAddresses(hostname).GetValue(1).ToString(); } catch (Exception ex) { ProfilesSearchAPI.Utilities.DebugLogging.Log(ex.Message + " ++ " + ex.StackTrace); ipaddress = ""; } session.RequestIP = ipaddress; session.UserAgent = "Search API"; dataio.SessionCreate(ref session); //Store the object in the current session of the user. return session.SessionID; }