Exemple #1
0
        private TileData AssembleTileData(ArrayModel array, AssemblyContext context)
        {
            TileData data = new TileData(Width, Height);

            data.Assemble(array, context);
            return(data);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var array = new ArrayModel();

            array.UseArrayFamily();
            Console.ReadLine();
        }
Exemple #3
0
        public override AnimationCurve AssembleValue(ObjectModel value, AssemblyContext context)
        {
            ArrayModel     array = value.GetProperty <ArrayModel>("Keyframes");
            AnimationCurve curve = new AnimationCurve(array.Select(x => AssembleKeyframe(x as ObjectModel)).ToArray());

            return(curve);
        }
Exemple #4
0
        public void Extract_TableWithRows_ShouldMapToArrayOfElements()
        {
            // Arrange
            var          tableHandle = (IntPtr)3334;
            var          rowHandle   = (IntPtr)4445;
            uint         rowCount    = 3;
            int          intValue    = 888;
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.GetTable(It.IsAny <IntPtr>(), It.IsAny <string>(), out tableHandle, out errorInfo));
            _interopMock.Setup(x => x.GetRowCount(It.IsAny <IntPtr>(), out rowCount, out errorInfo));
            _interopMock.Setup(x => x.GetCurrentRow(It.IsAny <IntPtr>(), out errorInfo)).Returns(rowHandle);
            _interopMock.Setup(x => x.GetInt(It.IsAny <IntPtr>(), It.IsAny <string>(), out intValue, out errorInfo));

            // Act
            ArrayModel result = OutputMapper.Extract <ArrayModel>(_interopMock.Object, DataHandle);

            // Assert
            _interopMock.Verify(
                x => x.GetTable(DataHandle, "ELEMENTS", out tableHandle, out errorInfo),
                Times.Once);
            _interopMock.Verify(
                x => x.GetRowCount(tableHandle, out rowCount, out errorInfo),
                Times.Once);
            _interopMock.Verify(
                x => x.GetCurrentRow(tableHandle, out errorInfo),
                Times.Exactly(3));
            _interopMock.Verify(
                x => x.GetInt(rowHandle, "VALUE", out intValue, out errorInfo),
                Times.Exactly(3));
            _interopMock.Verify(x => x.MoveToNextRow(tableHandle, out errorInfo), Times.Exactly(3));
            result.Should().NotBeNull();
            result.Elements.Should().HaveCount(3);
            result.Elements.First().Value.Should().Be(888);
        }
Exemple #5
0
        public object Assemble(ValueModel model, Type expectedType, AssemblyContext context)
        {
            ArrayModel array       = model as ArrayModel;
            Type       elementType = GetElementType(expectedType);
            bool       isList      = IsList(expectedType);

            object     list = Activator.CreateInstance(typeof(List <>).MakeGenericType(elementType));
            MethodInfo add  = list.GetType().GetMethod("Add");

            // I barfed a little writing that.

            for (int i = 0; i < array.Length; i++)
            {
                add.Invoke(list, new object[] { _elementAssembler.Assemble(array[i], array.IsTypeImplicit ? elementType : array[i].GetModelType(), context) });
            }

            if (isList)
            {
                return(list);
            }
            else
            {
                MethodInfo toArray = list.GetType().GetMethod("ToArray");
                return(toArray.Invoke(list, new object[] { }));
            }
        }
        public void Extract_TableWithLessRowsThanAnnounced_ShouldReturnExtractedRows()
        {
            // Arrange
            var          tableHandle = (IntPtr)3334;
            var          rowHandle   = (IntPtr)4445;
            uint         rowCount    = 3;
            int          intValue    = 888;
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.GetTable(It.IsAny <IntPtr>(), It.IsAny <string>(), out tableHandle, out errorInfo));
            _interopMock.Setup(x => x.GetRowCount(It.IsAny <IntPtr>(), out rowCount, out errorInfo));
            _interopMock.Setup(x => x.MoveToFirstRow(It.IsAny <IntPtr>(), out errorInfo));
            _interopMock.Setup(x => x.GetCurrentRow(It.IsAny <IntPtr>(), out errorInfo)).Returns(rowHandle);
            _interopMock.Setup(x => x.GetInt(It.IsAny <IntPtr>(), It.IsAny <string>(), out intValue, out errorInfo));

            _interopMock
            .Setup(x => x.MoveToNextRow(It.IsAny <IntPtr>(), out errorInfo))
            .Returns(RfcResultCode.RFC_TABLE_MOVE_EOF);

            // Act
            ArrayModel result = OutputMapper.Extract <ArrayModel>(_interopMock.Object, DataHandle);

            // Assert
            result.Should().NotBeNull();
            result.Elements.Should().HaveCount(1);
        }
 public int[] ArrayDouble(ArrayModel array)
 {
     int[] result = new int[array.Numbers.Count()];
     for (int i = 0; i < array.Numbers.Count(); i++)
     {
         result[i] = array.Numbers[i] * 2;
     }
     return(result);
 }
        public IActionResult SortArray([FromBody] ArrayModel Array)
        {
            var hosts = HttpContext.Request.Host;

            _Apiloger.LogDebug($"{hosts.Host}正在请求 端口是 {hosts.Port},{hosts.Value}");
            var arrays = _compareMoneyInterface.SortThisArray(Array.Array);

            return(Ok(new SucessModelData(arrays)));
        }
        public int ArrayMultiply(ArrayModel array)
        {
            int result = 1;

            for (int i = 0; i < array.Numbers.Count(); i++)
            {
                result *= array.Numbers[i];
            }
            return(result);
        }
        private async Task <LoadMoreItemsResult> LoadMoreTask(uint count)
        {
            uint resultCount = 0;

            try
            {
                ArrayModel <T> data = null;
                try
                {
                    IsLoading = true;
                    data      = await Source(_maxid);
                }
                catch (MastodonException e)
                {
                    Notification.Show(e.Message);
                    IsError = true;
                }
                catch (Exception e)
                {
#if DEBUG
                    Notification.Show(e.Message);
#endif
                    IsError = true;
                }

                if (data != null && data.Result.Any())
                {
                    resultCount = (uint)data.Result.Count();

                    foreach (var item in data.Result)
                    {
                        Add(item);
                    }
                    _maxid = data.MaxId;
                }
                else
                {
                    HasMoreItems = false;
                }
            }
            finally
            {
                IsLoading = false;

                if (_refreshOnLoad)
                {
                    _refreshOnLoad = false;
                    Refresh();
                }
            }

            return(new LoadMoreItemsResult {
                Count = resultCount
            });
        }
        public IActionResult ArrayTest([FromForm] ArrayModel model)
        {
            var success = model?.Items?.Length == ArrayModel.SampleItems.Length;

            if (success)
            {
                return(Ok(new { success, message = "Array model lengths match." }));
            }

            return(BadRequest(new { success, error = "Array model lengths do not match." }));
        }
        public void Configure_Array()
        {
            SutEngine.Configure<ArrayModel>()
                .For(x => x.ArrayChildren, x => x.MatchUsing(y => y.Id));

            var oldModel = new ArrayModel()
            {
                Id = 1,
                ArrayChildren = new[]
                {
                    new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1",
                        Value = 100
                    },
                    new GrandChildModel()
                    {
                        Id = 200,
                        Name = "Name 2",
                        Value = 200
                    }
                },
            };

            var newModel = new ArrayModel()
            {
                Id = 1,
                ArrayChildren = new[]
                {
                    new GrandChildModel()
                    {
                        Id = 100,
                        Name = "Name 1",
                        Value = 100
                    },
                    new GrandChildModel()
                    {
                        Id = 300,
                        Name = "Name 3",
                        Value = 300
                    }
                },
            };

            var diff = SutEngine.Compare(oldModel, newModel);
            Assert.AreEqual(6, diff.Count);
        }
Exemple #13
0
        internal ArrayModel GetArrayModel(Type type)
        {
            TypeModel model;

            if (!_arrayModels.TryGetValue(type, out model))
            {
                model = GetTypeModel(type);
                if (!(model is ArrayModel))
                {
                    TypeDesc typeDesc = _typeScope.GetArrayTypeDesc(type);
                    model = new ArrayModel(type, typeDesc, this);
                }
                _arrayModels.Add(type, model);
            }
            return((ArrayModel)model);
        }
 public IActionResult Arrays([FromBody] ArrayModel array)
 {
     if (array.What == "sum")
     {
         return(Json(new { result = homeService.ArraySum(array) }));
     }
     else if (array.What == "multiply")
     {
         return(Json(new { result = homeService.ArrayMultiply(array) }));
     }
     else if (array.What == "double")
     {
         return(Json(new { result = homeService.ArrayDouble(array) }));
     }
     return(null);
 }
Exemple #15
0
        public ActionResult Array()
        {
            ArrayListModel array = new ArrayListModel();

            array.Array = new List <ArrayModel>();
            ArrayModel am;

            for (int i = 1; i < 5; i++)
            {
                am = new ArrayModel()
                {
                    intCol = i, stringCol = "Hello" + i, intCol2 = i * 2
                };
                array.Array.Add(am);
            }
            return(View(array));
        }
Exemple #16
0
        internal TypeModel GetTypeModel(Type type, bool directReference)
        {
            TypeModel model;

            if (_models.TryGetValue(type, out model))
            {
                return(model);
            }
            TypeDesc typeDesc = _typeScope.GetTypeDesc(type, null, directReference);

            switch (typeDesc.Kind)
            {
            case TypeKind.Enum:
                model = new EnumModel(type, typeDesc, this);
                break;

            case TypeKind.Primitive:
                model = new PrimitiveModel(type, typeDesc, this);
                break;

            case TypeKind.Array:
            case TypeKind.Collection:
            case TypeKind.Enumerable:
                model = new ArrayModel(type, typeDesc, this);
                break;

            case TypeKind.Root:
            case TypeKind.Class:
            case TypeKind.Struct:
                model = new StructModel(type, typeDesc, this);
                break;

            default:
                if (!typeDesc.IsSpecial)
                {
                    throw new NotSupportedException(SR.Format(SR.XmlUnsupportedTypeKind, type.FullName));
                }
                model = new SpecialModel(type, typeDesc, this);
                break;
            }

            _models.Add(type, model);
            return(model);
        }
Exemple #17
0
        private ArrayMapping ImportArrayLikeMapping(ArrayModel model, RecursionLimiter limiter)
        {
            ArrayMapping mapping = new ArrayMapping();

            mapping.IsSoap = true;
            TypeMapping itemTypeMapping = ImportTypeMapping(model.Element, limiter);

            if (itemTypeMapping.TypeDesc.IsValueType && !itemTypeMapping.TypeDesc.IsPrimitive && !itemTypeMapping.TypeDesc.IsEnum)
            {
                throw new NotSupportedException(SR.Format(SR.XmlRpcArrayOfValueTypes, model.TypeDesc.FullName));
            }

            mapping.TypeDesc = model.TypeDesc;
            mapping.Elements = new ElementAccessor[] {
                CreateElementAccessor(itemTypeMapping, mapping.Namespace)
            };
            SetArrayMappingType(mapping);

            // in the case of an ArrayMapping we can have more that one mapping correspond to a type
            // examples of that are ArrayList and object[] both will map tp ArrayOfur-type
            // so we create a link list for all mappings of the same XSD type
            ArrayMapping existingMapping = (ArrayMapping)_types[mapping.TypeName, mapping.Namespace];

            if (existingMapping != null)
            {
                ArrayMapping first = existingMapping;
                while (existingMapping != null)
                {
                    if (existingMapping.TypeDesc == model.TypeDesc)
                    {
                        return(existingMapping);
                    }
                    existingMapping = existingMapping.Next;
                }
                mapping.Next = first;
                _types[mapping.TypeName, mapping.Namespace] = mapping;
                return(mapping);
            }
            _typeScope.AddTypeMapping(mapping);
            _types.Add(mapping.TypeName, mapping.Namespace, mapping);
            IncludeTypes(model.Type);
            return(mapping);
        }
Exemple #18
0
        public IActionResult ArrayModifier([FromBody] ArrayModel toModify)
        {
            if (toModify.what == "sum")
            {
                int[] toSum  = toModify.numbers;
                int   summed = toSum.Sum();
                return(Json(new
                {
                    result = summed
                }));
            }
            else if (toModify.what == "multiply")
            {
                int[] toMultiply = toModify.numbers;
                int   multiplied = 1;
                foreach (int value in toMultiply)
                {
                    multiplied *= value;
                }
                return(Json(new
                {
                    result = multiplied
                }));
            }
            else if (toModify.what == "double")
            {
                int[] toDouble = toModify.numbers;
                for (int i = 0; i < toDouble.Length; i++)
                {
                    toDouble[i] *= 2;
                }

                return(Json(new { result = toDouble }));
            }
            else
            {
                return(Json(new { error = "Please provide what to do with the numbers!" }));
            }
        }
        public void Extract_TableWithZeroRows_ShouldNotCallMoveToFirstRow()
        {
            // Arrange
            var          tableHandle = (IntPtr)3334;
            var          rowHandle   = (IntPtr)4445;
            uint         rowCount    = 0;
            RfcErrorInfo errorInfo;

            _interopMock.Setup(x => x.GetTable(It.IsAny <IntPtr>(), It.IsAny <string>(), out tableHandle, out errorInfo));
            _interopMock.Setup(x => x.GetRowCount(It.IsAny <IntPtr>(), out rowCount, out errorInfo));
            _interopMock.Setup(x => x.MoveToFirstRow(It.IsAny <IntPtr>(), out errorInfo));
            _interopMock.Setup(x => x.GetCurrentRow(It.IsAny <IntPtr>(), out errorInfo)).Returns(rowHandle);

            _interopMock
            .Setup(x => x.MoveToNextRow(It.IsAny <IntPtr>(), out errorInfo))
            .Returns(RfcResultCode.RFC_TABLE_MOVE_EOF);

            // Act
            ArrayModel result = OutputMapper.Extract <ArrayModel>(_interopMock.Object, DataHandle);

            // Assert
            _interopMock.Verify(
                x => x.GetTable(DataHandle, "ELEMENTS", out tableHandle, out errorInfo),
                Times.Once);
            _interopMock.Verify(
                x => x.GetRowCount(tableHandle, out rowCount, out errorInfo),
                Times.Once);
            _interopMock.Verify(
                x => x.MoveToFirstRow(tableHandle, out errorInfo),
                Times.Never);
            _interopMock.Verify(
                x => x.GetCurrentRow(tableHandle, out errorInfo),
                Times.Never);
            _interopMock.Verify(x => x.MoveToNextRow(tableHandle, out errorInfo), Times.Never);
            result.Should().NotBeNull();
            result.Elements.Should().HaveCount(0);
        }
Exemple #20
0
 public IActionResult Post(ArrayModel arrayModel)
 {
     myArray = arrayModel.MyArray;
     Array.Sort(myArray);
     return(Ok(myArray));
 }
        protected override JToken SerializeWithoutMetadata(ValueModel model)
        {
            ArrayModel arrayModel = model as ArrayModel;

            return(new JArray(arrayModel.Elements.Select(x => _internalSerializer.Serialize(x))));
        }
Exemple #22
0
 public static void ReadVox(Stream stream, out ArrayModel model, out uint[] palette)
 {
     ReadVox(stream, out byte[][][] m, out palette);
     model = new ArrayModel(m);
 }
        public int ArraySum(ArrayModel array)
        {
            int summa = array.Numbers.Sum();

            return(summa);
        }