public static ExcelBindingDefinitionNamedRange CreateInstance(ExcelTemplateDefinitionPart templateDefinition, ExcelNamedRangeDefinition definition, IBindingDefinition nestedBindingDefinition) { try { string trimmedName = definition.Name.Trim(); IBindingDefinition nameBindingDefinition = null; string rootName = null; int pos = trimmedName.IndexOf('{'); if (pos != -1) { rootName = trimmedName.Remove(pos); string expression = trimmedName.Substring(pos); BindingDefinitionDescription bindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition.Parent, expression, expression); if (bindingDefinitionDescription != null && !string.IsNullOrEmpty(bindingDefinitionDescription.BindingExpression)) { if (bindingDefinitionDescription.BindingExpression.Contains(ALL_POS_KEYWORD) || bindingDefinitionDescription.BindingExpression.Contains(POS_KEYWORD)) { throw new ArgumentException($"Cannot mixte the keywords '{POS_KEYWORD}' and '{ALL_POS_KEYWORD}' with binding dataAccessor"); } nameBindingDefinition = BindingDefinitionFactory.CreateInstances(templateDefinition.Parent as ExcelTemplateDefinition, bindingDefinitionDescription); } } return(new ExcelBindingDefinitionNamedRange(definition, rootName, nestedBindingDefinition, nameBindingDefinition)); } catch (Exception ex) { string message = $"Cannot create create the named caller binding dataAccessor '{definition.Name}'. {ex.Message}"; throw new EtkException(message); } }
/// <summary>Create a binding definition from a cell value</summary> private IBindingDefinition CreateBindingDefinition(ExcelTemplateDefinitionPart templateDefinitionPart, string value, string trimmedValue) { ExcelTemplateDefinition excelTemplateDefinition = templateDefinitionPart.Parent as ExcelTemplateDefinition; IBindingDefinition ret = null; if (trimmedValue.StartsWith(ExcelBindingDefinitionButton.BUTTON_TEMPLATE_PREFIX)) { ret = ExcelBindingDefinitionButton.CreateInstance(excelTemplateDefinition, trimmedValue); } else if (trimmedValue.StartsWith(ExcelBindingDefinitionCheckBox.CHECKBOX_TEMPLATE_PREFIX)) { ret = ExcelBindingDefinitionCheckBox.CreateInstance(excelTemplateDefinition, trimmedValue); } else if (trimmedValue.StartsWith(ExcelBindingDefinitionFormulaResult.FORMULA_RESULT_PREFIX)) { ret = ExcelBindingDefinitionFormulaResult.CreateInstance(excelTemplateDefinition, trimmedValue); } else if (trimmedValue.StartsWith(ExcelBindingDefinitionNamedRange.NAMEDRANGE_TEMPLATE_PREFIX)) { ExcelNamedRangeDefinition excelNamedRangeDefinition = ExcelBindingDefinitionNamedRange.RetrieveNamedRangeDefinition(trimmedValue); if (excelNamedRangeDefinition != null) { BindingDefinition nestedBindingDefinition = null; if (!string.IsNullOrEmpty(excelNamedRangeDefinition.Value)) { nestedBindingDefinition = CreateBindingDefinition(templateDefinitionPart, excelNamedRangeDefinition.Value, excelNamedRangeDefinition.Value.Trim()) as BindingDefinition; } ret = ExcelBindingDefinitionNamedRange.CreateInstance(templateDefinitionPart, excelNamedRangeDefinition, nestedBindingDefinition); } } else { BindingDefinitionDescription bindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinitionPart.Parent, value, trimmedValue); if (bindingDefinitionDescription.Formula != null) { ret = ExcelBindingDefinitionWithFormula.CreateInstance(excelTemplateDefinition, bindingDefinitionDescription); } else { ret = BindingDefinitionFactory.CreateInstances(excelTemplateDefinition, bindingDefinitionDescription); } } return(ret); }
public static ExcelBindingDefinitionFormulaResult CreateInstance(ExcelTemplateDefinition templateDefinition, string definition) { try { definition = definition.Replace(FORMULA_RESULT_PREFIX, string.Empty); definition = definition.TrimEnd('}'); //UseFormulaBindingDefinition string[] parts = definition.Split(';'); if (parts.Count() > 2) { throw new ArgumentException($"dataAccessor '{definition}' is invalid."); } string useFormulaDefinition = null; string underlyingDefinition; if (parts.Count() == 1) { underlyingDefinition = $"{{{parts[0].Trim()}}}"; } else { useFormulaDefinition = $"{{{parts[0].Trim()}}}"; underlyingDefinition = $"{{{parts[1].Trim()}}}"; } BindingDefinitionDescription bindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, underlyingDefinition, underlyingDefinition); IBindingDefinition underlyingBindingDefinition = BindingDefinitionFactory.CreateInstances(templateDefinition, bindingDefinitionDescription); IBindingDefinition useFormulaBindingDefinition = null; if (!string.IsNullOrEmpty(useFormulaDefinition)) { bindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, useFormulaDefinition, useFormulaDefinition); useFormulaBindingDefinition = BindingDefinitionFactory.CreateInstances(templateDefinition, bindingDefinitionDescription); } ExcelBindingDefinitionFormulaResult ret = new ExcelBindingDefinitionFormulaResult(bindingDefinitionDescription, underlyingBindingDefinition, useFormulaBindingDefinition); return(ret); } catch (Exception ex) { string message = $"Cannot retrieve the formula result binding dataAccessor '{definition.EmptyIfNull()}'. {ex.Message}"; throw new EtkException(message); } }
public static ExcelBindingDefinitionButton CreateInstance(ExcelTemplateDefinition templateDefinition, string definition) { ExcelBindingDefinitionButton ret = null; if (!string.IsNullOrEmpty(definition)) { try { ExcelButtonDefinition excelButtonDefinition = definition.Deserialize <ExcelButtonDefinition>(); BindingDefinitionDescription definitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, excelButtonDefinition.Label, excelButtonDefinition.Label); ret = new ExcelBindingDefinitionButton(definitionDescription, templateDefinition, excelButtonDefinition); } catch (Exception ex) { string message = $"Cannot retrieve the button dataAccessor '{definition.EmptyIfNull()}'. {ex.Message}"; throw new EtkException(message); } } return(ret); }
public static ExcelBindingDefinitionWithFormula CreateInstance(ExcelTemplateDefinition templateDefinition, BindingDefinitionDescription definition) { try { IBindingDefinition formulaBindingDefinition = null; IBindingDefinition targetBindingDefinition = null; if (!string.IsNullOrEmpty(definition.Formula)) { BindingDefinitionDescription formulaBindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, definition.Formula, definition.Formula); formulaBindingDefinition = BindingDefinitionFactory.CreateInstances(templateDefinition, formulaBindingDefinitionDescription); } if (!string.IsNullOrEmpty(definition.BindingExpression)) { string bindingExpression = $"{{{definition.BindingExpression}}}"; BindingDefinitionDescription targetBindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, bindingExpression, bindingExpression); targetBindingDefinition = BindingDefinitionFactory.CreateInstances(templateDefinition, targetBindingDefinitionDescription); } ExcelBindingDefinitionWithFormula ret = new ExcelBindingDefinitionWithFormula(definition, targetBindingDefinition, formulaBindingDefinition); return(ret); } catch (Exception ex) { string message = $"Cannot create the 'ExcelBindingDefinitionWithFormula' from '{definition.BindingExpression ?? string.Empty}'. {ex.Message}"; throw new EtkException(message); } }