protected void Application_Start() { // register routes ContentDeliveryConfig.RegisterRoutes("sitecore"); // register databases var appDataDirectory = HttpContext.Current.Server.MapPath(Constants.AppDataDatabasesDirectory); if (!Directory.Exists(appDataDirectory)) { return; } var currentDirectory = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? appDataDirectory; foreach (var fileName in Directory.GetFiles(appDataDirectory)) { var extension = Path.GetExtension(fileName)?.ToLowerInvariant(); switch (extension) { case ".json": var parameters = new Dictionary <string, string> { ["file"] = fileName }; var jsonFileDatabase = new JsonFileDatabase(); jsonFileDatabase.Initialize(parameters, currentDirectory, appDataDirectory); ContentDeliveryManager.MountDatabase(jsonFileDatabase); break; } } }
public void Process([NotNull] PipelineArgs args) { // register routes var basePath = Settings.GetSetting(Constants.BasePath, "sitecore"); ContentDeliveryConfig.RegisterRoutes(basePath); // register formatters ContentDeliveryManager.RegisterFieldValueFormatter(new SitecoreFieldValueFormatter()); // register databases var appDataDirectory = FileUtil.MapPath(Constants.AppDataDatabasesDirectory); var currentDirectory = FileUtil.MapPath("/"); var treeNode = Factory.GetConfigNode("sitecore.contentdelivery/tree"); foreach (XmlNode rootNode in treeNode.ChildNodes) { if (rootNode.Attributes == null) { Log.Error("Empty root node definition. Skipping.", GetType()); continue; } var database = ReflectionUtil.CreateObject(rootNode) as IDatabase; if (database == null) { Log.Error("Failed to create database: " + XmlUtil.GetAttribute("type", rootNode), GetType()); continue; } var parameters = new Dictionary <string, string>(); foreach (XmlAttribute attribute in rootNode.Attributes) { parameters[attribute.Name] = attribute.Value; } database.Initialize(parameters, currentDirectory, appDataDirectory); ContentDeliveryManager.MountDatabase(database); } }