lunedì 1 febbraio 2010

Wrappare che passione...

Dato che mi sarebbe tornato comodo crearmi un piccolo manager di sessione.. mi sono wrappato tutta la session.

Non mi ha dato di volta il cervello.. anche se ai più potrebbe sembrare. Per una questione di comodo mi trovo
a dover condividere quest'oggetto un po qua e un po la in un web application, e dato che non so e non posso
sapere chi o come aggiungerà elementi o chi o come li rimuoverà me la wrappo in toto, e poi mi occuperò di
aggiungere qualche metodo specializzato per la gestione in modo che chi aggiunge o toglie lo faccia come dico
IO !!

caso contrario sono dati "persi" o senza persistenza ..

cmq dato che potrebbe servire..

using System;
using System.Data;
using System.Collections;
using System.Configuration;
using System.Collections.Specialized;
using System.Web;
using System.Web.SessionState;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Life20.Commons
{
public class wrSession
{
private HttpSessionState _xSession = null;

#region Public Properties
public int CodePage
{
get { return _xSession.CodePage; }
}

public HttpSessionState Contents
{
get { return _xSession.Contents; }
}

public HttpCookieMode CookieMode
{
get { return _xSession.CookieMode; }
}
public int Count
{
get { return _xSession.Count; }
}

public bool IsCookieless
{
get { return _xSession.IsCookieless; }
}

public bool IsNewSession
{
get { return _xSession.IsNewSession; }
}

public bool IsReadOnly
{
get { return _xSession.IsReadOnly; }
}

public bool IsSynchronized
{
get { return _xSession.IsSynchronized; }
}

public NameObjectCollectionBase.KeysCollection Keys
{
get { return _xSession.Keys; }
}

public int LCID
{
get { return _xSession.LCID; }
}

public SessionStateMode Mode
{
get { return _xSession.Mode; }
}

public string SessionID
{
get { return _xSession.SessionID; }
}

public HttpStaticObjectsCollection StaticObjects
{
get { return _xSession.StaticObjects; }
}

public object SyncRoot
{
get { return _xSession.SyncRoot; }
}

public int Timeout
{
get { return _xSession.Timeout; }
set { _xSession.Timeout = value; }
}
#endregion

#region Builder
public wrSession(HttpSessionState crSession)
{
_xSession = crSession;
}
#endregion

#region Public Methods
public void Add(string _Name, object value )
{
_xSession.Add(_Name, value);
}

public void Abandon()
{
_xSession.Abandon();
}

public void Clear()
{
_xSession.Clear();
}

public void CopyTo(Array array, int index)
{
_xSession.CopyTo(array, index);
}

public override bool Equals(object obj)
{
return _xSession.Equals(obj);
}

public IEnumerator GetEnumerator()
{
return _xSession.GetEnumerator();
}

public override int GetHashCode()
{
return _xSession.GetHashCode();
}

public new Type GetType()
{
return _xSession.GetType();
}

public void Remove(string Name)
{
_xSession.Remove(Name);
}

public void RemoveAll()
{
_xSession.RemoveAll();
}

public void RemoveAt(int index)
{
_xSession.RemoveAt(index);
}

public override string ToString()
{
return _xSession.ToString();
}
#endregion
}
}


questa è la base.. senza naturalmente le mie specializzazioni...

Nessun commento: