private static void SetEndNavigationProperty(NavigationProperty navProp, string value)
        {
            var     cpc = PropertyWindowViewModelHelper.GetCommandProcessorContext();
            Command c   = new EntityDesignRenameCommand(navProp, value, true);
            var     cp  = new CommandProcessor(cpc, c);

            cp.Invoke();
        }
Ejemplo n.º 2
0
        internal override void Invoke(CommandProcessorContext cpc)
        {
            var viewModel = _entityType.GetRootViewModel();

            Debug.Assert(viewModel != null, "Unable to find root view model from entity type: " + _entityType.Name);

            if (viewModel != null)
            {
                var entityType = viewModel.ModelXRef.GetExisting(_entityType) as Model.Entity.EntityType;
                Debug.Assert(entityType != null);
                Command c  = new EntityDesignRenameCommand(entityType, _entityType.Name, true);
                var     cp = new CommandProcessor(cpc, c);
                cp.Invoke();
            }
        }
Ejemplo n.º 3
0
        internal override void Invoke(CommandProcessorContext cpc)
        {
            var viewModel = _property.GetRootViewModel();

            Debug.Assert(viewModel != null, "Unable to find root view model from property: " + _property.Name);

            if (viewModel != null)
            {
                var property = viewModel.ModelXRef.GetExisting(_property) as Model.Entity.Property;
                Debug.Assert(property != null);

                Command c  = new EntityDesignRenameCommand(property, _property.Name, true);
                var     cp = new CommandProcessor(cpc, c);
                cp.Invoke();
            }
        }
Ejemplo n.º 4
0
        protected override void OnApplyChanges()
        {
            // SCCI operation, check out any file that need to be changed.
            // If failed to check out any file or user cancelled check out, return.
            var filesToCheckOut = new List <String>(GetListOfFilesToCheckOut());

            if (!EnsureFileCheckOut(filesToCheckOut))
            {
                return;
            }

            // Set up linked undo
            var linkedUndoManager = ServiceProvider.GetService(typeof(SVsLinkedUndoTransactionManager)) as IVsLinkedUndoTransactionManager;

            var completedLinkedUndo = false;

            try
            {
                var hr = linkedUndoManager.OpenLinkedUndo(ApplyChangesUndoScope, UndoDescription);
                if (hr == VSConstants.S_OK)
                {
                    var linkedUndoHr = 0;

                    // Remember what are invisible editors we open, we will release them explicitly
                    // after apply changes are done.
                    var invisibleEditors = new List <IVsInvisibleEditor>();
                    try
                    {
                        var    changeCount  = FileChanges.Count;
                        string errorMessage = null;
                        string fileName     = null;
                        try
                        {
                            for (var changeIndex = 0; changeIndex < changeCount && !IsCancelled && !ErrorOccurred; changeIndex++)
                            {
                                var fileChange = FileChanges[changeIndex];
                                if (fileChange.IsFileModified)
                                {
                                    // When apply change to a file, if that file is not in RDT, it will open that file in invisible editor.
                                    fileName = fileChange.FileName;
                                    var textBuffer = GetTextBufferForFile(fileName, invisibleEditors);
                                    if (textBuffer != null)
                                    {
                                        ApplyChangesToOneFile(fileChange, textBuffer, false, null);
                                    }
                                }
                            }

                            // Execute the rename command to update the CSDL model
                            var artifact = _objectToRename.Artifact as EntityDesignArtifact;
                            Debug.Assert(artifact != null, "Object being refactored does not have an EntityDesignArtifact parent.");
                            if (artifact != null)
                            {
                                var renameCommand = new EntityDesignRenameCommand(_objectToRename, _newName, false);
                                var cpc           = new CommandProcessorContext(
                                    artifact.EditingContext, "EFRefactoringOperation->OnApplyChanges", Resources.Tx_RefactorRenameCommand);
                                CommandProcessor.InvokeSingleCommand(cpc, renameCommand);
                            }
                        }
                        catch (IOException)
                        {
                            errorMessage = string.Format(CultureInfo.CurrentCulture, Resources.Error_FailedApplyChangeToFile, fileName);
                        }
                        catch (InvalidOperationException)
                        {
                            errorMessage = string.Format(CultureInfo.CurrentCulture, Resources.Error_FailedApplyChangeToFile, fileName);
                        }

                        if (errorMessage != null)
                        {
                            // Any error occur, abort the transaction.
                            linkedUndoManager.AbortLinkedUndo();
                            OnError(errorMessage);
                        }
                        else
                        {
                            // Succeed, close linked undo and submit the transaction.
                            // This operation will automatically save any dirty file.
                            linkedUndoHr = linkedUndoManager.CloseLinkedUndo();
                            if (linkedUndoHr != VSConstants.S_OK)
                            {
                                linkedUndoManager.AbortLinkedUndo();
                            }
                        }

                        completedLinkedUndo = true;
                    }
                    finally
                    {
                        var editorCount = invisibleEditors.Count;
                        for (var editorIndex = 0; editorIndex < editorCount; editorIndex++)
                        {
                            // Close invisible editor from RDT
                            var invisibleEditor = invisibleEditors[editorIndex];
                            if (invisibleEditor != null)
                            {
                                Marshal.ReleaseComObject(invisibleEditor);
                            }
                        }
                    }
                }
                else
                {
                    OnError(string.Format(CultureInfo.CurrentCulture, Resources.Error_FailedApplyChangeToFile, string.Empty));
                }
            }
            finally
            {
                if (completedLinkedUndo == false)
                {
                    linkedUndoManager.AbortLinkedUndo();
                }
            }
        }