当前位置: 首页>>代码示例>>C#>>正文


C# Machine.SetLocalName方法代码示例

本文整理汇总了C#中System.Machine.SetLocalName方法的典型用法代码示例。如果您正苦于以下问题:C# Machine.SetLocalName方法的具体用法?C# Machine.SetLocalName怎么用?C# Machine.SetLocalName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Machine的用法示例。


在下文中一共展示了Machine.SetLocalName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ShouldRecordAndPlayEvents

        public void ShouldRecordAndPlayEvents()
        {
            var random = new Random();

            var machineThreadFunctionFactory = new Func<BaseClockSource, ThreadStart>(cSource => new ThreadStart(() =>
            {
                for(var i = 0; i < 100; i++)
                {
                    Thread.Sleep(10);
                    cSource.Advance(10);
                }
            }));

            var machineFactory = new Func<BaseClockSource, Machine>(cSource =>
            {
                var sDomain = new SynchronizationDomain();
                var result = new Machine();
                result.SetClockSource(cSource);
                result.SyncUnit = 10;
                result.SyncDomain = sDomain;
                var peripheral = new PeripheralMock(result, sDomain);
                result.SystemBus.Register(peripheral, 0.To(1));
                result.SetLocalName(peripheral, "mock");
                return result;
            });
                
            var clockSource = clockSources[0];
            var machine = machineFactory(clockSource);
            var peripheralMock = (PeripheralMock)machine["sysbus.mock"];
            machine.RecordTo(temporaryFile.Value);

            var machineThread = new Thread(machineThreadFunctionFactory(clockSource));
            machineThread.Start();

            var eventNo = 0;
            while(!machineThread.Join(0))
            {
                peripheralMock.Method(eventNo++);
                peripheralMock.MethodTwoArgs(eventNo++, 0);
                Thread.Sleep(random.Next(30));
            }

            machine.Dispose();

            var recordedEvents = peripheralMock.Events;

            clockSource = clockSources[1];
            machine = machineFactory(clockSource);
            peripheralMock = (PeripheralMock)machine["sysbus.mock"];
            machine.PlayFrom(temporaryFile.Value);

            machineThread = new Thread(machineThreadFunctionFactory(clockSource));
            machineThread.Start();
            machineThread.Join();

            var playedEvents = peripheralMock.Events;
            CollectionAssert.AreEqual(recordedEvents, playedEvents);
        }
开发者ID:rte-se,项目名称:emul8,代码行数:58,代码来源:SyncDomainsTest.cs

示例2: 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);
            }
        }
开发者ID:rte-se,项目名称:emul8,代码行数:98,代码来源:DevicesConfig.cs

示例3: ShouldRememberCpuNames

		public void ShouldRememberCpuNames()
		{
			var names = new [] { "Xavier", "Alice", "Bob" };
			var machine = new Machine();
			foreach(var name in names)
			{
				var cpu =  new MockCPU(machine) { Placeholder = name };
				machine.SystemBus.Register(cpu,  new CPURegistrationPoint());
				machine.SetLocalName(cpu, name);
			}
			machine = Serializer.DeepClone(machine);
			var cpus = machine.SystemBus.GetCPUs();
            CollectionAssert.AreEquivalent(names, cpus.Select(x => machine.GetLocalName(x)));
			foreach(var cpu in cpus.Cast<MockCPU>())
			{
                Assert.AreEqual(cpu.Placeholder, machine.GetLocalName(cpu));
			}		
		}
开发者ID:rte-se,项目名称:emul8,代码行数:18,代码来源:SerializationTests.cs


注:本文中的System.Machine.SetLocalName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。