Posted 9 October 2019, 12:52 am EST
Hi Mohitg
Thanks for the reply. I have tried your suggestion and I have managed to get a File based theme to work. I was not expecting the themes and other resources to be dependent on embedded paths for preview, I was hoping they would use the same methods that the designer does.
This poses a new question. How would I pull a theme from an API on preview? The designer can pull themes form the API by doing the following
public Theme GetTheme(string id) {
try {
string[] IDparts = id.Split('|');
if (IDparts.Length != 2) {
throw new LoggedException($"Invalid theme selected - {id}.");
}
Theme theme = null;
ReportPreviewOptions reportPreviewOptions = GetPreviewOptionsFromHeaders();
if (reportPreviewOptions == null) {
return null;
}
HttpResponseMessage result = ReportHttpClient.SendRequest(reportPreviewOptions.CoreURL, $"Theme/GetThemeDetailsByID/{IDparts[1]}", reportPreviewOptions.Token, HttpMethod.Get);
if (result.IsSuccessStatusCode) {
Dictionary<string, ThemeDet> coreThemeDetails = result.Content.ReadAsStringAsync().Result.ConvertJsonStringToObjectAsync<Dictionary<string, ThemeDet>>().Result;
if (coreThemeDetails.Values == null || coreThemeDetails.Values.Count == 0) {
throw new Exception($" theme for ID {IDparts[1]} has not been properly configured");
}
theme = ParseTheme(coreThemeDetails);
} else {
throw new Exception("Failed to get theme.");
}
return theme;
} catch (Exception ex) {
throw new LoggedException($"Failed to get theme {id}", ex);
}
}
public IThemeInfo[] GetThemesList() {
List<ReportTheme> reportThemes = new List<ReportTheme>();
ReportPreviewOptions reportPreviewOptions = GetPreviewOptionsFromHeaders();
try {
HttpResponseMessage result = ReportHttpClient.SendRequest(reportPreviewOptions.CoreURL, "Theme/GetAllThemeDefinitionStubs", reportPreviewOptions.Token, HttpMethod.Get);
if (result.IsSuccessStatusCode) {
List<ThemeDet> coreThemes = result.Content.ReadAsStringAsync().Result.ConvertJsonStringToObjectAsync<List<ThemeDet>>().Result;
foreach (var item in coreThemes) {
result = null;
result = ReportHttpClient.SendRequest(reportPreviewOptions.CoreURL, $"Theme/GetThemeByID/{item.ID}", reportPreviewOptions.Token, HttpMethod.Get);
if (result.IsSuccessStatusCode) {
ThemeDefinition coreTheme = result.Content.ReadAsStringAsync().Result.ConvertJsonStringToObjectAsync<ThemeDefinition>().Result;
ReportTheme reportTheme = new ReportTheme();
reportTheme = (ReportTheme)ParseTheme(coreTheme.Details);
reportTheme.Id = "APITheme |" + item.ID;
reportTheme.Title = item.Name;
reportThemes.Add(reportTheme);
} else {
throw new LoggedException("Failed to get theme.");
}
}
} else {
throw new LoggedException("Failed to get themes.");
}
} catch (Exception ex) {
throw new LoggedException("Failed to get themes.", ex);
}
return reportThemes.ToArray();
}
But I don`t seem how I would be able to embed the API call into the saved report for preview
FYI my report are based on the MVC Core solution.