123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- using Comal.Classes;
- using InABox.Clients;
- using InABox.Core;
- using InABox.WPF;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace PRSDesktop
- {
- public static class CustomModuleUtils
- {
- public static List<CustomModule> LoadCustomModules(string section, DataModel model)
- {
- return new Client<CustomModule>()
- .Query(
- new Filter<CustomModule>(x => x.Section).IsEqualTo(section)
- .And(x => x.DataModel).IsEqualTo(model.Name)
- .And(x => x.Visible).IsEqualTo(true),
- null,
- new SortOrder<CustomModule>(x => x.Name))
- .ToObjects<CustomModule>().ToList();
- }
- public static IEnumerable<Tuple<CustomModule, Bitmap>> LoadCustomModuleThumbnails(IList<CustomModule> modules)
- {
- var thumbids = modules.Where(x => x.Thumbnail.IsValid()).Select(x => x.Thumbnail.ID);
- var thumbs = thumbids.Any()
- ? new Client<Document>().Load(Filter<Document>.List(x => x.ID, ListOperator.Includes, thumbids))
- : Array.Empty<Document>();
- var list = new List<Tuple<CustomModule, Bitmap>>();
- foreach (var module in modules)
- {
- Bitmap image;
- try
- {
- var doc = thumbs.FirstOrDefault(x => x.ID.Equals(module.Thumbnail.ID));
- if (doc != null)
- {
- var bmp = (new ImageConverter().ConvertFrom(doc.Data) as Bitmap)!;
- image = bmp;
- }
- else
- {
- image = PRSDesktop.Resources.edit;
- }
- }
- catch
- {
- image = PRSDesktop.Resources.edit;
- }
- yield return new(module, image);
- }
- }
- public static IEnumerable<Tuple<CustomModule, Bitmap>> LoadCustomModuleThumbnails(string section, DataModel model)
- {
- return LoadCustomModuleThumbnails(LoadCustomModules(section, model));
- }
- }
- }
|