private void Calculate(FunctionArgument arg, ref double retVal, ref double nValues) { if (ShouldIgnore(arg)) { return; } if (arg.Value is double) { nValues++; retVal += Convert.ToDouble(arg.Value); } else if (arg.Value is int) { nValues++; retVal += Convert.ToDouble((int)arg.Value); } else if (arg.Value is bool) { nValues++; retVal += (bool)arg.Value ? 1 : 0; } else if (arg.Value is IEnumerable <FunctionArgument> ) { foreach (var item in (IEnumerable <FunctionArgument>)arg.Value) { Calculate(item, ref retVal, ref nValues); } } }
public void FontFaceRule_ParseTest() { string text = "@font-face { font-family: Headline; src: local(Futura-Medium), url(fonts.svg#MyGeometricModern) format(\"svg\", 'opentype'); unicode-range: U+3000-9FFF, U+ff??; }"; ITextProvider tp = new StringTextProvider(text); TokenStream tokens = Helpers.MakeTokenStream(tp); FontFaceDirective ff = new FontFaceDirective(); Assert.IsTrue(ff.Parse(new ItemFactory(tp, null), tp, tokens)); Assert.IsTrue(tp.CompareTo(ff.Keyword.Start, "font-face", ignoreCase: false)); Assert.IsNotNull(ff.Block.OpenCurlyBrace); Assert.IsNotNull(ff.Block.CloseCurlyBrace); Assert.AreEqual(3, ff.RuleBlock.Declarations.Count); Assert.IsTrue(tp.CompareTo(ff.RuleBlock.Declarations[0].PropertyName.Start, "font-family", ignoreCase: false)); Assert.IsTrue(tp.CompareTo(ff.RuleBlock.Declarations[1].PropertyName.Start, "src", ignoreCase: false)); Assert.IsTrue(ff.RuleBlock.Declarations[1].Values[0] is FunctionLocal); Assert.IsTrue(ff.RuleBlock.Declarations[1].Values[2] is UrlItem); Assert.IsTrue(ff.RuleBlock.Declarations[1].Values[3] is FunctionFormat); FunctionFormat func = ff.RuleBlock.Declarations[1].Values[3] as FunctionFormat; FunctionArgument arg = func.Arguments[0] as FunctionArgument; Assert.AreEqual("\"svg\",", tp.GetText(arg.Start, arg.Length)); arg = func.Arguments[1] as FunctionArgument; Assert.AreEqual("'opentype'", tp.GetText(arg.Start, arg.Length)); Assert.IsTrue(tp.CompareTo(ff.RuleBlock.Declarations[2].PropertyName.Start, "unicode-range", ignoreCase: false)); }
internal Udf(Table table, FunctionArgument[] arguments) : this(null) { Build = (buildContext, buildArgs) => { if (arguments == null) { arguments = new FunctionArgument[] { Designer.Null }; } foreach (var argument in arguments) { if (!argument.IsNullReference() && argument.Original is View) { var arg = ((View)argument.Original).Parameterize(buildContext); argument.SetStringBuildMethod(arg); argument.SetArgType(arg); } } var sql = Text.GenerateSql(50) .Append(table.Build(buildContext, buildArgs)) .Append(Text.LeftBracket) .Append(FunctionArgument.Concatenate(arguments, buildContext, buildArgs)) .Append(Text.RightBracket) .ToString(); TryThrow(buildContext); return(sql); }; }
private void createNewConstructors() { NameReference type_name = this.Name.CreateNameReference(null, this.InstanceOf, isLocal: true); if (!this.NestedFunctions.Any(it => it.IsNewConstructor())) { foreach (FunctionDefinition init_cons in this.NestedFunctions.Where(it => it.IsInitConstructor()).StoreReadOnly()) { //if (this.NestedFunctions.Any(it => it.IsNewConstructor() // && it.Name.Arity == init_cons.Name.Arity && it.NOT_USED_CounterpartParameters(init_cons))) //continue; const string local_this = "__this__"; var new_cons = FunctionDefinition.CreateHeapConstructor(init_cons.Modifier, init_cons.Parameters, type_name, Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement(local_this, null, Alloc.Create(type_name, useHeap: true)), FunctionCall.Create(NameReference.Create(NameReference.Create(local_this), NameFactory.InitConstructorName), init_cons.Parameters.Select(it => FunctionArgument.Create(it.Name.CreateNameReference())).ToArray()), Return.Create(NameReference.Create(local_this)) })); this.AddNode(new_cons); } } }
protected void BuildFunctionArguments(CompileResult compileResult, DataType dataType, List <FunctionArgument> args) { if (compileResult.Result is IEnumerable <object> && !(compileResult.Result is ExcelDataProvider.IRangeInfo)) { var compileResultFactory = new CompileResultFactory(); var argList = new List <FunctionArgument>(); var objects = compileResult.Result as IEnumerable <object>; foreach (var arg in objects) { var cr = compileResultFactory.Create(arg); BuildFunctionArguments(cr, dataType, argList); } args.Add(new FunctionArgument(argList)); } else { var funcArg = new FunctionArgument(compileResult.Result, dataType); funcArg.ExcelAddressReferenceId = compileResult.ExcelAddressReferenceId; if (compileResult.IsHiddenCell) { funcArg.SetExcelStateFlag(Excel.ExcelCellState.HiddenCell); } args.Add(funcArg); } }
public object Next(FunctionArgument _args, EvalContext cal) { StringBuilder sb = new StringBuilder(); char? c = null; while (!sr.EndOfStream) { c = (char)sr.Read(); if (!char.IsWhiteSpace(c.Value)) { break; } } if (c.HasValue == false) { return((StringValue)(sb.ToString())); } sb.Append(c.Value); while (!sr.EndOfStream) { c = (char)sr.Read(); if (char.IsWhiteSpace(c.Value)) { break; } sb.Append(c); } return((StringValue)sb.ToString()); }
public IErrorReporter ErrorIgnoringFunctionResult() { NameResolver resolver = null; foreach (var mutability in Options.AllMutabilityModes) { var env = Environment.Create(new Options() { GlobalVariables = true, RelaxedMode = true }.SetMutability(mutability)); var root_ns = env.Root; var func_def = root_ns.AddBuilder(FunctionBuilder.Create( "foo", ExpressionReadMode.ReadRequired, NameFactory.RealNameReference(), Block.CreateStatement(new[] { Return.Create(RealLiteral.Create("3.3")) })) .Parameters(FunctionParameter.Create("x", NameFactory.Int64NameReference(), usageMode: ExpressionReadMode.CannotBeRead))); root_ns.AddNode(VariableDeclaration.CreateStatement("i", NameFactory.Int64NameReference(), Undef.Create())); var call = FunctionCall.Create(NameReference.Create("foo"), FunctionArgument.Create(NameReference.Create("i"))); root_ns.AddNode(Block.CreateStatement(new[] { call })); resolver = NameResolver.Create(env); Assert.AreEqual(1, resolver.ErrorManager.Errors.Count); Assert.IsTrue(resolver.ErrorManager.HasError(ErrorCode.ExpressionValueNotUsed, call)); } return(resolver); }
public override CompileResult Compile(IEnumerable <Expression> children, ParsingContext context) { var args = new List <FunctionArgument>(); base.Function.BeforeInvoke(context); foreach (var child in children) { if (base.Function.ResolveArgumentsAsRange) { base.ConfigureExcelAddressExpressionToResolveAsRange(child.Children); } var compileResult = child.Compile(); if (compileResult.IsResultOfSubtotal) { var arg = new FunctionArgument(compileResult.Result); arg.SetExcelStateFlag(ExcelCellState.IsResultOfSubtotal); args.Add(arg); } else { base.BuildFunctionArguments(compileResult.Result, compileResult.DataType, args); } } return(base.Function.Execute(args, context)); }
public async Task <IActionResult> PutFunctionArgument(int id, FunctionArgument functionArgument) { if (id != functionArgument.Id) { return(BadRequest()); } _context.Entry(functionArgument).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!FunctionArgumentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <FunctionArgument> > PostFunctionArgument(FunctionArgument functionArgument) { _context.FunctionArguments.Add(functionArgument); await _context.SaveChangesAsync(); return(CreatedAtAction("GetFunctionArgument", new { id = functionArgument.Id }, functionArgument)); }
private void setFunctionArguments(int variablesCount) { for (int i = 0; i < variablesCount; i++) { arguments[i] = new FunctionArgument("x" + (i + 1).ToString() + " = "); } }
private double Calculate(FunctionArgument arg) { var retVal = 0d; if (ShouldIgnore(arg)) { return(retVal); } if (arg.Value is double || arg.Value is int) { retVal += Convert.ToDouble(arg.Value); } else if (arg.Value is System.DateTime) { retVal += Convert.ToDateTime(arg.Value).ToOADate(); } else if (arg.Value is IEnumerable <FunctionArgument> ) { foreach (var item in (IEnumerable <FunctionArgument>)arg.Value) { retVal += Calculate(item); } } return(retVal); }
// replace string argument(s) with Value object (string treated as values) internal static void PrepareFunctionArguments(FunctionArgument[] arguments, DbNode node) { if (node.Map.Params.Count > 0) { if (arguments.IsEmpty()) { node.Mapper.Throw(QueryTalkExceptionType.MissingFunctionArguments, null, Text.NotAvailable); } } else { return; } for (int i = 0; i < arguments.Length; ++i) { var arg = arguments[i]; if (!arg.IsNullReference() && arg.Original is System.String) { if (Variable.Detect(arg.Original)) { continue; } arguments[i] = new FunctionArgument(((string)arguments[i].Original).V()); } } }
public WorkdayCalculatorResult AdjustResultWithHolidays(WorkdayCalculatorResult calculatedResult, FunctionArgument holidayArgument) { var startDate = calculatedResult.StartDate; var endDate = calculatedResult.EndDate; var direction = calculatedResult.Direction; var workdaysCounted = calculatedResult.NumberOfWorkdays; var additionalDays = new AdditionalHolidayDays(holidayArgument); foreach (var date in additionalDays.AdditionalDates) { if (direction == WorkdayCalculationDirection.Forward && (date < startDate || date > endDate)) { continue; } if (direction == WorkdayCalculationDirection.Backward && (date > startDate || date < endDate)) { continue; } if (_holidayWeekdays.IsHolidayWeekday(date)) { continue; } var tmpDate = _holidayWeekdays.GetNextWorkday(endDate, direction); while (additionalDays.AdditionalDates.Contains(tmpDate)) { tmpDate = _holidayWeekdays.GetNextWorkday(tmpDate, direction); } workdaysCounted++; endDate = tmpDate; } return(new WorkdayCalculatorResult(workdaysCounted, calculatedResult.StartDate, endDate, direction)); }
public List <double> CreateSet(FunctionArgument arg) { List <double> result = new List <double>(); if (arg.IsExcelRange) { var r1 = arg.ValueAsRangeInfo; for (var x = 0; x < r1.Count(); x++) { var v = r1.ElementAt(x).Value; if (!IsNumeric(v)) { result.Add(double.NaN); } else { result.Add(ConvertUtil.GetValueDouble(v)); } } } else { result = ArgsToDoubleEnumerable(new List <FunctionArgument> { arg }, _context).Select(x => Convert.ToDouble(x)).ToList(); } return(result); }
private void CreateSets(FunctionArgument arg1, FunctionArgument arg2, out double[] set1, out double[] set2) { var list1 = CreateSet(arg1); var list2 = CreateSet(arg2); if (list1.Count == list2.Count) { var r1 = new List <double>(); var r2 = new List <double>(); for (var x = 0; x < list1.Count; x++) { if (!double.IsNaN(list1[x]) && !double.IsNaN(list2[x])) { r1.Add(list1[x]); r2.Add(list2[x]); } } set1 = r1.ToArray(); set2 = r2.ToArray(); } else { set1 = list1.ToArray(); set2 = list2.ToArray(); } }
public IInterpreter ChannelDeadLockOnSend() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { VariableDeclaration.CreateStatement("ch", null, ExpressionFactory.HeapConstructor(NameFactory.ChannelNameReference(NameFactory.Int64NameReference()))), ExpressionFactory.Readout(FunctionCall.Create(NameReference.Create("ch", NameFactory.ChannelSend), FunctionArgument.Create(Int64Literal.Create("2")))), Return.Create(Int64Literal.Create("0")) }))); int task_id = Task.WaitAny(Task.Delay(TimeSpan.FromSeconds(Interpreter.Interpreter.TimeoutSeconds)), interpreter.TestRunAsync(env)); Assert.AreEqual(0, task_id); } return(interpreter); }
public void AverageAWithArraysWorksAsExpected() { // For arrays, AverageA completely ignores booleans. It divides by strings and numbers, but only // numbers are added to the total. Real dates cannot be specified and string dates are not parsed. var date = new DateTime(2013, 1, 15); double[] expectedIndividualValues = { 0, 2000, 0, 0, 0 }; var function = new AverageA(); var argumentsInArray = new FunctionArgument[] { new FunctionArgument(1000.ToString("n")), new FunctionArgument(2000), new FunctionArgument(6000.ToString("n")), new FunctionArgument(true), new FunctionArgument(date.ToString("d")), new FunctionArgument("test") }; var argumentsInArrayInArray = new FunctionArgument[] { new FunctionArgument(argumentsInArray) }; var result = function.Execute(argumentsInArrayInArray, this.ParsingContext); Assert.AreEqual(expectedIndividualValues.Average(), result.Result); }
public IInterpreter RawMethods() { var interpreter = new Interpreter.Interpreter(); foreach (var mutability in Options.AllMutabilityModes) { var env = Language.Environment.Create(new Options() { AllowInvalidMainResult = true }.SetMutability(mutability)); var root_ns = env.Root; var main_func = root_ns.AddBuilder(FunctionBuilder.Create( "main", ExpressionReadMode.OptionalUse, NameFactory.Int64NameReference(), Block.CreateStatement(new IExpression[] { Return.Create(FunctionCall.Create(NameReference.Create(Int64Literal.Create("1"), NameFactory.AddOperator), FunctionArgument.Create(Int64Literal.Create("1")))) }))); ExecValue result = interpreter.TestRun(env); Assert.AreEqual(2L, result.RetValue.PlainValue); } return(interpreter); }
private void _CheckForAndHandleExcelError(FunctionArgument arg, ParsingContext context) { if (context.Scopes.Current.IsSubtotal) { CheckForAndHandleExcelError(arg); } }
public void Push(FunctionArgument _args, EvalContext cal) { OperationHelper.AssertArgsNumberThrowIf(this, 1, _args.Arguments); var v = cal.GetValue <IValue>(_args.Arguments[0]); stack.Enqueue(v); }
public void Function_ParseTest6() { // Unknown token and block in a function argument StyleSheet ss = Helpers.MakeStyleSheet("p { width: calc(100% * (attr(value) - attr(min)) / (attr(max) - attr(min))); }"); Function func = ss.RuleSets[0].Block.Declarations[0].Values[0] as Function; Assert.IsNotNull(func); Assert.IsInstanceOfType(func, typeof(FunctionCalc)); Assert.AreEqual(1, func.Arguments.Count); Assert.IsInstanceOfType(func.Arguments[0], typeof(FunctionArgument)); FunctionArgument arg = (FunctionArgument)func.Arguments[0]; Assert.AreEqual(5, arg.ArgumentItems.Count); Assert.IsInstanceOfType(arg.ArgumentItems[0], typeof(UnitValue)); Assert.IsInstanceOfType(arg.ArgumentItems[1], typeof(TokenItem)); Assert.IsInstanceOfType(arg.ArgumentItems[2], typeof(UnknownBlock)); Assert.IsInstanceOfType(arg.ArgumentItems[3], typeof(TokenItem)); Assert.IsInstanceOfType(arg.ArgumentItems[4], typeof(UnknownBlock)); Assert.AreEqual("100% * (attr(value) - attr(min)) / (attr(max) - attr(min))", arg.Text); }
public void ShouldSetExcelState() { var arg = new FunctionArgument(2); arg.SetExcelStateFlag(ExcelCellState.HiddenCell); Assert.IsTrue(arg.ExcelStateFlagIsSet(ExcelCellState.HiddenCell)); }
private void Calculate(FunctionArgument arg, ref double retVal, ref double nValues) { if (ShouldIgnore(arg)) { return; } if (arg.Value is double) { nValues++; retVal += Convert.ToDouble(arg.Value); } else if (arg.Value is int) { nValues++; retVal += Convert.ToDouble((int)arg.Value); } else if(arg.Value is bool) { nValues++; retVal += (bool)arg.Value ? 1 : 0; } else if (arg.Value is IEnumerable<FunctionArgument>) { foreach (var item in (IEnumerable<FunctionArgument>)arg.Value) { Calculate(item, ref retVal, ref nValues); } } }
private double Calculate(FunctionArgument arg, ParsingContext context) { var retVal = 0d; if (ShouldIgnore(arg)) { return retVal; } if (arg.Value is IEnumerable<FunctionArgument>) { foreach (var item in (IEnumerable<FunctionArgument>)arg.Value) { retVal += Calculate(item, context); } } else if (arg.Value is ExcelDataProvider.IRangeInfo) { foreach (var c in (ExcelDataProvider.IRangeInfo)arg.Value) { if (ShouldIgnore(c, context) == false) { CheckForAndHandleExcelError(c); retVal += c.ValueDouble; } } } else { CheckForAndHandleExcelError(arg); retVal += ConvertUtil.GetValueDouble(arg.Value, true); } return retVal; }
static void Execute(DoWhileFunctionValue main, FunctionArgument args, EvalContext cal) { var children = args.Contents; try { do { try { foreach (var v in children) { cal.Evaluate(v); } } catch (BContinue) { continue; } }while (cal.GetValue <bool>(cal.Evaluate(main.Condition))); } catch (BBreak) { return; } }
static void Execute(ForFunctionValue main, FunctionArgument args, EvalContext cal) { var children = args.Contents; try { for (cal.Evaluate(main.Begin); cal.GetValue <bool>(cal.Evaluate(main.Condition)); cal.Evaluate(main.Step)) { try { foreach (var v in children) { cal.Evaluate(v); } } catch (BContinue) { continue; } } } catch (BBreak) { return; } }
private double Calculate(FunctionArgument arg, string expression) { var retVal = 0d; if (ShouldIgnore(arg) || !_numericExpressionEvaluator.Evaluate(arg.Value, expression)) { return(retVal); } if (IsNumeric(arg.Value)) { retVal += ConvertUtil.GetValueDouble(arg.Value); } //else if (arg.Value is System.DateTime) //{ // retVal += Convert.ToDateTime(arg.Value).ToOADate(); //} else if (arg.Value is IEnumerable <FunctionArgument> ) { foreach (var item in (IEnumerable <FunctionArgument>)arg.Value) { retVal += Calculate(item, expression); } } return(retVal); }
private double Calculate(FunctionArgument arg, ParsingContext context) { var retVal = 0d; if (ShouldIgnore(arg)) { return(retVal); } if (arg.Value is IEnumerable <FunctionArgument> ) { foreach (var item in (IEnumerable <FunctionArgument>)arg.Value) { retVal += Calculate(item, context); } } else if (arg.Value is ExcelDataProvider.IRangeInfo) { foreach (var c in (ExcelDataProvider.IRangeInfo)arg.Value) { if (ShouldIgnore(c, context) == false) { CheckForAndHandleExcelError(c); retVal += c.ValueDouble; } } } else { CheckForAndHandleExcelError(arg); retVal += ConvertUtil.GetValueDouble(arg.Value, true); } return(retVal); }
private void Calculate(FunctionArgument arg, ParsingContext context, ref double retVal, ref double nValues, bool isInArray = false) { if (ShouldIgnore(arg)) { return; } if (arg.Value is IEnumerable <FunctionArgument> ) { foreach (var item in (IEnumerable <FunctionArgument>)arg.Value) { Calculate(item, context, ref retVal, ref nValues, true); } } else if (arg.IsExcelRange) { foreach (var c in arg.ValueAsRangeInfo) { if (ShouldIgnore(c, context)) { continue; } CheckForAndHandleExcelError(c); if (IsNumeric(c.Value) && !(c.Value is bool)) { nValues++; retVal += c.ValueDouble; } else if (c.Value is bool) { nValues++; retVal += (bool)c.Value ? 1 : 0; } else if (c.Value is string) { nValues++; } } } else { var numericValue = GetNumericValue(arg.Value, isInArray); if (numericValue.HasValue) { nValues++; retVal += numericValue.Value; } else if ((arg.Value is string)) { if (isInArray) { nValues++; } else { ThrowExcelErrorValueException(eErrorType.Value); } } } CheckForAndHandleExcelError(arg); }
public void FunctionRgb_ParseTest1() { ITextProvider tp = new StringTextProvider("rgb(25, 10%, 34)"); TokenStream tokens = Helpers.MakeTokenStream(tp); Function f = Function.ParseFunction(null, new ItemFactory(tp, null), tp, tokens); Assert.AreEqual(typeof(FunctionColor), f.GetType()); Assert.AreEqual(3, f.Arguments.Count); Assert.IsInstanceOfType(f.Arguments[0], typeof(FunctionArgument)); FunctionArgument fa = f.Arguments[0] as FunctionArgument; Assert.IsNotNull(fa.Comma); Assert.AreEqual(1, fa.ArgumentItems.Count); Assert.IsInstanceOfType(fa.ArgumentItems[0], typeof(NumericalValue)); NumericalValue numericalValue = (NumericalValue)fa.ArgumentItems[0]; Assert.IsInstanceOfType(numericalValue.Children[0], typeof(TokenItem)); Assert.AreEqual(CssTokenType.Number, ((TokenItem)numericalValue.Children[0]).TokenType); Assert.IsInstanceOfType(f.Arguments[1], typeof(FunctionArgument)); Assert.IsNotNull(fa.Comma); Assert.AreEqual(1, fa.ArgumentItems.Count); Assert.IsInstanceOfType(fa.ArgumentItems[0], typeof(NumericalValue)); fa = f.Arguments[1] as FunctionArgument; Assert.IsInstanceOfType(fa.ArgumentItems[0], typeof(NumericalValue)); numericalValue = (NumericalValue)fa.ArgumentItems[0]; Assert.IsInstanceOfType(numericalValue.Children[1], typeof(TokenItem)); Assert.IsInstanceOfType(numericalValue.Children[1], typeof(TokenItem)); Assert.AreEqual(CssTokenType.Number, ((TokenItem)numericalValue.Children[0]).TokenType); Assert.AreEqual(CssTokenType.Units, ((TokenItem)numericalValue.Children[1]).TokenType); }
static void Execute(ForeachFunctionValue main, FunctionArgument args, EvalContext cal) { var children = args.Contents; try { IEnumerableValue l = cal.GetValue <IEnumerableValue>(cal.Evaluate(main.Collection)); foreach (var t in l) { cal.Variables.Set(main.Vid, t); try { foreach (var v in children) { cal.Evaluate(v); } } catch (BContinue) { continue; } } } catch (BBreak) { return; } }
private bool ShouldCount(FunctionArgument item) { if (ShouldIgnore(item)) { return false; } if (item.Value == null) return false; return (!string.IsNullOrEmpty(item.Value.ToString())); }
private void Calculate(FunctionArgument arg, ParsingContext context, ref double retVal, ref double nValues, bool isInArray = false) { if (ShouldIgnore(arg)) { return; } if (arg.Value is IEnumerable<FunctionArgument>) { foreach (var item in (IEnumerable<FunctionArgument>)arg.Value) { Calculate(item, context, ref retVal, ref nValues, true); } } else if (arg.IsExcelRange) { foreach (var c in arg.ValueAsRangeInfo) { if (ShouldIgnore(c, context)) continue; CheckForAndHandleExcelError(c); if (IsNumeric(c.Value)) { nValues++; retVal += c.ValueDouble; } else if (c.Value is bool) { nValues++; retVal += (bool) c.Value ? 1 : 0; } else if (c.Value is string) { nValues++; } } } else { var numericValue = GetNumericValue(arg.Value, isInArray); if (numericValue.HasValue) { nValues++; retVal += numericValue.Value; } else if((arg.Value is string) && !ConvertUtil.IsNumericString(arg.Value)) { if (isInArray) { nValues++; } else { ThrowExcelErrorValueException(eErrorType.Value); } } } CheckForAndHandleExcelError(arg); }
private bool ShouldCount(FunctionArgument item) { if (ShouldIgnore(item)) { return false; } if (item.Value == null) return false; if (item.Value.GetType() == typeof(int) || item.Value.GetType() == typeof(double) || item.Value.GetType() == typeof(decimal) || item.Value.GetType() == typeof(System.DateTime)) { return true; } return false; }
private double Calculate(FunctionArgument arg, ParsingContext context, bool isInArray = false) { var retVal = 0d; if (ShouldIgnore(arg)) { return retVal; } if (arg.Value is IEnumerable<FunctionArgument>) { foreach (var item in (IEnumerable<FunctionArgument>)arg.Value) { retVal += Calculate(item, context, true); } } else { var cs = arg.Value as ExcelDataProvider.IRangeInfo; if (cs != null) { foreach (var c in cs) { if (ShouldIgnore(c, context) == false) { CheckForAndHandleExcelError(c); retVal += System.Math.Pow(c.ValueDouble, 2); } } } else { CheckForAndHandleExcelError(arg); if (IsNumericString(arg.Value) && !isInArray) { var value = ConvertUtil.GetValueDouble(arg.Value); return System.Math.Pow(value, 2); } var ignoreBool = isInArray; retVal += System.Math.Pow(ConvertUtil.GetValueDouble(arg.Value, ignoreBool), 2); } } return retVal; }
private double Calculate(FunctionArgument arg) { var retVal = 0d; if (ShouldIgnore(arg)) { return retVal; } if (arg.Value is double || arg.Value is int) { retVal += Convert.ToDouble(arg.Value); } else if (arg.Value is System.DateTime) { retVal += Convert.ToDateTime(arg.Value).ToOADate(); } else if (arg.Value is IEnumerable<FunctionArgument>) { foreach (var item in (IEnumerable<FunctionArgument>)arg.Value) { retVal += Calculate(item); } } return retVal; }
public WorkdayCalculatorResult AdjustResultWithHolidays(WorkdayCalculatorResult calculatedResult, FunctionArgument holidayArgument) { var startDate = calculatedResult.StartDate; var endDate = calculatedResult.EndDate; var direction = calculatedResult.Direction; var workdaysCounted = calculatedResult.NumberOfWorkdays; var additionalDays = new AdditionalHolidayDays(holidayArgument); foreach (var date in additionalDays.AdditionalDates) { if (direction == WorkdayCalculationDirection.Forward && (date < startDate || date > endDate)) continue; if (direction == WorkdayCalculationDirection.Backward && (date > startDate || date < endDate)) continue; if (_holidayWeekdays.IsHolidayWeekday(date)) continue; var tmpDate = _holidayWeekdays.GetNextWorkday(endDate, direction); while (additionalDays.AdditionalDates.Contains(tmpDate)) { tmpDate = _holidayWeekdays.GetNextWorkday(tmpDate, direction); } workdaysCounted++; endDate = tmpDate; } return new WorkdayCalculatorResult(workdaysCounted, calculatedResult.StartDate, endDate, direction); }
public AdditionalHolidayDays(FunctionArgument holidayArg) { _holidayArg = holidayArg; Initialize(); }
public WorkdayCalculatorResult ReduceWorkdaysWithHolidays(WorkdayCalculatorResult calculatedResult, FunctionArgument holidayArgument) { var startDate = calculatedResult.StartDate; var endDate = calculatedResult.EndDate; var additionalDays = new AdditionalHolidayDays(holidayArgument); System.DateTime calcStartDate; System.DateTime calcEndDate; if (startDate < endDate) { calcStartDate = startDate; calcEndDate = endDate; } else { calcStartDate = endDate; calcEndDate = startDate; } var nAdditionalHolidayDays = additionalDays.AdditionalDates.Count(x => x >= calcStartDate && x <= calcEndDate && !_holidayWeekdays.IsHolidayWeekday(x)); return new WorkdayCalculatorResult(calculatedResult.NumberOfWorkdays - nAdditionalHolidayDays, startDate, endDate, calculatedResult.Direction); }
/// <summary> /// Parses a comma-separated list of function arguments. /// </summary> /// <param name="endToken"> The token that ends parsing. </param> /// <returns> A list of parsed arguments. </returns> internal List<FunctionArgument> ParseFunctionArguments(Token endToken) { var arguments = new List<FunctionArgument>(); if (this.nextToken != endToken) { while (true) { // Read the argument name. var argument = new FunctionArgument(); argument.Name = this.ExpectIdentifier(); ValidateVariableName(argument.Name); // Check if the argument has a default value. if (this.nextToken == PunctuatorToken.Assignment) { // Read past the assignment token. Consume(); // Parse the expression that follows. argument.DefaultValue = ParseExpression(PunctuatorToken.Comma, endToken); } // Add the variable to the scope so that it can be used in the default value of // the next argument. Do this *after* parsing the default value. this.currentVarScope.DeclareVariable(argument.Name); // Add the argument to the list. arguments.Add(argument); if (this.nextToken == PunctuatorToken.Comma) { // Consume the comma. this.Consume(); } else if (this.nextToken == endToken) break; else throw new JavaScriptException(this.engine, ErrorType.SyntaxError, "Expected ',' or ')'", this.LineNumber, this.SourcePath); } } return arguments; }
private double Calculate(FunctionArgument arg, string expression) { var retVal = 0d; if (ShouldIgnore(arg) || !_numericExpressionEvaluator.Evaluate(arg.Value, expression)) { return retVal; } if (IsNumeric(arg.Value)) { retVal += ConvertUtil.GetValueDouble(arg.Value); } //else if (arg.Value is System.DateTime) //{ // retVal += Convert.ToDateTime(arg.Value).ToOADate(); //} else if (arg.Value is IEnumerable<FunctionArgument>) { foreach (var item in (IEnumerable<FunctionArgument>)arg.Value) { retVal += Calculate(item, expression); } } return retVal; }