本文整理汇总了C#中MgaProject.BeginTransactionInNewTerr方法的典型用法代码示例。如果您正苦于以下问题:C# MgaProject.BeginTransactionInNewTerr方法的具体用法?C# MgaProject.BeginTransactionInNewTerr怎么用?C# MgaProject.BeginTransactionInNewTerr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MgaProject
的用法示例。
在下文中一共展示了MgaProject.BeginTransactionInNewTerr方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例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: CheckParadigmVersionUpgrade
public static void CheckParadigmVersionUpgrade(MgaProject project)
{
GME.Util.MgaRegistrar registar = new GME.Util.MgaRegistrar();
string MetaConnStr;
object MetaGuid = null;
object ProjectMetaGuid;
project.BeginTransactionInNewTerr();
try
{
registar.QueryParadigm(project.MetaName, out MetaConnStr, ref MetaGuid, GME.Util.regaccessmode_enum.REGACCESS_BOTH);
ProjectMetaGuid = project.MetaGUID;
}
finally
{
project.AbortTransaction();
}
if (((Array)ProjectMetaGuid).Cast<byte>().SequenceEqual(((Array)MetaGuid).Cast<byte>()) == false)
{
Xunit.Assert.True(false, string.Format("Please upgrade {0} to the latest registered {1} paradigm", project.ProjectConnStr, project.MetaName));
}
}
示例7: Main
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
{
string OutputBaseDir = (string)componentParameters["output_dir"];
SotConfig sotConfig = new SotConfig();
sotConfig.MultiJobRun = true;
sotConfig.OriginalProjectFileName = project.ProjectConnStr.Substring("MGA=".Length);
sotConfig.ProjectFileName = Path.Combine(OutputBaseDir, Path.GetFileName(sotConfig.OriginalProjectFileName));
// can't be in a tx and save the project
project.AbortTransaction();
project.Save("MGA=" + sotConfig.ProjectFileName, true);
project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED);
MgaGateway.PerformInTransaction(delegate
{
sotConfig.SoTID = currentobj.ID;
}, transactiontype_enum.TRANSACTION_READ_ONLY);
using (StreamWriter writer = new StreamWriter(Path.Combine(OutputBaseDir, "manifest.sot.json")))
{
writer.WriteLine(Newtonsoft.Json.JsonConvert.SerializeObject(sotConfig, Newtonsoft.Json.Formatting.Indented));
}
string configsDir = Path.Combine(Path.GetDirectoryName((string)componentParameters["original_project_file"]), "config");
if (Directory.Exists(configsDir))
{
var configs = Directory.EnumerateFiles(configsDir, "*xml").ToList();
string sotConfigDir = Path.Combine(OutputBaseDir, "config");
Directory.CreateDirectory(sotConfigDir);
foreach (var config in configs)
{
File.Copy(config, Path.Combine(sotConfigDir, Path.GetFileName(config)));
}
}
//componentParameters["labels"] = "";
//componentParameters["runCommand"] = ;
//componentParameters["results_zip_py"] as string;
// result.LogFileDirectory = Path.Combine(MainParameters.ProjectDirectory, "log");
// componentParameters["build_query"] as string;
}
示例8: Connectors_Invalid
public void Connectors_Invalid()
{
string XmePath = Path.GetFullPath(@"..\..\..\..\models\CADTeam\MSD_CAD.xme");
string OutputDir = Path.Combine(Path.GetDirectoryName(XmePath), "Connectors_Invalid");
var generatedAsmPath = Path.Combine(OutputDir, generatedAsmFile);
if (Directory.Exists(OutputDir))
{
Directory.Delete(OutputDir, true);
}
Directory.CreateDirectory(OutputDir);
string ProjectConnStr;
MgaUtils.ImportXMEForTest(XmePath, Path.Combine(OutputDir, Path.GetFileNameWithoutExtension(XmePath) + "_CADtest.mga"), out ProjectConnStr);
MgaProject project = new MgaProject();
bool ro_mode;
project.Open(ProjectConnStr, out ro_mode);
// testbenchpath doesn't work:(
var terr = project.BeginTransactionInNewTerr();
var testObj = project.RootFolder.GetObjectByPathDisp("/@Generated_configurations/MyMassSpringDamper/Config1/MyMassSpringDamper_cfg_broken");
project.AbortTransaction();
bool status = CyPhy2CADRun.Run(OutputDir, project, (MgaFCO)testObj, false);
string logfilename = Path.Combine(OutputDir, "log", CyPhy2CAD_CSharp.Logger.LogFileName);
StreamReader r = new StreamReader(logfilename);
string logcontent = r.ReadToEnd();
Assert.True(logcontent.Contains("badname"));
}
示例9: ExecuteInTransaction
private void ExecuteInTransaction(MgaProject project, Action doWork, bool abort = false, transactiontype_enum type = transactiontype_enum.TRANSACTION_NON_NESTED)
{
if (project == null ||
doWork == null)
{
throw new ArgumentNullException();
}
bool inTx = (project.ProjectStatus & 8) != 0;
if (inTx)
{
doWork();
return;
}
project.BeginTransactionInNewTerr(type);
try
{
doWork();
if (abort)
{
project.AbortTransaction();
}
else
{
project.CommitTransaction();
}
project.FlushUndoQueue();
}
catch (Exception)
{
try
{
project.AbortTransaction();
}
catch
{
}
throw;
}
}
示例10: TestCodeSample
//[Fact]
public void TestCodeSample()
{
string ProjectConnStr;
MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr);
MgaProject project = new MgaProject();
bool ro_mode;
project.Open(ProjectConnStr, out ro_mode);
MgaHelper.CheckParadigmVersionUpgrade(project);
try
{
List<IMgaFCO> objectsToGetConfigurations = null;
project.BeginTransactionInNewTerr();
try
{
// discover objects
var allObjects = project
.RootFolder
.ChildFolders
.Cast<MgaFolder>()
.Where(x => x.Name.StartsWith("0"))
.SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast<IMgaFCO>())
.Where(x => x.RootFCO == x);
// get all objects from folders starts with 0 within the root folder.
objectsToGetConfigurations = allObjects.Where(x => x.AbsPath.Contains("TestingGetConfigurations")).ToList();
objectsToGetConfigurations.Sort((x, y) =>
{
return x.Meta.Name.CompareTo(y.Meta.Name) != 0 ?
x.Meta.Name.CompareTo(y.Meta.Name) :
x.AbsPath.CompareTo(y.AbsPath);
});
}
finally
{
project.AbortTransaction();
}
Assert.True(objectsToGetConfigurations != null, "There are no object in the project that has to be checked.");
int numContexts = objectsToGetConfigurations.Count;
int numSuccess = 0;
int numFailures = 0;
bool success = true;
foreach (var subject in objectsToGetConfigurations)
{
// single test
using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project))
{
IMgaFCOs configurations = null;
Assert.ThrowsDelegate d = () =>
{
configurations = masterInterpreter.GetConfigurations(subject as MgaModel);
};
Assert.DoesNotThrow(d);
//Assert.True(configurations != null, "GetConfiguration returned with null.");
if (configurations == null)
{
numFailures++;
}
else
{
numSuccess++;
}
// print out nicely in the GME console
project.BeginTransactionInNewTerr();
try
{
Console.Out.WriteLine("{0} [{1}] has {2} configurations.", subject.Name, subject.Meta.Name, configurations.Count);
foreach (IMgaFCO configuration in configurations)
{
Console.Out.WriteLine(" > {0} - {1}", configuration.Name, configuration.ID);
}
}
finally
{
project.AbortTransaction();
}
}
}
if (success)
{
Console.Out.WriteLine("[OK] Got configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures);
}
else
//.........这里部分代码省略.........
示例11: CallCyPhy2CADWithTransaction
public void CallCyPhy2CADWithTransaction(MgaProject project, MgaFCO toplevelAssembly, int param)
{
if (GMEConsole == null)
{
GMEConsole = GMEConsole.CreateFromProject(project);
}
Dictionary<MgaFCO, MgaFCO> objectMap = new Dictionary<MgaFCO, MgaFCO>();
try
{
project.BeginTransactionInNewTerr(transactiontype_enum.TRANSACTION_NON_NESTED);
handleEvents = false;
GenerateCADAssemblyXml(project, toplevelAssembly, param);
try
{
HighlightInTree(toplevelAssembly, 1);
}
catch (Exception e)
{
GMEConsole.Error.Write("Error during processing the model: " + e.Message);
// Don't do anything, there won't be highlight
}
}
finally
{
project.AbortTransaction();
handleEvents = true;
}
}
示例12: CallCyberInterpreter
private bool CallCyberInterpreter(CyPhy.CyberModel cyberModel)
{
bool success = true;
string cyberModelPath = string.Empty;
// checks
if (string.IsNullOrWhiteSpace(cyberModel.Attributes.FileRef))
{
this.Logger.WriteError("[Cyber] Model filename attribute is empty: {0}", cyberModel.ToHyperLink());
return false;
}
if (Path.IsPathRooted(cyberModel.Attributes.FileRef))
{
cyberModelPath = cyberModel.Attributes.FileRef;
}
else
{
cyberModelPath = Path.Combine(this.mainParameters.ProjectDirectory, cyberModel.Attributes.FileRef);
}
string cyberModelMgaPath = string.Empty;
string cyberModelXmePath = string.Empty;
bool requiresImport = false;
cyberModelMgaPath = Path.GetFileNameWithoutExtension(cyberModelPath) + ".mga";
cyberModelXmePath = Path.GetFileNameWithoutExtension(cyberModelPath) + ".xme";
if (Path.GetExtension(cyberModelPath) == ".mga")
{
if (File.Exists(cyberModelMgaPath) == false)
{
requiresImport = true;
if (File.Exists(cyberModelXmePath) == false)
{
this.Logger.WriteError("[Cyber] Model filename does not exist: {0} {1}", cyberModel.ToHyperLink(), cyberModelPath);
return false;
}
}
}
else if (Path.GetExtension(cyberModelPath) == ".xme")
{
requiresImport = true;
if (File.Exists(cyberModelXmePath) == false)
{
this.Logger.WriteError("[Cyber] Model filename does not exist: {0} {1}", cyberModel.ToHyperLink(), cyberModelPath);
return false;
}
}
else
{
this.Logger.WriteError("[Cyber] Model filename attribute has unknown extension (valid: [mga|xme]): {0} {1}", cyberModel.ToHyperLink(), Path.GetExtension(cyberModelPath));
return false;
}
MgaProject cyberProject = new MgaProject();
if (requiresImport)
{
// FIXME: this will throw an exception if xme is referenced mga exists and it is being used.
MgaUtils.ImportXME(cyberModelXmePath, cyberModelMgaPath);
}
try
{
bool ro_mode;
// FIXME: any race conditions here???
// FIXME: for SoT we need to copy the referenced xme/mgas
cyberProject.Open("MGA=" + cyberModelMgaPath, out ro_mode);
string cyberComponentPath = "";
if (cyberModel.Attributes.FilePathWithinResource.Contains('.'))
{
cyberComponentPath = cyberModel.Attributes.FilePathWithinResource.Substring(cyberModel.Attributes.FilePathWithinResource.IndexOf('.')).Replace(".", "/@");
}
this.Logger.WriteInfo("[Cyber] {0} --> {1}", cyberModel.Attributes.FilePathWithinResource, cyberComponentPath);
var terr = cyberProject.BeginTransactionInNewTerr();
MgaFCO currentObj = cyberProject.ObjectByPath[cyberComponentPath] as MgaFCO;
cyberProject.AbortTransaction();
terr.Destroy();
if (currentObj == null)
{
this.Logger.WriteError("[Cyber] Referenced cyber object was not found in model: {0} {1} {2}", cyberModel.ToHyperLink(), cyberModelPath, cyberModel.Attributes.FilePathWithinResource);
return false;
}
// Cyber model type and interpreter progid map. Each cyber model type has a different interpreter.
Dictionary<CyPhyClasses.CyberModel.AttributesClass.ModelType_enum, string> interpreterMap =
new Dictionary<CyPhyClasses.CyberModel.AttributesClass.ModelType_enum, string>()
{
//{ CyPhyClasses.CyberModel.AttributesClass.ModelType_enum.ESMoL, ""},
//{ CyPhyClasses.CyberModel.AttributesClass.ModelType_enum.SignalFlow, ""},
{ CyPhyClasses.CyberModel.AttributesClass.ModelType_enum.Simulink, "MGA.Interpreter.Cyber2SLC_CodeGen" }
//.........这里部分代码省略.........
示例13: TestCodeSample
//[Fact]
public void TestCodeSample()
{
string ProjectConnStr;
MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr);
MgaProject project = new MgaProject();
bool ro_mode;
project.Open(ProjectConnStr, out ro_mode);
MgaHelper.CheckParadigmVersionUpgrade(project);
try
{
List<IMgaFCO> objectsToCheck = null;
project.BeginTransactionInNewTerr();
try
{
// discover objects
var allObjects = project
.RootFolder
.ChildFolders
.Cast<MgaFolder>()
.Where(x => x.Name.StartsWith("0"))
.SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast<IMgaFCO>())
.Where(x => x.RootFCO == x);
// get all objects from folders starts with 0 within the root folder.
objectsToCheck = allObjects.Where(x => x.AbsPath.Contains("TestingContextChecker") && x.Name.Contains("ReadOnly") == false).ToList();
objectsToCheck.Sort((x, y) =>
{
return x.Meta.Name.CompareTo(y.Meta.Name) != 0 ?
x.Meta.Name.CompareTo(y.Meta.Name) :
x.AbsPath.CompareTo(y.AbsPath);
});
}
finally
{
project.AbortTransaction();
}
Assert.True(objectsToCheck != null, "There are no object in the project that has to be checked.");
int numContexts = objectsToCheck.Count;
int numSuccess = 0;
int numFailures = 0;
bool success = true;
foreach (var subject in objectsToCheck)
{
// single test
using (var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project))
{
CyPhyMasterInterpreter.Rules.ContextCheckerResult[] contextCheckerResults = null;
// check context
var checkerSuccess = masterInterpreter.TryCheckContext(subject as MgaModel, out contextCheckerResults);
List<CyPhyMasterInterpreter.Rules.ContextCheckerResult> sortedResults = contextCheckerResults.ToList();
// sort results Passed, Failed, then alphabetically based on message.
sortedResults.Sort((x, y) => { return x.Success == y.Success ? x.Message.CompareTo(y.Message) : y.Success.CompareTo(x.Success); });
project.BeginTransactionInNewTerr();
try
{
MgaObject parent = null;
GME.MGA.Meta.objtype_enum type;
subject.GetParent(out parent, out type);
var successExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true;
if (successExpected == checkerSuccess)
{
numSuccess++;
//GMEConsole.Info.WriteLine("OK");
}
else
{
success = false;
foreach (var result in sortedResults)
{
TextWriter tw = null;
StringBuilder sb = new StringBuilder();
if (result.Success)
{
sb.Append("[Passed]");
tw = Console.Out;
}
else
{
sb.Append("[Failed]");
tw = Console.Error;
}
//.........这里部分代码省略.........
示例14: TestCodeSample
//[Fact]
public void TestCodeSample()
{
string ProjectConnStr;
MgaUtils.ImportXMEForTest(Path.GetFullPath(@"..\..\..\..\models\DynamicsTeam\MasterInterpreter\MasterInterpreter.xme"), out ProjectConnStr);
MgaProject project = new MgaProject();
bool ro_mode;
project.Open(ProjectConnStr, out ro_mode);
MgaHelper.CheckParadigmVersionUpgrade(project);
try
{
List<IMgaFCO> objectsToCheck = null;
project.BeginTransactionInNewTerr();
try
{
// discover objects
var allObjects = project
.RootFolder
.ChildFolders
.Cast<MgaFolder>()
.Where(x => x.Name.StartsWith("0"))
.SelectMany(x => x.GetDescendantFCOs(project.CreateFilter()).Cast<IMgaFCO>())
.Where(x => x.RootFCO == x);
// get all objects from folders starts with 0 within the root folder.
objectsToCheck = allObjects.Where(x => x.AbsPath.Contains("ProcessorTypesForContexts")).ToList();
objectsToCheck.Sort((x, y) =>
{
return x.Meta.Name.CompareTo(y.Meta.Name) != 0 ?
x.Meta.Name.CompareTo(y.Meta.Name) :
x.AbsPath.CompareTo(y.AbsPath);
});
}
finally
{
project.AbortTransaction();
}
Assert.True(objectsToCheck != null, "There are no object in the project that has to be checked.");
int numContexts = objectsToCheck.Count;
int numSuccess = 0;
int numFailures = 0;
bool success = true;
foreach (var subject in objectsToCheck)
{
// single test
CyPhyMasterInterpreter.AnalysisModelProcessor analysisModelProcessor = null;
project.BeginTransactionInNewTerr();
try
{
Assert.ThrowsDelegate d = () =>
{
analysisModelProcessor = CyPhyMasterInterpreter.AnalysisModelProcessor.GetAnalysisModelProcessor(subject as MgaModel);
};
MgaObject parent = null;
GME.MGA.Meta.objtype_enum type;
subject.GetParent(out parent, out type);
var contextSupportExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true;
if (contextSupportExpected)
{
Assert.DoesNotThrow(d);
Assert.True(analysisModelProcessor != null, string.Format("Analysis model processor was not able to create the model processor for {0} {1}.", subject.Name, subject.Meta.Name));
if (subject.Name.Contains(analysisModelProcessor.GetType().Name))
{
numSuccess++;
Console.Out.WriteLine("[Passed] {0} was created for test bench {1} [{2}]", analysisModelProcessor.GetType().Name, subject.Name, subject.Meta.Name);
}
else
{
success = false;
numFailures++;
Console.Out.WriteLine("[Failed] {0} was created for test bench {1} [{2}]", analysisModelProcessor.GetType().Name, subject.Name, subject.Meta.Name);
}
}
else
{
Assert.Throws<CyPhyMasterInterpreter.AnalysisModelContextNotSupportedException>(d);
numSuccess++;
Console.Out.WriteLine("[Passed] Context not supported {0} [{1}]", subject.Name, subject.Meta.Name);
}
}
finally
{
project.AbortTransaction();
}
}
//.........这里部分代码省略.........
示例15: CallCyberInterpreter
//.........这里部分代码省略.........
return false;
}
}
else
{
this.Logger.WriteError("[Cyber] Model filename attribute has unknown extension (valid: [mga|xme]): {0} {1}", cyberModel.ToHyperLink(), Path.GetExtension(cyberModelPath));
return false;
}
MgaProject cyberProject = new MgaProject();
if (requiresImport)
{
// FIXME: this will throw an exception if xme-referenced mga exists and it is being used.
MgaUtils.ImportXME(cyberModelXmePath, cyberModelMgaPath);
}
try
{
bool ro_mode;
// FIXME: any race conditions here???
// FIXME: for SoT we need to copy the referenced xme/mgas
cyberProject.Open("MGA=" + cyberModelMgaPath, out ro_mode);
string cyberComponentPath = "";
if (cyberModel.Attributes.FilePathWithinResource.Contains('.'))
{
cyberComponentPath = cyberModel.Attributes.FilePathWithinResource.Substring(cyberModel.Attributes.FilePathWithinResource.IndexOf('.')).Replace(".", "/@");
}
this.Logger.WriteInfo("[Cyber] {0} --> {1}", cyberModel.Attributes.FilePathWithinResource, cyberComponentPath);
var terr = cyberProject.BeginTransactionInNewTerr();
MgaFCO currentObj = cyberProject.ObjectByPath[cyberComponentPath] as MgaFCO;
cyberProject.AbortTransaction();
terr.Destroy();
if (currentObj == null)
{
this.Logger.WriteError("[Cyber] Referenced cyber object was not found in model: {0} {1} {2}", cyberModel.ToHyperLink(), cyberModelPath, cyberModel.Attributes.FilePathWithinResource);
return false;
}
// Cyber model type and interpreter progid map. Each cyber model type has a different interpreter.
Dictionary<CyPhyClasses.CyberModel.AttributesClass.ModelType_enum, string> interpreterMap =
new Dictionary<CyPhyClasses.CyberModel.AttributesClass.ModelType_enum, string>()
{
//{ CyPhyClasses.CyberModel.AttributesClass.ModelType_enum.ESMoL, ""},
//{ CyPhyClasses.CyberModel.AttributesClass.ModelType_enum.SignalFlow, ""},
{ CyPhyClasses.CyberModel.AttributesClass.ModelType_enum.Simulink, "MGA.Interpreter.Cyber2SLC_CodeGen" }
};
// call appropriate Cyber interpreter
Type tCyber = Type.GetTypeFromProgID(interpreterMap[cyberModel.Attributes.ModelType]);
if (tCyber == null)
{
this.Logger.WriteError("[Cyber] Cannot instantiate Cyber interpreter: {0} {1}", cyberModel.ToHyperLink(), interpreterMap[cyberModel.Attributes.ModelType]);
}
IMgaComponentEx cyberCodeGenerator = Activator.CreateInstance(tCyber) as IMgaComponentEx;
cyberCodeGenerator.Initialize(cyberProject);
string cyberOutputDir = Path.Combine(this.mainParameters.OutputDirectory, Modelica.CodeGenerator.MainPackage);
Directory.CreateDirectory(cyberOutputDir);
cyberCodeGenerator.ComponentParameter["output_dir"] = cyberOutputDir;