예제 #1
0
        public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
        {
            if (!enabled)
            {
                return;
            }

            try
            {
                MgaGateway = new MgaGateway(project);

                MgaGateway.BeginTransaction(transactiontype_enum.TRANSACTION_NON_NESTED);
                try
                {
                    Main(project, currentobj, selectedobjs, Convert(param));
                }
                finally
                {
                    MgaGateway.AbortTransaction();
                }
            }
            finally
            {
                MgaGateway   = null;
                project      = null;
                currentobj   = null;
                selectedobjs = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
        }
예제 #2
0
        private void GenerateDotNetCode(
            MgaProject project,
            MgaFCO currentobj,
            MgaFCOs selectedobjs,
            ComponentStartMode startMode)
        {
            // speed up the generation process
            CSharpDSMLGenerator.Generator.FCO.derivedClassCache.Clear();

            string projectDir      = Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length));
            string paradigmXmpFile = Path.Combine(projectDir, project.RootFolder.Name);

            paradigmXmpFile = Path.ChangeExtension(paradigmXmpFile, "xmp");
            if (!File.Exists(paradigmXmpFile))
            {
                string error = String.Format("Paradigm file '{0}' does not exist.", paradigmXmpFile);
                if (startMode == ComponentStartMode.GME_SILENT_MODE)
                {
                    throw new Exception(error);
                }
                DialogResult yesno = MessageBox.Show(error + "\n\nDo you want to run the Meta Interpreter?",
                                                     "Paradigm file missing", MessageBoxButtons.YesNo);
                if (yesno != DialogResult.Yes)
                {
                    throw new Exception(error);
                }
                MgaGateway.AbortTransaction();
                IMgaComponentEx metaInterpreter = (IMgaComponentEx)Activator.CreateInstance(Type.GetTypeFromProgID("MGA.Interpreter.MetaInterpreter"));
                metaInterpreter.InvokeEx(project, null, null, (int)ComponentStartMode.GME_SILENT_MODE);
                MgaGateway.BeginTransaction();
            }

            string outputDir = ".";

            if (project.ProjectConnStr.StartsWith("MGA="))
            {
                outputDir = Path.GetDirectoryName(project.ProjectConnStr.Substring(4));
            }
            GeneratorMode mode;

            if (startMode != ComponentStartMode.GME_SILENT_MODE)
            {
                ApiGenerator apiForm = new ApiGenerator();
                apiForm.txtOutputDir.Text =
                    Path.GetDirectoryName(project.ProjectConnStr.Substring("MGA=".Length));

                DialogResult dr = apiForm.ShowDialog();
                if (dr != DialogResult.OK)
                {
                    return;
                }

                mode = ((ApiGenerator.ModeItem)apiForm.cbMode.SelectedItem).Mode;
            }
            else
            {
                mode = GeneratorMode.Namespaces;
            }
            var compileUnit = GenerateDotNetCode(project, paradigmXmpFile, outputDir, mode);

            CompileDll(outputDir, compileUnit);
        }