本文整理匯總了C#中System.Machine.TryGetByName方法的典型用法代碼示例。如果您正苦於以下問題:C# Machine.TryGetByName方法的具體用法?C# Machine.TryGetByName怎麽用?C# Machine.TryGetByName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Machine
的用法示例。
在下文中一共展示了Machine.TryGetByName方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DevicesConfig
public DevicesConfig(string filename, Machine machine)
{
try
{
var devices = InitializeJSON(filename);
this.machine = machine;
//Every main node is one peripheral/device
foreach(var dev in devices)
{
InitializeDevice(dev);
}
while(deferred.Count > 0)
{
var lastCount = deferred.Count;
foreach(var deferredDevice in deferred.ToList())
{
if(InitializeDevice(deferredDevice.Key, deferredDevice.Value))
{
deferred.Remove(deferredDevice.Key);
}
}
if(lastCount == deferred.Count)
{
throw new ConstructionException("The provided configuration is not consistent. Some devices could not have been created due to wrong references.");
}
}
//Initialize connections
while(deviceList.Any(x => !x.IsRegistered))
{
var anyChange = false;
//setup connections
foreach(var periConn in deviceList.Where(x=> !x.IsRegistered && x.HasConnections))
{
var parents = new Dictionary<string, IPeripheral>();
foreach(var conn in periConn.Connections.Select(x=>x.Key))
{
var fromList = deviceList.SingleOrDefault(x => x.Name == conn);
if(fromList != null)
{
parents.Add(conn, fromList.Peripheral);
}
else
{
IPeripheral candidate;
if(!machine.TryGetByName(conn, out candidate))
{
FailDevice(periConn.Name, "connection to " + conn, null);
}
parents.Add(conn, candidate);
}
}
var canBeRegistered = parents.All(x => machine.IsRegistered(x.Value));
if(canBeRegistered)
{
RegisterInParents(periConn, parents);
periConn.IsRegistered = true;
anyChange = true;
}
}
if(!anyChange)
{
var invalidDevices = deviceList.Where(x => !x.IsRegistered).Select(x => x.Name).Aggregate((x, y) => x + ", " + y);
throw new RegistrationException("The " +
"provided configuration is not consistent. The following devices could not have been registered: "
+ invalidDevices
);
}
}
foreach(var device in deviceList.Where(x=>x.Irqs.Any()))
{
InitializeGPIOs(device);
}
foreach(var device in deviceList.Where(x=>x.IrqsFrom.Any()))
{
InitializeGPIOsFrom(device);
}
}
catch(RuntimeBinderException e)
{
throw new RecoverableException("The config file could not be analyzed. You should reset your current emulation.", e);
}
foreach(var group in groups)
{
machine.PeripheralsGroups.GetOrCreate(group.Key, group.Value.Select(x => x.Peripheral));
}
foreach(var device in deviceList)
{
machine.SetLocalName(device.Peripheral, device.Name);
}
}