OSDN Git Service

RAD-391: Added ability to report status of last application run to the grid login...
authorLatif Khalifa <latifer@streamgrid.net>
Sat, 16 Feb 2013 04:42:48 +0000 (05:42 +0100)
committerLatif Khalifa <latifer@streamgrid.net>
Sat, 16 Feb 2013 04:42:48 +0000 (05:42 +0100)
Radegast/Core/RadegastInstance.cs
Radegast/GUI/Consoles/LoginConsole.cs
Radegast/GUI/Dialogs/MainForm.cs
Radegast/Netcom/LoginOptions.cs
Radegast/Netcom/RadegastNetcom/SLNetCom.cs

index 00d65e7..1bdb2cf 100644 (file)
@@ -216,6 +216,14 @@ namespace Radegast
 
         public CurrentOutfitFolder COF;
 
+        private string CrashMarkerFileName
+        {
+            get
+            {
+                return Path.Combine(UserDir, "crash_marker");
+            }
+        }
+
         #region Events
 
         #region ClientChanged event
@@ -421,6 +429,9 @@ namespace Radegast
 
         public void Reconnect()
         {
+            // We are logging in without exiting the client
+            // Mark last run as successful
+            MarkEndExecution();
             TabConsole.DisplayNotificationInChat("Attempting to reconnect...", ChatBufferTextStyle.StatusDarkBlue);
             Logger.Log("Attemting to reconnect", Helpers.LogLevel.Info, client);
             GridClient oldClient = client;
@@ -433,6 +444,8 @@ namespace Radegast
 
         public void CleanUp()
         {
+            MarkEndExecution();
+
             if (COF != null)
             {
                 COF.Dispose();
@@ -658,6 +671,41 @@ namespace Radegast
                 Helpers.LogLevel.Error,
                 client);
         }
+
+        public LastExecStatus GetLastExecStatus()
+        {
+            if (File.Exists(CrashMarkerFileName))
+            {
+                Logger.Log(string.Format("Found crash marker file {0}, reporting unclean shutdown to the grid", CrashMarkerFileName), Helpers.LogLevel.Warning);
+                return LastExecStatus.OtherCrash;
+            }
+            else
+            {
+                Logger.Log(string.Format("No crash marker file {0} found, reporting clean shutdown to the grid", CrashMarkerFileName), Helpers.LogLevel.Info);
+                return LastExecStatus.Normal;
+            }
+        }
+
+        public void MarkStartExecution()
+        {
+            Logger.Log(string.Format("Marking start of execution run, creating file: {0}", CrashMarkerFileName), Helpers.LogLevel.Info);
+            try
+            {
+                File.Create(CrashMarkerFileName).Dispose();
+            }
+            catch { }
+        }
+
+        public void MarkEndExecution()
+        {
+            Logger.Log(string.Format("Marking end of execution run, deleting file: {0}", CrashMarkerFileName), Helpers.LogLevel.Info);
+            try
+            {
+                File.Delete(CrashMarkerFileName);
+            }
+            catch { }
+        }
+
     }
 
     #region Event classes
index 18067b8..0645845 100644 (file)
@@ -435,6 +435,7 @@ namespace Radegast
             netcom.LoginOptions.Channel = Properties.Resources.ProgramName; // Channel
             netcom.LoginOptions.Version = Properties.Resources.RadegastTitle; // Version
             netcom.AgreeToTos = cbTOS.Checked;
+            netcom.LoginOptions.LastExecEvent = instance.GetLastExecStatus();
 
             switch (cbxLocation.SelectedIndex)
             {
@@ -473,6 +474,7 @@ namespace Radegast
                 instance.Client.Settings.MULTIPLE_SIMS = true;
             }
 
+            instance.MarkStartExecution();
             netcom.Login();
             SaveConfig();
         }
index fbed1d3..7c564ac 100644 (file)
@@ -1629,6 +1629,9 @@ namespace Radegast
 
         private void loginToolStripMenuItem_Click(object sender, EventArgs e)
         {
+            // We are logging in without exiting the client
+            // Mark last run as successful
+            instance.MarkEndExecution();
             TabConsole.InitializeMainTab();
             TabConsole.Tabs["login"].Select();
         }
index 6cb7ab3..1332a1c 100644 (file)
@@ -29,6 +29,8 @@
 // $Id$
 //
 
+using OpenMetaverse;
+
 namespace Radegast.Netcom
 {
     public class LoginOptions
@@ -44,6 +46,8 @@ namespace Radegast.Netcom
 
         private Grid grid;
         private string gridCustomLoginUri = string.Empty;
+        private LastExecStatus lastExecEvent = LastExecStatus.Normal;
+
 
         public LoginOptions()
         {
@@ -119,5 +123,11 @@ namespace Radegast.Netcom
             get { return gridCustomLoginUri; }
             set { gridCustomLoginUri = value; }
         }
+
+        public LastExecStatus LastExecEvent
+        {
+            get { return lastExecEvent; }
+            set { lastExecEvent = value; }
+        }
     }
 }
index 19ef5f3..cb564ae 100644 (file)
@@ -294,6 +294,7 @@ namespace Radegast.Netcom
             loginParams.Start = startLocation;
             loginParams.AgreeToTos = AgreeToTos;
             loginParams.URI = grid.LoginURI;
+            loginParams.LastExecEvent = loginOptions.LastExecEvent;
             client.Network.BeginLogin(loginParams);
         }