private void Publish(object unusedState) { Operation operation = null; try { lock (_pendingPublishOperations) { operation = _pendingPublishOperations.Dequeue(); } if (operation == null) { PublishHelper.LogVerboseInformation("Publish: Thread {0} did not find any operations to process", Thread.CurrentThread.ManagedThreadId); return; } // This was not required earlier but now that every site will be synced twice for every incoming publish (Look at the postsync override in publishextender), // there are chances that same operation might get scheduled in concurrent threads which is not a supported web deploy scenario. bool canContinue = true; lock (_operationsInProgress) { if (_operationsInProgress.Contains(operation.SiteName)) { PublishHelper.LogVerboseInformation("Publish: An operation for {0} is already in progress. Thread {1} will mark it as not started to be scheduled later.", operation.SiteName, Thread.CurrentThread.ManagedThreadId); operation.Status = PublishOperationStatus.NotStarted; canContinue = false; } else { _operationsInProgress.Add(operation.SiteName); } } if (!canContinue) { lock (_completedOperations) { _completedOperations.Enqueue(operation); } return; } operation.ThreadID = Thread.CurrentThread.ManagedThreadId; operation.Status = PublishOperationStatus.Error; DeploymentBaseOptions srcBaseOptions = new DeploymentBaseOptions(); AntaresEventProvider.EventWritePublishFailOverServiceProgressInformation(operation.ThreadID, operation.SiteName); using (DeploymentObject depObj = DeploymentManager.CreateObject(DeploymentWellKnownProvider.Manifest, PublishHelper.GetPublishManifest(operation.PhysicalPath), srcBaseOptions)) { try { DeploymentBaseOptions destBaseOptions = new DeploymentBaseOptions(); destBaseOptions.ComputerName = operation.PublishUrl; string modifiedPhysicalPath = operation.PhysicalPath; string ipDefaultValue = GetFileServerIP(ref modifiedPhysicalPath); var fileServerIPParameter = new DeploymentSyncParameter( FileServerIPParameterName, FileServerIPParameterDescription, ipDefaultValue, string.Empty); var fileServerIPEntry = new DeploymentSyncParameterEntry( DeploymentSyncParameterEntryKind.ProviderPath, DeploymentWellKnownProvider.ContentPath.ToString(), string.Empty, string.Empty); fileServerIPParameter.Add(fileServerIPEntry); 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); var setAclParameter = new DeploymentSyncParameter( SetAclParameterName, SetAclParameterDescription, modifiedPhysicalPath, DeploymentWellKnownTag.SetAcl.ToString()); var setAclParamEntry = new DeploymentSyncParameterEntry( DeploymentSyncParameterEntryKind.ProviderPath, DeploymentWellKnownProvider.SetAcl.ToString(), string.Empty, string.Empty); setAclParameter.Add(setAclParamEntry); depObj.SyncParameters.Add(fileServerIPParameter); depObj.SyncParameters.Add(contentPathParameter); depObj.SyncParameters.Add(setAclParameter); 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; depObj.SyncTo(destBaseOptions, new DeploymentSyncOptions()); operation.Status = PublishOperationStatus.Completed; AntaresEventProvider.EventWritePublishFailOverServicePublishComplete(operation.SiteName); } catch (Exception e) { AntaresEventProvider.EventWritePublishFailOverServiceFailedToPublishSite(operation.SiteName, e.ToString()); } } } catch (Exception e) { if ((e is DeploymentDetailedException && ((DeploymentDetailedException)e).ErrorCode == DeploymentErrorCode.FileOrFolderNotFound) || e is WebHostingObjectNotFoundException) { operation.Status = PublishOperationStatus.SourceOrDestinationInvalid; } AntaresEventProvider.EventWritePublishFailOverServiceFailedToGetSourceSite(operation.SiteName, e.ToString()); } finally { lock (_completedOperations) { PublishHelper.LogVerboseInformation("Publish: Thread {0} qeuing completed operation for site: {1}", operation.ThreadID, operation.SiteName); _completedOperations.Enqueue(operation); } lock (_operationsInProgress) { _operationsInProgress.Remove(operation.SiteName); } _continueEvent.Set(); PublishHelper.LogVerboseInformation("Publish: Thread {0} exiting", Thread.CurrentThread.ManagedThreadId); } }