src/Misc/EFTools/EntityDesignDatabaseGeneration/Activities/CsdlToSsdlAndMslActivity.cs
/// <summary>
///     Generates output that is supplied to the specified NativeActivityContext based on input specified in the NativeActivityContext.
/// </summary>
/// <param name="context"> The state of the current activity. </param>
Generates output that is supplied to the specified NativeActivityContext based on input specified in the NativeActivityContext.
Generates output that is supplied to the specified NativeActivityContext based on input specified in the NativeActivityContext .
[SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        protected override void Execute(NativeActivityContext context)
        {
            var edmItemCollection = CsdlInput.Get(context);
            if (edmItemCollection == null)
            {
                throw new InvalidOperationException(Resources.ErrorCouldNotFindCSDL);
            }
            var symbolResolver = context.GetExtension<SymbolResolver>();
            var edmParameterBag = symbolResolver[typeof(EdmParameterBag).Name] as EdmParameterBag;
            if (edmParameterBag == null)
            {
                throw new InvalidOperationException(Resources.ErrorNoEdmParameterBag);
            }
            var targetFrameworkVersion = edmParameterBag.GetParameter<Version>(EdmParameterBag.ParameterName.TargetVersion);
            if (targetFrameworkVersion == null)
            {
                throw new InvalidOperationException(
                    String.Format(
                        CultureInfo.CurrentCulture, Resources.ErrorNoParameterDefined,
                        EdmParameterBag.ParameterName.TargetVersion.ToString()));
            }
            if (false == EntityFrameworkVersion.IsValidVersion(targetFrameworkVersion))
            {
                throw new InvalidOperationException(
                    String.Format(CultureInfo.CurrentCulture, Resources.ErrorNonValidTargetVersion, targetFrameworkVersion));
            }
            var inputs = new Dictionary<string, object>
                {
                    { EdmConstants.csdlInputName, edmItemCollection }
                };
            var ssdl = ProcessOutputGenerator<string>(OutputGeneratorType.Get(context), context, inputs);
            var msl = ProcessOutputGenerator<string>(MslOutputGeneratorType.Get(context), context, inputs);
            var ssdlCollection = EdmExtension.CreateAndValidateStoreItemCollection(
                ssdl, targetFrameworkVersion, DependencyResolver.Instance, true);
#if DEBUG
            IList<EdmSchemaError> mslErrors;
            EdmExtension.CreateStorageMappingItemCollection(
                edmItemCollection, ssdlCollection, msl, out mslErrors);
            if (mslErrors != null
                && mslErrors.Count > 0)
            {
                var errorSb = new StringBuilder();
                errorSb.AppendLine("Encountered the following errors while validating the MSL:");
                foreach (var error in mslErrors)
                {
                    errorSb.AppendLine(error.Message);
                }
                Debug.Fail(errorSb.ToString());
            }
#endif
            SsdlOutput.Set(context, ssdl);
            MslOutput.Set(context, msl);
        }
[ SuppressMessage ( " " , " " ) ] protected override void Execute ( NativeActivityContext context ) { var edmItemCollection = CsdlInput . Get ( context ) ; if ( edmItemCollection == null ) { throw new InvalidOperationException ( Resources . ErrorCouldNotFindCSDL ) ; } var symbolResolver = context . GetExtension < SymbolResolver > ( ) ; var edmParameterBag = symbolResolver [ typeof ( EdmParameterBag ) . Name ] as EdmParameterBag ; if ( edmParameterBag == null ) { throw new InvalidOperationException ( Resources . ErrorNoEdmParameterBag ) ; } var targetFrameworkVersion = edmParameterBag . GetParameter < Version > ( EdmParameterBag . ParameterName . TargetVersion ) ; if ( targetFrameworkVersion == null ) { throw new InvalidOperationException ( String . Format ( CultureInfo . CurrentCulture , Resources . ErrorNoParameterDefined , EdmParameterBag . ParameterName . TargetVersion . ToString ( ) ) ) ; } if ( false == EntityFrameworkVersion . IsValidVersion ( targetFrameworkVersion ) ) { throw new InvalidOperationException ( String . Format ( CultureInfo . CurrentCulture , Resources . ErrorNonValidTargetVersion , targetFrameworkVersion ) ) ; } var inputs = new Dictionary < string , object > { { EdmConstants . csdlInputName , edmItemCollection } } ; var ssdl = ProcessOutputGenerator < string > ( OutputGeneratorType . Get ( context ) , context , inputs ) ; var msl = ProcessOutputGenerator < string > ( MslOutputGeneratorType . Get ( context ) , context , inputs ) ; var ssdlCollection = EdmExtension . CreateAndValidateStoreItemCollection ( ssdl , targetFrameworkVersion , DependencyResolver . Instance , true ) ; if DEBUG IList < EdmSchemaError > mslErrors ; EdmExtension . CreateStorageMappingItemCollection ( edmItemCollection , ssdlCollection , msl , out mslErrors ) ; if ( mslErrors != null && mslErrors . Count > 0 ) { var errorSb = new StringBuilder ( ) ; errorSb . AppendLine ( " " ) ; foreach ( var error in mslErrors ) { errorSb . AppendLine ( error . Message ) ; } Debug . Fail ( errorSb . ToString ( ) ) ; } endif SsdlOutput . Set ( context , ssdl ) ; MslOutput . Set ( context , msl ) ; }
Generates output that is supplied to the specified NativeActivityContext based on input specified in the NativeActivityContext.
Generates output that is supplied to the specified NativeActivityContext based on input specified in the NativeActivityContext .
// Find the TargetVersion parameter // Validate the TargetVersion parameter // Construct the Code View inputs in a dictionary  // Process the SSDL and MSL code views, feeding in the CSDL // Validate the SSDL, but catch any naming errors and throw a friendlier one // Validate the MSL in Debug mode // We are done processing, save off all the outputs for the next stage
context
NativeActivityContext
The state of the current activity.
The state of the current activity .