/// <summary>
        ///     Updates artifact URI and error list when a document is renamed/moved/save-as'd WHEN IT IS OPEN
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="cpc"></param>
        /// <returns></returns>
        private int OnAfterFileNameChanged(object sender, ModelChangeEventArgs args)
        {
            // after a file name change we have to rename the artifact
            if (args.OldFileName != null &&
                args.NewFileName != null)
            {
                // if the user renamed the extension of the file, we will still take it
                var oldUri = Utils.FileName2Uri(args.OldFileName);
                if (oldUri != null
                    &&
                    _package != null
                    &&
                    _package.ModelManager != null
                    &&
                    _package.ModelManager.GetArtifact(oldUri) != null)
                {
                    var newUri = Utils.FileName2Uri(args.NewFileName);

                    // first we need to remove the errors attached to this soon-to-be stale artifact
                    // this applies to rename/move
                    var oldArtifact = _package.ModelManager.GetArtifact(oldUri);
                    if (oldArtifact != null &&
                        oldArtifact.ArtifactSet != null)
                    {
                        oldArtifact.ArtifactSet.RemoveErrorsForArtifact(oldArtifact);
                    }

                    ClearErrorList(oldUri, newUri);

                    _package.ModelManager.RenameArtifact(oldUri, newUri);
                }
            }

            return(VSConstants.S_OK);
        }
        public int OnQueryRemoveFiles(
            IVsProject pProject, int cFiles, string[] rgpszMkDocuments, VSQUERYREMOVEFILEFLAGS[] rgFlags,
            VSQUERYREMOVEFILERESULTS[] pSummaryResult, VSQUERYREMOVEFILERESULTS[] rgResults)
        {
            var hr      = VSConstants.S_OK;
            var handler = QueryRemoveFile;

            if (handler != null)
            {
                if (cFiles <= rgpszMkDocuments.Length)
                {
                    for (var fileCount = 0; fileCount < cFiles; fileCount++)
                    {
                        var args = new ModelChangeEventArgs();
                        args.OldFileName = rgpszMkDocuments[fileCount];
                        args.ProjectObj  = VSHelpers.GetProject(pProject as IVsHierarchy);
                        if (args.ProjectObj == null)
                        {
                            continue;
                        }

                        hr = handler(this, args);
                    }
                }
            }
            return(hr);
        }
        public int OnBeforeUnloadProject(IVsHierarchy pRealHierarchy, IVsHierarchy pStubHierarchy)
        {
            var handler = BeforeCloseProject;

            if (handler != null)
            {
                var args = new ModelChangeEventArgs();
                try
                {
                    args.ProjectObj = VSHelpers.GetProject(pRealHierarchy);
                }
                catch (ArgumentException)
                {
                    return(VSConstants.E_NOTIMPL);
                }

                if (args.ProjectObj == null)
                {
                    return(VSConstants.E_NOTIMPL);
                }
                return(handler(this, args));
            }

            return(VSConstants.S_OK);
        }
        public int OnAfterRemoveFiles(
            int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgpszMkDocuments,
            VSREMOVEFILEFLAGS[] rgFlags)
        {
            var hr      = VSConstants.S_OK;
            var handler = AfterRemoveFile;

            if (handler != null)
            {
                if (cFiles <= rgpszMkDocuments.Length)
                {
                    for (var fileCount = 0; fileCount < cFiles; fileCount++)
                    {
                        var args = new ModelChangeEventArgs();
                        args.OldFileName = rgpszMkDocuments[fileCount];
                        args.ProjectObj  = GetProjectFromArray(cProjects, fileCount, rgpProjects, rgFirstIndices);
                        if (args.ProjectObj == null)
                        {
                            continue;
                        }

                        hr = handler(this, args);
                    }
                }
            }
            return(hr);
        }
Ejemplo n.º 5
0
 private int OnFileNameChanged(object sender, ModelChangeEventArgs args)
 {
     // TODO: The code could be optimized so we don't have to reload the model browser when EDMX file is renamed.
     // But this should be ok for now since renaming should not be performed frequently.
     ClearAndReload();
     return(VSConstants.S_OK);
 }
Ejemplo n.º 6
0
 private int OnFileNameChanged(object sender, ModelChangeEventArgs args)
 {
     // TODO: The code could be optimized so we don't have to reload the model browser when EDMX file is renamed.
     // But this should be ok for now since renaming should not be performed frequently.
     ClearAndReload();
     return VSConstants.S_OK;
 }
Ejemplo n.º 7
0
 public void OnFileNameChanged(string oldFileName, string newFileName)
 {
     var args = new ModelChangeEventArgs();
     args.OldFileName = oldFileName;
     args.NewFileName = newFileName;
     FileNameChanged(this, args);
 }
Ejemplo n.º 8
0
        public void OnFileNameChanged(string oldFileName, string newFileName)
        {
            var args = new ModelChangeEventArgs();

            args.OldFileName = oldFileName;
            args.NewFileName = newFileName;
            FileNameChanged(this, args);
        }
        public int OnAfterRenameFiles(
            int cProjects, int cFiles, IVsProject[] rgpProjects, int[] rgFirstIndices, string[] rgszMkOldNames, string[] rgszMkNewNames,
            VSRENAMEFILEFLAGS[] rgFlags)
        {
            var hr      = VSConstants.S_OK;
            var handler = AfterRenameFile;

            if (handler != null)
            {
                for (var fileCount = 0; fileCount < cFiles; fileCount++)
                {
                    var args = new ModelChangeEventArgs();
                    args.OldFileName = rgszMkOldNames[fileCount];
                    args.NewFileName = rgszMkNewNames[fileCount];
                    args.ProjectObj  = GetProjectFromArray(cProjects, fileCount, rgpProjects, rgFirstIndices);
                    if (args.ProjectObj == null)
                    {
                        continue;
                    }

                    var          newUri           = Utils.FileName2Uri(args.NewFileName);
                    ModelManager modelManager     = PackageManager.Package.ModelManager;
                    var          artifact         = modelManager.GetArtifact(newUri);
                    ModelManager tempModelManager = null;
                    try
                    {
                        if (artifact == null &&
                            Path.GetExtension(args.NewFileName)
                            .Equals(EntityDesignArtifact.EXTENSION_EDMX, StringComparison.CurrentCulture))
                        {
                            tempModelManager = new EntityDesignModelManager(new EFArtifactFactory(), new VSArtifactSetFactory());
                            artifact         = tempModelManager.GetNewOrExistingArtifact(
                                newUri, new StandaloneXmlModelProvider(PackageManager.Package));
                        }
                        args.Artifact = artifact;

                        hr = handler(this, args);
                    }
                    finally
                    {
                        if (tempModelManager != null)
                        {
                            tempModelManager.Dispose();
                        }
                    }
                }
            }
            return(hr);
        }
        public int OnBeforeGenerateDDL(Project project, EFArtifact artifact)
        {
            var args = new ModelChangeEventArgs();

            args.ProjectObj = project;
            args.Artifact   = artifact;
            if (BeforeGenerateDDL != null)
            {
                return(BeforeGenerateDDL(this, args));
            }
            else
            {
                return(0);
            }
        }
        public int OnBeforeValidateModel(Project project, EFArtifact artifact, bool isCurrentlyBuilding)
        {
            var args = new ModelChangeEventArgs();

            args.ProjectObj          = project;
            args.Artifact            = artifact;
            args.IsCurrentlyBuilding = isCurrentlyBuilding;
            if (BeforeValidateModel != null)
            {
                return(BeforeValidateModel(this, args));
            }
            else
            {
                return(0);
            }
        }
        /// <summary>
        ///     Event handler when we change any properties of the model. For now we'll handle just the renaming
        ///     the entity container name.
        /// </summary>
        private void OnModelChangesCommitted(object sender, EfiChangedEventArgs e)
        {
            var changeEnum = e.ChangeGroup.Changes.GetEnumerator();

            while (changeEnum.MoveNext())
            {
                // update operation?
                if (changeEnum.Current.Type == EfiChange.EfiChangeType.Update)
                {
                    // are we updating the entity container name?
                    var entityContainer = changeEnum.Current.Changed as SingleItemBinding <ConceptualEntityContainer>;
                    if (entityContainer != null)
                    {
                        // get the values from the EfiChange properties, use those to construct the arguments
                        var pair = changeEnum.Current.Properties[EntityContainerMapping.AttributeCdmEntityContainer];
                        var args = new ModelChangeEventArgs();
                        args.OldEntityContainerName = (string)pair.OldValue;

                        AfterEntityContainerNameChange(this, args);

                        // ignore any further action
                        continue;
                    }
                }

                // are we updating the metadata artifact processing value?
                var metadataArtifactProcessingValue = changeEnum.Current.Changed as DefaultableValue <string>;
                if (metadataArtifactProcessingValue != null)
                {
                    var mapProp = metadataArtifactProcessingValue.Parent as DesignerProperty;

                    if (mapProp != null &&
                        mapProp.LocalName != null &&
                        String.Compare(
                            mapProp.LocalName.Value, ConnectionDesignerInfo.AttributeMetadataArtifactProcessing,
                            StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        var pair = changeEnum.Current.Properties[DesignerProperty.AttributeValue];
                        var args = new ModelChangeEventArgs();
                        args.OldMetadataArtifactProcessing = (string)pair.OldValue;
                        AfterMetadataArtifactProcessingChange(this, args);
                        continue;
                    }
                }
            }
        }
        public int OnAfterSave(uint docCookie)
        {
            var hr = VSConstants.S_OK;

            if (AfterSaveFile != null)
            {
                var          docTable = Services.IVsRunningDocumentTable;
                uint         rdtFlags, readLocks, editLocks, itemId;
                string       fileName;
                IVsHierarchy hierarchy;
                var          docData = IntPtr.Zero;

                try
                {
                    hr = docTable.GetDocumentInfo(
                        docCookie, out rdtFlags, out readLocks, out editLocks, out fileName, out hierarchy, out itemId, out docData);
                }
                finally
                {
                    if (docData != IntPtr.Zero)
                    {
                        Marshal.Release(docData);
                    }
                }

                if (hr == VSConstants.S_OK &&
                    hierarchy != null)
                {
                    var projectObj = VSHelpers.GetProject(hierarchy);
                    if (projectObj != null)
                    {
                        var args = new ModelChangeEventArgs();
                        args.DocCookie  = docCookie;
                        args.Artifact   = PackageManager.Package.ModelManager.GetArtifact(Utils.FileName2Uri(fileName));
                        args.ProjectObj = projectObj;
                        hr = AfterSaveFile(this, args);
                    }
                }
            }
            return(hr);
        }
        public int OnAfterOpenProject(IVsHierarchy pHierarchy, int fAdded)
        {
            if (AfterOpenProject != null)
            {
                var args = new ModelChangeEventArgs();
                try
                {
                    args.ProjectObj = VSHelpers.GetProject(pHierarchy);
                }
                catch (ArgumentException)
                {
                    return(VSConstants.E_NOTIMPL);
                }

                if (args.ProjectObj == null)
                {
                    return(VSConstants.E_NOTIMPL);
                }
                return(AfterOpenProject(this, args));
            }

            return(VSConstants.S_OK);
        }