src/Misc/EFTools/EntityDesign/VisualStudio/Package/ConnectionManager.cs
// <summary>
//     After renaming a file, we need to update the metadata portion of the connection string
//     to reflect the new name of the edmx file.
// </summary>
After renaming a file, we need to update the metadata portion of the connection string
to reflect the new name of the edmx file.
After renaming a file we need to update the metadata portion of the connection string to reflect the new name of the edmx file .
internal int OnAfterRenameFile(object sender, ModelChangeEventArgs args)
        {
            if (!Path.GetExtension(args.OldFileName).Equals(EntityDesignArtifact.ExtensionEdmx, StringComparison.CurrentCulture))
            {
                return VSConstants.E_NOTIMPL;
            }
            if (args.ProjectObj == null)
            {
                Debug.Fail(
                    String.Format(
                        CultureInfo.CurrentCulture, Resources.ConnectionManager_UpdateError, "Metadata portion of connection string",
                        "No project was found"));
                return VSConstants.E_INVALIDARG;
            }
            if (args.Artifact == null)
            {
                if (Path.GetExtension(args.NewFileName).Equals(EntityDesignArtifact.ExtensionEdmx, StringComparison.CurrentCulture))
                {
                    Debug.Fail("we are renaming the file to one with an edmx extension, why weren't we able to find the artifact?");
                }
                return VSConstants.E_INVALIDARG;
            }
            if (args.Artifact.ConceptualModel() != null
                && args.Artifact.ConceptualModel().FirstEntityContainer != null
                && HasConnectionString(args.ProjectObj, args.Artifact.ConceptualModel().FirstEntityContainer.LocalName.Value))
            {                   
                var metadataFileNames = GetMetadataFileNamesFromArtifactFileName(args.ProjectObj, args.Artifact.Uri.LocalPath, PackageManager.Package);
                var mapProperty = GetMetadataPropertyFromArtifact(args.Artifact);
                string mapPropertyValue;
                if (mapProperty != null)
                {
                    mapPropertyValue = mapProperty.ValueAttr.Value;
                }
                else
                {
                    mapPropertyValue = ConnectionDesignerInfo.MAP_CopyToOutputDirectory;
                }
                var applicationType = VsUtils.GetApplicationType(Services.ServiceProvider, args.ProjectObj);
                var newMetaData = GetConnectionStringMetadata(metadataFileNames, args.ProjectObj, applicationType, mapPropertyValue);
                UpdateMetadataName(args.ProjectObj, args.Artifact.ConceptualModel().FirstEntityContainer.LocalName.Value, newMetaData);
            }
            return VSConstants.S_OK;
        }
internal int OnAfterRenameFile ( object sender , ModelChangeEventArgs args ) { if ( ! Path . GetExtension ( args . OldFileName ) . Equals ( EntityDesignArtifact . ExtensionEdmx , StringComparison . CurrentCulture ) ) { return VSConstants . E_NOTIMPL ; } if ( args . ProjectObj == null ) { Debug . Fail ( String . Format ( CultureInfo . CurrentCulture , Resources . ConnectionManager_UpdateError , " " , " " ) ) ; return VSConstants . E_INVALIDARG ; } if ( args . Artifact == null ) { if ( Path . GetExtension ( args . NewFileName ) . Equals ( EntityDesignArtifact . ExtensionEdmx , StringComparison . CurrentCulture ) ) { Debug . Fail ( " " ) ; } return VSConstants . E_INVALIDARG ; } if ( args . Artifact . ConceptualModel ( ) != null && args . Artifact . ConceptualModel ( ) . FirstEntityContainer != null && HasConnectionString ( args . ProjectObj , args . Artifact . ConceptualModel ( ) . FirstEntityContainer . LocalName . Value ) ) { var metadataFileNames = GetMetadataFileNamesFromArtifactFileName ( args . ProjectObj , args . Artifact . Uri . LocalPath , PackageManager . Package ) ; var mapProperty = GetMetadataPropertyFromArtifact ( args . Artifact ) ; string mapPropertyValue ; if ( mapProperty != null ) { mapPropertyValue = mapProperty . ValueAttr . Value ; } else { mapPropertyValue = ConnectionDesignerInfo . MAP_CopyToOutputDirectory ; } var applicationType = VsUtils . GetApplicationType ( Services . ServiceProvider , args . ProjectObj ) ; var newMetaData = GetConnectionStringMetadata ( metadataFileNames , args . ProjectObj , applicationType , mapPropertyValue ) ; UpdateMetadataName ( args . ProjectObj , args . Artifact . ConceptualModel ( ) . FirstEntityContainer . LocalName . Value , newMetaData ) ; } return VSConstants . S_OK ; }
After renaming a file, we need to update the metadata portion of the connection string
to reflect the new name of the edmx file.
After renaming a file we need to update the metadata portion of the connection string to reflect the new name of the edmx file .
// ignore files that are not edmx // if we are renaming the extension to a non-edmx extension, then the artifact will be null
sender
object
args
ModelChangeEventArgs