private void showvalueEditor_handler(object ss, ShowValueEditorEventArgs ee)
        {
            using (WaitCursorHelper.NewWaitCursor())
            {
                // be sere fc is created
                make_fc();

                if (_ds.AttributesCache.ContainsKey(_fc.CurrentFieldName))
                {
                    foreach (CustomAttribute a in _ds.AttributesCache[_fc.CurrentFieldName])
                    {
                        a.applyCustomEditShownFilterControl(_ds, ee);
                    }
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     The DoOperation method begins the entire refactoring process.
        ///     The launch point for the refactoring operation must call this method.
        ///     overall flow
        ///     1) UI flows input into an instance of a derivation of this class ... (ctor)
        ///     2) The class may present its own UI (cancel)
        ///     3) It creates an ContributorInput object
        ///     4) Feeds it to the manager (or base class, depending on how you look at it)
        ///     5) Proposals returned
        ///     6) Merge proposals
        ///     7) Preview UI (optional)kind
        ///     8) Apply changes (or cancel or fail)
        /// </summary>
        public void DoOperation()
        {
            try
            {
                // If we don't have a ContributorInput yet, call OnGetContributorInput method to get ContributorInput for this operation.
                if (ContributorInput == null)
                {
                    ContributorInput = OnGetContributorInput();
                }

                if (ErrorOccurred || IsCancelled)
                {
                    return;
                }
                if (ContributorInput == null)
                {
                    // If not cancelled and contributorInput is null, throw exception.
                    throw new InvalidOperationException();
                }

                // Collect the list of files to change
                FileChanges = GetFileChanges();

                using (var cursor = WaitCursorHelper.NewWaitCursor())
                {
                    if (HasPreviewWindow)
                    {
                        // Log names of files with error to event log
                        OnBeforeShowPreviewWindow();

                        if (ErrorOccurred || IsCancelled)
                        {
                            return;
                        }

                        if (PreviewData.ChangeList == null ||
                            PreviewData.ChangeList.Count == 0)
                        {
                            if (System.Windows.MessageBox.Show(
                                    Resources.RefactoringOperation_NoChangesToPreview,
                                    Resources.RefactoringOperation_NoChangesToPreviewTitle,
                                    MessageBoxButton.OKCancel) == MessageBoxResult.OK)
                            {
                                ApplyChanges();
                            }
                        }
                        else
                        {
                            // After feed the preview window with PreviewChangesEngine, the engine will call back the ApplyChanges
                            // method in this Operation if user clicks Apply button.
                            ShowPreviewWindow();
                        }
                    }
                    else
                    {
                        // If no preview needed, apply the changes.
                        ApplyChanges();
                    }
                }

                if (ErrorOccurred || IsCancelled)
                {
                    return;
                }
            }
            catch (InvalidOperationException ex)
            {
                OnError(string.Format(CultureInfo.CurrentCulture, Resources.Error_FailedOperation, ex.Message));
            }
            catch (OperationCanceledException ex)
            {
                var errorMessage = ex.Message;
                if (string.IsNullOrEmpty(errorMessage))
                {
                    errorMessage = Resources.Dialog_CancelRefactoring;
                }
                CancelOperation();
                CommonVsUtilities.ShowMessageBoxEx(
                    Resources.RefactorDialog_Title, errorMessage,
                    MessageBoxButtons.OK, MessageBoxDefaultButton.Button1, MessageBoxIcon.Error);
            }
            finally
            {
                UnregisterEvents();
            }
        }
Exemplo n.º 3
0
        protected override IList <FileChange> GetFileChanges()
        {
            var fileChangeMap = new Dictionary <string, FileChange>();

            using (WaitCursorHelper.NewWaitCursor())
            {
                var artifact            = _contributorInput.ObjectToBeRenamed.Artifact;
                var artifactProjectItem = VsUtils.GetProjectItemForDocument(artifact.Uri.LocalPath, Services.ServiceProvider);

                if (artifactProjectItem != null)
                {
                    // Run the custom tool to ensure the generated code is up-to-date
                    VsUtils.RunCustomTool(artifactProjectItem);
                    var generatedCodeProjectItem = VsUtils.GetGeneratedCodeProjectItem(artifactProjectItem);

                    if (generatedCodeProjectItem != null)
                    {
                        var generatedItemPath    = generatedCodeProjectItem.get_FileNames(1);
                        var objectSearchLanguage = FileExtensions.VbExt.Equals(
                            Path.GetExtension(generatedItemPath), StringComparison.OrdinalIgnoreCase)
                                                       ? ObjectSearchLanguage.VB
                                                       : ObjectSearchLanguage.CSharp;

                        var codeElements = generatedCodeProjectItem.FileCodeModel.CodeElements.OfType <CodeElement2>();
                        CodeElementRenameData renameData = null;

                        // Check if we're refactoring an EntityType or Property
                        var entityType = _contributorInput.ObjectToBeRenamed as EntityType;
                        var property   = _contributorInput.ObjectToBeRenamed as Property;

                        if (entityType != null)
                        {
                            var newEntitySetName = _contributorInput.NewName;
                            var pluralize        = ModelHelper.GetDesignerPropertyValueFromArtifactAsBool(
                                OptionsDesignerInfo.ElementName, OptionsDesignerInfo.AttributeEnablePluralization,
                                OptionsDesignerInfo.EnablePluralizationDefault, artifact);

                            // Pluralize the entity set name if the setting it turned on
                            if (pluralize)
                            {
                                var pluralizationService = DependencyResolver.GetService <IPluralizationService>();
                                newEntitySetName = pluralizationService.Pluralize(_contributorInput.NewName);
                            }

                            renameData = new CodeElementRenameData(
                                _contributorInput.NewName, newEntitySetName, _contributorInput.OldName, entityType.EntitySet.Name.Value);
                        }
                        else if (property != null)
                        {
                            if (property.EntityType != null)
                            {
                                renameData = new CodeElementRenameData(
                                    _contributorInput.NewName, _contributorInput.OldName, property.EntityType.Name.Value);
                            }
                        }

                        if (renameData != null)
                        {
                            var codeElementsToRename = new Dictionary <CodeElement2, Tuple <string, string> >();
                            CodeElementUtilities.FindRootCodeElementsToRename(
                                codeElements, renameData, generatedItemPath, objectSearchLanguage, ref codeElementsToRename);
                            var changeProposals = new List <ChangeProposal>();

                            // We may need to rename more than one object, as type names affect functions and entity set properties. This means we need to loop through and
                            // process each root item change in the generated code designer file.
                            foreach (var codeElementToRename in codeElementsToRename.Keys)
                            {
                                var nameTuple = codeElementsToRename[codeElementToRename];

                                CodeElementUtilities.CreateChangeProposals(
                                    codeElementToRename, nameTuple.Item1, nameTuple.Item2, generatedItemPath,
                                    changeProposals, objectSearchLanguage);
                            }

                            // Now sort the change proposals by filename so that we can return a list of file changes
                            foreach (var changeProposal in changeProposals)
                            {
                                FileChange fileChange;
                                HashSet <ChangeProposal> fileChangeProposals;

                                if (fileChangeMap.TryGetValue(changeProposal.FileName, out fileChange))
                                {
                                    fileChangeProposals = fileChange.ChangeList.Values.First();
                                }
                                else
                                {
                                    fileChange          = new FileChange(changeProposal.FileName);
                                    fileChangeProposals = new HashSet <ChangeProposal>();
                                    fileChange.ChangeList.Add(
                                        new KeyValuePair <RefactoringPreviewGroup, HashSet <ChangeProposal> >(
                                            new RefactoringPreviewGroup(Resources.RefactorPreviewGroupName), fileChangeProposals));
                                    fileChangeMap.Add(changeProposal.FileName, fileChange);
                                }

                                if (!fileChangeProposals.Contains(changeProposal))
                                {
                                    fileChangeProposals.Add(changeProposal);
                                }
                            }
                        }
                    }
                }
            }

            return(fileChangeMap.Values.ToList());
        }