public bool MoveToFirstPage (SolutionTemplate template, ProjectCreateParameters parameters)
		{
			Reset ();

			if (!template.HasWizard) {
				return false;
			}

			CurrentWizard = GetWizard (template.Wizard);
			if (CurrentWizard == null) {
				LoggingService.LogError ("Unable to find project template wizard '{0}'.", template.Wizard);
				return false;
			}

			CurrentWizard.Parameters = parameters;
			CurrentWizard.UpdateParameters (template);
			IsFirstPage = true;
			CurrentPageNumber = 1;

			if (CurrentWizard.TotalPages == 0) {
				IsLastPage = true;
				return false;
			}

			CurrentWizardPage = GetCurrentWizardPage ();

			IsLastPage = CurrentWizard.TotalPages == 1;

			return true;
		}
		SolutionTemplate AddTemplate (string id, string category)
		{
			var template = new SolutionTemplate (id, id, "icon-id") {
				Category = category
			};
			templates.Add (template);
			return template;
		}
		void CreateProvider ()
		{
			template = new SolutionTemplate ("id", "name", "icon");
			template.Wizard = "wizard-id";
			parameters = new ProjectCreateParameters ();
			wizard = new TestableTemplateWizard ();
			provider = new TestableTemplateWizardProvider ();
			wizard = provider.Wizard;
		}
		public void AddTemplate (SolutionTemplate template)
		{
			SolutionTemplate groupTemplate = templates.Find (t => t.IsGroupMatch (template));
			if (groupTemplate != null) {
				groupTemplate.AddGroupTemplate (template);
			} else {
				templates.Add (template);
			}
		}
Exemplo n.º 5
0
        Image GetImageFile(SolutionTemplate template)
        {
            if (template.HasImageFile)
            {
                Image image = Image.FromFile(template.ImageFile);

                if (image != null)
                {
                    fileImages [template.Id] = image;
                    return(image);
                }
            }
            return(null);
        }
Exemplo n.º 6
0
        public ProcessedTemplateResult ProcessTemplate(SolutionTemplate template, NewProjectConfiguration config, SolutionFolder parentFolder)
        {
            IProjectTemplatingProvider provider = GetTemplatingProviderForTemplate(template);

            if (provider != null)
            {
                var result = provider.ProcessTemplate(template, config, parentFolder);
                if (result.WorkspaceItems.Any())
                {
                    RecentTemplates.AddTemplate(template);
                }
                return(result);
            }
            return(null);
        }
Exemplo n.º 7
0
        public void GetCategorizedTemplates_OneTemplateTwoTopLevelCategories_EmptyTopLevelCategoryIsRemoved()
        {
            CreateCategories("android", "app", "general");
            CreateCategories("ios", "app", "general");
            CreateCategorizer();
            SolutionTemplate template = AddTemplate("template-id", "android/app/general");

            CategorizeTemplates();

            TemplateCategory appCategory     = categorizedTemplates.First().Categories.First();
            TemplateCategory generalCategory = appCategory.Categories.First();

            Assert.That(generalCategory.Templates.ToList(), Contains.Item(template));
            Assert.AreEqual(1, categorizedTemplates.Count);
            Assert.AreEqual(1, appCategory.Categories.Count());
        }
Exemplo n.º 8
0
        RecentItem CreateRecentItem(SolutionTemplate template)
        {
            var mime         = "application/vnd.monodevelop.template";
            var uri          = templateUriScheme;
            var categoryPath = template.Category;

            if (!string.IsNullOrEmpty(categoryPath))
            {
                uri += categoryPath + "/";
            }
            uri += template.Id;
            return(new RecentItem(uri, mime, templateGroup)
            {
                Private = template.Name
            });
        }
Exemplo n.º 9
0
        TemplateCategory GetCategory(SolutionTemplate template)
        {
            TemplateCategory match = GetCategory(template, categories);

            if (match != null)
            {
                return(match);
            }
            else if (defaultCategory != null)
            {
                LogUsingDefaultCategory(template);

                return(defaultCategory);
            }
            return(null);
        }
Exemplo n.º 10
0
        public void GetCategorizedTemplates_TemplateUsesGoogleGlassLegacyCategory_TemplateIsMappedToNewCategories()
        {
            TemplateCategory topLevelCategory    = AddTemplateCategory("android");
            TemplateCategory secondLevelCategory = AddTemplateCategory("app", topLevelCategory);
            TemplateCategory category            = AddTemplateCategory("general", secondLevelCategory);

            category.MappedCategories = "C#/Glass";
            CreateCategorizer();
            SolutionTemplate template = AddTemplate("template-id", "C#/Glass");

            CategorizeTemplates();

            TemplateCategory appCategory     = categorizedTemplates.First().Categories.First();
            TemplateCategory generalCategory = appCategory.Categories.First();

            Assert.That(generalCategory.Templates.ToList(), Contains.Item(template));
        }
Exemplo n.º 11
0
        public void GetCategorizedTemplates_OneTemplateOneCategoryWithGroupConditionContainingExtraWhitespace_TemplateFilteredUsingTemplateParameters()
        {
            CreateCategories("android", "app", "general");
            CreateCategorizer();
            SolutionTemplate template = AddTemplate("template-id", "android/app/general");

            template.GroupId   = "console";
            template.Language  = "C#";
            template.Condition = " Device = MyDevice ";
            ProjectCreateParameters parameters = CreateParameters("Device", "MyDevice");

            CategorizeTemplates();

            TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First();
            SolutionTemplate firstTemplate   = generalCategory.Templates.FirstOrDefault();
            SolutionTemplate matchedTemplate = firstTemplate.GetTemplate("C#", parameters);

            Assert.AreEqual(template, matchedTemplate);
        }
Exemplo n.º 12
0
        public void GetCategorizedTemplates_TwoLegacyCategoriesMappedToNewCategory_TemplatesAreMappedToNewCategories()
        {
            TemplateCategory topLevelCategory    = AddTemplateCategory("android");
            TemplateCategory secondLevelCategory = AddTemplateCategory("app", topLevelCategory);
            TemplateCategory category            = AddTemplateCategory("general", secondLevelCategory);

            category.MappedCategories = "C#/Android;VBNet/Android";
            CreateCategorizer();
            SolutionTemplate csharpTemplate = AddTemplate("template-id", "C#/Android");
            SolutionTemplate vbnetTemplate  = AddTemplate("template-id2", "VBNet/Android");

            CategorizeTemplates();

            TemplateCategory appCategory     = categorizedTemplates.First().Categories.First();
            TemplateCategory generalCategory = appCategory.Categories.First();

            Assert.That(generalCategory.Templates.ToList(), Contains.Item(csharpTemplate));
            Assert.That(generalCategory.Templates.ToList(), Contains.Item(vbnetTemplate));
        }
Exemplo n.º 13
0
        Image GetCachedImage(SolutionTemplate template)
        {
            Image image = null;

            if (template.HasImageFile)
            {
                if (fileImages.TryGetValue(template.Id, out image))
                {
                    return(image);
                }
            }
            else
            {
                if (images.TryGetValue(template.ImageId, out image))
                {
                    return(image);
                }
            }
            return(null);
        }
        public void GetGroupedTemplates_TwoGroupedConsoleProjectTemplates_CanGetOtherTemplatesInGroupFromEitherTemplate()
        {
            CreateCategories("android", "app", "general");
            CreateCategorizer();
            SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general");

            template1.GroupId  = "console";
            template1.Language = "C#";
            SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general");

            template2.GroupId  = "console";
            template2.Language = "F#";
            CategorizeTemplates();

            var templatesInGroupForTemplate1 = template1.GetGroupedTemplates().Single();
            var templatesInGroupForTemplate2 = template2.GetGroupedTemplates().Single();

            Assert.AreEqual(template2, templatesInGroupForTemplate1);
            Assert.AreEqual(template1, templatesInGroupForTemplate2);
        }
Exemplo n.º 15
0
        public void GetCategorizedTemplates_OneTemplateTwoDifferentSecondLevelCategories_EmptySecondLevelCategoryIsRemoved()
        {
            TemplateCategory topLevelCategory    = AddTemplateCategory("android");
            TemplateCategory secondLevelCategory = AddTemplateCategory("app", topLevelCategory);

            AddTemplateCategory("general", secondLevelCategory);
            secondLevelCategory = AddTemplateCategory("tests", topLevelCategory);
            AddTemplateCategory("general", secondLevelCategory);
            CreateCategorizer();
            SolutionTemplate template = AddTemplate("template-id", "android/app/general");

            CategorizeTemplates();

            TemplateCategory androidCategory = categorizedTemplates.First();
            TemplateCategory appCategory     = androidCategory.Categories.First();
            TemplateCategory generalCategory = appCategory.Categories.First();

            Assert.That(generalCategory.Templates.ToList(), Contains.Item(template));
            Assert.AreEqual(1, categorizedTemplates.Count);
            Assert.AreEqual(1, androidCategory.Categories.Count());
        }
Exemplo n.º 16
0
        public void GetCategorizedTemplates_TwoTemplatesAndFilterShouldRemoveOneTemplate_TemplatesFiltered()
        {
            CreateCategories("android", "app", "general");
            CreateCategorizer(solutionTemplate => {
                return(solutionTemplate.Id == "template-id2");
            });
            SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general");

            template1.Language = "C#";
            SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general");

            template2.Language = "C#";

            CategorizeTemplates();

            TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First();
            SolutionTemplate firstTemplate   = generalCategory.Templates.FirstOrDefault();

            Assert.AreEqual(1, generalCategory.Templates.Count());
            Assert.AreEqual("template-id2", firstTemplate.Id);
        }
Exemplo n.º 17
0
        public void GetCategorizedTemplates_TwoTemplatesAndFilterByNewSolution_TemplatesFiltered()
        {
            CreateCategories("android", "app", "general");
            CreateCategorizer(ProjectTemplateCategorizer.MatchNewSolutionTemplates);
            SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general");

            template1.Language   = "C#";
            template1.Visibility = SolutionTemplateVisibility.NewProject;
            SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general");

            template2.Language   = "C#";
            template2.Visibility = SolutionTemplateVisibility.All;

            CategorizeTemplates();

            TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First();
            SolutionTemplate firstTemplate   = generalCategory.Templates.FirstOrDefault();

            Assert.AreEqual(1, generalCategory.Templates.Count());
            Assert.AreEqual("template-id2", firstTemplate.Id);
        }
Exemplo n.º 18
0
        public void GetCategorizedTemplates_TwoConsoleProjectTemplatesWithSameLanguageInSameGroup_TemplatesCombinedIntoOneGroupWarningLoggedAboutDuplicateLanguageOneLanguageShown()
        {
            CreateCategories("android", "app", "general");
            CreateCategorizer();
            SolutionTemplate template1 = AddTemplate("template-id1", "android/app/general");

            template1.GroupId  = "console";
            template1.Language = "C#";
            SolutionTemplate template2 = AddTemplate("template-id2", "android/app/general");

            template2.GroupId  = "console";
            template2.Language = "C#";

            CategorizeTemplates();

            TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First();
            SolutionTemplate template        = generalCategory.Templates.FirstOrDefault();

            Assert.That(template.AvailableLanguages, Contains.Item("C#"));
            Assert.AreEqual(1, template.AvailableLanguages.Count);
            Assert.AreEqual(1, generalCategory.Templates.Count());
        }
		public Image GetImage (SolutionTemplate template)
		{
			try {
				Image image = GetCachedImage (template);
				if (image != null) {
					return image;
				}

				image = GetImageFile (template);
				if (image == null) {
					image = GetImageFromId (template.ImageId);
				}

				if (image == null) {
					image = defaultImage;
				}

				return image;
			} catch (Exception ex) {
				LoggingService.LogError (String.Format ("Unable to load image for project template '{0}'.", template.Id), ex);
				return defaultImage;
			}
		}
Exemplo n.º 20
0
        public void GetCategorizedTemplates_OneTemplateOneCategoryWithGroupConditionAndParameterIsBoolean_TemplateFilteredUsingTemplateParameters()
        {
            CreateCategories("android", "app", "general");
            CreateCategorizer();
            SolutionTemplate template = AddTemplate("template-id", "android/app/general");

            template.GroupId   = "console";
            template.Language  = "C#";
            template.Condition = "SupportsSizeClasses=True";
            ProjectCreateParameters parameters = CreateParameters("SupportsSizeClasses", true.ToString());

            CategorizeTemplates();

            TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First();
            SolutionTemplate firstTemplate   = generalCategory.Templates.FirstOrDefault();
            SolutionTemplate matchedTemplate = firstTemplate.GetTemplate("C#", parameters);

            Assert.AreEqual(template, matchedTemplate);
            parameters.Clear();
            SolutionTemplate noMatchedTemplate = firstTemplate.GetTemplate("C#", parameters);

            Assert.IsNull(noMatchedTemplate);
        }
Exemplo n.º 21
0
        public void GetCategorizedTemplates_OneTemplateOneCategoryWithGroupConditionAndParameterNameAndValueHaveDifferentCase_TemplateFilteredUsingTemplateParametersIgnoringCase()
        {
            CreateCategories("android", "app", "general");
            CreateCategorizer();
            SolutionTemplate template = AddTemplate("template-id", "android/app/general");

            template.GroupId   = "console";
            template.Language  = "C#";
            template.Condition = "Device=MyDevice";
            ProjectCreateParameters parameters = CreateParameters("device", "mydevice");

            CategorizeTemplates();

            TemplateCategory generalCategory = categorizedTemplates.First().Categories.First().Categories.First();
            SolutionTemplate firstTemplate   = generalCategory.Templates.FirstOrDefault();
            SolutionTemplate matchedTemplate = firstTemplate.GetTemplate("C#", parameters);

            Assert.AreEqual(template, matchedTemplate);
            parameters = CreateParameters("device", "no-match");
            SolutionTemplate noMatchedTemplate = firstTemplate.GetTemplate("C#", parameters);

            Assert.IsNull(noMatchedTemplate);
        }
Exemplo n.º 22
0
        SolutionTemplate FromRecentItem(RecentItem item)
        {
            var templatePath = item.Uri.StartsWith(templateUriScheme, StringComparison.Ordinal) ? item.Uri.Substring(templateUriScheme.Length) : item.Uri;
            var parts        = templatePath.Split('/');
            var templateId   = parts [parts.Length - 1];
            SolutionTemplate recentTemplate = null;

            if (parts.Length > 1)
            {
                recentTemplate = IdeApp.Services.TemplatingService.GetTemplate(
                    (template) => template.Id == templateId,
                    (category) => parts.Length > 1 ? category.Id == parts[0] : true,
                    (category) => parts.Length > 2 ? category.Id == parts[1] : true
                    );
            }

            // fallback to global template lookup if no category matched
            // in this case the category is not guaranteed if a template is listed in more than one category
            if (recentTemplate == null)
            {
                recentTemplate = IdeApp.Services.TemplatingService.GetTemplate(templateId);
            }
            return(recentTemplate);
        }
Exemplo n.º 23
0
        public void GetCategorizedTemplates_TwoTemplateProvidersEachWithOneTemplateForTwoDifferentThirdLevelCategories_ThirdLevelCategoriresAreNotRemoved()
        {
            TemplateCategory topLevelCategory    = AddTemplateCategory("android");
            TemplateCategory secondLevelCategory = AddTemplateCategory("app", topLevelCategory);

            AddTemplateCategory("general", secondLevelCategory);
            AddTemplateCategory("tests", secondLevelCategory);
            CreateCategorizer();
            SolutionTemplate firstTemplateProviderTemplate = AddTemplate("first-provider-template-id", "android/app/general");

            categorizer.CategorizeTemplates(templates);
            templates.Clear();
            SolutionTemplate secondTemplateProviderTemplate = AddTemplate("second-provider-template-id", "android/app/tests");

            CategorizeTemplates();

            TemplateCategory appCategory     = categorizedTemplates.First().Categories.First();
            TemplateCategory generalCategory = appCategory.Categories.First(category => category.Id == "general");
            TemplateCategory testsCategory   = appCategory.Categories.First(category => category.Id == "tests");

            Assert.That(generalCategory.Templates.ToList(), Contains.Item(firstTemplateProviderTemplate));
            Assert.That(testsCategory.Templates.ToList(), Contains.Item(secondTemplateProviderTemplate));
            Assert.AreEqual(2, appCategory.Categories.Count());
        }
		IProjectTemplatingProvider GetTemplatingProviderForTemplate (SolutionTemplate template)
		{
			return templateProviders.FirstOrDefault (provider => provider.CanProcessTemplate (template));
		}
Exemplo n.º 25
0
        public async Task <ProcessedTemplateResult> ProcessTemplate(SolutionTemplate template, NewProjectConfiguration config, SolutionFolder parentFolder)
        {
            var solutionTemplate = (MicrosoftTemplateEngineSolutionTemplate)template;
            var parameters       = GetParameters(solutionTemplate, config);
            var templateInfo     = solutionTemplate.templateInfo;
            var workspaceItems   = new List <IWorkspaceFileObject> ();
            var result           = await templateCreator.InstantiateAsync(
                templateInfo,
                config.ProjectName,
                config.GetValidProjectName(),
                config.ProjectLocation,
                parameters,
                true,
                false,
                null
                );

            var filesToOpen = new List <string> ();

            foreach (var postAction in result.ResultInfo.PostActions)
            {
                switch (postAction.ActionId.ToString().ToUpper())
                {
                case "84C0DA21-51C8-4541-9940-6CA19AF04EE6":
                    if (postAction.Args.TryGetValue("files", out var files))
                    {
                        foreach (var fi in files.Split(';'))
                        {
                            if (int.TryParse(fi.Trim(), out var i))
                            {
                                filesToOpen.Add(Path.Combine(config.ProjectLocation, result.ResultInfo.PrimaryOutputs [i].Path));
                            }
                        }
                    }
                    break;

                case "D396686C-DE0E-4DE6-906D-291CD29FC5DE":
                    //TODO: Load project files
                    break;
                }
            }

            //TODO: Once templates support "D396686C-DE0E-4DE6-906D-291CD29FC5DE" use that to load projects
            foreach (var path in Directory.GetFiles(config.ProjectLocation, "*.*proj", SearchOption.AllDirectories))
            {
                if (path.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) || path.EndsWith(".fsproj", StringComparison.OrdinalIgnoreCase) || path.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase))
                {
                    workspaceItems.Add(await MonoDevelop.Projects.Services.ProjectService.ReadSolutionItem(new Core.ProgressMonitor(), path));
                }
            }

            var metadata = new Dictionary <string, string> ();

            metadata ["Id"]       = templateInfo.Identity;
            metadata ["Name"]     = templateInfo.Name;
            metadata ["Language"] = template.Language;
            metadata ["Platform"] = string.Join(";", templateInfo.Classifications);
            TemplateCounter.Inc(1, null, metadata);

            MicrosoftTemplateEngineProcessedTemplateResult processResult;

            if (parentFolder == null)
            {
                var solution = new Solution();
                solution.SetLocation(config.SolutionLocation, config.SolutionName);
                foreach (var item in workspaceItems.Cast <SolutionFolderItem> ())
                {
                    IConfigurationTarget configurationTarget = item as IConfigurationTarget;
                    if (configurationTarget != null)
                    {
                        foreach (ItemConfiguration configuration in configurationTarget.Configurations)
                        {
                            bool flag = false;
                            foreach (SolutionConfiguration solutionCollection in solution.Configurations)
                            {
                                if (solutionCollection.Id == configuration.Id)
                                {
                                    flag = true;
                                }
                            }
                            if (!flag)
                            {
                                solution.AddConfiguration(configuration.Id, true);
                            }
                        }
                    }
                    solution.RootFolder.AddItem(item);
                }
                processResult = new MicrosoftTemplateEngineProcessedTemplateResult(new [] { solution }, solution.FileName, config.ProjectLocation);
            }
            else
            {
                processResult = new MicrosoftTemplateEngineProcessedTemplateResult(workspaceItems.ToArray(), parentFolder.ParentSolution.FileName, config.ProjectLocation);
            }

            // Format all source files generated during the project creation
            foreach (var p in workspaceItems.OfType <Project> ())
            {
                foreach (var file in p.Files)
                {
                    await FormatFile(p, file.FilePath);
                }
            }
            processResult.SetFilesToOpen(filesToOpen);
            return(processResult);
        }
Exemplo n.º 26
0
 public bool CanProcessTemplate(SolutionTemplate template)
 {
     return(template is MicrosoftTemplateEngineSolutionTemplate);
 }
		TemplateCategory GetCategory (SolutionTemplate template, IEnumerable<TemplateCategory> currentCategories)
		{
			TemplateCategory match = null;

			match = GetMappedCategory (template);
			if (match != null) {
				return match;
			}

			var path = new TemplateCategoryPath (template.Category);
			foreach (string part in path.GetParts ()) {
				match = currentCategories.FirstOrDefault (category => category.IsMatch (part));

				if (match != null) {
					currentCategories = match.Categories;
				} else {
					return null;
				}
			}

			return match;
		}
Exemplo n.º 28
0
 IProjectTemplatingProvider GetTemplatingProviderForTemplate(SolutionTemplate template)
 {
     return(templateProviders.FirstOrDefault(provider => provider.CanProcessTemplate(template)));
 }
		public bool IsGroupMatch (SolutionTemplate template)
		{
			if (template.HasGroupId && HasGroupId) {
				return String.Equals (GroupId, template.GroupId, StringComparison.OrdinalIgnoreCase);
			}
			return false;
		}
		void SelectTemplate (SolutionTemplate template)
		{
			TreeIter iter = TreeIter.Zero;
			if (!templatesListStore.GetIterFirst (out iter)) {
				return;
			}

			while (templatesListStore.IterNext (ref iter)) {
				var currentTemplate = templatesListStore.GetValue (iter, TemplateColumn) as SolutionTemplate;
				if (currentTemplate == template) {
					templatesTreeView.Selection.SelectIter (iter);
					TreePath path = templatesListStore.GetPath (iter);
					templatesTreeView.ScrollToCell (path, null, true, 1, 0);
					break;
				}
			}
		}
		Image GetCachedImage (SolutionTemplate template)
		{
			Image image = null;
			if (template.HasImageFile) {
				if (fileImages.TryGetValue (template.Id, out image)) {
					return image;
				}
			} else {
				if (images.TryGetValue (template.ImageId, out image)) {
					return image;
				}
			}
			return null;
		}
		void AddLanguageMenuItems (Menu menu, SolutionTemplate template)
		{
			foreach (string language in template.AvailableLanguages.OrderBy (item => item)) {
				var menuItem = new MenuItem (language);
				menuItem.Activated += (o, e) => {
					templateTextRenderer.SelectedLanguage = language;
					controller.SelectedLanguage = language;
					templatesTreeView.QueueDraw ();
					ShowSelectedTemplate ();
				};
				menu.Append (menuItem);
			}
		}
		public Image GetImage (SolutionTemplate template)
		{
			return imageProvider.GetImage (template);
		}
		TemplateCategory GetMappedCategory (SolutionTemplate template)
		{
			TemplateCategory category = null;
			if (mappedCategories.TryGetValue (template.Category, out category)) {
				return category;
			}
			return null;
		}
		Image GetImageFile (SolutionTemplate template)
		{
			if (template.HasImageFile) {
				Image image = Image.FromFile (template.ImageFile);

				if (image != null) {
					fileImages [template.Id] = image;
					return image;
				}
			}
			return null;
		}
		public void AddGroupTemplate (SolutionTemplate template)
		{
			groupedTemplates.Add (template);

			if (!availableLanguages.Contains (template.Language)) {
				availableLanguages.Add (template.Language);
			}
		}
Exemplo n.º 37
0
        public async Task <ProcessedTemplateResult> ProcessTemplate(SolutionTemplate template, NewProjectConfiguration config, SolutionFolder parentFolder)
        {
            var solutionTemplate = (MicrosoftTemplateEngineSolutionTemplate)template;
            var parameters       = GetParameters(solutionTemplate, config);
            var templateInfo     = solutionTemplate.templateInfo;
            var workspaceItems   = new List <IWorkspaceFileObject> ();

            var filesBeforeCreation = Directory.GetFiles(config.ProjectLocation, "*", SearchOption.AllDirectories);

            var result = await MicrosoftTemplateEngine.InstantiateAsync(templateInfo, config, parameters);

            if (result.Status != CreationResultStatus.Success)
            {
                string message = string.Format("Could not create template. Id='{0}' {1} {2}", template.Id, result.Status, result.Message);
                throw new InvalidOperationException(message);
            }

            var filesToOpen = new List <string> ();

            foreach (var postAction in result.ResultInfo.PostActions)
            {
                switch (postAction.ActionId.ToString().ToUpper())
                {
                case "84C0DA21-51C8-4541-9940-6CA19AF04EE6":
                    if (postAction.Args.TryGetValue("files", out var files))
                    {
                        foreach (var fi in files.Split(';'))
                        {
                            if (int.TryParse(fi.Trim(), out var i))
                            {
                                filesToOpen.Add(Path.Combine(config.ProjectLocation, GetPath(result.ResultInfo.PrimaryOutputs [i])));
                            }
                        }
                    }
                    break;

                case "D396686C-DE0E-4DE6-906D-291CD29FC5DE":
                    //TODO: Load project files
                    break;
                }
            }

            //TODO: Once templates support "D396686C-DE0E-4DE6-906D-291CD29FC5DE" use that to load projects
            foreach (var path in result.ResultInfo.PrimaryOutputs)
            {
                var fullPath = Path.Combine(config.ProjectLocation, GetPath(path));
                if (Services.ProjectService.IsSolutionItemFile(fullPath))
                {
                    workspaceItems.Add(await MonoDevelop.Projects.Services.ProjectService.ReadSolutionItem(new Core.ProgressMonitor(), fullPath));
                }
            }

            var metadata = new TemplateMetadata {
                Id       = templateInfo.Identity,
                Name     = templateInfo.Name,
                Language = template.Language,
                Platform = string.Join(";", templateInfo.Classifications)
            };

            TemplateCounter.Inc(1, null, metadata);

            MicrosoftTemplateEngineProcessedTemplateResult processResult;

            if (parentFolder == null)
            {
                var solution = new Solution();
                solution.SetLocation(config.SolutionLocation, config.SolutionName);
                foreach (var item in workspaceItems.Cast <SolutionFolderItem> ())
                {
                    IConfigurationTarget configurationTarget = item as IConfigurationTarget;
                    if (configurationTarget != null)
                    {
                        foreach (ItemConfiguration configuration in configurationTarget.Configurations)
                        {
                            bool flag = false;
                            foreach (SolutionConfiguration solutionCollection in solution.Configurations)
                            {
                                if (solutionCollection.Id == configuration.Id)
                                {
                                    flag = true;
                                }
                            }
                            if (!flag)
                            {
                                solution.AddConfiguration(configuration.Id, true);
                            }
                        }
                    }
                    solution.RootFolder.AddItem(item);
                }
                processResult = new MicrosoftTemplateEngineProcessedTemplateResult(new [] { solution }, solution.FileName, config.ProjectLocation);
            }
            else
            {
                processResult = new MicrosoftTemplateEngineProcessedTemplateResult(workspaceItems.ToArray(), parentFolder.ParentSolution.FileName, config.ProjectLocation);
            }

            // Format all source files generated during the project creation
            foreach (var p in workspaceItems.OfType <Project> ())
            {
                foreach (var file in p.Files)
                {
                    if (!filesBeforeCreation.Contains((string)file.FilePath, FilePath.PathComparer))                        //Format only newly created files
                    {
                        if (solutionTemplate.ShouldFormatFile(file.FilePath))
                        {
                            await MicrosoftTemplateEngine.FormatFile(parentFolder?.Policies ?? p.Policies, file.FilePath);
                        }
                    }
                }
            }
            processResult.SetFilesToOpen(filesToOpen);
            return(processResult);
        }
Exemplo n.º 38
0
 internal void UpdateParameters(SolutionTemplate template)
 {
     Parameters ["TemplateName"] = template.Name;
     UpdateSupportedParameters(template.SupportedParameters);
     UpdateDefaultParameters(template.DefaultParameters);
 }
Exemplo n.º 39
0
		internal void UpdateParameters (SolutionTemplate template)
		{
			Parameters ["TemplateName"] = template.Name;
			UpdateSupportedParameters (template.SupportedParameters);
			UpdateDefaultParameters (template.DefaultParameters);
		}
Exemplo n.º 40
0
 public Task <ProcessedTemplateResult> ProcessTemplate(SolutionTemplate template, NewProjectConfiguration config, SolutionFolder parentFolder)
 {
     return(ProcessTemplate((DefaultSolutionTemplate)template, config, parentFolder));
 }
        public async Task <ProcessedTemplateResult> ProcessTemplate(SolutionTemplate template, NewProjectConfiguration config, SolutionFolder parentFolder)
        {
            var templateInfo   = ((MicrosoftTemplateEngineSolutionTemplate)template).templateInfo;
            var workspaceItems = new List <IWorkspaceFileObject> ();
            var result         = await templateCreator.InstantiateAsync(
                templateInfo,
                config.ProjectName,
                config.GetValidProjectName(),
                config.ProjectLocation,
                new Dictionary <string, string> (),
                true,
                false);

            if (result.ResultInfo.PrimaryOutputs.Any())
            {
                foreach (var res in result.ResultInfo.PrimaryOutputs)
                {
                    var fullPath = Path.Combine(config.ProjectLocation, res.Path);
                    //This happens if some project is excluded by modifiers, e.g. Test project disabled in wizard settings by user
                    if (!File.Exists(fullPath))
                    {
                        continue;
                    }
                    workspaceItems.Add(await MonoDevelop.Projects.Services.ProjectService.ReadSolutionItem(new Core.ProgressMonitor(), fullPath));
                }
            }
            else
            {
                //TODO: Remove this code once https://github.com/dotnet/templating/pull/342 is released in NuGet feed and we bump NuGet version of templating engine
                foreach (var path in Directory.GetFiles(config.ProjectLocation, "*.*proj", SearchOption.AllDirectories))
                {
                    if (path.EndsWith(".csproj", StringComparison.OrdinalIgnoreCase) || path.EndsWith(".fsproj", StringComparison.OrdinalIgnoreCase) || path.EndsWith(".vbproj", StringComparison.OrdinalIgnoreCase))
                    {
                        workspaceItems.Add(await MonoDevelop.Projects.Services.ProjectService.ReadSolutionItem(new Core.ProgressMonitor(), path));
                    }
                }
            }

            var metadata = new Dictionary <string, string> ();

            metadata ["Id"]       = templateInfo.Identity;
            metadata ["Name"]     = templateInfo.Name;
            metadata ["Language"] = template.Language;
            metadata ["Platform"] = string.Join(";", templateInfo.Classifications);
            TemplateCounter.Inc(1, null, metadata);

            if (parentFolder == null)
            {
                var solution = new Solution();
                solution.SetLocation(config.SolutionLocation, config.SolutionName);
                foreach (var item in workspaceItems.Cast <SolutionFolderItem> ())
                {
                    IConfigurationTarget configurationTarget = item as IConfigurationTarget;
                    if (configurationTarget != null)
                    {
                        foreach (ItemConfiguration configuration in configurationTarget.Configurations)
                        {
                            bool flag = false;
                            foreach (SolutionConfiguration solutionCollection in solution.Configurations)
                            {
                                if (solutionCollection.Id == configuration.Id)
                                {
                                    flag = true;
                                }
                            }
                            if (!flag)
                            {
                                solution.AddConfiguration(configuration.Id, true);
                            }
                        }
                    }
                    solution.RootFolder.AddItem(item);
                }
                return(new MicrosoftTemplateEngineProcessedTemplateResult(new [] { solution }, solution.FileName, config.ProjectLocation));
            }
            else
            {
                return(new MicrosoftTemplateEngineProcessedTemplateResult(workspaceItems.ToArray(), parentFolder.ParentSolution.FileName, config.ProjectLocation));
            }
        }
		TemplateCategory GetCategory (SolutionTemplate template)
		{
			TemplateCategory match = GetCategory (template, categories);

			if (match != null) {
				return match;
			} else if (defaultCategory != null) {
				LogUsingDefaultCategory (template);

				return defaultCategory;
			}
			return null;
		}
		void LogUsingDefaultCategory (SolutionTemplate template)
		{
			string message = String.Format (
				"Invalid category using default category. Template id='{0}', category='{1}'.",
				template.Id,
				template.Category);
			LogWarning (message);
		}
Exemplo n.º 44
0
 public bool CanProcessTemplate(SolutionTemplate template)
 {
     return(template is DefaultSolutionTemplate);
 }
		void SelectTemplate (SolutionTemplate template)
		{
			TreeIter iter = TreeIter.Zero;
			if (!templatesListStore.GetIterFirst (out iter)) {
				return;
			}

			while (templatesListStore.IterNext (ref iter)) {
				var currentTemplate = templatesListStore.GetValue (iter, TemplateColumn) as SolutionTemplate;
				if (currentTemplate == template) {
					templatesTreeView.Selection.SelectIter (iter);
					break;
				}
			}
		}
		public ProcessedTemplateResult ProcessTemplate (SolutionTemplate template, NewProjectConfiguration config, SolutionFolder parentFolder)
		{
			IProjectTemplatingProvider provider = GetTemplatingProviderForTemplate (template);
			if (provider != null) {
				return provider.ProcessTemplate (template, config, parentFolder);
			}
			return null;
		}
		void ShowTemplate (SolutionTemplate template)
		{
			templateNameLabel.Markup = MarkupTemplateName (template.Name);
			templateDescriptionLabel.Text = template.Description;
			templateImage.Image = controller.GetImage (template);
			templateVBox.Visible = true;
			templateVBox.ShowAll ();
		}
		public bool CanProcessTemplate (SolutionTemplate template)
		{
			return template is DefaultSolutionTemplate;
		}
		void LogNoCategoryMatch (SolutionTemplate template)
		{
			string message = String.Format (
				"Invalid category. Template id='{0}', category='{1}'.",
				template.Id,
				template.Category);
			LogWarning (message);
		}
		public ProcessedTemplateResult ProcessTemplate (SolutionTemplate template, NewProjectConfiguration config, SolutionFolder parentFolder)
		{
			return ProcessTemplate ((DefaultSolutionTemplate)template, config, parentFolder);
		}