void OnEnable()
        {
            if (m_RawDataClient == null)
            {
                Texture2D failedIcon   = Resources.Load("unity_analytics_heatmaps_failed") as Texture2D;
                Texture2D completeIcon = Resources.Load("unity_analytics_heatmaps_success") as Texture2D;
                Texture2D runningIcon  = Resources.Load("unity_analytics_heatmaps_running") as Texture2D;

                m_RawDataClient = RawDataClient.GetInstance();
                if (m_DataSource == FETCH && !m_ValidManifest)
                {
                    m_RawDataClient.GetJobs(GetJobsCompletionHandler);
                    m_ValidManifest = true;
                }
                titleContent = new GUIContent("Raw Data");

                m_FailedContent   = new GUIContent(failedIcon, "Status: Failed");
                m_CompleteContent = new GUIContent(completeIcon, "Status: Completed");
                m_RunningContent  = new GUIContent(runningIcon, "Status: Running");
                return;
            }
        }
        void OnGUIFetchView()
        {
            if (Event.current.type == EventType.Layout)
            {
                m_RawDataClient.TestFilesAreLocal(m_Jobs);
            }

            using (new GUILayout.VerticalScope("box"))
            {
                string oldKey = m_SecretKey;
                m_AppId = EditorGUILayout.TextField(m_UpidContent, m_AppId);
                RestoreAppId();
                m_SecretKey = EditorGUILayout.TextField(m_SecretKeyContent, m_SecretKey);

                m_RawDataClient.m_DataPath  = m_DataPath;
                m_RawDataClient.m_AppId     = m_AppId;
                m_RawDataClient.m_SecretKey = m_SecretKey;

                if (oldKey != m_SecretKey && !string.IsNullOrEmpty(m_SecretKey))
                {
                    EditorPrefs.SetString(k_FetchKey, m_SecretKey);
                }
            }

            using (new GUILayout.VerticalScope("box"))
            {
                GUILayout.Label("New Job", EditorStyles.boldLabel);

                var oldStartDate = m_StartDate;
                var oldEndDate   = m_EndDate;
                m_StartDate = EditorGUILayout.TextField(m_StartDateContent, m_StartDate);
                m_EndDate   = EditorGUILayout.TextField(m_EndDateContent, m_EndDate);
                if (oldStartDate != m_StartDate || oldEndDate != m_EndDate)
                {
                    EditorPrefs.SetString(k_StartDate, m_StartDate);
                    EditorPrefs.SetString(k_EndDate, m_EndDate);
                }
                if (GUILayout.Button("Create Job"))
                {
                    RawDataReport report = null;
                    try
                    {
                        DateTime startDate = DateTime.Parse(m_StartDate).ToUniversalTime();
                        DateTime endDate   = DateTime.Parse(m_EndDate).ToUniversalTime();
                        report = m_RawDataClient.CreateJob("custom", startDate, endDate);
                    }
                    catch (Exception ex)
                    {
                        string exText = "Unknown exception.";
                        if (ex is FormatException)
                        {
                            exText = "Date formats appear to be incorrect. Start and End Dates must be ISO-8601 format (YYYY-MM-DD).";
                        }
                        else if (ex is WebException)
                        {
                            WebException webEx = ex as WebException;
                            exText = webEx.Message;
                        }
                        EditorUtility.DisplayDialog("Can't create job", exText, "OK");
                    }
                    if (m_Jobs == null)
                    {
                        m_Jobs = new List <RawDataReport>();
                    }
                    if (report != null)
                    {
                        m_Jobs.Add(report);
                    }
                    m_JobFoldouts = m_Jobs.Select(fb => false).ToArray();
                }
            }

            using (new GUILayout.VerticalScope("box"))
            {
                using (new EditorGUILayout.HorizontalScope())
                {
                    if (GUILayout.Button(m_GetJobsContent))
                    {
                        m_RawDataClient.GetJobs(GetJobsCompletionHandler);
                    }
                    if (GUILayout.Button(m_DownloadAllContent))
                    {
                        m_RawDataClient.DownloadAll(m_Jobs);
                    }
                }
                m_ScrollPosition = EditorGUILayout.BeginScrollView(m_ScrollPosition);
                if (m_Jobs != null)
                {
                    for (int a = m_Jobs.Count - 1; a > -1; a--)
                    {
                        var    job        = m_Jobs[a];
                        string start      = String.Format("{0:yyyy-MM-dd}", job.request.startDate);
                        string end        = String.Format("{0:yyyy-MM-dd}", job.request.endDate);
                        string shortStart = String.Format("{0:MM-dd}", job.request.startDate);
                        string shortEnd   = String.Format("{0:MM-dd}", job.request.endDate);
                        string created    = String.Format("{0:yyyy-MM-dd hh:mm:ss}", job.createdAt);
                        string type       = job.request.dataset;

                        using (new EditorGUILayout.HorizontalScope())
                        {
                            float windowWidth         = EditorGUIUtility.currentViewWidth;
                            float foldoutWidth        = windowWidth * .5f;
                            float downloadButtonWidth = 75f;
                            float continueButtonWidth = 25f;
                            float downloadedWidth     = downloadButtonWidth;
                            float statusWidth         = 20f;

                            GUIContent foldoutContent = new GUIContent(type + ": " + shortStart + " to " + shortEnd, start + " — " + end + "\n" + job.id);
                            Rect       pos            = GUILayoutUtility.GetRect(foldoutContent, "foldout");
                            Rect       rect           = new Rect(pos.x, pos.y, foldoutWidth, 20f);
                            m_JobFoldouts[a] = EditorGUI.Foldout(
                                rect,
                                m_JobFoldouts[a],
                                foldoutContent,
                                true
                                );

                            var statusContent = m_CompleteContent;
                            switch (job.status)
                            {
                            case RawDataReport.Failed:
                                statusContent = m_FailedContent;
                                break;

                            case RawDataReport.Running:
                                statusContent = m_RunningContent;
                                break;
                            }
                            GUILayout.Label(statusContent, GUILayout.Width(statusWidth));

                            if (job.status == RawDataReport.Completed)
                            {
                                if (job.isLocal)
                                {
                                    GUILayout.Label("Downloaded", GUILayout.Width(downloadedWidth));
                                }
                                else if (job.result != null && job.result.size == 0)
                                {
                                    GUILayout.Label("No Data", GUILayout.Width(downloadedWidth));
                                }
                                else if (GUILayout.Button(m_DownloadJobContent, GUILayout.Width(downloadButtonWidth)))
                                {
                                    m_RawDataClient.Download(job);
                                }
                                if (GUILayout.Button(m_ContinueJobContent, GUILayout.Width(continueButtonWidth)))
                                {
                                    RawDataReport report = m_RawDataClient.ContinueFromJob(job);
                                    m_Jobs.Add(report);
                                    m_JobFoldouts = m_Jobs.Select(fb => false).ToArray();
                                }
                            }
                        }
                        if (m_JobFoldouts[a])
                        {
                            Color defaultColor = GUI.color;
                            GUI.backgroundColor = s_BoxColor;
                            using (new GUILayout.VerticalScope("box"))
                            {
                                GUILayout.Label("ID: " + job.id);
                                GUILayout.Label("Created: " + created);
                                GUILayout.Label("Duration: " + (job.duration / 1000) + " seconds");
                                if (job.result != null)
                                {
                                    GUILayout.Label("# Events: " + job.result.eventCount);
                                    GUILayout.Label("# Bytes: " + job.result.size);
                                    GUILayout.Label("# Files: " + job.result.fileList.Count);
                                    GUILayout.Label("Partial day: " + job.result.intraDay);
                                }
                            }
                            GUI.backgroundColor = defaultColor;
                        }
                    }

                    if (m_Jobs.Count == 0)
                    {
                        GUILayout.Label("No jobs found", EditorStyles.boldLabel);
                    }
                }
                else
                {
                    GUILayout.Label("No data yet", EditorStyles.boldLabel);
                }
                GUILayout.Space(10f);
                EditorGUILayout.EndScrollView();
            }



            using (new GUILayout.HorizontalScope())
            {
                if (GUILayout.Button("Purge"))
                {
                    PurgeData();
                }
                if (GUILayout.Button("Dashboard"))
                {
                    Application.OpenURL(m_RawDataClient.DashboardPath);
                }
                if (GUILayout.Button("Project Config"))
                {
                    Application.OpenURL(m_RawDataClient.ConfigPath);
                }
            }
        }