Ejemplo n.º 1
0
        /// <summary>
        /// Adds the parameter.
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings AddParameter(this DeploySettings settings, string key, string value)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Parameters[key] = value;
            return(settings);
        }
        /// <summary>
        /// Sets the destination of the package to publish to
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="path">The path where the package should end up</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings ToDestinationPath(this DeploySettings settings, string path)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.DestinationPath = path;
            return(settings);
        }
        /// <summary>
        /// Sets if deployment compares each file using a checksum value instead of datetime
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="useChecksum">The useChecksum</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings UseChecksum(this DeploySettings settings, bool useChecksum)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.UseChecksum = useChecksum;
            return(settings);
        }
        /// <summary>
        /// Sets the type of remote agent to connect to
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="agentType">The type of remote agent</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings UseAgentType(this DeploySettings settings, RemoteAgent agentType)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.AgentType = agentType;
            return(settings);
        }
        /// <summary>
        /// Adds a <see cref="SkipRule" />.
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="rule">The rule.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings AddSkipRule(this DeploySettings settings, SkipRule rule)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.SkipRules.Add(rule);
            return(settings);
        }
        /// <summary>
        /// Adds a <see cref="SkipRule" />.
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="name">The name.</param>
        /// <param name="skipAction">The skipAction.</param>
        /// <param name="objectName">The objectName.</param>
        /// <param name="absolutePath">The absolutePath.</param>
        /// <param name="xpath">The xpath.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings AddSkipRule(this DeploySettings settings, string name, string skipAction, string objectName, string absolutePath, string xpath = null)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.SkipRules.Add(new SkipRule(name, skipAction, objectName, absolutePath, xpath));
            return(settings);
        }
        /// <summary>
        /// Sets the computer name on publish to
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="name">The computer name</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings UseComputerName(this DeploySettings settings, string name)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.ComputerName = name;
            return(settings);
        }
        /// <summary>
        /// Sets if untrusted certificates should be allowed
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="untrusted">Allow untrusted certificates</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings SetAllowUntrusted(this DeploySettings settings, bool untrusted = true)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.AllowUntrusted = untrusted;
            return(settings);
        }
        /// <summary>
        /// Sets the url to publish that package to
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="url">The publish url</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings SetPublishUrl(this DeploySettings settings, string url)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.PublishUrl = url;
            return(settings);
        }
        /// <summary>
        /// Sets if operations will not be executed but events will still be fired
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="whatIf">If operations will not be executed</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings SetWhatIf(this DeploySettings settings, bool whatIf = true)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.WhatIf = whatIf;
            return(settings);
        }
        /// <summary>
        /// Sets the logging trace level
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="level">The trace level.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings SetTraceLevel(this DeploySettings settings, TraceLevel level)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.TraceLevel = level;
            return(settings);
        }
        /// <summary>
        /// Sets if files that no longer exist should be deleted
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="delete">IF files should be deleted.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings SetDelete(this DeploySettings settings, bool delete = true)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Delete = delete;
            return(settings);
        }
        /// <summary>
        /// Sets the credentials to use when connecting
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="password">The password to connect with.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings UsePassword(this DeploySettings settings, string password)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Password = password;
            return(settings);
        }
        /// <summary>
        /// Sets the credentials to use when connecting
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="username">The username to connect with.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings UseUsername(this DeploySettings settings, string username)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Username = username;
            return(settings);
        }
        /// <summary>
        /// Sets the remote port to connect on.
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="port">The remote port to connect on</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings UsePort(this DeploySettings settings, int port)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.Port = port;
            return(settings);
        }
        /// <summary>
        /// Sets if NTLM authentication should be used
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="ntlm">use NTLM</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings UseNTLM(this DeploySettings settings, bool ntlm = true)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            settings.NTLM = ntlm;
            return(settings);
        }
        /// <summary>
        /// Sets if the target web app should be put offline during the deployment process.
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="useAppOffline">Wether to put the app offline or not.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings UseAppOffline(this DeploySettings settings, bool useAppOffline)
        {
            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            settings.UseAppOffline = useAppOffline;

            return(settings);
        }
        /// <summary>
        /// Adds the parameter.
        /// </summary>
        /// <param name="settings">The publish settings.</param>
        /// <param name="key">The key.</param>
        /// <param name="value">The value.</param>
        /// <returns>The same <see cref="DeploySettings"/> instance so that multiple calls can be chained.</returns>
        public static DeploySettings AddParameter(this DeploySettings settings, string key, string value)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }

            if (settings.Parameters.ContainsKey(key))
            {
                settings.Parameters[key] = value;
            }
            else
            {
                settings.Parameters.Add(key, value);
            }

            return(settings);
        }
Ejemplo n.º 19
0
        //Helpers
        private DeploymentBaseOptions GetBaseOptions(DeploySettings settings)
        {
            DeploymentBaseOptions options = new DeploymentBaseOptions
            {
                ComputerName = settings.PublishUrl,

                UserName = settings.Username,
                Password = settings.Password,

                AuthenticationType = settings.NTLM ? "ntlm" : "basic"
            };

            if (settings.AllowUntrusted)
            {
                ServicePointManager.ServerCertificateValidationCallback = OnCertificateValidation;
            }

            return(options);
        }
Ejemplo n.º 20
0
            /// <summary>
            /// Deploys the content of a website
            /// </summary>
            /// <param name="settings">The deployment settings.</param>
            /// <returns>The <see cref="DeploymentChangeSummary"/> that was applied during the deployment.</returns>
            public DeploymentChangeSummary Deploy(DeploySettings settings)
            {
                if (settings == null)
                {
                    throw new ArgumentNullException("settings");
                }
                if (settings.SourcePath == null)
                {
                    throw new ArgumentNullException("settings.SourcePath");
                }



                DeploymentBaseOptions sourceOptions = new DeploymentBaseOptions();
                DeploymentBaseOptions destOptions = this.GetBaseOptions(settings);

                FilePath sourcePath = settings.SourcePath.MakeAbsolute(_Environment);
                string destPath = settings.SiteName;

                destOptions.TraceLevel = settings.TraceLevel;
                destOptions.Trace += OnTraceEvent;

                DeploymentWellKnownProvider sourceProvider = DeploymentWellKnownProvider.ContentPath;
                DeploymentWellKnownProvider destProvider = DeploymentWellKnownProvider.Auto;



                //If a target path was specified, it could be virtual or physical
                if (settings.DestinationPath != null)
                {
                    if (System.IO.Path.IsPathRooted(settings.DestinationPath.FullPath))
                    {
                        // If it's rooted (e.g. d:\home\site\foo), use DirPath
                        sourceProvider = DeploymentWellKnownProvider.DirPath;
                        destProvider = DeploymentWellKnownProvider.DirPath;

                        destPath = settings.DestinationPath.FullPath;
                    }
                    else
                    {
                        // It's virtual, so append it to what we got from the publish profile
                        destPath += "/" + settings.DestinationPath.FullPath;
                    }
                }
                //When a SiteName is given but no DestinationPath
                else if (!String.IsNullOrWhiteSpace(settings.SiteName))
                {
                    //use ContentPath so it gets deployed to the Path of the named website in IIS
                    //which is the same behaviour as in Visual Studio
                    destProvider = DeploymentWellKnownProvider.ContentPath;
                }



                //If the content path is a zip file, use the Package provider
                string extension = sourcePath.GetExtension();
                if (extension != null && extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
                {
                    // For some reason, we can't combine a zip with a physical target path
                    if (destProvider == DeploymentWellKnownProvider.DirPath)
                    {
                        throw new Exception("A source zip file can't be used with a physical target path");
                    }

                    sourceProvider = DeploymentWellKnownProvider.Package;
                }



                //Sync Options
                DeploymentSyncOptions syncOptions = new DeploymentSyncOptions
                {
                    DoNotDelete = !settings.Delete,
                    WhatIf = settings.WhatIf
                };



                //Deploy
                _Log.Debug(Verbosity.Normal, "Deploying Website...");
                _Log.Debug(Verbosity.Normal, String.Format("-siteName '{0}'", settings.SiteName));
                _Log.Debug(Verbosity.Normal, String.Format("-destination '{0}'", settings.PublishUrl));
                _Log.Debug(Verbosity.Normal, String.Format("-source '{0}'", sourcePath.FullPath));
                _Log.Debug("");

                using (var deploymentObject = DeploymentManager.CreateObject(sourceProvider, sourcePath.FullPath, sourceOptions))
                {
                    foreach (var kv in settings.Parameters)
                    {
                        deploymentObject.SyncParameters[kv.Key].Value = kv.Value;
                    }

                    return deploymentObject.SyncTo(destProvider, destPath, destOptions, syncOptions);
                }
            }
Ejemplo n.º 21
0
            //Helpers
            private DeploymentBaseOptions GetBaseOptions(DeploySettings settings)
            {
                DeploymentBaseOptions options = new DeploymentBaseOptions
                {
                    ComputerName = settings.PublishUrl,

                    UserName = settings.Username,
                    Password = settings.Password,

                    AuthenticationType = settings.NTLM ? "ntlm" : "basic"
                };

                if (settings.AllowUntrusted)
                {
                    ServicePointManager.ServerCertificateValidationCallback = OnCertificateValidation;
                }

                return options;
            }
Ejemplo n.º 22
0
 public static DeploymentChangeSummary DeployWebsite(this ICakeContext context, DeploySettings settings)
 {
     return(new WebDeployManager(context.Environment, context.Log).Deploy(settings));
 }
Ejemplo n.º 23
0
        /// <summary>
        /// Deploys the content of a website
        /// </summary>
        /// <param name="settings">The deployment settings.</param>
        /// <returns>The <see cref="DeploymentChangeSummary"/> that was applied during the deployment.</returns>
        public DeploymentChangeSummary Deploy(DeploySettings settings)
        {
            if (settings == null)
            {
                throw new ArgumentNullException("settings");
            }
            if (settings.SourcePath == null)
            {
                throw new ArgumentNullException("settings.SourcePath");
            }



            DeploymentBaseOptions sourceOptions = new DeploymentBaseOptions();
            DeploymentBaseOptions destOptions   = this.GetBaseOptions(settings);

            FilePath sourcePath = settings.SourcePath.MakeAbsolute(_Environment);
            string   destPath   = settings.SiteName;

            destOptions.TraceLevel = settings.TraceLevel;
            destOptions.Trace     += OnTraceEvent;

            DeploymentWellKnownProvider sourceProvider = DeploymentWellKnownProvider.ContentPath;
            DeploymentWellKnownProvider destProvider   = DeploymentWellKnownProvider.Auto;



            //If a target path was specified, it could be virtual or physical
            if (settings.DestinationPath != null)
            {
                if (System.IO.Path.IsPathRooted(settings.DestinationPath.FullPath))
                {
                    // If it's rooted (e.g. d:\home\site\foo), use DirPath
                    sourceProvider = DeploymentWellKnownProvider.DirPath;
                    destProvider   = DeploymentWellKnownProvider.DirPath;

                    destPath = settings.DestinationPath.FullPath;
                }
                else
                {
                    // It's virtual, so append it to what we got from the publish profile
                    destPath += "/" + settings.DestinationPath.FullPath;
                }
            }
            //When a SiteName is given but no DestinationPath
            else if (!String.IsNullOrWhiteSpace(settings.SiteName))
            {
                //use ContentPath so it gets deployed to the Path of the named website in IIS
                //which is the same behaviour as in Visual Studio
                destProvider = DeploymentWellKnownProvider.ContentPath;
            }



            //If the content path is a zip file, use the Package provider
            string extension = sourcePath.GetExtension();

            if (extension != null && extension.Equals(".zip", StringComparison.OrdinalIgnoreCase))
            {
                // For some reason, we can't combine a zip with a physical target path
                if (destProvider == DeploymentWellKnownProvider.DirPath)
                {
                    throw new Exception("A source zip file can't be used with a physical target path");
                }

                sourceProvider = DeploymentWellKnownProvider.Package;
            }



            //Sync Options
            DeploymentSyncOptions syncOptions = new DeploymentSyncOptions
            {
                DoNotDelete = !settings.Delete,
                WhatIf      = settings.WhatIf
            };

            // Add SkipRules
            foreach (var rule in settings.SkipRules)
            {
                syncOptions.Rules.Add(new DeploymentSkipRule(rule.Name, rule.SkipAction, rule.ObjectName, rule.AbsolutePath, rule.XPath));
            }

            //Deploy
            _Log.Debug(Verbosity.Normal, "Deploying Website...");
            _Log.Debug(Verbosity.Normal, String.Format("-siteName '{0}'", settings.SiteName));
            _Log.Debug(Verbosity.Normal, String.Format("-destination '{0}'", settings.PublishUrl));
            _Log.Debug(Verbosity.Normal, String.Format("-source '{0}'", sourcePath.FullPath));
            _Log.Debug("");

            using (var deploymentObject = DeploymentManager.CreateObject(sourceProvider, sourcePath.FullPath, sourceOptions))
            {
                foreach (var kv in settings.Parameters)
                {
                    if (deploymentObject.SyncParameters.Contains(kv.Key))
                    {
                        deploymentObject.SyncParameters[kv.Key].Value = kv.Value;
                    }
                    else
                    {
                        deploymentObject.SyncParameters.Add(new DeploymentSyncParameter(kv.Key, kv.Key, "", "")
                        {
                            Value = kv.Value
                        });
                    }
                }

                return(deploymentObject.SyncTo(destProvider, destPath, destOptions, syncOptions));
            }
        }
Ejemplo n.º 24
0
 public static DeploymentChangeSummary DeployWebsite(this ICakeContext context, DeploySettings settings)
 {
     return new WebDeployManager(context.Environment, context.Log).Deploy(settings);
 }