Exemple #1
0
        public void MakeSrc()
        {
            if (null == module.Parent)
            {
                return; // must be solution
            }
            Zeze.Util.FileChunkGen fcg = new Util.FileChunkGen("-- ZEZE_FILE_CHUNK {{{", "-- ZEZE_FILE_CHUNK }}}");
            string fullDir             = module.Parent.GetFullPath(srcDir);
            string fullFileName        = System.IO.Path.Combine(fullDir, module.Name + "Impl.lua");

            if (fcg.LoadFile(fullFileName))
            {
                fcg.SaveFile(fullFileName, GenChunkByName);
            }
            else
            {
                System.IO.Directory.CreateDirectory(fullDir);
                using System.IO.StreamWriter sw = new System.IO.StreamWriter(fullFileName, false, Encoding.UTF8);

                sw.WriteLine($"local {module.Name}Impl = {{}}");
                sw.WriteLine();
                sw.WriteLine("local Zeze = require 'Zeze'");
                sw.WriteLine();
                sw.WriteLine($"function {module.Name}Impl:Init()");
                sw.WriteLine("    " + fcg.ChunkStartTag + " " + ChunkNameRegisterProtocol);
                RegisterProtocol(sw);
                sw.WriteLine("    " + fcg.ChunkEndTag + " " + ChunkNameRegisterProtocol);
                sw.WriteLine($"end");
                sw.WriteLine();
                Module  realmod = (Module)module;
                Service serv    = realmod.ReferenceService;
                if (serv != null)
                {
                    int serviceHandleFlags = realmod.ReferenceService.HandleFlags;
                    foreach (Protocol p in realmod.Protocols.Values)
                    {
                        if (p is Rpc rpc)
                        {
                            if ((rpc.HandleFlags & serviceHandleFlags & Program.HandleScriptFlags) != 0)
                            {
                                sw.WriteLine($"function {module.Name}Impl.Process{p.Name}Request(rpc)");
                                sw.WriteLine($"    -- write rpc request handle here");
                                sw.WriteLine($"end");
                                sw.WriteLine($"");
                            }
                            continue;
                        }
                        if (0 != (p.HandleFlags & serviceHandleFlags & Program.HandleScriptFlags))
                        {
                            sw.WriteLine($"function {module.Name}Impl.Process{p.Name}(p)");
                            sw.WriteLine($"    -- write handle here");
                            sw.WriteLine($"end");
                            sw.WriteLine($"");
                        }
                    }
                }
                sw.WriteLine();
                sw.WriteLine($"return {module.Name}Impl");
            }
        }
Exemple #2
0
        public void Make()
        {
            Zeze.Util.FileChunkGen fcg = new Util.FileChunkGen();
            string fullDir             = project.Solution.GetFullPath(genDir);
            string fullFileName        = System.IO.Path.Combine(fullDir, "App.ts");

            if (fcg.LoadFile(fullFileName))
            {
                fcg.SaveFile(fullFileName, GenChunkByName);
                return;
            }
            // new file
            System.IO.Directory.CreateDirectory(fullDir);
            using System.IO.StreamWriter sw = new System.IO.StreamWriter(fullFileName, false, Encoding.UTF8);
            sw.WriteLine();
            sw.WriteLine(fcg.ChunkStartTag + " " + ChunkNameImportGen);
            ImportGen(sw);
            sw.WriteLine(fcg.ChunkEndTag + " " + ChunkNameImportGen);
            sw.WriteLine();
            sw.WriteLine("export class " + project.Solution.Name + "_App {");
            sw.WriteLine("    " + fcg.ChunkStartTag + " " + ChunkNamePropertyGen);
            PropertyGen(sw);
            sw.WriteLine("    " + fcg.ChunkEndTag + " " + ChunkNamePropertyGen);
            sw.WriteLine("    public constructor() {");
            sw.WriteLine("        " + fcg.ChunkStartTag + " " + ChunkNamePropertyInitGen);
            PropertyInitInConstructorGen(sw);
            sw.WriteLine("        " + fcg.ChunkEndTag + " " + ChunkNamePropertyInitGen);
            sw.WriteLine("    }");
            sw.WriteLine();
            sw.WriteLine("    public Start(): void {");
            sw.WriteLine("        " + fcg.ChunkStartTag + " " + ChunkNameStartGen);
            StartGen(sw);
            sw.WriteLine("        " + fcg.ChunkEndTag + " " + ChunkNameStartGen);
            sw.WriteLine("    }");
            sw.WriteLine();
            sw.WriteLine("    public Stop(): void {");
            sw.WriteLine("        " + fcg.ChunkStartTag + " " + ChunkNameStopGen);
            StopGen(sw);
            sw.WriteLine("        " + fcg.ChunkEndTag + " " + ChunkNameStopGen);
            sw.WriteLine("    }");
            sw.WriteLine("}");
        }
Exemple #3
0
        public void Make()
        {
            Zeze.Util.FileChunkGen fcg = new Util.FileChunkGen();
            string fullDir             = module.GetFullPath(genDir);
            string fullFileName        = System.IO.Path.Combine(fullDir, $"Module{module.Name}.ts");

            if (fcg.LoadFile(fullFileName))
            {
                fcg.SaveFile(fullFileName, GenChunkByName);
            }
            else
            {
                // new file
                System.IO.Directory.CreateDirectory(fullDir);
                using System.IO.StreamWriter sw = new System.IO.StreamWriter(fullFileName, false, Encoding.UTF8);
                sw.WriteLine();
                sw.WriteLine(fcg.ChunkStartTag + " " + ChunkNameImport);
                Import(sw);
                sw.WriteLine(fcg.ChunkEndTag + " " + ChunkNameImport);
                sw.WriteLine();
                sw.WriteLine("export class " + module.Path("_") + " {");
                sw.WriteLine("        " + fcg.ChunkStartTag + " " + ChunkNameModuleEnums);
                PrintModuleEnums(sw);
                sw.WriteLine("        " + fcg.ChunkEndTag + " " + ChunkNameModuleEnums);
                sw.WriteLine("    public constructor(app: " + module.Solution.Name + "_App) {");
                sw.WriteLine("        " + fcg.ChunkStartTag + " " + ChunkNameRegisterProtocol);
                RegisterProtocol(sw);
                sw.WriteLine("        " + fcg.ChunkEndTag + " " + ChunkNameRegisterProtocol);
                sw.WriteLine("    }");
                sw.WriteLine("");
                sw.WriteLine("    public Start(app: " + module.Solution.Name + "_App): void {");
                sw.WriteLine("    }");
                sw.WriteLine("");
                sw.WriteLine("    public Stop(app: " + module.Solution.Name + "_App): void {");
                sw.WriteLine("    }");
                sw.WriteLine("");
                if (module.ReferenceService != null)
                {
                    int serviceHandleFlags = module.ReferenceService.HandleFlags;
                    foreach (Protocol p in module.Protocols.Values)
                    {
                        string fullName = p.Space.Path("_", p.Name);
                        if (p is Rpc rpc)
                        {
                            if ((rpc.HandleFlags & serviceHandleFlags & Program.HandleScriptFlags) != 0)
                            {
                                sw.WriteLine("    public Process" + rpc.Name + "Request(rpc: " + fullName + "): number {");
                                sw.WriteLine("        return 0;");
                                sw.WriteLine("    }");
                                sw.WriteLine("");
                            }
                            continue;
                        }
                        if (0 != (p.HandleFlags & serviceHandleFlags & Program.HandleScriptFlags))
                        {
                            sw.WriteLine("    public Process" + p.Name + "(protocol: " + fullName + "): number {");
                            sw.WriteLine("        return 0;");
                            sw.WriteLine("    }");
                            sw.WriteLine("");
                        }
                    }
                }
                sw.WriteLine("}");
            }
        }