public ActionResult GetLocationStatisticsCsv(DateTime startDate, DateTime endDate, Guid regionId, Guid ownerId, Guid codecTypeId) { var statistics = _statisticsManager.GetLocationStatistics(startDate.ToUniversalTime(), endDate.ToUniversalTime().AddDays(1.0), regionId, ownerId, codecTypeId); var csv = new StringBuilder(); csv.AddCsvValue(Resources.Location) .AddCsvSeparator() .AddCsvValue(Resources.Calls) .AddCsvSeparator() .AddCsvValue(Resources.Call_Time) .AddCsvSeparator() .AddCsvValue(Resources.Call_Simultaneous) .AppendLine(); var svCulture = CultureInfo.CreateSpecificCulture("sv-SE"); foreach (var stats in statistics) { csv.AddCsvValue(string.IsNullOrWhiteSpace(stats.LocationName) ? "-" : stats.LocationName) .AddCsvSeparator() .AddCsvValue(stats.NumberOfCalls) .AddCsvSeparator() .AddCsvValue(stats.TotaltTimeForCalls, 0, svCulture) .AddCsvSeparator() .AddCsvValue(stats.MaxSimultaneousCalls) .AppendLine(); } var encoding = Encoding.GetEncoding(1252); return(File(encoding.GetBytes(csv.ToString()), "text/csv", string.Format("Platser_{0:yyMMdd}_{1:yyMMdd}.csv", startDate, endDate))); }
public ActionResult GetDateBasedCsv(DateBasedFilterType filterType, DateTime startDate, DateTime endDate, Guid filterId) { IList <DateBasedStatistics> stats; switch (filterType) { case DateBasedFilterType.Regions: stats = _statisticsManager.GetRegionStatistics(startDate.ToUniversalTime(), endDate.ToUniversalTime().AddDays(1.0), filterId); break; case DateBasedFilterType.SipAccounts: stats = _statisticsManager.GetSipStatistics(startDate.ToUniversalTime(), endDate.ToUniversalTime().AddDays(1.0), filterId); break; default: stats = _statisticsManager.GetCodecTypeStatistics(startDate.ToUniversalTime(), endDate.ToUniversalTime().AddDays(1.0), filterId); break; } var csv = new StringBuilder(); csv.AddCsvValue(Resources.Date) .AddCsvSeparator() .AddCsvValue(Resources.Calls) .AddCsvSeparator() .AddCsvValue(Resources.Call_Time + "/" + Resources.Total) .AddCsvSeparator() .AddCsvValue(Resources.Call_Time + "/" + Resources.Average) .AddCsvSeparator() .AddCsvValue(Resources.Call_Time + "/" + Resources.Shortest) .AddCsvSeparator() .AddCsvValue(Resources.Call_Time + "/" + Resources.Longest) .AppendLine(); var svCulture = CultureInfo.CreateSpecificCulture("sv-SE"); foreach (var row in stats) { csv.AddCsvValue(row.Date.ToString("yyyy-MM-dd", svCulture)) .AddCsvSeparator() .AddCsvValue(row.NumberOfCalls) .AddCsvSeparator() .AddCsvValue(row.TotaltTimeForCalls, 0, svCulture) .AddCsvSeparator() .AddCsvValue(row.AverageTime, 0, svCulture) .AddCsvSeparator() .AddCsvValue(row.MinCallTime, 0, svCulture) .AddCsvSeparator() .AddCsvValue(row.MaxCallTime, 0, svCulture) .AppendLine(); } var encoding = Encoding.GetEncoding(1252); var prefix = filterType == DateBasedFilterType.CodecTypes ? Resources.Codec_Type : filterType == DateBasedFilterType.SipAccounts ? Resources.Sip_Accounts : Resources.Region; return(File(encoding.GetBytes(csv.ToString()), "text/csv", string.Format("{0}_{1:yyMMdd}_{2:yyMMdd}.csv", prefix, startDate, endDate))); }
public ActionResult GetLocationSim24HourCsv(DateTime startDate, DateTime endDate, Guid locationId) { var stats = _statisticsManager.GetHourStatisticsForLocation(startDate.ToUniversalTime(), endDate.ToUniversalTime().AddDays(1.0), locationId, true); var csv = new StringBuilder(); csv.AddCsvValue(Resources.Statistics).AddCsvSeparator().AddCsvValue(Resources.Call_Sim24Hour).AppendLine(); csv.AddCsvValue(Resources.Location).AddCsvSeparator().AddCsvValue(stats.LocationName).AppendLine(); csv.AddCsvValue(Resources.From).AddCsvSeparator().AddCsvValue(string.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd}", startDate)).AppendLine(); csv.AddCsvValue(Resources.To).AddCsvSeparator().AddCsvValue(string.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd}", endDate)).AppendLine(); csv.AppendLine(); csv.AddCsvValue(Resources.Hour).AddCsvSeparator().AddCsvValue(Resources.Stats_Number_Of_Simultaneous_Calls).AppendLine(); foreach (var hour in stats.Statistics) { csv.AddCsvValue(string.Format(CultureInfo.InvariantCulture, "{0:yyyy-MM-dd HH:mm}", hour.Date.ToLocalTime())) .AddCsvSeparator() .AddCsvValue(hour.MaxSimultaneousCalls) .AppendLine(); } var encoding = Encoding.GetEncoding(1252); var locationName = Regex.Replace(stats.LocationName ?? "", string.Join("|", Path.GetInvalidFileNameChars().Select(c => Regex.Escape(c.ToString()))), "") .Replace(" ", "_"); return(File(encoding.GetBytes(csv.ToString()), "text/csv", string.Format("{0}_{1:yyMMdd}_{2:yyMMdd}.csv", locationName, startDate, endDate))); }