reading wpi logs fixed

This commit is contained in:
ruslan 2012-08-14 16:29:26 +03:00
parent ce1842eef9
commit b419cfc72d
2 changed files with 38 additions and 19 deletions

View file

@ -740,12 +740,13 @@ namespace WebsitePanel.Server
Log.WriteError("WpiGetLogFileDirectory", ex); Log.WriteError("WpiGetLogFileDirectory", ex);
throw; //throw;
return string.Empty;
} }
} }
[WebMethod] [WebMethod]
public SettingPair[] WpiGetLogsInDirectory(string Path) public SettingPair[] WpiGetLogsInDirectory(string path)
{ {
try try
{ {
@ -753,7 +754,7 @@ namespace WebsitePanel.Server
ArrayList result = new ArrayList(); ArrayList result = new ArrayList();
string[] filePaths = Directory.GetFiles(Path); string[] filePaths = Directory.GetFiles(path);
foreach (string filePath in filePaths) foreach (string filePath in filePaths)
{ {
using (StreamReader streamReader = new StreamReader(filePath)) using (StreamReader streamReader = new StreamReader(filePath))
@ -773,7 +774,8 @@ namespace WebsitePanel.Server
Log.WriteError("WpiGetLogFileDirectory", ex); Log.WriteError("WpiGetLogFileDirectory", ex);
throw; //throw;
return null;
} }
} }

View file

@ -327,7 +327,10 @@ namespace WebsitePanel.Portal
if (string.IsNullOrEmpty(wpiLogsDir)) if (string.IsNullOrEmpty(wpiLogsDir))
{ {
wpiLogsDir = ES.Services.Servers.WpiGetLogFileDirectory(PanelRequest.ServerId); wpiLogsDir = ES.Services.Servers.WpiGetLogFileDirectory(PanelRequest.ServerId);
ViewState[_wpiLogsDirViewStateKey] = wpiLogsDir; if (!string.IsNullOrEmpty(wpiLogsDir))
{
ViewState[_wpiLogsDirViewStateKey] = wpiLogsDir;
}
} }
} }
catch catch
@ -532,37 +535,51 @@ namespace WebsitePanel.Portal
protected void ShowLogsButton_OnClick(object sender, EventArgs e) protected void ShowLogsButton_OnClick(object sender, EventArgs e)
{ {
//show logs //show logs
string wpiLogsDir = null;
object[] logsEntrys = null;
try try
{ {
string wpiLogsDir = ViewState[_wpiLogsDirViewStateKey] as string; wpiLogsDir = ViewState[_wpiLogsDirViewStateKey] as string;
if (!string.IsNullOrEmpty(wpiLogsDir)) if (!string.IsNullOrEmpty(wpiLogsDir))
{ {
//Get logs !!! //Get logs !!!
object[] logsEntrys = ES.Services.Servers.WpiGetLogsInDirectory(PanelRequest.ServerId, wpiLogsDir); logsEntrys = ES.Services.Servers.WpiGetLogsInDirectory(PanelRequest.ServerId, wpiLogsDir);
WpiLogsPanel.Visible = true; if (null == logsEntrys)
StringBuilder sb = new StringBuilder();
foreach (SettingPair entry in logsEntrys)
{ {
string fileName = (string)entry.Name; WpiLogsPanel.Visible = true;
string fileContent = (string)entry.Value; string msg = string.Format("Could not get logs files. Log files folder:\n{0}", wpiLogsDir);
sb.AppendLine().AppendFormat("<h3>{0}</h3>", fileName).AppendLine().Append(fileContent).AppendLine(); WpiLogsPre.InnerText = msg;
} }
else
{
WpiLogsPanel.Visible = true;
WpiLogsPre.InnerHtml = sb.ToString(); StringBuilder sb = new StringBuilder();
ShowLogsButton.Visible = false; foreach (SettingPair entry in logsEntrys)
ProgressTimer.Enabled = false; {
string fileName = (string) entry.Name;
string fileContent = (string) entry.Value;
sb.AppendLine().AppendFormat("<h3>{0}</h3>", fileName).AppendLine().Append(fileContent).
AppendLine();
}
WpiLogsPre.InnerHtml = sb.ToString();
ShowLogsButton.Visible = false;
ProgressTimer.Enabled = false;
}
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
WpiLogsPanel.Visible = true; WpiLogsPanel.Visible = true;
WpiLogsPre.InnerText = ex.ToString(); string msg = string.Format("wpiLogsDir: {0}\nlogsEntrys is null: {1}\n{2}", wpiLogsDir, logsEntrys == null, ex);
WpiLogsPre.InnerText = msg;
} }
} }
} }