예제 #1
0
        public static void BuildSingleContent(ContentType resType, String inFile, String outFile)
        {
            FileInfo fi = new FileInfo(inFile);
            sd_inFileName = fi.Name;
            sd_inFileNameN = sd_inFileName.Replace(fi.Extension, "");
            sd_outFile = outFile;

            ////////
            // 拷贝源文件
            File.Copy(inFile, Path.Combine(EditorService.Instance.EditorDir, EditorStatics.MSBuild_InPath, sd_inFileName), true);

            ////////
            // 设置编译参数
            XmlDocument projDoc = new XmlDocument();
            projDoc.Load(Path.Combine(EditorService.Instance.EditorDir,EditorStatics.SContentBuilderPath));

            // Project.ItemGroup.Compile
            XmlElement compileEle = (XmlElement)projDoc.FirstChild.ChildNodes[2].ChildNodes[0];

            // Compile[Include] = inFile
            compileEle.Attributes[0].Value = sd_inFileName;

            // Compile.Name = filename
            compileEle.ChildNodes[0].InnerText = sd_inFileNameN;

            // Compile.Importer = ...
            compileEle.ChildNodes[1].InnerText = getImporterName(resType);

            // Compile.Processor = ...
            compileEle.ChildNodes[2].InnerText = getProcessorName(resType);

            projDoc.Save(Path.Combine(EditorService.Instance.EditorDir,EditorStatics.SContentBuilderPath));

            waitView = EditorService.Instance.QueryModule<ViewModule>().QueryView<IWaitView>();

            ////////
            // 执行编译
            process = new Process();
            process.StartInfo.FileName = EditorStatics.MSBuildExe;
            process.StartInfo.Arguments ="\"" + Path.Combine(EditorService.Instance.EditorDir, EditorStatics.SContentBuilderPath) + "\"";
            process.StartInfo.CreateNoWindow = true;
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;  // 表示进程标准输出不再同步读取,而是使用事件委托异步处理
            process.EnableRaisingEvents = true;
            process.Exited += delegate
            {
                OnBuildFinish();
                waitView.TaskEndCallback(process.ExitCode);
            };
            process.OutputDataReceived += new DataReceivedEventHandler(buildDataReceived);

            waitView.SetTaskBeginCallback(beginBuild);
            waitView.StartTask();
        }
        private bool Invoke(string message, IWaitView waitView)
        {
            if (!string.IsNullOrEmpty(message))
            {
                waitView.ShowView();
            }

            waitView.ProgressDialogMessage = message;

            // Perform work
            IAsyncResult res = _doWorkFunc.BeginInvoke(null, null, null);

            // Whait wail operation complete and this time execute waiting app threads
            while (!res.IsCompleted)
            {
                Application.DoEvents();
                Thread.Sleep(10);
            }

            _doWorkFunc.EndInvoke(res);
            // Close perform operation dialog
            return(true);
        }