コード例 #1
0
        public static void MarkActivity()
        {
            using (var db = new SessionsContext())
            {
                if (db.LastActivity.Count() == 0)
                {
                    var entity = new LastActivityEntity();
                    entity.Last = DateTime.Now;
                    db.LastActivity.Add(entity);

                    // First Session
                    var session = new SessionEntity();
                    session.Start    = entity.Last.Value;
                    session.Complete = false;
                    session.End      = null;
                    db.Sessions.Add(session);
                }
                else
                {
                    var entity       = db.LastActivity.ToList().SingleOrDefault();
                    var previousTime = entity.Last;
                    entity.Last = DateTime.Now;

                    var delta = (entity.Last.Value - previousTime.Value).TotalMinutes;
                    if (delta >= 15.0)
                    {
                        HandleSession(db, entity.Last.Value, previousTime.Value);
                    }
                }

                db.SaveChanges();
            }
        }
コード例 #2
0
        public static void MarkCurrentPosition(String filePath)
        {
            using (var db = new SessionsContext())
            {
                if (db.LastActivity.Count() == 0)
                {
                    var e = new LastActivityEntity();
                    e.Last = DateTime.Now;
                    db.LastActivity.Add(e);
                }
                var entity = db.LastActivity.ToList().SingleOrDefault();

                // Clear up things in case they can't be set again.
                entity.LastFile      = "";
                entity.LastProject   = "";
                entity.LastNamespace = "";
                entity.LastClass     = "";
                entity.LastMethod    = "";

                String path = filePath;
                entity.LastFile = path;
                if (CodeElementMagic.CanSupportFile(filePath))
                {
                    try
                    {
                        var activeCodeElement = CodeElementMagic.GetCodeElementFromActivePoint();
                        if (activeCodeElement != null)
                        {
                            if (activeCodeElement.Kind == EnvDTE.vsCMElement.vsCMElementClass)
                            {
                                var codeKlass = activeCodeElement as EnvDTE.CodeClass;
                                entity.LastNamespace = codeKlass.Namespace.FullName;
                                entity.LastClass     = codeKlass.FullName;
                            }
                            else if (activeCodeElement.Kind == EnvDTE.vsCMElement.vsCMElementFunction)
                            {
                                var codeMethod = activeCodeElement as EnvDTE.CodeFunction;
                                var codeKlass  = codeMethod.Parent as EnvDTE.CodeClass;
                                if (codeKlass != null)
                                {
                                    entity.LastNamespace = codeKlass.Namespace.FullName;
                                    entity.LastClass     = codeKlass.FullName;
                                }
                                entity.LastMethod = codeMethod.FullName;
                            }
                        }
                    }
                    catch
                    {
                        // COM code likes to crap out
                    }
                }
                entity.LastProject = GetCurrentProject();

                db.SaveChanges();
            }
        }