32 public Dictionary<DocumentCreationTypes, DocumentCreationConfig>
DocumentCreationConfigPerType {
get; } =
new Dictionary<DocumentCreationTypes, DocumentCreationConfig>();
37 public Dictionary<DocumentCreationTypes, DocumentCreationStatus>
DocumentCreationStatusPerType {
get; } =
new Dictionary<DocumentCreationTypes, DocumentCreationStatus>();
49 private void changeDocumentCreationSuccessfulState(
DocumentCreationTypes documentType,
bool isSuccessful)
50 => setDictionaryValue(documentType, isSuccessful, nameof(
DocumentCreationStatus.IsDocumentCreationSuccessful));
52 private void changeDocumentDataAvailableState(
DocumentCreationTypes documentType,
bool isDataAvailable)
53 => setDictionaryValue(documentType, isDataAvailable, nameof(
DocumentCreationStatus.IsDocumentDataAvailable));
55 private void changeDocumentTemplateAvailableState(
DocumentCreationTypes documentType,
bool isTemplateAvailable)
56 => setDictionaryValue(documentType, isTemplateAvailable, nameof(
DocumentCreationStatus.IsDocumentTemplateAvailable));
58 private void changeLastDocumentFilePath(
DocumentCreationTypes documentType,
string lastDocumentFilePath)
59 => setDictionaryValue(documentType, lastDocumentFilePath, nameof(
DocumentCreationStatus.LastDocumentFilePath));
74 #region Create Certificates Properties
88 public List<Person>
AvailablePersons => _personService?.GetPersons().OrderBy(p => p.Name).ToList();
102 #region Create Time Forms Properties
116 private ObservableCollection<DocumentPlaceholderViewConfig> _placeholderViewConfigs =
new ObservableCollection<DocumentPlaceholderViewConfig>();
122 get => _placeholderViewConfigs;
123 private set => SetProperty(ref _placeholderViewConfigs, value);
137 foreach(KeyValuePair<
string, (
string groupName, List<string> placeholders)> placeholderEntry in Placeholders.PlaceholderDict)
139 string placeholderKey = placeholderEntry.Key;
141 string resourceStringName = rm.GetString($
"PlaceholderName{placeholderKey}") ??
"?";
142 string resourceStringInfo = rm.GetString($
"PlaceholderInfo{placeholderKey}") ??
"?";
143 string resourceStringGroup = rm.GetString($
"PlaceholderGroup{placeholderEntry.Value.groupName}") ??
"?";
145 Dictionary<DocumentCreationTypes, bool> isSupportedForDocumentType =
new Dictionary<DocumentCreationTypes, bool>();
146 Dictionary<DocumentCreationTypes, bool> isSupportedForTextPlaceholders =
new Dictionary<DocumentCreationTypes, bool>();
147 Dictionary<DocumentCreationTypes, bool> isSupportedForTablePlaceholders =
new Dictionary<DocumentCreationTypes, bool>();
148 Dictionary<DocumentCreationTypes, string> postfixNumbersSupportedForDocumentType =
new Dictionary<DocumentCreationTypes, string>();
153 bool isCurrentPlaceholderSupportedForStrategy = supportedPlaceholderKeys.Contains(placeholderKey);
155 bool isCurrentPlaceholderSupportedForTable = strategy.SupportTablePlaceholders || strategy.
AlwaysSupportedPlaceholderKeys.Contains(placeholderKey);
157 int indexOfKey = supportedPlaceholderKeys.IndexOf(placeholderKey);
159 string postfixNumbersSupportedStr = postfixNumbersSupported > 0 ? postfixNumbersSupported.ToString() :
string.Empty;
161 if (!isSupportedForDocumentType.ContainsKey(documentCreationType))
163 isSupportedForDocumentType.Add(documentCreationType, isCurrentPlaceholderSupportedForStrategy);
164 isSupportedForTextPlaceholders.Add(documentCreationType, isCurrentPlaceholderSupportedForText);
165 isSupportedForTablePlaceholders.Add(documentCreationType, isCurrentPlaceholderSupportedForTable);
166 postfixNumbersSupportedForDocumentType.Add(documentCreationType, postfixNumbersSupportedStr);
170 isSupportedForDocumentType[documentCreationType] = isCurrentPlaceholderSupportedForStrategy;
171 isSupportedForTextPlaceholders[documentCreationType] = isCurrentPlaceholderSupportedForText;
172 isSupportedForTablePlaceholders[documentCreationType] = isCurrentPlaceholderSupportedForTable;
173 postfixNumbersSupportedForDocumentType[documentCreationType] = postfixNumbersSupportedStr;
179 Group = resourceStringGroup,
180 Key = placeholderKey,
181 Name = resourceStringName,
182 Info = resourceStringInfo,
183 Placeholders =
string.Join(Environment.NewLine, placeholderEntry.Value.placeholders.Select(p => $
"{_documentService.PlaceholderMarker}{p}{_documentService.PlaceholderMarker}")),
184 IsSupportedForDocumentType = isSupportedForDocumentType,
185 IsSupportedForTextPlaceholders = isSupportedForTextPlaceholders,
186 IsSupportedForTablePlaceholders = isSupportedForTablePlaceholders,
187 PostfixNumbersSupportedForDocumentType = postfixNumbersSupportedForDocumentType
201 private IDialogCoordinator _dialogCoordinator;
203 private IEnumerable<IDocumentStrategy> _documentStrategies;
216 _documentService = documentService;
217 _personService = personService;
218 _workspaceService = workspaceService;
219 _dialogCoordinator = dialogCoordinator;
221 _documentStrategies = documentStrategies;
228 IDocumentStrategy strategy = _documentStrategies.FirstOrDefault(d => d.DocumentType == type);
233 DocumentStrategy = strategy,
248 private ICommand _createDocumentCommand;
252 public ICommand
CreateDocumentCommand => _createDocumentCommand ?? (_createDocumentCommand =
new RelayCommand<DocumentCreationTypes>(async (documentType) =>
254 int numCreatedPages = 0;
255 string returnFilePath =
string.Empty;
261 IDocumentStrategy strategy = _documentStrategies.FirstOrDefault(s => s.DocumentType == type);
262 if (strategy !=
null)
270 changeDocumentCreationRunningState(documentType,
true);
273 changeDocumentCreationSuccessfulState(documentType,
false);
274 switch (documentType)
278 (numCreatedPages, returnFilePath) = await _documentService.CreateDocument(
DocumentCreationTypes.Certificates);
279 NumberCreatedCertificates = numCreatedPages;
284 (numCreatedPages, returnFilePath) = await _documentService.CreateDocument(
DocumentCreationTypes.OverviewList);
289 (numCreatedPages, returnFilePath) = await _documentService.CreateDocument(
DocumentCreationTypes.RaceStartList);
294 (numCreatedPages, returnFilePath) = await _documentService.CreateDocument(
DocumentCreationTypes.TimeForms);
295 NumberCreatedTimeForms = numCreatedPages;
300 (numCreatedPages, returnFilePath) = await _documentService.CreateDocument(
DocumentCreationTypes.ResultList);
305 (numCreatedPages, returnFilePath) = await _documentService.CreateDocument(
DocumentCreationTypes.ResultListDetail);
310 (numCreatedPages, returnFilePath) = await _documentService.CreateDocument(
DocumentCreationTypes.Analytics);
313 default:
throw new ArgumentOutOfRangeException(nameof(documentType), documentType,
"Unknown document type for creation command.");
315 changeLastDocumentFilePath(documentType, returnFilePath);
316 changeDocumentCreationSuccessfulState(documentType,
true);
322 changeDocumentCreationRunningState(documentType,
false);
331 object[] items = strategy.
GetItems();
332 bool isDataAvailable = items !=
null;
333 changeDocumentDataAvailableState(strategy.
DocumentType, isDataAvailable);
335 bool isTemplateAvailable = !
string.IsNullOrEmpty(strategy.
TemplatePath) &&
338 changeDocumentTemplateAvailableState(strategy.
DocumentType, isTemplateAvailable);
340 if (!isDataAvailable || !isTemplateAvailable)
342 changeDocumentCreationRunningState(strategy.
DocumentType,
false);
343 changeDocumentCreationSuccessfulState(strategy.
DocumentType,
false);
347 string templateFileNamePostfix = _workspaceService?.Settings?.GetSettingValue<
string>(
WorkspaceSettings.GROUP_DOCUMENT_CREATION,
WorkspaceSettings.SETTING_DOCUMENT_CREATION_TEMPLATE_FILENAME_POSTFIX) ??
string.Empty;
348 string documentOutputFolder = _workspaceService?.Settings?.GetSettingValue<
string>(
WorkspaceSettings.GROUP_DOCUMENT_CREATION,
WorkspaceSettings.SETTING_DOCUMENT_CREATION_OUTPUT_FOLDER) ??
string.Empty;
349 documentOutputFolder = FilePathHelper.MakePathAbsolute(documentOutputFolder, _workspaceService?.PersistentPath);
351 string outputFileNameDocx = Path.GetFileNameWithoutExtension(strategy.
TemplatePath);
352 outputFileNameDocx = outputFileNameDocx.Replace(templateFileNamePostfix,
"") +
".docx";
353 string outputFilePathDocx = Path.Combine(documentOutputFolder, outputFileNameDocx);
354 string outputFilePathPdf = outputFilePathDocx.Replace(
".docx",
".pdf", StringComparison.InvariantCultureIgnoreCase);
355 if(File.Exists(outputFilePathPdf))
357 changeLastDocumentFilePath(strategy.
DocumentType, outputFilePathPdf);
358 changeDocumentCreationSuccessfulState(strategy.
DocumentType,
true);
360 else if(File.Exists(outputFilePathDocx))
362 changeLastDocumentFilePath(strategy.
DocumentType, outputFilePathDocx);
363 changeDocumentCreationSuccessfulState(strategy.
DocumentType,
true);