Ejemplo n.º 1
0
        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;
                }
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
        protected virtual void PreprocessRequest(string databaseName, [CanBeNull] out ActionResult actionResult, [NotNull] out RequestParameters requestParameters, [NotNull] out IDatabase database)
        {
            // ReSharper disable once AssignNullToNotNullAttribute
            database          = null;
            requestParameters = RequestParameters.Empty;

            actionResult = AuthenticateUser();
            if (actionResult != null)
            {
                return;
            }

            var db = ContentDeliveryManager.GetDatabase(databaseName);

            if (db == null)
            {
                actionResult = new HttpStatusCodeResult(HttpStatusCode.NotFound, "Database not found");
                return;
            }

            database = db;

            requestParameters = new RequestParameters(database.RequestParameters, Request);
        }