Esempio n. 1
0
        private void ConvertButton_Click(object sender, EventArgs e)
        {
            var logWriter = new StringWriter();
            var logger    = new StreamLoggerWithContext(logWriter, logWriter, false);

            try
            {
                if (!EocEnv.IsValid)
                {
                    logger.Error("环境变量EOC_HOME未正确配置");
                    return;
                }
                var srcFile  = textBox1.Text;
                var destFile = textBox2.Text;
                var source   = new EProjectFile.EProjectFile();
                source.Load(File.OpenRead(srcFile));
                ProjectConverter.EocProjectType projectType;
                switch (comboBox1.SelectedIndex)
                {
                case 0:
                    projectType = ProjectConverter.EocProjectType.Windows;
                    break;

                case 1:
                    projectType = ProjectConverter.EocProjectType.Console;
                    break;

                case 2:
                    projectType = ProjectConverter.EocProjectType.Dll;
                    break;

                default:
                    throw new Exception("请选择正确的项目类型");
                }
                if (source.ESystemInfo.FileType != 3 && !checkBox1.Checked)
                {
                    throw new Exception("源文件应为ECom(*.ec)文件");
                }
                new ProjectConverter(source, projectType, null, logger).Generate(destFile);
                logger.Info("操作完成");
            }
            catch (Exception exception)
            {
                logger.Error("处理程序不正常退出,异常信息:{0}", exception);
            }
            finally
            {
                MessageBox.Show(logWriter.ToString(), "Log");
            }
        }
Esempio n. 2
0
 private async Task<bool> ExecuteJob(StepwiseLog log)
 {
     var eocLogWriter = new StringWriter();
     var eocLogger = new StreamLoggerWithContext(eocLogWriter, eocLogWriter, false);
     var step = new SpecificStepLog()
     {
         Description = "转换为C++/CMake工程",
     };
     log.Steps.Add(step);
     try
     {
         if (!EocEnv.IsValid)
         {
             eocLogger.Error("环境变量EOC_HOME未正确配置");
             step.State = StepState.Failed;
         }
         var source = new EProjectFile.EProjectFile();
         source.Load(File.OpenRead(ViewModel.SourcePath));
         if (source.ESystemInfo.FileType != 3 && !ViewModel.Force)
         {
             eocLogger.Error("源文件应为ECom(*.ec)文件");
             step.State = StepState.Failed;
         }
         else
         {
             await Task.Run(() =>
             {
                 new ProjectConverter(source, ViewModel.ProjectType, null, eocLogger).Generate(ViewModel.OutputPath);
                 eocLogger.Info("完成");
             });
         }
     }
     catch (Exception exception)
     {
         eocLogger.Error("处理程序不正常退出,异常信息:{0}", exception);
         step.State = StepState.Failed;
     }
     step.Content = new TextBlock()
     {
         TextWrapping = TextWrapping.Wrap,
         Text = eocLogWriter.ToString()
     };
     if (step.State == StepState.Failed)
     {
         return false;
     }
     step.State = StepState.Success;
     if (!ViewModel.Build)
     {
         return false;
     }
     step = new SpecificStepLog()
     {
         Description = "初始化CMake环境",
     };
     log.Steps.Add(step);
     if (CMakeEnv.DefaultInstance == null)
     {
         step.State = StepState.Failed;
         step.Content = new TextBlock()
         {
             TextWrapping = TextWrapping.Wrap,
             Text = "Error: 未找到CMake编译环境"
         };
         return false;
     }
     if (ViewModel.CMakeKit == null || ViewModel.ProjectConfig == null)
     {
         step.State = StepState.Failed;
         step.Content = new TextBlock()
         {
             TextWrapping = TextWrapping.Wrap,
             Text = "Error: 工具链参数不完整"
         };
         return false;
     }
     step.Content = new TextBlock()
     {
         TextWrapping = TextWrapping.Wrap,
         Text = $"CMake Detected: {CMakeEnv.DefaultInstance.CMakeBin}"
     };
     CMakeKit cmakeKit;
     try
     {
         cmakeKit = new CMakeKit(ViewModel.CMakeKit);
     }
     catch (Exception)
     {
         step.State = StepState.Failed;
         step.Content = new TextBlock()
         {
             TextWrapping = TextWrapping.Wrap,
             Text = $"Error: 初始化工具链 (${ViewModel.CMakeKit?.Name}) 失败"
         };
         return false;
     }
     step.State = StepState.Success;
     var success = await RunProcessAsync(log, "配置CMake工程", startInfoHelper => cmakeKit.StartConfigure(
         CMakeEnv.DefaultInstance,
         ViewModel.OutputPath,
         ViewModel.BuildPath,
         new Dictionary<string, CMakeSetting>() {
             {"CMAKE_BUILD_TYPE", new CMakeSetting(ViewModel.ProjectConfig, "STRING") }
         },
         startInfoHelper));
     if (!success)
     {
         return false;
     }
     success = await RunProcessAsync(log, "编译CMake工程", startInfoHelper => cmakeKit.StartBuild(
         CMakeEnv.DefaultInstance,
         ViewModel.BuildPath,
         new CMakeBuildConfig()
         {
             Config = ViewModel.ProjectConfig
         },
         startInfoHelper));
     if (!success)
     {
         return false;
     }
     return true;
 }