/// <summary>
        /// Find a user to the database, and add them if they do not exist.
        /// </summary>
        /// <param name="UserName">The user name to find or add.</param>
        /// <param name="UserGroupId">The id of the user group to add the user to.</param>
        /// <returns>The id of the found or added user.</returns>
        /// <remarks>All user interaction is done this way to remove any dependencies on pre-populated tables.</remarks>
        public int FindOrAddUser(string UserName, int UserGroupId = 1)
        {
            int UserNameId = 0;

            try
            {
                IQueryable <int> UserNames = (from UserDetail in Users
                                              where UserDetail.UserName.ToLower() == UserName.ToLower()
                                              select UserDetail.Id);

                // If there is no existing user, add a new one
                if (UserNames.Count() == 0)
                {
                    User NewUser = new User();
                    NewUser.UserName    = UserName;
                    NewUser.UserGroupId = UserGroupId;
                    Users.InsertOnSubmit(NewUser);

                    SubmitChanges();
                    UserNameId = NewUser.Id;
                }
                else
                {
                    UserNameId = UserNames.First();
                }
            }
            catch (Exception Ex)
            {
                FLogger.WriteException("FindOrAddUser: " + Ex.ToString());
            }

            return(UserNameId);
        }
        /// <summary>
        /// Build a callstack pattern for a crash to ease bucketing of crashes into Buggs.
        /// </summary>
        /// <param name="CrashInstance">A crash that was recently added to the database.</param>
        public void BuildPattern(Crash CrashInstance)
        {
            using (FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer(this.GetType().ToString() + "(Crash=" + CrashInstance.Id + ")"))
            {
                List <string> Pattern = new List <string>();

                // Get an array of callstack items
                CallStackContainer CallStack = new CallStackContainer(CrashInstance);
                CallStack.bDisplayFunctionNames = true;

                if (CrashInstance.Pattern == null)
                {
                    // Set the module based on the modules in the callstack
                    CrashInstance.Module = CallStack.GetModuleName();
                    try
                    {
                        foreach (CallStackEntry Entry in CallStack.CallStackEntries)
                        {
                            FunctionCall CurrentFunctionCall = new FunctionCall();

                            if (FunctionCalls.Where(f => f.Call == Entry.FunctionName).Count() > 0)
                            {
                                CurrentFunctionCall = FunctionCalls.Where(f => f.Call == Entry.FunctionName).First();
                            }
                            else
                            {
                                CurrentFunctionCall      = new FunctionCall();
                                CurrentFunctionCall.Call = Entry.FunctionName;
                                FunctionCalls.InsertOnSubmit(CurrentFunctionCall);
                            }

                            SubmitChanges();

                            Pattern.Add(CurrentFunctionCall.Id.ToString());
                        }

                        //CrashInstance.Pattern = "+";
                        CrashInstance.Pattern = string.Join("+", Pattern);
                        // We need something like this +1+2+3+5+ for searching for exact pattern like +5+
                        //CrashInstance.Pattern += "+";

                        SubmitChanges();
                    }
                    catch (Exception Ex)
                    {
                        FLogger.WriteException("BuildPattern: " + Ex.ToString());
                    }
                }
            }
        }
        /// <summary>
        /// Sets the fixed in changelist for all crashes in a Bugg.
        /// </summary>
        /// <param name="FixedChangeList">A string representing a revision.</param>
        /// <param name="BuggId">The id of the Bugg to update the crashes for.</param>
        public void SetBuggFixedChangeList(string FixedChangeList, int BuggId)
        {
            try
            {
                string Query = "UPDATE Crashes SET FixedChangeList = {0} WHERE Id IN ( SELECT CrashId FROM Buggs_Crashes WHERE BuggId = {1} )";
                Context.ExecuteCommand(Query, FixedChangeList, BuggId);

                Query = "UPDATE Buggs SET FixedChangeList = {0} WHERE id = {1}";
                Context.ExecuteCommand(Query, FixedChangeList, BuggId);
            }
            catch (Exception Ex)
            {
                FLogger.WriteException("SetBuggFixedChangeList: " + Ex.ToString());
            }
        }
        /// <summary>
        /// Sets the status for all crashes in a Bugg.
        /// </summary>
        /// <param name="Status">The new status of all crashes.</param>
        /// <param name="BuggId">The id of the Bugg to update the crashes for.</param>
        public void SetBuggStatus(string Status, int BuggId)
        {
            try
            {
                string Query = "UPDATE Crashes SET Status = {0} WHERE Id IN ( SELECT CrashId FROM Buggs_Crashes WHERE BuggId = {1} )";
                Context.ExecuteCommand(Query, Status, BuggId);

                Query = "UPDATE Buggs SET Status = {0} WHERE id = {1}";
                Context.ExecuteCommand(Query, Status, BuggId);
            }
            catch (Exception Ex)
            {
                FLogger.WriteException("SetBuggStatus: " + Ex.ToString());
            }
        }
 /// <summary>
 /// Sets the UserName and UserGroupName as derived data for a crash.
 /// </summary>
 /// <param name="CrashInstance">An instance of a crash we wish to augment with additional data.</param>
 public void PopulateUserInfo(Crash CrashInstance)
 {
     using (FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer(this.GetType().ToString() + "(CrashId=" + CrashInstance.Id + ")"))
     {
         try
         {
             int UserGroupId = CrashInstance.User.UserGroupId;
             var Result      = Context.UserGroups.Where(i => i.Id == UserGroupId).First();
             CrashInstance.UserGroupName = Result.Name;
         }
         catch (Exception Ex)
         {
             FLogger.WriteException("PopulateUserInfo: " + Ex.ToString());
         }
     }
 }
Exemple #6
0
        /// <summary>
        /// Sets the JIRA for all crashes in a Bugg.
        /// </summary>
        /// <param name="JIRA">A string representing a TTP.</param>
        /// <param name="BuggId">The id of the Bugg to update the crashes for.</param>
        public static void SetJIRAForBuggAndCrashes(string JIRA, int BuggId)
        {
            try
            {
                using (FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer("SetJIRAForBuggAndCrashes (" + BuggId + ")"))
                {
                    string Query = "UPDATE Crashes SET TTPID = {0} WHERE Id IN ( SELECT CrashId FROM Buggs_Crashes WHERE BuggId = {1} )";
                    Context.ExecuteCommand(Query, JIRA, BuggId);

                    Query = "UPDATE Buggs SET TTPID = {0} WHERE id = {1}";
                    Context.ExecuteCommand(Query, JIRA, BuggId);
                }
            }
            catch (Exception Ex)
            {
                FLogger.WriteException("SetBuggTTPID: " + Ex.ToString());
            }
        }
        /// <summary>
        /// Sets a user group for a given user.
        /// </summary>
        /// <param name="UserName">The user name to update.</param>
        /// <param name="UserGroupName">The user group to add the user to.</param>
        public void SetUserGroup(string UserName, string UserGroupName)
        {
            try
            {
                IQueryable <int> UserGroups = (from UserGroupDetail in Context.UserGroups
                                               where UserGroupDetail.Name.ToLower() == UserGroupName.ToLower()
                                               select UserGroupDetail.Id);

                IQueryable <int> UserNames = (from UserDetail in Context.Users
                                              where UserDetail.UserName.ToLower() == UserName.ToLower()
                                              select UserDetail.Id);

                if (UserGroups.Count() == 1 && UserNames.Count() == 1)
                {
                    string Query = "UPDATE Users SET UserGroupId = {0} WHERE Id = {1}";
                    Context.ExecuteCommand(Query, UserGroups.First(), UserNames.First());
                }
            }
            catch (Exception Ex)
            {
                FLogger.WriteException("AdSetUserGroupdUser: " + Ex.ToString());
            }
        }