示例#1
0
        public void BundlesDownload(string[] args)
        {
            string owner      = args.GetRequiredValue <string>(0);
            string folderpath = args.GetRequiredValue <string>(1);

            if (!Directory.Exists(folderpath))
            {
                WriteLine("Folder not found");
                return;
            }

            AnchorBundleDownloader bundleDownloader = new AnchorBundleDownloader();

            bundleDownloader.TimeoutMS  = 30 * 1000;
            bundleDownloader.MaxRetries = 1;
            bundleDownloader.VerifySSL  = false;

            Bundle[] bundles = Client.GetBundlesForOwner(owner);
            foreach (Bundle bundle in bundles)
            {
                string fileName = string.Format("Bundle_{0}.p7b", bundle.ID);
                string filePath = Path.Combine(folderpath, fileName);
                try
                {
                    WriteLine("Downloading ID={0}, {1}", bundle.ID, bundle.Url);
                    bundleDownloader.DownloadToFile(bundle.Uri, filePath);
                    WriteLine("ok");
                }
                catch (Exception ex)
                {
                    WriteLine("Error downloading bundle {0} from {1}", bundle.ID, bundle.Url);
                    WriteLine(ex.Message);
                }
            }
        }
示例#2
0
 /// <summary>
 /// Construct a new BundleAnchorIndex
 /// </summary>
 /// <param name="settings">Construct index based on these settings</param>
 /// <param name="incoming">Retrieve incoming or outgoing anchors</param>
 public BundleAnchorIndex(BundleResolverSettings settings, bool incoming)
 {
     m_clientSettings        = settings.ClientSettings;
     m_incoming              = incoming;
     m_downloader            = new AnchorBundleDownloader();
     m_downloader.VerifySSL  = settings.VerifySSL;
     m_downloader.TimeoutMS  = settings.TimeoutMilliseconds;
     m_downloader.MaxRetries = settings.MaxRetries;
 }
        public void TestDownloadBundle()
        {
            AnchorBundleDownloader downloader = new AnchorBundleDownloader();

            downloader.MaxRetries = 1;

            AnchorBundle bundle = null;

            Assert.DoesNotThrow(() => bundle = downloader.Download(new Uri(PatientTestBundleUrl)));
            Assert.True(!bundle.Certificates.IsNullOrEmpty());
        }
        public void TestDownloadCerts()
        {
            AnchorBundleDownloader downloader = new AnchorBundleDownloader();

            downloader.MaxRetries = 1;

            X509Certificate2Collection bundle = null;

            Assert.DoesNotThrow(() => bundle = downloader.DownloadCertificates(new Uri(PatientTestBundleUrl)));
            Assert.True(!bundle.IsNullOrEmpty());
        }
示例#5
0
        public void BundlesDownloadCerts(string[] args)
        {
            string owner      = args.GetRequiredValue <string>(0);
            string folderpath = args.GetRequiredValue <string>(1);

            if (!Directory.Exists(folderpath))
            {
                WriteLine("Folder not found");
                return;
            }

            AnchorBundleDownloader bundleDownloader = new AnchorBundleDownloader();

            bundleDownloader.TimeoutMS  = 30 * 1000;
            bundleDownloader.MaxRetries = 1;
            bundleDownloader.VerifySSL  = false;

            Bundle[] bundles = Client.GetBundlesForOwner(owner);
            foreach (Bundle bundle in bundles)
            {
                try
                {
                    WriteLine("Downloading ID={0}, {1}", bundle.ID, bundle.Url);
                    string bundleFolderPath = Path.Combine(folderpath, string.Format("Bundle_{0}", bundle.ID));
                    if (Directory.Exists(bundleFolderPath))
                    {
                        Directory.Delete(bundleFolderPath);
                    }
                    Directory.CreateDirectory(bundleFolderPath);

                    X509Certificate2Collection certs = bundleDownloader.DownloadCertificates(bundle.Uri);
                    foreach (X509Certificate2 cert in certs)
                    {
                        string certName = cert.ExtractEmailNameOrName();
                        WriteLine(certName);
                        string fileName = certName.ToFileName() + ".cer";
                        File.WriteAllBytes(Path.Combine(bundleFolderPath, fileName), cert.RawData);
                    }
                    WriteLine("ok");
                }
                catch (Exception ex)
                {
                    WriteLine("Error downloading bundle {0} from {1}", bundle.ID, bundle.Url);
                    WriteLine(ex.Message);
                }
            }
        }