123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- using SAGA.DotNetUtils.Revit;
- using System;
- using System.Diagnostics;
- using System.IO;
- using System.Text.RegularExpressions;
- using Newtonsoft.Json.Linq;
- using SAGA.DotNetUtils.Extend;
- using System.Threading;
- namespace StartVisionSelector
- {
- public class Program
- {
- public static void Main(string[] args)
- {
- string command = null;
- string param = null;
- string path = null;
- if (args.Length > 0)
- {
- command = args[0];
- }
- if (args.Length > 1)
- {
-
- param = args[1].Replace("\"", "\\\""); ;
- }
- if (args.Length > 2)
- {
- path = args[2];
- }
- #if DEBUG
- if (string.IsNullOrWhiteSpace(command))
- {
- command = "DataExport";
- path = @"E:\导出测试\testR17.rvt";
- path = @"E:\导出测试\TestEmptyR17.rvt";
- JObject jObject = new JObject();
- jObject.Add("ResultFileName", @"C:\Users\SAGACLOUD\AppData\Local\RevitService\Result_e26be2fd-2097-462b-bdd0-a2a86b616928.txt");
- param = jObject.ToString().Replace("\"","\\\"");
-
-
-
-
-
-
- }
- #endif
- Console.WriteLine("start");
- #region 保存版本号
-
-
- var runPath = AppDomain.CurrentDomain.BaseDirectory;
- string revitVision = null;
- try
- {
- revitVision = RevitVisionUtil.GetRevitVision(path);
- if (string.IsNullOrEmpty(revitVision))
- {
- SaveFileErrorResult(param);
- return;
- }
- }
- catch (Exception e)
- {
- SaveFileErrorResult(param);
- return;
- }
- string destination = GetObjectiveFilePath(param);
-
- File.WriteAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, SelectorConst.RevitFileVisionFile), revitVision);
- #endregion
- #region 删除生成的Revit dll
-
- var loadingRevitPath = Path.Combine(runPath, SelectorConst.LoadingRevit);
-
- #region Del RevitDll
- foreach (string loadingItem in File.ReadAllLines(loadingRevitPath))
- {
- string destFile = Path.Combine(runPath, $"{loadingItem}.dll");
- if(File.Exists(destFile))
- File.Delete(destFile);
- }
- #endregion
-
- #endregion
-
- #region 启动
- Process process = new Process();
- process.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ExportStart.exe");
- process.StartInfo.UseShellExecute = false;
- process.StartInfo.CreateNoWindow = true;
- process.StartInfo.RedirectStandardInput = true;
- process.StartInfo.RedirectStandardOutput = true;
- process.StartInfo.RedirectStandardError = true;
- process.StartInfo.Arguments = command + " "+
- "\"" + param + "\"" + " "+
- "\"" + path + "\"";
- process.Start();
-
-
- try
- {
- while (process != null && !process.HasExited)
- {
- process.WaitForExit(60 * 1000);
- if (!process.HasExited)
- {
- Thread.Sleep(5000);
- if (process != null && !process.HasExited)
- {
- process.Close();
- process = null;
-
-
- }
- }
- }
- }
- catch (Exception ex)
- {
- File.AppendAllText(@"e:\error.txt", ex.Message + ex.StackTrace);
- Console.WriteLine(ex.Message + "\r\n" + ex.StackTrace);
- }
-
-
- #endregion
- Console.WriteLine("end");
-
- Environment.Exit(0);
-
- }
- private static string GetObjectiveFilePath(string param)
- {
- Console.WriteLine(param);
- string path = string.Empty;
- try
- {
- var tempParam = param.Replace("\\\"", "\"");
- JObject jObject = JObject.Parse(tempParam);
- string key = @"ResultFileName";
- path = jObject[key].ToString();
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- return path;
- }
-
-
-
-
-
-
- private static void SaveFileErrorResult(string param)
- {
- Console.WriteLine(param);
- try
- {
- var tempParam = param.Replace("\\\"", "\"");
- JObject jObject = JObject.Parse(tempParam);
- string key = @"ResultFileName";
- string path = jObject[key].ToString();
- if (path.IsNotNullEmpty())
- {
- Console.WriteLine(path);
- var dir = Directory.GetParent(path);
- if (!dir.Exists)
- dir.Create();
- JObject jResult=new JObject();
- jResult.Add("Result", "Failure");
- jResult.Add("ResultMsg","文件格式错误或文件打开失败");
- File.AppendAllText(path, jResult.ToString());
- }
- }
- catch (Exception e)
- {
- Console.WriteLine(e);
- }
- }
- }
- }
|