Пример #1
0
        public void ReplaceLog(ILog oldLog, ILogNode newNode)
        {
            lock (this.logs)
            {
                ILogNode oldNode = null;

                // Find the ILogNode for the old log.
                foreach (ILogNode logNode in this.logs)
                {
                    if (ReferenceEquals(logNode.Log, oldLog))
                    {
                        oldNode = logNode;
                        break;
                    }
                }

                if (oldNode != null)
                {
                    // Change all nodes matching the old ILogNode to use the new node.
                    for (LinkedListNode <ILogNode> node = this.logs.First; node != null; node = node.Next)
                    {
                        if (node.Value.Equals(oldNode))
                        {
                            node.Value = newNode;
                        }
                    }
                }
                this.BakeImpl();
            }
        }
Пример #2
0
        public void LogExceptionFile(Exception ex)
        {
            string   local = GameManager.GetAppDataPath();
            DateTime now   = DateTime.Now;
            string   file  = string.Format("{0}{1}{2}_{3}{4}{5}", now.Day.ToString("00"), now.Month.ToString("00"), now.Year.ToString("0000"), now.Hour.ToString("00"), now.Minute.ToString("00"), now.Second.ToString("00")) + ".log";
            string   path  = Path.Combine(local, file);

            using (Stream stream = File.OpenWrite(path)) {
                using (StreamWriter writer = new StreamWriter(stream)) {
                    writer.WriteLine("[Header]");
                    writer.WriteLine(now.ToLongDateString());
                    writer.WriteLine(now.ToLongTimeString());
                    writer.WriteLine("Nucleus Coop Alpha v" + Globals.Version);
                    writer.WriteLine("[PC Specs]");

                    writer.WriteLine("[Message]");
                    writer.WriteLine(ex.Message);
                    writer.WriteLine("[Stacktrace]");
                    writer.WriteLine(ex.StackTrace);

                    for (int i = 0; i < logCallbacks.Count; i++)
                    {
                        ILogNode node = logCallbacks[i];
                        try {
                            node.OnFailureLog(writer);
                        } catch {
                            writer.WriteLine("LogNode failed to log: " + node.ToString());
                        }
                    }
                }
            }

            MessageBox.Show("Application crash. Log generated at Data/" + file);
            Application.Exit();
        }
Пример #3
0
 public void AddLog(ILogNode log)
 {
     lock (this.logs)
     {
         this.logs.AddLast(log);
         this.BakeImpl();
     }
 }
Пример #4
0
        public override bool Equals(ILogNode other)
        {
            // ARSE. Replacing a root should only be possible with another root.
            // As usual, inheritance was the wrong way to go.
            // Replacing a normal with a normal, fine.
            // Replacing a root with a normal, no - reject.
            // Replacing a normal with a root, hmmmm, for now let's say nope.
            bool equal = !(other is LogNodeNameHierarchyRoot);

            if (equal)
            {
                equal = base.Equals(other);
            }

            return(equal);
        }
Пример #5
0
        public override bool IsParent(ILogNode potentialChild)
        {
            bool isParent = false;

            if (!ReferenceEquals(this, potentialChild)) // If not same object
            {
                string childName = potentialChild.Name;

                if (!string.IsNullOrEmpty(childName)) // If child has a name
                {
                    isParent = this.CheckForChild(childName);
                } // Ends if child has a name
            }     // Ends if not same object

            return(isParent);
        }
Пример #6
0
        public override bool Equals(ILogNode other)
        {
            // ARSE. Replacing a root should only be possible with another root.
            // As usual, inheritance was the wrong way to go.
            // Replacing a normal with a normal, fine.
            // Replacing a root with a normal, no - reject.
            // Replacing a normal with a root, hmmmm, for now let's say nope.
            // i.e. normals and root's don't interact.
            // Sadly, this is going to be busted working the other way around without implementing Equals in both classes. C'est la vie.
            bool equal = other is LogNodeNameHierarchyRoot;

            if (equal)
            {
                equal = Equals(this, other);
            }

            return(equal);
        }
Пример #7
0
 /**
 * Takes the "next" LogNode as a parameter, to simplify chaining.
 */
 public MessageOnlyLogFilter(ILogNode next)
 {
     NextNode = next;
 }
Пример #8
0
        public void LogExceptionFile(Exception ex)
        {
            Log("ERROR - " + ex.Message + " | Stacktrace: " + ex.StackTrace);

            string   local = GetAppDataPath();
            DateTime now   = DateTime.Now;
            string   file  = string.Format("{0}{1}{2}_{3}{4}{5}", now.Day.ToString("00"), now.Month.ToString("00"), now.Year.ToString("0000"), now.Hour.ToString("00"), now.Minute.ToString("00"), now.Second.ToString("00")) + ".log";

            MessageBox.Show($"Nucleus has crashed unexpectedly. An attempt to clean up will be made.\n\n[Type]\n{ex.GetType().Name}\n\n[Message]\n{ex.Message}\n\n[Stacktrace]\n{ex.StackTrace}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

            Log("Attempting shut-down procedures in order to clean-up");

            string[] regFiles = Directory.GetFiles(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "utils\\backup"), "*.reg", SearchOption.AllDirectories);
            if (regFiles.Length > 0)
            {
                LogManager.Log("Restoring backed up registry files - method 2");
                foreach (string regFilePath in regFiles)
                {
                    System.Diagnostics.Process proc = new System.Diagnostics.Process();

                    try
                    {
                        proc.StartInfo.FileName        = "reg.exe";
                        proc.StartInfo.WindowStyle     = System.Diagnostics.ProcessWindowStyle.Hidden;
                        proc.StartInfo.CreateNoWindow  = true;
                        proc.StartInfo.UseShellExecute = false;

                        string command = "import \"" + regFilePath + "\"";
                        proc.StartInfo.Arguments = command;
                        proc.Start();

                        proc.WaitForExit();
                        LogManager.Log($"Imported {Path.GetFileName(regFilePath)}");
                    }
                    catch (Exception)
                    {
                        proc.Dispose();
                    }

                    File.Delete(regFilePath);
                }
            }

            GenericGameHandler.Instance.End(false);
            while (!GenericGameHandler.Instance.HasEnded)
            {
                Thread.Sleep(1000);
            }

            Thread.Sleep(1000);

            string path = Path.Combine(local, file);

            using (Stream stream = File.OpenWrite(path))
            {
                using (StreamWriter writer = new StreamWriter(stream))
                {
                    writer.WriteLine("[Header]");
                    writer.WriteLine(now.ToLongDateString());
                    writer.WriteLine(now.ToLongTimeString());
                    writer.WriteLine("Nucleus Coop Alpha v" + Globals.Version);
                    writer.WriteLine("[Message]");
                    writer.WriteLine(ex.Message);
                    writer.WriteLine("[Stacktrace]");
                    writer.WriteLine(ex.StackTrace);

                    for (int i = 0; i < logCallbacks.Count; i++)
                    {
                        ILogNode node = logCallbacks[i];
                        try
                        {
                            node.Log(writer);
                        }
                        catch
                        {
                            writer.WriteLine("LogNode failed to log: " + node.ToString());
                        }
                    }
                }
            }

            Windows.User32Util.ShowTaskBar();

            Log("High-level error log generated at content/" + file);

            Application.Exit();
        }
 /**
  * Takes the "next" LogNode as a parameter, to simplify chaining.
  */
 public MessageOnlyLogFilter(ILogNode next)
 {
     mNext = next;
 }
		/**
     	* Takes the "next" LogNode as a parameter, to simplify chaining.
     	*/
		public MessageOnlyLogFilter (ILogNode next)
		{
			mNext = next;
		}
Пример #11
0
 public static void SetLogNode(ILogNode node)
 {
     mLogNode = node;
 }
Пример #12
0
 protected LogTraceSource(ILogNode logNode, IEnumerable <System.Diagnostics.TraceSource> tracesources)
     : base(logNode)
 {
     this.tracesources = tracesources;
 }
Пример #13
0
 protected LogTraceSource(ILogNode logNode, params System.Diagnostics.TraceSource[] tracesources)
     : base(logNode)
 {
     this.tracesources = tracesources;
 }
Пример #14
0
 internal static ILog GetLog(ILogNode logNode)
 {
     return(logNode.Log);
 }
Пример #15
0
 // It's up to the sub-classes to call Construct with thes constructors...
 protected LogBase(ILogNode logNode)
 {
     this.logNode = logNode;
 }
Пример #16
0
 public void SetNext(ILogNode node)
 {
     mNext = node;
 }
Пример #17
0
 public static void RegisterForLogCallback(ILogNode node)
 {
     Instance.logCallbacks.Add(node);
 }
Пример #18
0
 abstract public bool IsParent(ILogNode potentialChild);
Пример #19
0
 private bool NodeIsParent(ILogNode logNode)
 {
     return(logNode.IsParent(this));
 }
Пример #20
0
 public override bool IsParent(ILogNode potentialChild)
 {
     return(false);
 }
Пример #21
0
 public virtual bool Equals(ILogNode other)
 {
     return(Equals(this, other));
 }
Пример #22
0
 protected internal static bool Equals(ILogNode self, ILogNode other)
 {
     return(self.Name.Equals(other.Name));
 }
Пример #23
0
 /**
  * Takes the "next" LogNode as a parameter, to simplify chaining.
  */
 public MessageOnlyLogFilter(ILogNode next)
 {
     NextNode = next;
 }
Пример #24
0
 protected static void Construct(LogBase log, ILogNode logNode)
 {
     log.logNode = logNode;
     logNode.Construct();
 }
Пример #25
0
 public static void UnregisterForLogCallback(ILogNode node)
 {
     Instance.logCallbacks.Remove(node);
 }
Пример #26
0
 protected static void Replace(ILog logOld, LogBase log, ILogNode logNode)
 {
     log.logNode = logNode;
     logNode.Replace(logOld);
 }