Пример #1
0
 /// <summary>
 /// Creates a new instance of the <see cref="WindowsFileImporter"/> class.
 /// </summary>
 public WindowsFileImporter(ISolution solution, IUriReferenceService uriService, IProductElement currentElement, string targetPath)
 {
     this.solution       = solution;
     this.uriService     = uriService;
     this.currentElement = currentElement;
     this.targetPath     = targetPath;
 }
        public static T TryResolveUri <T>(this IUriReferenceService uriReferenceService, Uri uri) where T : class
        {
            Guard.NotNull(() => uriReferenceService, uriReferenceService);

            try
            {
                return(uriReferenceService.ResolveUri <T>(uri));
            }
            catch (UriFormatException)
            {
                return(null);
            }
            catch (InvalidOperationException)
            {
                return(null);
            }
            catch (ArgumentException)
            {
                return(null);
            }
            catch (NotSupportedException)
            {
                return(null);
            }
            catch (COMException)
            {
                return(null);
            }
        }
Пример #3
0
 public UnfoldParentResolver(ISolution solution, IUriReferenceService uriService, IProductElement currentElement, IVsTemplate template)
 {
     this.solution       = solution;
     this.uriService     = uriService;
     this.currentElement = currentElement;
     this.theTemplate    = template;
 }
Пример #4
0
        public static GenerateProductCodeCommand CreateTempGenerateCodeCommand(this IProductElement element,
                                                                               IServiceProvider sp
                                                                               , string targetFileName
                                                                               , string targetPath
                                                                               , string templateUri
                                                                               , string namePrefix  = "GenerateCode"
                                                                               , string buildAction = "Compile")
        {
            var                  guid           = Guid.NewGuid();
            ISolution            solution       = sp.TryGetService <ISolution>();
            IPatternManager      patternManager = sp.TryGetService <IPatternManager>();
            IUriReferenceService uriService     = sp.TryGetService <IUriReferenceService>();
            var                  command        = new GenerateProductCodeCommand
            {
                TargetBuildAction  = buildAction,
                TargetCopyToOutput = CopyToOutput.DoNotCopy,
                Settings           = new EmptySettings {
                    Name = String.Format("{0}{1}", namePrefix, guid.ToString()), Id = guid
                },
                PatternManager  = patternManager,
                UriService      = uriService,
                Solution        = solution,
                ServiceProvider = sp,
                TargetFileName  = targetFileName,
                TargetPath      = targetPath,
                CurrentElement  = element,
                TemplateUri     = new Uri(templateUri)
            };

            return(command);
        }
        public static void RemoveArtifactLinks(this IProductElement element, IUriReferenceService uriService, ISolution solution)
        {
            using (new MouseCursor(System.Windows.Input.Cursors.Wait))
            {
                foreach (var referenceLink in element.References)
                {
                    var item = default(IItemContainer);
                    try
                    {
                        item = uriService.ResolveUri<IItemContainer>(new Uri(referenceLink.Value));
                    }
                    catch { }

                    if (item != null)
                    {
                        var physicalPath = item.PhysicalPath;

                        if (item.Kind == ItemKind.Project)
                        {
                            solution.As<Solution>().Remove(item.As<Project>());
                            System.IO.Directory.Delete(Path.GetDirectoryName(physicalPath), true);
                        }
                        else if (item.Kind == ItemKind.Item)
                        {
                            item.As<ProjectItem>().Delete();
                            System.IO.File.Delete(physicalPath);
                        }
                    }
                }
            }
        }
Пример #6
0
 public UnfoldParentResolver(ISolution solution, IUriReferenceService uriService, IProductElement currentElement, IVsTemplate template)
 {
     this.solution = solution;
     this.uriService = uriService;
     this.currentElement = currentElement;
     this.theTemplate = template;
 }
Пример #7
0
        public static void RemoveArtifactLinks(this IProductElement element, IUriReferenceService uriService, ISolution solution)
        {
            using (new MouseCursor(System.Windows.Input.Cursors.Wait))
            {
                foreach (var referenceLink in element.References)
                {
                    var item = default(IItemContainer);
                    try
                    {
                        item = uriService.ResolveUri <IItemContainer>(new Uri(referenceLink.Value));
                    }
                    catch { }

                    if (item != null)
                    {
                        var physicalPath = item.PhysicalPath;

                        if (item.Kind == ItemKind.Project)
                        {
                            solution.As <Solution>().Remove(item.As <Project>());
                            System.IO.Directory.Delete(Path.GetDirectoryName(physicalPath), true);
                        }
                        else if (item.Kind == ItemKind.Item)
                        {
                            item.As <ProjectItem>().Delete();
                            System.IO.File.Delete(physicalPath);
                        }
                    }
                }
            }
        }
Пример #8
0
 /// <summary>
 /// Creates a new instance of the <see cref="WindowsFileImporter"/> class.
 /// </summary>
 public WindowsFileImporter(ISolution solution, IUriReferenceService uriService, IProductElement currentElement, string targetPath)
 {
     this.solution = solution;
     this.uriService = uriService;
     this.currentElement = currentElement;
     this.targetPath = targetPath;
 }
        public void Initialize()
        {
            VsIdeTestHostContext.Dte.Solution.Open(this.PathTo(@"Runtime.IntegrationTests.Content\PackUriProvider\TestProviders.sln"));

            this.solution = VsIdeTestHostContext.ServiceProvider.GetService<ISolution>();
            this.project = this.solution.Find<IProject>().First();
            this.service = VsIdeTestHostContext.ServiceProvider.GetService<IUriReferenceService>();
        }
Пример #10
0
        public void Initialize()
        {
            VsIdeTestHostContext.Dte.Solution.Open(this.PathTo(@"Runtime.IntegrationTests.Content\PackUriProvider\TestProviders.sln"));

            this.solution = VsIdeTestHostContext.ServiceProvider.GetService <ISolution>();
            this.project  = this.solution.Find <IProject>().First();
            this.service  = VsIdeTestHostContext.ServiceProvider.GetService <IUriReferenceService>();
        }
Пример #11
0
        /// <summary>
        /// Creates a new instance of the <see cref="PathResolver"/> class.
        /// </summary>
        public PathResolver(object context, IUriReferenceService uriService, string path = null, string fileName = null)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => uriService, uriService);

            this.Context    = context;
            this.UriService = uriService;

            this.Path     = path;
            this.FileName = fileName;
        }
Пример #12
0
 private static void SetSelectedItem(ITypeDescriptorContext context, ISolutionPicker picker, IUriReferenceService uriService, object value)
 {
     var uri = value as string;
     if (!string.IsNullOrEmpty(uri))
     {
         var item = uriService.TryResolveUri<IItemContainer>(new Uri(uri));
         if (item != null)
         {
             picker.SelectedItem = item;
         }
     }
 }
Пример #13
0
        public GuidanceBrowserViewModel(GuidanceBrowserContext context, IServiceProvider serviceProvider)
        {
            Guard.NotNull(() => context, context);
            Guard.NotNull(() => serviceProvider, serviceProvider);

            this.context         = context;
            this.serviceProvider = serviceProvider;

            this.NavigationCommand   = new RelayCommand <Uri>(uri => this.Navigate(uri));
            this.guidanceManager     = context.GuidanceManager;
            this.uriReferenceService = context.UriReferenceService;
        }
Пример #14
0
 public TemplateMappings(IUriReferenceService uriService)
 {
     var vsixUri = new Uri(VsixExtensionUriProvider.UriSchemeName + "://" + ToolkitConstants.VsixIdentifier);
     var extension = uriService.ResolveUri<IInstalledExtension>(vsixUri);
     if (extension == null)
     {
         tracer.Warn("Cannot find installed extension for toolkit {0}", ToolkitConstants.VsixIdentifier);
     }
     else
     {
         SetupMappings(extension.InstallPath);
     }
 }
Пример #15
0
        public TemplateMappings(IUriReferenceService uriService)
        {
            var vsixUri   = new Uri(VsixExtensionUriProvider.UriSchemeName + "://" + ToolkitConstants.VsixIdentifier);
            var extension = uriService.ResolveUri <IInstalledExtension>(vsixUri);

            if (extension == null)
            {
                tracer.Warn("Cannot find installed extension for toolkit {0}", ToolkitConstants.VsixIdentifier);
            }
            else
            {
                SetupMappings(extension.InstallPath);
            }
        }
Пример #16
0
        private void EnsureServices(ITypeDescriptorContext context)
        {
            if (this.uriReferenceService == null)
            {
                this.uriReferenceService = context.GetService <IUriReferenceService>();

                if (this.uriReferenceService == null)
                {
                    throw new NotSupportedException(string.Format(
                                                        CultureInfo.CurrentCulture,
                                                        Resources.SolutionItemUriConverter_MissingService,
                                                        typeof(IUriReferenceService)));
                }
            }
        }
        public static void RenameArtifactLinks(this IProductElement element, IUriReferenceService uriService, string currentName, string newName)
        {
            foreach (var referenceLink in element.References)
            {
                var item = default(IItemContainer);
                try
                {
                    item = uriService.ResolveUri<IItemContainer>(new Uri(referenceLink.Value));
                }
                catch { }

                if (item != null &&
                    item.Kind == ItemKind.Item &&
                    Path.GetFileNameWithoutExtension(item.Name) != newName)
                {
                    item.As<ProjectItem>().Name = item.Name.Replace(currentName, newName);
                }
            }
        }
Пример #18
0
        public static void RenameArtifactLinks(this IProductElement element, IUriReferenceService uriService, string currentName, string newName)
        {
            foreach (var referenceLink in element.References)
            {
                var item = default(IItemContainer);
                try
                {
                    item = uriService.ResolveUri <IItemContainer>(new Uri(referenceLink.Value));
                }
                catch { }

                if (item != null &&
                    item.Kind == ItemKind.Item &&
                    Path.GetFileNameWithoutExtension(item.Name) != newName)
                {
                    item.As <ProjectItem>().Name = item.Name.Replace(currentName, newName);
                }
            }
        }
Пример #19
0
        public static IItemContainer Resolve(this IReference reference, IUriReferenceService referenceService)
        {
            Guard.NotNull(() => reference, reference);
            Guard.NotNull(() => referenceService, referenceService);

            if (String.IsNullOrEmpty(reference.Value))
            {
                return null;
            }

            // Ensure we can create a valid Uri from the reference value
            Uri referenceUri;
            if (Uri.TryCreate(reference.Value, UriKind.RelativeOrAbsolute, out referenceUri) == false)
            {
                return null;
            }

            // Get the solution item
            return referenceService.TryResolveUri<IItemContainer>(referenceUri);
        }
Пример #20
0
        public static IItemContainer Resolve(this IReference reference, IUriReferenceService referenceService)
        {
            Guard.NotNull(() => reference, reference);
            Guard.NotNull(() => referenceService, referenceService);

            if (String.IsNullOrEmpty(reference.Value))
            {
                return(null);
            }

            // Ensure we can create a valid Uri from the reference value
            Uri referenceUri;

            if (Uri.TryCreate(reference.Value, UriKind.RelativeOrAbsolute, out referenceUri) == false)
            {
                return(null);
            }

            // Get the solution item
            return(referenceService.TryResolveUri <IItemContainer>(referenceUri));
        }
        public static void CloseDocuments(this IProductElement element, IUriReferenceService uriService, EnvDTE.Documents EnvDTEDocuments)
        {
            var documents = EnvDTEDocuments.OfType<EnvDTE.Document>();

            foreach (var referenceLink in element.References)
            {
                var item = default(IItemContainer);
                try
                {
                    item = uriService.ResolveUri<IItemContainer>(new Uri(referenceLink.Value));
                }
                catch { }

                if (item != null &&
                    item.Kind == ItemKind.Item &&
                    documents.Any (x => x.FullName == item.PhysicalPath))
                {
                    documents.First(x => x.FullName == item.PhysicalPath).Close(vsSaveChanges.vsSaveChangesYes);
                }
            }
        }
        public static void CloseDocuments(this IProductElement element, IUriReferenceService uriService, EnvDTE.Documents EnvDTEDocuments)
        {
            var documents = EnvDTEDocuments.OfType <EnvDTE.Document>();

            foreach (var referenceLink in element.References)
            {
                var item = default(IItemContainer);
                try
                {
                    item = uriService.ResolveUri <IItemContainer>(new Uri(referenceLink.Value));
                }
                catch { }

                if (item != null &&
                    item.Kind == ItemKind.Item &&
                    documents.Any(x => x.FullName == item.PhysicalPath))
                {
                    documents.First(x => x.FullName == item.PhysicalPath).Close(vsSaveChanges.vsSaveChangesYes);
                }
            }
        }
Пример #23
0
        public void Rename(IUriReferenceService uriService, RefactoringManager refactoringManager)
        {
            var element = this.As <IProductElement>();
            var app     = element.Root.As <IApplication>();

            // Remove existing links to Endpoints
            foreach (var component in this.Components.Component)
            {
                foreach (var endpoint in component.DeployedTo)
                {
                    component.RemoveLinks(endpoint);
                }
            }

            // Perform renaming
            var renameNamespaces = new Dictionary <string, string>();

            renameNamespaces.Add(String.Format("{0}.{1}", app.InstanceName, this.OriginalInstanceName),
                                 String.Format("{0}.{1}", app.InstanceName, this.InstanceName));
            renameNamespaces.Add(String.Format("{0}.{1}.{2}", app.InstanceName, app.ProjectNameInternalMessages, this.OriginalInstanceName),
                                 String.Format("{0}.{1}.{2}", app.InstanceName, app.ProjectNameInternalMessages, this.InstanceName));
            renameNamespaces.Add(String.Format("{0}.{1}.{2}", app.InstanceName, app.ProjectNameContracts, this.OriginalInstanceName),
                                 String.Format("{0}.{1}.{2}", app.InstanceName, app.ProjectNameContracts, this.InstanceName));
            renameNamespaces.Add(String.Format("Console.WriteLine(\"{0} received \" + message.GetType().Name);", this.OriginalInstanceName),
                                 String.Format("Console.WriteLine(\"{0} received \" + message.GetType().Name);", this.InstanceName));


            refactoringManager.RenameNamespaces(this.OriginalInstanceName, this.InstanceName, renameNamespaces);
            element.RenameArtifactLinks(uriService, this.OriginalInstanceName, this.InstanceName);

            // Restore existing links to Endpoints
            foreach (var component in this.Components.Component)
            {
                foreach (var endpoint in component.DeployedTo)
                {
                    component.AddLinks(endpoint);
                }
            }
        }
Пример #24
0
        public void Rename(IUriReferenceService uriService, RefactoringManager refactoringManager)
        {
            var element = this.As<IProductElement>();
            var app = element.Root.As<IApplication>();

            // Remove existing links to Endpoints
            foreach (var component in this.Components.Component)
            {
                foreach (var endpoint in component.DeployedTo)
                {
                    component.RemoveLinks(endpoint);
                }
            }

            // Perform renaming
            var renameNamespaces = new Dictionary<string, string>();
            renameNamespaces.Add(String.Format("{0}.{1}", app.InstanceName, this.OriginalInstanceName),
                                 String.Format("{0}.{1}", app.InstanceName, this.InstanceName));
            renameNamespaces.Add(String.Format("{0}.{1}.{2}", app.InstanceName, app.ProjectNameInternalMessages, this.OriginalInstanceName),
                                 String.Format("{0}.{1}.{2}", app.InstanceName, app.ProjectNameInternalMessages, this.InstanceName));
            renameNamespaces.Add(String.Format("{0}.{1}.{2}", app.InstanceName, app.ProjectNameContracts, this.OriginalInstanceName),
                                 String.Format("{0}.{1}.{2}", app.InstanceName, app.ProjectNameContracts, this.InstanceName));
            renameNamespaces.Add(String.Format("Console.WriteLine(\"{0} received \" + message.GetType().Name);", this.OriginalInstanceName),
                                 String.Format("Console.WriteLine(\"{0} received \" + message.GetType().Name);", this.InstanceName));

            refactoringManager.RenameNamespaces(this.OriginalInstanceName, this.InstanceName, renameNamespaces);
            element.RenameArtifactLinks(uriService, this.OriginalInstanceName, this.InstanceName);

            // Restore existing links to Endpoints
            foreach (var component in this.Components.Component)
            {
                foreach (var endpoint in component.DeployedTo)
                {
                    component.AddLinks(endpoint);
                }
            }
        }
Пример #25
0
 private static void SetSelectedItem(ITypeDescriptorContext context, ISolutionPicker picker, IUriReferenceService uriService, DesignProperty prop)
 {
     if (prop != null)
     {
         var value = prop.GetValue().ToString();
         if (!String.IsNullOrEmpty(value))
         {
             var item = uriService.TryResolveUri<IItemContainer>(new Uri(value));
             if (item != null)
             {
                 picker.SelectedItem = item;
             }
         }
     }
 }
 public void Initialize()
 {
     this.service = VsIdeTestHostContext.ServiceProvider.GetService<IUriReferenceService>();
 }
Пример #27
0
 /// <summary>
 /// Creates a new instance of the <see cref="VsTemplateFileImporter"/> class.
 /// </summary>
 public VsTemplateFileImporter(ISolution solution, IUriReferenceService uriService, IProductElement currentElement, string targetPath)
     : base(solution, uriService, currentElement, targetPath)
 {
     this.currentElement = currentElement;
 }
        public static bool RenameElement(this IProductElement element, IToolkitElement toolkitElement, IUriReferenceService uriService, RefactoringManager refactoringManager)
        {
            using (new MouseCursor(System.Windows.Input.Cursors.Wait))
            {
                var renameRefactoring = toolkitElement as IRenameRefactoring;
                if (renameRefactoring != null)
                {
                    refactoringManager.RenameClass(renameRefactoring.Namespace, renameRefactoring.OriginalInstanceName, renameRefactoring.InstanceName);
                    element.RenameArtifactLinks(uriService, renameRefactoring.OriginalInstanceName, renameRefactoring.InstanceName);
                    return true;
                }

                var renameRefactoringNamespace = toolkitElement as IRenameRefactoringNamespace;
                if (renameRefactoringNamespace != null && toolkitElement.InstanceName != "" && toolkitElement is IService)
                {
                    var service = toolkitElement as IService;
                    service.Rename(uriService, refactoringManager);

                    //MessageBox.Show("The Service renaming is almost done. Please, re-open the solution to finish with the renaming.", "Rename Service", MessageBoxButton.OK);
                    return true;
                }

                var renameRefactoringNotSupported = toolkitElement as IRenameRefactoringNotSupported;
                if (renameRefactoringNotSupported != null && toolkitElement.InstanceName != "")
                {
                    var result = MessageBox.Show("This element doesn't support code refactoring, you will need to update your code manually. Do you want to do the renaming anyway?", "Rename element", MessageBoxButton.YesNo);
                    return result == MessageBoxResult.Yes;
                }

                return true;
            }
        }
Пример #29
0
        /// <summary>
        /// Gets the path to the guidance document from the current element.
        /// </summary>
        /// <remarks>
        /// Returns the first artifact link with a *.doc extension of the current element.
        /// </remarks>
        public static string GetDocumentPath(ITracer tracer, IProductElement element, IUriReferenceService uriService)
        {
            // Return path of first reference
            var references = SolutionArtifactLinkReference.GetResolvedReferences(element, uriService);

            if (!references.Any())
            {
                tracer.Warn(String.Format(CultureInfo.CurrentCulture,
                                          Resources.GuidanceDocumentPathProvider_NoLinksFound, element.InstanceName));
                return(string.Empty);
            }
            else
            {
                var reference = references.FirstOrDefault(r => r.PhysicalPath.EndsWith(GuidanceDocumentExtension));
                if (reference == null)
                {
                    tracer.Warn(String.Format(CultureInfo.CurrentCulture,
                                              Resources.GuidanceDocumentPathProvider_NoDocumentLinkFound, element.InstanceName));
                    return(string.Empty);
                }
                else
                {
                    tracer.Info(String.Format(CultureInfo.CurrentCulture,
                                              Resources.GuidanceDocumentPathProvider_LinkFound, element.InstanceName, reference.PhysicalPath));
                    return(reference.PhysicalPath);
                }
            }
        }
Пример #30
0
 private static void SetSelectedItem(ITypeDescriptorContext context, ISolutionPicker picker, IUriReferenceService uriService, DesignProperty prop)
 {
     if (prop != null)
     {
         var value = prop.GetValue().ToString();
         if (!String.IsNullOrEmpty(value))
         {
             var item = uriService.TryResolveUri <IItemContainer>(new Uri(value));
             if (item != null)
             {
                 picker.SelectedItem = item;
             }
         }
     }
 }
Пример #31
0
        /// <summary>
        /// Resolves the current element paths and filename, and returns the item if exists.
        /// </summary>
        public static IItemContainer ResolveToSolutionItem <T>(object context, ISolution solution, IUriReferenceService uriService, string path = null, string fileName = null) where T : IItemContainer
        {
            // Resolve SourcePath
            var resolver = new PathResolver(context, uriService, path, fileName);

            if (resolver.TryResolve())
            {
                // Load file from solution
                var sourceFile = resolver.Path;
                return(solution.Find <T>(sourceFile).FirstOrDefault());
            }

            return(null);
        }
 public static IEnumerable <IItemContainer> GetResolvedReferences(IProductElement element, IUriReferenceService uriService)
 {
     return(GetResolvedReferences(element, uriService, r => true));
 }
        public static IEnumerable <Guid> GetResolvedReferences(IProductElement element, IUriReferenceService uriService, Func <IReference, bool> whereFilter)
        {
            Guard.NotNull(() => element, element);
            Guard.NotNull(() => uriService, uriService);
            Guard.NotNull(() => whereFilter, whereFilter);

            return(Enumerable.Empty <Guid>());
        }
 public void Initialize()
 {
     this.service = VsIdeTestHostContext.ServiceProvider.GetService <IUriReferenceService>();
 }
Пример #35
0
        internal static IItemContainer UnfoldTemplate(ISolution solution, IUriReferenceService uriService, IServiceProvider serviceProvider, IProductElement owner, UnfoldVsTemplateSettings settings, bool fromWizard)
        {
            var eventScope = new StoreEventBufferingScope();

            try
            {
                Guard.NotNull(() => solution, solution);
                Guard.NotNull(() => owner, owner);
                Guard.NotNull(() => settings, settings);

                var pathHelper  = new UnfoldPathHelper(solution);
                var templateUri = new Uri(settings.TemplateUri);

                // Resolve the designtime template
                tracer.Verbose(
                    Resources.UnfoldVsTemplateCommand_TraceResolvingTemplateUri, owner, settings.TemplateUri.ToString());
                var template = uriService.TryResolveUri <ITemplate>(templateUri);
                if (template == null)
                {
                    throw new FileNotFoundException(
                              string.Format(CultureInfo.CurrentCulture,
                                            Resources.UnfoldVsTemplateCommand_ErrorTemplateNotFound, templateUri), settings.TemplateUri.ToString());
                }

                // Resolve the vstemplate
                tracer.Verbose(
                    Resources.UnfoldVsTemplateCommand_TraceResolvingVsTemplateUri, owner, templateUri);
                var vsTemplate = uriService.ResolveUri <IVsTemplate>(templateUri);

                // Get the resolved instance name for the unfolded item
                var unfoldResolver = new UnfoldParentResolver(solution, uriService, owner, vsTemplate);
                unfoldResolver.ResolveParent(settings.TargetPath, settings.TargetFileName);
                var instanceName = unfoldResolver.FileName;
                if (settings.SanitizeName)
                {
                    instanceName = DataFormats.MakePreferredSolutionItemName(instanceName);
                }

                // Ensure name is unique (on disk)
                var solutionItemName = pathHelper.GetUniqueName(instanceName, vsTemplate, unfoldResolver.ParentItem);

                //TODO: We need to close the existing solution (if any) if template is a ProjectGroup
                // if (vsTemplate.Type == VsTemplateType.ProjectGroup).
                // Otherwise this will fail the unfold

                // Unfold the template
                var generatedItem = template.Unfold(unfoldResolver.ResolveExtension(solutionItemName), unfoldResolver.ParentItem);
                eventScope.Dispose();

                // Perhaps the template unfolded multiple items and none was identifed as the primary
                // (such as in a multi-item item template, with no non-fixed named items)
                if (generatedItem != null)
                {
                    // Prompt user to update element instance name (on name collision) if he is synching names,
                    // it doesn't make sense to correlate them otherwise
                    if (settings.SyncName)
                    {
                        if (!instanceName.Equals(solutionItemName, StringComparison.OrdinalIgnoreCase))
                        {
                            if (serviceProvider != null)
                            {
                                var shellService = serviceProvider.GetService <IVsUIShell>();
                                if (shellService != null)
                                {
                                    var result = shellService.ShowPrompt(
                                        Resources.UnfoldVsTemplateCommand_PromptToSyncNameTitle,
                                        string.Format(CultureInfo.CurrentCulture,
                                                      Resources.UnfoldVsTemplateCommand_PromptToSyncName,
                                                      instanceName, solutionItemName));
                                    if (result)
                                    {
                                        owner.InstanceName = solutionItemName;
                                    }
                                }
                                else
                                {
                                    owner.InstanceName = solutionItemName;
                                }
                            }
                            else
                            {
                                owner.InstanceName = solutionItemName;
                            }
                        }
                    }

                    if (!fromWizard)
                    {
                        tracer.Info(
                            Resources.UnfoldVsTemplateCommand_TraceAddReference, owner);

                        SolutionArtifactLinkReference
                        .AddReference(owner, uriService.CreateUri(generatedItem))
                        .Tag = BindingSerializer.Serialize(new ReferenceTag
                        {
                            Tag            = settings.Tag ?? string.Empty,
                            SyncNames      = settings.SyncName,
                            TargetFileName = settings.TargetFileName
                        });
                    }
                }
                return(generatedItem);
            }
            catch (WizardBackoutException) //cancel the unfold if wizard backout
            {
                tracer.Info(
                    Resources.UnfoldVsTemplateCommand_TraceWizardCancelled);
                owner.Delete();
                eventScope.Dispose();
                return(null);
            }
            catch (COMException comEx)
            {
                tracer.Error(
                    comEx, Resources.UnfoldVsTemplateCommand_TraceCOMException, owner.InstanceName, settings.TemplateUri);
                owner.Delete();
                eventScope.Dispose();
                throw;
            }
            catch (OperationCanceledException)
            {
                // This exception can be throw explicitly by author code
                // that wishes to cancel execution, with a friendly user
                // message, so we can pass this on as-is.
                throw;
            }
            catch (Exception ex) //cancel the unfold if another unexpected exception happened
            {
                tracer.Info(
                    Resources.UnfoldVsTemplateCommand_TraceUnexpectedException, owner.InstanceName, settings.TemplateUri);
                owner.Delete();
                eventScope.Dispose();

                throw new OperationCanceledException(string.Format(
                                                         CultureInfo.CurrentCulture,
                                                         Resources.UnfoldVsTemplateCommand_UnexpectedException,
                                                         settings.TemplateUri, owner.InstanceName, ex.Message));
            }
        }
Пример #36
0
        public static bool RenameElement(this IProductElement element, IToolkitElement toolkitElement, IUriReferenceService uriService, RefactoringManager refactoringManager)
        {
            using (new MouseCursor(System.Windows.Input.Cursors.Wait))
            {
                var renameRefactoring = toolkitElement as IRenameRefactoring;
                if (renameRefactoring != null)
                {
                    refactoringManager.RenameClass(renameRefactoring.Namespace, renameRefactoring.OriginalInstanceName, renameRefactoring.InstanceName);
                    element.RenameArtifactLinks(uriService, renameRefactoring.OriginalInstanceName, renameRefactoring.InstanceName);
                    return(true);
                }

                var renameRefactoringNamespace = toolkitElement as IRenameRefactoringNamespace;
                if (renameRefactoringNamespace != null && toolkitElement.InstanceName != "" && toolkitElement is IService)
                {
                    var service = toolkitElement as IService;
                    service.Rename(uriService, refactoringManager);

                    //MessageBox.Show("The Service renaming is almost done. Please, re-open the solution to finish with the renaming.", "Rename Service", MessageBoxButton.OK);
                    return(true);
                }

                var renameRefactoringNotSupported = toolkitElement as IRenameRefactoringNotSupported;
                if (renameRefactoringNotSupported != null && toolkitElement.InstanceName != "")
                {
                    var result = MessageBox.Show("This element doesn't support code refactoring, you will need to update your code manually. Do you want to do the renaming anyway?", "Rename element", MessageBoxButton.YesNo);
                    return(result == MessageBoxResult.Yes);
                }

                return(true);
            }
        }
        public static IEnumerable <IItemContainer> GetResolvedReferences(IProductElement element, IUriReferenceService uriService, Func <IReference, bool> whereFilter)
        {
            Guard.NotNull(() => element, element);
            Guard.NotNull(() => uriService, uriService);
            Guard.NotNull(() => whereFilter, whereFilter);

            return(GetReferenceValues(element, whereFilter)
                   .Select(reference => uriService.TryResolveUri <IItemContainer>(reference))
                   .Where(item => item != null));
        }
Пример #38
0
        internal static IItemContainer UnfoldTemplate(ISolution solution, IUriReferenceService uriService, IServiceProvider serviceProvider, IProductElement owner, UnfoldVsTemplateSettings settings, bool fromWizard)
        {
            var eventScope = new StoreEventBufferingScope();
            try
            {
                Guard.NotNull(() => solution, solution);
                Guard.NotNull(() => owner, owner);
                Guard.NotNull(() => settings, settings);

                var pathHelper = new UnfoldPathHelper(solution);
                var templateUri = new Uri(settings.TemplateUri);

                // Resolve the designtime template
                tracer.Verbose(
                    Resources.UnfoldVsTemplateCommand_TraceResolvingTemplateUri, owner, settings.TemplateUri.ToString());
                var template = uriService.TryResolveUri<ITemplate>(templateUri);
                if (template == null)
                {
                    throw new FileNotFoundException(
                        string.Format(CultureInfo.CurrentCulture,
                        Resources.UnfoldVsTemplateCommand_ErrorTemplateNotFound, templateUri), settings.TemplateUri.ToString());
                }

                // Resolve the vstemplate
                tracer.Verbose(
                    Resources.UnfoldVsTemplateCommand_TraceResolvingVsTemplateUri, owner, templateUri);
                var vsTemplate = uriService.ResolveUri<IVsTemplate>(templateUri);

                // Get the resolved instance name for the unfolded item
                var unfoldResolver = new UnfoldParentResolver(solution, uriService, owner, vsTemplate);
                unfoldResolver.ResolveParent(settings.TargetPath, settings.TargetFileName);
                var instanceName = unfoldResolver.FileName;
                if (settings.SanitizeName)
                {
                    instanceName = DataFormats.MakePreferredSolutionItemName(instanceName);
                }

                // Ensure name is unique (on disk)
                var solutionItemName = pathHelper.GetUniqueName(instanceName, vsTemplate, unfoldResolver.ParentItem);

                //TODO: We need to close the existing solution (if any) if template is a ProjectGroup 
                // if (vsTemplate.Type == VsTemplateType.ProjectGroup).
                // Otherwise this will fail the unfold

                // Unfold the template
                var generatedItem = template.Unfold(unfoldResolver.ResolveExtension(solutionItemName), unfoldResolver.ParentItem);
                eventScope.Dispose();

                // Perhaps the template unfolded multiple items and none was identifed as the primary
                // (such as in a multi-item item template, with no non-fixed named items)
                if (generatedItem != null)
                {
                    // Prompt user to update element instance name (on name collision) if he is synching names, 
                    // it doesn't make sense to correlate them otherwise
                    if (settings.SyncName)
                    {
                        if (!instanceName.Equals(solutionItemName, StringComparison.OrdinalIgnoreCase))
                        {
                            if (serviceProvider != null)
                            {
                                var shellService = serviceProvider.GetService<IVsUIShell>();
                                if (shellService != null)
                                {
                                    var result = shellService.ShowPrompt(
                                        Resources.UnfoldVsTemplateCommand_PromptToSyncNameTitle,
                                        string.Format(CultureInfo.CurrentCulture,
                                            Resources.UnfoldVsTemplateCommand_PromptToSyncName,
                                            instanceName, solutionItemName));
                                    if (result)
                                    {
                                        owner.InstanceName = solutionItemName;
                                    }
                                }
                                else
                                {
                                    owner.InstanceName = solutionItemName;
                                }
                            }
                            else
                            {
                                owner.InstanceName = solutionItemName;
                            }
                        }
                    }

                    if (!fromWizard)
                    {
                        tracer.Info(
                            Resources.UnfoldVsTemplateCommand_TraceAddReference, owner);

                        SolutionArtifactLinkReference
                            .AddReference(owner, uriService.CreateUri(generatedItem))
                            .Tag = BindingSerializer.Serialize(new ReferenceTag
                        {
                            Tag = settings.Tag ?? string.Empty,
                            SyncNames = settings.SyncName,
                            TargetFileName = settings.TargetFileName
                        });
                    }
                }
                return generatedItem;
            }
            catch (WizardBackoutException) //cancel the unfold if wizard backout
            {
                tracer.Info(
                    Resources.UnfoldVsTemplateCommand_TraceWizardCancelled);
                owner.Delete();
                eventScope.Dispose();
                return null;
            }
            catch (COMException comEx)
            {
                tracer.Error(
                    comEx, Resources.UnfoldVsTemplateCommand_TraceCOMException, owner.InstanceName, settings.TemplateUri);
                owner.Delete();
                eventScope.Dispose();
                throw;
            }
            catch (OperationCanceledException)
            {
                // This exception can be throw explicitly by author code 
                // that wishes to cancel execution, with a friendly user 
                // message, so we can pass this on as-is.
                throw;
            }
            catch (Exception ex) //cancel the unfold if another unexpected exception happened
            {
                tracer.Info(
                    Resources.UnfoldVsTemplateCommand_TraceUnexpectedException, owner.InstanceName, settings.TemplateUri);
                owner.Delete();
                eventScope.Dispose();

                throw new OperationCanceledException(string.Format(
                    CultureInfo.CurrentCulture,
                    Resources.UnfoldVsTemplateCommand_UnexpectedException,
                    settings.TemplateUri, owner.InstanceName, ex.Message));
            }
        }
Пример #39
0
        private static void SetSelectedItem(ITypeDescriptorContext context, ISolutionPicker picker, IUriReferenceService uriService, object value)
        {
            var uri = value as string;

            if (!string.IsNullOrEmpty(uri))
            {
                var item = uriService.TryResolveUri <ResourcePack>(new Uri(uri));
                if (item != null)
                {
                    if (item.Type == ResourcePackType.ProjectItem)
                    {
                        picker.SelectedItem = item.GetItem();
                    }
                }
            }
        }
        private void EnsureServices(ITypeDescriptorContext context)
        {
            if (this.uriReferenceService == null)
            {
                this.uriReferenceService = context.GetService<IUriReferenceService>();

                if (this.uriReferenceService == null)
                {
                    throw new NotSupportedException(string.Format(
                        CultureInfo.CurrentCulture,
                        Resources.SolutionItemUriConverter_MissingService,
                        typeof(IUriReferenceService)));
                }
            }
        }
Пример #41
0
 /// <summary>
 /// Creates a new instance of the <see cref="VsTemplateFileImporter"/> class.
 /// </summary>
 public VsTemplateFileImporter(ISolution solution, IUriReferenceService uriService, IProductElement currentElement, string targetPath)
     : base(solution, uriService, currentElement, targetPath)
 {
     this.currentElement = currentElement;
 }
Пример #42
0
 private static void SetSelectedItem(ITypeDescriptorContext context, ISolutionPicker picker, IUriReferenceService uriService, object value)
 {
     var uri = value as string;
     if (!string.IsNullOrEmpty(uri))
     {
         var item = uriService.TryResolveUri<ResourcePack>(new Uri(uri));
         if (item != null)
         {
             if (item.Type == ResourcePackType.ProjectItem)
             {
                 picker.SelectedItem = item.GetItem();
             }
         }
     }
 }
Пример #43
0
 private static void SetSelectedItem(ITypeDescriptorContext context, ISolutionPicker picker, IUriReferenceService uriService, string uri)
 {
     if (!string.IsNullOrEmpty(uri))
     {
         var item = uriService.TryResolveUri <IItemContainer>(new Uri(uri));
         if (item != null)
         {
             picker.SelectedItem = item;
         }
     }
 }
Пример #44
-1
 /// <summary>
 /// Gets the path to the guidance document from the current element.
 /// </summary>
 /// <remarks>
 /// Returns the first artifact link with a *.doc extension of the current element.
 /// </remarks>
 public static string GetDocumentPath(ITracer tracer, IProductElement element, IUriReferenceService uriService)
 {
     // Return path of first reference
     var references = SolutionArtifactLinkReference.GetResolvedReferences(element, uriService);
     if (!references.Any())
     {
         tracer.Warn(String.Format(CultureInfo.CurrentCulture,
             Resources.GuidanceDocumentPathProvider_NoLinksFound, element.InstanceName));
         return string.Empty;
     }
     else
     {
         var reference = references.FirstOrDefault(r => r.PhysicalPath.EndsWith(GuidanceDocumentExtension));
         if (reference == null)
         {
             tracer.Warn(String.Format(CultureInfo.CurrentCulture,
                 Resources.GuidanceDocumentPathProvider_NoDocumentLinkFound, element.InstanceName));
             return string.Empty;
         }
         else
         {
             tracer.Info(String.Format(CultureInfo.CurrentCulture,
                 Resources.GuidanceDocumentPathProvider_LinkFound, element.InstanceName, reference.PhysicalPath));
             return reference.PhysicalPath;
         }
     }
 }