<commit_before>﻿using System;
using System.Collections.Generic;
using ConDep.Dsl.Operations.WebDeploy.Model;
using Microsoft.Web.Deployment;

namespace ConDep.Dsl
{
    public class WebSiteProvider : ExistingServerProvider
    {
        private readonly string _destFilePath;
        //private readonly string _sourceWebsiteName;
        //private readonly string _destWebSiteName;

        public WebSiteProvider(string sourceWebsiteName, string destWebSiteName)
        {
            DestinationPath = destWebSiteName;
            SourcePath = sourceWebsiteName;
            //_sourceWebsiteName = sourceWebsiteName;
            //_destWebSiteName = destWebSiteName;
        }

        public WebSiteProvider(string sourceWebsiteName, string destWebSiteName, string destFilePath)
        {
            _destFilePath = destFilePath;
            //-replace:objectName=virtualDirectory,targetAttributeName=physicalPath,match="C:\\WebDeployTemplateWebSites",replace="C:\Web"
            DestinationPath = destWebSiteName;
            SourcePath = sourceWebsiteName;
        }

        public override string Name
        {
            get { return DeploymentWellKnownProvider.AppHostConfig.ToString(); }
        }

        public bool ExcludeAppPools { get; set; }

        public bool ExcludeCertificates { get; set; }

        public bool ExcludeContent { get; set; }

        public bool ExcludeFrameworkConfig { get; set; }

        public bool ExcludeHttpCertConfig { get; set; }

        public override DeploymentProviderOptions GetWebDeployDestinationObject()
        {
            return new DeploymentProviderOptions(Name) { Path = DestinationPath };
        }

        public override DeploymentObject GetWebDeploySourceObject(DeploymentBaseOptions sourceBaseOptions)
        {
            return DeploymentManager.CreateObject(Name, SourcePath, sourceBaseOptions);
        }

        public override IList<DeploymentRule> GetReplaceRules()
        {
            if (string.IsNullOrWhiteSpace(_destFilePath))
                return base.GetReplaceRules();

            return new List<DeploymentRule>
                       {
                           new DeploymentReplaceRule("ConDepReplaceRule", "virtualDirectory", "", "", "physicalPath", "", _destFilePath)
                       };
        }

        public override bool IsValid(Notification notification)
        {
            return !string.IsNullOrWhiteSpace(SourcePath) && !string.IsNullOrWhiteSpace(DestinationPath);
        }
    }
}<commit_msg>Fixed the possibility to disable WebDeploy provider links for the WebSite provider.<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using ConDep.Dsl.Operations.WebDeploy.Model;
using Microsoft.Web.Deployment;

namespace ConDep.Dsl
{
    public class WebSiteProvider : ExistingServerProvider
    {
        private readonly string _destFilePath;
        private readonly Dictionary<string, bool> _disabledLinkExtensions = new Dictionary<string, bool>();

        //private readonly string _sourceWebsiteName;
        //private readonly string _destWebSiteName;

        public WebSiteProvider(string sourceWebsiteName, string destWebSiteName)
        {
            DestinationPath = destWebSiteName;
            SourcePath = sourceWebsiteName;
            //_sourceWebsiteName = sourceWebsiteName;
            //_destWebSiteName = destWebSiteName;
        }

        public WebSiteProvider(string sourceWebsiteName, string destWebSiteName, string destFilePath)
        {
            _destFilePath = destFilePath;
            DestinationPath = destWebSiteName;
            SourcePath = sourceWebsiteName;
        }

        public override string Name
        {
            get { return DeploymentWellKnownProvider.AppHostConfig.ToString(); }
        }

        public bool ExcludeAppPools
        {
            get { return GetExcludeValue("AppPoolExtension"); }
            set { SetExcludeValue("AppPoolExtension", value); }
        }

        public bool ExcludeCertificates
        {
            get { return GetExcludeValue("CertificateExtension"); }
            set { SetExcludeValue("CertificateExtension", value); }
        }

        public bool ExcludeContent
        {
            get { return GetExcludeValue("ContentExtension"); }
            set { SetExcludeValue("ContentExtension", value); }
        }

        public bool ExcludeFrameworkConfig
        {
            get { return GetExcludeValue("FrameworkConfigExtension"); }
            set { SetExcludeValue("FrameworkConfigExtension", value); }
        }

        public bool ExcludeHttpCertConfig
        {
            get { return GetExcludeValue("HttpCertConfigExtension"); }
            set { SetExcludeValue("HttpCertConfigExtension", value); }
        }

        public override DeploymentProviderOptions GetWebDeployDestinationObject()
        {
            return new DeploymentProviderOptions(Name) { Path = DestinationPath };
        }

        public override DeploymentObject GetWebDeploySourceObject(DeploymentBaseOptions sourceBaseOptions)
        {
            var excludedLinks = (from link in sourceBaseOptions.LinkExtensions
                                from excludedLink in _disabledLinkExtensions
                                where excludedLink.Value && link.Name == excludedLink.Key
                                select link).ToList();

            excludedLinks.ForEach(x => x.Enabled = false);

            return DeploymentManager.CreateObject(Name, SourcePath, sourceBaseOptions);
            
        }

        public override IList<DeploymentRule> GetReplaceRules()
        {
            if (string.IsNullOrWhiteSpace(_destFilePath))
                return base.GetReplaceRules();

            return new List<DeploymentRule>
                       {
                           new DeploymentReplaceRule("ConDepReplaceRule", "virtualDirectory", "", "", "physicalPath", "", _destFilePath)
                       };
        }

        public override bool IsValid(Notification notification)
        {
            return !string.IsNullOrWhiteSpace(SourcePath) && !string.IsNullOrWhiteSpace(DestinationPath);
        }

        private bool GetExcludeValue(string extensionExcludeName)
        {
            return _disabledLinkExtensions.ContainsKey(extensionExcludeName) ? _disabledLinkExtensions[extensionExcludeName] : false;
        }

        private void SetExcludeValue(string extensionExcludeName, bool value)
        {
            if (_disabledLinkExtensions.ContainsKey(extensionExcludeName))
            {
                _disabledLinkExtensions[extensionExcludeName] = value;
            }
            else
            {
                _disabledLinkExtensions.Add(extensionExcludeName, value);
            }
        }

    }
}
{'fraction_non_alphanumeric': 0.0706713780918728, 'fraction_numerical': 0.0, 'mean_word_length': 2.29917435648373, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4627938', 'n_tokens_mistral': 1610, 'n_tokens_neox': 1560, 'n_words': 334}