Пример #1
0
        public static DebugSession CreateSession(RenderContext context, Guid CodeId)
        {
            if (context.WebSite == null)
            {
                return(null);
            }

            if (Sessions.ContainsKey(context.WebSite.Id))
            {
                var list = Sessions[context.WebSite.Id];

                lock (_locker)
                {
                    var find = list.Find(o => o.CodeId == CodeId && o.IpAddress == context.Request.IP);

                    if (find == null)
                    {
                        var sitedb = context.WebSite.SiteDb();
                        var code   = sitedb.Code.Get(CodeId);

                        find        = new DebugSession();
                        find.CodeId = CodeId;

                        if (code != null && code.IsEmbedded)
                        {
                            find.BodyHash = code.BodyHash;
                        }

                        find.IpAddress = context.Request.IP;
                        list.Add(find);
                        return(find);
                    }
                    else
                    {
                        return(find);
                    }
                }
            }
            else
            {
                lock (_locker)
                {
                    List <DebugSession> newsessions = new List <DebugSession>();
                    Sessions[context.WebSite.Id] = newsessions;

                    DebugSession session = new DebugSession();
                    session.CodeId     = CodeId;
                    session.IpAddress  = context.Request.IP;
                    session.ActiveTime = DateTime.Now;

                    var sitedb = context.WebSite.SiteDb();
                    var code   = sitedb.Code.Get(CodeId);

                    if (code != null && code.IsEmbedded)
                    {
                        session.BodyHash = code.BodyHash;
                    }


                    newsessions.Add(session);

                    return(session);
                }
            }
        }
Пример #2
0
 public static void RemoveSession(RenderContext context, DebugSession session)
 {
     RemoveSession(context, session.CodeId, session.IpAddress);
 }