public static async void DownloadFromCloud(ICollection <AutomationAsset> assetsToDownload, String localWorkspacePath, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName, String encryptionCertThumbprint, ICollection <ConnectionType> connectionTypes)
        {
            try
            {
                var cloudAssets = await AutomationAssetManager.GetAll(null, automationApi, resourceGroupName, automationAccountName, encryptionCertThumbprint, connectionTypes);

                var assetsToSaveLocally = new SortedSet <AutomationAsset>();

                foreach (var cloudAsset in cloudAssets)
                {
                    foreach (var assetToDownload in assetsToDownload)
                    {
                        if (cloudAsset.Equals(assetToDownload))
                        {
                            assetsToSaveLocally.Add(cloudAsset);
                            break;
                        }
                    }
                }

                AutomationAssetManager.SaveLocally(localWorkspacePath, assetsToSaveLocally, encryptionCertThumbprint, connectionTypes);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
        public static async void DownloadFromCloud(ICollection <AutomationAsset> assetsToDownload, String localWorkspacePath, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName, String encryptionCertThumbprint)
        {
            var cloudAssets = await AutomationAssetManager.GetAll(null, automationApi, resourceGroupName, automationAccountName, encryptionCertThumbprint);

            var assetsToSaveLocally = new SortedSet <AutomationAsset>();

            foreach (var cloudAsset in cloudAssets)
            {
                foreach (var assetToDownload in assetsToDownload)
                {
                    if (cloudAsset.Equals(assetToDownload))
                    {
                        assetsToSaveLocally.Add(cloudAsset);
                        break;
                    }
                }
            }

            AutomationAssetManager.SaveLocally(localWorkspacePath, assetsToSaveLocally, encryptionCertThumbprint);
        }
Exemplo n.º 3
0
        private string updateEncryptionCertificateIfExpiring(String baseWorkspace, String thumbprint)
        {
            if (thumbprint != null)
            {
                var encryptionCert = AutomationSelfSignedCertificate.GetCertificateWithThumbprint(thumbprint);
                // If the certificate will expire 30 days from now, ask to create a new one and encyprt assets with new thumbprint.
                if (Convert.ToDateTime(encryptionCert.GetExpirationDateString()) < DateTime.Now.AddDays(30))
                {
                    var messageBoxResult = System.Windows.Forms.MessageBox.Show(
                        string.Format("Your certificate to encrypt local assets will expire on '{0}'. Do you want to generate a new certificate?", encryptionCert.GetExpirationDateString())
                        , "Expiring certificate", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Warning
                        );

                    if (messageBoxResult == System.Windows.Forms.DialogResult.Yes)
                    {
                        // Create new certificate for encryption
                        certObj.CreateCertificateRequest(Properties.Settings.Default.certName);
                        var selfSignedCert = certObj.InstallCertficate();
                        var newThumbprint  = selfSignedCert.Thumbprint;

                        // Reset local assets with new encryption thumbprint
                        string[] secureAssetFiles = Directory.GetFiles(baseWorkspace, "SecureLocalAssets.json", SearchOption.AllDirectories);
                        foreach (var secureAssetFile in secureAssetFiles)
                        {
                            var localAssets = AutomationAssetManager.GetLocalEncryptedAssets(Path.GetDirectoryName(secureAssetFile), thumbprint);
                            AutomationAssetManager.SetLocalEncryptedAssets(Path.GetDirectoryName(secureAssetFile), localAssets, newThumbprint);
                        }

                        // Set new thumbprint in configuration file.
                        SetCertificateInConfigFile(newThumbprint);

                        // Remove old thumbprint
                        RemoveCertificateWithThumbprint(thumbprint);
                        return(newThumbprint);
                    }
                }
            }
            return(thumbprint);
        }
        public static async Task DownloadAllFromCloud(String localWorkspacePath, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName, String encryptionCertThumbprint, ICollection <ConnectionType> connectionTypes)
        {
            var assets = await AutomationAssetManager.GetAll(null, automationApi, resourceGroupName, automationAccountName, encryptionCertThumbprint, connectionTypes);

            AutomationAssetManager.SaveLocally(localWorkspacePath, assets, encryptionCertThumbprint, connectionTypes);
        }