using Autodesk.Revit.DB;
using ServiceRevitLib;
using System;
using System.IO;

//using RevitToJBim.Common;

namespace ExportStart
{
    class Program
    {
        static Program()
        {
            RevitCoreContext.Instance.Run();
        }
        [STAThread]
        static void Main(string[] args)
        {
            string command = null;
            string path = null;
            if (args.Length > 0)
            {
                command = args[0];
            }
            if (args.Length > 1)
            {
                path = args[1];
            }
#if DEBUG
            if (string.IsNullOrWhiteSpace(command))
            {
                command = "DataExport";
                path = @"E:\导出测试\test.rvt";
            }

#endif
            if (string.IsNullOrEmpty(command))
            {
                Console.WriteLine("命令参数错误");
            }
            Console.WriteLine(command);
            Console.WriteLine(path);
            if (File.Exists(path) && Enum.TryParse(command, out CommandType commandType))
            {
                var app = RevitCoreContext.Instance.Application;
                var doc = app.OpenDocumentFile(path);
                switch (commandType)
                {
                    case CommandType.DataCheck:
                        Check(doc);
                        break;
                    case CommandType.DataExport:
                        Export(doc);
                        break;
                }
                RevitCoreContext.Instance.Stop();
            }
        }

        enum CommandType
        {
            None = 0,
            DataCheck,
            DataExport
        }


        public static void Export(Document doc)
        {
            try
            {
                Console.WriteLine("Start Export");
                RevitToJBim.MbiExport.Export(doc);

                Console.WriteLine("End Export");
            }
            catch (Exception e)
            {
                Console.WriteLine("导出失败");
                Console.WriteLine(e.StackTrace);
            }
        }


        public static void Check(Document doc)
        {
            try
            {
                Console.WriteLine("Start DataCheck");
                ServiceDataCheckTest.Check(doc);

                Console.WriteLine("End DataCheck");
            }
            catch (Exception e)
            {
                Console.WriteLine("导出失败");
                Console.WriteLine(e.StackTrace);
            }
        }


    }
}
