public IDataSource GetViewDataSource(int moduleId, bool showDrafts, Template template) { if (_viewDataSource == null) { var configurationProvider = GetConfigurationProvider(moduleId); // Get ModuleDataSource var initialSource = GetInitialDataSource(ZoneId.Value, AppId.Value, showDrafts); var moduleDataSource = DataSource.GetDataSource<ModuleDataSource>(ZoneId, AppId, initialSource, configurationProvider); moduleDataSource.ModuleId = moduleId; if(template != null) moduleDataSource.OverrideTemplateId = template.TemplateId; moduleDataSource.Sexy = this; var viewDataSourceUpstream = moduleDataSource; // If the Template has a Data-Pipeline, use it instead of the ModuleDataSource created above if (template != null && template.Pipeline != null) viewDataSourceUpstream = null; var viewDataSource = DataSource.GetDataSource<ViewDataSource>(ZoneId, AppId, viewDataSourceUpstream, configurationProvider); // Take Publish-Properties from the View-Template if (template != null) { viewDataSource.Publish.Enabled = template.PublishData; viewDataSource.Publish.Streams = template.StreamsToPublish; // Append Streams of the Data-Pipeline (this doesn't require a change of the viewDataSource itself) if (template.Pipeline != null) DataPipelineFactory.GetDataSource(AppId.Value, template.Pipeline.EntityId, configurationProvider, viewDataSource); } _viewDataSource = viewDataSource; } return _viewDataSource; }
/// <summary> /// Returns a JSON string for the elements /// </summary> public string GetJsonFromStreams(IDataSource source, string[] streamsToPublish) { var language = Thread.CurrentThread.CurrentCulture.Name; var y = streamsToPublish.Where(k => source.Out.ContainsKey(k)).ToDictionary(k => k, s => new { List = (from c in source.Out[s].List select GetDictionaryFromEntity(c.Value, language)).ToList() }); return JsonConvert.SerializeObject(y); }