Example #1
0
        static void Main(string[] args)
        {
            var trace = new StringBuilder();

            try
            {
                var harpFilePath = Path.Combine(Environment.CurrentDirectory, "DataLayer.harp");
                Console.WriteLine(harpFilePath);

                // read
                var inYaml = File.ReadAllText(harpFilePath);
                var result = HarpFile.FromYaml(inYaml);
                Console.WriteLine($"Parse: {result.code}");

                if (result.code != HarpFile.ParseResult.OK)
                {
                    return;
                }

                // synchronize
                var sync    = new HarpSynchronizer(new Sql(), trace);
                var sResult = sync.Synchronize(result.file);
                Console.WriteLine($"Sync: {sResult.Code}");

                if (sResult.Code != HarpSynchronizer.SynchronizeResultCode.OK)
                {
                    return;
                }

                if (sResult.WasUpdated)
                {
                    var outYaml = result.file.GenerateYaml();
                    File.WriteAllText(harpFilePath, outYaml);
                }
            }
            finally
            {
                Console.WriteLine($"----- TRACE -----");
                Console.WriteLine(trace.ToString());
                Console.WriteLine($"-----------------");

                Console.ReadLine();
            }
        }
Example #2
0
        static void Main(string[] args)
        {
            if (args == null || args.Count() < 2)
            {
                logAndTerminate("Both parameters must be specified: {command} {file}");
                return;
            }

            var cmd  = args[0];
            var file = args[1];

            if (string.IsNullOrWhiteSpace(cmd) || string.IsNullOrWhiteSpace(file))
            {
                logAndTerminate("Both parameters must be specified: {command} {file}");
                return;
            }

            var actionSync            = "sync";
            var actionSyncAndGenerate = "syncgen";
            var supportedActions      = new[]
            {
                actionSync,
                actionSyncAndGenerate
            };

            if (!supportedActions.Any(a => cmd.ToLower() == a.ToLower()))
            {
                logAndTerminate("Command not recognized.");
                return;
            }

            if (!File.Exists(file))
            {
                file = Path.Combine(Environment.CurrentDirectory, file);

                if (!File.Exists(file))
                {
                    logAndTerminate("Could not find the specified file");
                    return;
                }
            }

            if (file.EndsWith(".harp"))
            {
                logAndTerminate("File is not a .harp file");
                return;
            }

            var verboseOutput = (args.Length > 2);

            var sb   = new StringBuilder();
            var sync = new HarpSynchronizer(new Sql(), sb);

            // read file
            var harpYaml = File.ReadAllText(file);

            // load
            var loadResult = HarpFile.FromYaml(harpYaml);

            if (loadResult.code != HarpFile.ParseResult.OK)
            {
                logAndTerminate($"Could not load harp file: {loadResult.code}");
                return;
            }

            var syncSuccessful = false;

            var syncResult = sync.Synchronize(loadResult.file);

            if (syncResult.Code == HarpSynchronizer.SynchronizeResultCode.OK)
            {
                syncSuccessful = true;

                log("Sync was successful");

                if (syncResult.WasUpdated)
                {
                    log("Harp file was updated");
                }

                if (syncResult.UnmappedStoredProcs.Any())
                {
                    log("There are unmapped stored procedures");
                }

                if (syncResult.UnmappedTableColumns.Any())
                {
                    log("There are unmapped table columns");
                }
            }
            else
            {
                log($"Sync was NOT successful: {syncResult.Code}");

                if (syncResult.UnmappedStoredProcs.Any())
                {
                    log("There are also some unmapped stored procedures");
                }

                if (syncResult.UnmappedTableColumns.Any())
                {
                    log("There are also some unmapped table columns");
                }

                Environment.Exit(1);
            }

            if (cmd.ToLower() == actionSyncAndGenerate && syncSuccessful)
            {
                log("Not implemented");
                Environment.Exit(1);

                //var gen = new HarpGenerator();
                //gen.Generate(HarpFile,)
            }
        }