/// <summary>
 /// The main view of the home page.
 /// </summary>
 public ActionResult Index()
 {
     using (FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ))
     {
         CrashesViewModel Result = new CrashesViewModel();
         Result.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
         return View( "Index", Result );
     }
 }
		/// <summary>
		/// The main view of the home page.
		/// </summary>
		public ActionResult Index()
		{
            using (var logTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ))
			{
				var result = new CrashesViewModel();
                result.BranchNames = _unitOfWork.CrashRepository.GetBranchesAsListItems();
                result.VersionNames = _unitOfWork.CrashRepository.GetVersionsAsListItems();
                result.PlatformNames = _unitOfWork.CrashRepository.GetPlatformsAsListItems();
                result.EngineModes = _unitOfWork.CrashRepository.GetEngineModesAsListItems();
                result.EngineVersions = _unitOfWork.CrashRepository.GetEngineVersionsAsListItems();
				result.GenerationTime = logTimer.GetElapsedSeconds().ToString( "F2" );
				return View( "Index", result );
			}
		}
        /*
        /// <summary>
        /// The empty view of the buggs page.
        /// </summary>
        ///
        public ActionResult Index()
        {
            using (FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ))
            {
                BuggsViewModel Results = new BuggsViewModel();
                Results.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
                return View( "Index", Results );
            }
        }*/
        /// <summary>
        /// The Index action.
        /// </summary>
        /// <param name="BuggsForm">The form of user data passed up from the client.</param>
        /// <returns>The view to display a list of Buggs on the client.</returns>
        public ActionResult Index( FormCollection BuggsForm )
        {
            using (FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ))
            {
                BuggRepository Buggs = new BuggRepository();

                FormHelper FormData = new FormHelper( Request, BuggsForm, "CrashesInTimeFrameGroup" );
                BuggsViewModel Results = Buggs.GetResults( FormData );
                foreach (var Bugg in Results.Results)
                {
                    // Populate function calls.
                    Bugg.GetFunctionCalls();
                }
                Results.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
                return View( "Index", Results );
            }
        }
		/// <summary>
		/// Get a report with the default form data and return the reports index view
		/// </summary>
		/// <param name="ReportsForm"></param>
		/// <returns></returns>
		public ActionResult Index( FormCollection ReportsForm )
		{
			using( FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ) )
			{
				FormHelper FormData = new FormHelper( Request, ReportsForm, "JustReport" );

				// Handle 'CopyToJira' button
				int BuggIDToBeAddedToJira = 0;
				foreach( var Entry in ReportsForm )
				{
                    if (Entry.ToString().Contains("CopyToJira-"))
					{
                        int.TryParse(Entry.ToString().Substring("CopyToJira-".Length), out BuggIDToBeAddedToJira);
						break;
					}
				}
                
				var results = GetResults( FormData, BuggIDToBeAddedToJira );
				results.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
				return View( "Index", results );
			}
		}
        /// <summary>
        /// The Show action.
        /// </summary>
        /// <param name="buggsForm">The form of user data passed up from the client.</param>
        /// <param name="id">The unique id of the Bugg.</param>
        /// <returns>The view to display a Bugg on the client.</returns>
        public ActionResult Show(FormCollection buggsForm, int id, int page = 0)
        {
            using (var logTimer = new FAutoScopedLogTimer(this.GetType().ToString() + "(BuggId=" + id + ")"))
            {
                using (var unitOfWork = new UnitOfWork(new CrashReportEntities()))
                {
                    // Set the display properties based on the radio buttons
                    var displayModuleNames   = buggsForm["DisplayModuleNames"] == "true";
                    var displayFunctionNames = buggsForm["DisplayFunctionNames"] == "true";
                    var displayFileNames     = buggsForm["DisplayFileNames"] == "true";
                    var displayFilePathNames = false;


                    // Set up the view model with the Crash data
                    if (buggsForm["Page"] != null)
                    {
                        int.TryParse(buggsForm["Page"], out page);
                    }

                    if (buggsForm["DisplayFilePathNames"] == "true")
                    {
                        displayFilePathNames = true;
                        displayFileNames     = false;
                    }

                    var displayUnformattedCallStack = buggsForm["DisplayUnformattedCallStack"] == "true";

                    var model = GetResult(id, page, pageSize, unitOfWork);
                    model.SourceContext = model.CrashData.First().SourceContext;
                    model.Bugg.PrepareBuggForJira(model.CrashData);
                    // Handle 'CopyToJira' button
                    var buggIdToBeAddedToJira = 0;
                    foreach (var entry in buggsForm.Cast <object>().Where(entry => entry.ToString().Contains("CopyToJira-")))
                    {
                        int.TryParse(entry.ToString().Substring("CopyToJira-".Length), out buggIdToBeAddedToJira);
                        break;
                    }
                    if (buggIdToBeAddedToJira != 0)
                    {
                        model.Bugg.JiraProject = buggsForm["JiraProject"];
                        model.Bugg.CopyToJira();
                    }

                    var jc         = JiraConnection.Get();
                    var bValidJira = false;

                    // Verify valid JiraID, this may be still a TTP
                    if (!string.IsNullOrEmpty(model.Bugg.TTPID))
                    {
                        var jira = 0;
                        int.TryParse(model.Bugg.TTPID, out jira);

                        if (jira == 0)
                        {
                            bValidJira = true;
                        }
                    }

                    if (jc.CanBeUsed() && bValidJira)
                    {
                        // Grab the data form JIRA.
                        var jiraSearchQuery = "key = " + model.Bugg.TTPID;
                        var jiraResults     = new Dictionary <string, Dictionary <string, object> >();

                        try
                        {
                            jiraResults = jc.SearchJiraTickets(
                                jiraSearchQuery,
                                new string[]
                            {
                                "key",                 // string
                                "summary",             // string
                                "components",          // System.Collections.ArrayList, Dictionary<string,object>, name
                                "resolution",          // System.Collections.Generic.Dictionary`2[System.String,System.Object], name
                                "fixVersions",         // System.Collections.ArrayList, Dictionary<string,object>, name
                                "customfield_11200"    // string
                            });
                        }
                        catch (System.Exception)
                        {
                            model.Bugg.JiraSummary         = "JIRA MISMATCH";
                            model.Bugg.JiraComponentsText  = "JIRA MISMATCH";
                            model.Bugg.JiraResolution      = "JIRA MISMATCH";
                            model.Bugg.JiraFixVersionsText = "JIRA MISMATCH";
                            model.Bugg.JiraFixCL           = "JIRA MISMATCH";
                        }

                        // Jira Key, Summary, Components, Resolution, Fix version, Fix changelist
                        if (jiraResults.Any())
                        {
                            var jira           = jiraResults.First();
                            var summary        = (string)jira.Value["summary"];
                            var componentsText = "";
                            var components     = (System.Collections.ArrayList)jira.Value["components"];
                            foreach (Dictionary <string, object> component in components)
                            {
                                componentsText += (string)component["name"];
                                componentsText += " ";
                            }

                            var resolutionFields = (Dictionary <string, object>)jira.Value["resolution"];
                            var resolution       = resolutionFields != null ? (string)resolutionFields["name"] : "";

                            var fixVersionsText = "";
                            var fixVersions     = (System.Collections.ArrayList)jira.Value["fixVersions"];
                            foreach (Dictionary <string, object> fixVersion in fixVersions)
                            {
                                fixVersionsText += (string)fixVersion["name"];
                                fixVersionsText += " ";
                            }

                            var fixCl = jira.Value["customfield_11200"] != null
                                            ? (int)(decimal)jira.Value["customfield_11200"]
                                            : 0;

                            //Conversion to ado.net entity framework

                            model.Bugg.JiraSummary         = summary;
                            model.Bugg.JiraComponentsText  = componentsText;
                            model.Bugg.JiraResolution      = resolution;
                            model.Bugg.JiraFixVersionsText = fixVersionsText;
                            if (fixCl != 0)
                            {
                                model.Bugg.FixedChangeList = fixCl.ToString();
                            }
                        }
                    }

                    // Apply any user settings
                    if (buggsForm.Count > 0)
                    {
                        if (!string.IsNullOrEmpty(buggsForm["SetStatus"]))
                        {
                            model.Bugg.Status = buggsForm["SetStatus"];
                            unitOfWork.CrashRepository.SetStatusByBuggId(model.Bugg.Id, buggsForm["SetFixedIn"]);
                        }

                        if (!string.IsNullOrEmpty(buggsForm["SetFixedIn"]))
                        {
                            model.Bugg.FixedChangeList = buggsForm["SetFixedIn"];
                            unitOfWork.CrashRepository.SetFixedCLByBuggId(model.Bugg.Id, buggsForm["SetFixedIn"]);
                        }

                        if (!string.IsNullOrEmpty(buggsForm["SetTTP"]))
                        {
                            model.Bugg.TTPID = buggsForm["SetTTP"];
                            unitOfWork.CrashRepository.SetJiraByBuggId(model.Bugg.Id, buggsForm["SetTTP"]);
                        }
                        unitOfWork.BuggRepository.Update(model.Bugg);

                        unitOfWork.Save();
                    }

                    var newCrash = model.CrashData.FirstOrDefault();
                    if (newCrash != null)
                    {
                        var callStack = new CallStackContainer(newCrash.CrashType, newCrash.RawCallStack, newCrash.PlatformName);

                        // Set callstack properties
                        callStack.bDisplayModuleNames          = displayModuleNames;
                        callStack.bDisplayFunctionNames        = displayFunctionNames;
                        callStack.bDisplayFileNames            = displayFileNames;
                        callStack.bDisplayFilePathNames        = displayFilePathNames;
                        callStack.bDisplayUnformattedCallStack = displayUnformattedCallStack;

                        model.CallStack = callStack;

                        // Shorten very long function names.
                        foreach (var entry in model.CallStack.CallStackEntries)
                        {
                            entry.FunctionName = entry.GetTrimmedFunctionName(128);
                        }

                        model.SourceContext = newCrash.SourceContext;

                        model.LatestCrashSummary = newCrash.Summary;
                    }

                    model.LatestCrashSummary      = newCrash.Summary;
                    model.Bugg.LatestCrashSummary = newCrash.Summary;
                    model.GenerationTime          = logTimer.GetElapsedSeconds().ToString("F2");

                    //Populate Jira Projects
                    var jiraConnection = JiraConnection.Get();
                    var response       = jiraConnection.JiraRequest("/issue/createmeta", JiraConnection.JiraMethod.GET, null,
                                                                    HttpStatusCode.OK);

                    using (var responseReader = new StreamReader(response.GetResponseStream()))
                    {
                        var responseText = responseReader.ReadToEnd();

                        JObject jsonObject = JObject.Parse(responseText);

                        JToken fields = jsonObject["projects"];

                        foreach (var project in fields)
                        {
                            model.JiraProjects.Add(new SelectListItem()
                            {
                                Text  = project["name"].ToObject <string>(),
                                Value = project["key"].ToObject <string>()
                            });
                        }
                    }

                    model.PagingInfo = new PagingInfo
                    {
                        CurrentPage  = page,
                        PageSize     = pageSize,
                        TotalResults = model.Bugg.NumberOfCrashes.Value
                    };

                    return(View("Show", model));
                }
            }
        }
        /// <summary>
        /// Show detailed information about a crash.
        /// </summary>
        /// <param name="CrashesForm">A form of user data passed up from the client.</param>
        /// <param name="id">The unique id of the crash we wish to show the details of.</param>
        /// <returns>A view to show crash details.</returns>
        public ActionResult Show(FormCollection CrashesForm, int id)
        {
            using (var logTimer = new FAutoScopedLogTimer(this.GetType().ToString() + "(CrashId=" + id + ")", bCreateNewLog: true))
            {
                CallStackContainer currentCallStack = null;

                // Update the selected crash based on the form contents
                var currentCrash = _unitOfWork.CrashRepository.GetById(id);

                if (currentCrash == null)
                {
                    return(RedirectToAction("Index"));
                }

                string FormValue;

                FormValue = CrashesForm["SetStatus"];
                if (!string.IsNullOrEmpty(FormValue))
                {
                    currentCrash.Status = FormValue;
                }

                FormValue = CrashesForm["SetFixedIn"];
                if (!string.IsNullOrEmpty(FormValue))
                {
                    currentCrash.FixedChangeList = FormValue;
                }

                FormValue = CrashesForm["SetTTP"];
                if (!string.IsNullOrEmpty(FormValue))
                {
                    currentCrash.Jira = FormValue;
                }

                // Valid to set description to an empty string
                FormValue = CrashesForm["Description"];
                if (FormValue != null)
                {
                    currentCrash.Description = FormValue;
                }

                currentCallStack    = new CallStackContainer(currentCrash);
                currentCrash.Module = currentCallStack.GetModuleName();

                //Set call stack properties
                currentCallStack.bDisplayModuleNames          = true;
                currentCallStack.bDisplayFunctionNames        = true;
                currentCallStack.bDisplayFileNames            = true;
                currentCallStack.bDisplayFilePathNames        = true;
                currentCallStack.bDisplayUnformattedCallStack = false;

                currentCrash.CallStackContainer = new CallStackContainer(currentCrash);

                // Populate the crash with the correct user data
                //_crashRepo.PopulateUserInfo( CurrentCrash );
                //_crashRepo.SubmitChanges();

                var Model = new CrashViewModel {
                    Crash = currentCrash, CallStack = currentCallStack
                };
                Model.GenerationTime = logTimer.GetElapsedSeconds().ToString("F2");
                return(View("Show", Model));
            }
        }
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public ActionResult Index( FormCollection Form )
 {
     using( FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ) )
     {
         FormHelper FormData = new FormHelper( Request, Form, "JustReport" );
         CSV_ViewModel Results = GetResults( FormData );
         Results.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
         return View( "Index", Results );
     }
 }
Exemple #8
0
        /// <summary>
        /// The Show action.
        /// </summary>
        /// <param name="BuggsForm">The form of user data passed up from the client.</param>
        /// <param name="id">The unique id of the Bugg.</param>
        /// <returns>The view to display a Bugg on the client.</returns>
        public ActionResult Show(FormCollection BuggsForm, int id)
        {
            using (FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer(this.GetType().ToString() + "(BuggId=" + id + ")", bCreateNewLog: true))
            {
                // Handle 'CopyToJira' button
                int BuggIDToBeAddedToJira = 0;
                foreach (var Entry in BuggsForm)
                {
                    if (Entry.ToString().Contains(Bugg.JiraSubmitName))
                    {
                        int.TryParse(Entry.ToString().Substring(Bugg.JiraSubmitName.Length), out BuggIDToBeAddedToJira);
                        break;
                    }
                }

                BuggRepository Buggs = new BuggRepository();

                // Set the display properties based on the radio buttons
                bool DisplayModuleNames = false;
                if (BuggsForm["DisplayModuleNames"] == "true")
                {
                    DisplayModuleNames = true;
                }

                bool DisplayFunctionNames = false;
                if (BuggsForm["DisplayFunctionNames"] == "true")
                {
                    DisplayFunctionNames = true;
                }

                bool DisplayFileNames = false;
                if (BuggsForm["DisplayFileNames"] == "true")
                {
                    DisplayFileNames = true;
                }

                bool DisplayFilePathNames = false;
                if (BuggsForm["DisplayFilePathNames"] == "true")
                {
                    DisplayFilePathNames = true;
                    DisplayFileNames     = false;
                }

                bool DisplayUnformattedCallStack = false;
                if (BuggsForm["DisplayUnformattedCallStack"] == "true")
                {
                    DisplayUnformattedCallStack = true;
                }

                // Create a new view and populate with crashes
                List <Crash> Crashes = null;

                BuggViewModel Model   = new BuggViewModel();
                Bugg          NewBugg = Buggs.GetBugg(id);
                if (NewBugg == null)
                {
                    return(RedirectToAction(""));
                }

                Crashes = NewBugg.GetCrashes();

                using (FAutoScopedLogTimer GetCrashesTimer = new FAutoScopedLogTimer("Bugg.PrepareBuggForJira"))
                {
                    NewBugg.PrepareBuggForJira(Crashes);

                    if (BuggIDToBeAddedToJira != 0)
                    {
                        NewBugg.CopyToJira();
                    }
                }

                using (FAutoScopedLogTimer JiraResultsTimer = new FAutoScopedLogTimer("Bugg.GrabJira"))
                {
                    var  JC         = JiraConnection.Get();
                    bool bValidJira = false;

                    // Verify valid JiraID, this may be still a TTP
                    if (!string.IsNullOrEmpty(NewBugg.Jira))
                    {
                        int TTPID = 0;
                        int.TryParse(NewBugg.Jira, out TTPID);

                        if (TTPID == 0)
                        {
                            //AddBuggJiraMapping( NewBugg, ref FoundJiras, ref JiraIDtoBugg );
                            bValidJira = true;
                        }
                    }

                    if (JC.CanBeUsed() && bValidJira)
                    {
                        // Grab the data form JIRA.
                        string JiraSearchQuery = "key = " + NewBugg.Jira;

                        var JiraResults = JC.SearchJiraTickets(
                            JiraSearchQuery,
                            new string[]
                        {
                            "key",                                                  // string
                            "summary",                                              // string
                            "components",                                           // System.Collections.ArrayList, Dictionary<string,object>, name
                            "resolution",                                           // System.Collections.Generic.Dictionary`2[System.String,System.Object], name
                            "fixVersions",                                          // System.Collections.ArrayList, Dictionary<string,object>, name
                            "customfield_11200"                                     // string
                        });


                        // Jira Key, Summary, Components, Resolution, Fix version, Fix changelist
                        foreach (var Jira in JiraResults)
                        {
                            string JiraID = Jira.Key;

                            string Summary = (string)Jira.Value["summary"];

                            string ComponentsText = "";
                            System.Collections.ArrayList Components = (System.Collections.ArrayList)Jira.Value["components"];
                            foreach (Dictionary <string, object> Component in Components)
                            {
                                ComponentsText += (string)Component["name"];
                                ComponentsText += " ";
                            }

                            Dictionary <string, object> ResolutionFields = (Dictionary <string, object>)Jira.Value["resolution"];
                            string Resolution = ResolutionFields != null ? (string)ResolutionFields["name"] : "";

                            string FixVersionsText = "";
                            System.Collections.ArrayList FixVersions = (System.Collections.ArrayList)Jira.Value["fixVersions"];
                            foreach (Dictionary <string, object> FixVersion in FixVersions)
                            {
                                FixVersionsText += (string)FixVersion["name"];
                                FixVersionsText += " ";
                            }

                            int FixCL = Jira.Value["customfield_11200"] != null ? (int)(decimal)Jira.Value["customfield_11200"] : 0;

                            NewBugg.JiraSummary         = Summary;
                            NewBugg.JiraComponentsText  = ComponentsText;
                            NewBugg.JiraResolution      = Resolution;
                            NewBugg.JiraFixVersionsText = FixVersionsText;
                            if (FixCL != 0)
                            {
                                NewBugg.JiraFixCL = FixCL.ToString();
                            }

                            break;
                        }
                    }
                }

                // Apply any user settings
                if (BuggsForm.Count > 0)
                {
                    if (!string.IsNullOrEmpty(BuggsForm["SetStatus"]))
                    {
                        NewBugg.Status = BuggsForm["SetStatus"];
                        Buggs.SetBuggStatus(NewBugg.Status, id);
                    }

                    if (!string.IsNullOrEmpty(BuggsForm["SetFixedIn"]))
                    {
                        NewBugg.FixedChangeList = BuggsForm["SetFixedIn"];
                        Buggs.SetBuggFixedChangeList(NewBugg.FixedChangeList, id);
                    }

                    if (!string.IsNullOrEmpty(BuggsForm["SetTTP"]))
                    {
                        NewBugg.Jira = BuggsForm["SetTTP"];
                        Buggs.SetJIRAForBuggAndCrashes(NewBugg.Jira, id);
                    }

                    // <STATUS>
                }

                // Set up the view model with the crash data
                Model.Bugg    = NewBugg;
                Model.Crashes = Crashes;

                Crash NewCrash = Model.Crashes.FirstOrDefault();
                if (NewCrash != null)
                {
                    using (FScopedLogTimer LogTimer2 = new FScopedLogTimer("CallstackTrimming"))
                    {
                        CallStackContainer CallStack = new CallStackContainer(NewCrash);

                        // Set callstack properties
                        CallStack.bDisplayModuleNames          = DisplayModuleNames;
                        CallStack.bDisplayFunctionNames        = DisplayFunctionNames;
                        CallStack.bDisplayFileNames            = DisplayFileNames;
                        CallStack.bDisplayFilePathNames        = DisplayFilePathNames;
                        CallStack.bDisplayUnformattedCallStack = DisplayUnformattedCallStack;

                        Model.CallStack = CallStack;

                        // Shorten very long function names.
                        foreach (CallStackEntry Entry in Model.CallStack.CallStackEntries)
                        {
                            Entry.FunctionName = Entry.GetTrimmedFunctionName(128);
                        }

                        Model.SourceContext = NewCrash.SourceContext;
                    }

                    Model.Bugg.LatestCrashSummary = NewCrash.Summary;
                }

                Model.GenerationTime = LogTimer.GetElapsedSeconds().ToString("F2");
                return(View("Show", Model));
            }
        }
        /// <summary>
        /// The Show action.
        /// </summary>
        /// <param name="buggsForm">The form of user data passed up from the client.</param>
        /// <param name="id">The unique id of the Bugg.</param>
        /// <returns>The view to display a Bugg on the client.</returns>
        public ActionResult Show(FormCollection buggsForm, int id)
        {
            using (var logTimer = new FAutoScopedLogTimer(this.GetType().ToString() + "(BuggId=" + id + ")", bCreateNewLog: true))
            {
                // Set the display properties based on the radio buttons
                var displayModuleNames   = buggsForm["DisplayModuleNames"] == "true";
                var displayFunctionNames = buggsForm["DisplayFunctionNames"] == "true";
                var displayFileNames     = buggsForm["DisplayFileNames"] == "true";
                var displayFilePathNames = false;
                if (buggsForm["DisplayFilePathNames"] == "true")
                {
                    displayFilePathNames = true;
                    displayFileNames     = false;
                }
                var displayUnformattedCallStack = buggsForm["DisplayUnformattedCallStack"] == "true";

                // Create a new view and populate with crashes
                List <Crash> crashes = null;
                var          model   = new BuggViewModel();
                var          newBugg = _unitOfWork.BuggRepository.GetById(id);
                if (newBugg == null)
                {
                    return(RedirectToAction("Index"));
                }
                crashes = newBugg.Crashes.OrderByDescending(data => data.TimeOfCrash).ToList();
                newBugg.CrashesInTimeFrameAll   = crashes.Count;
                newBugg.CrashesInTimeFrameGroup = crashes.Count;
                newBugg.NumberOfCrashes         = crashes.Count;

                // Handle 'CopyToJira' button
                var buggIdToBeAddedToJira = 0;
                foreach (var entry in buggsForm.Cast <object>().Where(entry => entry.ToString().Contains("CopyToJira-")))
                {
                    int.TryParse(entry.ToString().Substring("CopyToJira-".Length), out buggIdToBeAddedToJira);
                    break;
                }

                newBugg.PrepareBuggForJira(crashes);
                if (buggIdToBeAddedToJira != 0)
                {
                    newBugg.JiraProject = buggsForm["JiraProject"];
                    newBugg.CopyToJira();
                }

                var jc         = JiraConnection.Get();
                var bValidJira = false;

                // Verify valid JiraID, this may be still a TTP
                if (!string.IsNullOrEmpty(newBugg.TTPID))
                {
                    var jira = 0;
                    int.TryParse(newBugg.TTPID, out jira);

                    if (jira == 0)
                    {
                        bValidJira = true;
                    }
                }

                if (jc.CanBeUsed() && bValidJira)
                {
                    // Grab the data form JIRA.
                    var jiraSearchQuery = "key = " + newBugg.TTPID;
                    var jiraResults     = new Dictionary <string, Dictionary <string, object> >();

                    try
                    {
                        jiraResults = jc.SearchJiraTickets(
                            jiraSearchQuery,
                            new string[]
                        {
                            "key",                                          // string
                            "summary",                                      // string
                            "components",                                   // System.Collections.ArrayList, Dictionary<string,object>, name
                            "resolution",                                   // System.Collections.Generic.Dictionary`2[System.String,System.Object], name
                            "fixVersions",                                  // System.Collections.ArrayList, Dictionary<string,object>, name
                            "customfield_11200"                             // string
                        });
                    }
                    catch (System.Exception)
                    {
                        newBugg.JiraSummary         = "JIRA MISMATCH";
                        newBugg.JiraComponentsText  = "JIRA MISMATCH";
                        newBugg.JiraResolution      = "JIRA MISMATCH";
                        newBugg.JiraFixVersionsText = "JIRA MISMATCH";
                        newBugg.JiraFixCL           = "JIRA MISMATCH";
                    }

                    // Jira Key, Summary, Components, Resolution, Fix version, Fix changelist
                    if (jiraResults.Any())
                    {
                        var jira    = jiraResults.First();
                        var summary = (string)jira.Value["summary"];

                        var componentsText = "";
                        var components     = (System.Collections.ArrayList)jira.Value["components"];
                        foreach (Dictionary <string, object> component in components)
                        {
                            componentsText += (string)component["name"];
                            componentsText += " ";
                        }

                        var resolutionFields = (Dictionary <string, object>)jira.Value["resolution"];
                        var resolution       = resolutionFields != null ? (string)resolutionFields["name"] : "";

                        var fixVersionsText = "";
                        var fixVersions     = (System.Collections.ArrayList)jira.Value["fixVersions"];
                        foreach (Dictionary <string, object> fixVersion in fixVersions)
                        {
                            fixVersionsText += (string)fixVersion["name"];
                            fixVersionsText += " ";
                        }

                        var fixCl = jira.Value["customfield_11200"] != null ? (int)(decimal)jira.Value["customfield_11200"] : 0;

                        //Conversion to ado.net entity framework

                        newBugg.JiraSummary         = summary;
                        newBugg.JiraComponentsText  = componentsText;
                        newBugg.JiraResolution      = resolution;
                        newBugg.JiraFixVersionsText = fixVersionsText;
                        if (fixCl != 0)
                        {
                            newBugg.FixedChangeList = fixCl.ToString();
                        }
                    }
                }

                // Apply any user settings
                if (buggsForm.Count > 0)
                {
                    if (!string.IsNullOrEmpty(buggsForm["SetStatus"]))
                    {
                        newBugg.Status = buggsForm["SetStatus"];
                        newBugg.Crashes.ForEach(data => data.Status = buggsForm["SetStatus"]);
                    }

                    if (!string.IsNullOrEmpty(buggsForm["SetFixedIn"]))
                    {
                        newBugg.FixedChangeList = buggsForm["SetFixedIn"];
                        newBugg.Crashes.ForEach(data => data.FixedChangeList = buggsForm["SetFixedIn"]);
                    }

                    if (!string.IsNullOrEmpty(buggsForm["SetTTP"]))
                    {
                        newBugg.TTPID = buggsForm["SetTTP"];
                        newBugg.Crashes.ForEach(data => data.Jira = buggsForm["SetTTP"]);
                    }

                    _unitOfWork.BuggRepository.Update(newBugg);
                    _unitOfWork.Save();
                }

                // Set up the view model with the crash data
                model.Crashes = crashes;
                model.Bugg    = newBugg;

                var newCrash = model.Crashes.FirstOrDefault();
                if (newCrash != null)
                {
                    var callStack = new CallStackContainer(newCrash);

                    // Set callstack properties
                    callStack.bDisplayModuleNames          = displayModuleNames;
                    callStack.bDisplayFunctionNames        = displayFunctionNames;
                    callStack.bDisplayFileNames            = displayFileNames;
                    callStack.bDisplayFilePathNames        = displayFilePathNames;
                    callStack.bDisplayUnformattedCallStack = displayUnformattedCallStack;

                    model.CallStack = callStack;

                    // Shorten very long function names.
                    foreach (var entry in model.CallStack.CallStackEntries)
                    {
                        entry.FunctionName = entry.GetTrimmedFunctionName(128);
                    }

                    model.SourceContext = newCrash.SourceContext;

                    model.LatestCrashSummary = newCrash.Summary;
                }
                model.LatestCrashSummary      = newCrash.Summary;
                model.Bugg.LatestCrashSummary = newCrash.Summary;
                model.GenerationTime          = logTimer.GetElapsedSeconds().ToString("F2");
                return(View("Show", model));
            }
        }
        /// <summary>
        /// The main view of the dash board.
        /// </summary>
        /// <returns>A view showing two charts of Crashes over time.</returns>
        public ActionResult Index()
        {
            using (FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer(this.GetType().ToString(), bCreateNewLog: true))
            {
                DateTime Today         = DateTime.UtcNow;
                DateTime AfewMonthsAgo = Today.AddMonths(-6);

                FAutoScopedLogTimer LogTimerSQL = new FAutoScopedLogTimer("CrashesFilterByDate", "", "");

                // Get engine versions from the last 6 months.
                var           TempVersions      = _Crashes.GetVersions();
                List <string> EngineUE4Versions = new List <string>();
                foreach (var Version in TempVersions)
                {
                    if (Version.StartsWith("4."))
                    {
                        EngineUE4Versions.Add(Version);
                    }
                }

                // Only 4 latest version.
                EngineUE4Versions = EngineUE4Versions.OrderByDescending(item => item).Take(5).ToList();

                var endDate = Today.AddDays(1);

                IQueryable <Crash> CrashesInTimeFrame = _Crashes.ListAll()
                                                        .Where(MyCrash => MyCrash.TimeOfCrash >= AfewMonthsAgo && MyCrash.TimeOfCrash <= endDate);
                //IEnumerable<Crash> Crashes = FRepository.Get().Crashes.FilterByDate( FRepository.Get().Crashes.ListAll(), AfewMonthsAgo, Today );
                var VMinimalCrashes = CrashesInTimeFrame.Select(Crash => new
                {
                    TimeOfCrash   = Crash.TimeOfCrash,
                    UserID        = Crash.UserId,
                    EngineVersion = Crash.BuildVersion,
                })
                                      .ToList();

                List <FCrashMinimal> MinimalCrashes = new List <FCrashMinimal>(VMinimalCrashes.Count);
                foreach (var Anotype in VMinimalCrashes)
                {
                    MinimalCrashes.Add(new FCrashMinimal(Anotype.TimeOfCrash, Anotype.UserID, Anotype.EngineVersion));
                }
                LogTimerSQL.Dispose();

                HashSet <int> AnonumousIDs = new HashSet <int>(_entities.UserGroups.First(data => data.Name == "Anonymous").Users.Select(data => data.Id));
                int           AnonymousID  = AnonumousIDs.First();

                int GeneralUserGroupId  = 1;         //FRepository.Get( _Crashes ).FindOrAddGroup( "General" );
                int CoderUserGroupId    = 3;         //FRepository.Get( _Crashes ).FindOrAddGroup( "Coder" );
                int EngineQAUserGroupId = 22;        //FRepository.Get( _Crashes ).FindOrAddGroup( "EngineQA" );
                int GameQAUserGroupId   = 21;        //FRepository.Get( _Crashes ).FindOrAddGroup( "GameQA" );

                // Weekly
                Dictionary <DateTime, int> WeeklyGeneralResults  = GetWeeklyCountsByGroup(MinimalCrashes, GeneralUserGroupId);
                Dictionary <DateTime, int> WeeklyCoderResults    = GetWeeklyCountsByGroup(MinimalCrashes, CoderUserGroupId);
                Dictionary <DateTime, int> WeeklyEngineQAResults = GetWeeklyCountsByGroup(MinimalCrashes, EngineQAUserGroupId);
                Dictionary <DateTime, int> WeeklyGameQAResults   = GetWeeklyCountsByGroup(MinimalCrashes, GameQAUserGroupId);

                Dictionary <string, Dictionary <DateTime, int> > WeeklyEngineVersionResults = new Dictionary <string, Dictionary <DateTime, int> >();
                foreach (string UE4Version in EngineUE4Versions)
                {
                    Dictionary <DateTime, int> Results = GetWeeklyCountsByVersion(MinimalCrashes, UE4Version, AnonymousID);
                    WeeklyEngineVersionResults.Add(UE4Version, Results);
                }

                Dictionary <DateTime, int> WeeklyAllResults = GetWeeklyCountsByGroup(MinimalCrashes, AllUserGroupId);

                // Daily
                Dictionary <DateTime, int> DailyGeneralResults  = GetDailyCountsByGroup(MinimalCrashes, GeneralUserGroupId);
                Dictionary <DateTime, int> DailyCoderResults    = GetDailyCountsByGroup(MinimalCrashes, CoderUserGroupId);
                Dictionary <DateTime, int> DailyEngineQAResults = GetDailyCountsByGroup(MinimalCrashes, EngineQAUserGroupId);
                Dictionary <DateTime, int> DailyGameQAResults   = GetDailyCountsByGroup(MinimalCrashes, GameQAUserGroupId);


                Dictionary <string, Dictionary <DateTime, int> > DailyEngineVersionResults = new Dictionary <string, Dictionary <DateTime, int> >();
                foreach (string UE4Version in EngineUE4Versions)
                {
                    Dictionary <DateTime, int> Results = GetDailyCountsByVersion(MinimalCrashes, UE4Version, AnonymousID);
                    DailyEngineVersionResults.Add(UE4Version, Results);
                }

                Dictionary <DateTime, int> DailyAllResults = GetDailyCountsByGroup(MinimalCrashes, AllUserGroupId);

                // Get daily buggs stats.
                List <Bugg> Buggs = _Buggs.ListAll().Where(Bugg => Bugg.TimeOfFirstCrash >= AfewMonthsAgo).ToList();

                Dictionary <DateTime, int> BuggDailyAllResults =
                    (
                        from Bugg in Buggs
                        group Bugg by Bugg.TimeOfFirstCrash.Value.Date into GroupCount
                        orderby GroupCount.Key
                        select new { Count = GroupCount.Count(), Date = GroupCount.Key }
                    ).ToDictionary(x => x.Date, y => y.Count);


                string CrashesByWeek = "";

                foreach (KeyValuePair <DateTime, int> WeeklyResult in WeeklyAllResults)
                {
                    int GeneralCrashes = 0;
                    WeeklyGeneralResults.TryGetValue(WeeklyResult.Key, out GeneralCrashes);

                    int CoderCrashes = 0;
                    WeeklyCoderResults.TryGetValue(WeeklyResult.Key, out CoderCrashes);

                    int EngineQACrashes = 0;
                    WeeklyEngineQAResults.TryGetValue(WeeklyResult.Key, out EngineQACrashes);

                    int GameQACrashes = 0;
                    WeeklyGameQAResults.TryGetValue(WeeklyResult.Key, out GameQACrashes);

                    string AnonymousLine = "";
                    foreach (var VersionCrashes in WeeklyEngineVersionResults)
                    {
                        int EngineVersionCrashes = 0;
                        VersionCrashes.Value.TryGetValue(WeeklyResult.Key, out EngineVersionCrashes);

                        AnonymousLine += EngineVersionCrashes;
                        AnonymousLine += ", ";
                    }

                    int Year  = WeeklyResult.Key.Year;
                    int Month = WeeklyResult.Key.AddMonths(-1).Month;
                    if (WeeklyResult.Key.Month == 13 || WeeklyResult.Key.Month == 1)
                    {
                        Month = 0;
                    }

                    int Day = WeeklyResult.Key.Day + 6;

                    string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + GeneralCrashes + ", " + CoderCrashes + ", " + EngineQACrashes + ", " + GameQACrashes + ", " + AnonymousLine + WeeklyResult.Value + "], ";
                    CrashesByWeek += Line;
                }

                CrashesByWeek = CrashesByWeek.TrimEnd(", ".ToCharArray());

                string CrashesByDay = "";
                foreach (KeyValuePair <DateTime, int> DailyResult in DailyAllResults)
                {
                    int GeneralCrashes = 0;
                    DailyGeneralResults.TryGetValue(DailyResult.Key, out GeneralCrashes);

                    int CoderCrashes = 0;
                    DailyCoderResults.TryGetValue(DailyResult.Key, out CoderCrashes);

                    int EngineQACrashes = 0;
                    DailyEngineQAResults.TryGetValue(DailyResult.Key, out EngineQACrashes);

                    int GameQACrashes = 0;
                    DailyGameQAResults.TryGetValue(DailyResult.Key, out GameQACrashes);

                    string AnonymousLine = "";
                    foreach (var VersionCrashes in DailyEngineVersionResults)
                    {
                        int EngineVersionCrashes = 0;
                        VersionCrashes.Value.TryGetValue(DailyResult.Key, out EngineVersionCrashes);

                        AnonymousLine += EngineVersionCrashes;
                        AnonymousLine += ", ";
                    }

                    int Year  = DailyResult.Key.Year;
                    int Month = DailyResult.Key.AddMonths(-1).Month;
                    if (DailyResult.Key.Month == 13 || DailyResult.Key.Month == 1)
                    {
                        Month = 0;
                    }

                    int Day = DailyResult.Key.Day;

                    string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + GeneralCrashes + ", " + CoderCrashes + ", " + EngineQACrashes + ", " + GameQACrashes + ", " + AnonymousLine + DailyResult.Value + "], ";
                    CrashesByDay += Line;
                }

                CrashesByDay = CrashesByDay.TrimEnd(", ".ToCharArray());

                string BuggsByDay = "";
                foreach (KeyValuePair <DateTime, int> DailyResult in BuggDailyAllResults)
                {
                    int Year  = DailyResult.Key.Year;
                    int Month = DailyResult.Key.AddMonths(-1).Month;
                    if (DailyResult.Key.Month == 13 || DailyResult.Key.Month == 1)
                    {
                        Month = 0;
                    }

                    int Day = DailyResult.Key.Day;

                    string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + DailyResult.Value + "], ";
                    BuggsByDay += Line;
                }

                BuggsByDay = BuggsByDay.TrimEnd(", ".ToCharArray());

                var ResultDashboard = new DashboardViewModel
                {
                    CrashesByWeek  = CrashesByWeek,
                    CrashesByDay   = CrashesByDay,
                    BuggsByDay     = BuggsByDay,
                    EngineVersions = EngineUE4Versions,
                };
                ResultDashboard.GenerationTime = LogTimer.GetElapsedSeconds().ToString("F2");
                return(View("Index", ResultDashboard));
            }
        }
        /// <summary>
        /// Display a summary list of crashes based on the search criteria.
        /// </summary>
        /// <param name="CrashesForm">A form of user data passed up from the client.</param>
        /// <returns>A view to display a list of crash reports.</returns>
        public ActionResult Index( FormCollection CrashesForm )
        {
            using( FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ) )
            {
                CrashRepository Crashes = new CrashRepository();

                // Handle any edits made in the Set form fields
                foreach( var Entry in CrashesForm )
                {
                    int Id = 0;
                    if( int.TryParse( Entry.ToString(), out Id ) )
                    {
                        Crash CurrentCrash = Crashes.GetCrash( Id );
                        if( CurrentCrash != null )
                        {
                            if( !string.IsNullOrEmpty( CrashesForm["SetStatus"] ) )
                            {
                                CurrentCrash.Status = CrashesForm["SetStatus"];
                            }

                            if( !string.IsNullOrEmpty( CrashesForm["SetFixedIn"] ) )
                            {
                                CurrentCrash.FixedChangeList = CrashesForm["SetFixedIn"];
                            }

                            if( !string.IsNullOrEmpty( CrashesForm["SetTTP"] ) )
                            {
                                CurrentCrash.Jira = CrashesForm["SetTTP"];
                            }
                        }
                    }

                    Crashes.SubmitChanges();
                }

                // <STATUS>

                // Parse the contents of the query string, and populate the form
                FormHelper FormData = new FormHelper( Request, CrashesForm, "TimeOfCrash" );
                CrashesViewModel Result = Crashes.GetResults( FormData );

                // Add the FromCollection to the CrashesViewModel since we don't need it for the get results function but we do want to post it back to the page.
                Result.FormCollection = CrashesForm;
                Result.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
                return View( "Index", Result );
            }
        }
		/// <summary>
		/// The main view of the dash board.
		/// </summary>
		/// <returns>A view showing two charts of crashes over time.</returns>
		public ActionResult Index()
		{
			using( FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ) )
			{
				DateTime Today = DateTime.UtcNow;
				DateTime AfewMonthsAgo = Today.AddMonths( -6 );

				FAutoScopedLogTimer LogTimerSQL = new FAutoScopedLogTimer( "CrashesFilterByDate", "", "" );

				// Get engine versions from the last 6 months.
				var TempVersions = _Crashes.GetVersions();
				List<string> EngineUE4Versions = new List<string>();
				foreach (var Version in TempVersions)
				{
					if( Version.StartsWith("4.") )
					{
						EngineUE4Versions.Add( Version );
					}
				}

				// Only 4 latest version.
				EngineUE4Versions = EngineUE4Versions.OrderByDescending( item => item ).Take( 5 ).ToList();

			    var endDate = Today.AddDays(1);

				IQueryable<Crash> CrashesInTimeFrame = _Crashes.ListAll()
                    .Where(MyCrash => MyCrash.TimeOfCrash >= AfewMonthsAgo && MyCrash.TimeOfCrash <= endDate);
				//IEnumerable<Crash> Crashes = FRepository.Get().Crashes.FilterByDate( FRepository.Get().Crashes.ListAll(), AfewMonthsAgo, Today );
				var VMinimalCrashes = CrashesInTimeFrame.Select( Crash => new 
				{ 
					TimeOfCrash = Crash.TimeOfCrash.Value, 
					UserID = Crash.UserNameId.Value,
					EngineVersion = Crash.BuildVersion,
				} )
				.ToList();

				List<FCrashMinimal> MinimalCrashes = new List<FCrashMinimal>( VMinimalCrashes.Count );
				foreach( var Anotype in VMinimalCrashes )
				{
					MinimalCrashes.Add( new FCrashMinimal( Anotype.TimeOfCrash, Anotype.UserID, Anotype.EngineVersion ) );
				}
				LogTimerSQL.Dispose();

			    HashSet<int> AnonumousIDs = new HashSet<int>(_entities.UserGroups.First(data => data.Name == "Anonymous").Users.Select(data => data.Id));
				int AnonymousID = AnonumousIDs.First();

			    int GeneralUserGroupId = 1;//FRepository.Get( _Crashes ).FindOrAddGroup( "General" );
			    int CoderUserGroupId = 3;//FRepository.Get( _Crashes ).FindOrAddGroup( "Coder" );
			    int EngineQAUserGroupId = 22;//FRepository.Get( _Crashes ).FindOrAddGroup( "EngineQA" );
			    int GameQAUserGroupId = 21;//FRepository.Get( _Crashes ).FindOrAddGroup( "GameQA" );

				// Weekly
				Dictionary<DateTime, int> WeeklyGeneralResults = GetWeeklyCountsByGroup( MinimalCrashes, GeneralUserGroupId );
				Dictionary<DateTime, int> WeeklyCoderResults = GetWeeklyCountsByGroup( MinimalCrashes, CoderUserGroupId );
				Dictionary<DateTime, int> WeeklyEngineQAResults = GetWeeklyCountsByGroup( MinimalCrashes, EngineQAUserGroupId );
				Dictionary<DateTime, int> WeeklyGameQAResults = GetWeeklyCountsByGroup( MinimalCrashes, GameQAUserGroupId );

				Dictionary<string, Dictionary<DateTime, int>> WeeklyEngineVersionResults = new Dictionary<string, Dictionary<DateTime, int>>();
				foreach (string UE4Version in EngineUE4Versions)
				{
					Dictionary<DateTime, int> Results = GetWeeklyCountsByVersion( MinimalCrashes, UE4Version, AnonymousID );
					WeeklyEngineVersionResults.Add( UE4Version, Results );
				}

				Dictionary<DateTime, int> WeeklyAllResults = GetWeeklyCountsByGroup( MinimalCrashes, AllUserGroupId );
				
				// Daily
				Dictionary<DateTime, int> DailyGeneralResults = GetDailyCountsByGroup( MinimalCrashes, GeneralUserGroupId );
				Dictionary<DateTime, int> DailyCoderResults = GetDailyCountsByGroup( MinimalCrashes, CoderUserGroupId );
				Dictionary<DateTime, int> DailyEngineQAResults = GetDailyCountsByGroup( MinimalCrashes, EngineQAUserGroupId );
				Dictionary<DateTime, int> DailyGameQAResults = GetDailyCountsByGroup( MinimalCrashes, GameQAUserGroupId );


				Dictionary<string, Dictionary<DateTime, int>> DailyEngineVersionResults = new Dictionary<string, Dictionary<DateTime, int>>();
				foreach(string UE4Version in EngineUE4Versions)
				{
					Dictionary<DateTime, int> Results = GetDailyCountsByVersion( MinimalCrashes, UE4Version, AnonymousID );
					DailyEngineVersionResults.Add( UE4Version, Results );
				}

				Dictionary<DateTime, int> DailyAllResults = GetDailyCountsByGroup( MinimalCrashes, AllUserGroupId );

				// Get daily buggs stats.
				List<Bugg> Buggs = _Buggs.ListAll().Where( Bugg => Bugg.TimeOfFirstCrash >= AfewMonthsAgo ).ToList();

				Dictionary<DateTime, int> BuggDailyAllResults  =
				(
					from Bugg in Buggs
					group Bugg by Bugg.TimeOfFirstCrash.Value.Date into GroupCount
					orderby GroupCount.Key
					select new { Count = GroupCount.Count(), Date = GroupCount.Key }
				).ToDictionary( x => x.Date, y => y.Count );
				

				string CrashesByWeek = "";

				foreach( KeyValuePair<DateTime, int> WeeklyResult in WeeklyAllResults )
				{
					int GeneralCrashes = 0;
					WeeklyGeneralResults.TryGetValue( WeeklyResult.Key, out GeneralCrashes );

					int CoderCrashes = 0;
					WeeklyCoderResults.TryGetValue( WeeklyResult.Key, out CoderCrashes );

					int EngineQACrashes = 0;
					WeeklyEngineQAResults.TryGetValue( WeeklyResult.Key, out EngineQACrashes );

					int GameQACrashes = 0;
					WeeklyGameQAResults.TryGetValue( WeeklyResult.Key, out GameQACrashes );

					string AnonymousLine = "";
					foreach (var VersionCrashes in WeeklyEngineVersionResults)
					{
						int EngineVersionCrashes = 0;
						VersionCrashes.Value.TryGetValue( WeeklyResult.Key, out EngineVersionCrashes );

						AnonymousLine += EngineVersionCrashes;
						AnonymousLine += ", ";
					}

					int Year = WeeklyResult.Key.Year;
					int Month = WeeklyResult.Key.AddMonths( -1 ).Month;
					if( WeeklyResult.Key.Month == 13 || WeeklyResult.Key.Month == 1 )
					{
						Month = 0;
					}

					int Day = WeeklyResult.Key.Day + 6;

					string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + GeneralCrashes + ", " + CoderCrashes + ", " + EngineQACrashes + ", " + GameQACrashes + ", " + AnonymousLine + WeeklyResult.Value + "], ";
					CrashesByWeek += Line;
				}

				CrashesByWeek = CrashesByWeek.TrimEnd( ", ".ToCharArray() );

				string CrashesByDay = "";
				foreach( KeyValuePair<DateTime, int> DailyResult in DailyAllResults )
				{
					int GeneralCrashes = 0;
					DailyGeneralResults.TryGetValue( DailyResult.Key, out GeneralCrashes );

					int CoderCrashes = 0;
					DailyCoderResults.TryGetValue( DailyResult.Key, out CoderCrashes );

					int EngineQACrashes = 0;
					DailyEngineQAResults.TryGetValue( DailyResult.Key, out EngineQACrashes );

					int GameQACrashes = 0;
					DailyGameQAResults.TryGetValue( DailyResult.Key, out GameQACrashes );

					string AnonymousLine = "";
					foreach (var VersionCrashes in DailyEngineVersionResults)
					{
						int EngineVersionCrashes = 0;
						VersionCrashes.Value.TryGetValue( DailyResult.Key, out EngineVersionCrashes );

						AnonymousLine += EngineVersionCrashes;
						AnonymousLine +=", ";
					}

					int Year = DailyResult.Key.Year;
					int Month = DailyResult.Key.AddMonths( -1 ).Month;
					if( DailyResult.Key.Month == 13 || DailyResult.Key.Month == 1 )
					{
						Month = 0;
					}

					int Day = DailyResult.Key.Day;

					string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + GeneralCrashes + ", " + CoderCrashes + ", " + EngineQACrashes + ", " + GameQACrashes + ", " + AnonymousLine + DailyResult.Value + "], ";
					CrashesByDay += Line;
				}

				CrashesByDay = CrashesByDay.TrimEnd( ", ".ToCharArray() );

				string BuggsByDay = "";
				foreach( KeyValuePair<DateTime, int> DailyResult in BuggDailyAllResults )
				{
					int Year = DailyResult.Key.Year;
					int Month = DailyResult.Key.AddMonths( -1 ).Month;
					if( DailyResult.Key.Month == 13 || DailyResult.Key.Month == 1 )
					{
						Month = 0;
					}

					int Day = DailyResult.Key.Day;

					string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + DailyResult.Value + "], ";
					BuggsByDay += Line;
				}

				BuggsByDay = BuggsByDay.TrimEnd( ", ".ToCharArray() );

				var ResultDashboard = new DashboardViewModel
				{
					CrashesByWeek = CrashesByWeek,
					CrashesByDay = CrashesByDay,
					BuggsByDay = BuggsByDay,
					EngineVersions = EngineUE4Versions,
				};
				ResultDashboard.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
				return View( "Index", ResultDashboard );
			}
		}
        /// <summary>
        /// The Show action.
        /// </summary>
        /// <param name="BuggsForm">The form of user data passed up from the client.</param>
        /// <param name="id">The unique id of the Bugg.</param>
        /// <returns>The view to display a Bugg on the client.</returns>
        public ActionResult Show( FormCollection BuggsForm, int id )
        {
            using( FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString() + "(BuggId=" + id + ")", bCreateNewLog: true ) )
            {
                // Handle 'CopyToJira' button
                int BuggIDToBeAddedToJira = 0;
                foreach( var Entry in BuggsForm )
                {
                    if( Entry.ToString().Contains( Bugg.JiraSubmitName ) )
                    {
                        int.TryParse( Entry.ToString().Substring( Bugg.JiraSubmitName.Length ), out BuggIDToBeAddedToJira );
                        break;
                    }
                }

                BuggRepository Buggs = new BuggRepository();

                // Set the display properties based on the radio buttons
                bool DisplayModuleNames = false;
                if( BuggsForm["DisplayModuleNames"] == "true" )
                {
                    DisplayModuleNames = true;
                }

                bool DisplayFunctionNames = false;
                if( BuggsForm["DisplayFunctionNames"] == "true" )
                {
                    DisplayFunctionNames = true;
                }

                bool DisplayFileNames = false;
                if( BuggsForm["DisplayFileNames"] == "true" )
                {
                    DisplayFileNames = true;
                }

                bool DisplayFilePathNames = false;
                if( BuggsForm["DisplayFilePathNames"] == "true" )
                {
                    DisplayFilePathNames = true;
                    DisplayFileNames = false;
                }

                bool DisplayUnformattedCallStack = false;
                if( BuggsForm["DisplayUnformattedCallStack"] == "true" )
                {
                    DisplayUnformattedCallStack = true;
                }

                // Create a new view and populate with crashes
                List<Crash> Crashes = null;

                BuggViewModel Model = new BuggViewModel();
                Bugg NewBugg = Buggs.GetBugg( id );
                if( NewBugg == null )
                {
                    return RedirectToAction( "" );
                }

                Crashes = NewBugg.GetCrashes();

                using (FAutoScopedLogTimer GetCrashesTimer = new FAutoScopedLogTimer( "Bugg.PrepareBuggForJira" ))
                {
                    if (Crashes.Count > 0)
                    {
                        NewBugg.PrepareBuggForJira( Crashes );

                        if (BuggIDToBeAddedToJira != 0)
                        {
                            NewBugg.CopyToJira();
                        }
                    }

                }

                using( FAutoScopedLogTimer JiraResultsTimer = new FAutoScopedLogTimer( "Bugg.GrabJira" ) )
                {
                    var JC = JiraConnection.Get();
                    bool bValidJira = false;

                    // Verify valid JiraID, this may be still a TTP
                    if( !string.IsNullOrEmpty( NewBugg.Jira ) )
                    {
                        int TTPID = 0;
                        int.TryParse( NewBugg.Jira, out TTPID );

                        if( TTPID == 0 )
                        {
                            //AddBuggJiraMapping( NewBugg, ref FoundJiras, ref JiraIDtoBugg );
                            bValidJira = true;
                        }
                    }

                    if( JC.CanBeUsed() && bValidJira )
                    {
                        // Grab the data form JIRA.
                        string JiraSearchQuery = "key = " + NewBugg.Jira;

                        var JiraResults = JC.SearchJiraTickets(
                            JiraSearchQuery,
                            new string[]
                            {
                                "key",				// string
                                "summary",			// string
                                "components",		// System.Collections.ArrayList, Dictionary<string,object>, name
                                "resolution",		// System.Collections.Generic.Dictionary`2[System.String,System.Object], name
                                "fixVersions",		// System.Collections.ArrayList, Dictionary<string,object>, name
                                "customfield_11200" // string
                            } );

                        // Jira Key, Summary, Components, Resolution, Fix version, Fix changelist
                        foreach( var Jira in JiraResults )
                        {
                            string JiraID = Jira.Key;

                            string Summary = (string)Jira.Value["summary"];

                            string ComponentsText = "";
                            System.Collections.ArrayList Components = (System.Collections.ArrayList)Jira.Value["components"];
                            foreach( Dictionary<string, object> Component in Components )
                            {
                                ComponentsText += (string)Component["name"];
                                ComponentsText += " ";
                            }

                            Dictionary<string, object> ResolutionFields = (Dictionary<string, object>)Jira.Value["resolution"];
                            string Resolution = ResolutionFields != null ? (string)ResolutionFields["name"] : "";

                            string FixVersionsText = "";
                            System.Collections.ArrayList FixVersions = (System.Collections.ArrayList)Jira.Value["fixVersions"];
                            foreach( Dictionary<string, object> FixVersion in FixVersions )
                            {
                                FixVersionsText += (string)FixVersion["name"];
                                FixVersionsText += " ";
                            }

                            int FixCL = Jira.Value["customfield_11200"] != null ? (int)(decimal)Jira.Value["customfield_11200"] : 0;

                            NewBugg.JiraSummary = Summary;
                            NewBugg.JiraComponentsText = ComponentsText;
                            NewBugg.JiraResolution = Resolution;
                            NewBugg.JiraFixVersionsText = FixVersionsText;
                            if( FixCL != 0 )
                            {
                                NewBugg.JiraFixCL = FixCL.ToString();
                            }

                            break;
                        }
                    }
                }

                // Apply any user settings
                if( BuggsForm.Count > 0 )
                {
                    if( !string.IsNullOrEmpty( BuggsForm["SetStatus"] ) )
                    {
                        NewBugg.Status = BuggsForm["SetStatus"];
                        Buggs.SetBuggStatus( NewBugg.Status, id );
                    }

                    if( !string.IsNullOrEmpty( BuggsForm["SetFixedIn"] ) )
                    {
                        NewBugg.FixedChangeList = BuggsForm["SetFixedIn"];
                        Buggs.SetBuggFixedChangeList( NewBugg.FixedChangeList, id );
                    }

                    if( !string.IsNullOrEmpty( BuggsForm["SetTTP"] ) )
                    {
                        NewBugg.Jira = BuggsForm["SetTTP"];
                        Buggs.SetJIRAForBuggAndCrashes( NewBugg.Jira, id );
                    }

                    // <STATUS>
                }

                // Set up the view model with the crash data
                Model.Bugg = NewBugg;
                Model.Crashes = Crashes;

                Crash NewCrash = Model.Crashes.FirstOrDefault();
                if( NewCrash != null )
                {
                    using( FScopedLogTimer LogTimer2 = new FScopedLogTimer( "CallstackTrimming" ) )
                    {
                        CallStackContainer CallStack = new CallStackContainer( NewCrash );

                        // Set callstack properties
                        CallStack.bDisplayModuleNames = DisplayModuleNames;
                        CallStack.bDisplayFunctionNames = DisplayFunctionNames;
                        CallStack.bDisplayFileNames = DisplayFileNames;
                        CallStack.bDisplayFilePathNames = DisplayFilePathNames;
                        CallStack.bDisplayUnformattedCallStack = DisplayUnformattedCallStack;

                        Model.CallStack = CallStack;

                        // Shorten very long function names.
                        foreach( CallStackEntry Entry in Model.CallStack.CallStackEntries )
                        {
                            Entry.FunctionName = Entry.GetTrimmedFunctionName( 128 );
                        }

                        Model.SourceContext = NewCrash.SourceContext;
                    }

                    Model.Bugg.LatestCrashSummary = NewCrash.Summary;
                }

                Model.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
                return View( "Show", Model );
            }
        }
        /// <summary>
        /// Show detailed information about a crash.
        /// </summary>
        /// <param name="CrashesForm">A form of user data passed up from the client.</param>
        /// <param name="id">The unique id of the crash we wish to show the details of.</param>
        /// <returns>A view to show crash details.</returns>
        public ActionResult Show( FormCollection CrashesForm, int id )
        {
            using( FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString() + "(CrashId=" + id + ")", bCreateNewLog: true ) )
            {
                CrashRepository Crashes = new CrashRepository();

                CallStackContainer CurrentCallStack = null;

                // Update the selected crash based on the form contents
                Crash CurrentCrash = Crashes.GetCrash( id );

                if( CurrentCrash == null )
                {
                    return RedirectToAction( "" );
                }

                string FormValue;

                FormValue = CrashesForm["SetStatus"];
                if( !string.IsNullOrEmpty( FormValue ) )
                {
                    CurrentCrash.Status = FormValue;
                }

                FormValue = CrashesForm["SetFixedIn"];
                if( !string.IsNullOrEmpty( FormValue ) )
                {
                    CurrentCrash.FixedChangeList = FormValue;
                }

                FormValue = CrashesForm["SetTTP"];
                if( !string.IsNullOrEmpty( FormValue ) )
                {
                    CurrentCrash.Jira = FormValue;
                }

                // Valid to set description to an empty string
                FormValue = CrashesForm["Description"];
                if( FormValue != null )
                {
                    CurrentCrash.Description = FormValue;
                }

                CurrentCallStack = new CallStackContainer( CurrentCrash );

                // Set callstack properties
                CurrentCallStack.bDisplayModuleNames = true;
                CurrentCallStack.bDisplayFunctionNames = true;
                CurrentCallStack.bDisplayFileNames = true;
                CurrentCallStack.bDisplayFilePathNames = true;
                CurrentCallStack.bDisplayUnformattedCallStack = false;

                CurrentCrash.CallStackContainer = CurrentCrash.GetCallStack();

                // Populate the crash with the correct user data
                Crashes.PopulateUserInfo( CurrentCrash );
                Crashes.SubmitChanges();

                var Model = new CrashViewModel { Crash = CurrentCrash, CallStack = CurrentCallStack };
                Model.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
                return View( "Show", Model );
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="Form"></param>
        /// <returns></returns>
	    public ActionResult GenerateCSV(FormCollection Form)
        {
            using (var logTimer = new FAutoScopedLogTimer(this.GetType().ToString(), bCreateNewLog: true))
            {
                var formData = new FormHelper(Request, Form, "JustReport");
                var results = GetResults(formData);
                results.GenerationTime = logTimer.GetElapsedSeconds().ToString("F2");
                return View("CSV", results);
            }
        }
Exemple #16
0
        /// <summary>
        /// The main view of the dash board.
        /// </summary>
        /// <returns>A view showing two charts of crashes over time.</returns>
        public ActionResult Index()
        {
            using( FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ) )
            {
                DateTime Today = DateTime.UtcNow;
                DateTime AfewMonthsAgo = Today.AddMonths( -6 );

                FAutoScopedLogTimer LogTimerSQL = new FAutoScopedLogTimer( "CrashesFilterByDate", "", "" );

                IQueryable<Crash> CrashesInTimeFrame = _Crashes.ListAll()
                    .Where( MyCrash => MyCrash.TimeOfCrash >= AfewMonthsAgo && MyCrash.TimeOfCrash <= Today.AddDays( 1 ) );
                //IEnumerable<Crash> Crashes = FRepository.Get().Crashes.FilterByDate( FRepository.Get().Crashes.ListAll(), AfewMonthsAgo, Today );
                var VMinimalCrashes = CrashesInTimeFrame.Select( Crash => new { TimeOfCrash = Crash.TimeOfCrash.Value, UserID = Crash.UserNameId.Value } ).ToList();

                List<FCrashMinimal> MinimalCrashes = new List<FCrashMinimal>( VMinimalCrashes.Count );
                foreach( var Anotype in VMinimalCrashes )
                {
                    MinimalCrashes.Add( new FCrashMinimal( Anotype.TimeOfCrash, Anotype.UserID ) );
                }
                LogTimerSQL.Dispose();

                int GeneralUserGroupId = FRepository.Get( _Crashes ).FindOrAddGroup( "General" );
                int CoderUserGroupId = FRepository.Get( _Crashes ).FindOrAddGroup( "Coder" );
                int EngineQAUserGroupId = FRepository.Get( _Crashes ).FindOrAddGroup( "EngineQA" );
                int GameQAUserGroupId = FRepository.Get( _Crashes ).FindOrAddGroup( "GameQA" );
                int AnonymousUserGroupId = FRepository.Get( _Crashes ).FindOrAddGroup( "Anonymous" );

                Dictionary<DateTime, int> GeneralResults = GetWeeklyCountsByGroup( MinimalCrashes, GeneralUserGroupId );
                Dictionary<DateTime, int> CoderResults = GetWeeklyCountsByGroup( MinimalCrashes, CoderUserGroupId );
                Dictionary<DateTime, int> EngineQAResults = GetWeeklyCountsByGroup( MinimalCrashes, EngineQAUserGroupId );
                Dictionary<DateTime, int> GameQAResults = GetWeeklyCountsByGroup( MinimalCrashes, GameQAUserGroupId );
                Dictionary<DateTime, int> AnonymousResults = GetWeeklyCountsByGroup( MinimalCrashes, AnonymousUserGroupId );
                Dictionary<DateTime, int> AllResults = GetWeeklyCountsByGroup( MinimalCrashes, AllUserGroupId );

                Dictionary<DateTime, int> DailyGeneralResults = GetDailyCountsByGroup( MinimalCrashes, GeneralUserGroupId );
                Dictionary<DateTime, int> DailyCoderResults = GetDailyCountsByGroup( MinimalCrashes, CoderUserGroupId );
                Dictionary<DateTime, int> DailyEngineQAResults = GetDailyCountsByGroup( MinimalCrashes, EngineQAUserGroupId );
                Dictionary<DateTime, int> DailyGameQAResults = GetDailyCountsByGroup( MinimalCrashes, GameQAUserGroupId );
                Dictionary<DateTime, int> DailyAnonymousResults = GetDailyCountsByGroup( MinimalCrashes, AnonymousUserGroupId );
                Dictionary<DateTime, int> DailyAllResults = GetDailyCountsByGroup( MinimalCrashes, AllUserGroupId );

                // Get daily buggs stats.
                List<Bugg> Buggs = _Buggs.ListAll().Where( Bugg => Bugg.TimeOfFirstCrash >= AfewMonthsAgo ).ToList();

                Dictionary<DateTime, int> BuggDailyAllResults  =
                (
                    from Bugg in Buggs
                    group Bugg by Bugg.TimeOfFirstCrash.Value.Date into GroupCount
                    orderby GroupCount.Key
                    select new { Count = GroupCount.Count(), Date = GroupCount.Key }
                ).ToDictionary( x => x.Date, y => y.Count );

                string CrashesByWeek = "";

                foreach( KeyValuePair<DateTime, int> Result in AllResults )
                {
                    int GeneralCrashes = 0;
                    GeneralResults.TryGetValue( Result.Key, out GeneralCrashes );

                    int CoderCrashes = 0;
                    CoderResults.TryGetValue( Result.Key, out CoderCrashes );

                    int EngineQACrashes = 0;
                    EngineQAResults.TryGetValue( Result.Key, out EngineQACrashes );

                    int GameQACrashes = 0;
                    GameQAResults.TryGetValue( Result.Key, out GameQACrashes );

                    int AnonymousCrashes = 0;
                    AnonymousResults.TryGetValue( Result.Key, out AnonymousCrashes );

                    int Year = Result.Key.Year;
                    int Month = Result.Key.AddMonths( -1 ).Month;
                    if( Result.Key.Month == 13 || Result.Key.Month == 1 )
                    {
                        Month = 0;
                    }

                    int Day = Result.Key.Day + 6;

                    string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + GeneralCrashes + ", " + CoderCrashes + ", " + EngineQACrashes + ", " + GameQACrashes + ", " + AnonymousCrashes + ", " + Result.Value + "], ";
                    CrashesByWeek += Line;
                }

                CrashesByWeek = CrashesByWeek.TrimEnd( ", ".ToCharArray() );

                string CrashesByDay = "";
                foreach( KeyValuePair<DateTime, int> DailyResult in DailyAllResults )
                {
                    int GeneralCrashes = 0;
                    DailyGeneralResults.TryGetValue( DailyResult.Key, out GeneralCrashes );

                    int CoderCrashes = 0;
                    DailyCoderResults.TryGetValue( DailyResult.Key, out CoderCrashes );

                    int EngineQACrashes = 0;
                    DailyEngineQAResults.TryGetValue( DailyResult.Key, out EngineQACrashes );

                    int GameQACrashes = 0;
                    DailyGameQAResults.TryGetValue( DailyResult.Key, out GameQACrashes );

                    int AnonymousCrashes = 0;
                    DailyAnonymousResults.TryGetValue( DailyResult.Key, out AnonymousCrashes );

                    int Year = DailyResult.Key.Year;
                    int Month = DailyResult.Key.AddMonths( -1 ).Month;
                    if( DailyResult.Key.Month == 13 || DailyResult.Key.Month == 1 )
                    {
                        Month = 0;
                    }

                    int Day = DailyResult.Key.Day;

                    string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + GeneralCrashes + ", " + CoderCrashes + ", " + EngineQACrashes + ", " + GameQACrashes + ", " + AnonymousCrashes + ", " + DailyResult.Value + "], ";
                    CrashesByDay += Line;
                }

                CrashesByDay = CrashesByDay.TrimEnd( ", ".ToCharArray() );

                string BuggsByDay = "";
                foreach( KeyValuePair<DateTime, int> DailyResult in BuggDailyAllResults )
                {
                    int Year = DailyResult.Key.Year;
                    int Month = DailyResult.Key.AddMonths( -1 ).Month;
                    if( DailyResult.Key.Month == 13 || DailyResult.Key.Month == 1 )
                    {
                        Month = 0;
                    }

                    int Day = DailyResult.Key.Day;

                    string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + DailyResult.Value + "], ";
                    BuggsByDay += Line;
                }

                BuggsByDay = BuggsByDay.TrimEnd( ", ".ToCharArray() );

                var ResultDashboard = new DashboardViewModel { CrashesByWeek = CrashesByWeek, CrashesByDay = CrashesByDay, BuggsByDay = BuggsByDay };
                ResultDashboard.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
                return View( "Index", ResultDashboard );
            }
        }
Exemple #17
0
        /// <summary>
        /// The main view of the dash board.
        /// </summary>
        /// <returns>A view showing two charts of crashes over time.</returns>
        public ActionResult Index()
        {
            using (FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer(this.GetType().ToString(), bCreateNewLog: true))
            {
                DateTime Today         = DateTime.UtcNow;
                DateTime AfewMonthsAgo = Today.AddMonths(-6);

                FAutoScopedLogTimer LogTimerSQL = new FAutoScopedLogTimer("CrashesFilterByDate", "", "");

                IQueryable <Crash> CrashesInTimeFrame = _Crashes.ListAll()
                                                        .Where(MyCrash => MyCrash.TimeOfCrash >= AfewMonthsAgo && MyCrash.TimeOfCrash <= Today.AddDays(1));
                //IEnumerable<Crash> Crashes = FRepository.Get().Crashes.FilterByDate( FRepository.Get().Crashes.ListAll(), AfewMonthsAgo, Today );
                var VMinimalCrashes = CrashesInTimeFrame.Select(Crash => new { TimeOfCrash = Crash.TimeOfCrash.Value, UserID = Crash.UserNameId.Value }).ToList();

                List <FCrashMinimal> MinimalCrashes = new List <FCrashMinimal>(VMinimalCrashes.Count);
                foreach (var Anotype in VMinimalCrashes)
                {
                    MinimalCrashes.Add(new FCrashMinimal(Anotype.TimeOfCrash, Anotype.UserID));
                }
                LogTimerSQL.Dispose();

                int GeneralUserGroupId   = FRepository.Get(_Crashes).FindOrAddGroup("General");
                int CoderUserGroupId     = FRepository.Get(_Crashes).FindOrAddGroup("Coder");
                int EngineQAUserGroupId  = FRepository.Get(_Crashes).FindOrAddGroup("EngineQA");
                int GameQAUserGroupId    = FRepository.Get(_Crashes).FindOrAddGroup("GameQA");
                int AnonymousUserGroupId = FRepository.Get(_Crashes).FindOrAddGroup("Anonymous");

                Dictionary <DateTime, int> GeneralResults   = GetWeeklyCountsByGroup(MinimalCrashes, GeneralUserGroupId);
                Dictionary <DateTime, int> CoderResults     = GetWeeklyCountsByGroup(MinimalCrashes, CoderUserGroupId);
                Dictionary <DateTime, int> EngineQAResults  = GetWeeklyCountsByGroup(MinimalCrashes, EngineQAUserGroupId);
                Dictionary <DateTime, int> GameQAResults    = GetWeeklyCountsByGroup(MinimalCrashes, GameQAUserGroupId);
                Dictionary <DateTime, int> AnonymousResults = GetWeeklyCountsByGroup(MinimalCrashes, AnonymousUserGroupId);
                Dictionary <DateTime, int> AllResults       = GetWeeklyCountsByGroup(MinimalCrashes, AllUserGroupId);

                Dictionary <DateTime, int> DailyGeneralResults   = GetDailyCountsByGroup(MinimalCrashes, GeneralUserGroupId);
                Dictionary <DateTime, int> DailyCoderResults     = GetDailyCountsByGroup(MinimalCrashes, CoderUserGroupId);
                Dictionary <DateTime, int> DailyEngineQAResults  = GetDailyCountsByGroup(MinimalCrashes, EngineQAUserGroupId);
                Dictionary <DateTime, int> DailyGameQAResults    = GetDailyCountsByGroup(MinimalCrashes, GameQAUserGroupId);
                Dictionary <DateTime, int> DailyAnonymousResults = GetDailyCountsByGroup(MinimalCrashes, AnonymousUserGroupId);
                Dictionary <DateTime, int> DailyAllResults       = GetDailyCountsByGroup(MinimalCrashes, AllUserGroupId);

                // Get daily buggs stats.
                List <Bugg> Buggs = _Buggs.ListAll().Where(Bugg => Bugg.TimeOfFirstCrash >= AfewMonthsAgo).ToList();

                Dictionary <DateTime, int> BuggDailyAllResults =
                    (
                        from Bugg in Buggs
                        group Bugg by Bugg.TimeOfFirstCrash.Value.Date into GroupCount
                        orderby GroupCount.Key
                        select new { Count = GroupCount.Count(), Date = GroupCount.Key }
                    ).ToDictionary(x => x.Date, y => y.Count);


                string CrashesByWeek = "";

                foreach (KeyValuePair <DateTime, int> Result in AllResults)
                {
                    int GeneralCrashes = 0;
                    GeneralResults.TryGetValue(Result.Key, out GeneralCrashes);

                    int CoderCrashes = 0;
                    CoderResults.TryGetValue(Result.Key, out CoderCrashes);

                    int EngineQACrashes = 0;
                    EngineQAResults.TryGetValue(Result.Key, out EngineQACrashes);

                    int GameQACrashes = 0;
                    GameQAResults.TryGetValue(Result.Key, out GameQACrashes);

                    int AnonymousCrashes = 0;
                    AnonymousResults.TryGetValue(Result.Key, out AnonymousCrashes);

                    int Year  = Result.Key.Year;
                    int Month = Result.Key.AddMonths(-1).Month;
                    if (Result.Key.Month == 13 || Result.Key.Month == 1)
                    {
                        Month = 0;
                    }

                    int Day = Result.Key.Day + 6;

                    string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + GeneralCrashes + ", " + CoderCrashes + ", " + EngineQACrashes + ", " + GameQACrashes + ", " + AnonymousCrashes + ", " + Result.Value + "], ";
                    CrashesByWeek += Line;
                }

                CrashesByWeek = CrashesByWeek.TrimEnd(", ".ToCharArray());

                string CrashesByDay = "";
                foreach (KeyValuePair <DateTime, int> DailyResult in DailyAllResults)
                {
                    int GeneralCrashes = 0;
                    DailyGeneralResults.TryGetValue(DailyResult.Key, out GeneralCrashes);

                    int CoderCrashes = 0;
                    DailyCoderResults.TryGetValue(DailyResult.Key, out CoderCrashes);

                    int EngineQACrashes = 0;
                    DailyEngineQAResults.TryGetValue(DailyResult.Key, out EngineQACrashes);

                    int GameQACrashes = 0;
                    DailyGameQAResults.TryGetValue(DailyResult.Key, out GameQACrashes);

                    int AnonymousCrashes = 0;
                    DailyAnonymousResults.TryGetValue(DailyResult.Key, out AnonymousCrashes);

                    int Year  = DailyResult.Key.Year;
                    int Month = DailyResult.Key.AddMonths(-1).Month;
                    if (DailyResult.Key.Month == 13 || DailyResult.Key.Month == 1)
                    {
                        Month = 0;
                    }

                    int Day = DailyResult.Key.Day;

                    string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + GeneralCrashes + ", " + CoderCrashes + ", " + EngineQACrashes + ", " + GameQACrashes + ", " + AnonymousCrashes + ", " + DailyResult.Value + "], ";
                    CrashesByDay += Line;
                }

                CrashesByDay = CrashesByDay.TrimEnd(", ".ToCharArray());

                string BuggsByDay = "";
                foreach (KeyValuePair <DateTime, int> DailyResult in BuggDailyAllResults)
                {
                    int Year  = DailyResult.Key.Year;
                    int Month = DailyResult.Key.AddMonths(-1).Month;
                    if (DailyResult.Key.Month == 13 || DailyResult.Key.Month == 1)
                    {
                        Month = 0;
                    }

                    int Day = DailyResult.Key.Day;

                    string Line = "[new Date(" + Year + ", " + Month + ", " + Day + "), " + DailyResult.Value + "], ";
                    BuggsByDay += Line;
                }

                BuggsByDay = BuggsByDay.TrimEnd(", ".ToCharArray());

                var ResultDashboard = new DashboardViewModel {
                    CrashesByWeek = CrashesByWeek, CrashesByDay = CrashesByDay, BuggsByDay = BuggsByDay
                };
                ResultDashboard.GenerationTime = LogTimer.GetElapsedSeconds().ToString("F2");
                return(View("Index", ResultDashboard));
            }
        }
		/// <summary>
		/// Display a summary list of crashes based on the search criteria.
		/// </summary>
		/// <param name="crashesForm">A form of user data passed up from the client.</param>
		/// <returns>A view to display a list of crash reports.</returns>
		public ActionResult Index( FormCollection crashesForm )
		{
            using( var logTimer = new FAutoScopedLogTimer( this.GetType().ToString(), bCreateNewLog: true ) )
			{
				// Handle any edits made in the Set form fields
				foreach( var Entry in crashesForm )
				{
					int Id = 0;
					if( int.TryParse( Entry.ToString(), out Id ) )
					{
                        Crash currentCrash = _unitOfWork.CrashRepository.GetById(Id);
						if( currentCrash != null )
						{
							if( !string.IsNullOrEmpty( crashesForm["SetStatus"] ) )
							{
								currentCrash.Status = crashesForm["SetStatus"];
							}

							if( !string.IsNullOrEmpty( crashesForm["SetFixedIn"] ) )
							{
								currentCrash.FixedChangeList = crashesForm["SetFixedIn"];
							}

							if( !string.IsNullOrEmpty( crashesForm["SetTTP"] ) )
							{
								currentCrash.Jira = crashesForm["SetTTP"];
							}
						}
					}

				    _unitOfWork.Save();
				}

				// <STATUS>

				// Parse the contents of the query string, and populate the form
				var formData = new FormHelper( Request, crashesForm, "TimeOfCrash" );
				var result = GetResults( formData );
                result.BranchNames = _unitOfWork.CrashRepository.GetBranchesAsListItems();
                result.VersionNames = _unitOfWork.CrashRepository.GetVersionsAsListItems();
                result.PlatformNames = _unitOfWork.CrashRepository.GetPlatformsAsListItems();
                result.EngineModes = _unitOfWork.CrashRepository.GetEngineModesAsListItems();
                result.EngineVersions = _unitOfWork.CrashRepository.GetEngineVersionsAsListItems();

				// Add the FromCollection to the CrashesViewModel since we don't need it for the get results function but we do want to post it back to the page.
				result.FormCollection = crashesForm;
				result.GenerationTime = logTimer.GetElapsedSeconds().ToString( "F2" );
				return View( "Index", result );
			}
		}
		/// <summary>
		/// 
		/// </summary>
		/// <param name="ReportsForm"></param>
		/// <returns></returns>
		public ActionResult Index( FormCollection ReportsForm )
		{
			using( FAutoScopedLogTimer LogTimer = new FAutoScopedLogTimer( this.GetType().ToString() ) )
			{
				FormHelper FormData = new FormHelper( Request, ReportsForm, "JustReport" );

				// Handle 'CopyToJira' button
				int BuggIDToBeAddedToJira = 0;
				foreach( var Entry in ReportsForm )
				{
					
					if( int.TryParse( Entry.ToString(), out BuggIDToBeAddedToJira ) )
					{
						break;
					}
				}

				ReportsViewModel Results = GetResults( FormData, BuggIDToBeAddedToJira );
				Results.GenerationTime = LogTimer.GetElapsedSeconds().ToString( "F2" );
				return View( "Index", Results );
			}
		}