Example #1
0
        public static IRuntimeContextInstance Constructor(IValue initialProperty)
        {
            var result = new SimpleClass();

            result.IntProperty = ContextValuesMarshaller.ConvertParam <int>(initialProperty);
            return(result);
        }
Example #2
0
        private static T ConvertParam <T>(IValue paramSource)
        {
            if (paramSource == null)
            {
                return(default(T));
            }

            if (paramSource.DataType == DataType.NotAValidValue)
            {
                return(default(T));
            }

            var raw = paramSource.GetRawValue();

            if (typeof(EnumerationValue).IsAssignableFrom(typeof(T)))
            {
                try
                {
                    return((T)raw);
                }
                catch (InvalidCastException)
                {
                    throw RuntimeException.InvalidArgumentType();
                }
            }
            else
            {
                return(ContextValuesMarshaller.ConvertParam <T>(raw));
            }
        }
Example #3
0
        public ViewDataDictionary GetDictionary()
        {
            var model    = Model;
            var realDict = _realDictionary ?? new ViewDataDictionary(new EmptyModelMetadataProvider(), new ModelStateDictionary());

            if (model != null)
            {
                if (model.DataType == DataType.Object)
                {
                    realDict.Model = new DynamicContextWrapper(model.AsObject());
                }
                else
                {
                    realDict.Model = ContextValuesMarshaller.ConvertToCLRObject(model.GetRawValue());
                }
            }

            foreach (var iValItem in _dictMap)
            {
                var iVal = iValItem.Value;
                if (iVal.DataType == DataType.Object)
                {
                    realDict[iValItem.Key] = new DynamicContextWrapper(iVal.AsObject());
                }
                else
                {
                    realDict[iValItem.Key] = ContextValuesMarshaller.ConvertToCLRObject(iVal.GetRawValue());
                }
            }

            return(realDict);
        }
Example #4
0
 public static FileStreamContext Constructor(IValue filename, IValue openMode, IValue access, IValue bufferSize = null)
 {
     return(new FileStreamContext(
                filename.AsString(),
                ContextValuesMarshaller.ConvertParam <FileOpenModeEnum>(openMode),
                ContextValuesMarshaller.ConvertParam <FileAccessEnum>(access),
                ContextValuesMarshaller.ConvertParam <int>(bufferSize)));
 }
        public static BinaryDataBuffer Constructor(IValue size, IValue byteOrder = null)
        {
            var orderValue = byteOrder == null ? ByteOrderEnum.LittleEndian : ContextValuesMarshaller.ConvertParam <ByteOrderEnum>(byteOrder);

            return(new BinaryDataBuffer(
                       new byte[ContextValuesMarshaller.ConvertParam <int>(size)],
                       orderValue));
        }
Example #6
0
        public static IRuntimeContextInstance Constructor(IValue length        = null,
                                                          IValue allowedLength = null)
        {
            var paramLength        = ContextValuesMarshaller.ConvertParam <int>(length);
            var paramAllowedLength = ContextValuesMarshaller.ConvertParam <AllowedLengthEnum>(allowedLength);

            return(new BinaryDataQualifiers(paramLength, paramAllowedLength));
        }
Example #7
0
        public static StringQualifiers Constructor(IValue length        = null,
                                                   IValue allowedLength = null)
        {
            var paramLength        = ContextValuesMarshaller.ConvertParam <int>(length);
            var paramAllowedLength = ContextValuesMarshaller.ConvertParam <AllowedLengthEnum>(allowedLength);

            return(new StringQualifiers(paramLength, paramAllowedLength));
        }
 public static object ConvertToCLRObject(IValue value)
 {
     if (value.DataType == DataType.Object && !(value.AsObject() is IObjectWrapper))
     {
         return(value.GetRawValue());
     }
     else
     {
         return(ContextValuesMarshaller.ConvertToCLRObject(value));
     }
 }
        public override object GetValue(object obj)
        {
            var irc = obj as IRuntimeContextInstance;

            if (irc == null)
            {
                throw new ArgumentException();
            }

            return(ContextValuesMarshaller.ConvertReturnValue(irc.GetPropValue(_info.Index)));
        }
Example #10
0
        public static IRuntimeContextInstance Constructor(IValue bufferOrCapacity)
        {
            if (bufferOrCapacity.DataType == DataType.Number)
            {
                return(new MemoryStreamContext((int)bufferOrCapacity.AsNumber()));
            }

            var memBuf = ContextValuesMarshaller.ConvertParam <BinaryDataBuffer>(bufferOrCapacity);

            return(new MemoryStreamContext(memBuf));
        }
        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 static HttpConnectionContext Constructor(IValue host,
                                                 IValue port     = null,
                                                 IValue user     = null,
                                                 IValue password = null,
                                                 IValue proxy    = null,
                                                 IValue timeout  = null)
 {
     return(new HttpConnectionContext(host.AsString(),
                                      ContextValuesMarshaller.ConvertParam <int>(port),
                                      ContextValuesMarshaller.ConvertParam <string>(user),
                                      ContextValuesMarshaller.ConvertParam <string>(password),
                                      ContextValuesMarshaller.ConvertParam <InternetProxyContext>(proxy),
                                      ContextValuesMarshaller.ConvertParam <int>(timeout)
                                      ));
 }
Example #13
0
        public static NumberQualifiers Constructor(IValue digits         = null,
                                                   IValue fractionDigits = null,
                                                   IValue allowedSign    = null)
        {
            var paramDigits         = ContextValuesMarshaller.ConvertParam <int>(digits);
            var paramFractionDigits = ContextValuesMarshaller.ConvertParam <int>(fractionDigits);

            if (paramDigits < 0 || paramFractionDigits < 0)
            {
                throw RuntimeException.InvalidArgumentValue();
            }

            var paramAllowedSign = ContextValuesMarshaller.ConvertParam <AllowedSignEnum>(allowedSign);

            return(new NumberQualifiers(paramDigits, paramFractionDigits, paramAllowedSign));
        }
Example #14
0
        public bool Read()
        {
            if (currentChar == -1)
            {
                return(false);
            }

            var c = (Char)currentChar;

            while (Char.IsWhiteSpace(c))
            {
                currentChar = reader.Read();
                if (currentChar == -1)
                {
                    return(false);
                }
                c = (Char)currentChar;
            }

            if (c == '{')
            {
                ElementType = ContextValuesMarshaller.ConvertReturnValue(BrackerNodeTypeEnum.StartElement);
                Value       = ValueFactory.Create();
                currentChar = reader.Read();
            }
            else if (c == '}')
            {
                ElementType = ContextValuesMarshaller.ConvertReturnValue(BrackerNodeTypeEnum.EndElement);
                Value       = ValueFactory.Create();
                currentChar = reader.Read();
            }
            else
            {
                ElementType = ContextValuesMarshaller.ConvertReturnValue(BrackerNodeTypeEnum.Value);
                Value       = ReadValue();
                if ((char)currentChar == ',')
                {
                    currentChar = reader.Read();
                }
            }

            return(true);
        }
Example #15
0
 public static FileStreamContext Constructor(IValue filename, IValue openMode, IValue bufferSize = null)
 {
     if (bufferSize == null || bufferSize.DataType == DataType.Number)
     {
         return(new FileStreamContext(
                    filename.AsString(),
                    ContextValuesMarshaller.ConvertParam <FileOpenModeEnum>(openMode),
                    FileAccessEnum.ReadAndWrite,
                    ContextValuesMarshaller.ConvertParam <int>(bufferSize)));
     }
     else
     {
         // перегрузка методов не позволяет вызвать второй конструктор без доуточнения реальных типов
         return(Constructor(
                    filename,
                    openMode,
                    new CLREnumValueWrapper <FileAccessEnum>(null, FileAccessEnum.ReadAndWrite),
                    bufferSize));
     }
 }
Example #16
0
 public static DataWriter Constructor(IValue file_stream, IValue textEncoding = null, IValue byteOrder = null, IValue lineSplitter = null, IValue param5 = null, IValue param6 = null, IValue param7 = null)
 {
     if (file_stream.DataType == DataType.String)
     {
         return(new DataWriter(file_stream.AsString(), textEncoding,
                               ContextValuesMarshaller.ConvertParam <ByteOrderEnum?>(byteOrder, null),
                               ContextValuesMarshaller.ConvertParam <string>(lineSplitter),
                               ContextValuesMarshaller.ConvertParam <bool>(param5),
                               ContextValuesMarshaller.ConvertParam <string>(param6),
                               ContextValuesMarshaller.ConvertParam <bool>(param7)));
     }
     else
     {
         return(ConstructorByStream(file_stream, textEncoding,
                                    ContextValuesMarshaller.ConvertParam <ByteOrderEnum?>(byteOrder, null),
                                    ContextValuesMarshaller.ConvertParam <string>(lineSplitter),
                                    ContextValuesMarshaller.ConvertParam <string>(param5),
                                    ContextValuesMarshaller.ConvertParam <bool>(param6)));
     }
 }
Example #17
0
        private void CallRoutesRegistrationHandler(string handler)
        {
            var handlerIndex = GetScriptMethod(handler);

            var routesCol = new RoutesCollectionContext();

            CallScriptMethod(handlerIndex, new IValue[] { routesCol });

            _startupBuilder.UseMvc(routes =>
            {
                foreach (var route in routesCol)
                {
                    routes.MapRoute(route.Name, route.Template, route.Defaults?.Select(x =>
                    {
                        var kv = new KeyValuePair <string, object>(x.Key.AsString(), ContextValuesMarshaller.ConvertToCLRObject(x.Value));
                        return(kv);
                    }));
                }
            });
        }
Example #18
0
        public static IRuntimeContextInstance Constructor(IValue dateFractions = null)
        {
            var paramDateFractions = ContextValuesMarshaller.ConvertParam <DateFractionsEnum>(dateFractions);

            return(new DateQualifiers(paramDateFractions));
        }