示例#1
0
 /// <summary>
 /// Checks if given debug data-source is already attached.
 /// </summary>
 public static bool ContainsSource(IDbgSource s)
 {
     lock (syncSources)
     {
         return(Find(s) != null);
     }
 }
示例#2
0
 private void StopGivenSource(IDbgSource s)
 {
     try
     {
         DebugViewMonitor.RemoveSource(s);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, DialogTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
示例#3
0
 /// <summary>
 /// Removes given debug messages source.
 /// </summary>
 public static void RemoveSource(IDbgSource s)
 {
     lock (syncSources)
     {
         if (s != null && dataSources.Contains(s))
         {
             s.Close();
             s.DataReceived -= SourceDataReceived;
             dataSources.Remove(s);
             cachedDataSources = null;
         }
     }
 }
示例#4
0
        /// <summary>
        /// Process received message.
        /// </summary>
        static void SourceDataReceived(IDbgSource source, uint pid, string message)
        {
            lock (syncItems)
            {
                DateTime creation = DateTime.Now;
                string[] msgs;

                if (string.IsNullOrEmpty(message))
                {
                    msgs = new string[] { string.Empty };
                }
                else
                {
                    message = message.Replace("\t", TabReplace);
                    msgs    = message.Replace("\r\n", "\r").Replace("\n", "\r").Split('\r');
                }

                // check if this element has already the name:
                if (pid == 0 && (!string.IsNullOrEmpty(source.Name) || !string.IsNullOrEmpty(source.Module)))
                {
                    foreach (string m in msgs)
                    {
                        storedItems.Enqueue(new DebugViewData(0, source.Name, source.Module, creation, m.TrimEnd(null)));
                    }
                }
                else
                {
                    ProcessData dbgProcess = ProcessDataCache.GetByID(pid);
                    if (dbgProcess != null)
                    {
                        foreach (string m in msgs)
                        {
                            storedItems.Enqueue(new DebugViewData(pid, dbgProcess.Name,
                                                                  dbgProcess.MainModuleFileName, creation,
                                                                  m.TrimEnd(null)));
                        }
                    }
                }

                // avoid data flooding, by adding 1-sec delays
                // when sending to the receiver:
                if (!isRefreshing)
                {
                    isRefreshing = true;
                    refreshTimer.Change(1000, Timeout.Infinite);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Adds reference to new source of debug messages.
        /// </summary>
        public static bool AddSource(IDbgSource s, bool overrideExisting, bool autoStart)
        {
            lock (syncSources)
            {
                IDbgSource existing;
                bool       canAdd    = false;
                bool       overriden = false;

                // check if there is already an item with the same name:
                if (s != null)
                {
                    existing = Find(s);

                    // if there is one with the same name:
                    if (existing != null)
                    {
                        // override?
                        if (overrideExisting)
                        {
                            RemoveSource(existing);
                            canAdd    = true;
                            overriden = true;
                        }
                    }
                    else
                    {
                        canAdd = true;
                    }

                    // add new data-source element if possible:
                    if (canAdd)
                    {
                        s.DataReceived -= SourceDataReceived;
                        s.DataReceived += SourceDataReceived;
                        dataSources.Add(s);
                        cachedDataSources = null;

                        if (isStarted && autoStart)
                        {
                            s.Start();
                        }
                    }
                }

                return(overriden);
            }
        }
示例#6
0
        /// <summary>
        /// Finds debug source with the same name.
        /// </summary>
        private static IDbgSource Find(IDbgSource s)
        {
            if (string.IsNullOrEmpty(s.Name))
            {
                return(null);
            }

            foreach (IDbgSource x in dataSources)
            {
                if (string.Compare(s.Name, x.Name, true) == 0)
                {
                    return(x);
                }
            }

            return(null);
        }