/// <summary>
        /// Handles the Click event of the removeFromAllReferencesMenuItem 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 removeFromAllReferencesMenuItem_Click(object sender,
                                                   MenuItemEventArgs e)
        {
            if (MessageBox.Show("Are you sure you want to remove this project item from all Features and Packages?", "Remove from all Features and Packages", MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.OK)
            {
                ISharePointProjectItem spi = e.Owner as ISharePointProjectItem;

                if (spi != null)
                {
                    ISharePointProjectLogger logger = spi.Project.ProjectService.Logger;
                    logger.ClearErrorList();
                    logger.ActivateOutputWindow();
                    logger.WriteLine(String.Format("Removing SharePoint Project Item '{0}' from Packages and Features...", spi.Name), LogCategory.Status);

                    var projects = spi.Project.ProjectService.Projects;

                    foreach (var project in projects)
                    {
                        ISharePointProjectItem spiInPackage = null;
                        foreach (ISharePointProjectItem s in project.Package.ProjectItems)
                        {
                            if (s.Id == spi.Id)
                            {
                                spiInPackage = s;
                                break;
                            }
                        }

                        if (spiInPackage != null)
                        {
                            project.Package.ProjectItems.Remove(spiInPackage);
                            logger.WriteLine(String.Format("SharePoint Project Item '{0}' removed from Package '{1}'", spi.Name, project.Package.Model.Name), LogCategory.Message, project.Package.PackageFile.FullPath, 1, 1);
                        }

                        foreach (var feature in project.Features)
                        {
                            ISharePointProjectItem spiInFeature = null;
                            foreach (var s in feature.ProjectItems)
                            {
                                if (s.Id == spi.Id)
                                {
                                    spiInFeature = s;
                                    break;
                                }
                            }

                            if (spiInFeature != null)
                            {
                                feature.ProjectItems.Remove(spiInFeature);
                                logger.WriteLine(String.Format("SharePoint Project Item '{0}' removed from Feature '{1}'", spi.Name, feature.Model.Title), LogCategory.Message, feature.FeatureFile.FullPath, 1, 1);
                            }
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the findAllReferencesMenuItem 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 findAllReferencesMenuItem_Click(object sender,
                                             MenuItemEventArgs e)
        {
            ISharePointProjectItem spi = e.Owner as ISharePointProjectItem;

            if (spi != null)
            {
                ISharePointProjectLogger logger = spi.Project.ProjectService.Logger;
                logger.ClearErrorList();
                logger.ActivateOutputWindow();
                logger.WriteLine(String.Format("Searching for references to SharePoint Project Item '{0}'...", spi.Name), LogCategory.Status);

                bool referencesFound = false;

                foreach (var project in spi.Project.ProjectService.Projects)
                {
                    if (SupportsDeploymentScope(spi.ProjectItemType.SupportedDeploymentScopes, SupportedDeploymentScopes.Package))
                    {
                        if ((from ISharePointProjectItem s
                             in project.Package.ProjectItems
                             where s.Id == spi.Id
                             select s).Any())
                        {
                            referencesFound = true;
                            spi.Project.ProjectService.Logger.WriteLine(String.Format("Found reference to SharePoint Project Item '{0}' in Package '{1}' ({2})", spi.Name, project.Package.Model.Name, project.Name), LogCategory.Message, project.Package.PackageFile.FullPath, 1, 1);
                        }
                    }

                    if (CanBeDeployedUsingFeature(spi.ProjectItemType.SupportedDeploymentScopes))
                    {
                        var spiInFeatures = from ISharePointProjectFeature f
                                            in project.Features
                                            where (from ISharePointProjectItem s
                                                   in f.ProjectItems
                                                   where s.Id == spi.Id
                                                   select s).Any()
                                            select f;

                        foreach (var feature in spiInFeatures)
                        {
                            referencesFound = true;
                            spi.Project.ProjectService.Logger.WriteLine(String.Format("Found reference to SharePoint Project Item '{0}' in Feature '{1}' ({2})", spi.Name, feature.Model.Title, feature.Project.Name), LogCategory.Message, feature.FeatureFile.FullPath, 1, 1);
                        }
                    }
                }

                if (!referencesFound)
                {
                    logger.WriteLine(String.Format("No references to SharePoint Project Item '{0}' found", spi.Name), LogCategory.Status);
                }
            }
        }
        /// <summary>
        /// Handles the Click event of the addToSpecificFeature 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 addToSpecificFeature_Click(object sender, MenuItemEventArgs e)
        {
            ISharePointProjectItem spi = e.Owner as ISharePointProjectItem;

            if (spi != null)
            {
                using (FeaturesViewerForm form = new FeaturesViewerForm(spi))
                {
                    if (form.ShowDialog() == DialogResult.OK && form.SelectedFeature != null)
                    {
                        form.SelectedFeature.ProjectItems.Add(spi);
                        ISharePointProjectLogger logger = spi.Project.ProjectService.Logger;
                        logger.ClearErrorList();
                        logger.ActivateOutputWindow();
                        logger.WriteLine(String.Format("SharePoint Project Item '{0}' successfully added to Feature '{1}'", spi.Name, form.SelectedFeature.Model.Title), LogCategory.Message, form.SelectedFeature.FullPath, 1, 1);
                    }
                }
            }
        }
Пример #4
0
        void buildAndDeployMenuItem_Click(object sender, MenuItemEventArgs e)
        {
            ISharePointProject       project = e.Owner as ISharePointProject;
            ISharePointProjectLogger logger  = project.ProjectService.Logger;

            logger.ActivateOutputWindow();

            if (project.Package.BuildPackage())
            {
                ProcessStartInfo gacutilStartInfo = new ProcessStartInfo(@"c:\Program Files (x86)\Microsoft SDKs\Windows\v8.0A\bin\NETFX 4.0 Tools\gacutil.exe", String.Format("/i {0}", project.OutputFullPath))
                {
                    RedirectStandardError  = true,
                    RedirectStandardOutput = true,
                    UseShellExecute        = false
                };
                Process gacutil = Process.Start(gacutilStartInfo);

                ThreadSafeStreamReader stdoutStream = new ThreadSafeStreamReader(gacutil.StandardOutput);
                ThreadSafeStreamReader stderrStream = new ThreadSafeStreamReader(gacutil.StandardError);

                Thread stdoutThread = new Thread(stdoutStream.Go);
                Thread stderrThread = new Thread(stdoutStream.Go);

                stdoutThread.Start();
                stderrThread.Start();

                stdoutThread.Join();
                stderrThread.Join();

                gacutil.WaitForExit();

                if (String.IsNullOrEmpty(stderrStream.Text))
                {
                    logger.WriteLine(stdoutStream.Text, LogCategory.Message);

                    logger.WriteLine("Recycling Application Pool...", LogCategory.Status);

                    string applicationPoolName = project.ProjectService.SharePointConnection.ExecuteCommand <string, string>(Commands.CommandIds.GetApplicationPoolName, project.SiteUrl.ToString());
                    if (!String.IsNullOrEmpty(applicationPoolName))
                    {
                        using (DirectoryEntry appPool = new DirectoryEntry(String.Format("IIS://localhost/w3svc/apppools/{0}", applicationPoolName))) {
                            appPool.Invoke("Stop", null);
                            appPool.Invoke("Start", null);
                        }

                        logger.WriteLine("Application Pool successfully recycled", LogCategory.Status);
                    }
                    else
                    {
                        logger.WriteLine("Application Pool not found", LogCategory.Error);
                    }
                }
                else
                {
                    logger.WriteLine(stderrStream.Text, LogCategory.Error);
                    logger.WriteLine("Installing assembly failed", LogCategory.Status);
                }
            }
            else
            {
                logger.WriteLine("Building Solution Package Failed", LogCategory.Error);
            }
        }