Example #1
0
        /// <summary>
        /// Build the model of the specified type.
        /// </summary>
        /// <param name="model">The model to build.</param>
        /// <param name="output">The output type.</param>
        public void Build(Model model, string output, string format)
        {
            if (string.IsNullOrEmpty(output))
            {
                output = @"Java";
            }

            if (!Directory.Exists(output))
            {
                Directory.CreateDirectory(output);
            }

            //AbstractTcpChannel.java
            var abstractTcpChannelTemplate = new AbstractTcpChannelTemplate();

            File.WriteAllText(Path.Combine(output, @"AbstractTcpChannel.java"), abstractTcpChannelTemplate.TransformText());

            //CLZF.java
            var clzfTemplate = new CLZFTemplate();

            File.WriteAllText(Path.Combine(output, @"CLZF.java"), clzfTemplate.TransformText());

            //ConnectionHandler.java
            var connectionHandlerTemplate = new ConnectionHandlerTemplate();

            File.WriteAllText(Path.Combine(output, @"ConnectionHandler.java"), connectionHandlerTemplate.TransformText());

            //DisconnectionHandler.java
            var disconnectionHandlerTemplate = new DisconnectionHandlerTemplate();

            File.WriteAllText(Path.Combine(output, @"DisconnectionHandler.java"), disconnectionHandlerTemplate.TransformText());

            //PacketHandler.java
            var packetHandlerTemplate = new PacketHandlerTemplate();

            File.WriteAllText(Path.Combine(output, @"PacketHandler.java"), packetHandlerTemplate.TransformText());


            var tcpChanneltemplate = new TcpChannelTemplate();
            var tcpChannelsession  = new Dictionary <string, object>();

            tcpChanneltemplate.Session = tcpChannelsession;

            tcpChannelsession["Model"] = model;
            tcpChanneltemplate.Initialize();

            var code = tcpChanneltemplate.TransformText();

            File.WriteAllText(Path.Combine(output, @"TcpChannel.java"), code);

            //Make packets
            var packetTemplate = new PacketTemplate();
            var packetSession  = new Dictionary <string, object>();

            packetTemplate.Session = packetSession;
            foreach (var receive in model.Receives)
            {
                packetTemplate.Clear();
                packetSession["Operation"] = receive;
                packetTemplate.Initialize();

                code = packetTemplate.TransformText();
                File.WriteAllText(Path.Combine(output, string.Format(@"{0}.java", receive.Name)), code);
            }

            //Make CustomType
            var customTypeTemplate = new CustomTypeTemplate();
            var customTypeSession  = new Dictionary <string, object>();

            customTypeTemplate.Session = customTypeSession;
            foreach (var customType in model.CustomTypes)
            {
                customTypeTemplate.Clear();
                customTypeSession["CustomType"] = customType;
                customTypeTemplate.Initialize();
                code = customTypeTemplate.TransformText();
                File.WriteAllText(Path.Combine(output, string.Format(@"{0}.java", customType.Name)), code);
            }
        }
        /// <summary>
        /// Build the model of the specified type.
        /// </summary>
        /// <param name="model">The model to build.</param>
        /// <param name="output">The output type.</param>
        public void Build(Model model, string output, string format)
        {
            if (string.IsNullOrEmpty(output))
                output = @"Java";

            if (!Directory.Exists(output))
                Directory.CreateDirectory(output);

            //AbstractTcpChannel.java
            var abstractTcpChannelTemplate = new AbstractTcpChannelTemplate();
            File.WriteAllText(Path.Combine(output, @"AbstractTcpChannel.java"), abstractTcpChannelTemplate.TransformText());

            //CLZF.java
            var clzfTemplate = new CLZFTemplate();
            File.WriteAllText(Path.Combine(output, @"CLZF.java"), clzfTemplate.TransformText());

            //ConnectionHandler.java
            var connectionHandlerTemplate = new ConnectionHandlerTemplate();
            File.WriteAllText(Path.Combine(output, @"ConnectionHandler.java"), connectionHandlerTemplate.TransformText());

            //DisconnectionHandler.java
            var disconnectionHandlerTemplate = new DisconnectionHandlerTemplate();
            File.WriteAllText(Path.Combine(output, @"DisconnectionHandler.java"), disconnectionHandlerTemplate.TransformText());

            //PacketHandler.java
            var packetHandlerTemplate = new PacketHandlerTemplate();
            File.WriteAllText(Path.Combine(output, @"PacketHandler.java"), packetHandlerTemplate.TransformText());

            var tcpChanneltemplate = new TcpChannelTemplate();
            var tcpChannelsession = new Dictionary<string, object>();
            tcpChanneltemplate.Session = tcpChannelsession;

            tcpChannelsession["Model"] = model;
            tcpChanneltemplate.Initialize();

            var code = tcpChanneltemplate.TransformText();
            File.WriteAllText(Path.Combine(output, @"TcpChannel.java"), code);

            //Make packets
            var packetTemplate = new PacketTemplate();
            var packetSession = new Dictionary<string, object>();
            packetTemplate.Session = packetSession;
            foreach (var receive in model.Receives)
            {
                packetTemplate.Clear();
                packetSession["Operation"] = receive;
                packetTemplate.Initialize();

                code = packetTemplate.TransformText();
                File.WriteAllText(Path.Combine(output, string.Format(@"{0}.java", receive.Name)), code);
            }

            //Make CustomType
            var customTypeTemplate = new CustomTypeTemplate();
            var customTypeSession = new Dictionary<string, object>();
            customTypeTemplate.Session = customTypeSession;
            foreach (var customType in model.CustomTypes)
            {
                customTypeTemplate.Clear();
                customTypeSession["CustomType"] = customType;
                customTypeTemplate.Initialize();
                code = customTypeTemplate.TransformText();
                File.WriteAllText(Path.Combine(output, string.Format(@"{0}.java", customType.Name)), code);
            }
        }