Commit 43b5f7d3 by Joona Romppanen

Capture 404 in WebEx handler and make logfile path configurable

1 parent e0d96526
...@@ -31,6 +31,8 @@ ...@@ -31,6 +31,8 @@
<PlatformTarget>x86</PlatformTarget> <PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
......
...@@ -160,6 +160,12 @@ namespace MoyaAdminLib ...@@ -160,6 +160,12 @@ namespace MoyaAdminLib
} }
catch (WebException e) catch (WebException e)
{ {
var errorResponse = e.Response as HttpWebResponse;
if (errorResponse != null && errorResponse.StatusCode == HttpStatusCode.NotFound)
{
throw new MoyaApiException("Resource not found", HttpStatusCode.NotFound, e);
}
if (e.Status == WebExceptionStatus.ConnectFailure) if (e.Status == WebExceptionStatus.ConnectFailure)
{ {
throw; throw;
......
...@@ -16,7 +16,7 @@ namespace MoyaSignup ...@@ -16,7 +16,7 @@ namespace MoyaSignup
static Logger() static Logger()
{ {
LogWriter = File.AppendText("log.txt"); LogWriter = File.AppendText(Properties.Settings.Default.LogFile);
} }
public static void Log(LogLevel level, string message) public static void Log(LogLevel level, string message)
...@@ -24,7 +24,7 @@ namespace MoyaSignup ...@@ -24,7 +24,7 @@ namespace MoyaSignup
LogWriter.Write("[{0}] [{1}] {2}", LogWriter.Write("[{0}] [{1}] {2}",
string.Format("{0} {1}", DateTime.UtcNow.ToLongTimeString(), DateTime.UtcNow.ToLongDateString()), string.Format("{0} {1}", DateTime.UtcNow.ToLongTimeString(), DateTime.UtcNow.ToLongDateString()),
level, level,
message + '\n' message + "\r\n"
); );
LogWriter.Flush(); LogWriter.Flush();
} }
...@@ -35,6 +35,6 @@ namespace MoyaSignup ...@@ -35,6 +35,6 @@ namespace MoyaSignup
public static void Error(string message) => Log(LogLevel.Error, message); public static void Error(string message) => Log(LogLevel.Error, message);
public static void Error(string message, Exception ex) => Log(LogLevel.Error, message + ":\n" + ex); public static void Error(string message, Exception ex) => Log(LogLevel.Error, message + ":\r\n" + ex);
} }
} }
\ No newline at end of file
...@@ -12,7 +12,7 @@ namespace MoyaSignup.Properties { ...@@ -12,7 +12,7 @@ namespace MoyaSignup.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.1.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
...@@ -130,5 +130,17 @@ namespace MoyaSignup.Properties { ...@@ -130,5 +130,17 @@ namespace MoyaSignup.Properties {
this["ApiURL"] = value; this["ApiURL"] = value;
} }
} }
[global::System.Configuration.UserScopedSettingAttribute()]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Configuration.DefaultSettingValueAttribute("log.txt")]
public string LogFile {
get {
return ((string)(this["LogFile"]));
}
set {
this["LogFile"] = value;
}
}
} }
} }
...@@ -29,5 +29,8 @@ ...@@ -29,5 +29,8 @@
<Setting Name="ApiURL" Type="System.String" Scope="User"> <Setting Name="ApiURL" Type="System.String" Scope="User">
<Value Profile="(Default)">http://myapi.moya.endpoint/MoyaWeb</Value> <Value Profile="(Default)">http://myapi.moya.endpoint/MoyaWeb</Value>
</Setting> </Setting>
<Setting Name="LogFile" Type="System.String" Scope="User">
<Value Profile="(Default)">log.txt</Value>
</Setting>
</Settings> </Settings>
</SettingsFile> </SettingsFile>
\ No newline at end of file
...@@ -96,7 +96,6 @@ namespace MoyaSignup ...@@ -96,7 +96,6 @@ namespace MoyaSignup
var client = new RestClient(); var client = new RestClient();
try try
{ {
throw new MoyaApiException("test", HttpStatusCode.Ambiguous, new WebException());
var json = client.MakeRequest("user", "email=" + txtEmail.Text); var json = client.MakeRequest("user", "email=" + txtEmail.Text);
var ser = new JavaScriptSerializer(); var ser = new JavaScriptSerializer();
var euser = ser.Deserialize<Eventuser>(json); var euser = ser.Deserialize<Eventuser>(json);
...@@ -110,7 +109,9 @@ namespace MoyaSignup ...@@ -110,7 +109,9 @@ namespace MoyaSignup
} }
catch (WebException ex) catch (WebException ex)
{ {
if (ex is MoyaApiException && ((MoyaApiException) ex).StatusCode == HttpStatusCode.NotFound) timer1.Stop();
var apiException = ex as MoyaApiException;
if (apiException != null && apiException.StatusCode == HttpStatusCode.NotFound)
{ {
CurrentUser = null; CurrentUser = null;
infoLabel.Text = "Uusi kävijä?"; infoLabel.Text = "Uusi kävijä?";
...@@ -119,7 +120,6 @@ namespace MoyaSignup ...@@ -119,7 +120,6 @@ namespace MoyaSignup
} }
else else
{ {
timer1.Stop();
Logger.Error("Connection to MoyaApi failed", ex); Logger.Error("Connection to MoyaApi failed", ex);
MessageBox.Show( MessageBox.Show(
...@@ -142,8 +142,6 @@ namespace MoyaSignup ...@@ -142,8 +142,6 @@ namespace MoyaSignup
MessageBoxIcon.Error MessageBoxIcon.Error
); );
} }
timer1.Stop();
} }
private void ShowLogin(bool show) private void ShowLogin(bool show)
......
...@@ -42,6 +42,12 @@ ...@@ -42,6 +42,12 @@
<setting name="ApiURL" serializeAs="String"> <setting name="ApiURL" serializeAs="String">
<value>http://myapi.moya.endpoint/MoyaWeb</value> <value>http://myapi.moya.endpoint/MoyaWeb</value>
</setting> </setting>
<setting name="LogFile" serializeAs="String">
<value>log.txt</value>
</setting>
</MoyaSignup.Properties.Settings> </MoyaSignup.Properties.Settings>
</userSettings> </userSettings>
<startup><supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/></startup></configuration> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
</configuration>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!