コード例 #1
0
ファイル: SaveFileController.cs プロジェクト: jraghu24/Rraghu
        public JsonResult SavePartialView(string filename, string oldName, string contents)
        {
            var folderPath = SystemDirectories.MvcViews.EnsureEndsWith('/');            // +"/Partials/";

            // validate file
            IOHelper.ValidateEditPath(IOHelper.MapPath(folderPath + filename), folderPath);
            // validate extension
            IOHelper.ValidateFileExtension(IOHelper.MapPath(folderPath + filename), new[] { "cshtml" }.ToList());

            //TODO: Validate using the macro engine
            var engine = MacroEngineFactory.GetEngine(PartialViewMacroEngine.EngineName);
            //engine.Validate(...)

            var val         = contents;
            var saveOldPath = oldName.StartsWith("~/") ? IOHelper.MapPath(oldName) : IOHelper.MapPath(folderPath + oldName);
            var savePath    = filename.StartsWith("~/") ? IOHelper.MapPath(filename) : IOHelper.MapPath(folderPath + filename);

            //Directory check.. only allow files in script dir and below to be edited
            if (!savePath.StartsWith(IOHelper.MapPath(folderPath)))
            {
                return(Failed(
                           ui.Text("speechBubbles", "partialViewErrorText"), ui.Text("speechBubbles", "partialViewErrorHeader"),
                           //pass in a new exception ... this will also append the the message
                           new ArgumentException("Illegal path: " + savePath)));
            }

            //deletes the old file
            if (savePath != saveOldPath)
            {
                if (System.IO.File.Exists(saveOldPath))
                {
                    System.IO.File.Delete(saveOldPath);
                }
            }

            //NOTE: I've left the below here just for informational purposes. If we save a file this way, then the UTF8
            // BOM mucks everything up, strangely, if we use WriteAllText everything is ok!
            // http://issues.umbraco.org/issue/U4-2118
            //using (var sw = System.IO.File.CreateText(savePath))
            //{
            //    sw.Write(val);
            //}

            System.IO.File.WriteAllText(savePath, val, Encoding.UTF8);

            return(Success(ui.Text("speechBubbles", "partialViewSavedText"), ui.Text("speechBubbles", "partialViewSavedHeader")));
        }
コード例 #2
0
        // copied and adapted from Umbraco's code to execute partial view macros
        private static ScriptingMacroResult LoadPartialViewMacro(MacroModel macro, IPublishedContent content)
        {
            var result = new ScriptingMacroResult();

            var engine = MacroEngineFactory.GetEngine(PartialViewMacroEngine.EngineName) as PartialViewMacroEngine;

            if (engine == null)
            {
                throw new Exception("Oops.");
            }
            result.Result = engine.Execute(macro, content);

            // don't bother - only the legacy razor engine seems to implement that interface
            //var reportingEngine = engine as IMacroEngineResultStatus;
            //if (reportingEngine != null)
            //{
            //    if (reportingEngine.Success == false)
            //        result.ResultException = reportingEngine.ResultException;
            //}

            return(result);
        }
コード例 #3
0
        public void Get_Engine()
        {
            var engine1 = MacroEngineFactory.GetEngine("MacroEngine1");

            Assert.IsNotNull(engine1);
        }