Example #1
0
        public static string EnsureDownloaded(NodeDownloadData downloadData)
        {
            if (!Directory.Exists("TestData"))
            {
                Directory.CreateDirectory("TestData");
            }

            var osDownloadData = downloadData.GetCurrentOSDownloadData();

            if (osDownloadData == null)
            {
                throw new Exception("This platform does not support tests involving this crypto currency, DownloadData for this OS are unavailable");
            }
            var bitcoind = Path.Combine("TestData", String.Format(osDownloadData.Executable, downloadData.Version));
            var zip      = Path.Combine("TestData", String.Format(osDownloadData.Archive, downloadData.Version));

            if (File.Exists(bitcoind))
            {
                return(bitcoind);
            }

            string     url    = String.Format(osDownloadData.DownloadLink, downloadData.Version);
            HttpClient client = new HttpClient();

            client.Timeout = TimeSpan.FromMinutes(10.0);
            var data = client.GetByteArrayAsync(url).GetAwaiter().GetResult();

            CheckHash(osDownloadData, data);
            File.WriteAllBytes(zip, data);

            var extractDirectory = "TestData";

            if (osDownloadData.CreateFolder != null)
            {
                if (!Directory.Exists(osDownloadData.CreateFolder))
                {
                    Directory.CreateDirectory(osDownloadData.CreateFolder);
                }
                extractDirectory = Path.Combine(extractDirectory, string.Format(osDownloadData.CreateFolder, downloadData.Version));
            }

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                ZipFile.ExtractToDirectory(zip, extractDirectory);
            }
            else
            {
                Process.Start("tar", "-zxvf " + zip + " -C " + extractDirectory).WaitForExit();
            }
            File.Delete(zip);
            return(bitcoind);
        }
Example #2
0
        private static string EnsureDownloaded(NodeDownloadData downloadData)
        {
            if (!Directory.Exists("TestData"))
            {
                Directory.CreateDirectory("TestData");
            }

            string zip;
            string bitcoind;

            var osDownloadData = downloadData.GetCurrentOSDownloadData();

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                bitcoind = "TestData/" + String.Format(osDownloadData.Executable, downloadData.Version);
                if (File.Exists(bitcoind))
                {
                    return(bitcoind);
                }
                zip = "TestData/" + String.Format(osDownloadData.Archive, downloadData.Version);
                string     url    = String.Format(osDownloadData.DownloadLink, downloadData.Version);
                HttpClient client = new HttpClient();
                client.Timeout = TimeSpan.FromMinutes(10.0);
                var data = client.GetByteArrayAsync(url).GetAwaiter().GetResult();
                CheckHash(osDownloadData, data);
                File.WriteAllBytes(zip, data);
                ZipFile.ExtractToDirectory(zip, new FileInfo(zip).Directory.FullName);
            }
            else
            {
                bitcoind = "TestData/" + String.Format(osDownloadData.Executable, downloadData.Version);
                if (File.Exists(bitcoind))
                {
                    return(bitcoind);
                }

                zip = "TestData/" + String.Format(osDownloadData.Archive, downloadData.Version);

                string     url    = String.Format(osDownloadData.DownloadLink, downloadData.Version);
                HttpClient client = new HttpClient();
                client.Timeout = TimeSpan.FromMinutes(10.0);
                var data = client.GetByteArrayAsync(url).GetAwaiter().GetResult();
                CheckHash(osDownloadData, data);
                File.WriteAllBytes(zip, data);
                Process.Start("tar", "-zxvf " + zip + " -C TestData").WaitForExit();
            }
            File.Delete(zip);
            return(bitcoind);
        }