RightsManagementEncryptionTransform(
            TransformEnvironment transformEnvironment
            )
        {
            Debug.Assert(transformEnvironment != null);
            
            Stream instanceDataStream = transformEnvironment.GetPrimaryInstanceData();

            Debug.Assert(instanceDataStream != null, SR.Get(SRID.NoPublishLicenseStream));

            _useLicenseStorage = transformEnvironment.GetInstanceDataStorage();

            Debug.Assert(_useLicenseStorage != null, SR.Get(SRID.NoUseLicenseStorage));

            // Create a wrapper that manages persistence and comparison of FormatVersion
            // in our InstanceData stream.  We can read/write to this stream as needed (though CompressionTransform
            // does not because we don't house any non-FormatVersion data in the instance data stream).
            // We need to give out our current code version so it can compare with any file version as appropriate.
            _publishLicenseStream = new VersionedStreamOwner(
                instanceDataStream,
                new FormatVersion(FeatureName, MinimumReaderVersion, MinimumUpdaterVersion, CurrentFeatureVersion));
        }
    /// <summary>
    /// Define a data transform object with the given object identification and
    /// labeled with the given name.
    /// </summary>
    /// <param name="transformClassName">Transform identification string</param>
    /// <param name="newTransformLabel">Label to use for new transform</param>
    internal void DefineTransform(string transformClassName, string newTransformLabel )
    {
        CheckDisposedStatus();

        // Check to see if transform name is obviously invalid
        CU.CheckStringAgainstNullAndEmpty( transformClassName, "Transform identifier name" );

        // Check to see if transform name is valid
        CU.CheckStringAgainstNullAndEmpty( newTransformLabel, "Transform label" );

        // Given transform name must not be a reserved string
        CU.CheckStringAgainstReservedName( newTransformLabel, "Transform label" );
        
        // Can't re-use an existing transform name
        if( TransformLabelIsDefined( newTransformLabel ) )
            throw new ArgumentException(
                SR.Get(SRID.TransformLabelInUse));

        // Create class the transform object will use to communicate to us
        TransformEnvironment transformEnvironment = new TransformEnvironment( this, newTransformLabel );

        // Create a TransformInstance object to represent this transform instance.
        TransformInstance newTransform = new TransformInstance(
            TransformIdentifierTypes_PredefinedTransformName,
            transformClassName,
            null,
            transformEnvironment );

        SetTransformDefinition( newTransformLabel, newTransform );

        // Create the transform object
        IDataTransform transformObject = InstantiateDataTransformObject(
                                                    TransformIdentifierTypes_PredefinedTransformName,
                                                    transformClassName,
                                                    transformEnvironment );
        newTransform.transformReference = transformObject;

        // If transform is not ready out-of-the-box, do an initialization run.
        //  Note: Transform is not required to be "ready" after this.  This is
        //  done for those transforms that need initialization work up-front.
        if( ! transformObject.IsReady )
        {
            CallTransformInitializers( 
                new TransformInitializationEventArgs(
                    transformObject,
                    null,
                    null,
                    newTransformLabel) 
                );
        }

        _dirtyFlag = true;

        return;
    }
    /// <summary>
    /// Internal method to get the transform object corresponding to the specified
    /// transform instance label. The transform object is created if it does not exist.
    /// </summary>
    /// <param name="transformLabel">
    /// String that identifies the transform instance.
    /// </param>
    /// <returns>
    /// An IDataTransform interface pointer to the transform object identified by
    /// <paramref name="transformLabel"/>, or null if there is no such transform.
    /// </returns>
    internal IDataTransform GetTransformFromName(string transformLabel)
    {
        TransformInstance transformInstance = _transformDefinitions[transformLabel] as TransformInstance;

        if (transformInstance == null)
        {
            //
            // There is no transform instance with the specified name.
            //
            return null;
        }

        IDataTransform transformObject = transformInstance.transformReference;
        if (transformObject == null)
        {
            //
            // There is a transform instance with the specified name, but its transform
            // object has not yet been created. Create it now. This code is modeled on the
            // code in DefineTransform.
            //
            TransformEnvironment transformEnvironment = new TransformEnvironment(this, transformLabel);

            // Create the transform object.
            transformObject = InstantiateDataTransformObject(
                                    transformInstance.ClassType,
                                    transformInstance.typeName,
                                    transformEnvironment);
            transformInstance.transformReference = transformObject;
        }

        return transformObject;
    }
    /// <summary>
    /// Tranform object is created. We are no longer using reflection to do this. We are supporting limited data transforms.
    /// </summary>
    private IDataTransform InstantiateDataTransformObject(int transformClassType,  string transformClassName, TransformEnvironment transformEnvironment )
    {
        object transformInstance = null;

        if (transformClassType != (int) TransformIdentifierTypes_PredefinedTransformName)
            throw new NotSupportedException(SR.Get(SRID.TransformTypeUnsupported));

        // Transform Identifier: we preserve casing, but do case-insensitive comparison
        if (((IEqualityComparer) CU.StringCaseInsensitiveComparer).Equals(transformClassName,
                RightsManagementEncryptionTransform.ClassTransformIdentifier))
        {
            transformInstance = new RightsManagementEncryptionTransform( transformEnvironment);
        }
        else if (((IEqualityComparer) CU.StringCaseInsensitiveComparer).Equals(transformClassName,
                CompressionTransform.ClassTransformIdentifier))
        {
             transformInstance = new CompressionTransform( transformEnvironment );
        }
        else
        {
            //this transform class is not supported. Need to change this to appropriate error.
            throw new ArgumentException(
                    SR.Get(SRID.TransformLabelUndefined));
        }

        if (null != transformInstance)
        {
            if( !( transformInstance is IDataTransform ) )
                throw new ArgumentException(
                    SR.Get(SRID.TransformObjectImplementIDataTransform));
            return (IDataTransform)transformInstance;
        }

        return null;        
    }
 // When we know everything to put into a TransformInstance.
 internal TransformInstance( 
     int classType,
     string name, 
     IDataTransform instance, 
     TransformEnvironment environment, 
     Stream primaryStream, 
     StorageInfo storage )
 {
     typeName = name;
     transformReference = instance;
     transformEnvironment = environment;
     transformPrimaryStream = primaryStream;
     transformStorage = storage;
     _classType = classType;
 }
 // When we also have an actual object in memory and its associated
 //  environment object
 internal TransformInstance( 
     int classType,
     string name, 
     IDataTransform instance, 
     TransformEnvironment environment ) : this(classType, name, instance, environment, null, null ) {;}
Beispiel #7
0
        /// <summary>
        /// constructor
        /// </summary>
        /// <param name="myEnvironment">environment</param>
        /// <remarks>this should only be used by the DataSpaceManager class</remarks>
        public CompressionTransform(TransformEnvironment myEnvironment)
        {
            _transformEnvironment = myEnvironment;

            // Create a wrapper that manages persistence and comparison of FormatVersion
            // in our InstanceData stream.  We can read/write to this stream as needed (though CompressionTransform
            // does not because we don't house any non-FormatVersion data in the instance data stream).
            // We need to give out our current code version so it can compare with any file version as appropriate.
            _versionedStreamOwner = new VersionedStreamOwner(
                _transformEnvironment.GetPrimaryInstanceData(),
                new FormatVersion(_featureName, _minimumReaderVersion, _minimumUpdaterVersion, _currentFeatureVersion));
        }