Vereinsmeisterschaften  22aa7800eae54b428d40e835886cefe1fdefdfdf
This is a software that can be used to manage the internal competition of the swimming club Illertissen called "Vereinsmeisterschaften".
Loading...
Searching...
No Matches
DocumentStrategyBase.cs
5
7{
12 public abstract class DocumentStrategyBase<TData> : IDocumentStrategy
13 {
14 protected readonly IWorkspaceService _workspaceService;
15 protected readonly IServiceProvider _serviceProvider;
16
22 protected DocumentStrategyBase(IWorkspaceService workspaceService, IServiceProvider serviceProvider)
23 {
24 _workspaceService = workspaceService;
25 _serviceProvider = serviceProvider;
26
27 Type resolverType = typeof(IDocumentPlaceholderResolver<>).MakeGenericType(ItemType);
28 PlaceholderResolver = _serviceProvider.GetService(resolverType) as IDocumentPlaceholderResolver<TData>;
29 if (PlaceholderResolver is null) throw new InvalidOperationException($"No Resolver found for type {ItemType.Name}.");
30 }
31
33 public abstract DocumentCreationTypes DocumentType { get; }
34
36 public abstract string TemplatePath { get; }
37
39 public virtual string TemplateFileNamePostfixReplaceStr => string.Empty;
40
42 public abstract bool CreateMultiplePages { get; }
43
45 public abstract object[] GetItems();
46
51 public Type ItemType => typeof(TData);
52
55
58
62 public IDocumentPlaceholderResolver<TData> PlaceholderResolver { get; }
63
67 public List<string> AlwaysSupportedPlaceholderKeys => new List<string>
68 {
69 Placeholders.PLACEHOLDER_KEY_COMPETITION_YEAR,
70 Placeholders.PLACEHOLDER_KEY_COMPETITION_DATE,
71 Placeholders.PLACEHOLDER_KEY_APP_VERSION,
72 Placeholders.PLACEHOLDER_KEY_WORKSPACE_PATH
73 };
74
79 public List<string> SupportedPlaceholderKeys
80 {
81 get
82 {
83 List<string> supportedPlaceholderKeys = new List<string>(AlwaysSupportedPlaceholderKeys);
84 supportedPlaceholderKeys.AddRange(PlaceholderResolver.SupportedPlaceholderKeys);
85 return supportedPlaceholderKeys;
86 }
87 }
88
89 public List<int> PostfixNumbersSupported
90 {
91 get
92 {
93 List<int> postfixNumbersResolver = PlaceholderResolver.PostfixNumbersSupported ?? Enumerable.Repeat(0, PlaceholderResolver?.SupportedPlaceholderKeys?.Count ?? 0).ToList();
94 postfixNumbersResolver.InsertRange(0, Enumerable.Repeat(0, AlwaysSupportedPlaceholderKeys.Count)); // Always supported placeholders don't support postfix numbers
95 return postfixNumbersResolver;
96 }
97 }
98
99 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
100
103 {
104 if (!SupportTextPlaceholders || item == null) { return null; }
105
106 return PlaceholderResolver.ResolveTextPlaceholders((TData)item);
107 }
108
111 {
112 if (!SupportTablePlaceholders || items == null) { return null; }
113
114 return PlaceholderResolver.ResolveTablePlaceholders(items.Cast<TData>());
115 }
116
117 // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
118
120 public virtual Enum ItemOrdering { get; set; } = null;
121
123 public virtual IEnumerable<Enum> AvailableItemOrderings { get; } = null;
124
126 public virtual IEnumerable<Enum> AvailableItemFilters { get; } = null;
127
129 public virtual Enum ItemFilter { get; set; } = null;
130
132 public virtual object ItemFilterParameter { get; set; } = null;
133 }
134}
object[] GetItems()
Retrieves the items that will be used to create the document.List with items
virtual bool SupportTablePlaceholders
Indicating if DocXPlaceholderHelper.TablePlaceholders are supported.If CreateMultiplePages is false,...
DocumentCreationTypes DocumentType
Gets the type of document this strategy creates.
virtual string TemplateFileNamePostfixReplaceStr
Use this string instead of the template file name postfix during document creation....
List< string > SupportedPlaceholderKeys
List of all placeholder keys that are supported by the PlaceholderResolver.
string TemplatePath
Gets the path to the template used for creating the document.
virtual bool SupportTextPlaceholders
Indicating if DocXPlaceholderHelper.TextPlaceholders are supported.If CreateMultiplePages is true,...
virtual IEnumerable< Enum > AvailableItemFilters
Array with all available filters for the items.If no filtering is supported, this will be null.
DocumentStrategyBase(IWorkspaceService workspaceService, IServiceProvider serviceProvider)
Constructor for the document strategy base class.
DocXPlaceholderHelper.TablePlaceholders ResolveTablePlaceholders(object[] items)
Resolve table placeholders for the given items.DocXPlaceholderHelper.TablePlaceholders
bool CreateMultiplePages
Gets a value indicating whether this strategy supports creating multiple pages in the document....
DocXPlaceholderHelper.TextPlaceholders ResolveTextPlaceholders(object item=null)
Resolve text placeholders for the given item.DocXPlaceholderHelper.TextPlaceholders
Type ItemType
Gets the type of items that this strategy will handle.
virtual Enum ItemFilter
Current filter for the items.If no filtering is supported, this will be null.
List< string > AlwaysSupportedPlaceholderKeys
List with placeholder keys that are always supported, no matter what the PlaceholderResolver supports...
IDocumentPlaceholderResolver< TData > PlaceholderResolver
Placeholder resolver used to resolve placeholders in the document.
virtual Enum ItemOrdering
Current ordering for the items.If no ordering is supported, this will be null.
List< int > PostfixNumbersSupported
Number of postfix numbers that are supported for the placeholders.If this is e.g. 2,...
virtual object ItemFilterParameter
Filter parameter that can be used together with ItemFiltering.The type and usage of this parameter de...
virtual IEnumerable< Enum > AvailableItemOrderings
Array with all available orderings for the items.If no ordering is supported, this will be null.
Class to hold table placeholders and their list of values.
Interface for a service used to manage a workspace.
Interface for document strategies that define how to create and collect data for different types of d...
DocumentCreationTypes
Different types of documents that can be created.