public Model.SourceControl CreateSourceControl(
            string resourceGroupName,
            string automationAccountName,
            string name,
            string description,
            SecureString accessToken,
            string repoUrl,
            string sourceType,
            string branch,
            string folderPath,
            bool publishRunbook,
            bool autoSync)
        {
            Requires.Argument("resourceGroupName", resourceGroupName).NotNullOrEmpty();
            Requires.Argument("automationAccountName", automationAccountName).NotNullOrEmpty();
            Requires.Argument("name", name).NotNullOrEmpty();
            Requires.Argument("accessToken", accessToken).NotNullOrEmpty();
            Requires.Argument("repoUrl", repoUrl).NotNullOrEmpty();
            Requires.Argument("sourceType", sourceType).NotNullOrEmpty();
            Requires.Argument("folderPath", folderPath).NotNullOrEmpty();

            if (String.Equals(sourceType, Constants.SupportedSourceType.GitHub.ToString()) ||
                String.Equals(sourceType, Constants.SupportedSourceType.VsoGit.ToString()))
            {
                Requires.Argument("branch", branch).NotNullOrEmpty();
            }

            var decryptedAccessToken = Utils.GetStringFromSecureString(accessToken);

            var createParams = new SourceControlCreateOrUpdateParameters(
                repoUrl,
                branch,
                folderPath,
                autoSync,
                publishRunbook,
                sourceType,
                GetAccessTokenProperties(decryptedAccessToken),
                description);

            var sdkSourceControl = this.automationManagementClient.SourceControl.CreateOrUpdate(
                resourceGroupName,
                automationAccountName,
                name,
                createParams);

            Model.SourceControl result = null;

            if (sdkSourceControl != null)
            {
                result = new Model.SourceControl(sdkSourceControl, automationAccountName, resourceGroupName);
            }

            return(result);
        }
        public Model.SourceControl GetSourceControl(
            string resourceGroupName,
            string automationAccountName,
            string name)
        {
            Requires.Argument("resourceGroupName", resourceGroupName).NotNullOrEmpty();
            Requires.Argument("automationAccountName", automationAccountName).NotNullOrEmpty();
            Requires.Argument("name", name).NotNullOrEmpty();

            var existingSourceControl = this.automationManagementClient.SourceControl.Get(
                resourceGroupName,
                automationAccountName,
                name);

            Model.SourceControl result = null;

            if (existingSourceControl != null)
            {
                result = new Model.SourceControl(existingSourceControl, automationAccountName, resourceGroupName);
            }

            return(result);
        }
        public Model.SourceControl UpdateSourceControl(
            string resourceGroupName,
            string automationAccountName,
            string name,
            string description,
            SecureString accessToken,
            string branch,
            string folderPath,
            bool?publishRunbook,
            bool?autoSync)
        {
            Requires.Argument("ResourceGroupName", resourceGroupName).NotNullOrEmpty();
            Requires.Argument("AutomationAccountName", automationAccountName).NotNullOrEmpty();
            Requires.Argument("name", name).NotNullOrEmpty();

            var updateParams = new AutomationManagement.Models.SourceControlUpdateParameters();

            if (autoSync.HasValue)
            {
                updateParams.AutoSync = autoSync;
            }

            if (publishRunbook.HasValue)
            {
                updateParams.PublishRunbook = publishRunbook;
            }

            if (!string.IsNullOrEmpty(description))
            {
                updateParams.Description = description;
            }

            if (!string.IsNullOrEmpty(branch))
            {
                updateParams.Branch = branch;
            }

            if (!string.IsNullOrEmpty(folderPath))
            {
                updateParams.FolderPath = folderPath;
            }

            if (accessToken != null)
            {
                var decryptedAccessToken = Utils.GetStringFromSecureString(accessToken);
                updateParams.SecurityToken = GetAccessTokenProperties(decryptedAccessToken);
            }

            var sdkSourceControl = this.automationManagementClient.SourceControl.Update(
                resourceGroupName,
                automationAccountName,
                name,
                updateParams);

            Model.SourceControl result = null;

            if (sdkSourceControl != null)
            {
                result = new Model.SourceControl(sdkSourceControl, automationAccountName, resourceGroupName);
            }

            return(result);
        }