Пример #1
0
        public IEnumerable <SolutionItem> CreateProjects(SolutionFolderItem policyParent, ProjectCreateInformation cInfo)
        {
            if (solutionDescriptor.EntryDescriptors.Length == 0)
            {
                throw new InvalidOperationException(GettextCatalog.GetString("Solution template doesn't have any project templates"));
            }

            var solutionEntryItems = new List <SolutionItem> ();

            packageReferencesForCreatedProjects = new List <PackageReferencesForCreatedProject> ();

            foreach (ISolutionItemDescriptor solutionItemDescriptor in GetItemsToCreate(solutionDescriptor, cInfo))
            {
                ProjectCreateInformation itemCreateInfo = GetItemSpecificCreateInfo(solutionItemDescriptor, cInfo);
                itemCreateInfo = new ProjectTemplateCreateInformation(itemCreateInfo, cInfo.ProjectName);
                itemCreateInfo.TemplateInitializationCallback = async p => {
                    try {
                        await solutionItemDescriptor.InitializeItem(policyParent, itemCreateInfo, this.languagename, p);

                        // Handle the case where InitializeItem has to wait for a Task to complete and the project
                        // is saved before all the files are added to the project. Otherwise the project will not contain
                        // the files even though the solution pad shows them.
                        // TODO: Investigate making the InitializeFromTemplate methods Task based.
                        await p.SaveAsync(new ProgressMonitor());
                    } catch (Exception ex) {
                        LoggingService.LogError("TemplateInitializationCallback error.", ex);
                    }
                };

                SolutionItem solutionEntryItem = solutionItemDescriptor.CreateItem(itemCreateInfo, this.languagename);
                if (solutionEntryItem != null)
                {
                    SavePackageReferences(solutionEntryItem, solutionItemDescriptor, itemCreateInfo);
                    solutionEntryItems.Add(solutionEntryItem);
                }
            }

            var pDesc    = this.solutionDescriptor.EntryDescriptors.OfType <ProjectDescriptor> ().FirstOrDefault();
            var metadata = new TemplateMetadata {
                Id       = Id,
                Name     = nonLocalizedName,
                Language = LanguageName,
                Platform = pDesc != null ? pDesc.ProjectType : "Unknown"
            };

            TemplateCounter.Inc(1, null, metadata);

            return(solutionEntryItems);
        }
Пример #2
0
        public IEnumerable <SolutionEntityItem> CreateProjects(SolutionItem policyParent, ProjectCreateInformation cInfo)
        {
            if (solutionDescriptor.EntryDescriptors.Length == 0)
            {
                throw new InvalidOperationException("Solution template doesn't have any project templates");
            }

            var solutionEntryItems = new List <SolutionEntityItem> ();

            packageReferencesForCreatedProjects = new List <PackageReferencesForCreatedProject> ();

            foreach (ISolutionItemDescriptor solutionItemDescriptor in GetItemsToCreate(solutionDescriptor, cInfo))
            {
                ProjectCreateInformation itemCreateInfo = GetItemSpecificCreateInfo(solutionItemDescriptor, cInfo);
                itemCreateInfo = new ProjectTemplateCreateInformation(itemCreateInfo, cInfo.ProjectName);

                SolutionEntityItem solutionEntryItem = solutionItemDescriptor.CreateItem(itemCreateInfo, this.languagename);
                if (solutionEntryItem != null)
                {
                    solutionItemDescriptor.InitializeItem(policyParent, itemCreateInfo, this.languagename, solutionEntryItem);

                    SavePackageReferences(solutionEntryItem, solutionItemDescriptor, itemCreateInfo);

                    solutionEntryItems.Add(solutionEntryItem);
                }
            }

            var pDesc    = this.solutionDescriptor.EntryDescriptors.OfType <ProjectDescriptor> ().FirstOrDefault();
            var metadata = new Dictionary <string, string> ();

            metadata ["Id"]       = this.Id;
            metadata ["Name"]     = this.nonLocalizedName;
            metadata ["Language"] = this.LanguageName;
            metadata ["Platform"] = pDesc != null ? pDesc.ProjectType : "Unknown";
            TemplateCounter.Inc(1, null, metadata);

            createdProjectInformation = cInfo;

            return(solutionEntryItems);
        }
Пример #3
0
        public IEnumerable <SolutionItem> CreateProjects(SolutionFolderItem policyParent, ProjectCreateInformation cInfo)
        {
            if (solutionDescriptor.EntryDescriptors.Length == 0)
            {
                throw new InvalidOperationException(GettextCatalog.GetString("Solution template doesn't have any project templates"));
            }

            var solutionEntryItems = new List <SolutionItem> ();

            packageReferencesForCreatedProjects = new List <PackageReferencesForCreatedProject> ();

            foreach (ISolutionItemDescriptor solutionItemDescriptor in GetItemsToCreate(solutionDescriptor, cInfo))
            {
                ProjectCreateInformation itemCreateInfo = GetItemSpecificCreateInfo(solutionItemDescriptor, cInfo);
                itemCreateInfo = new ProjectTemplateCreateInformation(itemCreateInfo, cInfo.ProjectName);
                itemCreateInfo.TemplateInitializationCallback = p => solutionItemDescriptor.InitializeItem(policyParent, itemCreateInfo, this.languagename, p);

                SolutionItem solutionEntryItem = solutionItemDescriptor.CreateItem(itemCreateInfo, this.languagename);
                if (solutionEntryItem != null)
                {
                    SavePackageReferences(solutionEntryItem, solutionItemDescriptor, itemCreateInfo);
                    solutionEntryItems.Add(solutionEntryItem);
                }
            }

            var pDesc    = this.solutionDescriptor.EntryDescriptors.OfType <ProjectDescriptor> ().FirstOrDefault();
            var metadata = new TemplateMetadata {
                Id       = Id,
                Name     = nonLocalizedName,
                Language = LanguageName,
                Platform = pDesc != null ? pDesc.ProjectType : "Unknown"
            };

            TemplateCounter.Inc(1, null, metadata);

            return(solutionEntryItems);
        }
Пример #4
0
		public WorkspaceItemCreatedInformation CreateEntry (ProjectCreateInformation projectCreateInformation, string defaultLanguage)
        {
            WorkspaceItem workspaceItem = null;

            if (string.IsNullOrEmpty (type))
                workspaceItem = new Solution ();
            else {
                Type workspaceItemType = addin.GetType (type, false);
                if (workspaceItemType != null)
                    workspaceItem = Activator.CreateInstance (workspaceItemType) as WorkspaceItem;

                if (workspaceItem == null) {
                    MessageService.ShowError (GettextCatalog.GetString ("Can't create solution with type: {0}", type));
					return null;
				}
            }

			var substitution = new string[,] { { "ProjectName", projectCreateInformation.SolutionName } };
            workspaceItem.Name = StringParserService.Parse (name, substitution);
			string newStartupProjectName = startupProject;
			if (newStartupProjectName != null) {
				newStartupProjectName = StringParserService.Parse (startupProject, substitution);
			}

            workspaceItem.SetLocation (projectCreateInformation.SolutionPath, workspaceItem.Name);

            ProjectCreateInformation localProjectCI;
            if (!string.IsNullOrEmpty (directory) && directory != ".") {
                localProjectCI = new ProjectCreateInformation (projectCreateInformation);

                localProjectCI.SolutionPath = Path.Combine (localProjectCI.SolutionPath, directory);
                localProjectCI.ProjectBasePath = Path.Combine (localProjectCI.ProjectBasePath, directory);

                if (!Directory.Exists (localProjectCI.SolutionPath))
                    Directory.CreateDirectory (localProjectCI.SolutionPath);

                if (!Directory.Exists (localProjectCI.ProjectBasePath))
                    Directory.CreateDirectory (localProjectCI.ProjectBasePath);
            }
            else
                localProjectCI = projectCreateInformation;

			var workspaceItemCreatedInfo = new WorkspaceItemCreatedInformation (workspaceItem);

            Solution solution = workspaceItem as Solution;
            if (solution != null) {
                for ( int i = 0; i < entryDescriptors.Count; i++ ) {
                    ProjectCreateInformation entryProjectCI;
                    var entry = entryDescriptors[i] as ICustomProjectCIEntry;
					if (entry != null) {
						entryProjectCI = entry.CreateProjectCI (localProjectCI);
						entryProjectCI = new ProjectTemplateCreateInformation (entryProjectCI, localProjectCI.ProjectName);
					} else
	                    entryProjectCI = localProjectCI;

					var solutionItemDesc = entryDescriptors[i];

					SolutionEntityItem info = solutionItemDesc.CreateItem (entryProjectCI, defaultLanguage);
					if (info == null)
						continue;

					solutionItemDesc.InitializeItem (solution.RootFolder, entryProjectCI, defaultLanguage, info);

                    IConfigurationTarget configurationTarget = info 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);
                        }
                    }

					if ((info is Project) && (solutionItemDesc is ProjectDescriptor)) {
						workspaceItemCreatedInfo.AddPackageReferenceForCreatedProject ((Project)info, (ProjectDescriptor)solutionItemDesc, projectCreateInformation);
					}
                    solution.RootFolder.Items.Add (info);
					if (newStartupProjectName == info.Name)
						solution.StartupItem = info;
                }
            }

			if (!workspaceItem.FileFormat.CanWrite (workspaceItem)) {
				// The default format can't write solutions of this type. Find a compatible format.
				FileFormat f = IdeApp.Services.ProjectService.FileFormats.GetFileFormatsForObject (workspaceItem).First ();
				workspaceItem.ConvertToFormat (f, true);
			}
			
			return workspaceItemCreatedInfo;
        }
		public IEnumerable<SolutionItem> CreateProjects (SolutionFolderItem policyParent, ProjectCreateInformation cInfo)
		{
			if (solutionDescriptor.EntryDescriptors.Length == 0)
				throw new InvalidOperationException ("Solution template doesn't have any project templates");

			var solutionEntryItems = new List<SolutionItem> ();
			packageReferencesForCreatedProjects = new List<PackageReferencesForCreatedProject> ();

			foreach (ISolutionItemDescriptor solutionItemDescriptor in GetItemsToCreate (solutionDescriptor, cInfo)) {
				ProjectCreateInformation itemCreateInfo = GetItemSpecificCreateInfo (solutionItemDescriptor, cInfo);
				itemCreateInfo = new ProjectTemplateCreateInformation (itemCreateInfo, cInfo.ProjectName);

				SolutionItem solutionEntryItem = solutionItemDescriptor.CreateItem (itemCreateInfo, this.languagename);
				if (solutionEntryItem != null) {
					solutionItemDescriptor.InitializeItem (policyParent, itemCreateInfo, this.languagename, solutionEntryItem);

					SavePackageReferences (solutionEntryItem, solutionItemDescriptor, itemCreateInfo);

					solutionEntryItems.Add (solutionEntryItem);
				}
			}

			var pDesc = this.solutionDescriptor.EntryDescriptors.OfType<ProjectDescriptor> ().FirstOrDefault ();
			var metadata = new Dictionary<string, string> ();
			metadata ["Id"] = this.Id;
			metadata ["Name"] = this.nonLocalizedName;
			metadata ["Language"] = this.LanguageName;
			metadata ["Platform"] = pDesc != null ? pDesc.ProjectType : "Unknown";
			TemplateCounter.Inc (1, null, metadata);

			return solutionEntryItems;
		}
Пример #6
0
        public WorkspaceItemCreatedInformation CreateEntry(ProjectCreateInformation projectCreateInformation, string defaultLanguage)
        {
            WorkspaceItem workspaceItem = null;

            if (string.IsNullOrEmpty(type))
            {
                workspaceItem = new Solution();
            }
            else
            {
                Type workspaceItemType = addin.GetType(type, false);
                if (workspaceItemType != null)
                {
                    workspaceItem = Activator.CreateInstance(workspaceItemType) as WorkspaceItem;
                }

                if (workspaceItem == null)
                {
                    MessageService.ShowError(GettextCatalog.GetString("Can't create solution with type: {0}", type));
                    return(null);
                }
            }

            var substitution = new string[, ] {
                { "ProjectName", projectCreateInformation.SolutionName }
            };

            workspaceItem.Name = StringParserService.Parse(name, substitution);
            string newStartupProjectName = startupProject;

            if (newStartupProjectName != null)
            {
                newStartupProjectName = StringParserService.Parse(startupProject, substitution);
            }

            workspaceItem.SetLocation(projectCreateInformation.SolutionPath, workspaceItem.Name);

            ProjectCreateInformation localProjectCI;

            if (!string.IsNullOrEmpty(directory) && directory != ".")
            {
                localProjectCI = new ProjectCreateInformation(projectCreateInformation);

                localProjectCI.SolutionPath    = Path.Combine(localProjectCI.SolutionPath, directory);
                localProjectCI.ProjectBasePath = Path.Combine(localProjectCI.ProjectBasePath, directory);

                if (!Directory.Exists(localProjectCI.SolutionPath))
                {
                    Directory.CreateDirectory(localProjectCI.SolutionPath);
                }

                if (!Directory.Exists(localProjectCI.ProjectBasePath))
                {
                    Directory.CreateDirectory(localProjectCI.ProjectBasePath);
                }
            }
            else
            {
                localProjectCI = projectCreateInformation;
            }

            var workspaceItemCreatedInfo = new WorkspaceItemCreatedInformation(workspaceItem);

            Solution solution = workspaceItem as Solution;

            if (solution != null)
            {
                for (int i = 0; i < entryDescriptors.Count; i++)
                {
                    ProjectCreateInformation entryProjectCI;
                    var entry = entryDescriptors[i] as ICustomProjectCIEntry;
                    if (entry != null)
                    {
                        entryProjectCI = entry.CreateProjectCI(localProjectCI);
                        entryProjectCI = new ProjectTemplateCreateInformation(entryProjectCI, localProjectCI.ProjectName);
                    }
                    else
                    {
                        entryProjectCI = localProjectCI;
                    }

                    var solutionItemDesc = entryDescriptors[i];

                    SolutionItem info = solutionItemDesc.CreateItem(entryProjectCI, defaultLanguage);
                    if (info == null)
                    {
                        continue;
                    }

                    solutionItemDesc.InitializeItem(solution.RootFolder, entryProjectCI, defaultLanguage, info);

                    IConfigurationTarget configurationTarget = info 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);
                            }
                        }
                    }

                    if ((info is Project) && (solutionItemDesc is ProjectDescriptor))
                    {
                        workspaceItemCreatedInfo.AddPackageReferenceForCreatedProject((Project)info, (ProjectDescriptor)solutionItemDesc, projectCreateInformation);
                    }
                    solution.RootFolder.Items.Add(info);
                    if (newStartupProjectName == info.Name)
                    {
                        solution.StartupItem = info;
                    }
                }
            }

            var sol = workspaceItem as Solution;

            if (sol != null && !sol.SupportsFormat(sol.FileFormat))
            {
                // The default format can't write solutions of this type. Find a compatible format.
                var f = MSBuildFileFormat.GetSupportedFormats().First(ff => ff.CanWriteFile(sol));
                sol.ConvertToFormat(f);
            }

            return(workspaceItemCreatedInfo);
        }