/// <summary>
 /// Called right before the file will be saved to disk.
 /// </summary>
 /// <param name="context">Provides file and Visual Studio project information.</param>
 void IModelConversionExtension.OnBeforeFileSaved(ModelConversionExtensionContext context)
 {
     // context.CurrentDocument = The .edmx content (as an XDocument) created by the Entity Designer.
     //                           This is for reference and cannot be modified.
     //
     // context.OriginalDocument = The .edmx (as a string) after it has been converted to a custom file format.
 }
Esempio n. 2
0
        internal static void DispatchToConversionExtensions(
            ICollection <Lazy <IModelConversionExtension, IEntityDesignerConversionData> > exports, string fileExtension,
            ModelConversionExtensionContext context, bool loading)
        {
            var converters = new List <string>();

            if (exports != null)
            {
                foreach (var exportInfo in exports)
                {
                    var converterFileExtension = exportInfo.Metadata.FileExtension;
                    if (converterFileExtension != null &&
                        !converterFileExtension.StartsWith(".", StringComparison.Ordinal))
                    {
                        converterFileExtension = "." + converterFileExtension;
                    }

                    if (string.Equals(fileExtension, converterFileExtension, StringComparison.OrdinalIgnoreCase))
                    {
                        if (converters.Count > 0)
                        {
                            break;
                        }

                        var extension = exportInfo.Value;
                        if (loading)
                        {
                            extension.OnAfterFileLoaded(context);
                        }
                        else
                        {
                            extension.OnBeforeFileSaved(context);
                        }

                        converters.Add(extension.GetType().FullName);
                    }
                }
            }

            if (converters.Count == 0)
            {
                throw new InvalidOperationException(Resources.Extensibility_NoConverterForExtension);
            }
            else if (converters.Count > 1)
            {
                var convs = string.Empty;
                for (var i = 0; i < converters.Count; i++)
                {
                    if (i != 0)
                    {
                        convs += ", ";
                    }
                    convs += converters[i];
                }

                var message = string.Format(CultureInfo.CurrentCulture, Resources.Extensibility_TooManyConverters, convs);
                throw new InvalidOperationException(message);
            }
        }
        /* These callbacks do not appear to be working */

        /// <summary>
        /// Called after the contents of a custom file have been loaded, but before the contents are converted
        /// to an .edmx document for display in the Entity Designer.
        /// </summary>
        /// <param name="context">Provides file and Visual Studio project information.</param>
        void IModelConversionExtension.OnAfterFileLoaded(ModelConversionExtensionContext context)
        {
            // context.OriginalDocument = Contents of the custom file as a string.
            //                            This is for reference only and cannot be modified.
            //
            // context.CurrentDocument = Contents of the converted file as an XDocument.
            //                           This should be a valid .edmx document.
        }