Ejemplo n.º 1
0
        private void CompileAllCommandCallback(object sender, EventArgs args)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            Interlocked.Exchange(ref package.IsCompiling, 1);

            var projs    = new List <Project>();
            var selitems = package.dte2.ToolWindows.SolutionExplorer.UIHierarchyItems;

            if (selitems != null)
            {
                foreach (UIHierarchyItem uiitem in selitems)
                {
                    if (uiitem != null)
                    {
                        var proj = uiitem.Object as Project;
                        if (proj != null)
                        {
                            projs.Add(proj);
                        }
                    }
                }
            }

            UPPCompiler.RaiseReported(null, new CompilerReportedEventArgs(null));

            package.JoinableTaskFactory.RunAsyncAsVsTask(VsTaskRunContext.UIThreadBackgroundPriority,
                                                         async cancellationToken =>
            {
                await package.JoinableTaskFactory.SwitchToMainThreadAsync();

                IVsStatusbar statusBar = (IVsStatusbar)package.GetServiceAsync(typeof(SVsStatusbar));

                object icon = (short)Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Build;

                statusBar?.Animation(1, ref icon);

                var tasks = package.Compile(projs);

                await TaskScheduler.Default;

                await Task.WhenAll(tasks.Select(vtask => vtask.WaitForFinishedAsync()));

                await package.JoinableTaskFactory.SwitchToMainThreadAsync();

                statusBar?.Animation(0, ref icon);

                Interlocked.Exchange(ref package.IsCompiling, 0);

                return(VSConstants.S_OK);
            });
        }
Ejemplo n.º 2
0
 private void UPPCompiler_Reported(object sender, CompilerReportedEventArgs e)
 {
     if (e.Clear)
     {
         _output.Clear();
     }
     else
     {
         if (!e.IsZombie)
         {
             if (e.Mode == UWorkerReports.Normal)
             {
                 UPPCompiler upj = e.Compiler;
                 if (upj != null)
                 {
                     AddMessage(string.Format("{0}> {1}", upj.Id, e.Message));
                 }
             }
         }
     }
 }
Ejemplo n.º 3
0
        public System.Collections.Generic.List <UPPCompiler> Compile(System.Collections.Generic.List <Project> projects)
        {
            ThreadHelper.ThrowIfNotOnUIThread();
            var vtasks = new System.Collections.Generic.List <UPPCompiler>();

            if (UPPCompilerExtensions.IsUSDKSupported())
            {
                var tasks = new System.Collections.Generic.List <UPPCompiler>();

                bool   failure       = false;
                string failure_title = string.Empty;
                string failure_msg   = string.Empty;

                foreach (var project in projects)
                {
                    string ProjectConfig = project.ConfigurationManager.ActiveConfiguration.ConfigurationName;
                    string Platform      = project.ConfigurationManager.ActiveConfiguration.PlatformName;

                    string   configneedmessage = string.Empty;
                    SDKError uerr = project.DetectUSDK(ProjectConfig, Platform, out configneedmessage);
                    if (uerr == SDKError.ConfigNeed)
                    {
                        failure_title = "未设置指定配置";
                        failure_msg   = configneedmessage;
                        failure       = true;
                    }

                    if (uerr == SDKError.Success)
                    {
                        using (var serviceProvider = new ServiceProvider(dte2.DTE as Microsoft.VisualStudio.OLE.Interop.IServiceProvider))
                        {
                            Guid guid = project.GetProjectGuid(serviceProvider);

                            string      clmsg = string.Empty;
                            UPPCompiler uppcl = UPPCompiler.Create(0, dte2.GetVCProject(guid), ProjectConfig, Platform, out clmsg);

                            if (uppcl != null)
                            {
                                tasks.Add(uppcl);
                            }
                            else
                            {
                                failure_title = "无效项设置";
                                failure_msg   = clmsg;
                                failure       = true;
                                foreach (var task in tasks)
                                {
                                    task.Dispose();
                                }
                                tasks.Clear();
                            }
                        }
                    }
                }

                if (!failure)
                {
                    if (tasks.Count > 0)
                    {
                        foreach (var task in tasks)
                        {
                            if (task.Compile())
                            {
                                vtasks.Add(task);
                            }
                        }
                    }
                }
            }
            return(vtasks);
        }
Ejemplo n.º 4
0
        private void CompileCommandCallback(object sender, EventArgs args)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            //var mainWindow = System.Windows.Application.Current.MainWindow;
            //var contentControl = mainWindow?.Template?.FindName("PART_SccStatusBarHost", mainWindow) as System.Windows.Controls.ContentControl;

            //var statusbar = contentControl?.Content as System.Windows.Controls.Primitives.StatusBar;

            //statusbar.Items.Add(new System.Windows.Controls.Button() { Content = "U++test" });

            Interlocked.Exchange(ref package.IsCompiling, 1);

            if (package.dte2.Solution.SolutionBuild.BuildState != vsBuildState.vsBuildStateInProgress)
            {
                var projs    = new List <Project>();
                var selitems = package.dte2.ToolWindows.SolutionExplorer.SelectedItems as Array;
                if (selitems != null)
                {
                    foreach (var selitem in selitems)
                    {
                        var uiitem = selitem as UIHierarchyItem;
                        if (uiitem != null)
                        {
                            var proj = uiitem.Object as Project;
                            if (proj != null)
                            {
                                projs.Add(proj);
                            }
                        }
                    }
                }

                UPPCompiler.RaiseReported(null, new CompilerReportedEventArgs(null));

                package.JoinableTaskFactory.RunAsyncAsVsTask(VsTaskRunContext.UIThreadBackgroundPriority,
                                                             async cancellationToken =>
                {
                    await package.JoinableTaskFactory.SwitchToMainThreadAsync();

                    IVsMonitorSelection monitorSelection = await package.GetServiceAsync(typeof(IVsMonitorSelection)) as IVsMonitorSelection;
                    Assumes.Present(monitorSelection);
                    var sol_build_guid    = VSConstants.UICONTEXT_SolutionBuilding;
                    uint sol_build_cookie = 0;
                    monitorSelection.GetCmdUIContextCookie(ref sol_build_guid, out sol_build_cookie);

                    int uiactive = -1;
                    monitorSelection.IsCmdUIContextActive(sol_build_cookie, out uiactive);
                    if (uiactive == 0)
                    {
                        monitorSelection.SetCmdUIContext(sol_build_cookie, 1);
                    }


                    IVsStatusbar statusBar = await package.GetServiceAsync(typeof(SVsStatusbar)) as IVsStatusbar;

                    object icon = (short)Microsoft.VisualStudio.Shell.Interop.Constants.SBAI_Build;

                    statusBar?.SetText("开始编译...");
                    statusBar?.Animation(1, ref icon);

                    var tasks = package.Compile(projs);

                    statusBar?.SetText("编译...");

                    await TaskScheduler.Default;

                    await Task.WhenAll(tasks.Select(vtask => vtask.WaitForFinishedAsync()));

                    await package.JoinableTaskFactory.SwitchToMainThreadAsync();

                    statusBar?.SetText("链接源文件...");
                    tasks.ForEach(task => task.ReLink());

                    statusBar?.Animation(0, ref icon);

                    Interlocked.Exchange(ref package.IsCompiling, 0);

                    uiactive = -1;
                    monitorSelection.IsCmdUIContextActive(sol_build_cookie, out uiactive);
                    if (uiactive == 1)
                    {
                        monitorSelection.SetCmdUIContext(sol_build_cookie, 0);
                    }

                    statusBar?.SetText("已完成");
                    statusBar?.Clear();

                    return(VSConstants.S_OK);
                });
            }
        }