Beispiel #1
0
        static void Main(string[] args)
        {
            //1 >>> --input_path = D:\GitHub\ProtocolGenerator\ProtocolForClient\
            //1 >>> --output_path = D:\GitHub\ProtocolGenerator\Bin\
            //1 >>> --filename = D:\GitHub\ProtocolGenerator\ProtocolForClient\Client\C2G.code
            string operationType = "default";

            foreach (string arg in args)
            {
                //Console.WriteLine(">>>{0} ", arg);
                string lhs = arg, rhs = "";
                int    index = arg.IndexOf('=');
                if (index > 0)
                {
                    lhs = arg.Substring(0, index);
                    rhs = arg.Substring(index + 1);
                }

                switch (lhs)
                {
                case "":
                    break;

                case "--operate_type":
                    operationType = rhs;
                    break;

                case "--input_path":
                    InputPath = rhs;
                    break;

                case "--output_path":
                    OutputPath = rhs;
                    break;

                case "--filename":
                    if (rhs.ToLower().EndsWith(".code".ToLower()))
                    {
                        Filename = rhs;
                    }
                    else
                    {
                        Console.WriteLine("File type error :{0}  ( mast ends with .code ) ", rhs);
                        return;
                    }
                    break;

                default:
                    break;
                }
            }

            if (!DataManager.GetInstance().CheckFilePast(Filename))
            {
#if DEBUG
                Console.WriteLine("File no change: {0}", Filename);
#else
                return;
#endif
            }

            GeneratorManager.GetInstance().Init(operationType);

            if (operationType == "all")
            {
                DataManager.GetInstance().Load(Filename);
            }
            else if (operationType == "CSharpId" || operationType == "JavaId" || operationType == "id")
            {
                GeneratorManager.GetInstance().GenerateId();
            }
            else if (operationType == "default")
            {
                GeneratorManager.GetInstance().GenerateId();
                if (InputPath == null)
                {
                    Console.WriteLine("operationType got an error. InputPath = null");
                    return;
                }
                else
                {
                    try
                    {
                        string[] files = FileUtil.FindFiles(InputPath, "*.code");
                        foreach (var file in files)
                        {
                            DataManager.GetInstance().Load(file);
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine("operationType got an error. {0}", e.Message);
                        return;
                    }
                }
            }
            else
            {
                DataManager.GetInstance().Load(Filename);
            }
            GeneratorManager.GetInstance().Run();
        }