async public void initCSV()
 {
     await Task.Run(async() => {
         Ranker rank           = new Ranker(Preferences.Get("matchEventsString", ""));
         csvString             = "Team,Match Num,Side,Avg. Hatch,Num Hatch,Avg. Cargo,Num Cargo,Climb,Lvl1,Lvl2,Lvl3,Cargoship\n";
         JArray matches        = rank.getDataAsJArray();
         CSVRanker singleMatch = new CSVRanker();
         foreach (JObject match in matches)
         {
             csvString += singleMatch.matchCalc(match) + "\n";
         }
         string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
         File.WriteAllText(path + "/" + excelFileBase + ".csv", csvString);
     });
 }
        private async Task PitText()
        {
            await Task.Run(async() => {
                Ranker rank = new Ranker(Preferences.Get("matchEventsString", ""));
                csvString   = "Team";
                foreach (String s in ConstantVars.QUESTIONS)
                {
                    csvString += "," + s;
                }
                csvString += "\n";
                JObject tempJSON;
                JArray pits;
                if (!String.IsNullOrWhiteSpace(Preferences.Get("matchEventsString", "")))
                {
                    try {
                        tempJSON = JObject.Parse(Preferences.Get("matchEventsString", ""));
                    } catch (NullReferenceException) {
                        System.Diagnostics.Debug.WriteLine("Caught NullRepEx for ranker JObject");
                        tempJSON = new JObject();
                    }
                }
                else
                {
                    tempJSON = new JObject(new JProperty("PitNotes"));
                }
                if (tempJSON.ContainsKey("PitNotes"))
                {
                    pits = (JArray)tempJSON["PitNotes"];
                }
                else
                {
                    pits = new JArray();
                }
                for (int i = 0; i < pits.Count; i++)
                {
                    csvString += pits[i]["team"];
                    for (int j = 0; j < ConstantVars.QUESTIONS.Length; j++)
                    {
                        try {
                            String ss  = (pits[i]["q" + j]).ToString().Replace("\n", "");
                            csvString += "," + ss;
                        } catch {
                            csvString += ",";
                        }
                    }
                    csvString += "\n";
                }
                string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                File.WriteAllText(path + "/" + pitFileBase + ".csv", csvString);
            });

            switch (Device.RuntimePlatform)
            {
            case Device.iOS:
                string path = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
                await Share.RequestAsync(new ShareTextRequest
                {
                    Uri   = "file://" + path + "/" + pitFileBase + ".csv",
                    Title = "Share Pit"
                });

                break;

            default:
                //var response = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Storage);
                //String fileDir = Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).ToString(), excelFileBase + ".csv");
                //File.WriteAllText(fileDir, "");
                //File.WriteAllText(fileDir, csvString);
                break;
            }
        }