本文整理汇总了C#中MgaProject.Open方法的典型用法代码示例。如果您正苦于以下问题:C# MgaProject.Open方法的具体用法?C# MgaProject.Open怎么用?C# MgaProject.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MgaProject
的用法示例。
在下文中一共展示了MgaProject.Open方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetProject
/* Copied/Adapted from CyPhyCompomponentExporterCL Proj */
public static MgaProject GetProject(String mgaFilename)
{
MgaProject result = null;
if (mgaFilename != null && mgaFilename != "")
{
if (Path.GetExtension(mgaFilename) == ".mga")
{
result = new MgaProject();
if (System.IO.File.Exists(mgaFilename))
{
Console.Out.Write("Opening {0} ... ", mgaFilename);
bool ro_mode = true;
result.Open("MGA=" + Path.GetFullPath(mgaFilename), out ro_mode);
Console.Out.WriteLine("Done.");
}
else
{
Console.Error.WriteLine("{0} file must be an existing mga project.", mgaFilename);
}
}
else
{
Console.Error.WriteLine("{0} file must be an mga project.", mgaFilename);
}
}
else
{
Console.Error.WriteLine("Please specify an Mga project.");
}
return result;
}
示例2: ExporterFixture
public ExporterFixture()
{
String mgaConnectionString;
GME.MGA.MgaUtils.ImportXMEForTest(pathXME, out mgaConnectionString);
proj = new MgaProject();
bool ro_mode;
proj.Open(mgaConnectionString, out ro_mode);
proj.EnableAutoAddOns(true);
}
示例3: GMEProjectFixtureBase
public GMEProjectFixtureBase()
{
String mgaConnectionString;
GME.MGA.MgaUtils.ImportXMEForTest(xmePath, out mgaConnectionString);
var mgaPath = mgaConnectionString.Substring("MGA=".Length);
Assert.True(File.Exists(Path.GetFullPath(mgaPath)),
String.Format("{0} not found. Model import may have failed.", mgaPath));
proj = new MgaProject();
bool ro_mode;
proj.Open("MGA=" + Path.GetFullPath(mgaPath), out ro_mode);
proj.EnableAutoAddOns(true);
}
示例4: Main
public static void Main(string[] args)
{
try
{
// parse command line arguments
string projectConnStr = args[0];
string originalSubjectID = args[1];
string[] configIDs = args.Skip(2).ToArray();
if (projectConnStr.StartsWith("MGA=") == false)
{
// use the full absolute path
projectConnStr = "MGA=" + Path.GetFullPath(projectConnStr);
}
MgaProject project = new MgaProject();
bool ro_mode;
project.Open(projectConnStr, out ro_mode);
try
{
// get an instance of the master interpreter
using (var master = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI(project))
{
// create a configuration for the run
var configLight = new CyPhyMasterInterpreter.ConfigurationSelectionLight();
configLight.ContextId = originalSubjectID;
configLight.SelectedConfigurationIds = configIDs;
configLight.KeepTemporaryModels = false;
configLight.PostToJobManager = true;
// run master interpreter on configuration
var results = master.RunInTransactionWithConfigLight(configLight);
// summarize results
master.WriteSummary(results);
}
}
finally
{
project.Close(true);
}
}
catch (Exception e)
{
System.Console.Error.WriteLine(e.ToString());
System.Environment.Exit(5);
}
}
示例5: GetProject
private static MgaProject GetProject( String filename ) {
MgaProject result = null;
if( filename != null && filename != "" ) {
if( Path.GetExtension( filename ) == ".mga" ) {
result = new MgaProject();
if( System.IO.File.Exists( filename ) ) {
Console.Out.Write( "Opening {0} ... ", filename );
bool ro_mode;
result.Open( "MGA=" + Path.GetFullPath(filename), out ro_mode );
} else {
Console.Out.Write( "Creating {0} ... ", filename );
result.Create( "MGA=" + filename, "CyPhyML" );
}
Console.Out.WriteLine( "Done." );
} else {
Console.Error.WriteLine( "{0} file must be an mga project.", filename );
}
} else {
Console.Error.WriteLine( "Please specify an Mga project." );
}
return result;
}
示例6: 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();
}
}
//.........这里部分代码省略.........
示例7: 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"));
}
示例8: 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
//.........这里部分代码省略.........
示例9: GetProject
private static MgaProject GetProject(String filename)
{
MgaProject result = null;
if (!string.IsNullOrEmpty(filename))
{
if (Path.GetExtension(filename) == ".mga")
{
result = new MgaProject();
if (File.Exists(filename))
{
Console.Out.Write("Opening {0} ... ", filename);
var roMode = true;
result.Open("MGA=" + filename, out roMode);
Console.Out.WriteLine("Done.");
}
else
{
Console.Error.WriteLine("{0} file must be an existing mga project.", filename);
}
}
else
{
Console.Error.WriteLine("{0} file must be an mga project.", filename);
}
}
else
{
Console.Error.WriteLine("Please specify an Mga project.");
}
return result;
}
示例10: 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" }
//.........这里部分代码省略.........
示例11: Run
public static bool Run(string outputdirname, string xmePath, string absPath, bool copycomponents = false, bool deletedir = true)
{
bool status = true;
string ProjectConnStr;
if (deletedir && Directory.Exists(outputdirname))
{
Directory.Delete(outputdirname, true);
}
Directory.CreateDirectory(outputdirname);
MgaUtils.ImportXMEForTest(xmePath, Path.Combine(outputdirname, Path.GetFileNameWithoutExtension(xmePath) + "_CADtest.mga"), out ProjectConnStr);
MgaProject project = new MgaProject();
bool ro_mode;
project.Open(ProjectConnStr, out ro_mode);
try
{
var terr = project.BeginTransactionInNewTerr();
var testObj = project.ObjectByPath[absPath] as MgaFCO;
project.AbortTransaction();
return Run(outputdirname, project, testObj, copycomponents);
}
catch(Exception)
{
status = false;
}
finally
{
project.Close();
}
return status;
}
示例12: DesignSpaceWithRefs
//[Fact]
public void DesignSpaceWithRefs()
{
var fullTestPath = Path.Combine(_exportModelDirectory, "DesignSpaceWithRefs");
var xmeFilePath = Path.Combine(fullTestPath, "DesignSpaceWithRefs.xme");
var pathExportedDesign = Path.Combine(fullTestPath, "DesignSpace.adm");
// delete design file if it already exists
if (File.Exists(pathExportedDesign))
{
File.Delete(pathExportedDesign);
}
String connectionString;
GME.MGA.MgaUtils.ImportXMEForTest(xmeFilePath, out connectionString);
var proj = new MgaProject();
bool ro_mode;
proj.Open(connectionString, out ro_mode);
proj.EnableAutoAddOns(true);
try
{
var designExporter = new CyPhyDesignExporter.CyPhyDesignExporterInterpreter();
designExporter.Initialize(proj);
var mgaGateway = new MgaGateway(proj);
MgaFCO currentFCO = null;
mgaGateway.PerformInTransaction(delegate
{
currentFCO = proj.get_ObjectByPath("/@DesignSpaces|kind=DesignSpace|relpos=0/@DesignSpace|kind=DesignContainer|relpos=0") as MgaFCO;
Assert.NotNull(currentFCO);
});
var parameters = new CyPhyGUIs.InterpreterMainParameters()
{
CurrentFCO = currentFCO,
Project = proj,
OutputDirectory = fullTestPath
};
var result = designExporter.Main(parameters);
var design = avm.Design.LoadFromFile(pathExportedDesign);
/// Add assert statements to check structure
var root = design.RootContainer;
Assert.NotNull(root);
Assert.Equal(1, root.Container1.Count(c => c.Name == "AltContainer"));
var AltContainer = root.Container1.First(c => c.Name == "AltContainer");
Assert.Equal(1, AltContainer.ComponentInstance.Count(ci => ci.Name == "CompA_5"));
Assert.Equal(1, AltContainer.ComponentInstance.Count(ci => ci.Name == "CompA_6"));
Assert.Equal(1, AltContainer.ComponentInstance.Count(ci => ci.Name == "CompA_7"));
Assert.Equal(1, root.Container1.Count(c => c.Name == "DesignContainer"));
var DesignContainer = root.Container1.First(c => c.Name == "DesignContainer");
Assert.Equal(1, DesignContainer.ComponentInstance.Count(ci => ci.Name == "CompA3"));
Assert.Equal(1, DesignContainer.Container1.Count(c => c.Name == "Assembly1"));
var Assembly1 = DesignContainer.Container1.First(c => c.Name == "Assembly1");
Assert.Equal(1, Assembly1.ComponentInstance.Count(ci => ci.Name == "CompA1"));
Assert.Equal(1, Assembly1.ComponentInstance.Count(ci => ci.Name == "CompA2"));
Assert.Equal(1, root.Container1.Count(c => c.Name == "ReusableContainer"));
var ReusableContainer = root.Container1.First(c => c.Name == "ReusableContainer");
Assert.Equal(1, ReusableContainer.Container1.Count(c => c.Name == "Assembly4"));
var Assembly4 = ReusableContainer.Container1.First(c => c.Name == "Assembly4");
Assert.Equal(1, Assembly4.ComponentInstance.Count(ci => ci.Name == "CompA1"));
Assert.Equal(1, Assembly4.ComponentInstance.Count(ci => ci.Name == "CompA2"));
Assert.Equal(1, ReusableContainer.ComponentInstance.Count(ci => ci.Name == "CompA4"));
Assert.Equal(1, root.ComponentInstance.Count(ci => ci.Name == "CompA"));
Assert.Equal(1, root.ComponentInstance.Count(ci => ci.Name == "CompA"));
}
finally
{
proj.Close();
}
}
示例13: CallCyberInterpreter
//.........这里部分代码省略.........
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-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]);
示例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("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;
}
//.........这里部分代码省略.........