public int OnQueryRenameFiles(IVsProject ivsProject, int filesLength, string[] oldNames, string[] newNames,
                               VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult,
                               VSQUERYRENAMEFILERESULTS[] rgResults)
 {
     try
     {
         EnvDTE.Project project = DTEUtil.GetProject(ivsProject as IVsHierarchy);
         if (DTEUtil.IsIceBuilderEnabled(project))
         {
             for (int i = 0; i < filesLength; ++i)
             {
                 if (Path.GetExtension(oldNames[i]).Equals(".ice") &&
                     Path.GetExtension(newNames[i]).Equals(".ice"))
                 {
                     if (!ProjectUtil.CheckGenerateFileIsValid(project, newNames[i]))
                     {
                         rgResults[i] = VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return(0);
 }
 public int OnAfterRenameFiles(int projectsLength, int filesLength, IVsProject[] projects, int[] indices,
                               string[] oldNames, string[] newNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     try
     {
         for (int i = 0; i < projectsLength; ++i)
         {
             EnvDTE.Project project = DTEUtil.GetProject(projects[i] as IVsHierarchy);
             if (DTEUtil.IsIceBuilderEnabled(project))
             {
                 int j = indices[i];
                 int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength;
                 for (; j < k; ++j)
                 {
                     ProjectUtil.DeleteItems(project, ProjectUtil.GetGeneratedFiles(project, oldNames[j]));
                     if (ProjectUtil.IsSliceFileName(newNames[j]))
                     {
                         ProjectUtil.SetupGenerated(project, newNames[j]);
                     }
                 }
                 Package.Instance.FileTracker.Reap(project);
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return(0);
 }
 public int OnQueryAddFiles(IVsProject p, int length, string[] files,
                            VSQUERYADDFILEFLAGS[] rgFlags, VSQUERYADDFILERESULTS[] pSummaryResult,
                            VSQUERYADDFILERESULTS[] rgResults)
 {
     try
     {
         EnvDTE.Project project = DTEUtil.GetProject(p as IVsHierarchy);
         if (DTEUtil.IsIceBuilderEnabled(project))
         {
             for (int i = 0; i < length; ++i)
             {
                 String path = files[i];
                 if (Path.GetExtension(path).Equals(".ice"))
                 {
                     if (!ProjectUtil.CheckGenerateFileIsValid(project, path))
                     {
                         pSummaryResult[i] = VSQUERYADDFILERESULTS.VSQUERYADDFILERESULTS_AddNotOK;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return(0);
 }
Ejemplo n.º 4
0
 public int OnQueryAddFiles(IVsProject project, int length, string[] files,
                            VSQUERYADDFILEFLAGS[] rgFlags, VSQUERYADDFILERESULTS[] pSummaryResult,
                            VSQUERYADDFILERESULTS[] rgResults)
 {
     try
     {
         if (files.Any(f => ProjectUtil.IsSliceFileName(f)))
         {
             IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project);
             if (projectType != IceBuilderProjectType.None)
             {
                 for (int i = 0; i < length; ++i)
                 {
                     if (ProjectUtil.IsSliceFileName(files[i]))
                     {
                         if (!ProjectUtil.CheckGenerateFileIsValid(project, projectType, files[i]))
                         {
                             pSummaryResult[i] = VSQUERYADDFILERESULTS.VSQUERYADDFILERESULTS_AddNotOK;
                         }
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return(0);
 }
        public int OnAfterAddFilesEx(int projectsLength, int filesLength, IVsProject[] projects, int[] indices,
                                     string[] paths, VSADDFILEFLAGS[] rgFlags)
        {
            try
            {
                for (int i = 0; i < projectsLength; ++i)
                {
                    EnvDTE.Project project = DTEUtil.GetProject(projects[i] as IVsHierarchy);
                    if (DTEUtil.IsIceBuilderEnabled(project))
                    {
                        int j = indices[i];
                        int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength;

                        for (; j < k; ++j)
                        {
                            if (ProjectUtil.IsSliceFileName(paths[j]))
                            {
                                ProjectUtil.SetupGenerated(project, paths[j]);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Package.UnexpectedExceptionWarning(ex);
                throw;
            }
            return(0);
        }
Ejemplo n.º 6
0
 public int OnQueryRenameFiles(IVsProject project, int filesLength, string[] oldNames, string[] newNames,
                               VSQUERYRENAMEFILEFLAGS[] rgFlags, VSQUERYRENAMEFILERESULTS[] pSummaryResult,
                               VSQUERYRENAMEFILERESULTS[] rgResults)
 {
     try
     {
         IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project);
         if (projectType != IceBuilderProjectType.None)
         {
             for (int i = 0; i < filesLength; ++i)
             {
                 if (ProjectUtil.IsSliceFileName(newNames[i]))
                 {
                     if (!ProjectUtil.CheckGenerateFileIsValid(project, projectType, newNames[i]))
                     {
                         rgResults[i] = VSQUERYRENAMEFILERESULTS.VSQUERYRENAMEFILERESULTS_RenameNotOK;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return(0);
 }
        public void InitializeProjects(List <IVsProject> upgradeProjects)
        {
            ProjectConverter.TryUpgrade(upgradeProjects);

            List <IVsProject> projects = DTEUtil.GetProjects();

            List <IVsProject> sliceProjects = new List <IVsProject>();

            foreach (IVsProject project in projects)
            {
                IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project);

                if (projectType != IceBuilderProjectType.None)
                {
                    if (projectType == IceBuilderProjectType.CppProjectType)
                    {
                        VCUtil.SetupSliceFilter(DTEUtil.GetProject(project as IVsHierarchy));
                    }
                    if (AutoBuilding)
                    {
                        sliceProjects.Add(project);
                    }
                    else
                    {
                        FileTracker.Add(project, projectType);
                    }
                }
            }

            if (AutoBuilding)
            {
                QueueProjectsForBuilding(sliceProjects);
            }
        }
Ejemplo n.º 8
0
 public int OnAfterRenameFiles(int projectsLength, int filesLength, IVsProject[] projects, int[] indices,
                               string[] oldNames, string[] newNames, VSRENAMEFILEFLAGS[] rgFlags)
 {
     try
     {
         for (int i = 0; i < projectsLength; ++i)
         {
             IVsProject            project     = projects[i];
             IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project);
             if (projectType != IceBuilderProjectType.None)
             {
                 int j = indices[i];
                 int k = i < (projectsLength - 1) ? indices[i + 1] : filesLength;
                 for (; j < k; ++j)
                 {
                     string oldPath = oldNames[i];
                     string newPath = newNames[j];
                     if (ProjectUtil.IsSliceFileName(oldPath) || ProjectUtil.IsSliceFileName(newPath))
                     {
                         ProjectUtil.SetupGenerated(project, projectType);
                         break;
                     }
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return(0);
 }
        //
        // Set Ice Home and force projects to re evaluate changes in the imported project
        //
        public static void SetIceHome(List <IVsProject> projects, string iceHome, string iceVersion, string iceIntVersion, string iceVersionMM)
        {
            foreach (IVsProject p in projects)
            {
                if (DTEUtil.IsIceBuilderEnabled(p) != IceBuilderProjectType.None)
                {
                    Microsoft.Build.Evaluation.Project project = LoadedProject(ProjectUtil.GetProjectFullPath(p), DTEUtil.IsCppProject(p), true);
                    ResolvedImport import = project.Imports.FirstOrDefault(i => i.ImportedProject.FullPath.EndsWith("IceBuilder.Common.props"));

                    if (import.ImportedProject != null)
                    {
                        ProjectPropertyGroupElement group = import.ImportedProject.PropertyGroups.FirstOrDefault(
                            g => g.Label.Equals("IceHome", StringComparison.CurrentCultureIgnoreCase));
                        if (group != null)
                        {
                            group.SetProperty(Package.IceHomeValue, iceHome);
                            group.SetProperty(Package.IceVersionValue, iceVersion);
                            group.SetProperty(Package.IceIntVersionValue, iceIntVersion);
                            group.SetProperty(Package.IceVersionMMValue, iceVersionMM);
                            project.ReevaluateIfNecessary();
                        }
                    }
                }
            }
        }
        private void BuildEvents_OnBuildBegin(EnvDTE.vsBuildScope scope, EnvDTE.vsBuildAction action)
        {
            try
            {
                if (action == EnvDTE.vsBuildAction.vsBuildActionBuild ||
                    action == EnvDTE.vsBuildAction.vsBuildActionRebuildAll)
                {
                    //
                    // Ensure this runs once for parallel builds.
                    //
                    if (Building)
                    {
                        return;
                    }
                    Building = true;
                }

                List <IVsProject> projects = new List <IVsProject>();
                if (scope.Equals(EnvDTE.vsBuildScope.vsBuildScopeSolution))
                {
                    projects = DTEUtil.GetProjects();
                }
                else
                {
                    IVsProject selected = DTEUtil.GetSelectedProject();
                    if (selected != null)
                    {
                        projects.Add(selected);
                        DTEUtil.GetSubProjects(selected, ref projects);
                    }
                }

                foreach (IVsProject project in projects)
                {
                    IceBuilderProjectType type = DTEUtil.IsIceBuilderEnabled(project);
                    if (type != IceBuilderProjectType.None)
                    {
                        ProjectUtil.SetupGenerated(project, type);
                    }
                }
            }
            catch (Exception ex)
            {
                Package.UnexpectedExceptionWarning(ex);
                throw;
            }
        }
        private void BuildEvents_OnBuildBegin(EnvDTE.vsBuildScope scope, EnvDTE.vsBuildAction action)
        {
            try
            {
                if (action == EnvDTE.vsBuildAction.vsBuildActionBuild ||
                    action == EnvDTE.vsBuildAction.vsBuildActionRebuildAll)
                {
                    //
                    // Ensure this runs once for parallel builds.
                    //
                    if (Building)
                    {
                        return;
                    }
                    Building = true;
                }

                List <EnvDTE.Project> projects = new List <EnvDTE.Project>();
                if (scope.Equals(EnvDTE.vsBuildScope.vsBuildScopeSolution))
                {
                    projects = DTEUtil.GetProjects(DTE2.Solution);
                }
                else
                {
                    EnvDTE.Project selected = DTEUtil.GetSelectedProject();
                    if (selected != null)
                    {
                        DTEUtil.GetProjects(selected, ref projects);
                    }
                }

                foreach (EnvDTE.Project project in projects)
                {
                    if (DTEUtil.IsIceBuilderEnabled(project))
                    {
                        FileTracker.Reap(project);
                        ProjectUtil.SetupGenerated(project);
                    }
                }
            }
            catch (Exception ex)
            {
                Package.UnexpectedExceptionWarning(ex);
                throw;
            }
        }
 public void BuildNextProject()
 {
     if (_buildProjects.Count == 0)
     {
         BuildContext(false);
     }
     else if (!Building && BuildingProject == null)
     {
         IVsProject p = _buildProjects.ElementAt(0);
         ProjectUtil.SaveProject(p);
         ProjectUtil.SetupGenerated(p, DTEUtil.IsIceBuilderEnabled(p));
         if (BuildProject(p))
         {
             _buildProjects.Remove(p);
         }
     }
 }
 public void InitializeProjects(List <EnvDTE.Project> projects)
 {
     ProjectConverter.TryUpgrade(projects);
     projects = DTEUtil.GetProjects(DTE.Solution);
     foreach (EnvDTE.Project project in projects)
     {
         List <EnvDTE.Project> build = new List <EnvDTE.Project>();
         if (DTEUtil.IsIceBuilderEnabled(project))
         {
             if (DTEUtil.IsCppProject(project))
             {
                 VCUtil.SetupSliceFilter(project);
             }
             FileTracker.Add(project);
             build.Add(project);
         }
         QueueProjectsForBuilding(build);
     }
 }
 public int OnBeforeCloseProject(IVsHierarchy pHierarchy, int fRemoved)
 {
     try
     {
         IVsProject project = pHierarchy as IVsProject;
         if (project != null)
         {
             if (DTEUtil.IsIceBuilderEnabled(project) != IceBuilderProjectType.None)
             {
                 Package.Instance.FileTracker.Remove(ProjectUtil.GetProjectFullPath(project));
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return(0);
 }
        public static void TryUpgrade(List <IVsProject> projects)
        {
            Dictionary <string, IVsProject> upgradeProjects = new Dictionary <string, IVsProject>();

            foreach (IVsProject project in projects)
            {
                IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project);
                if (projectType != IceBuilderProjectType.None)
                {
                    upgradeProjects.Add(project.GetDTEProject().UniqueName, project);
                }
            }

            if (upgradeProjects.Count > 0)
            {
                UpgradeDialog dialog = new UpgradeDialog();
                dialog.StartPosition = FormStartPosition.CenterParent;
                dialog.Projects      = upgradeProjects;
                dialog.ShowDialog();
            }
        }
 public int OnAfterSave(uint docCookie)
 {
     try
     {
         ProjectItem item = GetProjectItemFromDocumentCookie(docCookie);
         if (item != null)
         {
             if (item.ContainingProject != null && DTEUtil.IsIceBuilderEnabled(item.ContainingProject) &&
                 !String.IsNullOrEmpty(item.Name) && ProjectUtil.IsSliceFileName(item.Name))
             {
                 Package.Instance.QueueProjectsForBuilding(
                     new List <EnvDTE.Project>(new EnvDTE.Project[] { item.ContainingProject }));
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return(0);
 }
Ejemplo n.º 17
0
 public int OnAfterSave(uint docCookie)
 {
     try
     {
         if (Package.Instance.AutoBuilding)
         {
             IVsProject project = null;
             uint       item    = 0;
             string     path    = null;
             GetDocumentInfo(docCookie, ref project, ref item, ref path);
             if (DTEUtil.IsIceBuilderEnabled(project) != IceBuilderProjectType.None &&
                 ProjectUtil.IsSliceFileName(path))
             {
                 Package.Instance.QueueProjectsForBuilding(new List <IVsProject>(new IVsProject[] { project }));
             }
         }
     }
     catch (Exception ex)
     {
         Package.UnexpectedExceptionWarning(ex);
         throw;
     }
     return(0);
 }
Ejemplo n.º 18
0
 public static Dictionary <string, List <string> > GetGeneratedFiles(IVsProject project)
 {
     return(GetGeneratedFiles(project, DTEUtil.IsIceBuilderEnabled(project)));
 }
        public static void Upgrade(Dictionary <string, IVsProject> projects, UpgradeProgressCallback progressCallback)
        {
            Dispatcher dispatcher = Dispatcher.CurrentDispatcher;
            Thread     t          = new Thread(() =>
            {
                var NuGet   = Package.Instance.NuGet;
                var DTE     = Package.Instance.DTE;
                var builder = Package.Instance;
                int i       = 0;
                int total   = projects.Count;
                foreach (var entry in projects)
                {
                    var project    = entry.Value;
                    var dteProject = project.GetDTEProject();
                    var name       = entry.Key;
                    i++;
                    if (progressCallback.Canceled)
                    {
                        break;
                    }

                    dispatcher.Invoke(
                        new Action(() =>
                    {
                        progressCallback.ReportProgress(name, i);
                    }));

                    NuGet.Restore(dteProject);
                    if (!NuGet.IsPackageInstalled(dteProject, Package.NuGetBuilderPackageId))
                    {
                        DTE.StatusBar.Text = string.Format("Installing NuGet package {0} in project {1}",
                                                           Package.NuGetBuilderPackageId, name);
                        NuGet.InstallLatestPackage(dteProject, Package.NuGetBuilderPackageId);
                    }

                    IceBuilderProjectType projectType = DTEUtil.IsIceBuilderEnabled(project);
                    if (projectType != IceBuilderProjectType.None)
                    {
                        bool cpp           = projectType == IceBuilderProjectType.CppProjectType;
                        DTE.StatusBar.Text = string.Format("Upgrading project {0} Ice Builder settings", project.GetDTEProject().UniqueName);
                        var msproject      = project.GetMSBuildProject();
                        var fullPath       = ProjectUtil.GetProjectFullPath(project);
                        var assemblyDir    = ProjectUtil.GetEvaluatedProperty(project, "IceAssembliesDir");
                        if (projectType == IceBuilderProjectType.CsharpProjectType)
                        {
                            foreach (VSLangProj80.Reference3 r in dteProject.GetProjectRererences())
                            {
                                if (Package.AssemblyNames.Contains(r.Name))
                                {
                                    var item = msproject.AllEvaluatedItems.FirstOrDefault(referenceItem =>
                                                                                          referenceItem.ItemType.Equals("Reference") &&
                                                                                          referenceItem.EvaluatedInclude.Split(",".ToCharArray()).ElementAt(0).Equals(r.Name));
                                    if (item != null)
                                    {
                                        if (item.HasMetadata("HintPath"))
                                        {
                                            var hintPath = item.GetMetadata("HintPath").UnevaluatedValue;
                                            if (hintPath.Contains("$(IceAssembliesDir)"))
                                            {
                                                hintPath = hintPath.Replace("$(IceAssembliesDir)",
                                                                            FileUtil.RelativePath(Path.GetDirectoryName(r.ContainingProject.FullName), assemblyDir));
                                                //
                                                // If the HintPath points to the NuGet zeroc.ice.net package we upgrade it to not
                                                // use IceAssembliesDir otherwise we remove it
                                                if (hintPath.Contains("packages\\zeroc.ice.net"))
                                                {
                                                    item.SetMetadataValue("HintPath", hintPath);
                                                }
                                                else
                                                {
                                                    item.RemoveMetadata("HintPath");
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }

                        bool modified = MSBuildUtils.UpgradeProjectImports(msproject);
                        modified      = MSBuildUtils.UpgradeProjectProperties(msproject, cpp) || modified;
                        modified      = MSBuildUtils.RemoveIceBuilderFromProject(msproject, true) || modified;
                        modified      = MSBuildUtils.UpgradeProjectItems(msproject, cpp) || modified;

                        if (modified)
                        {
                            builder.SaveProject(project);
                        }
                    }
                }
                dispatcher.BeginInvoke(new Action(() => progressCallback.Finished()));
            });

            t.Start();
        }