private void UpdateSelectionOfTemplate() { Parameters.Clear(); ArrayParameters.Clear(); ShowIterationParameters = false; SelectedTemplate = Templates.FirstOrDefault(t => t.IsSelected); if (SelectedTemplate == null) { return; } foreach (var selectedTemplate in Templates.Where(t => t.IsSelected)) { if (selectedTemplate.IsScriptTemplate) { foreach (var parameter in selectedTemplate.Parameters) { if (parameter.AllowedValues?.Length > 0) { parameter.Value = parameter.AllowedValues[0]; } if (!Parameters.Any(p => p.Name == parameter.Name)) { Parameters.Add(parameter); } if (parameter.Type.Equals("iterations", StringComparison.OrdinalIgnoreCase)) { ShowIterationParameters = true; } } foreach (var parameter in selectedTemplate.ArrayParameters) { if (!ArrayParameters.Any(p => p.Name == parameter.Key)) { ArrayParameters.Add(new ParameterViewModel(parameter.Key, "", parameter.Value, null)); } } } } }
private void InnerExecuteExport() { var baseFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); foreach (var selectedTemplate in Templates.Where(t => t.IsSelected)) { if (selectedTemplate.IsScriptTemplate) { if (ArrayParameters.Any()) { var arrayParameters = ArrayParameters.Select(p => new { Name = p.Name, Values = p.Value?.Split(',', ';').ToList() ?? new List <string>() }) .ToList(); Int32 maxParameterCount = arrayParameters.Max(p => p.Values.Count); for (int i = 0; i < maxParameterCount; i++) { StringBuilder fileSuffix = new StringBuilder(); Dictionary <string, object> parameters = PrepareUserParameters(); foreach (var arrayParameter in arrayParameters) { var value = arrayParameter.Values.Count > i ? arrayParameter.Values[i] : String.Empty; parameters[arrayParameter.Name] = value; fileSuffix.Append(arrayParameter.Name); fileSuffix.Append("_"); fileSuffix.Append(value); } var fileName = Path.Combine(baseFolder, selectedTemplate.TemplateName + "_" + DateTime.Now.ToString("dd_MM_yyyy hh mm")) + "_" + fileSuffix.ToString(); GenerateFileFromScriptTemplate(fileName, selectedTemplate, parameters); } } else { var fileName = Path.Combine(baseFolder, selectedTemplate.TemplateName + "_" + DateTime.Now.ToString("dd_MM_yyyy hh mm")); Dictionary <string, object> parameters = PrepareUserParameters(); GenerateFileFromScriptTemplate(fileName, selectedTemplate, parameters); } } else { var fileName = Path.Combine(baseFolder, selectedTemplate.TemplateName + "_" + DateTime.Now.ToString("dd_MM_yyyy hh mm")) + ".docx"; var selected = SelectedQuery?.Results?.Where(q => q.Selected).ToList(); if (selected == null || selected.Count == 0) { return; } var template = selectedTemplate.WordTemplateFolderManager; using (WordManipulator manipulator = new WordManipulator(fileName, true)) { foreach (var workItemResult in selected) { var workItem = workItemResult.WorkItem; manipulator.InsertWorkItem(workItem, template.GetTemplateFor(workItem.Type.Name), true); } } ManageGeneratedWordFile(fileName); } } Status = $"Export Completed"; }
public int Count() => Parameters.Count() + ArrayParameters.Count();