/// <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 static async Task <PropertyListSetup> ReadPropertyListSetupAsync(Package package, Type model, string file) { using (ICacheDataProvider cacheDP = YetaWF.Core.IO.Caching.GetStaticSmallObjectCacheProvider()) { // Check cache first GetObjectInfo <PropertyListSetup> info = await cacheDP.GetAsync <PropertyListSetup>(file); if (info.Success) { return(info.Data); } // Load the file if (YetaWFManager.DiagnosticsMode) // to avoid exception spam { if (!await FileSystem.FileSystemProvider.FileExistsAsync(file)) { PropertyListSetup setup = new PropertyListSetup { ExplicitDefinitions = false, }; await cacheDP.AddAsync <PropertyListSetup>(file, setup);// failure also saved in cache return(setup); } } string text; try { text = await FileSystem.FileSystemProvider.ReadAllTextAsync(file); } catch (Exception) { PropertyListSetup setup = new PropertyListSetup { ExplicitDefinitions = false, }; await cacheDP.AddAsync <PropertyListSetup>(file, setup);// failure also saved in cache return(setup); } { PropertyListSetup setup = Utility.JsonDeserialize <PropertyListSetup>(text); setup.ExplicitDefinitions = true; // save in cache await cacheDP.AddAsync <PropertyListSetup>(file, setup); return(setup); } } }