public static void AddQPDatasetInfo(QProDatasetInfo qpdi)
 {
     if (RemoveQPDatasetInfo(qpdi.DatasetName))           //remove the key if it exists
     {
         QproDatasetInfoList.Add(qpdi.DatasetName, qpdi); //add the key. This is always a non existing key
     }
     //as we have deleted the exising one in the above line.
 }
        public Task GetRequest(string URL, QProDatasetInfo qpdsi)
        {
            HttpClient client = null;
            string     errmg  = string.Empty;

            //QProDatasetInfo qpdsi = null;
            try
            {
                //URL = "https://hivelabs.questionpro.com/a/ds/?t=5mnaDTMyMncTl24qn3Q%2BGgH8%2BI4tMoEcFUCnqiDY4NNwOIPEVWyCBq4xpKZdHA55";
                client = new HttpClient();
                //client.BaseAddress = new Uri(URL);
                HttpResponseMessage response = client.GetAsync(URL).Result;
                //string response2 =  client.GetStringAsync(apikeyparam).Result;

                if (response.IsSuccessStatusCode)
                {
                    //qpdsi = new QProDatasetInfo();
                    qpdsi.Filename  = response.Content.Headers.ContentDisposition.FileName;;
                    qpdsi.ApiKey    = response.Headers.GetValues("apikey").FirstOrDefault();;
                    qpdsi.DatasetId = response.Headers.GetValues("datasetid").FirstOrDefault();;
                    qpdsi.SurveyId  = response.Headers.GetValues("surveyid").FirstOrDefault();;
                    qpdsi.UserId    = response.Headers.GetValues("userid").FirstOrDefault();;
                    //qpdsi.DatasetName = "";
                    qpdsi.ErrorMsg = string.Empty;

                    ////get CSV filename
                    //string csvfname = response.Content.Headers.ContentDisposition.FileName;
                    ////reading CSV  content
                    ////html.Text = response.Content.ReadAsStringAsync().Result;

                    //string apikey = response.Headers.GetValues("apikey").FirstOrDefault();
                    //string datasetid = response.Headers.GetValues("datasetid").FirstOrDefault();
                    //string surveyid = response.Headers.GetValues("surveyid").FirstOrDefault();
                    //string userid = response.Headers.GetValues("userid").FirstOrDefault();
                }
                else
                {
                    errmg = string.Format("{0} ({1})", (int)response.StatusCode, response.ReasonPhrase);
                }
            }
            catch (Exception ex)
            {
                errmg = ex.Message + "\n" + ex.StackTrace;
            }
            finally
            {
                if (client != null)
                {
                    client.Dispose();
                }
                qpdsi.ErrorMsg = errmg;
            }
            return(Task.CompletedTask);
        }
        //public static bool overwriteDataset = true;//since QPro dialog will prompt user for overwrite, we always overwrite.
        //If user clicks NO when overwrite prompt is shown, we never come to this code anyway. So we always overwrite.

        //whenever Qpro dataset is opened, execute this
        public static void AddQPDatasetInfo(string filename, string apikey, string datasetid,
                                            string surveyid, string userid, string datasetname)
        {
            QProDatasetInfo qpdsi = new QProDatasetInfo();

            qpdsi.Filename    = filename;
            qpdsi.ApiKey      = apikey;
            qpdsi.DatasetId   = datasetid;//this should be the key but for user 'datasetname' is easier so
            qpdsi.SurveyId    = surveyid;
            qpdsi.UserId      = userid;
            qpdsi.DatasetName = datasetname;                 //this is the key for user convenience

            if (RemoveQPDatasetInfo(datasetname))            //remove the key if it exists
            {
                QproDatasetInfoList.Add(datasetname, qpdsi); //add the key. This is always a non existing key
            }
            //as we have deleted the exising one in the above line.
        }
 //Get QPro filename from the dictionary
 public static string GetQPDatasetFileName(string datasetname)
 {
     if (!string.IsNullOrEmpty(datasetname))
     {
         QProDatasetInfo qpdsi    = new QProDatasetInfo();
         bool            successs = QproDatasetInfoList.TryGetValue(datasetname, out qpdsi);
         if (successs)
         {
             return(qpdsi.Filename);
         }
         else
         {
             return(null);
         }
     }
     else
     {
         return(null);
     }
 }