Example #1
0
        public static void InitializeDbProviderOptions()
        {
            var providers = new[] { "dbdacfx", "dbfullsql" };

            foreach (var provider in providers)
            {
                var providerOption = new DeploymentProviderOptions(provider);
                foreach (var providerSetting in providerOption.ProviderSettings)
                {
                    var setting = ConfigurationManager.AppSettings[providerSetting.Name];
                    if (!string.IsNullOrEmpty(setting))
                    {
                        try
                        {
                            providerSetting.Value = setting;
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.ToString());
                            TraceHelper.Tracer.WriteTrace(ex.ToString());
                        }
                    }
                }
            }
        }
Example #2
0
        public static void SyncDatabases(Profile src, Profile dest , string dbtype)
        {
            DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
            DeploymentBaseOptions destBaseOptions = new DeploymentBaseOptions();
            DeploymentBaseOptions sourceBaseOptions = new DeploymentBaseOptions();
            destBaseOptions.Trace += TraceEventHandler;
            sourceBaseOptions.Trace += TraceEventHandler;
            destBaseOptions.TraceLevel = TraceLevel.Verbose;
            sourceBaseOptions.TraceLevel = TraceLevel.Verbose;

            DeploymentProviderOptions destProviderOptions = null;

            DeploymentObject sourceObj = null;
            if (dbtype.Equals("mysql", StringComparison.InvariantCultureIgnoreCase))
            {
                destProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.DBMySql);
                destProviderOptions.Path = dest.mysqlConnectionstring;
               sourceObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.DBMySql, src.mysqlConnectionstring, sourceBaseOptions);

            }
            else if (dbtype.Equals("sql", StringComparison.InvariantCultureIgnoreCase))
            {
                destProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.DBFullSql);
                destProviderOptions.Path = dest.sqlazureconnectionstring;
                sourceObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.DBFullSql,src.sqlazureconnectionstring, sourceBaseOptions);
            }
            if (sourceObj != null)
            {

                sourceObj.SyncTo(destProviderOptions, destBaseOptions, syncOptions);

            }
        }
        public static void SyncWebApps(Profile src, Profile dest)
        {
            DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();

            DeploymentBaseOptions sourceBaseOptions = new DeploymentBaseOptions();

            sourceBaseOptions.ComputerName       = "https://" + src.publishUrl + "/msdeploy.axd";
            sourceBaseOptions.UserName           = src.userName;
            sourceBaseOptions.Password           = src.userPwd;
            sourceBaseOptions.AuthenticationType = "basic";

            sourceBaseOptions.Trace += TraceEventHandler;

            sourceBaseOptions.TraceLevel = TraceLevel.Verbose;

            DeploymentBaseOptions destBaseOptions = new DeploymentBaseOptions();

            destBaseOptions.ComputerName       = "https://" + dest.publishUrl + "/msdeploy.axd";
            destBaseOptions.UserName           = dest.userName;
            destBaseOptions.Password           = dest.userPwd;
            destBaseOptions.AuthenticationType = "basic";


            destBaseOptions.Trace += TraceEventHandler;

            destBaseOptions.TraceLevel = TraceLevel.Verbose;

            DeploymentProviderOptions destProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.ContentPath);

            destProviderOptions.Path = dest.sitename;
            DeploymentObject sourceObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, src.sitename, sourceBaseOptions);

            sourceObj.SyncTo(destProviderOptions, destBaseOptions, syncOptions);
        }
Example #4
0
        public static void SyncDatabases(Profile src, Profile dest, string dbtype)
        {
            DeploymentSyncOptions syncOptions       = new DeploymentSyncOptions();
            DeploymentBaseOptions destBaseOptions   = new DeploymentBaseOptions();
            DeploymentBaseOptions sourceBaseOptions = new DeploymentBaseOptions();

            destBaseOptions.Trace       += TraceEventHandler;
            sourceBaseOptions.Trace     += TraceEventHandler;
            destBaseOptions.TraceLevel   = TraceLevel.Verbose;
            sourceBaseOptions.TraceLevel = TraceLevel.Verbose;

            DeploymentProviderOptions destProviderOptions = null;

            DeploymentObject sourceObj = null;

            if (dbtype.Equals("mysql", StringComparison.InvariantCultureIgnoreCase))
            {
                destProviderOptions      = new DeploymentProviderOptions(DeploymentWellKnownProvider.DBMySql);
                destProviderOptions.Path = dest.mysqlConnectionstring;
                sourceObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.DBMySql, src.mysqlConnectionstring, sourceBaseOptions);
            }
            else if (dbtype.Equals("sql", StringComparison.InvariantCultureIgnoreCase))
            {
                destProviderOptions      = new DeploymentProviderOptions(DeploymentWellKnownProvider.DBFullSql);
                destProviderOptions.Path = dest.sqlazureconnectionstring;
                sourceObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.DBFullSql, src.sqlazureconnectionstring, sourceBaseOptions);
            }
            if (sourceObj != null)
            {
                sourceObj.SyncTo(destProviderOptions, destBaseOptions, syncOptions);
            }
        }
Example #5
0
 public override DeploymentProviderOptions GetWebDeployDestinationProviderOptions()
 {
     var destProviderOptions = new DeploymentProviderOptions("Auto");// { Path = DestinationPath };
     //DeploymentProviderSetting dontUseCmdExe;
     //if (destProviderOptions.ProviderSettings.TryGetValue("dontUseCommandExe", out dontUseCmdExe))
     //{
     //    dontUseCmdExe.Value = true;
     //}
     return destProviderOptions;
 }
        DeploymentObjectProvider CreateDirPathProvider()
        {
            var providerOptions = new DeploymentProviderOptions("dirPath");

            providerOptions.Path = ServicePathHelper.GetPhysicalPath(Path);

            DeploymentObjectProvider provider = CreateProvider(providerOptions, ObjectName + LibFolderName);

            return(provider);
        }
Example #7
0
        public override DeploymentProviderOptions GetWebDeployDestinationProviderOptions()
        {
            var destProviderOptions = new DeploymentProviderOptions("Auto");        // { Path = DestinationPath };

            //DeploymentProviderSetting dontUseCmdExe;
            //if (destProviderOptions.ProviderSettings.TryGetValue("dontUseCommandExe", out dontUseCmdExe))
            //{
            //    dontUseCmdExe.Value = true;
            //}
            return(destProviderOptions);
        }
        // This method uses msdeploy APIs to sync a script to a database using dbMySql provider
        public void SyncScriptToMySqlDatabase(string sourceMySqlScriptFilePath, string destinationMySqlConnectionStringPath)
        {
            DeploymentProviderOptions sourceProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.DBMySql);

            sourceProviderOptions.Path = sourceMySqlScriptFilePath;

            using (DeploymentObject sourceObject = DeploymentManager.CreateObject(sourceProviderOptions, new DeploymentBaseOptions()))
            {
                DeploymentProviderOptions destProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.DBMySql);
                destProviderOptions.Path = destinationMySqlConnectionStringPath;

                sourceObject.SyncTo(destProviderOptions, new DeploymentBaseOptions(), new DeploymentSyncOptions());
            }
        }
Example #9
0
        public override DeploymentProviderOptions GetWebDeploySourceProviderOptions()
        {
            var sourceProviderOptions = new DeploymentProviderOptions(Name) { Path = SourcePath };

            DeploymentProviderSetting waitAttempts;
            DeploymentProviderSetting waitInterval;

            if (sourceProviderOptions.ProviderSettings.TryGetValue("waitAttempts", out waitAttempts))
            {
                waitAttempts.Value = 10;
            }
            if (sourceProviderOptions.ProviderSettings.TryGetValue("waitInterval", out waitInterval))
            {
                waitInterval.Value = 5000;
            }
            return sourceProviderOptions;
        }
Example #10
0
        public override DeploymentProviderOptions GetWebDeployDestinationProviderOptions()
        {
            var destProviderOptions = new DeploymentProviderOptions(Name) { Path = DestinationPath };

            DeploymentProviderSetting userSetting;
            if (destProviderOptions.ProviderSettings.TryGetValue("setAclUser", out userSetting))
            {
                userSetting.Value = User;
            }

            DeploymentProviderSetting permissionSetting;
            if (destProviderOptions.ProviderSettings.TryGetValue("setAclAccess", out permissionSetting))
            {
                permissionSetting.Value = Permissions.ToString();
            }
            return destProviderOptions;
        }
Example #11
0
        public override DeploymentProviderOptions GetWebDeployDestinationProviderOptions()
        {
            var destProviderOptions = new DeploymentProviderOptions(Name)
            {
                Path = DestinationPath
            };

            DeploymentProviderSetting waitAttempts;
            DeploymentProviderSetting waitInterval;

            if (destProviderOptions.ProviderSettings.TryGetValue("waitAttempts", out waitAttempts))
            {
                waitAttempts.Value = 10;
            }
            if (destProviderOptions.ProviderSettings.TryGetValue("waitInterval", out waitInterval))
            {
                waitInterval.Value = 5000;
            }
            return(destProviderOptions);
        }
Example #12
0
        public override DeploymentProviderOptions GetWebDeployDestinationProviderOptions()
        {
            var destProviderOptions = new DeploymentProviderOptions(Name)
            {
                Path = DestinationPath
            };

            DeploymentProviderSetting userSetting;

            if (destProviderOptions.ProviderSettings.TryGetValue("setAclUser", out userSetting))
            {
                userSetting.Value = User;
            }

            DeploymentProviderSetting permissionSetting;

            if (destProviderOptions.ProviderSettings.TryGetValue("setAclAccess", out permissionSetting))
            {
                permissionSetting.Value = Permissions.ToString();
            }
            return(destProviderOptions);
        }
Example #13
0
        public bool PublishDatabase(DeploymentBaseOptions sourceBaseOptions, DeploymentBaseOptions destBaseOptions, string provider, bool logException)
        {
            bool publishSucceeded = true;

            this.LogTrace("Starting db publish for {0}", _localSite.SiteName);
            try
            {
                var providerOption = new DeploymentProviderOptions(provider);
                foreach (var providerSetting in providerOption.ProviderSettings)
                {
                    var setting = ConfigurationManager.AppSettings[providerSetting.Name];
                    if (!string.IsNullOrEmpty(setting))
                    {
                        try
                        {
                            providerSetting.Value = setting;
                        }
                        catch (Exception ex)
                        {
                            this.LogTrace("Error trying to set value: {0} for setting: {1}, {2}", setting, providerSetting.Name, ex.ToString());
                        }
                    }
                }

                string path = _localSite.Databases[0].DBConnectionString;
                if (path.Contains("|DataDirectory|"))
                {
                    // TODO: is there a better way to do this? Can we lookup |DataDirectory|
                    path = path.Replace("|DataDirectory|", this._localSite.PhysicalPath + @"\App_Data\");
                }

                providerOption.Path = path;
                RemoteSystemInfo remoteSystemInfo = null;
                if (RemoteSystemInfos.Servers.Any() && UseTrustedConnection(_localSite.Databases[0].DBConnectionString))
                {
                    remoteSystemInfo = RemoteSystemInfos.Servers[_localSite.ServerName];
                }

                using (Impersonator.ImpersonateUser(remoteSystemInfo))
                {
                    using (var sourceObject =
                               DeploymentManager.CreateObject(providerOption,
                                                              sourceBaseOptions))
                    {
                        LogTrace("Starting DB Sync for: {0} using {1}",
                                 (string)_localSite.Databases[0].DbConnectionStringBuilder["Initial Catalog"], provider);
                        this.LogTrace("Publishing database as: {0}", destBaseOptions.UserName);

                        try
                        {
                            sourceObject.SyncTo(provider, _publishSettings.SqlDBConnectionString.ConnectionString,
                                                destBaseOptions, new DeploymentSyncOptions());
                            this.LogTrace("DB Synced successfully");
                            Helper.UpdateStatus(_localSite.SiteName, _localSite.ServerName, true);
                        }
                        catch (Exception ex)
                        {
                            if (logException)
                            {
                                LogTrace("Error starting publish for db: {0}",
                                         (string)_localSite.Databases[0].DbConnectionStringBuilder["Initial Catalog"]);
                                this.LogTrace(ex.ToString());
                            }

                            publishSucceeded = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (logException)
                {
                    LogTrace("Error syncing db: {0}",
                             (string)_localSite.Databases[0].DbConnectionStringBuilder["Initial Catalog"]);
                    LogTrace(ex.ToString());
                }

                publishSucceeded = false;
            }

            return(publishSucceeded);
        }
        /// <summary>
        /// Publish a WebDeploy package zip file to a web site.
        /// </summary>
        /// <param name="websiteName">The name of the web site.</param>
        /// <param name="slot">The name of the slot.</param>
        /// <param name="package">The WebDeploy package zip file.</param>
        /// <param name="connectionStrings">The connection strings to overwrite the ones in the Web.config file.</param>
        /// <param name="skipAppData">Skip app data</param>
        /// <param name="doNotDelete">Do not delete files at destination</param>
        private void PublishWebProjectFromPackageFile(string websiteName, string slot, string package, Hashtable connectionStrings, bool skipAppData, bool doNotDelete)
        {
            DeploymentBaseOptions remoteBaseOptions = CreateRemoteDeploymentBaseOptions(websiteName, slot);
            DeploymentBaseOptions localBaseOptions = new DeploymentBaseOptions();

            SetWebDeployToSkipAppData(skipAppData, localBaseOptions, remoteBaseOptions);

            DeploymentProviderOptions remoteProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.Auto);

            using (var deployment = DeploymentManager.CreateObject(DeploymentWellKnownProvider.Package, package, localBaseOptions))
            {
                DeploymentSyncParameter providerPathParameter = new DeploymentSyncParameter(
                    "Provider Path Parameter",
                    "Provider Path Parameter",
                    SetWebsiteNameForWebDeploy(websiteName, slot),
                    null);
                DeploymentSyncParameterEntry iisAppEntry = new DeploymentSyncParameterEntry(
                    DeploymentSyncParameterEntryKind.ProviderPath,
                    DeploymentWellKnownProvider.IisApp.ToString(),
                    ".*",
                    null);
                DeploymentSyncParameterEntry setAclEntry = new DeploymentSyncParameterEntry(
                    DeploymentSyncParameterEntryKind.ProviderPath,
                    DeploymentWellKnownProvider.SetAcl.ToString(),
                    ".*",
                    null);
                providerPathParameter.Add(iisAppEntry);
                providerPathParameter.Add(setAclEntry);
                deployment.SyncParameters.Add(providerPathParameter);

                // Replace the connection strings in Web.config with the ones user specifies from the cmdlet.
                ReplaceConnectionStrings(deployment, connectionStrings);

                DeploymentSyncOptions syncOptions = new DeploymentSyncOptions
                {
                    DoNotDelete = doNotDelete
                };

                deployment.SyncTo(remoteProviderOptions, remoteBaseOptions, syncOptions);
            }
        }
        public string InstallApplication(string productId, List <DeploymentParameter> updatedValues)
        {
            string packageFile     = GetApplicationPackagePath(productId);
            string applicationPath = null;

            //
            if (String.IsNullOrEmpty(packageFile))
            {
                return(null);
            }
            //
            Log.WriteInfo("WebApp Package Path: {0}", packageFile);
            //
            if (!File.Exists(packageFile))
            {
                throw new Exception(GalleryErrorCodes.FILE_NOT_FOUND);
            }
            //
            // Setup source deployment options
            DeploymentBaseOptions sourceOptions = new DeploymentBaseOptions();

            // Add tracing capabilities
            sourceOptions.Trace     += new EventHandler <DeploymentTraceEventArgs>(sourceOptions_Trace);
            sourceOptions.TraceLevel = TraceLevel.Verbose;
            // Setup deployment provider
            DeploymentProviderOptions providerOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.Package);

            // Set the package path location
            providerOptions.Path = packageFile;
            // Prepare the package deployment procedure
            using (DeploymentObject iisApplication = DeploymentManager.CreateObject(providerOptions, sourceOptions))
            {
                // Setup destination deployment options
                DeploymentBaseOptions destinationOptions = new DeploymentBaseOptions();
                // Add tracing capabilities
                destinationOptions.Trace     += new EventHandler <DeploymentTraceEventArgs>(sourceOptions_Trace);
                destinationOptions.TraceLevel = TraceLevel.Verbose;

                // MSDEPLOY TEAM COMMENTS: For each parameter that was specified in the UI, set its value
                foreach (DeploymentParameter updatedValue in updatedValues)
                {
                    DeploymentSyncParameter parameter = null;
                    // Assert whether a parameter assigned a value
                    Trace.Assert(!String.IsNullOrEmpty(updatedValue.Name));
                    if (!iisApplication.SyncParameters.TryGetValue(updatedValue.Name, out parameter))
                    {
                        throw new InvalidOperationException("Could not find a parameter with the name " + updatedValue.Name);
                    }
                    parameter.Value = updatedValue.Value;
                }

                // Find database parameter received in updated parameters arrays
                DeploymentParameter dbNameParam = Array.Find <DeploymentParameter>(updatedValues.ToArray(),
                                                                                   p => MatchParameterByNames(p, DeploymentParameter.DATABASE_NAME_PARAMS) ||
                                                                                   MatchParameterTag(p, DeploymentParameter.DB_NAME_PARAM_TAG));

                // MSDEPLOY TEAM COMMENTS: There may be a bunch of hidden parameters that never got set.
                // set these to their default values (which will probably be calculated based on the other
                // parameters that were set).
                foreach (DeploymentSyncParameter parameter in iisApplication.SyncParameters)
                {
                    // Ensure all syncronization parameters are set
                    if (parameter.Value == null)
                    {
                        throw new InvalidOperationException("Parameter '" + parameter.Name + "' value was not set. This indicates an issue with the package itself. Contact your system administrator.");
                    }
                    // Detect application path parameter in order to return it to the client
                    if (MatchParameterTag(parameter, DeploymentParameter.IISAPP_PARAM_TAG))
                    {
                        applicationPath = parameter.Value;
                        continue;
                    }
                    //
                    if (dbNameParam == null)
                    {
                        continue;
                    }

                    //
                    if (!MatchParameterTag(parameter, DeploymentParameter.DB_NAME_PARAM_TAG) &&
                        !MatchParameterByNames(parameter, DeploymentParameter.DATABASE_NAME_PARAMS))
                    {
                        continue;
                    }

                    // Application supports both databases MySQL & MSSQL - one of them should be skipped
                    if (MatchParameterTag(parameter, DeploymentParameter.MYSQL_PARAM_TAG) &&
                        MatchParameterTag(parameter, DeploymentParameter.SQL_PARAM_TAG))
                    {
                        if (dbNameParam.Tags.ToLowerInvariant().StartsWith("mssql"))
                        {
                            sourceOptions.SkipDirectives.Add(SkipMySQL);
                        }
                        // Skip MySQL database scripts
                        else if (dbNameParam.Tags.ToLowerInvariant().StartsWith("mysql"))
                        {
                            sourceOptions.SkipDirectives.Add(SkipMsSQL);
                        }
                    }
                }
                // Setup deployment options
                DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
                // Add tracing capabilities
                //syncOptions..Action += new EventHandler<DeploymentActionEventArgs>(syncOptions_Action);
                // Issue a syncronization signal between the parties
                iisApplication.SyncTo(DeploymentWellKnownProvider.Auto, applicationPath, destinationOptions, syncOptions);
                //
                Log.WriteInfo("{0}: {1}", DeploymentParameter.APPICATION_PATH_PARAM, applicationPath);
                //
            }
            //
            return(applicationPath);
        }
        public string InstallApplication(string productId, List <DeploymentParameter> updatedParameters)
        {
            string packageFile     = GetApplicationPackagePath(productId);
            string applicationPath = null;

            if (String.IsNullOrEmpty(packageFile))
            {
                return(null);
            }

            Log.WriteInfo("WebApp Package Path: {0}", packageFile);

            if (!File.Exists(packageFile))
            {
                throw new Exception(GalleryErrors.PackageFileNotFound);
            }

            // Setup source deployment options
            DeploymentBaseOptions sourceOptions = new DeploymentBaseOptions();

            // Add tracing capabilities
            sourceOptions.Trace     += new EventHandler <DeploymentTraceEventArgs>(sourceOptions_Trace);
            sourceOptions.TraceLevel = TraceLevel.Verbose;

            // Setup deployment provider
            DeploymentProviderOptions providerOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.Package);

            // Set the package path location
            providerOptions.Path = packageFile;

            // Prepare the package deployment procedure
            using (DeploymentObject iisApplication = DeploymentManager.CreateObject(providerOptions, sourceOptions))
            {
                // Setup destination deployment options
                DeploymentBaseOptions destinationOptions = new DeploymentBaseOptions();
                // Add tracing capabilities
                destinationOptions.Trace     += new EventHandler <DeploymentTraceEventArgs>(sourceOptions_Trace);
                destinationOptions.TraceLevel = TraceLevel.Verbose;

                // MSDEPLOY TEAM COMMENTS: For each parameter that was specified in the UI, set its value
                DeploymentParameterWellKnownTag databaseEngine = DeploymentParameterWellKnownTag.None;

                int i = 0;
                while (i < iisApplication.SyncParameters.Count)
                {
                    // try to find parameter in updated parameters
                    string name = iisApplication.SyncParameters[i].Name;
                    DeploymentParameter updatedParameter = updatedParameters.Find(p => { return(String.Compare(p.Name, name) == 0); });

                    if (updatedParameter != null)
                    {
                        // parameter found
                        // update its value
                        iisApplication.SyncParameters[i].Value = updatedParameter.Value;
                        i++; // advance to the next parameter

                        // check for selected database engine
                        if ((updatedParameter.WellKnownTags & DeploymentParameterWellKnownTag.MySql) == DeploymentParameterWellKnownTag.MySql)
                        {
                            databaseEngine = DeploymentParameterWellKnownTag.MySql;
                        }
                        else if ((updatedParameter.WellKnownTags & DeploymentParameterWellKnownTag.Sql) == DeploymentParameterWellKnownTag.Sql)
                        {
                            databaseEngine = DeploymentParameterWellKnownTag.Sql;
                        }

                        // get application path
                        if ((updatedParameter.WellKnownTags & DeploymentParameterWellKnownTag.IisApp) == DeploymentParameterWellKnownTag.IisApp)
                        {
                            applicationPath = updatedParameter.Value;
                        }
                    }
                    else
                    {
                        // parameter not found
                        // delete it
                        iisApplication.SyncParameters.Remove(name);
                    }
                }


                // Skip SQL Server database scripts if not SQL Server was selected
                if (databaseEngine != DeploymentParameterWellKnownTag.Sql)
                {
                    sourceOptions.SkipDirectives.Add(SkipMsSQL);
                }

                // Skip MySQL database scripts if not MySQL was selected
                if (databaseEngine != DeploymentParameterWellKnownTag.MySql)
                {
                    sourceOptions.SkipDirectives.Add(SkipMySQL);
                }

                // Setup deployment options
                DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
                // Add tracing capabilities
                //syncOptions..Action += new EventHandler<DeploymentActionEventArgs>(syncOptions_Action);
                // Issue a syncronization signal between the parties
                iisApplication.SyncTo(DeploymentWellKnownProvider.Auto, applicationPath, destinationOptions, syncOptions);
                //
                Log.WriteInfo("{0}: {1}", "Application path", applicationPath);
                //
            }
            //
            return(applicationPath);
        }
		public string InstallApplication(string productId, List<DeploymentParameter> updatedParameters)
		{
			string packageFile = GetApplicationPackagePath(productId);
			string applicationPath = null;
			
			if (String.IsNullOrEmpty(packageFile))
				return null;
			
			Log.WriteInfo("WebApp Package Path: {0}", packageFile);
			
			if (!File.Exists(packageFile))
                throw new Exception(GalleryErrors.PackageFileNotFound);
			
			// Setup source deployment options
			DeploymentBaseOptions sourceOptions = new DeploymentBaseOptions();

			// Add tracing capabilities
			sourceOptions.Trace += new EventHandler<DeploymentTraceEventArgs>(sourceOptions_Trace);
			sourceOptions.TraceLevel = TraceLevel.Verbose;

			// Setup deployment provider
			DeploymentProviderOptions providerOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.Package);

			// Set the package path location
			providerOptions.Path = packageFile;

			// Prepare the package deployment procedure
			using (DeploymentObject iisApplication = DeploymentManager.CreateObject(providerOptions, sourceOptions))
			{
				// Setup destination deployment options
				DeploymentBaseOptions destinationOptions = new DeploymentBaseOptions();
				// Add tracing capabilities
				destinationOptions.Trace += new EventHandler<DeploymentTraceEventArgs>(sourceOptions_Trace);
				destinationOptions.TraceLevel = TraceLevel.Verbose;

				// MSDEPLOY TEAM COMMENTS: For each parameter that was specified in the UI, set its value
                DeploymentParameterWellKnownTag databaseEngine = DeploymentParameterWellKnownTag.None;

                int i = 0;
                while(i < iisApplication.SyncParameters.Count)
                {
                    // try to find parameter in updated parameters
                    string name = iisApplication.SyncParameters[i].Name;
                    DeploymentParameter updatedParameter = updatedParameters.Find( p => { return String.Compare(p.Name, name) == 0; });

                    if(updatedParameter != null)
                    {
                        // parameter found
                        // update its value
                        iisApplication.SyncParameters[i].Value = updatedParameter.Value;
                        i++; // advance to the next parameter

                        // check for selected database engine
                        if ((updatedParameter.WellKnownTags & DeploymentParameterWellKnownTag.MySql) == DeploymentParameterWellKnownTag.MySql)
                            databaseEngine = DeploymentParameterWellKnownTag.MySql;
                        else if ((updatedParameter.WellKnownTags & DeploymentParameterWellKnownTag.Sql) == DeploymentParameterWellKnownTag.Sql)
                            databaseEngine = DeploymentParameterWellKnownTag.Sql;
                    
                        // get application path
                        if ((updatedParameter.WellKnownTags & DeploymentParameterWellKnownTag.IisApp) == DeploymentParameterWellKnownTag.IisApp)
                            applicationPath = updatedParameter.Value;
                    }
                    else
                    {
                        // parameter not found
                        // delete it
                        iisApplication.SyncParameters.Remove(name);
                    }
                }


                // Skip SQL Server database scripts if not SQL Server was selected
                if (databaseEngine != DeploymentParameterWellKnownTag.Sql)
                    sourceOptions.SkipDirectives.Add(SkipMsSQL);

                // Skip MySQL database scripts if not MySQL was selected
                if (databaseEngine != DeploymentParameterWellKnownTag.MySql)
                    sourceOptions.SkipDirectives.Add(SkipMySQL);

				// Setup deployment options
				DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();
				// Add tracing capabilities
				//syncOptions..Action += new EventHandler<DeploymentActionEventArgs>(syncOptions_Action);
				// Issue a syncronization signal between the parties
				iisApplication.SyncTo(DeploymentWellKnownProvider.Auto, applicationPath, destinationOptions, syncOptions);
				//
				Log.WriteInfo("{0}: {1}", "Application path", applicationPath);
				//
			}
			//
			return applicationPath;
		}
        public bool PublishDatabase(DeploymentBaseOptions sourceBaseOptions, DeploymentBaseOptions destBaseOptions, string provider, bool logException)
        {
            bool publishSucceeded = true;
            this.LogTrace("Starting db publish for {0}", _localSite.SiteName);
            try
            {
                var providerOption = new DeploymentProviderOptions(provider);
                foreach (var providerSetting in providerOption.ProviderSettings)
                {
                    var setting = ConfigurationManager.AppSettings[providerSetting.Name];
                    if (!string.IsNullOrEmpty(setting))
                    {
                        try
                        {
                            providerSetting.Value = setting;
                        }
                        catch (Exception ex)
                        {
                            this.LogTrace("Error trying to set value: {0} for setting: {1}, {2}", setting, providerSetting.Name, ex.ToString());
                        }
                    }
                }

                string path = _localSite.Databases[0].DBConnectionString;
                if (path.Contains("|DataDirectory|"))
                {
                    // TODO: is there a better way to do this? Can we lookup |DataDirectory|
                    path = path.Replace("|DataDirectory|", this._localSite.PhysicalPath + @"\App_Data\");
                }

                providerOption.Path = path;
                RemoteSystemInfo remoteSystemInfo = null;
                if (RemoteSystemInfos.Servers.Any() && UseTrustedConnection(_localSite.Databases[0].DBConnectionString))
                {
                    remoteSystemInfo = RemoteSystemInfos.Servers[_localSite.ServerName];
                }

                using (Impersonator.ImpersonateUser(remoteSystemInfo))
                {
                    using (var sourceObject =
                        DeploymentManager.CreateObject(providerOption,
                            sourceBaseOptions))
                    {
                        LogTrace("Starting DB Sync for: {0} using {1}",
                            (string)_localSite.Databases[0].DbConnectionStringBuilder["Initial Catalog"], provider);
                        this.LogTrace("Publishing database as: {0}", destBaseOptions.UserName);

                        try
                        {
                            sourceObject.SyncTo(provider, _publishSettings.SqlDBConnectionString.ConnectionString,
                                destBaseOptions, new DeploymentSyncOptions());
                            this.LogTrace("DB Synced successfully");
                            Helper.UpdateStatus(_localSite.SiteName, _localSite.ServerName, true);
                        }
                        catch (Exception ex)
                        {
                            if (logException)
                            {
                                LogTrace("Error starting publish for db: {0}",
                                            (string)_localSite.Databases[0].DbConnectionStringBuilder["Initial Catalog"]);
                                this.LogTrace(ex.ToString());
                            }

                            publishSucceeded = false;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                if (logException)
                {
                    LogTrace("Error syncing db: {0}",
                                    (string)_localSite.Databases[0].DbConnectionStringBuilder["Initial Catalog"]);
                    LogTrace(ex.ToString());
                }

                publishSucceeded = false;
            }

            return publishSucceeded;
        }
 public static void InitializeDbProviderOptions()
 {
     var providers = new[] { "dbdacfx", "dbfullsql" };
     foreach (var provider in providers)
     {
         var providerOption = new DeploymentProviderOptions(provider);
         foreach (var providerSetting in providerOption.ProviderSettings)
         {
             var setting = ConfigurationManager.AppSettings[providerSetting.Name];
             if (!string.IsNullOrEmpty(setting))
             {
                 try
                 {
                     providerSetting.Value = setting;
                 }
                 catch (Exception ex)
                 {
                     MessageBox.Show(ex.ToString());
                     TraceHelper.Tracer.WriteTrace(ex.ToString());
                 }
             }
         }
     }
 }
        DeploymentObjectProvider CreateDirPathProvider()
        {
            var providerOptions = new DeploymentProviderOptions("dirPath");
            providerOptions.Path = ServicePathHelper.GetPhysicalPath(Path);

            DeploymentObjectProvider provider = CreateProvider(providerOptions, ObjectName + LibFolderName);
            return provider;
        }
Example #21
0
        public static void SyncWebApps(Profile src, Profile dest)
        {
            DeploymentSyncOptions syncOptions = new DeploymentSyncOptions();

            DeploymentBaseOptions sourceBaseOptions = new DeploymentBaseOptions();
            sourceBaseOptions.ComputerName = "https://" + src.publishUrl + "/msdeploy.axd";
            sourceBaseOptions.UserName = src.userName;
            sourceBaseOptions.Password = src.userPwd;
            sourceBaseOptions.AuthenticationType = "basic";

            sourceBaseOptions.Trace += TraceEventHandler;

            sourceBaseOptions.TraceLevel = TraceLevel.Verbose;

            DeploymentBaseOptions destBaseOptions = new DeploymentBaseOptions();
            destBaseOptions.ComputerName = "https://"+dest.publishUrl+"/msdeploy.axd";
            destBaseOptions.UserName = dest.userName;
            destBaseOptions.Password = dest.userPwd;
            destBaseOptions.AuthenticationType = "basic";

            destBaseOptions.Trace += TraceEventHandler;

            destBaseOptions.TraceLevel = TraceLevel.Verbose;

            DeploymentProviderOptions destProviderOptions = new DeploymentProviderOptions(DeploymentWellKnownProvider.ContentPath);
            destProviderOptions.Path = dest.sitename;
            DeploymentObject sourceObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, src.sitename,sourceBaseOptions);
            sourceObj.SyncTo(destProviderOptions, destBaseOptions, syncOptions);
        }