public override void SetIndexedValue(IValue index, IValue val) { if (index.DataType != DataType.String) { throw RuntimeException.InvalidArgumentType(); } var n = FindProperty(index.AsString()); if (IsPropWritable(n)) SetPropValue(n, val); else throw RuntimeException.PropIsNotWritableException(index.AsString()); }
public override IValue GetIndexedValue(IValue index) { if (index.DataType != DataType.String) { throw RuntimeException.InvalidArgumentType(); } var n = FindProperty(index.AsString()); if (IsPropReadable(n)) return GetPropValue(n); else throw RuntimeException.PropIsNotReadableException(index.AsString()); }
public static ZipReader Constructor(IValue dataSource, IValue password = null) { var dataSourceRawValue = dataSource.GetRawValue(); if (dataSourceRawValue.DataType == DataType.String) { return(new ZipReader(dataSourceRawValue.AsString(), password?.AsString())); } else if (dataSourceRawValue is IStreamWrapper) { return(new ZipReader((IStreamWrapper)dataSourceRawValue.AsObject(), password?.AsString())); } else { throw RuntimeException.InvalidArgumentType(nameof(dataSource)); } }
public static IRuntimeContextInstance Constructor(IValue encoding = null, IValue version = null, IValue indent = null, IValue indentAttributes = null, IValue indentChars = null) { var _indent = ContextValuesMarshaller.ConvertParam <bool>(indent, true); var _indentAttributes = ContextValuesMarshaller.ConvertParam <bool>(indentAttributes); return(new XmlWriterSettingsImpl(encoding?.AsString() ?? "UTF-8", version?.AsString() ?? "1.0", _indent, _indentAttributes, indentChars?.AsString() ?? "\t")); }
public HttpRequestBodyBinary(string body, IValue encoding = null, ByteOrderMarkUsageEnum bomUsage = ByteOrderMarkUsageEnum.Auto) { var utfs = new List <string> { "utf-16", "utf-32" }; var addBom = utfs.Contains(encoding?.AsString(), StringComparer.OrdinalIgnoreCase) && bomUsage == ByteOrderMarkUsageEnum.Auto || bomUsage == ByteOrderMarkUsageEnum.Use; var encoder = encoding == null ? new UTF8Encoding(addBom) : TextEncodingEnum.GetEncoding(encoding, addBom); var byteArray = encoder.GetBytes(body); _memoryStream.Write(byteArray, 0, byteArray.Length); }
public IValue Adjust(IValue value) { var stringValue = value?.AsString() ?? ""; if (Length != 0 && stringValue.Length > Length) { stringValue = stringValue.Substring(0, Length); } if (AllowedLength == AllowedLengthEnum.Fixed && stringValue.Length < Length) { var tail = new string(' ', Length - stringValue.Length); stringValue = string.Format("{0}{1}", stringValue, tail); } return(ValueFactory.Create(stringValue)); }
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 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 static DriveInfo Constructor(IValue driveName) { return(new DriveInfo(driveName.AsString())); }
public IValue ReadXML(XmlReaderImpl xmlReader, IValue valueType = null) { TypeTypeValue typeValue = null; if (valueType is TypeTypeValue typeTypeValue) { typeValue = typeTypeValue; } else if (xmlReader.NodeType == xmlNodeEnum.FromNativeValue(XmlNodeType.Element)) { IValue xsiType = xmlReader.GetAttribute(ValueFactory.Create("type"), XmlSchema.InstanceNamespace); IValue xsiNil = xmlReader.GetAttribute(ValueFactory.Create("nil"), XmlSchema.InstanceNamespace); if (xsiType.DataType == DataType.String) { switch (xsiType.AsString()) { case "string": typeValue = new TypeTypeValue("String"); break; case "decimal": typeValue = new TypeTypeValue("Number"); break; case "boolean": typeValue = new TypeTypeValue("Boolean"); break; case "dateTime": typeValue = new TypeTypeValue("Date"); break; default: break; } } else if (xsiNil.DataType == DataType.String) { typeValue = new TypeTypeValue("Undefined"); } } ; if (typeValue == null) { throw RuntimeException.InvalidArgumentValue(); } Type implType = TypeManager.GetImplementingClass(typeValue.Value.ID); IValue result = ValueFactory.Create(); if (typeValue.Equals(new TypeTypeValue("Undefined"))) { result = ValueFactory.Create(); xmlReader.Skip(); } else if (implType == typeof(DataType)) { xmlReader.Read(); if (xmlReader.NodeType == xmlNodeEnum.FromNativeValue(XmlNodeType.Text)) { result = XMLValue(typeValue, xmlReader.Value); xmlReader.Read(); } else { throw RuntimeException.InvalidArgumentValue(); } } else if (typeof(IXDTOSerializableXML).IsAssignableFrom(implType)) { result = Activator.CreateInstance(implType, new object[] { xmlReader, this }) as IValue; } xmlReader.Read(); return(result); }
public override bool Equals(IValue other) { return _val == other.AsString(); }
public static IRuntimeContextInstance Constructor(IValue path, IValue encoding, IValue append) { return(new TextWriteImpl(path.AsString(), encoding.AsString(), append.AsBoolean())); }
public string TrimAll(IValue str) { return(str.AsString().Trim()); }
public override void SetIndexedValue(IValue index, IValue val) { throw RuntimeException.PropIsNotWritableException(index.AsString()); }
public static IRuntimeContextInstance Constructor(IValue path, IValue encoding = null, IValue lineDelimiter = null, IValue append = null) { bool _append = append == null ? false : append.AsBoolean(); return(new TextWriteImpl(path.AsString(), encoding, _append)); }
public static IRuntimeContextInstance Constructor(IValue path, IValue encoding) { return(new TextWriteImpl(path.AsString(), encoding)); }
public override void SetIndexedValue(IValue index, IValue val) { _dictMap[index.AsString()] = val; }
public override IValue GetIndexedValue(IValue index) { return(_dictMap[index.AsString()]); }
public int CompareTo(IValue other) { return(AsString().CompareTo(other.AsString())); }
public static ExceptionTemplate Create(IValue msg, IValue parameter) { return(new ExceptionTemplate(msg.AsString(), parameter)); }
public static ZipReader ConstructByNameAndPassword(IValue filename, IValue password = null) { return(new ZipReader(filename.AsString(), password?.AsString())); }
public static GuidWrapper Create(IValue uuidString) { return new GuidWrapper(uuidString.AsString()); }
public static IRuntimeContextInstance Constructor(IValue strProperties, IValue[] args) { return new StructureImpl(strProperties.AsString(), args); }
public int StrLen(IValue str) { return(str.AsString().Length); }
public static IRuntimeContextInstance Constructor(IValue pattern) { var regex = new RegExpImpl(pattern.AsString()); return(regex); }
public int Find(IValue str, IValue substring) { return(str.AsString().IndexOf(substring.AsString(), StringComparison.Ordinal) + 1); }
public override int CompareTo(IValue other) { return(_val.CompareTo(other.AsString())); }
public override int CompareTo(IValue other) { return _val.CompareTo(other.AsString()); }
public override bool Equals(IValue other) { return(_val == other.AsString()); }
public static BinaryDataContext Constructor(IValue filename) { return(new BinaryDataContext(filename.AsString())); }
public static RegExpImpl Constructor(IValue pattern) { var regex = new RegExpImpl(pattern.AsString()); return(regex); }
public static IRuntimeContextInstance Constructor(IValue strProperties, IValue[] args) { return(new StructureImpl(strProperties.AsString(), args)); }
public static Encoding GetEncoding(IValue encoding) { if (encoding.DataType == DataType.String) return Encoding.GetEncoding(encoding.AsString()); else { if (encoding.DataType != DataType.GenericValue) throw RuntimeException.InvalidArgumentType(); var encValue = encoding.GetRawValue() as SelfAwareEnumValue<TextEncodingEnum>; if (encValue == null) throw RuntimeException.InvalidArgumentType(); var encodingEnum = GlobalsManager.GetEnum<TextEncodingEnum>(); Encoding enc; if (encValue == encodingEnum.Ansi) enc = Encoding.GetEncoding(1251); else if (encValue == encodingEnum.Oem) enc = Encoding.GetEncoding(866); else if (encValue == encodingEnum.Utf16) enc = new UnicodeEncoding(false, true); else if (encValue == encodingEnum.Utf8) enc = new UTF8Encoding(true); else if (encValue == encodingEnum.Utf8NoBOM) enc = new UTF8Encoding(false); else if (encValue == encodingEnum.System) enc = Encoding.Default; else throw RuntimeException.InvalidArgumentValue(); return enc; } }
public static ZipReader ConstructByName(IValue filename) { return(new ZipReader(filename.AsString())); }
public static IRuntimeContextInstance Constructor(IValue name) { return(new FileContext(name.AsString())); }
public bool Equals(IValue other) { if (other.DataType == this.DataType) { var scv = other.AsString(); return scv == this._value; } else { return false; } }
public IValue String(IValue value) { return(ValueFactory.Create(value.AsString())); }
public int CompareTo(IValue other) { if(other.DataType == DataType.String) return _value.CompareTo(other.AsString()); throw RuntimeException.ComparisonNotSupportedException(); }
public IValue StrReplace(IValue str, IValue substring_search, IValue substring_replace) { string result = str.AsString().Replace(substring_search.AsString(), substring_replace.AsString()); return(ValueFactory.Create(result)); }
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 (type == typeof(string)) { valueObj = value.AsString(); } else if (value == SimpleConstantValue.Undefined()) { // Если тип параметра не IValue и не IVariable && Неопределено -> null valueObj = null; } else if (type == typeof(int)) { valueObj = (int)value.AsNumber(); } else if (type == typeof(sbyte)) { valueObj = (sbyte)value.AsNumber(); } else if (type == typeof(short)) { valueObj = (short)value.AsNumber(); } else if (type == typeof(ushort)) { valueObj = (ushort)value.AsNumber(); } else if (type == typeof(uint)) { valueObj = (uint)value.AsNumber(); } else if (type == typeof(byte)) { valueObj = (byte)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)) { valueObj = (double)value.AsNumber(); } else if (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 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; }