private FileWatcherService(ISharePointProjectService projectService) { this.ProjectService = projectService; this.FileListener = new Dictionary <string, FileEventListener>(StringComparer.OrdinalIgnoreCase); this.ProjectTokenReplacements = new Dictionary <Guid, Dictionary <string, string> >(); this.ProjectTokenReplacementFileExtensions = new Dictionary <Guid, string[]>(); }
/// <summary> /// Initializes the SharePoint project extension. /// </summary> /// <param name="projectService">An instance of SharePoint project service.</param> public void Initialize(ISharePointProjectService projectService) { if (EnabledExtensionsOptionsPage.GetSetting <bool>(EnabledExtensionsOptions.ActivateSelectedFeatures, true)) { projectService.ProjectMenuItemsRequested += new EventHandler <SharePointProjectMenuItemsRequestedEventArgs>(projectService_ProjectMenuItemsRequested); } }
internal static string GetStartupUrl(DTE dte, Project project) { try { ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(dte); if (project != null) { try { //set url for current project ISharePointProject sharePointProject = projectService.Convert <EnvDTE.Project, ISharePointProject>(project); if (sharePointProject.StartupUrl != null) { return(sharePointProject.StartupUrl.ToString()); } return(sharePointProject.SiteUrl.ToString()); } catch { } } } catch { } return(Helpers.GetApplicationConfigValue(dte, "StartupUrl", Helpers.GetApplicationConfigValue(dte, "DebuggingWebApp", "").ToString()).ToString()); }
/// <summary> /// Detects if a project is a SharePoint project based on a list of project type GUIDs. /// </summary> public static bool IsSharePointProject(EnvDTE.Project project, bool requireFarm) { //TODO: move this into the project utilities try { ISharePointProjectService projectService = DTEManager.ProjectService; if (projectService != null) { // Convert the DTE project into a SharePoint project. If the conversion fails, this is not a SP project. ISharePointProject p = projectService.Convert <EnvDTE.Project, Microsoft.VisualStudio.SharePoint.ISharePointProject>(project); if (p != null && requireFarm) { return(!p.IsSandboxedSolution); } else { return(p != null); } } } catch { // Must be VERY careful not to throw exceptions in here, since this is called on every click of the context menu. } return(false); }
private string GetDebuggingSite(DTE dte) { try { ISharePointProjectService projectService = Helpers.GetSharePointProjectService(dte); if (projectService != null) { //set url for all projects foreach (ISharePointProject sharePointProject in projectService.Projects) { try { if (sharePointProject.SiteUrl != null) { if (sharePointProject.SiteUrl.ToString() != "") { return(sharePointProject.SiteUrl.ToString()); } } } catch (Exception ex) { } } } } catch { } return(""); }
/// <summary> /// Imports the type of the content. /// </summary> /// <param name="contentTypeInfo">The content type info.</param> public static void ImportContentType(ContentTypeInfo contentTypeInfo) { if (contentTypeInfo != null) { //Create the encoding definition XDeclaration declaration = new XDeclaration("1.0", Encoding.UTF8.WebName, null); XNamespace sharepointToolsNamespace = @"http://schemas.microsoft.com/VisualStudio/2010/SharePointTools/SharePointProjectItemModel"; XNamespace sharepointNamespace = @"http://schemas.microsoft.com/sharepoint/"; XElement elementsFileContents = XElement.Parse(BuildElements(contentTypeInfo, declaration, sharepointNamespace)); EnvDTE.Project activeProject = DTEManager.ActiveProject; if (activeProject != null) { ISharePointProjectService projectService = DTEManager.ProjectService; ISharePointProject activeSharePointProject = DTEManager.ActiveSharePointProject; if (activeSharePointProject != null) { ISharePointProjectItem contentTypeProjectItem = activeSharePointProject.ProjectItems.Add(contentTypeInfo.Name, "Microsoft.VisualStudio.SharePoint.ContentType"); System.IO.File.WriteAllText(Path.Combine(contentTypeProjectItem.FullPath, "Elements.xml"), elementsFileContents.ToString().Replace("xmlns=\"\"", String.Empty)); ISharePointProjectItemFile elementsXml = contentTypeProjectItem.Files.AddFromFile("Elements.xml"); elementsXml.DeploymentType = DeploymentType.ElementManifest; elementsXml.DeploymentPath = String.Format(@"{0}\", contentTypeInfo.Name); contentTypeProjectItem.DefaultFile = elementsXml; } } } }
public void Initialize(ISharePointProjectService projectService) { if (projectService.IsSharePointInstalled) { projectService.ProjectPropertiesRequested += new EventHandler <SharePointProjectPropertiesRequestedEventArgs>(projectService_ProjectPropertiesRequested); } }
/// <summary> /// Initializes the SharePoint project extension. /// </summary> /// <param name="projectService">An instance of SharePoint project service.</param> public void Initialize(ISharePointProjectService projectService) { if (EnabledExtensionsOptionsPage.GetSetting <bool>(EnabledExtensionsOptions.CopyAssemblyName, true)) { projectService.ProjectMenuItemsRequested += new EventHandler <SharePointProjectMenuItemsRequestedEventArgs>(projectService_ProjectMenuItemsRequested); } }
/// <summary> /// Recycles all application pools. /// </summary> /// <param name="service">The service.</param> public void RecycleAllApplicationPools(ISharePointProjectService service) { string[] names = GetAllApplicationPoolNames(service); foreach (string name in names) { RecycleApplicationPool(name); } }
public void Initialize(ISharePointProjectService projectService) { var items = from pi in projectService.ProjectItemTypes where pi.Key == "Microsoft.VisualStudio.SharePoint.ListDefinition" select pi.Value; var listType = items.FirstOrDefault(); listType.ProjectItemMenuItemsRequested += ContextMenuRequested; }
public EventHandler( ISharePointProjectService spProjectService, IVsRunningDocumentTable rdt ) { _spProjService = spProjectService; _rdt = rdt; }
/// <summary> /// Quick copy this artefact and all children via all projects and artefacts in the project it is packaged in. /// </summary> /// <param name="service">The SharePoint service.</param> /// <param name="requiresQuickPackage">Flag to indicate if this requires quick package.</param> public void QuickCopy(ISharePointProjectService service, bool requiresQuickPackage) { IEnumerable <ISharePointProject> projects = this.GetPackagedProjects(service); foreach (ISharePointProject project in projects) { this.QuickCopy(new SharePointPackageArtefact(project), requiresQuickPackage); } }
public void Initialize(ISharePointProjectService projectService) { projectService.ProjectAdded += projectService_ProjectAdded; projectService.ProjectInitialized += projectService_ProjectInitialized; projectService.ProjectNameChanged += projectService_ProjectNameChanged; projectService.ProjectPropertyChanged += projectService_ProjectPropertyChanged; projectService.ProjectRemoved += projectService_ProjectRemoved; projectService.ProjectDisposing += projectService_ProjectDisposing; }
/// <summary> /// Initializes the SharePoint project extension. /// </summary> /// <param name="projectService">An instance of SharePoint project service.</param> public void Initialize(ISharePointProjectService projectService) { if (EnabledExtensionsOptionsPage.GetSetting <bool>(EnabledExtensionsOptions.SPIReferences, true)) { foreach (ISharePointProjectItemType spit in projectService.ProjectItemTypes.Values) { spit.ProjectItemMenuItemsRequested += new EventHandler <SharePointProjectItemMenuItemsRequestedEventArgs>(spit_ProjectItemMenuItemsRequested); } } }
public void Initialize(ISharePointProjectService projectService) { if (!projectService.IsSharePointInstalled) { return; } FileWatcherService.Initialize(projectService); SolutionEventListener.Initialize(projectService.ServiceProvider); }
/// <summary> /// Gets the onet contents. /// </summary> /// <param name="projectService">The project service.</param> /// <param name="siteDefinitionName">Name of the site definition.</param> /// <param name="siteDefinitionConfig">The site definition config.</param> /// <param name="setupPath">The setup path.</param> /// <param name="webTemplateName">Name of the web template.</param> /// <param name="webTemplateTitle">The web template title.</param> /// <param name="replacements">The replacements.</param> /// <param name="welcomePageType">Type of the welcome page.</param> /// <returns></returns> private string GetOnetContents(ISharePointProjectService projectService, string siteDefinitionName, string siteDefinitionConfig, string setupPath, string webTemplateName, string webTemplateTitle, IDictionary <string, string> replacements, out WelcomePageType welcomePageType) { string onetContents = String.Empty; welcomePageType = WelcomePageType.WebPartPage; string templatesFolderPath = projectService.SharePointConnection.ExecuteCommand <string, string>(ObjectModelSharePointCommandIds.GetFullSPRootFolderPath, @"TEMPLATE"); string siteDefinitionOnetPath = Path.Combine(templatesFolderPath, String.IsNullOrEmpty(setupPath) ? Path.Combine("SiteTemplates", siteDefinitionName) : setupPath, @"xml\onet.xml"); XElement xProject = XElement.Parse(File.ReadAllText(siteDefinitionOnetPath)); xProject.Descendants("ListTemplates").Remove(); xProject.Descendants("DocumentTemplates").Remove(); xProject.Descendants("ServerEmailFooter").Remove(); xProject.Descendants("Configurations").Descendants("Configuration").Where(xConfig => xConfig.Attribute("ID").Value != siteDefinitionConfig).Remove(); xProject.Descendants("Configurations").Descendants("Configuration").Descendants("Modules").Remove(); xProject.Descendants("Modules").Remove(); xProject.Attribute("Title").Value = webTemplateTitle; XElement xConfiguration = xProject.Descendants("Configurations").Descendants("Configuration").First(); xConfiguration.Attribute("ID").Value = "0"; xConfiguration.Attribute("Name").Value = webTemplateName; XElement xWebFeatures = xConfiguration.Descendants("WebFeatures").First(); xWebFeatures.Add( new XComment(String.Format("{0} Welcome Page", webTemplateTitle)), new XElement("Feature", new XAttribute("ID", replacements["$guid3$"])), new XComment(String.Format("{0} Stamp", webTemplateTitle)), new XElement("Feature", new XAttribute("ID", replacements["$guid2$"]))); onetContents = xProject.ToString(); if (onetContents.IndexOf("00BFEA71-D8FE-4FEC-8DAD-01C19A6E4053", StringComparison.InvariantCultureIgnoreCase) > 0) { welcomePageType = WelcomePageType.WikiPage; } else if (onetContents.IndexOf("94C94CA6-B32F-4da9-A9E3-1F3D343D7ECB", StringComparison.InvariantCultureIgnoreCase) > 0) { welcomePageType = WelcomePageType.PublishingPage; } return(onetContents); }
void writeMessageMenuItem_Click(object sender, MenuItemEventArgs e) { IExplorerNode node = (IExplorerNode)e.Owner; if (projectService == null) { projectService = (ISharePointProjectService)node.ServiceProvider.GetService(typeof(ISharePointProjectService)); } projectService.Logger.WriteLine("Clicked the menu item for " + node.Text, LogCategory.Message); }
/// <summary> /// Initializes the SharePoint project extension. /// </summary> /// <param name="projectService">Instance of SharePoint project service.</param> public void Initialize(ISharePointProjectService projectService) { if (EnabledExtensionsOptionsPage.GetSetting <bool>(EnabledExtensionsOptions.CancelAddingSPIs, true)) { foreach (ISharePointProjectItemType type in projectService.ProjectItemTypes.Values) { type.ProjectItemAdded += new EventHandler <SharePointProjectItemEventArgs>(spiType_ProjectItemAdded); type.ProjectItemInitialized += new EventHandler <SharePointProjectItemEventArgs>(spiType_ProjectItemInitialized); } } }
void ImportListInstanceExplorerExtension_Click(object sender, MenuItemEventArgs e) { IExplorerNode listNode = e.Owner as IExplorerNode; if (listNode != null) { try { IListNodeInfo listInfo = listNode.Annotations.GetValue <IListNodeInfo>(); string listInstanceContents = listNode.Context.SharePointConnection.ExecuteCommand <Guid, string>(CommandIds.GetListInstanceXmlCommandId, listInfo.Id); XNamespace xn = "http://schemas.microsoft.com/sharepoint/"; string moduleContents = new XElement(xn + "Elements", XElement.Parse(listInstanceContents)).ToString().Replace(" xmlns=\"\"", String.Empty); EnvDTE.Project activeProject = Utils.GetActiveProject(); if (activeProject != null) { ISharePointProjectService projectService = listNode.ServiceProvider.GetService(typeof(ISharePointProjectService)) as ISharePointProjectService; ISharePointProject activeSharePointProject = projectService.Projects[activeProject.FullName]; if (activeSharePointProject != null) { string spiName = listInfo.Title; ISharePointProjectItem listInstanceProjectItem = null; bool itemCreated = false; int counter = 0; do { try { listInstanceProjectItem = activeSharePointProject.ProjectItems.Add(spiName, "Microsoft.VisualStudio.SharePoint.ListInstance"); itemCreated = true; } catch (ArgumentException) { spiName = String.Format("{0}{1}", listInfo.Title, ++counter); } }while (!itemCreated); string elementsXmlFullPath = Path.Combine(listInstanceProjectItem.FullPath, "Elements.xml"); System.IO.File.WriteAllText(elementsXmlFullPath, moduleContents); ISharePointProjectItemFile elementsXml = listInstanceProjectItem.Files.AddFromFile("Elements.xml"); elementsXml.DeploymentType = DeploymentType.ElementManifest; elementsXml.DeploymentPath = String.Format(@"{0}\", spiName); listInstanceProjectItem.DefaultFile = elementsXml; Utils.OpenFile(Path.Combine(elementsXmlFullPath)); } } } catch (Exception ex) { listNode.Context.ShowMessageBox(String.Format("The following exception occured while exporting List Instance: {0}", ex.Message), MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
/// <summary> /// Imports the field. /// </summary> /// <param name="fieldNode">The field node.</param> /// <exception cref="System.ArgumentNullException"></exception> public static void ImportField(IExplorerNode fieldNode) { if (fieldNode == null) { throw new ArgumentNullException("fieldNode"); } Microsoft.VisualStudio.SharePoint.Explorer.Extensions.IFieldNodeInfo nodeInfo = fieldNode.Annotations.GetValue <Microsoft.VisualStudio.SharePoint.Explorer.Extensions.IFieldNodeInfo>(); if (nodeInfo != null) { FieldNodeInfo fieldNodeInfo = new FieldNodeInfo { ContentTypeName = nodeInfo.ContentTypeName, Id = nodeInfo.Id, IsHidden = nodeInfo.IsHidden, ListId = nodeInfo.ListId, Title = nodeInfo.Title }; Dictionary <string, string> fieldProperties = null; if (String.IsNullOrEmpty(fieldNodeInfo.ContentTypeName) && fieldNodeInfo.ListId == Guid.Empty) { fieldProperties = fieldNode.Context.SharePointConnection.ExecuteCommand <FieldNodeInfo, Dictionary <string, string> >(SiteColumnsSharePointCommandIds.GetProperties, fieldNodeInfo); } else { fieldProperties = fieldNode.Context.SharePointConnection.ExecuteCommand <FieldNodeInfo, Dictionary <string, string> >(FieldSharePointCommandIds.GetProperties, fieldNodeInfo); } if (fieldProperties != null) { XNamespace xn = XNamespace.Get("http://schemas.microsoft.com/sharepoint/"); XElement xElements = new XElement(xn + "Elements", XElement.Parse(fieldProperties["SchemaXml"])); EnvDTE.Project activeProject = DTEManager.ActiveProject; if (activeProject != null) { ISharePointProjectService projectService = fieldNode.ServiceProvider.GetService(typeof(ISharePointProjectService)) as ISharePointProjectService; ISharePointProject activeSharePointProject = projectService.Projects[activeProject.FullName]; if (activeSharePointProject != null) { ISharePointProjectItem fieldProjectItem = activeSharePointProject.ProjectItems.Add(fieldProperties["InternalName"], "Microsoft.VisualStudio.SharePoint.Field"); System.IO.File.WriteAllText(Path.Combine(fieldProjectItem.FullPath, "Elements.xml"), xElements.ToString().Replace("xmlns=\"\"", String.Empty)); ISharePointProjectItemFile elementsXml = fieldProjectItem.Files.AddFromFile("Elements.xml"); elementsXml.DeploymentType = DeploymentType.ElementManifest; elementsXml.DeploymentPath = String.Format(@"{0}\", fieldProperties["InternalName"]); fieldProjectItem.DefaultFile = elementsXml; } } } } }
public override void Execute() { if (string.IsNullOrEmpty(SiteUrl)) { return; } EnvDTE.DTE service = this.GetService <EnvDTE.DTE>(true); if (!string.IsNullOrEmpty(CurrentProjectName)) { CurrentProject = Helpers.GetProjectByName(service, CurrentProjectName); } try { ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(service); if (CurrentProject != null) { try { //set url for current project ISharePointProject sharePointProject = projectService.Convert <EnvDTE.Project, ISharePointProject>(CurrentProject); sharePointProject.SiteUrl = new Uri(SiteUrl); } catch { } } else { //set url for all projects foreach (ISharePointProject sharePointProject in projectService.Projects) { try { if (sharePointProject.SiteUrl == null) { sharePointProject.SiteUrl = new Uri(SiteUrl); Helpers.LogMessage(service, this, "Settings site url of project " + sharePointProject.Name + " to " + new Uri(SiteUrl).ToString()); } } catch (Exception) { Helpers.LogMessage(service, this, "Could not set site url of project " + sharePointProject.Name + " to " + new Uri(SiteUrl).ToString()); } } } } catch { } }
/// <summary> /// Recycles the application pool. /// </summary> /// <param name="service">The service.</param> /// <param name="url">The URL.</param> /// <returns></returns> public bool RecycleApplicationPool(ISharePointProjectService service, string url) { string name = GetApplicationPoolName(service, url); if (String.IsNullOrEmpty(name)) { return(false); } else { RecycleApplicationPool(name); return(true); } }
/// <summary> /// Handles the Click event of the SPMetalListNodeExtension control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="Microsoft.VisualStudio.SharePoint.MenuItemEventArgs"/> instance containing the event data.</param> void SPMetalListNodeExtension_Click(object sender, MenuItemEventArgs e) { IExplorerNode listNode = e.Owner as IExplorerNode; IListNodeInfo listInfo = listNode.Annotations.GetValue <IListNodeInfo>(); ISharePointProjectService projectService = (ISharePointProjectService)listNode.ServiceProvider.GetService(typeof(ISharePointProjectService)); if (projectService != null) { string tempParamsFilePath = Path.GetTempFileName(); File.WriteAllText(tempParamsFilePath, String.Format(CKSProperties.SPMetalListParametersXml, listInfo.Title)); SPMetalUtilities.RunSPMetal(listNode.Context.SiteUrl.ToString(), String.Format(" /parameters:{0}", tempParamsFilePath), ProjectUtilities.GetSafeFileName(listInfo.Title) + ".cs", projectService); File.Delete(tempParamsFilePath); } }
private void SetDeploymentPath(DTE dte, Project project, ProjectItem CreatedProjectItem, SPFileType sPFileType, string evaluatedDeploymentPath) { //set to content if ((sPFileType != SPFileType.CustomCode)) { CreatedProjectItem.Properties.Item("BuildAction").Value = 2; } //ok, file is placed, but we need set the deployment path ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(dte); ISharePointProject sharePointProject = projectService.Convert <EnvDTE.Project, ISharePointProject>(project); sharePointProject.Synchronize(); if (CreatedProjectItem.Collection.Parent is ProjectItem) { ProjectItem parentItem = CreatedProjectItem.Collection.Parent as ProjectItem; string name = parentItem.Name; //is the parent element a feature? try { ISharePointProjectFeature parentIsFeature = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectFeature>(parentItem); if (parentIsFeature != null) { ISharePointProjectItem addedSharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItem>(CreatedProjectItem); if (addedSharePointItem != null) { parentIsFeature.ProjectItems.Add(addedSharePointItem); } } } catch { } } try { //sometimes property deploymentpath is readonly //1. new added items need to be validated before ISharePointProjectItemFile newaddedSharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItemFile>(CreatedProjectItem); newaddedSharePointItem.DeploymentType = Helpers2.GetDeploymentTypeFromFileType(this.DeploymentType); if (!string.IsNullOrEmpty(evaluatedDeploymentPath)) { newaddedSharePointItem.DeploymentPath = evaluatedDeploymentPath; } } catch { } }
public static void Initialize(ISharePointProjectService projectService) { var fileWatcherService = new FileWatcherService(projectService); var existingProjectItemFiles = projectService.Projects .SelectMany(p => p.ProjectItems) .SelectMany(i => i.Files) .Where(f => f.DeploymentType == DeploymentType.TemplateFile || f.DeploymentType == DeploymentType.RootFile) .ToArray(); foreach (var file in existingProjectItemFiles) { fileWatcherService.AddFile(file.FullPath); } FileWatcherService.Current = fileWatcherService; }
public override void Execute() { if (string.IsNullOrEmpty(DeploymentTarget)) { return; } var service = this.GetService <DTE>(true); if (!string.IsNullOrEmpty(CurrentProjectName)) { CurrentProject = Helpers.GetProjectByName(service, CurrentProjectName); } try { ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(service); if (CurrentProject != null) { try { //set url for current project ISharePointProject sharePointProject = projectService.Convert <Project, ISharePointProject>(CurrentProject); ChangeDeploymentTarget(sharePointProject, DeploymentTarget); } catch { } } else { foreach (ISharePointProject sharePointProject in projectService.Projects) { try { ChangeDeploymentTarget(sharePointProject, DeploymentTarget); } catch { } } } } catch { } }
// 实现 IProjectItemTypeProvider.InitializeType。配置该项目项类型的行为。 public void InitializeType(ISharePointProjectItemTypeDefinition projectItemTypeDefinition) { projectItemTypeDefinition.Name = "CustomAction"; projectItemTypeDefinition.SupportedDeploymentScopes = SupportedDeploymentScopes.Site | SupportedDeploymentScopes.Web; projectItemTypeDefinition.SupportedTrustLevels = SupportedTrustLevels.All; // 获取服务,以便此类中的其他代码可以使用它。 projectService = projectItemTypeDefinition.ProjectService; // 处理某些项目项事件。 projectItemTypeDefinition.ProjectItemInitialized += ProjectItemInitialized; projectItemTypeDefinition.ProjectItemNameChanged += ProjectItemNameChanged; projectItemTypeDefinition.ProjectItemDisposing += ProjectItemDisposing; // 处理事件以便为此项目项创建自定义属性和快捷菜单项。 projectItemTypeDefinition.ProjectItemPropertiesRequested += ProjectItemPropertiesRequested; projectItemTypeDefinition.ProjectItemMenuItemsRequested += ProjectItemMenuItemsRequested; }
// Implements IProjectItemTypeProvider.InitializeType. Configures the behavior of the project item type. public void InitializeType(ISharePointProjectItemTypeDefinition projectItemTypeDefinition) { projectItemTypeDefinition.Name = "CustomAction"; projectItemTypeDefinition.SupportedDeploymentScopes = SupportedDeploymentScopes.Site | SupportedDeploymentScopes.Web; projectItemTypeDefinition.SupportedTrustLevels = SupportedTrustLevels.All; // Get the service so that other code in this class can use it. projectService = projectItemTypeDefinition.ProjectService; // Handle some project item events. projectItemTypeDefinition.ProjectItemInitialized += ProjectItemInitialized; projectItemTypeDefinition.ProjectItemNameChanged += ProjectItemNameChanged; projectItemTypeDefinition.ProjectItemDisposing += ProjectItemDisposing; // Handle events to create a custom property and shortcut menu item for this project item. projectItemTypeDefinition.ProjectItemPropertiesRequested += ProjectItemPropertiesRequested; projectItemTypeDefinition.ProjectItemMenuItemsRequested += ProjectItemMenuItemsRequested; }
private bool ItemIsDeployable(ProjectItem pitem) { string sourcefilename = Helpers.GetFullPathOfProjectItem(pitem); if (!Helpers2.IsFileDeployableToHive(sourcefilename)) { return(false); } try { ISharePointProjectService projectService = Helpers2.GetSharePointProjectService(pitem.DTE); try { ISharePointProjectItemFile selectedSharePointItem = projectService.Convert <EnvDTE.ProjectItem, ISharePointProjectItemFile>(pitem); if (selectedSharePointItem != null && selectedSharePointItem.DeploymentPath != "") { return(true); } } catch { } } catch { } //check if the parent is folder 12 try { string itemPath = Helpers.GetFullPathOfProjectItem(pitem); string projectPath = Helpers.GetProjectFolder(pitem.ContainingProject); itemPath = itemPath.Substring(projectPath.Length + 1); if (itemPath.StartsWith(@"12") || itemPath.StartsWith(@"14") || itemPath.StartsWith(@"15") || itemPath.StartsWith(@"SharePointRoot", StringComparison.InvariantCultureIgnoreCase)) { return(true); } } catch { } return(false); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private async void Execute(object sender, EventArgs e) { await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); DTE dte = await this.ServiceProvider.GetServiceAsync(typeof(DTE)) as DTE; ISharePointProjectService sharePointProjectService = await this.ServiceProvider.GetServiceAsync(typeof(ISharePointProjectService)) as ISharePointProjectService; var selectedProjects = dte.ActiveSolutionProjects as Array; if (selectedProjects != null && selectedProjects.Length > 0) { var currentProject = sharePointProjectService.Convert <Project, ISharePointProject>((Project)selectedProjects.GetValue(0)) as ISharePointProject; var extService = new SPProjectExtService(currentProject); var assembliesToDeploy = extService.GetDeployableAssemblies(out string[] missing); if (assembliesToDeploy.Any()) { var gacService = new System.EnterpriseServices.Internal.Publish(); currentProject.ProjectService.Logger.ActivateOutputWindow(); currentProject.ProjectService.Logger.WriteLine("========= Copy to GAC ===========", LogCategory.Status); foreach (var assembly in assembliesToDeploy) { currentProject.ProjectService.Logger.WriteLine(Path.GetFileName(assembly) + "...", LogCategory.Status); gacService.GacInstall(assembly); } if (missing.Any()) { currentProject.ProjectService.Logger.WriteLine("Missing:", LogCategory.Status); foreach (var missingAssembly in missing) { currentProject.ProjectService.Logger.WriteLine(Path.GetFileName(missingAssembly), LogCategory.Status); } } currentProject.ProjectService.Logger.WriteLine($"===== Copy to GAC done at {DateTime.Now:hh:mm:ss} =====", LogCategory.Status); extService.RecyclePools(); } } }
void menuItem_Click(object sender, MenuItemEventArgs e) { // Get the data for the list node. IExplorerNode node = (IExplorerNode)e.Owner; //<Snippet11> IListNodeInfo nodeInfo = node.Annotations.GetValue <IListNodeInfo>(); //</Snippet11> if (dteObject == null) { if (projectService == null) { projectService = (ISharePointProjectService)node.ServiceProvider.GetService( typeof(ISharePointProjectService)); } dteObject = (EnvDTE.DTE)projectService.ServiceProvider.GetService(typeof(EnvDTE.DTE)); } dteObject.ItemOperations.Navigate(nodeInfo.DefaultViewUrl.ToString(), EnvDTE.vsNavigateOptions.vsNavigateOptionsNewWindow); }