Example #1
0
        public void Move(IValue row, int offset)
        {
            row = row.GetRawValue();

            int indexSource;

            if (row is ValueTreeRow)
            {
                indexSource = _rows.IndexOf(row as ValueTreeRow);
            }
            else if (row.DataType == Machine.DataType.Number)
            {
                indexSource = decimal.ToInt32(row.AsNumber());
            }
            else
            {
                throw RuntimeException.InvalidArgumentType();
            }

            if (indexSource < 0 || indexSource >= _rows.Count())
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            int indexDestination = (indexSource + offset) % _rows.Count();

            while (indexDestination < 0)
            {
                indexDestination += _rows.Count();
            }

            ValueTreeRow tmp = _rows[indexSource];

            if (indexSource < indexDestination)
            {
                _rows.Insert(indexDestination + 1, tmp);
                _rows.RemoveAt(indexSource);
            }
            else
            {
                _rows.RemoveAt(indexSource);
                _rows.Insert(indexDestination, tmp);
            }
        }
        public static T ConvertParam <T>(IValue value, T defaultValue)
        {
            var    type     = typeof(T);
            object valueObj = ConvertParam(value, type);

            if (valueObj == null)
            {
                return(defaultValue);
            }

            try
            {
                return((T)valueObj);
            }
            catch (InvalidCastException)
            {
                throw RuntimeException.InvalidArgumentType();
            }
        }
Example #3
0
 public void Write(IValue filenameOrStream)
 {
     if (filenameOrStream.DataType == DataType.String)
     {
         var filename = filenameOrStream.AsString();
         using (var fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
         {
             fs.Write(_buffer, 0, _buffer.Length);
         }
     }
     else if (filenameOrStream.AsObject() is IStreamWrapper stream)
     {
         stream.GetUnderlyingStream().Write(_buffer, 0, _buffer.Length);
     }
     else
     {
         throw RuntimeException.InvalidArgumentType("filenameOrStream");
     }
 }
Example #4
0
        public ValueTable.ValueTable GetMethodsTable(IValue target)
        {
            var result = new ValueTable.ValueTable();

            if (target.DataType == DataType.Object)
            {
                FillMethodsTableForObject(target.AsObject(), result);
            }
            else if (target.DataType == DataType.Type)
            {
                FillMethodsTableForType(target.GetRawValue() as TypeTypeValue, result);
            }
            else
            {
                throw RuntimeException.InvalidArgumentType();
            }

            return(result);
        }
        public static HttpRequestContext Constructor(IValue resource, IValue headers = null)
        {
            var ctx = new HttpRequestContext {
                ResourceAddress = resource.AsString()
            };

            if (headers == null)
            {
                return(ctx);
            }
            if (!(headers.GetRawValue() is MapImpl headersMap))
            {
                throw RuntimeException.InvalidArgumentType();
            }

            ctx.Headers = headersMap;

            return(ctx);
        }
Example #6
0
        private static IXSDirective CreateIXSDirective(XmlSchemaExternal xmlSchemaExternal)
        {
            if (xmlSchemaExternal is XmlSchemaImport import)
            {
                return(new XSImport(import));
            }

            else if (xmlSchemaExternal is XmlSchemaInclude include)
            {
                return(new XSInclude(include));
            }

            else if (xmlSchemaExternal is XmlSchemaRedefine redefine)
            {
                return(new XSRedefine(redefine));
            }

            throw RuntimeException.InvalidArgumentType();
        }
Example #7
0
        public ArrayImpl FindRows(IValue Filter)
        {
            if (!(Filter is StructureImpl))
            {
                throw RuntimeException.InvalidArgumentType();
            }

            ArrayImpl Result = new ArrayImpl();

            foreach (ValueTableRow row in _rows)
            {
                if (CheckFilterCriteria(row, Filter as StructureImpl))
                {
                    Result.Add(row);
                }
            }

            return(Result);
        }
 public void Записать(object filenameOrStream)
 {
     if (filenameOrStream is string)
     {
         var filename = filenameOrStream as string;
         using (var fs = new FileStream(filename, FileMode.Create, FileAccess.Write))
         {
             fs.Write(_buffer, 0, _buffer.Length);
         }
     }
     //else if(filenameOrStream is IStreamWrapper stream)
     //{
     //    stream.GetUnderlyingStream().Write(_buffer, 0, _buffer.Length);
     //}
     else
     {
         throw RuntimeException.InvalidArgumentType("filenameOrStream");
     }
 }
Example #9
0
        public ValueTable.ValueTable GetPropertiesTable(IValue target)
        {
            ValueTable.ValueTable result = new ValueTable.ValueTable();

            if (target.DataType == DataType.Object)
            {
                FillPropertiesTable(result, target.AsObject().GetProperties());
            }
            else if (target.DataType == DataType.Type)
            {
                var type = target.GetRawValue() as TypeTypeValue;
                FillPropertiesTableForType(type, result);
            }
            else
            {
                throw RuntimeException.InvalidArgumentType();
            }

            return(result);
        }
Example #10
0
        public void AddHandler(
            IRuntimeContextInstance eventSource,
            string eventName,
            IRuntimeContextInstance handlerTarget,
            string handlerMethod)
        {
            if (!(handlerTarget is ScriptDrivenObject handlerScript))
            {
                throw RuntimeException.InvalidArgumentType("handlerTarget");
            }

            if (!_registeredHandlers.TryGetValue(eventSource, out var handlers))
            {
                handlers            = new Dictionary <string, HandlersList>();
                handlers[eventName] = new HandlersList();
                _registeredHandlers[eventSource] = handlers;
            }

            handlers[eventName].Add(handlerScript, handlerMethod);
        }
Example #11
0
        public void CopyTo(IValue targetStream, int bufferSize = 0)
        {
            IStreamWrapper sw = targetStream.GetRawValue() as IStreamWrapper;

            if (sw == null)
            {
                throw RuntimeException.InvalidArgumentType("targetStream");
            }

            var stream = sw.GetUnderlyingStream();

            if (bufferSize == 0)
            {
                _underlyingStream.CopyTo(stream);
            }
            else
            {
                _underlyingStream.CopyTo(stream, bufferSize);
            }
        }
Example #12
0
 public void Append(IValue toAdd)
 {
     byte[] buffer = null;
     if (toAdd.DataType == DataType.String)
     {
         buffer = Encoding.UTF8.GetBytes(toAdd.AsString());
     }
     else if (toAdd.DataType == DataType.Object)
     {
         try
         {
             var binaryData = toAdd as BinaryDataContext;
             buffer = binaryData.Buffer;
         }
         catch
         {
             throw RuntimeException.InvalidArgumentType();
         }
     }
     AddStream(new MemoryStream(buffer));
 }
Example #13
0
        public static IRuntimeContextInstance ConstructByQualifiers(
            IValue types,
            IValue numberQualifiers     = null,
            IValue stringQualifiers     = null,
            IValue dateQualifiers       = null,
            IValue binaryDataQualifiers = null)
        {
            var _types = ConstructTypeList(types);

            if (_types == null)
            {
                throw RuntimeException.InvalidArgumentType(nameof(types));
            }

            var paramNumberQ     = numberQualifiers?.GetRawValue() as NumberQualifiers;
            var paramStringQ     = stringQualifiers?.GetRawValue() as StringQualifiers;
            var paramDateQ       = dateQualifiers?.GetRawValue() as DateQualifiers;
            var paramBinaryDataQ = binaryDataQualifiers?.GetRawValue() as BinaryDataQualifiers;

            return(new TypeDescription(_types, paramNumberQ, paramStringQ, paramDateQ, paramBinaryDataQ));
        }
Example #14
0
        public ArrayImpl FindRows(IValue filter)
        {
            var filterStruct = filter.GetRawValue() as StructureImpl;

            if (filterStruct == null)
            {
                throw RuntimeException.InvalidArgumentType();
            }

            ArrayImpl Result = new ArrayImpl();

            foreach (ValueTableRow row in _rows)
            {
                if (CheckFilterCriteria(row, filterStruct))
                {
                    Result.Add(row);
                }
            }

            return(Result);
        }
Example #15
0
        private IEnumerable <ValueTableRow> GetRowsEnumByArray(IValue Rows)
        {
            IEnumerable <ValueTableRow> requestedRows;
            var rowsArray = Rows.GetRawValue() as ArrayImpl;

            if (rowsArray == null)
            {
                throw RuntimeException.InvalidArgumentType();
            }

            requestedRows = rowsArray.Select(x =>
            {
                var vtr = x.GetRawValue() as ValueTableRow;
                if (vtr == null || vtr.Owner() != this)
                {
                    throw RuntimeException.InvalidArgumentValue();
                }

                return(vtr);
            });
            return(requestedRows);
        }
Example #16
0
        public ValueTable.ValueTable GetPropertiesTable(IValue target)
        {
            ValueTable.ValueTable result = new ValueTable.ValueTable();

            if (target.DataType == DataType.Object)
            {
                FillPropertiesTable(result, target.AsObject().GetProperties());
            }
            else if (target.DataType == DataType.Type)
            {
                var type        = target.GetRawValue() as TypeTypeValue;
                var clrType     = GetReflectableClrType(type);
                var magicCaller = CreatePropertiesMapper(clrType);
                FillPropertiesTable(result, magicCaller.GetProperties());
            }
            else
            {
                throw RuntimeException.InvalidArgumentType();
            }

            return(result);
        }
Example #17
0
    private byte[] GetBytes <T>(Converter <T, byte[]> converterOverload, T value, IValue byteOrder = null)
    {
        byte[] bytes;
        if (byteOrder == null)
        {
            bytes = converterOverload(value);
        }
        else
        {
            try
            {
                var order = (ByteOrderEnum)(object)byteOrder.GetRawValue();
                Converter.IsLittleEndian = order == ByteOrderEnum.LittleEndian;
                bytes = converterOverload(value);
            }
            catch (InvalidCastException)
            {
                throw RuntimeException.InvalidArgumentType();
            }
        }

        return(bytes);
    }
Example #18
0
        internal static string XMLStringIValue(IValue value)
        {
            switch (value.DataType)
            {
            case DataType.Undefined:
                return("");

            case DataType.String:
                return(value.AsString());

            case DataType.Boolean:
                return(XmlConvert.ToString(value.AsBoolean()));

            case DataType.Date:
                return(XmlConvert.ToString(value.AsDate(), XmlDateTimeSerializationMode.Unspecified));

            case DataType.Number:
                return(XmlConvert.ToString(value.AsNumber()));

            default:
                throw RuntimeException.InvalidArgumentType();
            }
        }
Example #19
0
        private void SetMinOccurs(XmlSchemaParticle particle, IValue minOccurs)
        {
            if (minOccurs.DataType == DataType.Undefined)
            {
                particle.MinOccursString = null;
            }

            else if (minOccurs.DataType == DataType.Number)
            {
                decimal number = minOccurs.AsNumber();
                if (number >= 0)
                {
                    particle.MinOccurs = number;
                }
                else
                {
                    throw RuntimeException.InvalidArgumentValue();
                }
            }
            else
            {
                throw RuntimeException.InvalidArgumentType();
            }
        }
Example #20
0
        public void Open(IValue filenameOrStream, string password = null, FileNamesEncodingInZipFile encoding = FileNamesEncodingInZipFile.Auto)
        {
            // f**k non-russian encodings on non-ascii files
            ZipFile.DefaultEncoding = Encoding.GetEncoding(866);

            if (filenameOrStream.DataType == DataType.String)
            {
                _zip = ZipFile.Read(filenameOrStream.AsString(), new ReadOptions {
                    Encoding = ChooseEncoding(encoding)
                });
            }
            else if (filenameOrStream.AsObject() is IStreamWrapper stream)
            {
                _zip = ZipFile.Read(stream.GetUnderlyingStream(), new ReadOptions {
                    Encoding = ChooseEncoding(encoding)
                });
            }
            else
            {
                throw RuntimeException.InvalidArgumentType(nameof(filenameOrStream));
            }

            _zip.Password = password;
        }