本文整理汇总了C#中MgaProject.OpenEx方法的典型用法代码示例。如果您正苦于以下问题:C# MgaProject.OpenEx方法的具体用法?C# MgaProject.OpenEx怎么用?C# MgaProject.OpenEx使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MgaProject
的用法示例。
在下文中一共展示了MgaProject.OpenEx方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConfigurations
public static bool GetConfigurations(string projectPath, string absPath)
{
bool result = false;
Assert.True(File.Exists(projectPath), "Project file does not exist.");
string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath);
MgaProject project = new MgaProject();
project.OpenEx(ProjectConnStr, "CyPhyML", null);
try
{
var terr = project.BeginTransactionInNewTerr();
var testObj = project.ObjectByPath[absPath] as MgaFCO;
project.AbortTransaction();
using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project))
{
IMgaFCOs configurations = null;
Assert.ThrowsDelegate d = () =>
{
configurations = masterInterpreter.GetConfigurations(testObj as MgaModel);
};
Assert.DoesNotThrow(d);
}
}
finally
{
project.Close(true);
}
return result;
}
示例2: RunFormulaEvaluate
public static void RunFormulaEvaluate(string projectPath, string absPath, bool automation)
{
Assert.True(File.Exists(projectPath), "Project file does not exist.");
string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath);
MgaProject project = new MgaProject();
project.OpenEx(ProjectConnStr, "CyPhyML", null);
try
{
var terr = project.BeginTransactionInNewTerr();
var testObj = project.ObjectByPath[absPath] as MgaFCO;
project.AbortTransaction();
MgaFCOs fcos = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
Type tFormulaEval = Type.GetTypeFromProgID("MGA.Interpreter.CyPhyFormulaEvaluator");
var formulaEval = Activator.CreateInstance(tFormulaEval) as GME.MGA.IMgaComponentEx;
formulaEval.ComponentParameter["automation"] = automation ? "true" : "false";
formulaEval.ComponentParameter["console_messages"] = "on";
formulaEval.ComponentParameter["expanded"] = "true";
//formulaEval.Initialize(project);
formulaEval.InvokeEx(project, testObj, fcos, 16);
}
finally
{
project.Close(true);
}
}
示例3: RunContextCheck
public static bool RunContextCheck(string projectPath, string absPath)
{
bool result = false;
Assert.True(File.Exists(projectPath), "Project file does not exist.");
string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath);
MgaProject project = new MgaProject();
project.OpenEx(ProjectConnStr, "CyPhyML", null);
try
{
var terr = project.BeginTransactionInNewTerr();
var testObj = project.ObjectByPath[absPath] as MgaFCO;
project.AbortTransaction();
using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project))
{
CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null;
// check context
result = masterInterpreter.TryCheckContext(testObj as MgaModel, out contextCheckerResults);
}
}
finally
{
project.Close(true);
}
return result;
}
示例4: RunElaborator
public static bool RunElaborator(string projectPath, string absPath)
{
bool result = false;
Assert.True(File.Exists(projectPath), "Project file does not exist.");
string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath);
MgaProject project = new MgaProject();
project.OpenEx(ProjectConnStr, "CyPhyML", null);
try
{
var terr = project.BeginTransactionInNewTerr();
var testObj = project.ObjectByPath[absPath] as MgaFCO;
if (testObj == null)
{
throw new ApplicationException(absPath + " not found in " + project.ProjectConnStr);
}
project.AbortTransaction();
MgaFCOs fcos = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
var elaborator = new CyPhyElaborateCS.CyPhyElaborateCSInterpreter();
result = elaborator.RunInTransaction(project, testObj, fcos, 128);
}
finally
{
project.Close(true);
}
return result;
}
示例5: Run
/// <summary>
/// Calls CyPhy2Modelica using early bindings
/// </summary>
/// <param name="outputdirname">xme folder from trunk/models/DynamicsTeam</param>
/// <param name="projectPath">name of mga-file</param>
/// <param name="absPath">Folder-path to test-bench</param>
/// <returns>Boolean - True -> interpreter call was successful</returns>
public static bool Run(string outputdirname, string projectPath, string absPath)
{
bool result = false;
Assert.True(File.Exists(projectPath), "Project file does not exist.");
string ProjectConnStr = "MGA=" + projectPath;
//Type CyPhy2Modelica_v2Interpreter = Type.GetTypeFromProgID("MGA.Interpreter.CyPhy2Modelica_v2");
//Type MainParametersType = Type.GetTypeFromProgID("ISIS.CyPhyML.InterpreterConfiguration");
MgaProject project = new MgaProject();
project.OpenEx(ProjectConnStr, "CyPhyML", null);
try
{
var terr = project.BeginTransactionInNewTerr();
var testObj = project.ObjectByPath[absPath] as MgaFCO;
project.AbortTransaction();
string OutputDir = Path.Combine(Path.GetDirectoryName(projectPath), outputdirname);
if (Directory.Exists(OutputDir))
{
Test.DeleteDirectory(OutputDir);
}
Directory.CreateDirectory(OutputDir);
//dynamic interpreter = Activator.CreateInstance(CyPhy2Modelica_v2Interpreter);
var interpreter = new CyPhy2Modelica_v2.CyPhy2Modelica_v2Interpreter();
interpreter.Initialize(project);
//dynamic mainParameters = Activator.CreateInstance(MainParametersType);
var mainParameters = new CyPhyGUIs.InterpreterMainParameters();
mainParameters.Project = project;
mainParameters.CurrentFCO = testObj;
mainParameters.SelectedFCOs = (MgaFCOs)Activator.CreateInstance(Type.GetTypeFromProgID("Mga.MgaFCOs"));
mainParameters.StartModeParam = 128;
mainParameters.ConsoleMessages = false;
mainParameters.ProjectDirectory = Path.GetDirectoryName(projectPath);
mainParameters.OutputDirectory = OutputDir;
//dynamic results = interpreter.Main(mainParameters);
var results = interpreter.MainThrows(mainParameters);
Assert.True(File.Exists(ProjectConnStr.Substring("MGA=".Length)));
result = results.Success;
if (result == false)
{
Test.DeleteDirectory(OutputDir);
}
}
finally
{
project.Close(true);
}
return result;
}
示例6: RunCyPhyMLSync
protected void RunCyPhyMLSync(System.Action<MgaProject, CyPhyMetaLink.CyPhyMetaLinkAddon, CyPhyMetaLink.CyPhyMetalinkInterpreter> testAction)
{
try
{
if (debugMetalinkStartup)
{
metalink.WaitForExit();
string stderr = metalink.StandardError.ReadToEnd();
string stdout = metalink.StandardOutput.ReadToEnd();
}
Exception exception = null;
AutoResetEvent workEvent = new AutoResetEvent(false);
Thread work = new Thread(new ThreadStart(delegate
{
try
{
// Import XME file to create an MGA
String xmeFullPath = Path.Combine(TestModelDir, testXMEFilename);
String mgaFullPath = TestModelDir + testInputFilename;
MgaUtils.ImportXME(xmeFullPath, mgaFullPath);
Assert.True(File.Exists(mgaFullPath), "MGA file not found. XME import may have failed.");
MgaProject project = new MgaProject();
project.EnableAutoAddOns(true);
project.OpenEx("MGA=" + mgaFullPath, "", true);
try
{
Assert.Contains("MGA.Addon.CyPhyMLPropagate", project.AddOnComponents.Cast<IMgaComponentEx>().Select(x => x.ComponentProgID));
CyPhyMetaLink.CyPhyMetaLinkAddon propagate = (CyPhyMetaLink.CyPhyMetaLinkAddon)project.AddOnComponents.Cast<IMgaComponent>().Where(comp => comp is CyPhyMetaLink.CyPhyMetaLinkAddon).FirstOrDefault();
CyPhyMetaLink.CyPhyMetalinkInterpreter interpreter = new CyPhyMetaLink.CyPhyMetalinkInterpreter();
propagate.TestMode = true;
interpreter.GMEConsole = GME.CSharp.GMEConsole.CreateFromProject(project);
interpreter.MgaGateway = new MgaGateway(project);
interpreter.ConnectToMetaLinkBridge(project, 128);
propagate.bridgeClient.SocketQueue.EditMessageReceived += msg => addonMessagesQueue.Add(msg);
testAction(project, propagate, interpreter);
}
finally
{
project.Save(project.ProjectConnStr + "_posttest.mga", true);
project.Close(true);
}
}
catch (Exception e)
{
exception = e;
KillMetaLink();
}
finally
{
workEvent.Set();
}
}));
work.SetApartmentState(ApartmentState.STA);
work.Start();
ManualResetEvent metalinkEvent = new ManualResetEvent(true);
metalinkEvent.SafeWaitHandle = new SafeWaitHandle(metalink.Handle, false);
int handle = WaitHandle.WaitAny(new WaitHandle[] { metalinkEvent, workEvent });
if (exception != null)
{
throw new Exception("Test failed", exception);
}
if (handle == 0)
{
work.Abort();
throw new Exception("metalink exited");
}
}
finally
{
KillMetaLink();
lock (metalinkLogStream)
metalinkLogStream.Dispose();
}
}
示例7: CAD_CurrentObjectNull
// This tests that the interpreters would not fail on null object
public void CAD_CurrentObjectNull()
{
var XmePath = Path.GetFullPath(@"..\..\..\..\models\CADTeam\MSD_CAD.xme");
UnpackXmes(XmePath);
var mgaFile = XmePath.Replace(".xme", ".mga");
string ProjectConnStr = "MGA=" + mgaFile;
MgaProject project = new MgaProject();
project.OpenEx(ProjectConnStr, "CyPhyML", null);
try
{
var PrepIFABInt = new CyPhyPrepareIFab.CyPhyPrepareIFabInterpreter();
var CADAnalysisInt = new CyPhyCADAnalysis.CyPhyCADAnalysisInterpreter();
var CyPhy2CAD = new CyPhy2CAD_CSharp.CyPhy2CAD_CSharpInterpreter();
PrepIFABInt.Initialize(project);
CADAnalysisInt.Initialize(project);
CyPhy2CAD.Initialize(project);
Assert.DoesNotThrow(() => PrepIFABInt.InvokeEx(project, null, null, 16));
Assert.DoesNotThrow(() => CyPhy2CAD.InvokeEx(project, null, null, 16));
Assert.DoesNotThrow(() => CADAnalysisInt.InvokeEx(project, null, null, 16));
}
finally
{
project.Close(true);
}
}
示例8: GetProject
private MgaProject GetProject(String filename, String metaName) {
MgaProject result = null;
if (filename != null && filename != "") {
if (Path.GetExtension(filename) == ".mga") {
result = new MgaProject();
if (System.IO.File.Exists(filename)) {
gmeConsole.Out.Write("Opening {0} ... ", filename);
result.OpenEx("MGA=" + filename, metaName, null);
} else {
gmeConsole.Out.Write("Creating {0} ... ", filename);
result.Create("MGA=" + filename, metaName);
}
gmeConsole.Out.WriteLine("Done.");
} else {
gmeConsole.Error.WriteLine("{0} file must be an mga project.", filename);
_exitStatus |= Errors.FileError;
}
} else {
gmeConsole.Error.WriteLine("Please specify an Mga project.");
_exitStatus |= Errors.FileError;
}
return result;
}
示例9: AnalysisModelSupported
public static bool AnalysisModelSupported(string projectPath, string absPath)
{
bool result = false;
Assert.True(File.Exists(projectPath), "Project file does not exist.");
string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath);
MgaProject project = new MgaProject();
project.OpenEx(ProjectConnStr, "CyPhyML", null);
try
{
var terr = project.BeginTransactionInNewTerr();
var testObj = project.ObjectByPath[absPath] as MgaFCO;
project.AbortTransaction();
CyPhyMasterInterpreter.AnalysisModelProcessor analysisModelProcessor = null;
project.BeginTransactionInNewTerr();
try
{
Assert.ThrowsDelegate d = () =>
{
analysisModelProcessor = CyPhyMasterInterpreter.AnalysisModelProcessor.GetAnalysisModelProcessor(testObj as MgaModel);
};
Assert.DoesNotThrow(d);
Assert.True(analysisModelProcessor != null, string.Format("Analysis model processor was not able to create the model processor for {0} {1}.", testObj.Name, testObj.Meta.Name));
}
finally
{
project.AbortTransaction();
}
}
finally
{
project.Close(true);
}
return result;
}
示例10: RunMasterInterpreter
public static bool RunMasterInterpreter(
string projectPath,
string absPath,
string configPath,
bool postToJobManager = false,
bool keepTempModels = false)
{
bool result = false;
Assert.True(File.Exists(projectPath), "Project file does not exist.");
string ProjectConnStr = "MGA=" + Path.GetFullPath(projectPath);
MgaProject project = new MgaProject();
project.OpenEx(ProjectConnStr, "CyPhyML", null);
try
{
var terr = project.BeginTransactionInNewTerr();
var testObj = project.ObjectByPath[absPath] as MgaFCO;
var configObj = project.ObjectByPath[configPath] as MgaFCO;
project.AbortTransaction();
using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project))
{
masterInterpreter.Logger.GMEConsoleLoggingLevel = CyPhyGUIs.SmartLogger.MessageType_enum.Debug;
var miResults = masterInterpreter.RunInTransactionOnOneConfig(testObj as MgaModel, configObj, postToJobManager, keepTempModels);
result = miResults.Any(x => x.Success == false) ? false: true;
}
}
finally
{
project.Close(true);
}
return result;
}
示例11: Run
//public List<IMgaFCO> InsertComponents(
// IMgaFCO designContainer,
// IMgaFCO componentRef,
// List<IMgaFCO> components,
// List<KeyValuePair<IMgaFCO, string>> messages)
/// <summary>
/// Calls CLM_LIght without showing any GUI.
/// </summary>
/// <param name="outputdirname">xme folder from trunk/models/DynamicsTeam</param>
/// <param name="projectPath">name of mga-file</param>
/// <param name="absPath">Folder-path to test-bench</param>
/// <returns>Boolean - True -> interpreter call was successful</returns>
public static bool Run(
string projectPath,
string absPathDesignContainer,
List<string> absPathComponentsToAdd)
{
bool result = false;
Assert.True(File.Exists(projectPath), "Project file does not exist.");
string ProjectConnStr = "MGA=" + projectPath;
//Type CLM_light_interpreter = Type.GetTypeFromProgID("MGA.Interpreter.CLM_light");
MgaProject project = new MgaProject();
project.OpenEx(ProjectConnStr, "CyPhyML", null);
try
{
//dynamic interpreter = Activator.CreateInstance(CLM_light_interpreter);
var interpreter = new CLM_light.CLM_lightInterpreter();
interpreter.Initialize(project);
var terr = project.BeginTransactionInNewTerr();
var designContainer = project.ObjectByPath[absPathDesignContainer] as MgaFCO;
List<IMgaFCO> componentsToAdd = new List<IMgaFCO>();
var defaultComponentRef = designContainer.ChildObjects.Cast<MgaFCO>().FirstOrDefault(x => x.Meta.Name == "ComponentRef");
var compRefCountBeforeInsert = designContainer.ChildObjects.Cast<MgaFCO>().Count(x => x.Meta.Name == "ComponentRef");
Assert.False(defaultComponentRef == null, string.Format("Design Container has no Component References: {0}", absPathDesignContainer));
foreach (string path in absPathComponentsToAdd)
{
var component = project.ObjectByPath[path] as MgaFCO;
Assert.False(component == null, string.Format("Component was not found in the project: {0}", path));
componentsToAdd.Add(component);
}
List<KeyValuePair<IMgaFCO, string>> messages = new List<KeyValuePair<IMgaFCO, string>>();
if (interpreter.CheckForValidContext(designContainer))
{
List<IMgaFCO> results = interpreter.InsertComponents(designContainer, defaultComponentRef, componentsToAdd, messages);
var compRefCountAfterInsert = designContainer.ChildObjects.Cast<MgaFCO>().Count(x => x.Meta.Name == "ComponentRef");
result = compRefCountBeforeInsert + absPathComponentsToAdd.Count == compRefCountAfterInsert;
project.AbortTransaction();
Assert.True(File.Exists(ProjectConnStr.Substring("MGA=".Length)));
}
}
finally
{
project.Close(true);
}
return result;
}