コード例 #1
0
        public static ProcHolder CheckAndAddProcHolder(EnvDTE80.Process2 process)
        {
            ProcHolder returnProcessHolder = null;

            try
            {
                if (process == null)
                {
                    return(null);
                }
                if (process.Name.Contains("dotnet.exe"))
                {
                    return(null);
                }
                var startTime   = ExcludedProcessesManager.CheckAndReturnStartTime(process);
                var ProcessPath = process.Name;

                if (startTime == null)
                {
                    return(null);
                }

                if (alreadyCheckedProcesses.TryGetValue(process.ProcessID, out returnProcessHolder))
                {
                    if (returnProcessHolder.Process.Name == process.Name)
                    {
                        returnProcessHolder.StartTime   = startTime;
                        returnProcessHolder.ProcessPath = ProcessPath;
                        return(returnProcessHolder);
                    }
                }

                returnProcessHolder = new ProcHolder(process);
                if (returnProcessHolder.Process != null)
                {
                    alreadyCheckedProcesses.TryAdd(process.ProcessID, returnProcessHolder);
                    returnProcessHolder.StartTime   = startTime;
                    returnProcessHolder.ProcessPath = ProcessPath;
                    return(returnProcessHolder);
                }

                return(null);
            }
            catch (Exception ex)
            {
            }

            return(returnProcessHolder);
        }
コード例 #2
0
        void RefreshList()
        {
            listBoxProcess.SafeAction(l => l.Items.Clear());

            var solutionName = Utils.GetSolutionName(DTE).ToLower();

            var nominatedForSelection  = -1;
            var lengthOfLastNomination = 0;

            var index = 0;

            using (var iis = new IIS())
            {
                var processes = GetWorkerProcesses().OfType <EnvDTE80.Process2>().ToList();

                if (CheckUser(processes) == false)
                {
                    return;
                }

                if (flushTask != null)
                {
                    Task.WaitAll(flushTask);
                }

                var procHolders =
                    processes
                    .AsParallel()
                    .Select(proc => ProcHolder.CheckAndAddProcHolder(proc))
                    .Where(proc => proc != null)
                    .OrderByDescending(proc => proc.StartTime)
                    .ToList();

                flushTask = Task.Run(() => ProcHolder.ExcludedProcessesManager.Flush());

                foreach (ProcHolder holder in procHolders)
                {
                    if ((checkBoxExcludeMSharp.Checked && holder.AppPool != null && !holder.AppPool.Contains("M#")) || (!checkBoxExcludeMSharp.Checked))
                    {
                        listBoxProcess.SafeAction(l => l.Items.Add(holder));
                    }

                    if (solutionName.HasValue())
                    {
                        var physicalPath = iis.GetPhysicalPath(holder.AppPool);
                        if (physicalPath != null && physicalPath.ToLower().Contains(solutionName))
                        {
                            if (nominatedForSelection == -1)
                            {
                                nominatedForSelection  = index;
                                lengthOfLastNomination = holder.AppPool.Length;
                            }
                            else if (holder.AppPool.Length < lengthOfLastNomination)
                            {
                                nominatedForSelection  = index;
                                lengthOfLastNomination = holder.AppPool.Length;
                            }
                        }
                    }

                    index++;
                }
            }

            var count = listBoxProcess.SafeGet(() => listBoxProcess.Items.Count);

            if (count == 0)
            {
                btnAttachToAll.SafeAction(b => b.Enabled = false);
            }

            this.SafeAction(f => f.ActiveControl = listBoxProcess);
            if (nominatedForSelection <= count - 1)
            {
                listBoxProcess.SafeAction(l => l.SelectedIndex = nominatedForSelection);
            }

            DTE.StatusBar.Text = "Ready.";
            lblStatus.SafeAction(statusBar, s => s.Text = "");
        }