コード例 #1
0
ファイル: Generator.cs プロジェクト: petegleeson/Cake
 private static bool GenerateContextSource()
 {
     bool hadException = false;
     DatabaseOperation dbOp = new DatabaseOperation();
     try
     {
         dbOp.WriteSourceFile();
     }
     catch
     {
         Console.WriteLine("Error writing database source file");
         hadException = true;
     }
     return hadException;
 }
コード例 #2
0
ファイル: Generator.cs プロジェクト: petegleeson/Cake
        private static bool GenerateHandler(string[] args)
        {
            bool hadException = false;
            switch (args[1].ToLower())
            {
                case GenerateCommand.database:
                    DatabaseOperation dbOp = new DatabaseOperation();
                    Globals.Settings.Names.Database = args[2];
                    try
                    {
                        dbOp.WriteMigrationFile();
                        dbOp.WriteSourceFile();
                    }
                    catch (Exception e)
                    {
                        hadException = true;
                        Console.WriteLine("Error generating database");
                        Console.WriteLine(e.Message);
                        Console.WriteLine(e.StackTrace);
                    }

                    if (!hadException)
                    {
                        Console.WriteLine("Success! Generated database on server.");
                        Globals.Settings.Names.Database = args[2];
                    }
                    break;
                case GenerateCommand.model:
                    ModelOperation modelOp = new ModelOperation();
                    modelOp.ClassName = args[2];
                    modelOp.Namespace = Globals.Settings.Namespaces.Model;
                    // add the fields
                    for (int i = 3; i < args.Length; ++i)
                    {
                        string[] fieldTypePair = args[i].Split(':');
                        // make sure the length is correct
                        if (fieldTypePair.Length != 2)
                        {
                            Console.WriteLine(String.Format("Invalid syntax for field {0}", args[i]));
                            continue;
                        }
                        Type type = Type.GetType(fieldTypePair[1]);
                        if (type == null)
                        {
                            Console.WriteLine(String.Format("Unable to parse type on field {0}", args[i]));
                            continue;
                        }
                        else
                        {
                            modelOp.PropertyMap.Add(fieldTypePair[0], type);
                        }
                    }
                    try
                    {
                        modelOp.WriteSourceFile(Globals.Settings.Paths.Model);
                        //Globals.Settings.ModelTableMap.Add(modelOp.TableName, modelOp.ClassName);
                        // regenerate the database file
                        hadException = GenerateContextSource();
                    }
                    catch
                    {
                        hadException = true;
                        Console.WriteLine("Error generating model");
                    }

                    if (!hadException)
                    {
                        Console.WriteLine("Success! Generated model.");
                    }
                    break;
                default:
                    Console.WriteLine("Error unrecognised generate command");
                    hadException = true;
                    break;
            }
            return hadException;
        }