/// <summary>
        /// Outputs the code.
        /// </summary>
        /// <param name="tempFilePath">The temp file path.</param>
        /// <param name="sharePointInstallPath">The share point install path.</param>
        internal static void OutputCode(string tempFilePath, string sharePointInstallPath)
        {
            EnvDTE.Project activeProject = DTEManager.ActiveProject;

            if (activeProject != null)
            {
                try
                {
                    activeProject.ProjectItems.AddFromFileCopy(tempFilePath);
                    File.Delete(tempFilePath);

                    // add reference to Microsoft.SharePoint.Linq
                    VSLangProj.VSProject vsProject = (VSLangProj.VSProject)activeProject.Object;
                    vsProject.References.Add(Path.Combine(sharePointInstallPath, @"ISAPI\Microsoft.SharePoint.Linq.dll"));
                }
                catch (Exception e)
                {
                    MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                string code = File.ReadAllText(tempFilePath);
                File.Delete(tempFilePath);
                DTEManager.CreateNewTextFile(Path.GetFileName(tempFilePath), code);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Determines whether [is loaded share point project selected] [the specified DTE].
        /// </summary>
        /// <param name="dte">The DTE.</param>
        /// <param name="requireFarm">if set to <c>true</c> [require farm].</param>
        /// <returns>
        ///     <c>true</c> if [is loaded share point project selected] [the specified DTE]; otherwise, <c>false</c>.
        /// </returns>
        public static bool IsLoadedSharePointProjectSelected(EnvDTE.DTE dte, bool requireFarm)
        {
            // We must loop to check a project is not only selecetd but loaded.
            foreach (SelectedItem item in dte.SelectedItems)
            {
                // If selected item is a project, and it is loaded, and it is a SharePoint project, then at least one project is selected.
                if ((item.Project != null) && (item.Project.ConfigurationManager != null) && IsSharePointProject(item.Project, requireFarm))
                {
                    return(true);
                }
            }
            // no SP project selected, check startup projects
            SolutionBuild solutionBuild = dte.Solution.SolutionBuild;

            if (solutionBuild != null)
            {
                Array startupProj = solutionBuild.StartupProjects as Array;
                if (startupProj != null)
                {
                    foreach (String projectName in startupProj)
                    {
                        EnvDTE.Project project = DTEManager.GetProjectByName(projectName);
                        if ((project != null) && (project.ConfigurationManager != null) && IsSharePointProject(project, requireFarm))
                        {
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
Beispiel #3
0
        /// <summary>
        /// Adds the allow partially trusted callers attribute to the AssemblyInfo.
        /// </summary>
        /// <param name="dteProject">The DTE project.</param>
        public static void AddAllowPartiallyTrustedCallersAttribute(EnvDTE.Project dteProject)
        {
            EnvDTE.ProjectItem item = DTEManager.FindItemByName(dteProject.ProjectItems, "assemblyinfo.cs", true);

            bool contains = false;

            FileCodeModel2 model = (FileCodeModel2)item.FileCodeModel;

            foreach (CodeElement codeElement in model.CodeElements)
            {
                if (ExamineCodeElement(codeElement, "allowpartiallytrustedcallers", 3))
                {
                    contains = true;
                    break;
                }
            }

            //The attribute was not found so make sure it gets added.
            if (!contains)
            {
                model.AddAttribute("AllowPartiallyTrustedCallers", null);
            }
        }
Beispiel #4
0
        /// <summary>
        /// Gets the share point projects.
        /// </summary>
        /// <param name="isSolutionContext">if set to <c>true</c> [is solution context].</param>
        /// <param name="requireFarm">if set to <c>true</c> [require farm].</param>
        /// <returns></returns>
        public static ISharePointProject[] GetSharePointProjects(bool isSolutionContext, bool requireFarm)
        {
            List <EnvDTE.Project> candidateProjects = new List <EnvDTE.Project>();

            if (isSolutionContext)
            {
                foreach (EnvDTE.Project project in DTEManager.DTE.Solution.Projects)
                {
                    candidateProjects.Add(project);
                }
            }
            else
            {
                foreach (SelectedItem item in DTEManager.DTE.SelectedItems)
                {
                    if (item.Project != null)
                    {
                        candidateProjects.Add(item.Project);
                    }
                }
            }

            List <ISharePointProject> spProjects = new List <ISharePointProject>();

            foreach (EnvDTE.Project project in candidateProjects)
            {
                ISharePointProject spProject = DTEManager.ProjectService.Convert <EnvDTE.Project, ISharePointProject>(project);
                if (spProject != null)
                {
                    if ((!spProject.IsSandboxedSolution) || (!requireFarm))
                    {
                        spProjects.Add(spProject);
                    }
                }
            }

            // no SP project selected, check startup projects
            if (spProjects.Count == 0)
            {
                SolutionBuild solutionBuild = DTEManager.DTE.Solution.SolutionBuild;
                if (solutionBuild != null)
                {
                    Array startupProj = solutionBuild.StartupProjects as Array;
                    if (startupProj != null)
                    {
                        foreach (String projectName in startupProj)
                        {
                            EnvDTE.Project project = DTEManager.GetProjectByName(projectName);
                            if (project != null)
                            {
                                ISharePointProject spProject = DTEManager.ProjectService.Convert <EnvDTE.Project, ISharePointProject>(project);
                                if (spProject != null)
                                {
                                    if ((!spProject.IsSandboxedSolution) || (!requireFarm))
                                    {
                                        spProjects.Add(spProject);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(spProjects.ToArray());
        }