public override DeploymentObjectProvider AddChild(DeploymentObject source, int position, bool whatIf) { if (source.Name == "dirPath") return CreateDirPathProvider(); return null; }
public override void Update(DeploymentSyncContext syncContext, DeploymentObject destinationObject, ref DeploymentObject sourceObject, ref bool proceed) { if (IsServiceStateProvider(destinationObject)) { syncContext.SourceObject.BaseContext.RaiseEvent(new WindowsServiceTraceEvent( Resources.SkipServiceStateEvent, "Update", destinationObject.AbsolutePath)); proceed = false; } }
bool IsServiceStateProvider(DeploymentObject destinationObject) { if (destinationObject.ProviderName != "filePath") return false; string extension = Path.GetExtension(destinationObject.AbsolutePath); return string.Equals(extension, ".InstallLog", StringComparison.InvariantCultureIgnoreCase) || string.Equals(extension, ".InstallState", StringComparison.InvariantCultureIgnoreCase); }
public override void Add(DeploymentObject source, bool whatIf) { foreach (DeploymentObject deploymentObject in source.GetChildren()) { if (deploymentObject.Name == "dirPath") { _isDirectory = true; break; } } }
public override DeploymentObjectProvider AddChild(DeploymentObject source, int position, bool whatIf) { string physicalPath = ServicePathHelper.GetPhysicalPath(Path); if (source.Name == "contentPathLib") return CreateProvider("contentPathLib", Path, "ContentPathLib"); if (source.Name == "dirPath" && !_isDirectory) throw new DeploymentException(Resources.FileAlreadyExists, physicalPath); throw new DeploymentException(Resources.DirectoryAlreadyExists, physicalPath); }
public override void Add(DeploymentObject source, bool whatIf) { ServicePathHelper.GetPhysicalPath(providerContext.Path); foreach(var deploymentObject in source.GetChildren()) { if (deploymentObject.Name == "dirPath") { _isDirectory = true; break; } } }
public override void Update(DeploymentObject source, bool whatIf) { this.Add(source, whatIf); }
/// <summary> /// Add a connection string parameter to the deployment. /// </summary> /// <param name="deployment">The deployment object.</param> /// <param name="name">Connection string name.</param> /// <param name="value">Connection string value.</param> private void AddConnectionString(DeploymentObject deployment, string name, string value) { var deploymentSyncParameterName = string.Format("Connection String {0} Parameter", name); DeploymentSyncParameter connectionStringParameter = new DeploymentSyncParameter( deploymentSyncParameterName, deploymentSyncParameterName, value, null); DeploymentSyncParameterEntry connectionStringEntry = new DeploymentSyncParameterEntry( DeploymentSyncParameterEntryKind.XmlFile, @"\\web.config$", string.Format(@"//connectionStrings/add[@name='{0}']/@connectionString", name), null); connectionStringParameter.Add(connectionStringEntry); deployment.SyncParameters.Add(connectionStringParameter); }
/// <summary> /// Replace all the connection strings in the deployment. /// </summary> /// <param name="deployment">The deployment object.</param> /// <param name="connectionStrings">Connection strings.</param> private void ReplaceConnectionStrings(DeploymentObject deployment, Hashtable connectionStrings) { if (connectionStrings != null) { foreach (var key in connectionStrings.Keys) { AddConnectionString(deployment, key.ToString(), connectionStrings[key].ToString()); } } }
public List <DeploymentParameter> GetApplicationParameters(string productId) { string packageFile = GetApplicationPackagePath(productId); // if (String.IsNullOrEmpty(packageFile)) { return(null); } // List <DeploymentParameter> appParams = new List <DeploymentParameter>(); // DeploymentObject iisApplication = null; // try { iisApplication = DeploymentManager.CreateObject(DeploymentWellKnownProvider.Package, packageFile); // foreach (DeploymentSyncParameter parameter in iisApplication.SyncParameters) { DeploymentParameter p = new DeploymentParameter { Name = parameter.Name, FriendlyName = !String.IsNullOrEmpty(parameter.FriendlyName) ? parameter.FriendlyName : parameter.Name, Value = parameter.Value, DefaultValue = parameter.DefaultValue, Description = parameter.Description, ValidationKind = (DeploymentParameterValidationKind)parameter.Validation.Kind, ValidationString = parameter.Validation.ValidationString, WellKnownTags = (DeploymentParameterWellKnownTag)parameter.WellKnownTags }; // add to the list appParams.Add(p); // fix tags for parameters with hard-coded names if (wellKnownParameters.ContainsKey(p.Name)) { p.WellKnownTags |= wellKnownParameters[p.Name]; } } } catch (Exception ex) { // Log an error Log.WriteError( String.Format("Could not read deployment parameters from '{0}' package.", packageFile), ex); // throw; } finally { if (iisApplication != null) { iisApplication.Dispose(); } } // return(appParams); }
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); }
/// <summary> /// Web Deploy does not parameterize or run any rules (parameterization is one of the rules) when deletion is used. /// So to work around that deletecontent does a simple publish of empty content to the server and gets the IP that is hosting the volume. /// After finding the IP the deletion is called on that content path. This will effectively delete "\\someipaddress\volumename\guidfolder" /// </summary> /// <param name="unusedState">This is not used. This is the signature for the waitcallback expected by threadpool.</param> private void DeleteContent(object unusedState) { Operation operation = null; try { lock (_pendingDeleteOperations) { operation = _pendingDeleteOperations.Dequeue(); } if (operation == null) { PublishHelper.LogVerboseInformation("DeleteContent: Thread {0} did not find any operations to process", Thread.CurrentThread.ManagedThreadId); return; } operation.ThreadID = Thread.CurrentThread.ManagedThreadId; operation.Status = PublishOperationStatus.Error; DeploymentBaseOptions srcBaseOptions = new DeploymentBaseOptions(); AntaresEventProvider.EventWritePublishFailOverServiceProgressInformation(operation.ThreadID, operation.SiteName); string remoteIP = string.Empty; bool errorOcurred = false; using (DeploymentObject depObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.ContentPath, Path.GetTempPath(), srcBaseOptions)) { try { DeploymentBaseOptions destBaseOptions = new DeploymentBaseOptions(); destBaseOptions.ComputerName = operation.PublishUrl; string modifiedPhysicalPath = operation.PhysicalPath; string ipDefaultValue = GetFileServerIP(ref modifiedPhysicalPath); var queryServerIPParameter = new DeploymentSyncParameter( QueryServerIPParameterName, QueryServerIPParameterDescription, string.Empty, DeploymentWellKnownTag.PhysicalPath.ToString()); var queryServerIPParameterEntry = new DeploymentSyncParameterEntry( DeploymentSyncParameterEntryKind.ProviderPath, DeploymentWellKnownProvider.ContentPath.ToString(), string.Empty, string.Empty); queryServerIPParameter.Add(queryServerIPParameterEntry); var contentPathParameter = new DeploymentSyncParameter( ContentPathParameterName, ContentPathParameterDescription, modifiedPhysicalPath, DeploymentWellKnownTag.PhysicalPath.ToString()); var contentParamEntry = new DeploymentSyncParameterEntry( DeploymentSyncParameterEntryKind.ProviderPath, DeploymentWellKnownProvider.ContentPath.ToString(), string.Empty, string.Empty); contentPathParameter.Add(contentParamEntry); depObj.SyncParameters.Add(contentPathParameter); depObj.SyncParameters.Add(queryServerIPParameter); destBaseOptions.UserName = operation.AdminCredential.UserName; destBaseOptions.Password = operation.AdminCredential.Password; destBaseOptions.AuthenticationType = "basic"; depObj.SyncTo(destBaseOptions, new DeploymentSyncOptions()); } catch (Exception e) { bool unhandledException = false; // In cases where the site was deleted on the source before it was ever synced to the destination // mark as the destination invalid and set the status so that its never attempted again. if (e is DeploymentDetailedException && ((DeploymentDetailedException)e).ErrorCode == DeploymentErrorCode.ERROR_INVALID_PATH) { string[] messageArray = e.Message.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries); if (messageArray.Length > 0) { remoteIP = messageArray[0]; } else { errorOcurred = true; } } else if (e is DeploymentException) { errorOcurred = true; } else { // its not a deployment exception. This is an exception not handled by web deploy such as duplicate key exception. // This needs to be retried. unhandledException = true; errorOcurred = true; } if (errorOcurred) { AntaresEventProvider.EventWritePublishFailOverServiceFailedToPublishSite(operation.SiteName, e.ToString()); operation.Status = unhandledException ? PublishOperationStatus.Error : PublishOperationStatus.SourceOrDestinationInvalid; } } } if (!errorOcurred) { string[] pathParts = operation.PhysicalPath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries); string remotePath = string.Concat(@"\\", remoteIP, @"\", pathParts[1], @"\", pathParts[2]); using (DeploymentObject depObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.Auto, string.Empty, srcBaseOptions)) { try { DeploymentBaseOptions destBaseOptions = new DeploymentBaseOptions(); destBaseOptions.ComputerName = operation.PublishUrl; destBaseOptions.UserName = operation.AdminCredential.UserName; destBaseOptions.Password = operation.AdminCredential.Password; destBaseOptions.AuthenticationType = "basic"; destBaseOptions.Trace += new EventHandler <DeploymentTraceEventArgs>(WebDeployPublishTrace); destBaseOptions.TraceLevel = System.Diagnostics.TraceLevel.Verbose; var syncOptions = new DeploymentSyncOptions(); syncOptions.DeleteDestination = true; depObj.SyncTo(DeploymentWellKnownProvider.ContentPath, remotePath, destBaseOptions, syncOptions); operation.Status = PublishOperationStatus.Completed; AntaresEventProvider.EventWritePublishFailOverServicePublishComplete(operation.SiteName); } catch (Exception e) { var ex = e as DeploymentDetailedException; if (ex != null && ex.ErrorCode == DeploymentErrorCode.FileOrFolderNotFound) { operation.Status = PublishOperationStatus.SourceOrDestinationInvalid; } else { AntaresEventProvider.EventWritePublishFailOverServiceFailedToPublishSite(operation.SiteName, e.ToString()); } } } } } finally { lock (_completedOperations) { PublishHelper.LogVerboseInformation("DeleteContent: Thread {0} queuing completed operation for site: {1}", operation.ThreadID, operation.SiteName); _completedOperations.Enqueue(operation); } _continueEvent.Set(); PublishHelper.LogVerboseInformation("DeleteContent: Thread {0} exiting.", Thread.CurrentThread.ManagedThreadId); } }
public override string GetSummary(DeploymentObject deploymentObject) { return(deploymentObject.KeyAttribute.GetValue <string>()); }
private static void WriteXmlObject(DeploymentObject obj, XmlTextWriter writer) { writer.WriteStartElement(obj.Name); foreach (var attr in obj.Attributes) { writer.WriteAttributeString(attr.Name, attr.Value.Value as string); } foreach (var childObj in obj.GetChildren()) { WriteXmlObject(childObj, writer); } writer.WriteEndElement(); }
private static XmlDocument GetDeploymentObjectAsXmlDocument(DeploymentObject obj) { using (var sw = new StringWriter()) { using (var tw = new XmlTextWriter(sw)) { WriteXmlObject(obj, tw); } var doc = new XmlDocument(); doc.LoadXml(sw.ToString()); return doc; } }
public override void Update(DeploymentSyncContext syncContext, DeploymentObject destinationObject, ref DeploymentObject sourceObject, ref bool proceed) { StopService(syncContext); }
public override void Delete(DeploymentSyncContext syncContext, DeploymentObject destinationObject, DeploymentObject sourceParentObject, ref bool proceed) { if (IsServiceStateProvider(destinationObject)) { syncContext.SourceObject.BaseContext.RaiseEvent(new WindowsServiceTraceEvent( Resources.SkipServiceStateEvent, "Delete", destinationObject.AbsolutePath)); proceed = false; } }