public static string CacheFilename(ScanProproteinInterfaceParameters scanProproteinInterfaceParameters)
        {
            if (scanProproteinInterfaceParameters == null)
            {
                throw new ArgumentNullException(nameof(scanProproteinInterfaceParameters));
            }

            var invalid = Path.GetInvalidFileNameChars();

            const string folder    = @"c:\k\";
            const string extension = @".xml";

            var queryString = string.Join("", scanProproteinInterfaceParameters.QueryString(false).Select(a => !invalid.Contains(a) ? a : '_').ToArray());

            var filename = folder + queryString + extension;

            if (filename.Length > 259)
            {
                using (SHA512 shaM = new SHA512Managed())
                {
                    var data = Encoding.UTF8.GetBytes(queryString);
                    var hash = shaM.ComputeHash(data);
                    filename = folder + BitConverter.ToString(hash) + extension;
                }
            }

            var path = Path.GetDirectoryName(filename);

            if (path != null)
            {
                Directory.CreateDirectory(path);
            }

            return(filename);
        }
        public static string GetProproteinInterfaceXml(ScanProproteinInterfaceParameters scanProproteinInterfaceParameters, TimeSpan timeout, int retries, TimeSpan retryDelay)
        {
            while (retries > 0)
            {
                retries--;

                using (var client = new HttpClient())
                {
                    client.Timeout     = new TimeSpan(1, 30, 0);
                    client.BaseAddress = new Uri("http://www.expasy.org/");
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/xml"));
                    //client.Timeout = ?

                    var queryString = "cgi-bin/proproteinInterface/PSScan.cgi?" + scanProproteinInterfaceParameters.QueryString();
                    // HTTP GET
                    var response = client.GetAsync(queryString);

                    if (response.IsCanceled || response.IsFaulted)
                    {
                        if (response.Exception != null)
                        {
                            throw response.Exception;
                        }
                    }

                    //response.Result.EnsureSuccessStatusCode();

                    try
                    {
                        response.Wait();

                        if (response.Result.IsSuccessStatusCode)
                        {
                            var readAsStringAsync = response.Result.Content.ReadAsStringAsync();

                            readAsStringAsync.Wait();

                            var resultString = readAsStringAsync.Result;

                            if (resultString == null)
                            {
                                resultString = "";
                            }

                            return(resultString);
                        }
                        else
                        {
                            return("");
                        }
                    }
                    catch (AggregateException)
                    {
                        if (retries == 0)
                        {
                            return(null);
                        }
                        else
                        {
                            var t = Task.Delay(1000);
                            t.Wait();
                        }
                    }
                }
            }

            return(null);
        }