Пример #1
0
        public void CreateStaticFile()
        {
            if (System.IO.Directory.Exists("tmp"))
            {
                System.IO.Directory.Delete("tmp", true);
            }

            System.IO.Directory.CreateDirectory("tmp");
            foreach (var i in Enumerable.Range(0, 1000))
            {
                System.IO.File.Copy("../../Core/TestData/IO/test.txt", "tmp/test" + i + ".txt");
            }
            Assert.True(Engine.Initialize("Altseed2 C# Engine", 800, 600, new Configuration()));

            var font = Font.LoadDynamicFont("../../Core/TestData/Font/mplus-1m-regular.ttf", 100);

            Assert.NotNull(font);

            var node = new TextNode()
            {
                Font = font, Text = ""
            };

            Engine.AddNode(node);

            var tasks = new List <Task <StaticFile> >();

            foreach (var i in Enumerable.Range(0, 1000))
            {
                tasks.Add(StaticFile.CreateAsync("tmp/test" + i + ".txt"));
            }

            while (Engine.DoEvents())
            {
                node.Text = $"Static File: {tasks.Count(obj => obj.IsCompleted)}/{tasks.Count()}";
                Assert.True(Engine.Update());

                if (tasks.All(obj => obj.IsCompleted))
                {
                    break;
                }
            }

            foreach (var i in Enumerable.Range(0, 1000))
            {
                Assert.AreEqual(tasks[0].Result.Size, tasks[i].Result.Size);
            }

            Engine.Terminate();
        }
Пример #2
0
        public void CreateStaticFile()
        {
            if (System.IO.Directory.Exists("tmp"))
            {
                System.IO.Directory.Delete("tmp", true);
            }

            System.IO.Directory.CreateDirectory("tmp");
            foreach (var i in Enumerable.Range(0, 1000))
            {
                System.IO.File.Copy("TestData/IO/test.txt", "tmp/test" + i + ".txt");
            }
            var tc = new TestCore();

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 64);

            Assert.NotNull(font);

            var node = new TextNode()
            {
                Font = font, FontSize = 80, Text = ""
            };

            Engine.AddNode(node);

            // TODO : improve performance
            int  itemnum = 100;
            bool dogc    = true;

            var tasks = new List <Task <StaticFile> >();

            foreach (var i in Enumerable.Range(0, itemnum))
            {
                if (i % 10 == 0 && dogc)
                {
                    Thread.Sleep(10);
                    Assert.True(Engine.Update());
                }

                tasks.Add(StaticFile.CreateAsync("tmp/test" + i + ".txt"));
            }

            while (Engine.DoEvents())
            {
                node.Text = $"Static File: {tasks.Count(obj => obj.IsCompleted)}/{tasks.Count()}";
                Assert.True(Engine.Update());

                if (tasks.All(obj => obj.IsCompleted))
                {
                    break;
                }
            }

            foreach (var i in Enumerable.Range(0, itemnum))
            {
                Assert.AreEqual(tasks[0].Result.Size, tasks[i].Result.Size);
            }

            tc.End();
        }