本文整理汇总了C#中MgaProject.CreateFilter方法的典型用法代码示例。如果您正苦于以下问题:C# MgaProject.CreateFilter方法的具体用法?C# MgaProject.CreateFilter怎么用?C# MgaProject.CreateFilter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MgaProject
的用法示例。
在下文中一共展示了MgaProject.CreateFilter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: convertFluidParameters
public void convertFluidParameters(MgaProject project)
{
MgaFilter modelicaFluidPortFilter = project.CreateFilter();
modelicaFluidPortFilter.ObjType = "OBJTYPE_MODEL";
modelicaFluidPortFilter.Kind = "ModelicaConnector";
var modelicaFluidPortArchetypes =
project
.AllFCOs(modelicaFluidPortFilter)
.Cast<MgaModel>()
.Where(x => x.ChildFCOs.OfType<MgaAtom>().ToList().Count() != 0 &&
x.ParentModel != null &&
x.ArcheType == null); //.ToList()
//GMEConsole.Info.WriteLine("Number of FluidPort Archetypes: {0}", modelicaFluidPortArchetypes.Count());
foreach (var port in modelicaFluidPortArchetypes)
{
//GMEConsole.Out.WriteLine("{0}", port.StrAttrByName["Class"]);
try
{
MgaAtom packageParameter =
port.ChildFCOs.OfType<MgaAtom>()
.Where(x => x.Name == "redeclare package Medium").FirstOrDefault();
if (packageParameter != null)
{
MgaFCO modelicaRedeclare = makeFCO(port, "ModelicaRedeclare");
modelicaRedeclare.Name = "Medium";
modelicaRedeclare.StrAttrByName["ModelicaRedeclareType"] = "Package";
modelicaRedeclare.StrAttrByName["Value"] = packageParameter.StrAttrByName["Value"];
}
}
catch (Exception ex)
{
GMEConsole.Warning.WriteLine(
"Could not make ModelicaRedeclare block within {0}.{1}",
port.ParentModel.Name,
port.Name);
GMEConsole.Error.WriteLine("{0}", ex.Message);
GMEConsole.Info.WriteLine("{0}", ex.StackTrace);
}
}
}
示例2: GetTestAssembly
protected MgaFCO GetTestAssembly(MgaProject project)
{
var filter = project.CreateFilter();
filter.Kind = "ComponentAssembly";
return project.AllFCOs(filter).Cast<MgaFCO>().Where(fco => fco.GetGuidDisp() == new Guid(testAssemblyId).ToString("B")).First();
}
示例3: 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();
}
}
//.........这里部分代码省略.........
示例4: Main
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
{
if (currentobj == null)
{
GMEConsole.Error.WriteLine("Please open a TestBench to run {0}.", ComponentName);
return;
}
else if (currentobj.Meta.Name != "TestBench")
{
GMEConsole.Error.WriteLine("Please open a TestBench to run {0}.", ComponentName);
return;
}
GMEConsole.Info.WriteLine("Running {0} on TestBench '{1}'", ComponentName, currentobj.Name);
// get root folder
IMgaFolder rootFolder = project.RootFolder;
// create a filter for components
MgaFilter filter = project.CreateFilter();
filter.Kind = "Component";
// get all components
var components = project.AllFCOs(filter).OfType<IMgaModel>().Cast<IMgaModel>().ToList();
// store components that may have an option (e.g. MM1, MM2)
List<IMgaModel> componentsToShow = new List<IMgaModel>();
// iterate through all components
// select only those which has more than one modelica model in it
foreach (var component in components)
{
var modelicaModels = component.ChildFCOs.Cast<IMgaFCO>().Where(x => x.Meta.Name == "ModelicaModel");
if (modelicaModels.Count() > 1)
{
componentsToShow.Add(component);
}
}
using (FidelitySelectorForm fsf = new FidelitySelectorForm())
{
// show the form for the user
foreach (var component in componentsToShow)
{
if (fsf.componentItems.FirstOrDefault(
x => x.Classification == component.StrAttrByName["Classifications"]) == null)
{
fsf.componentItems.Add(new ComponentItem(component));
}
}
// get the current fidelity settings from the Testbench registry
fsf.FidelitySettings = currentobj.RegistryValue["FidelitySettings"];
fsf.PopulateDgv();
fsf.ShowDialog();
foreach (string msg in fsf.consoleMessages)
{
GMEConsole.Info.WriteLine(msg);
}
// Check where the new fidelity settings should be applied:
if (fsf.rbThisTestbench.Checked)
{
// Write the updated fidelity settings back to the Testbench registry
currentobj.RegistryValue["FidelitySettings"] = fsf.FidelitySettings;
}
else if (fsf.rbThisFolder.Checked)
{
// Get all testbenches in the same folder as currentobj
var thisTestingFolder = currentobj.ParentFolder;
var siblingTBs =
thisTestingFolder.ChildFCOs.Cast<IMgaFCO>().Where(x => x.Meta.Name == "TestBench").ToList();
GMEConsole.Info.WriteLine(
"Applying these FidelitySettings to all TestBenches in folder '{0}':", thisTestingFolder.Name);
// Go through each one and set the fidelity settings
foreach (MgaFCO testbench in siblingTBs)
{
testbench.RegistryValue["FidelitySettings"] = fsf.FidelitySettings;
GMEConsole.Info.WriteLine("=> {0}", testbench.Name);
}
}
else if (fsf.rbThisProject.Checked)
{
// Get all testbenches in the entire project
MgaFilter testbenchFilter = project.CreateFilter();
testbenchFilter.Kind = "TestBench";
// get all testbenches
var testbenches = project.AllFCOs(testbenchFilter).OfType<IMgaModel>().Cast<IMgaModel>().ToList();
GMEConsole.Info.WriteLine(
"Applying these FidelitySettings to all TestBenches in project '{0}':", project.Name);
// Go through each one and set the fidelity settings
//.........这里部分代码省略.........
示例5: Main
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
{
// Get RootFolder
IMgaFolder rootFolder = project.RootFolder;
#region Prompt for Output Path
// Get an output path from the user.
String s_outPath;
using (META.FolderBrowserDialog fbd = new META.FolderBrowserDialog()
{
Description = "Choose a path for the generated files.",
//ShowNewFolderButton = true,
SelectedPath = Environment.CurrentDirectory,
})
{
DialogResult dr = fbd.ShowDialog();
if (dr == DialogResult.OK)
{
s_outPath = fbd.SelectedPath;
}
else
{
GMEConsole.Warning.WriteLine("Design Exporter cancelled");
return;
}
}
#endregion
GMEConsole.Info.WriteLine("Beginning Export...");
var testBanches = new List<CyPhy.TestBench>();
if (currentobj != null &&
currentobj.Meta.Name == "TestBench")
{
testBanches.Add(CyPhyClasses.TestBench.Cast(currentobj));
}
else if (selectedobjs.Count > 0)
{
foreach (MgaFCO mf in selectedobjs)
{
if (mf.Meta.Name == "TestBench")
{
testBanches.Add(CyPhyClasses.TestBench.Cast(mf));
}
}
}
else
{
CyPhy.RootFolder root = ISIS.GME.Common.Utils.CreateObject<CyPhyClasses.RootFolder>(project.RootFolder as MgaObject);
MgaFilter filter = project.CreateFilter();
filter.Kind = "TestBench";
foreach (var item in project.AllFCOs(filter).Cast<MgaFCO>())
{
if (item.ParentFolder != null)
{
testBanches.Add(CyPhyClasses.TestBench.Cast(item));
}
}
}
foreach (var tb in testBanches)
{
System.Windows.Forms.Application.DoEvents();
try
{
ExportToFile(tb, s_outPath);
}
catch (Exception ex)
{
GMEConsole.Error.WriteLine("{0}: Exception encountered ({1})", tb.Name, ex.Message);
}
GMEConsole.Info.WriteLine("{0}: {1}", tb.Name, s_outPath);
}
}
示例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> 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
//.........这里部分代码省略.........
示例7: CallCyber
private bool CallCyber(MgaProject mgaProject, MgaFCO mgaFCO, MgaFCOs mgaFCOs, int param)
{
var filter = mgaProject.CreateFilter();
filter.Kind = typeof(CyPhy.CyberModel).Name;
bool success = true;
var cyberModelFcos = (mgaFCO as MgaModel).GetDescendantFCOs(filter);
foreach (var cyberModelFco in cyberModelFcos)
{
success = success && this.CallCyberInterpreter(CyPhyClasses.CyberModel.Cast(cyberModelFco as MgaObject));
}
return success;
}
示例8: InvokeEx
public void InvokeEx(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, int param)
{
if (!enabled)
{
return;
}
try
{
GMEConsole = GMEConsole.CreateFromProject(project);
MgaGateway = new MgaGateway(project);
project.CreateTerritoryWithoutSink(out MgaGateway.territory);
this.InteractiveMode = this.Convert(param) != ComponentStartMode.GME_SILENT_MODE;
//bool runNewImplementationOnly = true;
//runNewImplementationOnly = false;
//if (runNewImplementationOnly)
//{
// this.NewMasterInterpreterImplementationFull(currentobj);
// return;
//}
List<IMgaFCO> objectsToCheck = new List<IMgaFCO>();
List<IMgaFCO> objectsToGetConfigurations = new List<IMgaFCO>();
MgaGateway.PerformInTransaction(() =>
{
if (currentobj == null)
{
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.AddRange(allObjects.Where(x => x.AbsPath.Contains("TestingContextChecker")));
objectsToGetConfigurations.AddRange(allObjects.Where(x => x.AbsPath.Contains("TestingGetConfigurations")));
}
else
{
objectsToCheck.Add(currentobj);
//objectsToGetConfigurations.Add(currentobj);
}
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);
});
});
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
sw.Start();
int numContexts = objectsToCheck.Count;
int numSuccess = 0;
int numFailures = 0;
StringBuilder sbAssumptions = new StringBuilder();
sbAssumptions.Append("Implemented".PadToCenter(11));
sbAssumptions.Append("Valid".PadToCenter(11));
sbAssumptions.Append("Context".PadToCenter(30));
sbAssumptions.Append("Assumption");
sbAssumptions.AppendLine();
foreach (var subject in objectsToCheck)
{
var masterInterpreter = new CyPhyMasterInterpreter.CyPhyMasterInterpreterAPI();
IEnumerable<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); });
// print out nicely in the GME console
MgaGateway.PerformInTransaction(() =>
{
MgaObject parent = null;
GME.MGA.Meta.objtype_enum type;
subject.GetParent(out parent, out type);
var successExpected = parent.Name.ToLowerInvariant() == "invalid" ? false : true;
//.........这里部分代码省略.........
示例9: Main
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
{
// TODO: show how to initialize DSML-generated classes
myMig = new myMigrator(project);
mig = new Migrator(project);
if (currentobj != null)
{
if (currentobj is MgaModel)
{
GMEConsole.Info.WriteLine(
"Migrating {0}... (To migrate the whole project, close all models and try again)",
currentobj.Name);
//myMig.migrateModel(currentobj as MgaModel);
mig.findOldPortTypes(project, false);
try
{
mig.migrateModel(currentobj as MgaModel);
}
catch (Exception ex)
{
GMEConsole.Error.WriteLine("{0}", ex.Message);
GMEConsole.Info.WriteLine("{0}", ex.StackTrace);
}
}
}
else
{
//mig.convertFluidParameters(project);
GMEConsole.Info.WriteLine("Migrating the entire project...");
myMig.migrateProject();
mig.findOldPortTypes(project, false);
mig.migrateCyPhy2ModelicaWorkflow(project);
List<string> kinds = new List<string>()
{
"TestBench",
"ComponentAssembly",
"DesignContainer",
"TestComponent",
"Component",
"Environment"
};
MgaFilter cyPhyModelFilter = project.CreateFilter();
cyPhyModelFilter.ObjType = objtype_enum.OBJTYPE_MODEL.ToString();
var objectsToMigrate = project
.AllFCOs(cyPhyModelFilter)
.OfType<MgaModel>()
.Where(x => x.ParentModel == null &&
kinds.Contains(x.Meta.Name));
foreach (var objectToMigrate in objectsToMigrate)
{
//GMEConsole.Info.WriteLine(
// "== Migrating <a href=\"mga:{0}\">{1}</a>",
// objectToMigrate.ID,
// objectToMigrate.Name);
try
{
mig.migrateModel(objectToMigrate);
}
catch (Exception ex)
{
GMEConsole.Error.WriteLine("{0}", ex.Message);
GMEConsole.Info.WriteLine("{0}", ex.StackTrace);
}
}
}
}
示例10: Main
public void Main(MgaProject project, MgaFCO currentobj, MgaFCOs selectedobjs, ComponentStartMode startMode)
{
Boolean disposeLogger = false;
if (Logger == null)
{
Logger = new CyPhyGUIs.GMELogger(project, "CyPhyDesignExporter");
disposeLogger = true;
}
// TODO: Add your interpreter code
Logger.WriteInfo("Running Design Exporter...");
#region Prompt for Output Path
// Get an output path from the user.
if (this.OutputDir == null)
{
using (META.FolderBrowserDialog fbd = new META.FolderBrowserDialog()
{
Description = "Choose a path for the generated files.",
//ShowNewFolderButton = true,
SelectedPath = Environment.CurrentDirectory,
})
{
DialogResult dr = fbd.ShowDialog();
if (dr == DialogResult.OK)
{
OutputDir = fbd.SelectedPath;
}
else
{
Logger.WriteWarning("Design Exporter cancelled");
return;
}
}
}
#endregion
Logger.WriteInfo("Beginning Export...");
List<CyPhy.DesignEntity> lde_allCAandDC = new List<CyPhy.DesignEntity>();
List<CyPhy.TestBenchType> ltbt_allTB = new List<CyPhy.TestBenchType>();
if (currentobj != null &&
currentobj.Meta.Name == "ComponentAssembly")
{
lde_allCAandDC.Add(CyPhyClasses.ComponentAssembly.Cast(currentobj));
}
else if (currentobj != null &&
currentobj.Meta.Name == "DesignContainer")
{
lde_allCAandDC.Add(CyPhyClasses.DesignContainer.Cast(currentobj));
}
else if (currentobj != null &&
IsTestBenchType(currentobj.MetaBase.Name))
{
ltbt_allTB.Add(CyPhyClasses.TestBenchType.Cast(currentobj));
}
else if (selectedobjs != null && selectedobjs.Count > 0)
{
foreach (MgaFCO mf in selectedobjs)
{
if (mf.Meta.Name == "ComponentAssembly")
{
lde_allCAandDC.Add(CyPhyClasses.ComponentAssembly.Cast(mf));
}
else if (mf.Meta.Name == "DesignContainer")
{
lde_allCAandDC.Add(CyPhyClasses.DesignContainer.Cast(mf));
}
else if (IsTestBenchType(mf.MetaBase.Name))
{
ltbt_allTB.Add(CyPhyClasses.TestBenchType.Cast(mf));
}
}
}
else
{
CyPhy.RootFolder rootFolder = ISIS.GME.Common.Utils.CreateObject<CyPhyClasses.RootFolder>(project.RootFolder as MgaObject);
MgaFilter filter = project.CreateFilter();
filter.Kind = "ComponentAssembly";
foreach (var item in project.AllFCOs(filter).Cast<MgaFCO>())
{
if (item.ParentFolder != null)
{
lde_allCAandDC.Add(CyPhyClasses.ComponentAssembly.Cast(item));
}
}
filter = project.CreateFilter();
filter.Kind = "DesignContainer";
foreach (var item in project.AllFCOs(filter).Cast<MgaFCO>())
{
if (item.ParentFolder != null)
{
lde_allCAandDC.Add(CyPhyClasses.DesignContainer.Cast(item));
}
}
filter = project.CreateFilter();
//.........这里部分代码省略.........
示例11: getObjectsByFilter
public void getObjectsByFilter(MgaProject project)
{
//MgaFilter componentFilter = project.CreateFilter();
//componentFilter.ObjType = "OBJTYPE_MODEL";
//componentFilter.Kind = "Component";
//componentArchetypes = project.AllFCOs(componentFilter).Cast<MgaFCO>().Where(x => x.ArcheType == null).ToList();
//foreach (var c in componentArchetypes)
//{
// string path = c.AbsPath;
// string[] splitPath = path.Split('/');
// string newPath = "";
// foreach (var s in splitPath)
// {
// newPath = newPath + s.Split('|').FirstOrDefault();
// }
// GMEConsole.Out.WriteLine("{0}", newPath);
//}
//MgaFilter assemblyFilter = project.CreateFilter();
//assemblyFilter.ObjType = "OBJTYPE_MODEL";
//assemblyFilter.Kind = "ComponentAssembly";
//componentAssemblies = project.AllFCOs(assemblyFilter).Cast<MgaFCO>().ToList();
//MgaFilter designContainerFilter = project.CreateFilter();
//designContainerFilter.ObjType = "OBJTYPE_MODEL";
//designContainerFilter.Kind = "DesignContainer";
//designContainers = project.AllFCOs(designContainerFilter).Cast<MgaFCO>().ToList();
//MgaFilter testCompFilter = project.CreateFilter();
//testCompFilter.ObjType = "OBJTYPE_MODEL";
//testCompFilter.Kind = "TestComponent";
//testComponents = project.AllFCOs(testCompFilter).Cast<MgaFCO>().Where(x => x.ArcheType == null).ToList();
//MgaFilter testbenchFilter = project.CreateFilter();
//testbenchFilter.ObjType = "OBJTYPE_MODEL";
//testbenchFilter.Kind = "TestBench";
//testbenches = project.AllFCOs(testbenchFilter).Cast<MgaFCO>().ToList();
MgaFilter portLibFilter = project.CreateFilter();
portLibFilter.ObjType = objtype_enum.OBJTYPE_MODEL.ToString();
portLibFilter.Kind = "ModelicaConnector";
var newPortTypes = project.AllFCOs(portLibFilter).Cast<MgaFCO>().Where(x => x.ParentFolder != null);
foreach (var pType in newPortTypes)
{
if (modelicaPortLib.ContainsKey(pType.Name))
{
continue;
}
modelicaPortLib.Add(pType.Name, pType);
}
d_OldKindToNewPortArchetype_jk = new Dictionary<string, MgaFCO>()
{
{ "MultibodyFramePowerPort" , modelicaPortLib["MultibodyFrame"] },
{ "MultibodyFrame" , modelicaPortLib["MultibodyFrame"] },
{ "ModelicaAggregateInterface" , modelicaPortLib["FlangeWithBearing"] },
{ "AggregatePort" , modelicaPortLib["FlangeWithBearing"] },
{ "HydraulicPowerPort" , modelicaPortLib["FluidPort"] },
{ "FluidPort" , modelicaPortLib["FluidPort"] },
{ "HeatPort" , modelicaPortLib["HeatPort"] },
{ "ThermalPowerPort" , modelicaPortLib["HeatPort"] },
{ "ElectricalPowerPort" , modelicaPortLib["ElectricalPin"] },
{ "ElectricalPin" , modelicaPortLib["ElectricalPin"] },
{ "InputSignalPort" , modelicaPortLib["RealInput"] },
{ "OutputSignalPort" , modelicaPortLib["RealOutput"] },
{ "RealInput" , modelicaPortLib["RealInput"] },
{ "RealOutput" , modelicaPortLib["RealOutput"] },
{ "BooleanInput" , modelicaPortLib["BooleanInput"] },
{ "BooleanOutput" , modelicaPortLib["BooleanOutput"] },
{ "IntegerInput" , modelicaPortLib["IntegerInput"] },
{ "IntegerOutput" , modelicaPortLib["IntegerOutput"] },
{ "TranslationalPowerPort" , modelicaPortLib["TranslationalFlange"] },
{ "TranslationalFlange" , modelicaPortLib["TranslationalFlange"] },
{ "RotationalPowerPort" , modelicaPortLib["RotationalFlange"] },
{ "RotationalFlange" , modelicaPortLib["RotationalFlange"] },
{ "Modelica.Blocks.Interfaces.BooleanInput" , modelicaPortLib["BooleanInput"] },
{ "Modelica.Blocks.Interfaces.BooleanOutput" , modelicaPortLib["BooleanOutput"] },
{ "Modelica.Blocks.Interfaces.IntegerInput" , modelicaPortLib["IntegerInput"] },
{ "Modelica.Blocks.Interfaces.IntegerOutput" , modelicaPortLib["IntegerOutput"] },
{ "C2M2L_Ext.Electrical.Interfaces.Battery_Bus" , modelicaPortLib["BatteryBus"] },
{ "C2M2L_Ext.Interfaces.Context_Interfaces.Driver.Driver_Bus" , modelicaPortLib["DriverBus"] },
{ "Modelica.Mechanics.MultiBody.Interfaces.FlangeWithBearing" , modelicaPortLib["FlangeWithBearing"] },
{ "C2M2L_Ext.Fluid.Hydraulics_Simple.Interfaces.Hydraulic_Port" , modelicaPortLib["HydraulicPower"] },
{ "C2M2L_Ext.C2M2L_Component_Building_Blocks.Drive_Line.Brakes_Clutch.Common_Controls.Brake_Control_Bus" , modelicaPortLib["BrakeControlBus"] },
{ "C2M2L_Ext.Electrical.Interfaces.Electric_Machine_Bus" , modelicaPortLib["ElectricMachineBus"] },
{ "C2M2L_Ext.C2M2L_Component_Building_Blocks.Prime_Movers.Common_Controls.Engine_Control_Bus" , modelicaPortLib["EngineControlBus"] },
{ "C2M2L_Ext.C2M2L_Component_Building_Blocks.Drive_Line.Range_Packs.Common_Controls.Range_Pack_Control_Bus" , modelicaPortLib["RangePackControlBus"] },
{ "C2M2L_Ext.C2M2L_Component_Building_Blocks.Drive_Line.Cross_Drive_Steering.Common_Controls.Steering_Control_Bus" , modelicaPortLib["SteeringControlBus"] },
{ "C2M2L_Ext.C2M2L_Component_Building_Blocks.Drive_Line.Torque_Converters.Common_Controls.Torque_Converter_Control_Bus" , modelicaPortLib["TorqueConverterControlBus"] },
{ "C2M2L_Ext.Interfaces.Context_Interfaces.Atmospheric_Environment.Atmospheric_Environment_Bus" , modelicaPortLib["AtmosphericEnvironmentBus"] },
};
}
示例12: migrateCyPhy2ModelicaWorkflow
internal void migrateCyPhy2ModelicaWorkflow(MgaProject project)
{
MgaFilter workflowFilter = project.CreateFilter();
workflowFilter.ObjType = objtype_enum.OBJTYPE_ATOM.ToString();
workflowFilter.Kind = "Task";
var workflowTasks = project.AllFCOs(workflowFilter).OfType<MgaAtom>();
foreach (var task in workflowTasks)
{
if (task.IsLibObject == false &&
task.StrAttrByName["COMName"] == "MGA.Interpreter.CyPhy2Modelica")
{
task.StrAttrByName["COMName"] = task.StrAttrByName["COMName"] + "_v2";
}
}
}
示例13: DeleteAllOldTypes
internal void DeleteAllOldTypes(MgaProject project)
{
foreach (var kvp in dfco_OldToNewMap)
{
try
{
if (kvp.Key == null)
{
if (kvp.Value != null)
{
GMEConsole.Warning.WriteLine(
"Migrated? <a href=\"mga:{0}\">{1}</a>",
kvp.Value.ID,
kvp.Value.Name);
}
continue;
}
if (kvp.Key.IsLibObject == false &&
kvp.Key.ParentModel != null &&
kvp.Key.ParentModel.DerivedFrom == null)
{
kvp.Key.DestroyObject();
}
else
{
GMEConsole.Info.WriteLine(
"Skipped <a href=\"mga:{0}\">{1}</a>",
kvp.Key.ID,
kvp.Key.Name);
}
}
catch (Exception ex)
{
GMEConsole.Error.WriteLine(
"Cannot delete object <a href=\"mga:{0}\">{1}</a>. Exception: {2} ({3})",
kvp.Key.ID,
kvp.Key.Name,
ex.Message,
ex.StackTrace);
}
}
foreach (var kvp in mapModel_migrated2original)
{
try
{
if (kvp.Value != null)
{
kvp.Value.DestroyObject();
}
}
catch (Exception ex)
{
GMEConsole.Error.WriteLine(
"Failed to Delete <a href=\"mga:{1}\">{2}</a>: {0}",
ex.Message,
kvp.Value.ID,
kvp.Value.Name);
}
}
MgaFilter materialSpecFilter = project.CreateFilter();
materialSpecFilter.Kind = "ModelicaMaterialSpec";
var materialSpecBlocks = project.AllFCOs(materialSpecFilter).Cast<MgaFCO>(); //.ToList()
foreach (MgaFCO msb in materialSpecBlocks)
{
try
{
msb.DestroyObject();
}
catch (Exception ex)
{
GMEConsole.Error.WriteLine(
"Failed to Delete <a href=\"mga:{1}\">{2}</a>: {0}",
ex.Message,
msb.ID,
msb.Name);
}
}
}
示例14: findOldPortTypes
internal void findOldPortTypes(MgaProject project, bool printHyperlinks)
{
List<string> oldPortKinds = new List<string>()
{
"MultibodyFramePowerPort",
"MultibodyFrame",
"ModelicaAggregateInterface",
"AggregatePort",
"HydraulicPowerPort",
"FluidPort",
"HeatPort",
"ThermalPowerPort",
"ElectricalPowerPort",
"ElectricalPin",
"InputSignalPort",
"OutputSignalPort",
"RealInput",
"RealOutput",
"BooleanInput",
"BooleanOutput",
"IntegerInput",
"IntegerOutput",
"TranslationalPowerPort",
"TranslationalFlange",
"RotationalPowerPort",
"RotationalFlange",
"ModelicaMaterialSpec",
};
MgaFilter filter = project.CreateFilter();
var oldPorts = project.AllFCOs(filter).Cast<MgaFCO>().Where(x => oldPortKinds.Contains(x.Meta.Name));
if (printHyperlinks)
{
foreach (var port in oldPorts)
{
GMEConsole.Info.WriteLine(
"Obsolete Port found: <a href=\"mga:{0}\">{1}</a>: {2}",
port.ID,
port.Name,
port.Meta.Name);
}
}
GMEConsole.Info.WriteLine("Number of Obsolete ports found in project: {0}", oldPorts.Count());
}
示例15: 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;
}
//.........这里部分代码省略.........