public override ServiceProviderItemBandwidth[] GetServiceItemsBandwidth(ServiceProviderItem[] items, DateTime since) { ServiceProviderItemBandwidth[] itemsBandwidth = new ServiceProviderItemBandwidth[items.Length]; // update items with diskspace for (int i = 0; i < items.Length; i++) { ServiceProviderItem item = items[i]; // create new bandwidth object itemsBandwidth[i] = new ServiceProviderItemBandwidth(); itemsBandwidth[i].ItemId = item.Id; itemsBandwidth[i].Days = new DailyStatistics[0]; if (item is MailDomain) { try { // get daily statistics itemsBandwidth[i].Days = GetDailyStatistics(since, item.Name); } catch (Exception ex) { Log.WriteError(ex); System.Diagnostics.Debug.WriteLine(ex); } } } return itemsBandwidth; }
private string BuildDiskBandwidthStatisticsXml(ServiceProviderItemBandwidth[] itemsBandwidth) { StringBuilder sb = new StringBuilder(); sb.Append("<items>"); if (itemsBandwidth != null) { CultureInfo culture = CultureInfo.InvariantCulture; if (itemsBandwidth != null) { foreach (ServiceProviderItemBandwidth item in itemsBandwidth) { if (item != null && item.Days != null) { foreach (DailyStatistics day in item.Days) { string dt = new DateTime(day.Year, day.Month, day.Day).ToString("MM/dd/yyyy", culture); sb.Append("<item id=\"").Append(item.ItemId).Append("\"") .Append(" date=\"").Append(dt).Append("\"") .Append(" sent=\"").Append(day.BytesSent).Append("\"") .Append(" received=\"").Append(day.BytesReceived).Append("\"") .Append("></item>\n"); } } } } } sb.Append("</items>"); return sb.ToString(); }