using MediaBrowser.Controller.Entities; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MediaBrowser.Api.Reports { public class ReportHelper { /// Gets java script localized string. /// The phrase. /// The java script localized string. public static string GetJavaScriptLocalizedString(string phrase) { var dictionary = BaseItem.LocalizationManager.GetJavaScriptLocalizationDictionary(BaseItem.ConfigurationManager.Configuration.UICulture); string value; if (dictionary.TryGetValue(phrase, out value)) { return value; } return phrase; } /// Gets server localized string. /// The phrase. /// The server localized string. public static string GetServerLocalizedString(string phrase) { return BaseItem.LocalizationManager.GetLocalizedString(phrase, BaseItem.ConfigurationManager.Configuration.UICulture); } /// Gets row type. /// The type. /// The row type. public static ReportViewType GetRowType(string rowType) { if (string.IsNullOrEmpty(rowType)) return ReportViewType.BaseItem; ReportViewType rType; if (!Enum.TryParse(rowType, out rType)) return ReportViewType.BaseItem; return rType; } /// Gets header metadata type. /// The header. /// The header metadata type. public static HeaderMetadata GetHeaderMetadataType(string header) { if (string.IsNullOrEmpty(header)) return HeaderMetadata.None; HeaderMetadata rType; if (!Enum.TryParse(header, out rType)) return HeaderMetadata.None; return rType; } /// Convert field to string. /// Generic type parameter. /// The value. /// Type of the field. /// The field converted to string. public static string ConvertToString(T value, ReportFieldType fieldType) { if (value == null) return ""; switch (fieldType) { case ReportFieldType.String: return value.ToString(); case ReportFieldType.Boolean: return value.ToString(); case ReportFieldType.Date: return string.Format("{0:d}", value); case ReportFieldType.Time: return string.Format("{0:t}", value); case ReportFieldType.DateTime: return string.Format("{0:d}", value); case ReportFieldType.Int: return string.Format("", value); default: if (value is Guid) return string.Format("{0:N}", value); return value.ToString(); } } } }