public NewOrEditVariableDialog(AutomationVariable variable)
        {
            InitializeComponent();

            variableTypeComboBox.Items.Add(Constants.VariableType.String);
            variableTypeComboBox.Items.Add(Constants.VariableType.Number);
            variableTypeComboBox.SelectedValue = Constants.VariableType.String;

            variableEncryptedComboBox.Items.Add(Constants.EncryptedState.PlainText);
            variableEncryptedComboBox.Items.Add(Constants.EncryptedState.Encrypted);
            variableEncryptedComboBox.SelectedValue = Constants.EncryptedState.PlainText;

            if (variable != null)
            {
                if(variable.Encrypted)
                {
                    if(variable.getValue() != null) {
                        encryptedValueTextbox.Password = variable.getValue().ToString();
                    }
                    variableEncryptedComboBox.SelectedValue = Constants.EncryptedState.Encrypted;
                }
                else
                {
                    valueTextbox.Text = variable.getValue().ToString();
                    variableEncryptedComboBox.SelectedValue = Constants.EncryptedState.PlainText;
                }

                if (variable.getValue() is String)
                {
                    variableTypeComboBox.SelectedValue = Constants.VariableType.String;
                }
                else if (IsNumber(variable.getValue()))
                {
                    variableTypeComboBox.SelectedValue = Constants.VariableType.Number;
                }

                initialized = true;
                setEncrypted(variable.Encrypted);

                // don't allow user to change encrypted status of an existing variable asset
                variableEncryptedComboBox.IsEnabled = false; 
                variableEncryptedComboBox.IsEditable = false;
                variableEncryptedComboBox.IsHitTestVisible = false;
                variableEncryptedComboBox.Focusable = false;
                
                this.Title = "Edit Variable Asset";
            }
            else
            {
                initialized = true;
                this.Title = "New Variable Asset";
            }
        }
        private void createOrUpdateVariableAsset(string variableAssetName, AutomationVariable variableToEdit)
        {
            var dialog = new NewOrEditVariableDialog(variableToEdit);

            if (dialog.ShowDialog() == true)
            {
                var assetsToSave = new List<AutomationAsset>();

                var newVariable = new AutomationVariable(variableAssetName, dialog.value, dialog.encrypted);
                assetsToSave.Add(newVariable);

                AutomationAssetManager.SaveLocally(iseClient.currWorkspace, assetsToSave, getEncryptionCertificateThumbprint());
                refreshAssets();
            }
        }
        private async Task createOrUpdateVariableAsset(string variableAssetName, AutomationVariable variableToEdit, bool newAsset = false)
        {
            if (newAsset)
            {
                // Check if variable already exists before creating one.
                var asset = await AutomationAssetManager.GetAsset(variableAssetName, Constants.AssetType.Variable, iseClient.currWorkspace, iseClient.automationManagementClient, iseClient.accountResourceGroups[iseClient.currAccount].Name, iseClient.currAccount.Name, getEncryptionCertificateThumbprint(), connectionTypes);
                if (asset != null) throw new Exception("Variable with that name already exists");
            }

            var dialog = new NewOrEditVariableDialog(variableToEdit);

            if (dialog.ShowDialog() == true)
            {
                var assetsToSave = new List<AutomationAsset>();

                var newVariable = new AutomationVariable(variableAssetName, dialog.value, dialog.encrypted);
                assetsToSave.Add(newVariable);

                try
                {
                    AutomationAssetManager.SaveLocally(iseClient.currWorkspace, assetsToSave, getEncryptionCertificateThumbprint(), connectionTypes);
                    await refreshAssets();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
        /// <summary>
        /// Returns if the asset exists locally or in the cloud
        /// </summary>
        /// <param name="assetName"></param>
        /// <param name="assetType"></param>
        /// <param name="localWorkspacePath"></param>
        /// <param name="automationApi"></param>
        /// <param name="resourceGroupName"></param>
        /// <param name="automationAccountName"></param>
        /// <param name="encryptionCertThumbprint"></param>
        /// <returns>null if the asset does not exist or else returns the asset</returns>
        public static async Task <AutomationAsset> GetAsset(String assetName, String assetType, String localWorkspacePath, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName, string encryptionCertThumbprint, ICollection <ConnectionType> connectionTypes)
        {
            AutomationAsset automationAsset = null;

            // Get local assets
            LocalAssets localAssets = LocalAssetsStore.Get(localWorkspacePath, encryptionCertThumbprint, connectionTypes);

            // Search for variables
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(TIMEOUT_MS);
            if (assetType == Constants.AssetType.Variable)
            {
                // Check local asset store first
                var localVariable = localAssets.Variables.Find(asset => asset.Name == assetName);
                if (localVariable != null)
                {
                    automationAsset = new AutomationVariable(localVariable);
                }
                else
                {
                    try
                    {
                        // Check cloud. Catch exception if it doesn't exist
                        VariableGetResponse cloudVariable = await automationApi.Variables.GetAsync(resourceGroupName, automationAccountName, assetName, cts.Token);

                        automationAsset = new AutomationVariable(cloudVariable.Variable);
                    }
                    catch (Exception e)
                    {
                        // If the exception is not found, don't throw new exception as this is expected
                        if (e.HResult != -2146233088)
                        {
                            throw e;
                        }
                    }
                }
            }
            // Search for credentials
            else if (assetType == Constants.AssetType.Credential)
            {
                // Check local asset store first
                var localCredential = localAssets.PSCredentials.Find(asset => asset.Name == assetName);
                if (localCredential != null)
                {
                    automationAsset = new AutomationCredential(localCredential);
                }
                else
                {
                    try
                    {
                        // Check cloud. Catch execption if it doesn't exist
                        CredentialGetResponse cloudVariable = await automationApi.PsCredentials.GetAsync(resourceGroupName, automationAccountName, assetName, cts.Token);

                        automationAsset = new AutomationCredential(cloudVariable.Credential);
                    }
                    catch (Exception e)
                    {
                        // If the exception is not found, don't throw new exception as this is expected
                        if (e.HResult != -2146233088)
                        {
                            throw e;
                        }
                    }
                }
            }
            // Search for connections
            else if (assetType == Constants.AssetType.Connection)
            {
                // Check local asset store first
                var localConnection = localAssets.Connections.Find(asset => asset.Name == assetName);
                if (localConnection != null)
                {
                    automationAsset = new AutomationConnection(localConnection);
                }
                else
                {
                    try
                    {
                        // Check cloud. Catch exception if it doesn't exist
                        ConnectionGetResponse cloudConnection = await automationApi.Connections.GetAsync(resourceGroupName, automationAccountName, assetName, cts.Token);

                        cts = new CancellationTokenSource();
                        cts.CancelAfter(TIMEOUT_MS);
                        ConnectionTypeGetResponse connectionType = await automationApi.ConnectionTypes.GetAsync(resourceGroupName, automationAccountName,
                                                                                                                cloudConnection.Connection.Properties.ConnectionType.Name, cts.Token);

                        automationAsset = new AutomationConnection(cloudConnection.Connection, connectionType.ConnectionType);
                    }
                    catch (Exception e)
                    {
                        // If the exception is not found, don't throw new exception as this is expected
                        if (e.HResult != -2146233088)
                        {
                            throw e;
                        }
                    }
                }
            }
            // Search for certificates
            else if (assetType == Constants.AssetType.Certificate)
            {
                // Check local asset store first
                var localCertificate = localAssets.Certificate.Find(asset => asset.Name == assetName);
                if (localCertificate != null)
                {
                    automationAsset = new AutomationCertificate(localCertificate);
                }
                else
                {
                    try
                    {
                        // Check cloud. Catch execption if it doesn't exist
                        CertificateGetResponse cloudCertificate = await automationApi.Certificates.GetAsync(resourceGroupName, automationAccountName, assetName, cts.Token);

                        automationAsset = new AutomationCertificate(cloudCertificate.Certificate);
                    }
                    catch (Exception e)
                    {
                        // If the exception is not found, don't throw new exception as this is expected
                        if (e.HResult != -2146233088)
                        {
                            throw e;
                        }
                    }
                }
            }
            return(automationAsset);
        }
예제 #5
0
 public VariableJson(AutomationVariable variable)
     : base(variable)
 {
     this.Encrypted = variable.Encrypted;
     this.Value     = variable.getValue();
 }
        public static async Task <ISet <AutomationAsset> > GetAll(String localWorkspacePath, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName, string encryptionCertThumbprint, ICollection <ConnectionType> connectionTypes)
        {
            CancellationTokenSource cts = new CancellationTokenSource();

            cts.CancelAfter(TIMEOUT_MS);
            VariableListResponse cloudVariables = await automationApi.Variables.ListAsync(resourceGroupName, automationAccountName, cts.Token);

            cts = new CancellationTokenSource();
            cts.CancelAfter(TIMEOUT_MS);
            CredentialListResponse cloudCredentials = await automationApi.PsCredentials.ListAsync(resourceGroupName, automationAccountName, cts.Token);

            cts = new CancellationTokenSource();
            cts.CancelAfter(TIMEOUT_MS);
            ConnectionListResponse cloudConnections = await automationApi.Connections.ListAsync(resourceGroupName, automationAccountName, cts.Token);

            CertificateListResponse cloudCertificates = await automationApi.Certificates.ListAsync(resourceGroupName, automationAccountName, cts.Token);

            // need to get connections one at a time to get each connection's values. Values currently come back as empty in list call
            var connectionAssetsWithValues = new HashSet <Connection>();

            foreach (var connection in cloudConnections.Connection)
            {
                cts = new CancellationTokenSource();
                cts.CancelAfter(TIMEOUT_MS);
                var connectionResponse = await automationApi.Connections.GetAsync(resourceGroupName, automationAccountName, connection.Name, cts.Token);

                connectionAssetsWithValues.Add(connectionResponse.Connection);
            }

            LocalAssets localAssets = LocalAssetsStore.Get(localWorkspacePath, encryptionCertThumbprint, connectionTypes);

            var automationAssets = new SortedSet <AutomationAsset>();

            // Compare cloud variables to local
            foreach (var cloudAsset in cloudVariables.Variables)
            {
                var localAsset = localAssets.Variables.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                                      new AutomationVariable(localAsset, cloudAsset) :
                                      new AutomationVariable(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created variables
            foreach (var localAsset in localAssets.Variables)
            {
                var automationAsset = new AutomationVariable(localAsset);
                automationAssets.Add(automationAsset);
            }

            // Compare cloud credentials to local
            foreach (var cloudAsset in cloudCredentials.Credentials)
            {
                var localAsset = localAssets.PSCredentials.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                                      new AutomationCredential(localAsset, cloudAsset) :
                                      new AutomationCredential(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created credentials
            foreach (var localAsset in localAssets.PSCredentials)
            {
                var automationAsset = new AutomationCredential(localAsset);
                automationAssets.Add(automationAsset);
            }

            // Compare cloud connections to local
            foreach (var cloudAsset in connectionAssetsWithValues)
            {
                ConnectionTypeGetResponse connectionType = await automationApi.ConnectionTypes.GetAsync(resourceGroupName, automationAccountName, cloudAsset.Properties.ConnectionType.Name);

                var localAsset = localAssets.Connections.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                                      new AutomationConnection(localAsset, cloudAsset) :
                                      new AutomationConnection(cloudAsset, connectionType.ConnectionType);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created connections
            foreach (var localAsset in localAssets.Connections)
            {
                var automationAsset = new AutomationConnection(localAsset);
                automationAssets.Add(automationAsset);
            }

            // Compare cloud certificates to local
            foreach (var cloudAsset in cloudCertificates.Certificates)
            {
                var localAsset = localAssets.Certificate.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                                      new AutomationCertificate(localAsset, cloudAsset) :
                                      new AutomationCertificate(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created certificates
            foreach (var localAsset in localAssets.Certificate)
            {
                var automationAsset = new AutomationCertificate(localAsset);
                automationAssets.Add(automationAsset);
            }

            return(automationAssets);
        }
 public VariableJson(AutomationVariable variable)
     : base(variable)
 {
     this.Encrypted = variable.Encrypted;
     this.Value = variable.getValue();
 }
        public static async Task <ISet <AutomationAsset> > GetAll(String localWorkspacePath, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName, string encryptionCertThumbprint)
        {
            VariableListResponse cloudVariables = await automationApi.Variables.ListAsync(resourceGroupName, automationAccountName);

            CredentialListResponse cloudCredentials = await automationApi.PsCredentials.ListAsync(resourceGroupName, automationAccountName);

            // TODO: need to get one at a time to get values. values currently comes back as empty
            //ConnectionListResponse cloudConnections = await automationApi.Connections.ListAsync(resourceGroupName, automationAccountName);

            LocalAssets localAssets = LocalAssetsStore.Get(localWorkspacePath, encryptionCertThumbprint);

            var automationAssets = new SortedSet <AutomationAsset>();

            // Compare cloud variables to local
            foreach (var cloudAsset in cloudVariables.Variables)
            {
                var localAsset = localAssets.Variables.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                                      new AutomationVariable(localAsset, cloudAsset) :
                                      new AutomationVariable(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created variables
            foreach (var localAsset in localAssets.Variables)
            {
                var automationAsset = new AutomationVariable(localAsset);
                automationAssets.Add(automationAsset);
            }

            // Compare cloud credentials to local
            foreach (var cloudAsset in cloudCredentials.Credentials)
            {
                var localAsset = localAssets.PSCredentials.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                                      new AutomationCredential(localAsset, cloudAsset) :
                                      new AutomationCredential(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created credentials
            foreach (var localAsset in localAssets.PSCredentials)
            {
                var automationAsset = new AutomationCredential(localAsset);
                automationAssets.Add(automationAsset);
            }

            // Compare cloud connections to local

            /*foreach (var cloudAsset in cloudConnections.Connection)
             * {
             *  var localAsset = localAssets.Connections.Find(asset => asset.Name == cloudAsset.Name);
             *
             *  var automationAsset = (localAsset != null) ?
             *          new AutomationConnection(localAsset, cloudAsset) :
             *          new AutomationConnection(cloudAsset);
             *
             *  automationAssets.Add(automationAsset);
             * }
             *
             * // Add remaining locally created connections
             * foreach (var localAsset in localAssets.Connections)
             * {
             *  var automationAsset = new AutomationConnection(localAsset);
             *  automationAssets.Add(automationAsset);
             * }*/

            return(automationAssets);
        }
        /// <summary>
        /// Returns if the asset exists locally or in the cloud
        /// </summary>
        /// <param name="assetName"></param>
        /// <param name="assetType"></param>
        /// <param name="localWorkspacePath"></param>
        /// <param name="automationApi"></param>
        /// <param name="resourceGroupName"></param>
        /// <param name="automationAccountName"></param>
        /// <param name="encryptionCertThumbprint"></param>
        /// <returns>null if the asset does not exist or else returns the asset</returns>
        public static async Task<AutomationAsset> GetAsset(String assetName, String assetType, String localWorkspacePath, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName, string encryptionCertThumbprint, ICollection<ConnectionType> connectionTypes)
        {
            AutomationAsset automationAsset = null;

            // Get local assets
            LocalAssets localAssets = LocalAssetsStore.Get(localWorkspacePath, encryptionCertThumbprint, connectionTypes);

            // Search for variables
            CancellationTokenSource cts = new CancellationTokenSource();
            cts.CancelAfter(TIMEOUT_MS);
            if (assetType == Constants.AssetType.Variable)
            {
                // Check local asset store first
                var localVariable = localAssets.Variables.Find(asset => asset.Name == assetName);
                if (localVariable != null)
                {
                    automationAsset = new AutomationVariable(localVariable);
                }
                else
                {
                    try
                    {
                        // Check cloud. Catch exception if it doesn't exist
                        VariableGetResponse cloudVariable = await automationApi.Variables.GetAsync(resourceGroupName, automationAccountName, assetName, cts.Token);
                        automationAsset = new AutomationVariable(cloudVariable.Variable);
                    }
                    catch (Exception e)
                    {
                        // If the exception is not found, don't throw new exception as this is expected
                        if (e.HResult != -2146233088) throw e;
                    }
                }
            }
            // Search for credentials
            else if (assetType == Constants.AssetType.Credential)
            {
                // Check local asset store first
                var localCredential = localAssets.PSCredentials.Find(asset => asset.Name == assetName);
                if (localCredential != null)
                {
                    automationAsset = new AutomationCredential(localCredential);
                }
                else
                {
                    try
                    {
                        // Check cloud. Catch execption if it doesn't exist
                        CredentialGetResponse cloudVariable = await automationApi.PsCredentials.GetAsync(resourceGroupName, automationAccountName, assetName, cts.Token);
                        automationAsset = new AutomationCredential(cloudVariable.Credential);
                    }
                    catch (Exception e)
                    {
                        // If the exception is not found, don't throw new exception as this is expected
                        if (e.HResult != -2146233088) throw e;
                    }
                }
            }
            // Search for connections
            else if (assetType == Constants.AssetType.Connection)
            {
                // Check local asset store first
                var localConnection = localAssets.Connections.Find(asset => asset.Name == assetName);
                if (localConnection != null)
                {
                    automationAsset = new AutomationConnection(localConnection);
                }
                else
                {
                    try
                    {
                        // Check cloud. Catch exception if it doesn't exist
                        ConnectionGetResponse cloudConnection = await automationApi.Connections.GetAsync(resourceGroupName, automationAccountName, assetName, cts.Token);
                        cts = new CancellationTokenSource();
                        cts.CancelAfter(TIMEOUT_MS);
                        ConnectionTypeGetResponse connectionType =  await automationApi.ConnectionTypes.GetAsync(resourceGroupName, automationAccountName, 
                            cloudConnection.Connection.Properties.ConnectionType.Name, cts.Token);
                        automationAsset = new AutomationConnection(cloudConnection.Connection, connectionType.ConnectionType);
                    }
                    catch (Exception e)
                    {
                        // If the exception is not found, don't throw new exception as this is expected
                        if (e.HResult != -2146233088) throw e;
                    }
                }
            }
            return automationAsset;
        }
        public static async Task<ISet<AutomationAsset>> GetAll(String localWorkspacePath, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName, string encryptionCertThumbprint, ICollection<ConnectionType> connectionTypes)
        {
            CancellationTokenSource cts = new CancellationTokenSource();
            cts.CancelAfter(TIMEOUT_MS);
            VariableListResponse cloudVariables = await automationApi.Variables.ListAsync(resourceGroupName, automationAccountName, cts.Token);
            cts = new CancellationTokenSource();
            cts.CancelAfter(TIMEOUT_MS);
            CredentialListResponse cloudCredentials = await automationApi.PsCredentials.ListAsync(resourceGroupName, automationAccountName, cts.Token);
            cts = new CancellationTokenSource();
            cts.CancelAfter(TIMEOUT_MS);
            ConnectionListResponse cloudConnections = await automationApi.Connections.ListAsync(resourceGroupName, automationAccountName, cts.Token);

            // need to get connections one at a time to get each connection's values. Values currently come back as empty in list call
            var connectionAssetsWithValues = new HashSet<Connection>();
            foreach (var connection in cloudConnections.Connection)
            {
                cts = new CancellationTokenSource();
                cts.CancelAfter(TIMEOUT_MS);
                var connectionResponse = await automationApi.Connections.GetAsync(resourceGroupName, automationAccountName, connection.Name, cts.Token);
                connectionAssetsWithValues.Add(connectionResponse.Connection);
            }

            LocalAssets localAssets = LocalAssetsStore.Get(localWorkspacePath, encryptionCertThumbprint, connectionTypes);

            var automationAssets = new SortedSet<AutomationAsset>();

            // Compare cloud variables to local
            foreach (var cloudAsset in cloudVariables.Variables)
            {
                var localAsset = localAssets.Variables.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                        new AutomationVariable(localAsset, cloudAsset) :
                        new AutomationVariable(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created variables
            foreach (var localAsset in localAssets.Variables)
            {
                var automationAsset = new AutomationVariable(localAsset);
                automationAssets.Add(automationAsset);
            }

            // Compare cloud credentials to local
            foreach (var cloudAsset in cloudCredentials.Credentials)
            {
                var localAsset = localAssets.PSCredentials.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                        new AutomationCredential(localAsset, cloudAsset) :
                        new AutomationCredential(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created credentials
            foreach (var localAsset in localAssets.PSCredentials)
            {
                var automationAsset = new AutomationCredential(localAsset);
                automationAssets.Add(automationAsset);
            }

            // Compare cloud connections to local
            foreach (var cloudAsset in connectionAssetsWithValues)
            {
                ConnectionTypeGetResponse connectionType = await automationApi.ConnectionTypes.GetAsync(resourceGroupName, automationAccountName, cloudAsset.Properties.ConnectionType.Name); 
                var localAsset = localAssets.Connections.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                        new AutomationConnection(localAsset, cloudAsset) :
                        new AutomationConnection(cloudAsset, connectionType.ConnectionType);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created connections
            foreach (var localAsset in localAssets.Connections)
            {
                var automationAsset = new AutomationConnection(localAsset);
                automationAssets.Add(automationAsset);
            }

            return automationAssets;
        }
        public static async Task<ISet<AutomationAsset>> GetAll(String localWorkspacePath, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName, string encryptionCertThumbprint)
        {
            VariableListResponse cloudVariables = await automationApi.Variables.ListAsync(resourceGroupName, automationAccountName);
            CredentialListResponse cloudCredentials = await automationApi.PsCredentials.ListAsync(resourceGroupName, automationAccountName);

            // TODO: need to get one at a time to get values. values currently comes back as empty
            //ConnectionListResponse cloudConnections = await automationApi.Connections.ListAsync(resourceGroupName, automationAccountName);

            LocalAssets localAssets = LocalAssetsStore.Get(localWorkspacePath, encryptionCertThumbprint);

            var automationAssets = new SortedSet<AutomationAsset>();

            // Compare cloud variables to local
            foreach (var cloudAsset in cloudVariables.Variables)
            {
                var localAsset = localAssets.Variables.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                        new AutomationVariable(localAsset, cloudAsset) :
                        new AutomationVariable(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created variables
            foreach (var localAsset in localAssets.Variables)
            {
                var automationAsset = new AutomationVariable(localAsset);
                automationAssets.Add(automationAsset);
            }

            // Compare cloud credentials to local
            foreach (var cloudAsset in cloudCredentials.Credentials)
            {
                var localAsset = localAssets.PSCredentials.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                        new AutomationCredential(localAsset, cloudAsset) :
                        new AutomationCredential(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created credentials
            foreach (var localAsset in localAssets.PSCredentials)
            {
                var automationAsset = new AutomationCredential(localAsset);
                automationAssets.Add(automationAsset);
            }

            // Compare cloud connections to local
            /*foreach (var cloudAsset in cloudConnections.Connection)
            {
                var localAsset = localAssets.Connections.Find(asset => asset.Name == cloudAsset.Name);

                var automationAsset = (localAsset != null) ?
                        new AutomationConnection(localAsset, cloudAsset) :
                        new AutomationConnection(cloudAsset);

                automationAssets.Add(automationAsset);
            }

            // Add remaining locally created connections
            foreach (var localAsset in localAssets.Connections)
            {
                var automationAsset = new AutomationConnection(localAsset);
                automationAssets.Add(automationAsset);
            }*/

            return automationAssets;
        }