private string GetAngularAppScript(HttpContext context, string AppName, string FrameworkTemplatePath, string AppTemplatePath, string[] Dependencies, List <AngularView> Templates, bool ShowMissingKeys, string AppConfigJS, string AppJS)
        {
            string CacheKey     = AppName + "_ScriptHandler_" + AppTemplatePath;
            string CachedScript = Utilities.DataCache.GetItemFromCache <string>(CacheKey);

            if (CachedScript == null)
            {
                string AppTemplateDir = context.Server.MapPath(AppTemplatePath);

                string FrameworkTemplateDir  = context.Server.MapPath(FrameworkTemplatePath + "Views/");
                string SharedResourceFile    = FrameworkTemplateDir + DotNetNuke.Services.Localization.Localization.LocalResourceDirectory + "\\Shared.resx";
                string SharedAppTemplateFile = AppTemplateDir + DotNetNuke.Services.Localization.Localization.LocalResourceDirectory + "\\Shared.resx";

                if (Directory.Exists(AppTemplateDir))
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("(function() {");
                    string appJS = AngularBootstrapUIEngine.GetConfig(AppName, FrameworkTemplatePath, AppTemplatePath, Dependencies, Templates, AppConfigJS, AppJS, SharedAppTemplateFile, ShowMissingKeys);

                    //Angular bootstrap common
                    foreach (string file in Directory.EnumerateFiles(FrameworkTemplateDir, "*.js", SearchOption.AllDirectories))
                    {
                        string ResourceFile = file.Split('\\').Last();
                        string ResourcePath = file.TrimEnd(ResourceFile.ToCharArray());
                        ResourceFile = ResourcePath + DotNetNuke.Services.Localization.Localization.LocalResourceDirectory + "\\" + ResourceFile.Substring(0, ResourceFile.LastIndexOf(".js")) + ".resx";

                        sb.Append(new DNNLocalizationEngine(ResourceFile, SharedResourceFile, ShowMissingKeys).Parse(File.ReadAllText(file) + Environment.NewLine));
                    }
                    //Add individual js files
                    foreach (string file in Directory.EnumerateFiles(AppTemplateDir, "*.js", SearchOption.AllDirectories))
                    {
                        string ResourceFile = file.Split('\\').Last();
                        string ResourcePath = file.TrimEnd(ResourceFile.ToCharArray());
                        ResourceFile = ResourcePath + DotNetNuke.Services.Localization.Localization.LocalResourceDirectory + "\\" + ResourceFile.Substring(0, ResourceFile.LastIndexOf(".js")) + ".resx";

                        sb.Append(new DNNLocalizationEngine(ResourceFile, SharedAppTemplateFile, ShowMissingKeys).Parse(File.ReadAllText(file) + Environment.NewLine));
                    }
                    sb.Append("})();");
                    CachedScript = appJS + Environment.NewLine + sb.ToString();
                }
                DataCache.SetCache <string>(CachedScript, CacheKey);
            }
            return(CachedScript);
        }
Пример #2
0
        public dynamic Render([FromBody] dynamic data)
        {
            dynamic result = null;

            IEnumerable <string> headerValues = Request.Headers.GetValues("ModuleId");
            string ModuleID = headerValues.FirstOrDefault();

            if (string.IsNullOrEmpty(ModuleID))
            {
                ThrowError(ref result, "Identifier is required to process UIEngine requests");
            }

            Dictionary <string, string> parameters = new Dictionary <string, string>();

            foreach (dynamic item in data.parameters)
            {
                parameters.Add(item.Name.ToLower(), item.Value.Value);
            }

            UIEngineInfo = new Dictionary <string, string>();
            foreach (dynamic item in data)
            {
                UIEngineInfo.Add(item.Name.ToLower(), item.Value.Value);
            }

            UIEngineInfo.Add("moduleid", ModuleID);

            //Requried for script initialization such as Sortable
            UIEngineInfo.Add("InitScript", string.Empty);

            //Fix for Ckeditor
            UIEngineInfo.Add("PreInitScript", string.Empty);


            if (!UIEngineInfo.ContainsKey("provider"))
            {
                ThrowError(ref result, "Did you forget to specify a UI Engine Provider? &lt;uielement provider=&quot;AngularBootstrap&quot;&gt;&lt;/uielement&gt;");
            }

            if (!UIEngineInfo.ContainsKey("identifier") || (UIEngineInfo.ContainsKey("identifier") && (UIEngineInfo["identifier"].Contains(".") || UIEngineInfo["identifier"].Contains(' '))))
            {
                ThrowError(ref result, "Did you forget to specify a UI Identifier and Identifier shouldn't contain whitespace and dot(.)? &lt;uielement identifier=&quot;admin_settings_general&quot;&gt;&lt;/uielement&gt;");
            }

            if (UIEngineInfo.ContainsKey("layout") && UIEngineInfo.ContainsKey("uienginepath"))
            {
                string _OverLoadPath = HttpContext.Current.Server.MapPath(UIEngineInfo["uienginepath"]);// + "/Layouts/" + UIEngineInfo["layout"] + ".htm");
                UIEngineInfo.Add("overloadpath", _OverLoadPath);
            }

            //if (!UIEngineInfo.ContainsKey("layoutmarkup"))
            //    ThrowError(ref result, "Did you forget to specify UI Elements? &lt;uielement identifier=&quot;admin_settings_general&quot;&gt;&lt;/uielement&gt;");

            if (!UIEngineInfo.ContainsKey("showmissingkeys"))
            {
                UIEngineInfo.Add("showmissingkeys", "false");
            }

            UIEngineInfo.Add("layoutmarkup", GetLayoutMarkup(UIEngineInfo["templateurl"]));


            //Return Cached Result
            //var cachedResult = Utilities.DataCache.GetItemFromCache<dynamic>(UIEngineInfo["moduleid"] + UIEngineInfo["identifier"]);
            //if (cachedResult != null)
            //    return cachedResult;

            ValidateMarkup(ref result);


            if (result == null) // No validation errors
            {
                lock (LockObject)
                {
                    //Get UI Data
                    List <IUIData> IUIDataList;

                    //if (UIEngineInfo["identifier"] == "licensing")
                    //    IUIDataList = GetLicensingData(UIEngineInfo["appname"]);
                    //else
                    IUIDataList = GetData(UIEngineInfo["identifier"], parameters);

                    //Convert it to Dynamic
                    if (IUIDataList != null)
                    {
                        dynamic UIData = ConvertToDynamic(IUIDataList);

                        switch (UIEngineInfo["provider"])
                        {
                        case "AngularBootstrap":
                        {
                            result = AngularBootstrapUIEngine.GetMarkup(UIEngineInfo, UIData);

                            break;
                        }

                        default:
                        {
                            ThrowError(ref result, UIEngineInfo["provider"] + ": This is not a valid UI Engine Provider");

                            break;
                        }
                        }
                    }
                }
            }
            return(result);
        }