private async Task <T> DoWithRetry <T>(Func <Task <T> > method) { if (m_Backoff > m_Time.Now) { return(default(T)); } try { return(await method()); } catch (WebException we) { var httpResponse = we.Response as HttpWebResponse; if (httpResponse == null || httpResponse.StatusCode != HttpStatusCode.Unauthorized) { Trace.WriteLine("Caught unhandled exception from zendesk .."); TrySetBackoff(2.Minutes()); throw; } } // You can trigger this code by going to the Zendesk profile page, // selecting the Devices and apps tab and deleting other sessions Trace.WriteLine("Caught 401 from zendesk .. attempting to reauth"); if (!TrySetBackoff(20.Seconds())) { return(default(T)); } // reconnect and retry once m_ZdApi = await m_ZdApiFactory(); return(await method()); }
public CachedZendeskApi(ITime time, IZendeskApi underlying) { m_Underlying = underlying; m_TicketCache = new Cache <string, Task <dynamic> >(time, TimeSpan.FromMinutes(5)); m_CommentsCache = new Cache <string, Task <dynamic> >(time, TimeSpan.FromMinutes(5)); m_UserCache = new Cache <string, Task <dynamic> >(time, TimeSpan.FromHours(2)); }
public TicketRetrieverTests() { _wait = Mock.Of <IWait>(); _zendeskApi = Mock.Of <IZendeskApi>(); _utcNowProvider = Mock.Of <Func <DateTime> >(); _sut = new TicketRetriever(_wait, _zendeskApi, _utcNowProvider); SetupDefaultMocks(); }
private static async Task Main(string[] args) { try { var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true) .AddJsonFile("appsettings.development.json", optional: true, reloadOnChange: true); var configuration = builder.Build(); var settings = new Settings(); configuration.GetSection("Zendesk").Bind(settings); api = new ZendeskApi("https://esfa.zendesk.com/", settings.UserName, settings.UserPassword); await UnShare(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public TicketRetriever(IWait wait, IZendeskApi zendeskApi, Func<DateTime> utcNowProvider = null) { _wait = wait; _zendeskApi = zendeskApi; _utcNowProvider = utcNowProvider ?? (() => DateTime.UtcNow); }
public ZendeskHelper(ZendeskApi_v2.IZendeskApi api, int pageSize = 100) { _api = api; _pageSize = pageSize; }
public TicketRetriever(IWait wait, IZendeskApi zendeskApi, Func <DateTime> utcNowProvider = null) { _wait = wait; _zendeskApi = zendeskApi; _utcNowProvider = utcNowProvider ?? (() => DateTime.UtcNow); }
private ReconnectingZendeskApi(IZendeskApi zdApi, Func <Task <IZendeskApi> > zdApiFactory, ITime time) { m_ZdApiFactory = zdApiFactory; m_ZdApi = zdApi; m_Time = time; }
public ZendeskTicketApi(IZendeskApi api) { m_Api = api; }
public TicketRetrieverTests() { _wait = Mock.Of<IWait>(); _zendeskApi = Mock.Of<IZendeskApi>(); _utcNowProvider = Mock.Of<Func<DateTime>>(); _sut = new TicketRetriever(_wait, _zendeskApi, _utcNowProvider); SetupDefaultMocks(); }