コード例 #1
0
        public void GenerateHexFile(string path, bool splitWithLowHigh = false)
        {
            if (splitWithLowHigh)
            {
                GenerateLowHighHexFile(path);
                return;
            }

            MessageManager.ShowLine($"Entry point is 0x{ StartupAddress.ToString("X8") } (by word address)", enumMessageLevel.ProgressLog);

            StringBuilder sb          = new StringBuilder();
            string        displayFmt  = IsSixteenBitArch ? "X4" : "X8";
            uint          displayMask = IsSixteenBitArch ? 0xFFFF : 0xFFFFFFFF;
            int           i           = 0;

            {
                MemoryContent content = MemoryContents[i];
                for (int addr = 0; addr < content.WordCapacity; addr++)
                {
                    sb.AppendLine($"{(content.Words[addr].InitialValue & displayMask).ToString(displayFmt)}{ ((content.GetDebugInfo(addr).DebugInfo != null && false) ? ("  # " + content.GetDebugInfo(addr).DebugInfo) : "") } ");
                }
            }

            System.IO.File.WriteAllText(path, sb.ToString());
        }
コード例 #2
0
        public void Test()
        {
            var factroy       = new AnimatedCursorFactroy();
            var memoryContent = new MemoryContent();
            var defaultCursor = new AnimatedCursor(defaultConfig, defaultTextures);

            using (memoryContent.BeginUpdateAuto())
            {
                factroy.Write(memoryContent, defaultCursor);
            }

            var cursor2 = factroy.Read(memoryContent);

            Assert.AreEqual(defaultConfig, cursor2.Config);
            AreEqual(defaultTextures, cursor2.Textures);
        }
コード例 #3
0
        public void Test()
        {
            var factroy       = new StaticCursorFactroy();
            var memoryContent = new MemoryContent();
            var defaultCursor = new StaticCursor(defaultTexture, defaultConfig);

            using (memoryContent.BeginUpdateAuto())
            {
                factroy.Write(memoryContent, defaultCursor);
            }

            var cursor2 = factroy.Read(memoryContent);

            Assert.AreEqual(defaultConfig, cursor2.Config);
            Assert.AreEqual(defaultTexture.width, cursor2.Texture.width);
            Assert.AreEqual(defaultTexture.height, cursor2.Texture.height);
        }
コード例 #4
0
        void UpdateOrientation()
        {
            var columns = 6;

            if (Orientation == StackOrientation.Vertical)
            {
                SiloContent.SetGridColumn(0, columns);
                SiloContent.SetGridRow(0, 1);

                //VersionContent.SetGridColumn (0, columns);
                //VersionContent.SetGridRow (1, 1);

                ActivationsContent.SetGridColumn(0, columns);
                ActivationsContent.SetGridRow(1, 1);

                CPUContent.SetGridColumn(0, columns);
                CPUContent.SetGridRow(2, 1);

                MemoryContent.SetGridColumn(0, columns);
                MemoryContent.SetGridRow(3, 1);

                GrainContent.SetGridColumn(0, columns);
                GrainContent.SetGridRow(4, 1);
            }
            else
            {
                SiloContent.SetGridColumn(0, 1);
                SiloContent.SetGridRow(0, columns);

                //VersionContent.SetGridColumn (1, 1);
                //VersionContent.SetGridRow (0, columns);

                ActivationsContent.SetGridColumn(1, 1);
                ActivationsContent.SetGridRow(0, columns);

                CPUContent.SetGridColumn(2, 1);
                CPUContent.SetGridRow(0, columns);

                MemoryContent.SetGridColumn(3, 1);
                MemoryContent.SetGridRow(0, columns);

                GrainContent.SetGridColumn(4, 1);
                GrainContent.SetGridRow(0, columns);
            }
        }
コード例 #5
0
        public void ReadWriteTest()
        {
            BindingSerializer <File> serializer = new BindingSerializer <File>();
            MemoryContent            content    = new MemoryContent();
            var file = DefalutFile;

            using (content.BeginUpdateAuto())
            {
                serializer.Serialize(content, ref file);
            }

            Assert.True(content.Contains(nameof(File.XmlTest)));
            Assert.True(content.Contains(nameof(File.ProtoTest)));
            Assert.IsFalse(content.Contains(nameof(File.IgnoreField)));

            var value = serializer.Deserialize(content) as File;

            Assert.AreEqual(file, value);
        }
コード例 #6
0
        public void GenerateLowHighHexFile(string pathWithoutExt)
        {
            int extLength = System.IO.Path.GetExtension(pathWithoutExt).Length;

            if (extLength > 0)
            {
                pathWithoutExt = pathWithoutExt.Remove(pathWithoutExt.Length - extLength);
            }

            MessageManager.ShowLine($"Entry point is 0x{ StartupAddress.ToString("X8") } (by word address)", enumMessageLevel.ProgressLog);
            {
                StringBuilder sb = new StringBuilder();
                int           i  = 0;
                {
                    MemoryContent content = MemoryContents[i];
                    for (int addr = 0; addr < content.WordCapacity; addr++)
                    {
                        uint val = content.Words[addr].InitialValue;
                        sb.AppendLine($"{((val >> 16) & 0xFFFF).ToString("X4")}{ ((content.GetDebugInfo(addr, 2, 0).DebugInfo != null && false) ? ("  # " + content.GetDebugInfo(addr, 2, 0).DebugInfo) : "") } ");
                    }
                }
                System.IO.File.WriteAllText(pathWithoutExt + "_h.hex", sb.ToString());
            }
            {
                StringBuilder sb = new StringBuilder();
                int           i  = 0;
                {
                    MemoryContent content = MemoryContents[i];
                    for (int addr = 0; addr < content.WordCapacity; addr++)
                    {
                        uint val = content.Words[addr].InitialValue;
                        sb.AppendLine($"{(val & 0xFFFF).ToString("X4")}{ ((content.GetDebugInfo(addr, 2, 1).DebugInfo != null&&false) ? ("  # " + content.GetDebugInfo(addr, 2, 1).DebugInfo) : "") } ");
                    }
                }
                System.IO.File.WriteAllText(pathWithoutExt + "_l.hex", sb.ToString());
            }
        }
コード例 #7
0
        public static void Run()
        {
            var compiler = new HandlerCompiler();

            compiler.Register <Object1>(new Object1());//Singleton
            compiler.Register <Object2>(() => new Object2());
            compiler.Register <IHttp2Pusher>(req => req.Pusher());
            compiler.RegisterAsync <AsyncObject>(async(req) =>
            {
                await Task.Delay(1000);
                return(new AsyncObject());
            });
            //泛型
            //Generic
            compiler.Register((type, req) =>
            {
                if (!type.IsGenericType || type.GetGenericTypeDefinition() != typeof(GenericObject <>))
                {
                    return(null);
                }

                var ctor = type.GetConstructor(Type.EmptyTypes);
                return(Expression.New(ctor));
            });

            compiler.RegisterParameterAsync <string>(p => p.Name == "test", async(req) =>
            {
                await Task.CompletedTask;
                return("this is string1");
            });

            compiler.RegisterProperty <string>(p => p.Name == "TestString", _ => "this is string2");

            //compiler.RegisterParameter();
            //compiler.RegisterProperty();

            compiler.RegisterReturn <string>((value, req, resp) =>
            {
                resp.Headers.Add(HttpHeaders.ContentType, "text/plain");
                resp.Content = StringContent.Create(value);
            });
            compiler.RegisterReturnAsync <byte[]>(async(value, req, resp) =>
            {
                await Task.CompletedTask;
                resp.Headers[HttpHeaders.ContentType] = "application/octet-stream";
                resp.Content = MemoryContent.Create(value);
            });


            var h1          = compiler.Compile(typeof(TestService).GetMethod("Test1"));
            var pathParams1 = new PathParams()
            {
                { "pathParam1", "ZhangHe" },
                { "pathParam2", "9999" }
            };
            var req1  = new HttpRequest().PathParams(pathParams1);
            var resp1 = h1.HandleAsync(req1).Result;

            Console.WriteLine();
            Console.WriteLine();
            var h2    = compiler.Compile(typeof(TestService).GetMethod("Test2"));
            var resp2 = h2.HandleAsync(new HttpRequest()).Result;

            Console.WriteLine($"Content:{resp2.Content.ReadStringAsync().Result}");

            Console.WriteLine();
            Console.WriteLine();
            var h3    = compiler.Compile(typeof(TestService).GetMethod("Test3"));
            var resp3 = h3.HandleAsync(new HttpRequest()).Result;

            Console.WriteLine($"Content:{resp3.Content.ReadStringAsync().Result}");

            Console.WriteLine();
            Console.WriteLine();
            var h4    = compiler.Compile(typeof(TestService).GetMethod("Test4"));
            var resp4 = h4.HandleAsync(new HttpRequest()).Result;

            Console.WriteLine($"Content:{resp4.Content.ReadStringAsync().Result}");

            Console.WriteLine();
            Console.WriteLine();
            var h5    = compiler.Compile(typeof(TestService2).GetMethod("Test"));
            var resp5 = h1.HandleAsync(new HttpRequest()).Result;

            foreach (var item in resp5.Headers)
            {
                Console.WriteLine($"{item.Key}={item.Value}");
            }


            //------------------------------------------------------------------------

            var compiler1 = new HandlerCompiler();

            QueryParamAttribute.Register(compiler1);
            QueryParamsAttribute.Register(compiler1);
            QueryAndFormAttribute.Register(compiler1);

            Console.WriteLine();
            Console.WriteLine();
            var h6           = compiler1.Compile(typeof(TestService).GetMethod("Test5"));
            var queryParams6 = new QueryParams()
            {
                { "Name", "ZhangSan" },
                { "Age", "100" }
            };
            var req6  = new HttpRequest().QueryParams(queryParams6);
            var resp6 = h6.HandleAsync(req6).Result;

            Console.WriteLine();
            Console.WriteLine();
            var h7          = compiler1.Compile(typeof(TestService).GetMethod("Test6"));
            var queryParam7 = new QueryParams()
            {
                { "Name", "ZhangSan" }
            };
            var formParams7 = new FormParams()
            {
                { "Age", "100" }
            };
            var req7  = new HttpRequest().QueryParams(queryParam7).FormParams(formParams7);
            var resp7 = h7.HandleAsync(req7).Result;
        }