Skip to content

Commit

Permalink
Solved blocking calls on Sync methods when in Aspnet or UWP
Browse files Browse the repository at this point in the history
  • Loading branch information
n3wt0n committed Apr 1, 2016
1 parent a0b2bfb commit 1b814bf
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 21 deletions.
12 changes: 9 additions & 3 deletions BugGuardian.Shared/Creator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ public Creator()
/// <param name="tags">Optional tags (list separated by comma) to be added to the WorkItem</param>
/// <returns></returns>
public BugGuardianResponse AddBug(Exception ex, string message = null, IEnumerable<string> tags = null)
=> AddWorkItemAsync(WorkItemType.Bug, ex, message, tags).Result;
=> Task.Factory.StartNew(async delegate
{
return await AddWorkItemAsync(WorkItemType.Bug, ex, message, tags);
}).Unwrap().Result;

/// <summary>
/// Add a Bug in async, with the info about the given Exception. You can optionally indicate a custom error message and a list of tags
Expand All @@ -33,7 +36,7 @@ public BugGuardianResponse AddBug(Exception ex, string message = null, IEnumerab
/// <param name="tags">Optional tags (list separated by comma) to be added to the WorkItem</param>
/// <returns></returns>
public Task<BugGuardianResponse> AddBugAsync(Exception ex, string message = null, IEnumerable<string> tags = null)
=> AddWorkItemAsync(WorkItemType.Bug, ex, message, tags);
=> AddWorkItemAsync(WorkItemType.Bug, ex, message, tags);

/// <summary>
/// Add a Task, with the info about the given Exception. You can optionally indicate a custom error message and a list of tags
Expand All @@ -43,7 +46,10 @@ public Task<BugGuardianResponse> AddBugAsync(Exception ex, string message = null
/// <param name="tags">Optional tags (list separated by comma) to be added to the WorkItem</param>
/// <returns></returns>
public BugGuardianResponse AddTask(Exception ex, string message = null, IEnumerable<string> tags = null)
=> AddWorkItemAsync(WorkItemType.Task, ex, message, tags).Result;
=> Task.Factory.StartNew(async delegate
{
return await AddWorkItemAsync(WorkItemType.Task, ex, message, tags);
}).Unwrap().Result;

/// <summary>
/// Add a Task in async, with the info about the given Exception. You can optionally indicate a custom error message and a list of tags
Expand Down
3 changes: 2 additions & 1 deletion BugGuardian.Shared/Helpers/WorkItemsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,9 @@ public static async Task<WorkItemData> GetExistentWorkItemId(string exceptionHas
return workItemData;
}
}
catch (Exception)
catch (Exception ex)
{
int i = 1;
}

return null;
Expand Down
2 changes: 1 addition & 1 deletion TestApps/BugGuardian.TestCallerConsole/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

<BugGuardianConfiguration>
<BugGuardianSettings>
<add key="Url" value="https://dbtek.visualstudio.com" />
<add key="Url" value="https://ACCOUNT.visualstudio.com" />
<add key="Username" value="USERNAME" />
<add key="Password" value="PASSWORD" />
<!-- Optional -->
Expand Down
20 changes: 20 additions & 0 deletions TestApps/BugGuardian.TestCallerWeb/App_Start/FilterConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using DBTek.BugGuardian.TestCallerWeb.Filters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DBTek.BugGuardian.TestCallerWeb
{
public class FilterConfig
{
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
//filters.Add(new HandleErrorAttribute());

//OPTION 1
filters.Add(new BugGuardianFilter());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,12 @@
<ItemGroup>
<Content Include="Global.asax" />
<Content Include="WebForms\PageWithError.aspx" />
<Content Include="Web.config" />
<Content Include="Web.config">
<SubType>Designer</SubType>
</Content>
</ItemGroup>
<ItemGroup>
<Compile Include="App_Start\FilterConfig.cs" />
<Compile Include="App_Start\RouteConfig.cs" />
<Compile Include="App_Start\WebApiConfig.cs" />
<Compile Include="Controllers\HomeController.cs" />
Expand Down
14 changes: 7 additions & 7 deletions TestApps/BugGuardian.TestCallerWeb/Filters/BugGuardianFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@
using System.Threading;
using System.Threading.Tasks;
using System.Web.Http.Filters;
using System.Web.Mvc;

namespace DBTek.BugGuardian.TestCallerWeb.Filters
{
public class BugGuardianFilter : IExceptionFilter
{
public bool AllowMultiple
=> true;

public Task ExecuteExceptionFilterAsync(HttpActionExecutedContext actionExecutedContext, CancellationToken cancellationToken)
public class BugGuardianFilter : HandleErrorAttribute
{
public override void OnException(ExceptionContext filterContext)
{
base.OnException(filterContext);

using (var creator = new DBTek.BugGuardian.Creator())
{
return creator.AddBugAsync(actionExecutedContext.Exception);
creator.AddBug(filterContext.Exception);
}
}
}
Expand Down
9 changes: 3 additions & 6 deletions TestApps/BugGuardian.TestCallerWeb/Global.asax.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@ public class Global : HttpApplication
{
void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup

//OPTION 1: Filter
GlobalConfiguration.Configuration.Filters.Add(new Filters.BugGuardianFilter());

// Code that runs on application startup
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
GlobalConfiguration.Configure(WebApiConfig.Register);
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
Expand All @@ -27,7 +24,7 @@ void Application_Start(object sender, EventArgs e)
// Exception ex = Server.GetLastError();
// using (var creator = new DBTek.BugGuardian.Creator())
// {
// creator.AddBug(ex);
// creator.AddBugAsync(ex);
// }
//}
}
Expand Down
6 changes: 4 additions & 2 deletions TestApps/BugGuardian.TestCallerWeb/Web.config
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@

<BugGuardianConfiguration>
<BugGuardianSettings>
<add key="Url" value="https://XXXXX.visualstudio.com" />
<add key="Username" value="USER_NAME" />
<add key="Url" value="https://ACCOUNT.visualstudio.com" />
<add key="Username" value="USERNAME" />
<add key="Password" value="PASSWORD" />
<!-- Optional -->
<add key="CollectionName" value="DefaultCollection" />
<add key="ProjectName" value="PROJECT_NAME" />
<!-- Optional -->
<add key="AvoidMultipleReport" value="true" />
</BugGuardianSettings>
</BugGuardianConfiguration>
</configuration>

0 comments on commit 1b814bf

Please sign in to comment.