/// <summary> /// Applies the specified transformation map against the input document. /// </summary> /// <param name="transformName">Either partial or fully qualified name of the transformation map.</param> /// <param name="input">The input document that needs to be transformed.</param> /// <returns>The results from transformation.</returns> public XDocument ApplyTransform(string transformName, XDocument input) { Guard.ArgumentNotNull(this.roleConfigExtension, "roleConfigExtension"); Guard.ArgumentNotNullOrEmptyString(transformName, "transformName"); Guard.ArgumentNotNull(input, "input"); Guard.ArgumentNotNull(input.Root, "input.Root"); var callToken = TraceManager.WorkerRoleComponent.TraceIn(transformName, input.Root.Name); try { ServiceBusEndpointInfo sbEndpointInfo = this.roleConfigExtension.GetServiceBusEndpoint(WellKnownEndpointName.ScalableTransformService); if (sbEndpointInfo != null) { using (ReliableServiceBusClient <IScalableTransformationServiceChannel> transform = new ReliableServiceBusClient <IScalableTransformationServiceChannel>(sbEndpointInfo, this.roleConfigExtension.CommunicationRetryPolicy)) using (MemoryStream dataStream = new MemoryStream()) using (XmlWriter xmlWriter = XmlWriter.Create(dataStream)) { input.WriteTo(xmlWriter); xmlWriter.Flush(); dataStream.Seek(0, SeekOrigin.Begin); XslTransformState preparedState = transform.RetryPolicy.ExecuteAction <XslTransformState>(() => { return(transform.Client.PrepareTransform(dataStream)); }); XslTransformState transformedState = transform.RetryPolicy.ExecuteAction <XslTransformState>(() => { return(transform.Client.ApplyTransform(transformName, preparedState)); }); using (Stream transformedData = transform.RetryPolicy.ExecuteAction <Stream>(() => { return(transform.Client.CompleteTransform(transformedState)); })) { return(XDocument.Load(transformedData)); } } } else { throw new CloudApplicationException(String.Format(CultureInfo.CurrentCulture, ExceptionMessages.ServiceBusEndpointNotFound, WellKnownEndpointName.ScalableTransformService)); } } catch (Exception ex) { TraceManager.WorkerRoleComponent.TraceError(ex, callToken); throw; } finally { TraceManager.WorkerRoleComponent.TraceOut(callToken); } }
/// <summary> /// Applies the specified transformation map name against the source document described by the given transformation state object. /// </summary> /// <param name="transformName">Either partial or fully qualified name of the transformation map.</param> /// <param name="state">An instance of the state object carrying the information related to the source document that will be transformed.</param> /// <returns>An instance of the object used by the Scalable Transformation Service to track state transitions when performing transformations.</returns> public XslTransformState ApplyTransform(string transformName, XslTransformState state) { try { Guard.ArgumentNotNullOrEmptyString(transformName, "transformName"); Guard.ArgumentNotNull(state, "state"); Guard.ArgumentNotNullOrEmptyString(state.StorageAccount, "state.StorageAccount"); Guard.ArgumentNotNullOrEmptyString(state.ContainerName, "state.ContainerName"); Guard.ArgumentNotNullOrEmptyString(state.InputDocumentRef, "state.InputDocumentRef"); XslTransformSet transformSet = this.transformProvider.GetXslTransform(transformName); if (transformSet != null) { using (ICloudBlobStorage blobStorage = this.cloudStorageProvider.GetBlobStorage(state.StorageAccount)) using (Stream blobData = blobStorage.Get <Stream>(state.ContainerName, state.InputDocumentRef)) { if (blobData != null) { using (MemoryStream outputDoc = new MemoryStream()) using (XmlReader inputDocReader = XmlReader.Create(blobData)) { transformSet.Transform.Transform(inputDocReader, transformSet.Arguments, outputDoc); outputDoc.Seek(0, SeekOrigin.Begin); XslTransformState newState = PersistInputDocument(outputDoc); return(new XslTransformState(newState, state)); } } else { throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, ExceptionMessages.ApplyTransformOperationFailureInputDocNotFound, state.StorageAccount, state.ContainerName, state.InputDocumentRef)); } } } else { throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, ExceptionMessages.ApplyTransformOperationFailureTransformNotFound, transformName)); } } catch (Exception ex) { throw new CloudApplicationException(String.Format(CultureInfo.InvariantCulture, ExceptionMessages.ApplyTransformOperationFailed, ex.Message), ex); } }
/// <summary> /// Retrieves the transformed version of the source document described by the given transformation state object. /// </summary> /// <param name="state">An instance of the state object carrying the information related to the source document that will be transformed.</param> /// <returns>The stream of data containing the results from transformation.</returns> public Stream CompleteTransform(XslTransformState state) { try { Guard.ArgumentNotNull(state, "state"); Guard.ArgumentNotNullOrEmptyString(state.StorageAccount, "state.StorageAccount"); Guard.ArgumentNotNullOrEmptyString(state.ContainerName, "state.ContainerName"); Guard.ArgumentNotNullOrEmptyString(state.InputDocumentRef, "state.InputDocumentRef"); Stream blobData = null; using (ICloudBlobStorage blobStorage = this.cloudStorageProvider.GetBlobStorage(state.StorageAccount)) { blobData = blobStorage.Get <Stream>(state.ContainerName, state.InputDocumentRef); } foreach (var knownState in state.GetTransitions()) { try { using (ICloudBlobStorage blobStorage = this.cloudStorageProvider.GetBlobStorage(knownState.StorageAccount)) { blobStorage.Delete(knownState.ContainerName, knownState.InputDocumentRef); } } catch (Exception ex) { // We must ensure that all blobs are deleted. An exception should not cause a stop condition. TraceManager.TransformComponent.TraceError(ex); } } if (null == blobData) { throw new InvalidOperationException(String.Format(CultureInfo.InvariantCulture, ExceptionMessages.CompleteTransformFailureFinalDocNotFound, state.StorageAccount, state.ContainerName, state.InputDocumentRef)); } return(blobData); } catch (Exception ex) { throw new CloudApplicationException(String.Format(CultureInfo.InvariantCulture, ExceptionMessages.CompleteTransformOperationFailed, ex.Message), ex); } }
/// <summary> /// Applies the specified transformation map name against the source document described by the given transformation state object. /// </summary> /// <param name="transformName">Either partial or fully qualified name of the transformation map.</param> /// <param name="state">An instance of the state object carrying the information related to the source document that will be transformed.</param> /// <returns>An instance of the object used by the Scalable Transformation Service to track state transitions when performing transformations.</returns> public XslTransformState ApplyTransform(string transformName, XslTransformState state) { Guard.ArgumentNotNull(state, "state"); var callToken = TraceManager.ServiceComponent.TraceIn(state.StorageAccount, state.ContainerName, state.InputDocumentRef); try { if (OnApplyTransform != null) { return(OnApplyTransform(transformName, state)); } else { throw new NotImplementedException(); } } finally { TraceManager.ServiceComponent.TraceOut(callToken); } }