protected override string ReplacePath(ControllerContext ctrlCtx, string viewPath)
        {
            string newViewPath = "~/Views/__";
            string fileName    = GetTemplateFile(ctrlCtx);

            if (!String.IsNullOrEmpty(fileName) && !String.IsNullOrEmpty(viewPath))
            {
                string folderPath = fileName.Substring(0, fileName.LastIndexOf("/")).ToLower();
                string folderName = folderPath.Substring(folderPath.LastIndexOf("/") + 1);

                CarrotCakeConfig config       = CarrotCakeConfig.GetConfig();
                string           templatePath = config.ConfigFileLocation.TemplatePath;
                if (templatePath.StartsWith("/"))
                {
                    templatePath = templatePath.Substring(1);
                }
                if (!templatePath.EndsWith("/"))
                {
                    templatePath = templatePath + "/";
                }

                string themePath = String.Format("{0}{1}", templatePath, folderName).ToLower();

#if DEBUG
                Debug.WriteLine(String.Format("CarrotViewEngineTemplate: n:{0}   c:{1}   v:{2}   f:{3}   t:{4}", ctrlCtx.Controller.GetType().Namespace, ctrlCtx.Controller.GetType().Name, viewPath, folderPath, themePath));
#endif

                newViewPath = viewPath.ToLower().Replace("::filepath::", folderPath).Replace("::themepath::", themePath);
            }

            return(newViewPath);
        }
Esempio n. 2
0
        public static FileDataHelper GetFileDataHelper()
        {
            string fileTypes = null;

            CarrotCakeConfig config = CarrotCakeConfig.GetConfig();

            if (config.FileManagerConfig != null && !String.IsNullOrEmpty(config.FileManagerConfig.BlockedExtensions))
            {
                fileTypes = config.FileManagerConfig.BlockedExtensions;
            }

            return(new FileDataHelper(fileTypes));
        }
Esempio n. 3
0
        private List <CMSTemplate> GetTemplatesByDirectory()
        {
            var _plugins = new List <CMSTemplate>();

            CarrotCakeConfig config = CarrotCakeConfig.GetConfig();

            string sPlugCfg = HttpContext.Current.Server.MapPath(config.ConfigFileLocation.TemplatePath);

            if (Directory.Exists(sPlugCfg))
            {
                string[] subdirs;
                try {
                    subdirs = Directory.GetDirectories(sPlugCfg);
                } catch {
                    subdirs = null;
                }

                if (subdirs != null)
                {
                    foreach (string theDir in subdirs)
                    {
                        string sTplDef = theDir + @"\Skin.config";

                        if (File.Exists(sTplDef))
                        {
                            string  sPathPrefix = GetFolderPrefix(theDir);
                            DataSet ds          = ReadDataSetConfig(CMSConfigFileType.SkinDef, sPathPrefix);

                            var _p2 = (from d in ds.Tables[0].AsEnumerable()
                                       select new CMSTemplate {
                                TemplatePath = "~/" + (sPathPrefix + d.Field <string>("templatefile").ToLowerInvariant()).ToLowerInvariant(),
                                EncodedPath = String.Empty,
                                Caption = d.Field <string>("filedesc")
                            }).ToList();

                            _plugins = _plugins.Union(_p2).ToList();

                            _plugins.Where(x => x.TemplatePath.StartsWith("~~/")).ToList()
                            .ForEach(r => r.TemplatePath = r.TemplatePath.Replace("~~/", "~/"));
                            _plugins.Where(x => x.TemplatePath.Contains("//")).ToList()
                            .ForEach(r => r.TemplatePath = r.TemplatePath.Replace("//", "/"));

                            _plugins.ForEach(r => r.EncodedPath = EncodeBase64(r.TemplatePath));
                        }
                    }
                }
            }

            return(_plugins);
        }
        public static void WriteDebugException(string sSrc, Exception objErr)
        {
            bool bWriteError = false;

            CarrotCakeConfig config = CarrotCakeConfig.GetConfig();

            if (config.ExtraOptions != null && config.ExtraOptions.WriteErrorLog)
            {
                bWriteError = config.ExtraOptions.WriteErrorLog;
            }
#if DEBUG
            bWriteError = true;             // always write errors when debug build
#endif
            DatabaseUpdate.WriteDebugException(bWriteError, sSrc, objErr);
        }
Esempio n. 5
0
        public static void WriteDebugException(string sSrc, Exception objErr)
        {
            bool bWriteError = false;

            CarrotCakeConfig config = CarrotCakeConfig.GetConfig();

            if (config.ExtraOptions != null && config.ExtraOptions.WriteErrorLog)
            {
                bWriteError = config.ExtraOptions.WriteErrorLog;
            }
#if DEBUG
            bWriteError = true;             // always write errors when debug build
#endif

            if (bWriteError && objErr != null)
            {
                StringBuilder sb = new StringBuilder();

                sb.AppendLine("----------------  " + sSrc.ToUpperInvariant() + " - " + DateTime.Now.ToString() + "  ----------------");

                sb.AppendLine("[" + objErr.GetType().ToString() + "] " + objErr.Message);

                if (objErr.StackTrace != null)
                {
                    sb.AppendLine(objErr.StackTrace);
                }

                if (objErr.InnerException != null)
                {
                    sb.AppendLine(objErr.InnerException.Message);
                }

                string filePath = HttpContext.Current.Server.MapPath("~/carrot_errors.txt");

                Encoding encode = Encoding.Default;
                lock (logLocker) {
                    using (FileStream fs = new FileStream(filePath, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) {
                        using (StreamWriter oWriter = new StreamWriter(fs, encode)) {
                            oWriter.Write(sb.ToString());
                        }
                    }
                }
            }
        }
Esempio n. 6
0
        private List <CMSAdminModule> GetModulesByDirectory()
        {
            var _plugins = new List <CMSAdminModule>();

            CarrotCakeConfig config = CarrotCakeConfig.GetConfig();

            string sPlugCfg = HttpContext.Current.Server.MapPath(config.ConfigFileLocation.PluginPath);

            if (Directory.Exists(sPlugCfg))
            {
                string[] subdirs;
                try {
                    subdirs = Directory.GetDirectories(sPlugCfg);
                } catch {
                    subdirs = null;
                }

                if (subdirs != null)
                {
                    foreach (string theDir in subdirs)
                    {
                        string sTplDef = theDir + @"\Admin.config";

                        if (File.Exists(sTplDef))
                        {
                            string  sPathPrefix = GetFolderPrefix(theDir);
                            DataSet ds          = ReadDataSetConfig(CMSConfigFileType.AdminMod, sPathPrefix);

                            var _modules = (from d in ds.Tables[0].AsEnumerable()
                                            select new CMSAdminModule {
                                PluginName = d.Field <string>("caption"),
                                AreaKey = d.Field <string>("area")
                            }).OrderBy(x => x.PluginName).ToList();

                            var _ctrls = (from d in ds.Tables[1].AsEnumerable()
                                          select new CMSAdminModuleMenu {
                                Caption = d.Field <string>("pluginlabel"),
                                SortOrder = String.IsNullOrEmpty(d.Field <string>("menuorder")) ? -1 : int.Parse(d.Field <string>("menuorder")),
                                Action = d.Field <string>("action"),
                                Controller = d.Field <string>("controller"),
                                UsePopup = String.IsNullOrEmpty(d.Field <string>("usepopup")) ? false : Convert.ToBoolean(d.Field <string>("usepopup")),
                                IsVisible = String.IsNullOrEmpty(d.Field <string>("visible")) ? false : Convert.ToBoolean(d.Field <string>("visible")),
                                AreaKey = d.Field <string>("area")
                            }).OrderBy(x => x.Caption).OrderBy(x => x.SortOrder).ToList();

                            foreach (var p in _modules)
                            {
                                p.PluginMenus = (from c in _ctrls
                                                 where c.AreaKey == p.AreaKey
                                                 orderby c.Caption, c.SortOrder
                                                 select c).ToList();
                            }

                            _plugins = _plugins.Union(_modules).ToList();
                        }
                    }
                }
            }

            return(_plugins);
        }
Esempio n. 7
0
        private List <CMSPlugin> GetPluginsByDirectory()
        {
            var _plugins = new List <CMSPlugin>();

            CarrotCakeConfig config = CarrotCakeConfig.GetConfig();

            string sPlugCfg = HttpContext.Current.Server.MapPath(config.ConfigFileLocation.PluginPath);

            if (Directory.Exists(sPlugCfg))
            {
                string[] subdirs;
                try {
                    subdirs = Directory.GetDirectories(sPlugCfg);
                } catch {
                    subdirs = null;
                }

                if (subdirs != null)
                {
                    foreach (string theDir in subdirs)
                    {
                        string sTplDef = theDir + @"\Public.config";

                        if (File.Exists(sTplDef))
                        {
                            string  sPathPrefix = GetFolderPrefix(theDir);
                            DataSet ds          = ReadDataSetConfig(CMSConfigFileType.PublicCtrl, sPathPrefix);

                            var _p2 = (from d in ds.Tables[0].AsEnumerable()
                                       select new CMSPlugin {
                                SortOrder = 100,
                                FilePath = d.Field <string>("filepath"),
                                Caption = d.Field <string>("crtldesc")
                            }).Where(x => x.FilePath.Contains(":")).ToList();

                            foreach (var p in _p2.Where(x => x.FilePath.ToLowerInvariant().EndsWith("html")).Select(x => x))
                            {
                                string[] path = p.FilePath.Split(':');
                                if (path.Length > 2 && !String.IsNullOrEmpty(path[2]) &&
                                    (path[2].ToLowerInvariant().EndsWith(".cshtml") || path[2].ToLowerInvariant().EndsWith(".vbhtml")))
                                {
                                    path[2]    = "~" + sPathPrefix + path[2];
                                    p.FilePath = String.Join(":", path);
                                }
                            }

                            var _p3 = (from d in ds.Tables[0].AsEnumerable()
                                       select new CMSPlugin {
                                SortOrder = 100,
                                FilePath = "~" + sPathPrefix + d.Field <string>("filepath"),
                                Caption = d.Field <string>("crtldesc")
                            }).Where(x => !x.FilePath.Contains(":")).ToList();

                            _plugins = _plugins.Union(_p2).Union(_p3).ToList();
                        }
                    }
                }
            }

            _plugins.Where(x => x.FilePath.StartsWith("~~/")).ToList().ForEach(r => r.FilePath = r.FilePath.Replace("~~/", "~/"));
            _plugins.Where(x => x.FilePath.Contains("//")).ToList().ForEach(r => r.FilePath    = r.FilePath.Replace("//", "/"));

            return(_plugins);
        }
Esempio n. 8
0
        private static DataSet ReadDataSetConfig(CMSConfigFileType cfg, string sPath)
        {
            string           sPlugCfg  = "default.config";
            string           sRealPath = HttpContext.Current.Server.MapPath(sPath);
            CarrotCakeConfig config    = CarrotCakeConfig.GetConfig();

            int iExpectedTblCount = 1;

            switch (cfg)
            {
            case CMSConfigFileType.SiteTextWidgets:
                sPlugCfg = sRealPath + config.ConfigFileLocation.TextContentProcessors;
                break;

            case CMSConfigFileType.SiteMapping:
                sPlugCfg = sRealPath + config.ConfigFileLocation.SiteMapping;
                break;

            case CMSConfigFileType.AdminMod:
                sPlugCfg          = sRealPath + "Admin.config";
                iExpectedTblCount = 2;
                break;

            case CMSConfigFileType.PublicCtrl:
                sPlugCfg = sRealPath + "Public.config";
                break;

            case CMSConfigFileType.SkinDef:
                sPlugCfg = sRealPath + "Skin.config";
                break;

            default:
                sPlugCfg          = sRealPath + "default.config";
                iExpectedTblCount = -1;
                break;
            }

            DataSet ds = new DataSet();

            if (File.Exists(sPlugCfg) && iExpectedTblCount > 0)
            {
                ds.ReadXml(sPlugCfg);
            }

            if (ds == null)
            {
                ds = new DataSet();
            }

            int iTblCount = ds.Tables.Count;

            // if dataset has wrong # of tables, build out more tables
            if (iTblCount < iExpectedTblCount)
            {
                for (int t = iTblCount; t <= iExpectedTblCount; t++)
                {
                    ds.Tables.Add(new DataTable());
                    ds.AcceptChanges();
                }
            }

            if (iExpectedTblCount > 0)
            {
                iTblCount = ds.Tables.Count;

                string table1Name = String.Empty;

                List <string> reqCols0 = new List <string>();
                List <string> reqCols1 = new List <string>();

                switch (cfg)
                {
                case CMSConfigFileType.AdminMod:
                    reqCols0.Add("caption");
                    reqCols0.Add("area");
                    table1Name = "pluginlist";

                    reqCols1.Add("area");
                    reqCols1.Add("pluginlabel");
                    reqCols1.Add("menuorder");
                    reqCols1.Add("action");
                    reqCols1.Add("controller");
                    reqCols1.Add("usepopup");
                    reqCols1.Add("visible");

                    break;

                case CMSConfigFileType.PublicCtrl:
                    //case CMSConfigFileType.PublicControls:
                    reqCols0.Add("filepath");
                    reqCols0.Add("crtldesc");
                    table1Name = "ctrlfile";

                    break;

                case CMSConfigFileType.SkinDef:
                    reqCols0.Add("templatefile");
                    reqCols0.Add("filedesc");
                    table1Name = "pagenames";

                    break;

                case CMSConfigFileType.SiteTextWidgets:
                    reqCols0.Add("pluginassembly");
                    reqCols0.Add("pluginname");
                    table1Name = "plugin";

                    break;

                case CMSConfigFileType.SiteMapping:
                    reqCols0.Add("domname");
                    reqCols0.Add("siteid");
                    table1Name = "sitedetail";

                    break;

                default:
                    reqCols0.Add("caption");
                    reqCols0.Add("pluginid");
                    table1Name = "none";

                    break;
                }

                if (ds.Tables.Contains(table1Name))
                {
                    //validate that the dataset has the right table configuration
                    DataTable dt0 = ds.Tables[table1Name];
                    foreach (string c in reqCols0)
                    {
                        if (!dt0.Columns.Contains(c))
                        {
                            DataColumn dc = new DataColumn(c);
                            dc.DataType = System.Type.GetType("System.String");                             // add if not found

                            dt0.Columns.Add(dc);
                            dt0.AcceptChanges();
                        }
                    }

                    for (int iTbl = 1; iTbl < iTblCount; iTbl++)
                    {
                        DataTable dt = ds.Tables[iTbl];
                        foreach (string c in reqCols1)
                        {
                            if (!dt.Columns.Contains(c))
                            {
                                DataColumn dc = new DataColumn(c);
                                dc.DataType = System.Type.GetType("System.String");                                 // add if not found

                                dt.Columns.Add(dc);
                                dt.AcceptChanges();
                            }
                        }
                    }
                }
            }

            return(ds);
        }