using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using rasp;
using rasp.SQL;
using rasp.SQL.SQLStatement;
using rasp.SQL.DBInfo;
using rasp.HTML;
using rasp.Workflow;
namespace rasp {
/// <summary>
/// The basepage contains all of the desired and shared functionality that every codebehind BasePage should derive from.
/// </summary>
public class BasePage : Page {
protected PlaceHolder _Header, _ScriptBlock;
private UserInfo _UserInformation;
/// <summary>
/// The login reason is the string that is displayed at the top of a login BasePage if the user gets redirected.
/// </summary>
public string loginReason = "";
private bool _IsLoggedIn = false;
//*******************************
#region properties
/// <summary>
/// Set this value to false in your derived pages onload event to disable security. The default value for this property is true.
/// </summary>
public bool RequiresLogin = true;
public void SetFilter(string adapter, Statement s) {
this.Session["Statement-"+adapter] = s;
}
public Statement GetFilter(string adapter) {
return (Statement)this.Session["Statement-"+adapter];
}
public UserInfo UserInformation {
get {
UserInfo ret = this._UserInformation;
if (Context != null) {
ret = (UserInfo)Session["UserInformation"];
if (ret == null) {
try {
int uid = int.Parse(this.Request.Cookies["UserID"].Value);
ret = new UserInfo(uid);
//ret = new UserInfo();
} catch {
ret = new UserInfo();
}
}
}
return ret;
}
set {
this._UserInformation = value;
Session["UserInformation"] = value;
Session["loggedIn"] = value.IsLoggedIn;
Session["userid"] = value.ID;
}
}
/// <summary>
/// Gets or sets a flag that indicates if the user is logged in or not.
/// </summary>
/// <remarks>
/// Behind the scenes, this property actually checks the session variable for a "loggedIn" key, parses it's contents to a boolean
/// variable and returns it. Setting it will also set the session variable with the key "loggedIn" with the appropriate value.
/// </remarks>
public bool IsLoggedIn {
get {
return this.UserInformation.IsLoggedIn;
}
}
/// <summary>
/// Gets or sets the current UserID
/// </summary>
/// <remarks>
/// Behind the scenes this property actually checks the session variable for a key of "userid" parses it to an int variable and
/// returns it. Setting this value also sets the session variable with the key of "userid" with the appropriate value.
/// </remarks>
public int UserID {
get {
return this.UserInformation.ID;
}
}
/// <summary>
/// Gets the string representation of the QueryString object.
/// </summary>
/// <remarks>
/// There was no appropriate method in the QueryString object itself, so we have one written here. This is used when we redirect
/// the user to a login page, but want to know what BasePage they tried to go to before that.
/// </remarks>
public string QueryString {
get {
string temp = "";
if (Context != null) {
temp = "?";
foreach(string key in Request.QueryString) {
temp += key + "=" + Request.QueryString[key] + "&";
}
if (temp.Length == 1) {
temp = "";
} else {
temp = temp.Substring(0,temp.Length -1);
}
}
return temp;
;
}
}
#endregion
//*******************************
private void Page_Load(object sender, System.EventArgs e) {
//Process: Here is where the duplicate control error occurs, when I use the workaround defined in ProcessViewer.cs, this catch block is
//never executed. As you can see, I attempt to clear the controls first, and although it gives a hint to the overall problem,
//it doesn't seem to have anything to do with the problem itself. However, when I use the workaround, the events of the process steps
//fire, and this catch block is never executed. However, when I do not use the workaround, this catch block is executed, and
//the events in the process step are not fired. It is somehow related to this, but it cannot be the root problem.
try {
_Header = (PlaceHolder)this.FindControl("_Header");
_ScriptBlock = (PlaceHolder)this.FindControl("_ScriptBlock");
} catch { }
if (_Header != null) {
_Header.Controls.Clear();
_Header.Controls.Add(HTML.SiteControls.Header(this.UserInformation));
}
if (_ScriptBlock != null) {
Literal l = new Literal();
l.Text = "<script type='text/javascript' src='"+ Constants.URLS.BaseURL+"/rasp.js'></script>" +
"<script type='text/javascript' src='"+ Constants.URLS.BaseURL+"/ie5.js'></script>" +
"<link rel='stylesheet' type='text/css' href='"+ Constants.URLS.BaseURL +"/rasp.css' />" +
"<script type='text/javascript' src='"+ Constants.URLS.BaseURL+"/DropDown.js'></script>";
_ScriptBlock.Controls.Add(l);
}
//TODO: Figure out why this is looping before a derived page's onLoad event fires and sets this.RequiresLogin = false (IE: The login page.)
if (!IsLoggedIn && RequiresLogin && !sender.ToString().Equals("ASP.login_aspx")) {
string loginRedirect = Request.FilePath + QueryString;
Response.Redirect(LinkGenerator.LoginLink(loginReason, Server.UrlEncode(loginRedirect)));
}
}
private string Contatinate(string what, string with) {
if (!what.EndsWith(",") && what.Length != 0) {
what += ",";
}
return what + with;
}
/*
//TODO: Fix this up to work when all of the parameters are finalized
/// <summary>
/// Gets the names of the commonly used querystring values that represent a given adapter.
/// </summary>
public string TableNames {
get {
string ret = "";
if (!TextUtilities.IsEqual(Request.Form["adapter"], "")) {
ret = Contatinate(ret, Request.Form["adapter"]);
}
if (!TextUtilities.IsEqual(Request.Form["organizer"], "")) {
ret = Contatinate(ret, Request.Form["organizer"]);
}
if (!TextUtilities.IsEqual(Request.Form["instance"], "")) {
ret = Contatinate(ret, Request.Form["instance"]);
}
if (!TextUtilities.IsEqual(Request.Form["adapters"], "")) {
ret = Contatinate(ret, Request.Form["adapters"]);
}
if (!TextUtilities.IsEqual(Request.QueryString[Constants.Parameters.Adapter], "")) {
ret = Contatinate(ret, Request.QueryString[Constants.Parameters.Adapter]);
}
if (!TextUtilities.IsEqual(Request.QueryString[Constants.Parametersorganizer"], "")) {
ret = Contatinate(ret, Request.QueryString[Constants.Parametersorganizer"]);
}
if (!TextUtilities.IsEqual(Request.QueryString[Constants.Parametersinstance"], "")) {
ret = Contatinate(ret, Request.QueryString[Constants.Parametersinstance"]);
}
if (!TextUtilities.IsEqual(Request.QueryString[Constants.Parametersadapters"], "")) {
ret = Contatinate(ret, Request.QueryString[Constants.Parametersadapters"]);
}
return ret;
}
}
*/
/// <summary>
/// Gets the string representation of the Form object.
/// </summary>
/// <remarks>
/// There was no appropriate method in the Form object itself, so we have one written here.
/// </remarks>
public string FormData {
get {
string temp = "";
if (Context != null) {
temp = "?";
foreach(string key in Request.Form) {
temp += key + "=" + Request.Form[key] + "&";
}
if (temp.Length == 1) {
temp = "";
} else {
temp = temp.Substring(0,temp.Length -1);
}
}
return temp;
}
}
#region Web Form Designer generated code
/// <summary>
/// The OnInit Method.
/// </summary>
/// <param name="e">The event args.</param>
override protected void OnInit(EventArgs e) {
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent() {
Load += new System.EventHandler(Page_Load);
}
#endregion
}
}