protected EventCallback RetrieveMethodInfo(ITemplateDefinition templateDefinition, string option, string callbackName) { try { return(EventCallbacksManager.RetrieveCallback(templateDefinition, callbackName)); } catch (Exception ex) { throw new Exception($"Property option '{option}'. {ex.Message}"); } }
private void RetrieveSelectionChangeMethod() { string selectionChanged = TemplateOption.SelectionChanged.EmptyIfNull(); selectionChanged = selectionChanged.Trim(); if (!string.IsNullOrEmpty(selectionChanged)) { try { SelectionChanged = EventCallbacksManager.RetrieveCallback(this, selectionChanged); } catch (Exception ex) { throw new EtkException($"Retrieve 'SelectionChanged' method information failed:{ex.Message}"); } } }
private void RetrieveOnClickMethod() { if (!string.IsNullOrEmpty(Definition.Command)) { try { string onCommand = Definition.Command.Trim(); Command = EventCallbacksManager.RetrieveCallback(TemplateDefinition, onCommand); if (!Command.IsNotDotNet) { ParameterInfo[] parameters = Command.Callback.GetParameters(); if (Command.Callback.IsStatic) { if (parameters.Count() > 2) { throw new EtkException($"Method dataAccessor must be 'void static {Command.Callback.Name}(object currentObject [, Range <currentObject caller>]'"); } OnClickWithRange = parameters.Count() == 2; } else { if (parameters.Count() > 1 || (parameters.Count() == 1 && parameters[0].ParameterType != typeof(Microsoft.Office.Interop.Excel.Range))) { throw new EtkException($"Method dataAccessor must be 'void {Command.Callback.Name}([Range <currentObject caller>])'"); } OnClickWithRange = parameters.Count() == 1; } } } catch (Exception ex) { throw new EtkException($"Get 'Command' methodInfo information failed:{ex.Message}"); } } }
private BindingDefinitionDescription(ITemplateDefinition templateDefinition, string bindingExpression, bool isConst, List <string> options) { BindingExpression = bindingExpression; IsConst = isConst; if (options != null) { IsReadOnly = options.Contains("R"); options.Remove("R"); if (options.Count > 0) { foreach (string option in options) { // Formula if (option.StartsWith("F=")) { Formula = option.Substring(2); continue; } // Description if (option.StartsWith("D=")) { Description = option.Substring(2); continue; } // Name if (option.StartsWith("N=")) { Name = option.Substring(2); continue; } // Decorator if (option.StartsWith("DEC=")) { string decoratorIdent = option.Substring(4); Decorator = DecoratorsManager.GetDecorator(decoratorIdent); continue; } // Decorator 2 if (option.StartsWith("DEC2=")) { string decoratorDescription = option.Substring(5); Decorator = DecoratorsManager.CreateSimpleDecorator(templateDefinition, decoratorDescription); continue; } // On Selection if (option.StartsWith("S=")) { string methodInfoName = option.Substring(2); OnSelection = RetrieveMethodInfo(templateDefinition, option, methodInfoName); continue; } // On double left click if (option.StartsWith("LDC=")) { string methodInfoName = option.Substring(4); OnLeftDoubleClick = RetrieveMethodInfo(templateDefinition, option, methodInfoName); continue; } // MultiLine based on the number of line passed as parameter if (option.StartsWith("M=")) { IsMultiLine = true; string factor = option.Substring(2); double multiLineFactor; if (!string.IsNullOrEmpty(factor) && double.TryParse(factor, out multiLineFactor)) { MultiLineFactor = multiLineFactor; } else { MultiLineFactor = 1.5; } continue; } // MultiLine where the number of line is determinated by a callback invocation if (option.StartsWith("ME=")) { string methodInfoName = option.Substring(3); if (!string.IsNullOrEmpty(methodInfoName)) { try { MultiLineFactorResolver = RetrieveMethodInfo(templateDefinition, null, methodInfoName); if (MultiLineFactorResolver != null) { if (!MultiLineFactorResolver.IsNotDotNet) { int parametersCpt = MultiLineFactorResolver.Callback.GetParameters().Length; if (MultiLineFactorResolver.Callback.ReturnType != typeof(int) || parametersCpt > 1 || (parametersCpt == 1 && !(MultiLineFactorResolver.Callback.GetParameters()[0].ParameterType.IsAssignableFrom(typeof(object))))) { throw new Exception("The function prototype must be defined as 'int <Function Name>([param]) with 'param' inheriting from 'system.object'"); } } IsMultiLine = true; } } catch (Exception ex) { throw new Exception($"Cannot resolve the 'ME' attribute for the binding definition '{bindingExpression}'", ex); } } } // On double left click, Show/Hide the x following/preceding colums/rows. Start hidden if (option.StartsWith("SH_COL_S=")) { string numberOfConcernedColumns = option.Substring(9); int wrk; if (!string.IsNullOrEmpty(numberOfConcernedColumns) && int.TryParse(numberOfConcernedColumns, out wrk)) { SpecificEventCallback callback = EventCallbacksManager.GetRegisteredCallback("ETK_ShowHideColumns") as SpecificEventCallback; SpecificEventCallback callbackToUse = new SpecificEventCallback(callback); callbackToUse.Parameters = new[] { new SpecificEventCallbackParameter { IsSender = true }, new SpecificEventCallbackParameter { ParameterValue = wrk } }; OnLeftDoubleClick = callbackToUse; continue; } throw new Exception("The 'Show/Hide' prototype must be defined as 'SH_COL_S=<int>' where '<int>' is a integer"); } // On double left click, Show/Hide the x following/preceding colums/rows. Start shown if (option.StartsWith("SH_COL_H=")) { string numberOfConcernedColumns = option.Substring(9); int wrk; if (!string.IsNullOrEmpty(numberOfConcernedColumns) && int.TryParse(numberOfConcernedColumns, out wrk)) { SpecificEventCallback callback = EventCallbacksManager.GetRegisteredCallback("ETK_ShowHideColumns") as SpecificEventCallback; SpecificEventCallback callbackToUse = new SpecificEventCallback(callback); callbackToUse.Parameters = new[] { new SpecificEventCallbackParameter { IsSender = true }, new SpecificEventCallbackParameter { ParameterValue = wrk } }; OnLeftDoubleClick = callbackToUse; OnAfterRendering = callbackToUse; continue; } throw new Exception("The 'Show/Hide' columns prototype must be defined as 'SH_COL_H==<int>' where '<int>' is a integer"); } } } } }