2 using System.Collections.Generic;
3 using System.Configuration;
4 using System.Diagnostics;
7 using CPE.App.Web.Models;
9 namespace CPE.App.Web.Code
11 public static class Extensions
13 public static DateTime GetLocalDateTime(DateTime UtcDateTime)
15 var timezoneId = ConfigurationManager.AppSettings["TimezoneId"] ?? "Eastern Standard Time";
16 var timezoneInfo = TimeZoneInfo.FindSystemTimeZoneById(timezoneId);
17 return TimeZoneInfo.ConvertTimeFromUtc(UtcDateTime, timezoneInfo);
19 public static string GetPercentComplete(double val1, double val2)
22 return 1.ToString("p");
23 return (val2 / val1).ToString("p");
25 public static double GetPollPercentComplete(double val1, double val2)
31 public static int ReentryCutoff()
33 var cuttoff = ConfigurationManager.AppSettings["ReEntryCutoffMinutes"] ?? "5";
34 return int.Parse(cuttoff);
37 public static void LogServiceError(string service, string message, Exception ex)
41 var context = CPEWebDataContext.GetContext();
42 var serviceError = new ServiceError()
44 Logged = DateTime.UtcNow,
45 ServiceMethod = service,
47 StackTrace = ex.ToString()
49 context.ServiceErrors.InsertOnSubmit(serviceError);
50 context.SubmitChanges();
52 catch (Exception blackhole)
54 //swallow logging errors
55 Debug.WriteLine(blackhole.Message);
59 public static void LogServiceError(string service, Exception ex)
63 var context = CPEWebDataContext.GetContext();
64 var serviceError = new ServiceError()
66 Logged = DateTime.UtcNow,
67 ServiceMethod = service,
69 StackTrace = ex.ToString()
71 context.ServiceErrors.InsertOnSubmit(serviceError);
72 context.SubmitChanges();
74 catch (Exception blackhole)
76 //swallow logging errors
77 Debug.WriteLine(blackhole.Message);
81 public static void LogServiceCall(string service, string details)
85 var context = CPEWebDataContext.GetContext();
86 var serviceLog = new ServiceLog()
88 ServiceMethod = service,
90 Created = DateTime.UtcNow,
91 LogKey = Guid.NewGuid()
93 context.ServiceLogs.InsertOnSubmit(serviceLog);
94 context.SubmitChanges();
96 catch (Exception blackhole)
98 //swallow logging errors
99 Debug.WriteLine(blackhole.Message);