示例#1
0
        public static void Main(String[] args)
        {
            Console.WriteLine("_________________________________Task 1_________________________________");
            int[] numbers = NewArrayWithRandomValues.GenerateArray(5);
            NewArrayWithRandomValues.PrintArray(numbers);
            int sum = NewArrayWithRandomValues.CalculateSum(numbers);

            Console.WriteLine($"sum of array elements is {sum}");

            Console.WriteLine("_________________________________Task 2_________________________________");
            TuttiFrutti.outputValues();

            Console.WriteLine("_________________________________Task 3_________________________________");
            int value = SumProgram.ReadValue();
            int sum1  = SumProgram.CountValue(value);

            Console.WriteLine($"the sum of numbers between {value} and 0 is {sum1}");

            Console.WriteLine("_________________________________Task 4_________________________________");
            int f1 = Arithmetical.ReadFirstNumber();
            int f2 = Arithmetical.ReadSecondNumber();

            Arithmetical.SumOfTheNumbers(f1, f2);
            Arithmetical.MultiplicationOfTheNumbers(f1, f2);
            Arithmetical.DivisionOfTheNumbers(f1, f2);

            Console.WriteLine("_________________________________Task 5_________________________________");
            int arraySize = ArrayHandler.ScanArraySize();

            int[] array = ArrayHandler.FillArray(arraySize);
            ArrayHandler.ValidateIfTheSequenseIsAscending(array);
        }
        protected override void Handle(BuildingRebuildCommand command)
        {
            IgnoreHelper.StartIgnore();

            // Using a delegate object because the 'OnRebuildClicked' delegate contains most of the needed code
            // This code from the CityServiceWorldInfoPanel is the same as in the EventBuildingWorldInfoPanel,
            // UniqueFactoryWorldInfoPanel and WarehouseWorldInfoPanel
            if (delegateType == null)
            {
                delegateType           = typeof(CityServiceWorldInfoPanel).GetNestedType("<OnRebuildClicked>c__AnonStorey2", ReflectionHelper.AllAccessFlags);
                rebuildClickedDelegate = Activator.CreateInstance(delegateType);
            }

            ReflectionHelper.SetAttr(rebuildClickedDelegate, "buildingID", command.Building);

            ArrayHandler.StartApplying(command.Array16Ids, null);

            FetchResource.DontFetchResource = true;

            delegateType.GetMethod("<>m__0", ReflectionHelper.AllAccessFlags)?.Invoke(rebuildClickedDelegate, null);

            FetchResource.DontFetchResource = false;

            ArrayHandler.StopApplying();

            IgnoreHelper.EndIgnore();
        }
        public ActionResult <ArrayHandler> ArrayHandler([FromBody] ArrayHandler input)
        {
            if (input.What.ToLower() == "sum")
            {
                input.Result = _frontendService.ArraySum(input.Numbers).ToString();
            }
            else if (input.What.ToLower() == "multiply")
            {
                input.Result = _frontendService.ArrayMultiply(input.Numbers).ToString();
            }
            else if (input.What.ToLower() == "double")
            {
                input.Result = _frontendService.ArrayDouble(input.Numbers).ToString();
            }
            else
            {
                input.Error = "Please provide what to do with the numbers!";
            }

            Log log = new Log()
            {
                CreatedAt = DateTime.Now,
                Data      = $"what: {input.What} " +
                            $"numbers: {input.Numbers} result: " +
                            $"{input.Result} error: {input.Error}",
                Endpoint = "/arrays"
            };

            _logService.Add(log);
            return(input);
        }
示例#4
0
        public IActionResult Array([FromBody] ArrayHandler data)
        {
            if (!string.IsNullOrEmpty(data.What) && data.Numbers.Length > 0)
            {
                int tmp = 0;
                switch (data.What)
                {
                case "sum":
                    for (int i = 0; i < data.Numbers.Length; i++)
                    {
                        tmp += data.Numbers[i];
                    }
                    return(Json(new { result = tmp }));

                case "multiply":
                    tmp = 1;
                    for (int i = 0; i < data.Numbers.Length; i++)
                    {
                        tmp *= data.Numbers[i];
                    }
                    return(Json(new { result = tmp }));

                case "double":
                    for (int i = 0; i < data.Numbers.Length; i++)
                    {
                        data.Numbers[i] = data.Numbers[i] * 2;
                    }
                    return(Json(new { result = data.Numbers }));
                }
            }
            return(Json(new { error = "Please provide what to do with the numbers!" }));
        }
 public PreparedArrayContainsComparison(IContext context, ArrayHandler arrayHandler
                                        , ITypeHandler4 typeHandler, object obj)
 {
     _arrayHandler       = arrayHandler;
     _preparedComparison = Handlers4.PrepareComparisonFor(typeHandler, context, obj);
     _container          = context.Transaction().Container();
 }
        protected override void Handle(TransportLineCreateCommand command)
        {
            TransportTool tool = ToolSimulator.GetTool <TransportTool>(command.SenderId);

            ArrayHandler.StartApplying(command.Array16Ids, null);

            tool.m_prefab = PrefabCollection <TransportInfo> .GetPrefab(command.Prefab);

            ReflectionHelper.SetAttr(tool, "m_building", command.Building);

            IgnoreHelper.StartIgnore();

            int mode = ReflectionHelper.GetEnumValue(typeof(TransportTool).GetNestedType("Mode", ReflectionHelper.AllAccessFlags), "NewLine");

            ReflectionHelper.SetAttr(tool, "m_mode", mode);
            ReflectionHelper.SetAttr(tool, "m_errors", ToolBase.ToolErrors.None);

            IEnumerator newLine = (IEnumerator)ReflectionHelper.Call(tool, "NewLine");

            newLine.MoveNext();

            IgnoreHelper.EndIgnore();

            ArrayHandler.StopApplying();
        }
        protected override void Handle(BuildingToolCreateCommand command)
        {
            BuildingTool tool = ToolSimulator.GetTool <BuildingTool>(command.SenderId);

            IgnoreHelper.StartIgnore();
            ArrayHandler.StartApplying(command.Array16Ids, command.Array32Ids);

            BuildingInfo prefab = null;

            if (command.Relocate == 0)
            {
                prefab = PrefabCollection <BuildingInfo> .GetPrefab(command.Prefab);
            }

            tool.m_prefab   = prefab;
            tool.m_relocate = command.Relocate;

            ReflectionHelper.SetAttr(tool, "m_mousePosition", command.MousePosition);
            ReflectionHelper.SetAttr(tool, "m_mouseAngle", command.MouseAngle);
            ReflectionHelper.SetAttr(tool, "m_elevation", command.Elevation);
            ReflectionHelper.SetAttr(tool, "m_placementErrors", ToolBase.ToolErrors.None);
            ReflectionHelper.SetAttr(tool, "m_constructionCost", 0);

            ToolController controller = ReflectionHelper.GetAttr <ToolController>(tool, "m_toolController");

            ReflectionHelper.SetAttr(controller, "m_collidingSegments1", command.CollidingSegments);
            ReflectionHelper.SetAttr(controller, "m_collidingBuildings1", command.CollidingBuildings);
            ReflectionHelper.SetAttr(controller, "m_collidingDepth", 1);

            ReflectionHelper.Call <IEnumerator>(tool, "CreateBuilding")?.MoveNext();

            ArrayHandler.StopApplying();
            IgnoreHelper.EndIgnore();
        }
示例#8
0
        public void FindIndex_DifferentNumbers_Minus1Return()
        {
            var arr = new[] { 1, 2, 3, 4, 5, 2, 1 };

            int?actual = ArrayHandler.FindIndex(arr);

            Assert.AreEqual(null, actual);
        }
示例#9
0
        public void FindIndex_AllOnes_Minus1Return()
        {
            var arr = new[] { 1, 1, 1, 1 };

            int?actual = ArrayHandler.FindIndex(arr);

            Assert.AreEqual(null, actual);
        }
示例#10
0
        public void FindIndex_DifferentNumbers_1Return()
        {
            var arr    = new[] { 1, 100, 50, -51, 1, 1 };
            int expect = 1;

            int?actual = ArrayHandler.FindIndex(arr);

            Assert.AreEqual(expect, actual);
        }
示例#11
0
        protected virtual void TraverseArray(IReflectClass claxx, object array)
        {
            IEnumerator contents = ArrayHandler.Iterator(claxx, array);

            while (contents.MoveNext())
            {
                QueueUpForTraversing(contents.Current);
            }
        }
示例#12
0
        public void FindIndex_AllPositiveNumbers_3Return()
        {
            var arr    = new[] { 1, 2, 3, 4, 3, 2, 1 };
            int expect = 3;

            int?actual = ArrayHandler.FindIndex(arr);

            Assert.AreEqual(expect, actual);
        }
示例#13
0
        static void Main(string[] args)
        {
            string resposta;

            Console.WriteLine("QUESTÃO 1");
            Console.WriteLine("");
            Console.WriteLine("Digite '1' para usar o Array Padrão (Valores setados)");
            Console.WriteLine("Digite '2' para usar o Array Dinâmico (Valores dinâmicos)");

            Console.Write("Digite a opção desejada: ");
            resposta = Console.ReadLine();

            while (resposta != "1" && resposta != "2")
            {
                Console.WriteLine("Valor inválido");
                Console.WriteLine("Digite a opção entre 1 e 2");
                resposta = Console.ReadLine();
            }

            Console.WriteLine("============================================================");
            Console.WriteLine("");

            if (resposta == "1")
            {
                var arrayNumeros = ArrayHandler.RetornarArrayPadrao();
                Array.ForEach(arrayNumeros, numeros => Console.Write($"{numeros} "));
            }
            else
            {
                Console.Write("Digite o tamanho desejado para o Array (quantos números poderão ter dentro do array):");
                int tamanho      = int.Parse(Console.ReadLine());
                var arrayNumeros = ArrayHandler.RetornarArrayDinamico(tamanho);

                Array.ForEach(arrayNumeros, numeros => Console.Write($"{numeros} "));
            }

            Console.WriteLine("");
            Console.Write("Digite um valor ALVO, esse valor deve ser a soma de dois valores que estão no Array:");
            int alvo = int.Parse(Console.ReadLine());
            var indicesRetornados = ArrayHandler.RetornarIndices(alvo);

            Console.WriteLine("");
            Console.WriteLine("============================================================");
            if (indicesRetornados[0] == 0 && indicesRetornados[1] == 0)
            {
                Console.WriteLine("O valor ALVO não é a soma de nenhum dos valores no Array :(");
            }
            else
            {
                Console.WriteLine("Esses são os índices da soma desejada :");
                Array.ForEach(indicesRetornados, indices => Console.Write($"{indices} "));
                Console.WriteLine("");
                Console.WriteLine("");
                Console.WriteLine("============================================================");
            }
        }
        protected override void Handle(TransportLineReleaseCommand command)
        {
            IgnoreHelper.StartIgnore();
            ArrayHandler.StartApplying(command.Array16Ids, null);

            TransportManager.instance.ReleaseLine(command.Line);

            ArrayHandler.StopApplying();
            IgnoreHelper.EndIgnore();
        }
 public ActionResult Arrays([FromBody] ArrayHandler arrayHandler)
 {
     logServices.SaveToDatabase(new Log(HttpContext.Request.RouteValues["action"].ToString(), JsonSerializer.Serialize(arrayHandler)));
     if (arrayHandler == null || arrayHandler?.What == null || arrayHandler?.Numbers == null)
     {
         return(StatusCode(400, new { error = "Please provide what to do with the numbers!" }));
     }
     return(StatusCode(200, new { result = restServices.Calculate(arrayHandler) }));
     //return StatusCode(200, new { result = restServices.Calculate(arrayHandler) });
 }
        protected override void Handle(TransportLineMoveStopManCommand command)
        {
            IgnoreHelper.StartIgnore();
            ArrayHandler.StartApplying(command.Array16Ids, null);

            TransportManager.instance.m_lines.m_buffer[command.Line].MoveStop(command.Line, command.Index, command.NewPos, command.FixedPlatform);

            ArrayHandler.StopApplying();
            IgnoreHelper.EndIgnore();
        }
示例#17
0
        protected override void Handle(BuildingUpgradeCommand command)
        {
            IgnoreHelper.StartIgnore();
            ArrayHandler.StartApplying(command.Array16Ids, command.Array32Ids);

            BuildingManager.instance.UpgradeBuilding(command.Building);

            ArrayHandler.StopApplying();
            IgnoreHelper.EndIgnore();
        }
示例#18
0
        public void FindIndexTests()
        {
            var exceptionName     = string.Empty;
            var expectedException = TestContext.DataRow["ExpectedException"].GetType()
                                    != typeof(System.DBNull) ?
                                    Convert.ToString(TestContext.DataRow["ExpectedException"]) : string.Empty;;

            try
            {
                var info   = Convert.ToString(TestContext.DataRow["Array"]);
                var tokens = info.Split(' ');
                int size   = Convert.ToInt32(TestContext.DataRow["Count"]);
                var arr    = new int[size];
                int i      = 0;
                if (size > 0)
                {
                    foreach (var element in tokens)
                    {
                        arr[i++] = int.Parse(element);
                    }
                }

                int?actual = ArrayHandler.FindIndex(arr);
                int?expect;

                var value = TestContext.DataRow["ExpectedResult"];

                if (!value.Equals("null"))
                {
                    expect = Convert.ToInt32(value);
                }
                else
                {
                    expect = null;
                }

                Assert.AreEqual(expect, actual);
            }
            catch (Exception ex)
            {
                exceptionName = ex.GetType().ToString();

                expectedException = TestContext.DataRow["ExpectedException"].GetType()
                                    != typeof(System.DBNull) ?
                                    Convert.ToString(TestContext.DataRow["ExpectedException"]) : string.Empty;

                Assert.AreEqual(expectedException, exceptionName);
            }

            if (expectedException.Length > 0 && exceptionName.Length == 0)
            {
                Assert.Fail($"{expectedException} was expected, but was not thrown!");
            }
        }
示例#19
0
        public override void Handle(TreeCreateCommand command)
        {
            TreeInfo info = PrefabCollection <TreeInfo> .GetPrefab(command.InfoIndex);

            TreeHandler.IgnoreAll = true;
            ArrayHandler.StartApplying(null, new uint[] { command.TreeID });

            TreeManager.instance.CreateTree(out uint _, ref SimulationManager.instance.m_randomizer, info, command.Position, command.Single);
            ArrayHandler.StopApplying();
            TreeHandler.IgnoreAll = false;
        }
示例#20
0
        protected override void Handle(TreeCreateCommand command)
        {
            TreeInfo info = PrefabCollection <TreeInfo> .GetPrefab(command.InfoIndex);

            IgnoreHelper.StartIgnore();
            ArrayHandler.StartApplying(null, new uint[] { command.TreeId });

            TreeManager.instance.CreateTree(out uint _, ref SimulationManager.instance.m_randomizer, info, command.Position, command.Single);
            ArrayHandler.StopApplying();
            IgnoreHelper.EndIgnore();
        }
示例#21
0
        public override void Handle(PropCreateCommand command)
        {
            PropInfo info = PrefabCollection <PropInfo> .GetPrefab(command.infoindex);

            PropHandler.IgnoreAll = true;
            ArrayHandler.StartApplying(new ushort[] { command.PropID }, null);

            PropManager.instance.CreateProp(out ushort _, ref SimulationManager.instance.m_randomizer, info, command.position, command.angle, command.single);

            ArrayHandler.StopApplying();
            PropHandler.IgnoreAll = false;
        }
示例#22
0
        public override void Handle(NodeCreateCommand command)
        {
            NetInfo info = PrefabCollection <NetInfo> .GetPrefab(command.InfoIndex);

            NodeHandler.IgnoreAll = true;
            ArrayHandler.StartApplying(new ushort[] { command.NodeId }, null);

            NetManager.instance.CreateNode(out ushort _, ref SimulationManager.instance.m_randomizer, info, command.Position, SimulationManager.instance.m_currentBuildIndex++);

            ArrayHandler.StopApplying();
            NodeHandler.IgnoreAll = false;
        }
示例#23
0
        public override void Handle(SegmentCreateCommand command)
        {
            NetInfo info = PrefabCollection <NetInfo> .GetPrefab(command.InfoIndex);

            NodeHandler.IgnoreAll = true;
            ArrayHandler.StartApplying(new ushort[] { command.SegmentId }, null);

            NetManager.instance.CreateSegment(out ushort _, ref SimulationManager.instance.m_randomizer, info, command.StartNode, command.EndNode, command.StartDirection, command.EndDirection, SimulationManager.instance.m_currentBuildIndex++, command.ModifiedIndex, command.Invert);

            ArrayHandler.StopApplying();
            NodeHandler.IgnoreAll = false;
        }
示例#24
0
        protected override void Handle(PropCreateCommand command)
        {
            PropInfo info = PrefabCollection <PropInfo> .GetPrefab(command.InfoIndex);

            IgnoreHelper.StartIgnore();
            ArrayHandler.StartApplying(new ushort[] { command.PropId }, null);

            PropManager.instance.CreateProp(out ushort _, ref SimulationManager.instance.m_randomizer, info, command.Position, command.Angle, command.Single);

            ArrayHandler.StopApplying();
            IgnoreHelper.EndIgnore();
        }
示例#25
0
        public override void Handle(BuildingCreateCommand command)
        {
            BuildingInfo info = PrefabCollection <BuildingInfo> .GetPrefab(command.InfoIndex);

            BuildingHandler.IgnoreAll = true;
            ArrayHandler.StartApplying(new ushort[] { command.BuildingId }, null);

            BuildingManager.instance.CreateBuilding(out _, ref SimulationManager.instance.m_randomizer, info,
                                                    command.Position, command.Angle, command.Length, SimulationManager.instance.m_currentBuildIndex++);

            ArrayHandler.StopApplying();
            BuildingHandler.IgnoreAll = false;
        }
        protected override void Handle(BuildingCreateCommand command)
        {
            BuildingInfo info = PrefabCollection <BuildingInfo> .GetPrefab(command.InfoIndex);

            IgnoreHelper.StartIgnore();
            ArrayHandler.StartApplying(command.Array16Ids, command.Array32Ids);

            BuildingManager.instance.CreateBuilding(out _, ref SimulationManager.instance.m_randomizer, info,
                                                    command.Position, command.Angle, command.Length, SimulationManager.instance.m_currentBuildIndex++);

            ArrayHandler.StopApplying();
            IgnoreHelper.EndIgnore();
        }
        protected override void Handle(TransportLineResetCommand command)
        {
            TransportTool tool = ToolSimulator.GetTool <TransportTool>(command.SenderId);

            ArrayHandler.StartApplying(command.Array16Ids, null);

            IgnoreHelper.StartIgnore();

            ReflectionHelper.Call(tool, "ResetTool");

            IgnoreHelper.EndIgnore();

            ArrayHandler.StopApplying();
        }
        public virtual void TestCorrectHandlerVersion()
        {
            OpenTypeHandler openTypeHandler = new OpenTypeHandler(Container());

            AssertCorrectedHandlerVersion(typeof(OpenTypeHandler0), openTypeHandler, -1);
            AssertCorrectedHandlerVersion(typeof(OpenTypeHandler0), openTypeHandler, 0);
            AssertCorrectedHandlerVersion(typeof(OpenTypeHandler2), openTypeHandler, 1);
            AssertCorrectedHandlerVersion(typeof(OpenTypeHandler2), openTypeHandler, 2);
            AssertCorrectedHandlerVersion(typeof(OpenTypeHandler), openTypeHandler, HandlerRegistry
                                          .HandlerVersion);
            AssertCorrectedHandlerVersion(typeof(OpenTypeHandler), openTypeHandler, HandlerRegistry
                                          .HandlerVersion + 1);
            StandardReferenceTypeHandler stdReferenceHandler = new StandardReferenceTypeHandler
                                                                   (ItemClassMetadata());

            AssertCorrectedHandlerVersion(typeof(StandardReferenceTypeHandler0), stdReferenceHandler
                                          , 0);
            AssertCorrectedHandlerVersion(typeof(StandardReferenceTypeHandler), stdReferenceHandler
                                          , 2);
            PrimitiveTypeMetadata primitiveMetadata = new PrimitiveTypeMetadata(Container(),
                                                                                openTypeHandler, 0, null);

            AssertPrimitiveHandlerDelegate(typeof(OpenTypeHandler0), primitiveMetadata, 0);
            AssertPrimitiveHandlerDelegate(typeof(OpenTypeHandler2), primitiveMetadata, 1);
            AssertPrimitiveHandlerDelegate(typeof(OpenTypeHandler2), primitiveMetadata, 2);
            AssertPrimitiveHandlerDelegate(typeof(OpenTypeHandler), primitiveMetadata, HandlerRegistry
                                           .HandlerVersion);
            ArrayHandler arrayHandler = new ArrayHandler(openTypeHandler, false);

            AssertCorrectedHandlerVersion(typeof(ArrayHandler0), arrayHandler, 0);
            AssertCorrectedHandlerVersion(typeof(ArrayHandler1), arrayHandler, 1);
            AssertCorrectedHandlerVersion(typeof(ArrayHandler3), arrayHandler, 2);
            AssertCorrectedHandlerVersion(typeof(ArrayHandler3), arrayHandler, 3);
            AssertCorrectedHandlerVersion(typeof(ArrayHandler), arrayHandler, HandlerRegistry
                                          .HandlerVersion);
            ArrayHandler multidimensionalArrayHandler = new MultidimensionalArrayHandler(openTypeHandler
                                                                                         , false);

            AssertCorrectedHandlerVersion(typeof(MultidimensionalArrayHandler0), multidimensionalArrayHandler
                                          , 0);
            AssertCorrectedHandlerVersion(typeof(MultidimensionalArrayHandler3), multidimensionalArrayHandler
                                          , 1);
            AssertCorrectedHandlerVersion(typeof(MultidimensionalArrayHandler3), multidimensionalArrayHandler
                                          , 2);
            AssertCorrectedHandlerVersion(typeof(MultidimensionalArrayHandler3), multidimensionalArrayHandler
                                          , 3);
            AssertCorrectedHandlerVersion(typeof(MultidimensionalArrayHandler), multidimensionalArrayHandler
                                          , HandlerRegistry.HandlerVersion);
        }
        public static ITypeHandler4 CorrectHandlerVersion(IHandlerVersionContext context,
                                                          ITypeHandler4 typeHandler, ClassMetadata classMetadata)
        {
            ITypeHandler4 correctHandlerVersion = CorrectHandlerVersion(context, typeHandler);

            if (typeHandler != correctHandlerVersion)
            {
                CorrectClassMetadataOn(correctHandlerVersion, classMetadata);
                if (correctHandlerVersion is ArrayHandler)
                {
                    ArrayHandler arrayHandler = (ArrayHandler)correctHandlerVersion;
                    CorrectClassMetadataOn(arrayHandler.DelegateTypeHandler(), classMetadata);
                }
            }
            return(correctHandlerVersion);
        }
示例#30
0
        protected override void Handle(TransportLineTempCommand command)
        {
            TransportTool tool = ToolSimulator.GetTool <TransportTool>(command.SenderId);

            ArrayHandler.StartApplying(command.Array16Ids, null);

            TransportInfo info = PrefabCollection <TransportInfo> .GetPrefab(command.InfoIndex);

            IgnoreHelper.StartIgnore();

            ReflectionHelper.Call(tool, "EnsureTempLine", info, command.SourceLine, command.MoveIndex, command.AddIndex, command.AddPos, command.FixedPlatform);

            IgnoreHelper.EndIgnore();

            ArrayHandler.StopApplying();
        }