Click here to Skip to main content
15,888,454 members
Home / Discussions / ASP.NET
   

ASP.NET

 
AnswerRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
Peace ON5-May-10 4:33
Peace ON5-May-10 4:33 
AnswerRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
Sandesh M Patil5-May-10 4:42
Sandesh M Patil5-May-10 4:42 
AnswerRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
overtech065-May-10 4:58
overtech065-May-10 4:58 
GeneralRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
Adam Brown 36-May-10 3:47
Adam Brown 36-May-10 3:47 
GeneralRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
overtech066-May-10 6:36
overtech066-May-10 6:36 
AnswerRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
T M Gray5-May-10 4:58
T M Gray5-May-10 4:58 
GeneralRe: How should I create a class that I can access across multiple ASP.NET pages? Pin
Adam Brown 36-May-10 3:53
Adam Brown 36-May-10 3:53 
QuestionProblem Pin
MaheshSharma5-May-10 4:21
MaheshSharma5-May-10 4:21 
namespace Ashwin {
public class Global : System.Web.HttpApplication, ICacheManager {

protected void Application_Start(object sender, EventArgs e) {
//Load the cache for the first time.
ReloadCache("All");
}

protected void Application_End(object sender, EventArgs e) {
//Cleanup anything that we left if we left anything using the SubmitReport.asmx
/*string tempPath = Server.MapPath("TempData");
if (System.IO.Directory.Exists(tempPath))
System.IO.Directory.Delete(tempPath, true);*/

}

/// <summary>
/// When the session starts.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void Session_Start(object sender, EventArgs e) {

UserSession session = new UserSession(Request);
try {
LoggedInUserInfo liui = session.Login();
// if user successfully logged in
// then store in Session cache
if(liui != null) {
CacheManager.SetCache("loggedInUser", CacheManager.cacheTypeEnum.Session, liui, this);

// get the top 10 Read reports in last 30 days i.e. one month
Report report = new Report();
IList list = report.GetTopReadReport(10, DateRangeEnum.OneMonth, ReportClassificationEnum.All, liui.User.UserId);
CacheManager.SetCache("TopReadReport", CacheManager.cacheTypeEnum.Session, list, this);

FillCache("SavedSearches");
}
} catch(Exception exc) {
Exception LastException = exc;
Session["LastException"] = LastException;
ErrorDetail ed = new ErrorDetail();
RecordError recordError = new RecordError();
recordError.Credentials = new System.Net.NetworkCredential(Util.GetConfigValue("WebServicesLogin"), Util.GetConfigValue("WebServicesPwd"));
recordError.PreAuthenticate = true;
ed.applicationName = "Ashwin20";
ed.browserVersion = Request.ServerVariables["HTTP_USER_AGENT"];
ed.errorUrl = Request.Url.ToString();
ed.note = LastException.Message;
ed.stackTrace = LastException.StackTrace;
ed.userName = Util.GetSimpleUsername(User);
//recordError.ReportError(ed);
Response.Redirect("ErrorPage.aspx");
}
}

/// <summary>
/// Fill in the cached value and return the list.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
private IList FillCache(string key) {
CacheManager.cacheTypeEnum application = CacheManager.cacheTypeEnum.Application;
CacheManager.cacheTypeEnum session = CacheManager.cacheTypeEnum.Session;
Org org = new Org();
SpecificSubject specificSubject = new SpecificSubject();
BusinessUnit busisnessUnit = new BusinessUnit();
OptinTitle optinTitle = new OptinTitle();
GeoArea geoArea = new GeoArea();
Function funtion = new Function();
Cop cop = new Cop();
Prod prod = new Prod();
DateRange dateRange = new DateRange();
SecurityGroup securityGroup = new SecurityGroup();
SecurityGroupInfo sgi = new SecurityGroupInfo();
Report report = new Report();
IList list = null;
// These tables hardly changes so we are going to store them
// in the application cache using the CacheManager.
if (key == "All" || key == "SecurityGroup") {
list = securityGroup.GetSecurityGroup();
CacheManager.SetCache("SecurityGroup", application, list, this);
}
if (key == "All" || key == "Organizations") {
list = org.GetOrg();
CacheManager.SetCache("Organizations", application, list, this);
}
if (key == "All" || key == "KeyCompetencies") {
list = specificSubject.GetSpecificSubject();
CacheManager.SetCache("KeyCompetencies", application, list, this);
}
if (key == "All" || key == "BusinessUnits") {
list = busisnessUnit.GetBusUnit();
CacheManager.SetCache("BusinessUnits", application, list, this);
}

if (key == "All" || key == "Levels") {
list = optinTitle.GetOptinTitle();
CacheManager.SetCache("Levels", application, list, this);
}
if (key == "All" || key == "Regions") {
list = geoArea.GetGeoArea();
CacheManager.SetCache("Regions", application, list, this);
}

if (key == "All" || key == "Functions") {
list = funtion.GetFunc();
CacheManager.SetCache("Functions", application, list, this);
}

if (key == "All" || key == "CoPs") {
list = cop.GetCop();
CacheManager.SetCache("CoPs", application, list, this);
}
if (key == "All" || key == "Sectors") {
list = prod.GetSector();
CacheManager.SetCache("Sectors", application, list, this);
}
if (key == "All" || key == "DateRange") {
list = dateRange.GetDateRange();
CacheManager.SetCache("DateRange", application, list, this);
}

// Cache Top 10 Readers and Top 10 Authors
// get the top 10 Readers in last 3 months
if(key == "All" || key == "TopReader") {
list = report.GetTopReaders(10, DateRangeEnum.ThreeMonths,"");
CacheManager.SetCache("TopReader",
CacheManager.cacheTypeEnum.Application, list, this);
}

// get the top 10 Authors in last 12 months i.e. one year
if(key == "All" || key == "TopAuthor") {
list = report.GetTopAuthors(10, DateRangeEnum.OneYear, "");
CacheManager.SetCache("TopAuthor",
CacheManager.cacheTypeEnum.Application, list, this);
}

// Get submitted report count in last 30 days from the database
if(key == "All" || key == "SubmittedReportCount") {
int submittedReportCount = 0;
Report ri = new Report();
// Call DB Method
// to get total reports submitted in last 30 days
submittedReportCount = ri.GetReportsSubmittedCount();
CacheManager.SetCache("SubmittedReportCount",
CacheManager.cacheTypeEnum.Application, submittedReportCount, this);
}

// Get report count in last 30 days from the content monitor service
if(key == "All" || key == "ViewedReportCount") {
int viewedReportCount = 0;
// Call Content Monitor WebService
// to get total viewed report count in last 30 days
MonitorReportService.ReportService reportService
= new MonitorReportService.ReportService();
reportService.Credentials = new NetworkCredential(Util.GetConfigValue("WebServiceUser"), Util.GetConfigValue("WebServicePswd"));
reportService.PreAuthenticate = true;

viewedReportCount = reportService.GetApplicationAccessCount
(Util.GetConfigValue("ApplicationName"), 30);
CacheManager.SetCache("ViewedReportCount",
CacheManager.cacheTypeEnum.Application, viewedReportCount, this);
}

if (key == "SavedSearches") {
// list of the user’s Saved searches using new Isubscribe webservice
//Get the saved Searches for the current user
iSubscribeService.iSubscribeWebService isubscribeService = new iSubscribeService.iSubscribeWebService();
isubscribeService.Credentials = new NetworkCredential(Util.GetConfigValue("WebServiceUser"), Util.GetConfigValue("WebServicePswd"));
isubscribeService.PreAuthenticate = true;
LoggedInUserInfo liui = Session["loggedInUser"] as LoggedInUserInfo;
list = isubscribeService.GetAllSavedSearchesByApplication
(liui.User.UserId,
int.Parse(Util.GetConfigValue("ApplicationId")));
CacheManager.SetCache("SavedSearches", session, list, this);
}

return list;
}

#region ICacheManager Methods
/// <summary>
/// Reload the cache.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public object ReloadCache(string key) {
object obj = null;
obj = FillCache(key);
return obj;
}
#endregion
}
}



---- Cache Manager ----


namespace Ashwin.BLL.Controls {
/// <summary>
/// Summary description for CacheManager.
/// </summary>
public class CacheManager {
//Hash table to hold all values
private static readonly Hashtable theCache = Hashtable.Synchronized(new Hashtable());
private static readonly CacheManager m_manager = new CacheManager();

/// <summary>
/// The types of cache we will deal with
/// </summary>
public enum cacheTypeEnum { Application, Session };

/// <summary>
/// Returns the singleton instance of the cache manager
/// </summary>
public static CacheManager Manager {
get { return m_manager; }
}

/// <summary>
/// Returns the cached value for the given key.
/// </summary>
/// <param name="key"></param>
/// <returns></returns>
public static object GetCache(string key) {
object ret;
CacheInfo cacheInfo = new CacheInfo();
cacheInfo.Key = key;
//Look in Application cache
ret = HttpContext.Current.Application[key];
if (ret == null) { //Look in Session
ret = HttpContext.Current.Session[key];
if (ret != null) {
cacheInfo.Type = cacheTypeEnum.Session;
cacheInfo.Value = ret;
}
} else {//Application
cacheInfo.Type = cacheTypeEnum.Application;
cacheInfo.Value = ret;
}

return ret;
}


/// <summary>
/// Adds the value to the cache
/// </summary>
/// <param name="key"></param>
/// <param name="type"></param>
/// <param name="theValue"></param>
/// <param name="container"></param>
public static void SetCache(string key, cacheTypeEnum type, object theValue, ICacheManager container) {
switch (type) {
case cacheTypeEnum.Application:
HttpContext.Current.Application[key] = theValue; //Add the value to the Application cache
break;
case cacheTypeEnum.Session: //Add the value to the Session cache
HttpContext.Current.Session[key] = theValue;
break;
}
//Add this to our hashtable
CacheInfo cacheInfo = new CacheInfo();
cacheInfo.Key = key;
cacheInfo.Type = type;
cacheInfo.Value = theValue;
cacheInfo.Container = container;
theCache[key] = cacheInfo;
}


/// <summary>
/// Returns an IList of CacheInfo objects representing all cached items
/// </summary>
/// <returns></returns>
public static IList GetAllCache() {
ArrayList list = new ArrayList();
foreach (string key in theCache.Keys) {
CacheInfo cacheInfo = theCache[key] as CacheInfo;
list.Add(cacheInfo);
}



return list;
}


/// <summary>
/// Clear the Cached Item
/// </summary>
/// <param name="key">The key to clear</param>
public static void ClearCacheReload(string key) {
CacheInfo cacheInfo = theCache[key] as CacheInfo;
if (cacheInfo != null) {
switch (cacheInfo.Type) {
case cacheTypeEnum.Application:
HttpContext.Current.Application[key] = null; //Add the value to the Application cache
cacheInfo.Value = cacheInfo.Container.ReloadCache(key);
break;
case cacheTypeEnum.Session: //Add the value to the Session cache
HttpContext.Current.Session[key] = null;
cacheInfo.Value = null;
break;
}
theCache[key] = cacheInfo;
}



}

/// <summary>
/// Clear All Items in the cache
/// </summary>
public static void ClearCache() {
foreach (string key in theCache.Keys) {
CacheInfo cacheInfo = theCache[key] as CacheInfo;
if (cacheInfo != null) {
switch (cacheInfo.Type) {
case cacheTypeEnum.Application:
HttpContext.Current.Application[key] = null; //Add the value to the Application cache
break;
case cacheTypeEnum.Session: //Add the value to the Session cache
HttpContext.Current.Session[key] = null;
break;
}
cacheInfo.Value = null;
theCache[key] = cacheInfo;
}
}
}
}
}

Please help
AnswerRe: Problem Pin
Sandesh M Patil5-May-10 4:24
Sandesh M Patil5-May-10 4:24 
AnswerRe: Problem Pin
JHizzle5-May-10 4:24
JHizzle5-May-10 4:24 
AnswerRe: Problem Pin
Not Active5-May-10 4:57
mentorNot Active5-May-10 4:57 
QuestionRegarding AjaxToolkit. Pin
dayakar_dn5-May-10 3:58
dayakar_dn5-May-10 3:58 
Questionproblem in update panel Pin
souravghosh185-May-10 2:35
souravghosh185-May-10 2:35 
AnswerRe: problem in update panel Pin
Jamil Hallal5-May-10 2:49
professionalJamil Hallal5-May-10 2:49 
AnswerRe: problem in update panel Pin
Abhijit Jana5-May-10 3:10
professionalAbhijit Jana5-May-10 3:10 
GeneralRe: problem in update panel Pin
Not Active5-May-10 3:22
mentorNot Active5-May-10 3:22 
AnswerRe: problem in update panel Pin
Not Active5-May-10 3:21
mentorNot Active5-May-10 3:21 
Questionhow to display properties on sale using google map Pin
Sandesh M Patil5-May-10 2:22
Sandesh M Patil5-May-10 2:22 
AnswerRe: how to display properties on sale using google map Pin
Not Active5-May-10 2:31
mentorNot Active5-May-10 2:31 
GeneralRe: how to display properties on sale using google map Pin
Sandesh M Patil5-May-10 2:43
Sandesh M Patil5-May-10 2:43 
GeneralRe: how to display properties on sale using google map Pin
Not Active5-May-10 3:07
mentorNot Active5-May-10 3:07 
GeneralRe: how to display properties on sale using google map Pin
Sandesh M Patil5-May-10 3:38
Sandesh M Patil5-May-10 3:38 
GeneralRe: how to display properties on sale using google map Pin
JHizzle5-May-10 3:27
JHizzle5-May-10 3:27 
AnswerRe: how to display properties on sale using google map Pin
T M Gray5-May-10 4:44
T M Gray5-May-10 4:44 
Questionsession lost in thread Pin
aamirzada5-May-10 2:11
aamirzada5-May-10 2:11 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.