public void BatchExport(ref MorphemeConnectExporter.Result result)
        {
            try
            {
                string morphemeConnectExe = MacrosSystem.GetInstance().ExpandMacro(Settings.GetInstance().MorphemeConnectPath);

                string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                appDataFolder += MorphemeConnectExporter.AppDataSubFolder;
                string luaLogDirectory = appDataFolder += MorphemeConnectExporter.LuaLogSubDirectory;

                if (false == Directory.Exists(luaLogDirectory))
                {
                    Directory.CreateDirectory(luaLogDirectory);
                }

                string lua = "";

                foreach (MorphemeConnectData morphemeConnectData in morphemeConnectDataList)
                {
                    string mcpFile;
                    string mcnFile;
                    string intermediateFile;

                    MorphemeHelper.GetFilePathsFromNetwork(morphemeConnectData.Network, morphemeConnectData.ExportPath, out mcpFile, out mcnFile, out intermediateFile);

                    // TODO optimization. pre-sort on mcp and only open when project changes

                    // generate the lua to open the project, open the mcn and export the mcn
                    lua += string.Format(" project.open({0})\n mcn.open({1})\n mcn.export({2})", '\"' + mcpFile + '\"', '\"' + mcnFile + '\"', '\"' + intermediateFile + "\"\n");
                }

                string luaFileName = "BatchExport_" + DateTime.Now.Ticks.ToString() + ".lua";

                MorphemeHelper.CreateLuaAndLaunchConnect(luaFileName, lua, morphemeConnectExe, ref result);
            }
            catch (System.Exception ex)
            {
                result.Success     = false;
                result.ErrorString = ex.ToString();
            }
        }
        public void Export(ref MorphemeConnectExporter.Result result)
        {
            try
            {
                string morphemeConnectExe = MacrosSystem.GetInstance().ExpandMacro(Settings.GetInstance().MorphemeConnectPath);

                string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                appDataFolder += MorphemeConnectExporter.AppDataSubFolder;
                string luaLogDirectory = appDataFolder += MorphemeConnectExporter.LuaLogSubDirectory;

                if (false == Directory.Exists(luaLogDirectory))
                {
                    Directory.CreateDirectory(luaLogDirectory);
                }

                string mcpFile;
                string mcnFile;
                string intermediateFile;

                MorphemeHelper.GetFilePathsFromNetwork(morphemeConnectData.Network, morphemeConnectData.ExportPath, out mcpFile, out mcnFile, out intermediateFile);

                // generate the lua to open the project, open the mcn and export the mcn
                string lua = string.Format(" project.open({0})\n mcn.open({1})\n mcn.export({2})", '\"' + mcpFile + '\"', '\"' + mcnFile + '\"', '\"' + intermediateFile + '\"');

                // generate the lua fileName
                FileInfo mcnfileInfo = new FileInfo(mcnFile);
                string   luaFileName = Path.GetFileNameWithoutExtension(mcnfileInfo.Name);
                luaFileName += "_" + DateTime.Now.Ticks.ToString() + ".lua";

                MorphemeHelper.CreateLuaAndLaunchConnect(luaFileName, lua, morphemeConnectExe, ref result);
            }
            catch (System.Exception ex)
            {
                result.Success     = false;
                result.ErrorString = ex.ToString();
            }
        }
        public static void CreateLuaAndLaunchConnect(string luaFileName, string lua, string morphemeConnectExe, ref MorphemeConnectExporter.Result result)
        {
            // write out the lua to a file
            string appDataFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);

            appDataFolder += MorphemeConnectExporter.AppDataSubFolder;
            string luaLogDirectory = appDataFolder += MorphemeConnectExporter.LuaLogSubDirectory;

            string luaPath = Path.Combine(luaLogDirectory, luaFileName);

            StreamWriter writer = new StreamWriter(luaPath);

            writer.Write(lua);
            writer.Close();

            // build up the command line
            string commandLine = "-nogui -script \"" + luaPath + "\"";

            // fire up connect and run the just generated lua
            Process.LeaveDebugMode();
            using (Process proc = System.Diagnostics.Process.Start(morphemeConnectExe, commandLine))
            {
                // wait for the process to end
                proc.WaitForExit();

                if (proc.ExitCode != 0)
                {
                    result.Success     = false;
                    result.ErrorString = "batch export failed " + " " + commandLine + " exited with ExitCode " + proc.ExitCode.ToString();
                }
            }
            Process.EnterDebugMode();
        }
 // Wrapper method for use with thread pool.
 public void ThreadPoolCallback(ref MorphemeConnectExporter.Result result)
 {
     Export(ref result);
     morphemeConnectData.DoneEvent.Set();
 }