public void CreateProject(string projectPath, string projectName) { IProjectTemplate projectTemplate = ( from template in this.serviceProvider.ProjectManager().TemplateManager.ProjectTemplates where template.Identifier.Equals("Microsoft.Blend.WPFApplication") select template).First <IProjectTemplate>(); IProject project = this.serviceProvider.ProjectManager().CreateProjectTemplate(projectPath, projectName, projectTemplate, null).FirstOrDefault <INamedProject>() as IProject; if (project != null) { IDocumentType item = this.serviceProvider.DocumentTypes()[DocumentTypeNamesHelper.Xaml]; ICodeDocumentType codeDocumentType = this.serviceProvider.DocumentTypes().CSharpDocumentType(); List <DocumentCreationInfo> documentCreationInfos = new List <DocumentCreationInfo>(); DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo() { DocumentType = item, TargetPath = Path.Combine(project.ProjectRoot.Path, "TestUserControl.xaml") }; documentCreationInfos.Add(documentCreationInfo); DocumentCreationInfo documentCreationInfo1 = new DocumentCreationInfo() { DocumentType = codeDocumentType, TargetPath = Path.Combine(project.ProjectRoot.Path, "TestUserControl.xaml.cs") }; documentCreationInfos.Add(documentCreationInfo1); project.AddItems(documentCreationInfos); project.StartupItem.OpenView(true); } }
protected override void OnDrop(DragEventArgs e) { SafeDataObject safeDataObject = new SafeDataObject(e.Data); if (safeDataObject != null && safeDataObject.GetDataPresent(DataFormats.FileDrop)) { string[] supportedFiles = this.dropUtility.GetSupportedFiles(e.Data); List <string> strs = new List <string>(); string[] strArrays = supportedFiles; for (int i = 0; i < (int)strArrays.Length; i++) { string str = strArrays[i]; if (((new FileInfo(str)).Attributes & FileAttributes.Directory) != FileAttributes.Directory) { strs.Add(str); } } if (strs.Count > 0) { IProject project = this.Services.ProjectManager().ItemSelectionSet.SelectedProjects.SingleOrNull <IProject>(); if (project != null) { project.AddItems( from item in strs select new DocumentCreationInfo() { SourcePath = item }); } } } }
protected override bool CreateProjectItem() { bool flag; string[] filesToImport = this.GetFilesToImport(base.GetImportFolder()); if (filesToImport == null || (int)filesToImport.Length <= 0) { return(false); } IProject project = this.SelectedProjects().SingleOrNull <IProject>(); string[] strArrays = filesToImport; int num = 0; while (true) { if (num >= (int)strArrays.Length) { IEnumerable <IProjectItem> projectItems = project.AddItems( from file in filesToImport select new DocumentCreationInfo() { SourcePath = file, CreationOptions = CreationOptions.LinkSourceFile }); if (projectItems == null) { return(false); } return(projectItems.CountIsMoreThan <IProjectItem>(0)); } string str = strArrays[num]; string fileName = Path.GetFileName(str); if (project.Items.FindMatchByUrl <IProjectItem>(str) != null) { CultureInfo currentCulture = CultureInfo.CurrentCulture; string linkToExistingItemCommandLinkedFileExistsDialogMessage = StringTable.LinkToExistingItemCommandLinkedFileExistsDialogMessage; object[] objArray = new object[] { fileName }; this.DisplayCommandFailedMessage(string.Format(currentCulture, linkToExistingItemCommandLinkedFileExistsDialogMessage, objArray)); flag = false; break; } else if (project.Items.FindMatchByUrl <IProjectItem>(Path.Combine(this.ProjectManager().TargetFolderForProject(project), fileName)) == null) { num++; } else { CultureInfo cultureInfo = CultureInfo.CurrentCulture; string linkToExistingItemCommandFileExistsDialogMessage = StringTable.LinkToExistingItemCommandFileExistsDialogMessage; object[] objArray1 = new object[] { fileName }; this.DisplayCommandFailedMessage(string.Format(cultureInfo, linkToExistingItemCommandFileExistsDialogMessage, objArray1)); flag = false; break; } } return(flag); }
private bool CopyItems(IProject activeProject, IEnumerable <CutBuffer.CopyInformation> itemsToCopy) { List <DocumentCreationInfo> documentCreationInfos = new List <DocumentCreationInfo>(); foreach (CutBuffer.CopyInformation copyInformation in itemsToCopy) { if (!Microsoft.Expression.Framework.Documents.PathHelper.FileExists(copyInformation.SourcePath)) { if (!Microsoft.Expression.Framework.Documents.PathHelper.DirectoryExists(copyInformation.SourcePath)) { continue; } List <string> strs = new List <string>() { "" }; this.AppendAllSubfolders(copyInformation.SourcePath, "", strs); foreach (string str in strs) { string str1 = Microsoft.Expression.Framework.Documents.PathHelper.ResolveCombinedPath(copyInformation.SourcePath, str); string str2 = Microsoft.Expression.Framework.Documents.PathHelper.ResolveCombinedPath(copyInformation.DestinationPath, str); DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo() { DocumentType = this.Services.DocumentTypeManager().DocumentTypes[DocumentTypeNamesHelper.Folder], SourcePath = str1, TargetPath = str2 }; documentCreationInfos.Add(documentCreationInfo); documentCreationInfos.AddRange(this.CopyFolderFiles(str1, str2)); } } else { DocumentCreationInfo documentCreationInfo1 = new DocumentCreationInfo() { SourcePath = copyInformation.SourcePath, TargetPath = copyInformation.DestinationPath }; documentCreationInfos.Add(documentCreationInfo1); } } IEnumerable <IProjectItem> projectItems = activeProject.AddItems(documentCreationInfos); if (itemsToCopy.CountIsLessThan <CutBuffer.CopyInformation>(1)) { return(true); } if (projectItems == null) { return(false); } return(projectItems.CountIsMoreThan <IProjectItem>(0)); }
protected override bool CreateProjectItem() { IProjectItem projectItem; IProject project = this.SelectedProjectOrNull(); if (project == null) { return(false); } IDocumentType item = base.Services.DocumentTypes()[DocumentTypeNamesHelper.Folder]; string str = this.ProjectManager().TargetFolderForProject(project); string availableFilePath = ProjectPathHelper.GetAvailableFilePath(item.DefaultFileName, str, project); Directory.CreateDirectory(availableFilePath); try { List <DocumentCreationInfo> documentCreationInfos = new List <DocumentCreationInfo>(); DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo() { DocumentType = item, TargetPath = availableFilePath }; documentCreationInfos.Add(documentCreationInfo); projectItem = project.AddItems(documentCreationInfos).FirstOrDefault <IProjectItem>(); } catch { Directory.Delete(availableFilePath); throw; } if (projectItem != null) { base.Services.SetSelection(projectItem); base.Services.CommandService().Execute("Project_RenameProjectItem", CommandInvocationSource.Internally); } return(projectItem != null); }
protected override bool CreateProjectItem() { string[] filesToImport = this.GetFilesToImport(base.GetImportFolder()); if (filesToImport != null && (int)filesToImport.Length > 0) { IProject project = this.SelectedProjectOrNull(); if (project != null) { IEnumerable <IProjectItem> projectItems = project.AddItems( from file in filesToImport select new DocumentCreationInfo() { SourcePath = file, CreationOptions = this.Options }); if (projectItems == null) { return(false); } return(projectItems.CountIsMoreThan <IProjectItem>(0)); } } return(false); }
public IEnumerable <IProjectItem> CreateProjectItems(string name, string targetFolder, IProject project, IEnumerable <TemplateArgument> templateArguments, CreationOptions creationOptions, out List <IProjectItem> itemsToOpen, IServiceProvider serviceProvider) { Uri uri; if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException("name"); } ICodeDocumentType codeDocumentType = base.GetCodeDocumentType(serviceProvider); if (templateArguments != null) { templateArguments = templateArguments.Concat <TemplateArgument>(TemplateManager.GetDefaultArguments(serviceProvider.ExpressionInformationService())); } else { templateArguments = TemplateManager.GetDefaultArguments(serviceProvider.ExpressionInformationService()); } IEnumerable <IProjectItem> projectItems = Enumerable.Empty <IProjectItem>(); itemsToOpen = new List <IProjectItem>(); using (ProjectPathHelper.TemporaryDirectory temporaryDirectory = new ProjectPathHelper.TemporaryDirectory(true)) { Uri uri1 = new Uri(Microsoft.Expression.Framework.Documents.PathHelper.EnsurePathEndsInDirectorySeparator(temporaryDirectory.Path)); List <DocumentCreationInfo> documentCreationInfos = new List <DocumentCreationInfo>(); List <string> strs = new List <string>(); bool flag = false; foreach (VSTemplateTemplateContentProjectItem templateProjectItem in this.TemplateProjectItems) { if (!templateProjectItem.OpenInEditorSpecified) { continue; } flag = true; break; } bool flag1 = false; string str = CodeGenerator.MakeSafeIdentifier(codeDocumentType, project.DocumentReference.DisplayNameShort, flag1); bool flag2 = true; string str1 = CodeGenerator.MakeSafeIdentifier(codeDocumentType, project.DocumentReference.DisplayNameShort, flag2); TemplateArgument templateArgument = new TemplateArgument("safeprojectname", str); TemplateArgument templateArgument1 = new TemplateArgument("safeprojectname", str1); TemplateArgument templateArgument2 = new TemplateArgument("assemblyname", project.DocumentReference.DisplayNameShort); TemplateArgument templateArgument3 = new TemplateArgument("safeassemblyname", project.DocumentReference.DisplayNameShort.Replace(' ', '\u005F')); foreach (VSTemplateTemplateContentProjectItem vSTemplateTemplateContentProjectItem in this.TemplateProjectItems) { string targetFileName = vSTemplateTemplateContentProjectItem.TargetFileName; if (string.IsNullOrEmpty(targetFileName)) { targetFileName = vSTemplateTemplateContentProjectItem.Value; } TemplateArgument[] templateArgumentArray = new TemplateArgument[] { new TemplateArgument("fileinputname", Path.GetFileNameWithoutExtension(name)), new TemplateArgument("fileinputextension", Path.GetExtension(name)) }; IEnumerable <TemplateArgument> templateArguments1 = templateArgumentArray; targetFileName = TemplateParser.ReplaceTemplateArguments(targetFileName, templateArguments1); templateArguments1 = templateArguments1.Concat <TemplateArgument>(templateArguments); bool flag3 = Path.GetExtension(vSTemplateTemplateContentProjectItem.Value).Equals(codeDocumentType.DefaultFileExtension, StringComparison.OrdinalIgnoreCase); string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(Microsoft.Expression.Framework.Documents.PathHelper.GetFileOrDirectoryName(targetFileName)); if (serviceProvider.DocumentTypeManager().DocumentTypes[DocumentTypeNamesHelper.Xaml].IsDocumentTypeOf(fileNameWithoutExtension)) { fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileNameWithoutExtension); } string str2 = CodeGenerator.MakeSafeIdentifier(codeDocumentType, fileNameWithoutExtension, flag3); IEnumerable <TemplateArgument> templateArguments2 = templateArguments1; TemplateArgument[] templateArgumentArray1 = new TemplateArgument[] { new TemplateArgument("rootnamespace", project.DefaultNamespaceName), new TemplateArgument("projectname", project.DocumentReference.DisplayNameShort), templateArgument2, templateArgument3, null, null, null, null }; templateArgumentArray1[4] = (flag3 ? templateArgument1 : templateArgument); templateArgumentArray1[5] = new TemplateArgument("safeitemname", str2); templateArgumentArray1[6] = new TemplateArgument("safeitemrootname", str2); templateArgumentArray1[7] = new TemplateArgument("culture", (string.IsNullOrEmpty(project.UICulture) ? CultureInfo.CurrentUICulture.ToString() : project.UICulture)); templateArguments1 = templateArguments2.Concat <TemplateArgument>(templateArgumentArray1); try { uri = base.ResolveFileUri(targetFileName, uri1); } catch (UriFormatException uriFormatException) { continue; } IDocumentType documentType = project.GetDocumentType(targetFileName); foreach (IDocumentType documentType1 in serviceProvider.DocumentTypeManager().DocumentTypes) { if (vSTemplateTemplateContentProjectItem.SubType != documentType1.Name) { continue; } documentType = documentType1; } if (!base.CreateFile(vSTemplateTemplateContentProjectItem.Value, base.TemplateLocation, uri, vSTemplateTemplateContentProjectItem.ReplaceParameters, templateArguments1)) { continue; } string str3 = ProjectItemTemplate.AdjustTargetFolder(targetFolder, uri1.LocalPath, uri.LocalPath); DocumentCreationInfo documentCreationInfo = new DocumentCreationInfo() { SourcePath = uri.LocalPath, TargetFolder = str3, DocumentType = documentType, CreationOptions = creationOptions }; documentCreationInfos.Add(documentCreationInfo); if (!flag) { if (strs.Count > 0) { continue; } strs.Add(Path.Combine(str3, Path.GetFileName(uri.LocalPath))); } else { if (!vSTemplateTemplateContentProjectItem.OpenInEditor) { continue; } strs.Add(Path.Combine(str3, Path.GetFileName(uri.LocalPath))); } } if (documentCreationInfos.Count > 0) { projectItems = project.AddItems(documentCreationInfos); } if (projectItems.Any <IProjectItem>()) { for (int i = 0; i < strs.Count; i++) { IProjectItem projectItem = projectItems.FirstOrDefault <IProjectItem>((IProjectItem item) => item.DocumentReference.Path.Equals(strs[i], StringComparison.OrdinalIgnoreCase)); if (projectItem != null) { itemsToOpen.Add(projectItem); } } projectItems = projectItems.Concat <IProjectItem>(this.AddAssemblies(project)); } } if (base.BuildOnLoad) { IProjectManager projectManager = serviceProvider.ProjectManager(); IProjectBuildContext activeBuildTarget = projectManager.ActiveBuildTarget; projectManager.BuildManager.Build(activeBuildTarget, null, true); KnownProjectBase knownProjectBase = project as KnownProjectBase; if (knownProjectBase != null) { knownProjectBase.CheckForChangedOrDeletedItems(); } } return(projectItems); }