private ProjectItem Add([NotNull] CreateItem element) { Debug.ArgumentNotNull(element, nameof(element)); var project = element.Project; var fileName = project.GetProjectItemFileName(element.Item); var result = ProjectFileItem.Load(project, fileName); project.Add(result); foreach (var item in element.Item.ProjectItems) { var subitem = item as EnvDTE.ProjectItem; if (subitem == null) { continue; } fileName = project.GetProjectItemFileName(subitem); project.Add(ProjectFileItem.Load(project, fileName)); } return(result); }
private void LinkItems() { var selectedItems = TreeView.SelectedItems; if (selectedItems.Count != 1) { return; } var selectedItem = selectedItems[0] as ItemTreeViewItem; if (selectedItem == null) { return; } var itemUri = selectedItem.ItemUri; var projects = new List <Project>(); foreach (var item in Items) { var project = ProjectManager.GetProject(item); if (project == null) { continue; } var projectItem = project.GetProjectItem(item); if (projectItem == null) { var fileName = project.GetProjectItemFileName(item); projectItem = ProjectFileItem.Load(project, fileName); project.Add(projectItem); } var projectFile = projectItem as ProjectFileItem; if (projectFile == null) { continue; } projectFile.Items.Add(itemUri); if (!projects.Contains(project)) { projects.Add(project); } } foreach (var project in projects) { project.Save(); } }
protected override void Process(DuplicateItemPipeline pipeline) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); if (pipeline.NewItemUri == ItemUri.Empty) { return; } var projectFileItem = ProjectManager.GetProjectFileItem(pipeline.ItemUri); if (projectFileItem == null) { return; } var project = projectFileItem.Project; var source = projectFileItem.AbsoluteFileName; var sourceFolder = Path.GetDirectoryName(source) ?? string.Empty; var extension = Path.GetExtension(source); var target = Path.Combine(sourceFolder, pipeline.NewName) + extension; if (!AppHost.Files.FileExists(target)) { AppHost.Files.Copy(source, target, false); } EnvDTE.ProjectItem newProjectItem; try { newProjectItem = SitecorePackage.Instance.Dte.ItemOperations.AddExistingItem(target); } catch (Exception ex) { AppHost.Output.LogException(ex); return; } var fileName = project.GetProjectItemFileName(newProjectItem); var projectItem = ProjectFileItem.Load(project, fileName); projectItem.Items.Add(pipeline.NewItemUri); project.Add(projectItem); project.Save(); var fileItemHandler = FileItemManager.GetFileItemHandler(source); if (fileItemHandler != null) { fileItemHandler.UpdateItemPath(pipeline.NewItemUri, projectItem.Path); } }
private ProjectFileItem AddToProject([NotNull] Project project, [NotNull] EnvDTE.ProjectItem item) { Debug.ArgumentNotNull(project, nameof(project)); Debug.ArgumentNotNull(item, nameof(item)); var fileName = project.GetProjectItemFileName(item); var projectItem = ProjectFileItem.Load(project, fileName); project.Add(projectItem); return(projectItem); }
private void Add() { var logWindow = new ProjectLogWindow { Maximum = addItems.Count }; logWindow.AutoStart = delegate { var iterator = new ElementIterator <AddItem>(addItems); iterator.Process = delegate(AddItem element) { logWindow.Increment(); if (!element.IsChecked) { iterator.Next(); return; } var project = element.Project; var fileName = project.GetProjectItemFileName(element.Item); var projectItem = ProjectFileItem.Load(project, fileName); project.Add(projectItem); logWindow.Write(projectItem.Path, Rocks.Resources.AddWindow_Add_added, string.Empty); logWindow.Increment(); iterator.Next(); }; iterator.Finish = delegate { logWindow.Write(Rocks.Resources.Finished, string.Empty, string.Empty); logWindow.Finish(); }; iterator.Start(); }; AppHost.Shell.ShowDialog(logWindow); SaveProjects(); }
private void CopyFile([NotNull] List <ProjectBase> projects, [NotNull] DragCopyPipeline.NewItem item) { Debug.ArgumentNotNull(projects, nameof(projects)); Debug.ArgumentNotNull(item, nameof(item)); var projectFileItem = ProjectManager.GetProjectFileItem(item.Item.ItemUri); if (projectFileItem == null) { return; } var project = projectFileItem.Project; var source = projectFileItem.AbsoluteFileName; var sourceFolder = Path.GetDirectoryName(source) ?? string.Empty; var extension = Path.GetExtension(source); var target = Path.Combine(sourceFolder, item.NewName) + extension; AppHost.Files.Copy(source, target, false); var newProjectItem = SitecorePackage.Instance.Dte.ItemOperations.AddExistingItem(target); var fileName = project.GetProjectItemFileName(newProjectItem); var projectItem = ProjectFileItem.Load(project, fileName); projectItem.Items.Add(item.NewItemUri); project.Add(projectItem); if (!projects.Contains(project)) { projects.Add(project); } var fileItemHandler = FileItemManager.GetFileItemHandler(source); if (fileItemHandler == null) { return; } fileItemHandler.UpdateItemPath(item.NewItemUri, projectItem.Path); }
protected override void Process(NewItemWizardPipeline pipeline) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); var project = ProjectManager.GetProject(pipeline.Item); if (project == null) { return; } var extension = Path.GetExtension(pipeline.Item.GetFileName()) ?? string.Empty; if (string.Compare(extension, ".package", StringComparison.InvariantCultureIgnoreCase) != 0) { return; } var fileName = project.GetProjectItemFileName(pipeline.Item); var projectItem = ProjectFileItem.Load(project, fileName); project.Add(projectItem); }
protected override void Process(NewItemWizardPipeline pipeline) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); string fileType; if (!pipeline.Tokens.TryGetValue("$filetype$", out fileType)) { return; } if (fileType != FileType) { return; } pipeline.Abort(); var project = ProjectManager.GetProject(pipeline.Item) ?? GetProject(pipeline); if (project == null) { return; } var site = project.Site; if (site == null) { return; } var itemPath = string.Empty; if (pipeline.DatabaseName == null) { var d = new NewItemWizardDialog(); d.Initialize(site, TemplateName); if (AppHost.Shell.ShowDialog(d) != true) { return; } var itemUri = d.ItemUri; if (itemUri == null || itemUri == ItemUri.Empty) { return; } pipeline.DatabaseName = itemUri.DatabaseName; itemPath = d.SelectedPath ?? string.Empty; if (!string.IsNullOrEmpty(itemPath)) { itemPath += "/" + Path.GetFileNameWithoutExtension(pipeline.Item.Name); } } var fileName = project.GetProjectItemFileName(pipeline.Item); var projectItem = ProjectFileItem.Load(project, fileName); project.Add(projectItem); var busy = true; Handle(pipeline, pipeline.DatabaseName, projectItem, itemPath, (sender, args) => busy = false); AppHost.DoEvents(ref busy); pipeline.ProjectItem = projectItem; }
protected override void Process(NewItemWizardPipeline pipeline) { Debug.ArgumentNotNull(pipeline, nameof(pipeline)); var template = pipeline.Template.Replace(@"xmlns=""http://schemas.microsoft.com/developer/vstemplate/2005""", string.Empty); var doc = XDocument.Parse(template); var itemElements = doc.XPathSelectElements(@"/VSTemplate/SitecoreItems/Item").ToList(); if (!itemElements.Any()) { itemElements = doc.XPathSelectElements(@"/VSTemplate/WizardData/SitecoreItems/Item").ToList(); } if (!itemElements.Any()) { return; } var project = ProjectManager.GetProject(pipeline.Item) ?? GetProject(pipeline); if (project == null) { return; } var site = project.Site; if (site == null) { return; } foreach (var element in itemElements) { var databaseName = Expand(pipeline, element.GetAttributeValue("DatabaseName")); var path = Expand(pipeline, element.GetAttributeValue("Path")); var name = Expand(pipeline, element.GetAttributeValue("Name")); var templateName = Expand(pipeline, element.GetAttributeValue("TemplateName")); var fields = new StringBuilder(); var first = true; foreach (var field in element.Elements()) { if (first) { first = false; } else { fields.Append('|'); } fields.Append(Expand(pipeline, field.GetAttributeValue("Name"))); fields.Append('|'); fields.Append(Expand(pipeline, field.GetAttributeValue("Value"))); } ExecuteCompleted completed = delegate(string response, ExecuteResult result) { if (!DataService.HandleExecute(response, result)) { return; } var parts = response.Split('|'); if (parts.Length != 2) { return; } Guid itemId; if (!Guid.TryParse(parts[0], out itemId)) { return; } Guid parentId; if (!Guid.TryParse(parts[1], out parentId)) { return; } var databaseUri = new DatabaseUri(site, new DatabaseName(databaseName)); var itemUri = new ItemUri(databaseUri, new ItemId(itemId)); var parentUri = new ItemUri(itemUri.DatabaseUri, new ItemId(parentId)); var fileName = project.GetProjectItemFileName(pipeline.Item); var projectItem = ProjectFileItem.Load(project, fileName); project.Add(projectItem); projectItem.Items.Add(itemUri); project.Save(); Notifications.RaiseItemAdded(this, new ItemVersionUri(itemUri, LanguageManager.CurrentLanguage, Data.Version.Latest), parentUri); }; site.DataService.ExecuteAsync("Items.CreateItem", completed, databaseName, path, name, templateName, fields.ToString()); } }
private static void Drop([NotNull] object sender, [NotNull] ItemTreeViewItem item, [NotNull] DragEventArgs args) { Debug.ArgumentNotNull(sender, nameof(sender)); Debug.ArgumentNotNull(item, nameof(item)); Debug.ArgumentNotNull(args, nameof(args)); if (!args.Data.GetDataPresent(@"CF_VSSTGPROJECTITEMS")) { return; } var fileName = args.Data.GetData(@"Text") as string ?? string.Empty; try { if (!File.Exists(fileName)) { return; } } catch { return; } var fileItemHandler = FileItemManager.GetFileItemHandler(fileName); if (fileItemHandler == null) { return; } Project project = null; string relativeFileName = null; foreach (var proj in ProjectManager.Projects) { relativeFileName = proj.GetRelativeFileName(fileName); if (relativeFileName == fileName) { continue; } if (proj.Site != item.ItemUri.Site) { continue; } project = proj; break; } if (project == null) { return; } var projectItem = project.GetProjectItem(relativeFileName) as ProjectFileItem; if (projectItem != null) { if (projectItem.Items.Any()) { return; } } projectItem = ProjectFileItem.Load(project, fileName); project.Add(projectItem); project.Save(); var itemPath = Path.Combine(item.GetPath(), Path.GetFileNameWithoutExtension(fileName) ?? string.Empty); fileItemHandler.Handle(item.ItemUri.DatabaseName, projectItem, itemPath, (s, e) => item.Refresh()); }