public static IRuntimeContextInstance Constructor( IValue server, IValue port = null, IValue userName = null, IValue password = null, InternetProxyContext proxy = null, IValue passiveConnection = null, IValue timeout = null, IValue secureConnection = null ) { var conn = new FtpConnection(server.AsString(), (int)(port?.AsNumber() ?? 21), userName?.AsString(), password?.AsString(), proxy, passiveConnection?.AsBoolean() ?? false, (int)(timeout?.AsNumber() ?? 0), secureConnection); return(conn); }
public static string Format(IValue value, string format) { var formatParameters = ParseParameters(format); string formattedValue; switch(value.DataType) { case DataType.Boolean: formattedValue = FormatBoolean(value.AsBoolean(), formatParameters); break; case DataType.Number: formattedValue = FormatNumber(value.AsNumber(), formatParameters); break; case DataType.Date: formattedValue = FormatDate(value.AsDate(), formatParameters); break; default: formattedValue = DefaultFormat(value, formatParameters); break; } return formattedValue; }
public override IValue GetIndexedValue(IValue index) { return(new MatchImpl(_matches[(int)index.AsNumber()])); }
public void GroupBy(string groupColumnNames, string aggregateColumnNames = null) { List <ValueTableColumn> GroupColumns = GetProcessingColumnList(groupColumnNames, true); List <ValueTableColumn> AggregateColumns = GetProcessingColumnList(aggregateColumnNames, true); foreach (ValueTableColumn group_column in GroupColumns) { if (AggregateColumns.Find(x => x.Name == group_column.Name) != null) { throw ColumnsMixedException(group_column.Name); } } var uniqueRows = new Dictionary <ValueTableRow, ValueTableRow>(new RowsByColumnsEqComparer(GroupColumns)); int new_idx = 0; foreach (ValueTableRow row in _rows) { if (uniqueRows.ContainsKey(row)) { ValueTableRow old_row = uniqueRows[row]; foreach (var Column in AggregateColumns) { IValue current = row.Get(Column); if (current.DataType == DataType.Number) { decimal sum = old_row.Get(Column).AsNumber() + current.AsNumber(); old_row.Set(Column, ValueFactory.Create(sum)); } } } else { uniqueRows.Add(row, row); ValueTableRow new_row = _rows[new_idx++]; foreach (var Column in GroupColumns) { new_row.Set(Column, row.Get(Column)); } foreach (var Column in AggregateColumns) { if (new_row.Get(Column).DataType != DataType.Number) { new_row.Set(Column, ValueFactory.Create(0)); } } } } _rows.RemoveRange(new_idx, _rows.Count() - new_idx); int i = 0; while (i < _columns.Count()) { ValueTableColumn Column = _columns.FindColumnByIndex(i); if (GroupColumns.IndexOf(Column) == -1 && AggregateColumns.IndexOf(Column) == -1) { _columns.Delete(Column); } else { ++i; } } }
public ValueTableColumn GetColumnByIIndex(IValue index) { if (index.DataType == DataType.String) { ValueTableColumn Column = FindColumnByName(index.AsString()); if (Column == null) throw RuntimeException.PropNotFoundException(index.AsString()); return Column; } if (index.DataType == DataType.Number) { int i_index = Decimal.ToInt32(index.AsNumber()); if (i_index < 0 || i_index >= Count()) throw RuntimeException.InvalidArgumentValue(); ValueTableColumn Column = FindColumnByIndex(i_index); return Column; } if (index is ValueTableColumn) { return index as ValueTableColumn; } throw RuntimeException.InvalidArgumentType(); }
public bool IsValueFilled(IValue value) { if (value.DataType == DataType.Undefined) return false; else if (value.DataType == DataType.Boolean) return true; else if (value.DataType == DataType.String) return !String.IsNullOrWhiteSpace(value.AsString()); else if (value.DataType == DataType.Number) return value.AsNumber() != 0; else if (value.DataType == DataType.Date) { var emptyDate = new DateTime(1, 1, 1, 0, 0, 0); return value.AsDate() != emptyDate; } else if (value.GetRawValue() is ICollectionContext) { var col = value.GetRawValue() as ICollectionContext; return col.Count() != 0; } else return true; }
public int CompareTo(IValue other) { if (other.DataType != this.DataType) { if (this.DataType == DataType.Boolean && other.DataType == DataType.Number || this.DataType == DataType.Number && other.DataType == DataType.Boolean) { return AsNumber().CompareTo(other.AsNumber()); } else { throw RuntimeException.ComparisonNotSupportedException(); } } switch (other.DataType) { case Machine.DataType.Boolean: return AsBoolean().CompareTo(other.AsBoolean()); case Machine.DataType.Date: return AsDate().CompareTo(other.AsDate()); case Machine.DataType.Undefined: return 0; default: return AsNumber().CompareTo(other.AsNumber()); } }
public void GroupBy(string GroupColumnNames, string AggregateColumnNames = null) { // TODO: Сворачиваем за N^2. Переделать на N*log(N) List <ValueTableColumn> GroupColumns = GetProcessingColumnList(GroupColumnNames, true); List <ValueTableColumn> AggregateColumns = GetProcessingColumnList(AggregateColumnNames, true); List <ValueTableRow> new_rows = new List <ValueTableRow>(); foreach (ValueTableRow row in _rows) { StructureImpl search = new StructureImpl(); foreach (ValueTableColumn Column in GroupColumns) { search.Insert(Column.Name, row.Get(Column)); } ValueTableRow new_row = null; foreach (ValueTableRow nrow in new_rows) { if (CheckFilterCriteria(nrow, search)) { new_row = nrow; break; } } if (new_row == null) { new_row = new ValueTableRow(this); foreach (ValueTableColumn Column in GroupColumns) { new_row.Set(Column, row.Get(Column)); } new_rows.Add(new_row); } foreach (ValueTableColumn Column in AggregateColumns) { IValue old = new_row.Get(Column); decimal d_old; if (old.DataType != Machine.DataType.Number) { d_old = 0; } else { d_old = old.AsNumber(); } IValue current = row.Get(Column); decimal d_current; if (current.DataType != Machine.DataType.Number) { d_current = 0; } else { d_current = current.AsNumber(); } new_row.Set(Column, ValueFactory.Create(d_old + d_current)); } } _rows.Clear(); _rows.AddRange(new_rows); { int i = 0; while (i < _columns.Count()) { ValueTableColumn Column = _columns.FindColumnByIndex(i); if (GroupColumns.IndexOf(Column) == -1 && AggregateColumns.IndexOf(Column) == -1) { _columns.Delete(Column); } else { ++i; } } } }
public static IValue Neg(IValue op1) { return(Create(op1.AsNumber() * -1)); }
public static IValue Mul(IValue op1, IValue op2) { return(Create(op1.AsNumber() * op2.AsNumber())); }
public override IValue GetIndexedValue(IValue index) { int idx = (int)index.AsNumber(); return(_entries[idx]); }
public static TCPServer ConstructByPort(IValue port) { return(new TCPServer((int)port.AsNumber())); }
public static IRuntimeContextInstance Constructor(IValue host, IValue port, IValue user, IValue pass) { return(new ClientSsh(host.AsString(), (int)port.AsNumber(), user.AsString(), pass.AsString())); }
public override IValue GetIndexedValue(IValue index) { var arrIdx = (int)index.AsNumber(); return(ValueFactory.Create(_values[arrIdx])); }
public override IValue GetIndexedValue(IValue index) { return(ValueFactory.Create(Get((int)index.AsNumber()))); }
public ValueListItem GetValue(IValue index) { int numericIndex = (int)index.AsNumber(); return(_items[numericIndex]); }
public static object ConvertParam(IValue value, Type type) { object valueObj; if (value == null || value.DataType == DataType.NotAValidValue) { return(null); } if (Nullable.GetUnderlyingType(type) != null) { return(ConvertParam(value, Nullable.GetUnderlyingType(type))); } if (type == typeof(IValue)) { valueObj = value; } else if (type == typeof(IVariable)) { valueObj = value; } else if (value == SimpleConstantValue.Undefined()) { // Если тип параметра не IValue и не IVariable && Неопределено -> null valueObj = null; } else if (type == typeof(string)) { valueObj = value.AsString(); } else if (type == typeof(int) || type == typeof(short) || type == typeof(sbyte)) { valueObj = (int)value.AsNumber(); } else if (type == typeof(uint) || type == typeof(ushort) || type == typeof(byte)) { valueObj = (uint)value.AsNumber(); } else if (type == typeof(long)) { valueObj = (long)value.AsNumber(); } else if (type == typeof(ulong)) { valueObj = (ulong)value.AsNumber(); } else if (type == typeof(double) || type == typeof(decimal)) { valueObj = value.AsNumber(); } else if (type == typeof(DateTime)) { valueObj = value.AsDate(); } else if (type == typeof(bool)) { valueObj = value.AsBoolean(); } else if (typeof(IRuntimeContextInstance).IsAssignableFrom(type)) { valueObj = value.AsObject(); } else { valueObj = CastToCLRObject(value); } return(valueObj); }
public override IValue GetIndexedValue(IValue index) { var intIndex = (int)index.AsNumber(); return(GetValue(intIndex)); }
public override IValue GetIndexedValue(IValue index) { return(Get((int)index.AsNumber())); }
public override void SetIndexedValue(IValue index, IValue val) { var intIndex = (int)index.AsNumber(); SetValue(intIndex, val); }
public bool Equals(IValue other) { if (other.DataType == this.DataType) { switch (DataType) { case Machine.DataType.Number: return this.AsNumber() == other.AsNumber(); case Machine.DataType.Boolean: return this.AsBoolean() == other.AsBoolean(); case Machine.DataType.Date: return this.AsDate() == other.AsDate(); case Machine.DataType.Undefined: return true; default: return false; } } else { return false; } }
public override void SetIndexedValue(IValue index, IValue val) { _values[(int)index.AsNumber()] = val; }
public override IValue GetIndexedValue(IValue index) { var arrIdx = (int)index.AsNumber(); return ValueFactory.Create(_values[arrIdx]); }
public decimal Number(IValue value) { return(value.AsNumber()); }
public override IValue GetIndexedValue(IValue index) { return(new GroupImpl(_groups[(int)index.AsNumber()])); }
public static TCPClient Constructor(IValue host, IValue port) { var client = new TcpClient(host.AsString(), (int)port.AsNumber()); return(new TCPClient(client)); }