/// <summary> /// Loads the propertylist definitions for a propertylist based on its model type. /// </summary> /// <param name="model">The model type for which propertylist definitions is to be loaded.</param> /// <returns>Returns an object describing the propertylist.</returns> /// <remarks>This method is not used by applications. It is reserved for component implementation.</remarks> public static async Task <PropertyListSetup> LoadPropertyListDefinitionsAsync(Type model) { string controller; string objClass; if (model.FullName.Contains("+")) { string className = model.FullName.Split(new char[] { '.' }).Last(); string[] s = className.Split(new char[] { '+' }); int len = s.Length; if (len != 2) { throw new InternalError($"Unexpected class {className} in propertylist model {model.FullName}"); } controller = s[0]; objClass = s[1]; } else { string[] s = model.FullName.Split(new char[] { '.' }); int len = s.Length; if (len < 2) { throw new InternalError($"Unexpected class {model.FullName} as propertylist model"); } controller = s[len - 2]; objClass = s[len - 1]; } string file = controller + "." + objClass; Package package = Package.GetPackageFromType(model); string predefUrl = VersionManager.GetAddOnPackageUrl(package.AreaName) + "PropertyLists/" + file; string customUrl = VersionManager.GetCustomUrlFromUrl(predefUrl); PropertyListSetup setup = null; PropertyListSetup predefSetup = await ReadPropertyListSetupAsync(package, model, Utility.UrlToPhysical(predefUrl)); if (predefSetup.ExplicitDefinitions) { setup = predefSetup; } PropertyListSetup customInfo = await ReadPropertyListSetupAsync(package, model, Utility.UrlToPhysical(customUrl)); if (customInfo.ExplicitDefinitions) { setup = customInfo; } if (setup == null) { setup = new PropertyListSetup(); } return(setup); }
private async Task LoadHighlightJSThemesAsync() { Package package = AreaRegistration.CurrentPackage; string url = VersionManager.GetAddOnNamedUrl(package.AreaName, "SkinHighlightJS"); string customUrl = VersionManager.GetCustomUrlFromUrl(url); string path = Utility.UrlToPhysical(url); string customPath = Utility.UrlToPhysical(customUrl); // use custom or default theme list string themeFile = HighlightJSThemeFile; string filename = Path.Combine(customPath, themeFile); if (!await FileSystem.FileSystemProvider.FileExistsAsync(filename)) { filename = Path.Combine(path, themeFile); } List <string> lines = await FileSystem.FileSystemProvider.ReadAllLinesAsync(filename); List <HighlightJSTheme> HighlightJSList = new List <HighlightJSTheme>(); foreach (string line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } string name = line.Trim(); #if DEBUG // only validate files in debug builds string f = Path.Combine(path, "themes", name) + ".css"; if (!await FileSystem.FileSystemProvider.FileExistsAsync(f)) { throw new InternalError("HighlightJS theme file not found: {0} - {1}", line, f); } #endif HighlightJSList.Add(new HighlightJSTheme { Name = name, }); } if (HighlightJSList.Count == 0) { throw new InternalError("No HighlightJS themes found"); } _HighlightJSThemeDefault = HighlightJSList[0]; _HighlightJSThemeList = (from theme in HighlightJSList orderby theme.Name select theme).ToList(); }
private async Task <string> GetHelpFileContentsAsync(HelpInfoDefinition model) { string urlBase = $"{VersionManager.GetAddOnPackageUrl(model.Package.AreaName)}Help"; string urlCustomBase = VersionManager.GetCustomUrlFromUrl(urlBase); string file = $"{model.Name}.html"; string lang = MultiString.ActiveLanguage; // try custom language specific HelpFileInfo helpCustomLang = await TryHelpFileAsync($"{urlCustomBase}/{lang}/{file}", model.UseCache); if (helpCustomLang.Exists) { return(helpCustomLang.Contents); } // try custom HelpFileInfo helpCustom = await TryHelpFileAsync($"{urlCustomBase}/{file}", model.UseCache); if (helpCustom.Exists) { return(helpCustom.Contents); } // try fallback language specific HelpFileInfo helpLang = await TryHelpFileAsync($"{urlBase}/{lang}/{file}", model.UseCache); if (helpLang.Exists) { return(helpLang.Contents); } // try fallback HelpFileInfo help = await TryHelpFileAsync($"{urlBase}/{file}", model.UseCache); if (help.Exists) { return(help.Contents); } return(null); }
/// <summary> /// Loads the grid column definitions for a grid. /// </summary> /// <param name="recordType">The record type for which grid column definitions are to be loaded.</param> /// <returns>A GridDictionaryInfo.ReadGridDictionaryInfo object describing the grid.</returns> /// <remarks>This method is not used by applications. It is reserved for component implementation.</remarks> private static async Task <GridDictionaryInfo.ReadGridDictionaryInfo> LoadGridColumnDefinitionsAsync(Type recordType) { Dictionary <string, GridColumnInfo> dict = new Dictionary <string, GridColumnInfo>(); string className = recordType.FullName.Split(new char[] { '.' }).Last(); string[] s = className.Split(new char[] { '+' }); int len = s.Length; if (len != 2) { throw new InternalError("Unexpected class {0} in record type {1}", className, recordType.FullName); } string controller = s[0]; string model = s[1]; string file = controller + "." + model; Package package = Package.GetPackageFromType(recordType); string predefUrl = VersionManager.GetAddOnPackageUrl(package.AreaName) + "Grids/" + file; string customUrl = VersionManager.GetCustomUrlFromUrl(predefUrl); GridDictionaryInfo.ReadGridDictionaryInfo info; GridDictionaryInfo.ReadGridDictionaryInfo predefInfo = await GridDictionaryInfo.ReadGridDictionaryAsync(package, recordType, Utility.UrlToPhysical(predefUrl)); if (!predefInfo.Success) { throw new InternalError("No grid definition exists for {0}", file); } info = predefInfo; GridDictionaryInfo.ReadGridDictionaryInfo customInfo = await GridDictionaryInfo.ReadGridDictionaryAsync(package, recordType, Utility.UrlToPhysical(customUrl)); if (customInfo.Success) { info = customInfo; } if (info.ColumnInfo.Count == 0) { throw new InternalError("No grid definition exists for {0}", file); } return(info); }
private async Task LoadSyntaxHighlighterThemesAsync() { Package package = AreaRegistration.CurrentPackage; string url = VersionManager.GetAddOnNamedUrl(package.AreaName, "SkinSyntaxHighlighter"); string customUrl = VersionManager.GetCustomUrlFromUrl(url); string path = Utility.UrlToPhysical(url); string customPath = Utility.UrlToPhysical(customUrl); // use custom or default theme list string themeFile; if (Utility.AspNetMvc == Utility.AspNetMvcVersion.MVC5) { themeFile = SyntaxHighlighterThemeFileMVC5; } else { themeFile = SyntaxHighlighterThemeFileMVC6; } string filename = Path.Combine(customPath, themeFile); if (!await FileSystem.FileSystemProvider.FileExistsAsync(filename)) { filename = Path.Combine(path, themeFile); } List <string> lines = await FileSystem.FileSystemProvider.ReadAllLinesAsync(filename); List <SyntaxHighlighterTheme> syntaxHighlighterList = new List <SyntaxHighlighterTheme>(); foreach (string line in lines) { if (string.IsNullOrWhiteSpace(line)) { continue; } string[] s = line.Split(new char[] { ',' }, 3); string name = s[0].Trim(); if (string.IsNullOrWhiteSpace(name)) { throw new InternalError("Invalid/empty SyntaxHighlighter theme name"); } if (s.Length < 2) { throw new InternalError("Invalid SyntaxHighlighter theme entry: {0}", line); } string file = s[1].Trim(); #if DEBUG // only validate files in debug builds if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows)) { url = url.Replace('/', '\\'); } if (file.StartsWith("\\") || file.StartsWith("/")) { string f = Path.Combine(YetaWFManager.RootFolder, file.Substring(1)); if (!await FileSystem.FileSystemProvider.FileExistsAsync(f)) { throw new InternalError("SyntaxHighlighter theme file not found: {0} - {1}", line, f); } } else { string f = Path.Combine(path, file); if (!await FileSystem.FileSystemProvider.FileExistsAsync(f)) { throw new InternalError("SyntaxHighlighter theme file not found: {0} - {1}", line, f); } } #endif string description = null; if (s.Length > 2) { description = s[2].Trim(); } if (string.IsNullOrWhiteSpace(description)) { description = null; } syntaxHighlighterList.Add(new SyntaxHighlighterTheme { Name = name, Description = description, File = file, }); } if (syntaxHighlighterList.Count == 0) { throw new InternalError("No SyntaxHighlighter themes found"); } _syntaxHighlighterThemeDefault = syntaxHighlighterList[0]; SyntaxHighlighterThemeList = (from theme in syntaxHighlighterList orderby theme.Name select theme).ToList(); }
private async Task <ScriptData> ReadScriptAsync(string phoneNumber) { // find the file string addonUrl = VersionManager.GetAddOnPackageUrl(Softelvdm.Modules.IVR.Controllers.AreaRegistration.CurrentPackage.AreaName); string scriptPath = Path.Combine(Utility.UrlToPhysical(VersionManager.GetCustomUrlFromUrl(addonUrl)), "Scripts", $"TWIML{phoneNumber}.txt"); Logging.AddLog($"Trying script at {scriptPath}"); if (!await FileSystem.FileSystemProvider.FileExistsAsync(scriptPath)) { Logging.AddLog($"Script at {scriptPath} not found"); addonUrl = VersionManager.GetAddOnPackageUrl(Softelvdm.Modules.IVR.Controllers.AreaRegistration.CurrentPackage.AreaName); scriptPath = Path.Combine(Utility.UrlToPhysical(addonUrl), "Scripts", $"TWIML{phoneNumber}.txt"); Logging.AddLog($"Trying script at {scriptPath}"); if (!await FileSystem.FileSystemProvider.FileExistsAsync(scriptPath)) { Logging.AddLog($"Script at {scriptPath} not found"); return(null); } } ScriptData script = new ScriptData(); using (ExtensionEntryDataProvider extensionDP = new ExtensionEntryDataProvider()) { DataProviderGetRecords <ExtensionEntry> data = await extensionDP.GetItemsAsync(0, 0, null, null); foreach (ExtensionEntry extension in data.Data) { Extension ext = new Extension { Digits = extension.Extension, Name = extension.Description, Numbers = new List <ExtensionNumber>(), }; foreach (ExtensionPhoneNumber extPhone in extension.PhoneNumbers) { ext.Numbers.Add(new ExtensionNumber { Number = extPhone.PhoneNumber, SendSMSVoiceMail = extPhone.SendSMS, }); } script.Extensions.Add(ext); } } // load the contents List <string> lines = await FileSystem.FileSystemProvider.ReadAllLinesAsync(scriptPath); int total = lines.Count; // TWIML Snippets int lineIx = 0; for ( ; lineIx < total; ++lineIx) { string l = lines[lineIx].Trim(); if (l.Length > 0 && !l.StartsWith("##")) { // tag and parms List <ScriptEntry> entries = new List <ScriptEntry>(); for ( ; ;) { if (l.StartsWith(" ")) { if (entries.Count > 0) { break; } throw new InternalError($"Tag name expected on line {lineIx + 1} in {scriptPath}"); } ScriptEntry entry = new ScriptEntry(); string[] tokens = l.Split(new char[] { ' ' }); if (tokens.Length < 1 || (tokens.Length % 2) != 1) { throw new InternalError($"Unexpected number of arguments on line {lineIx + 1} in {scriptPath}"); } entry.Tag = tokens[0].ToLower(); for (int tokIx = 1; tokIx < tokens.Length; tokIx += 2) { entry.Parms.Add(new ScriptParm { Name = tokens[tokIx], Value = tokens[tokIx + 1], }); } ++lineIx; l = lines[lineIx]; entries.Add(entry); } // text string text = ""; for ( ; lineIx < total; ++lineIx) { l = lines[lineIx]; if (l.Length == 0) { break; } if (!l.StartsWith(" ")) { throw new InternalError($"Unexpected content (not indented) on line {lineIx + 1} in {scriptPath}"); } l = l.Trim(); text += l + "\r\n"; } foreach (ScriptEntry entry in entries) { entry.Text = text; } script.Scripts.AddRange(entries); } } return(script); }