/// <summary> /// Return an application istance that correspond with the request. /// </summary> /// <param name="e"></param> /// <param name="application"></param> /// <returns>false if not exist</returns> public bool TryGetApplicationInstance(HttpRequest e, out ApplicationInstanceBase application) { /// /// The logic to get the right application from a request is very simple, /// For identify the application we look the main path in the url, is the first after the domain domain.xxx ex: /// http://domain.xxc/maindir/dir1/dir2 so, dir1/dir2 are internal paths relatively at the main path maindir. /// The rule is the main path indicate the name of the application, so /// http://localhost:8080/chat/index.html identify the chat application /// http://localhost:8080/chat/chat2/index.html identify the chat application /// /// application = null; string[] paths = e.Path.Split(new string[] { "/" }, StringSplitOptions.RemoveEmptyEntries); if (paths.Length == 0) return false; string mainPath = paths[0]; /// /// Immediately check if exist an ApplicationUniqueName equal to mainpath /// if (!applications.ContainsKey(mainPath)) return false; //Ok the applicatoin Exist! SessionManager sessionMgr = applications[mainPath]; ApplicationSettings settings = sessionMgr.Info; string sessionKey = string.Empty; /// /// The SessionManager is found now we check if already exist any session /// switch (settings.SessionType) { case ApplicationSessionMode.SingletonSession: /// /// SingletonSession /// application = sessionMgr.GetOrCreateSingletonInstance(); return true; case ApplicationSessionMode.BrowserSession: /// /// We need a session key to identfy one particolare browser /// sessionKey = e.Rawrequest.Connection.IP + "@" + e.Requests["User-Agent"]; break; case ApplicationSessionMode.IpSession: /// /// We need a session key to identfy one Ip address /// sessionKey = e.Rawrequest.Connection.IP.ToString(); break; } application = sessionMgr.GetOrCreateInstanceBySessionKey(sessionKey); return true; }
/// <summary> /// This Events is triggered every time one session share a response. /// Requiere ResponseMode = Share /// </summary> /// <param name="sender"></param> /// <param name="response"></param> /// <param name="req"></param> public override void OnNewShareResponse(ApplicationInstanceBase sender, ApplicationResponse response, ApplicationRequest req) { }
/// <summary> /// Dispatch a response to the other sessions. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <param name="req"></param> public void ShareApplicationOutput(ApplicationInstanceBase sender, ApplicationResponse e, HttpRequest req) { //### verify if application exist if (applications.ContainsKey(sender.Info.UniqueApplicationName)) { //### Session manager cointains all instances SessionManager session = applications[sender.Info.UniqueApplicationName]; foreach (var item in session.SessionList) { //### Skip the sender if (item.Value.ApplicationId != sender.ApplicationId) { item.Value.OnNewShareResponse(sender, e, req); } } } }