本文整理汇总了C#中MgaProject.Close方法的典型用法代码示例。如果您正苦于以下问题:C# MgaProject.Close方法的具体用法?C# MgaProject.Close怎么用?C# MgaProject.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MgaProject
的用法示例。
在下文中一共展示了MgaProject.Close方法的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: ImportXME
public static void ImportXME(string xmePath, string mgaPath, bool enableAutoAddons=false)
{
MgaParser parser = new MgaParser();
string paradigm;
string paradigmVersion;
object paradigmGuid;
string basename;
string version;
parser.GetXMLInfo(xmePath, out paradigm, out paradigmVersion, out paradigmGuid, out basename, out version);
parser = new MgaParser();
MgaProject project = new MgaProject();
MgaResolver resolver = new MgaResolver();
resolver.IsInteractive = false;
dynamic dynParser = parser;
dynParser.Resolver = resolver;
project.Create("MGA=" + Path.GetFullPath(mgaPath), paradigm);
if (enableAutoAddons)
{
project.EnableAutoAddOns(true);
}
try
{
parser.ParseProject(project, xmePath);
project.Save();
}
finally
{
project.Close();
}
}
示例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: 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: 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;
}
示例6: 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;
}
示例7: 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);
}
}
示例8: Run
public static bool Run(string outputdirname, MgaProject project, MgaFCO testObj, bool copycomponents)
{
bool status = true;
try
{
if (copycomponents)
{
CopyDirectory(Path.Combine(GetProjectDir(project),"components"), Path.Combine(outputdirname, "components"));
}
var interpreter = new CyPhy2CAD_CSharp.CyPhy2CAD_CSharpInterpreter();
interpreter.Initialize(project);
var mainParameters = new CyPhyGUIs.InterpreterMainParameters();
var cadSettings = new CyPhy2CAD_CSharp.CyPhy2CADSettings();
cadSettings.OutputDirectory = outputdirname;
cadSettings.AuxiliaryDirectory = "";
mainParameters.config = cadSettings;
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(GetProjectDir(project));
mainParameters.OutputDirectory = outputdirname;
interpreter.Main(mainParameters);
}
catch (Exception)
{
status = false;
}
finally
{
project.Close();
}
return status;
}
示例9: DesignPackageImport
public void DesignPackageImport()
{
// Clean the test directory
var pathTest = Path.Combine(META.VersionInfo.MetaPath,
"test",
"InterchangeTest",
"DesignInterchangeTest",
"ImportTestUnits",
"Package");
foreach (var path in Directory.EnumerateDirectories(pathTest))
{
Directory.Delete(path, true);
}
foreach (var path in Directory.EnumerateFiles(pathTest, "*.*"))
{
if (!path.Contains("NestedFolders.adp"))
{
File.Delete(path);
}
}
// Create a test project
var proj = new MgaProject();
proj.Create("MGA=" + Path.Combine(pathTest,"testmodel.mga"), "CyPhyML");
try
{
String pathCA = null;
proj.PerformInTransaction(() =>
{
// Instantiate the importer and import the package
var importer = new AVMDesignImporter(GMEConsole.CreateFromProject(proj), proj);
var mdlCA = importer.ImportFile(Path.Combine(pathTest, "NestedFolders.adp"), AVMDesignImporter.DesignImportMode.CREATE_CAS);
var ca = CyPhyClasses.ComponentAssembly.Cast(mdlCA.Impl);
pathCA = ca.GetDirectoryPath(ComponentLibraryManager.PathConvention.ABSOLUTE);
});
// Check the design's backend folder for all files except for the ADM.
var filesExpected = new List<String>
{
"testObject.txt",
"dir1/testObject.txt",
"dir1/dir1a/testObject.txt",
"dir2/testObject.txt"
};
var filesInDir = Directory.GetFiles(pathCA, "*.*", SearchOption.AllDirectories);
Assert.Equal(filesExpected.Count(), filesInDir.Count());
foreach (var file in filesExpected)
{
String fullPath = Path.Combine(pathCA, file);
Assert.True(File.Exists(fullPath));
}
}
finally
{
proj.Save();
proj.Close();
}
}
示例10: TestCodeSample
//.........这里部分代码省略.........
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();
}
}
if (success)
{
Console.Out.WriteLine("[OK] Analysis model processor creation was checked for: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures);
}
else
{
Console.Error.WriteLine("[FAILED] Analysis model processor creation was checked for: {0}, Success: {1}, Failed: {2}", numContexts, numSuccess, numFailures);
}
Assert.True(success, "At least one analysis model processor was not instantiated as expected.");
}
finally
{
project.Close(true);
}
}
示例11: 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);
}
}
示例12: TestCodeSample
//.........这里部分代码省略.........
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
{
Console.Error.WriteLine("[FAILED] Tried to get configurations for: {0} test benches. Success: {1}, Failed {2}", numContexts, numSuccess, numFailures);
}
Assert.True(success, "At least one context was failed to check against the expected results.");
}
finally
{
project.Close(true);
}
}
示例13: 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;
}
示例14: 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();
}
}
示例15: 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;
}