public MachineCreateForm() { InitializeComponent(); foreach (var devType in DeviceTypeRegistry.GetRegisteredDeviceTypes(out string[] types)) { var attr = devType.GetCustomAttribute <DeviceComponentAttribute>(); var icon = DeviceTypeRegistry.GetDeviceTypeIcon(devType.Name.ToLower()); icons.Images.Add(devType.Name.ToLower(), icon); } machineComp = Machine.CreateDevice <MachineComponent>(); eeprom = Machine.CreateDevice <EEPROM>(); scr = Machine.CreateDevice <Screen>(); gpu = Machine.CreateDevice <GPU>(); devices.Items.Add(new ListViewItem() { Text = machineComp.GetComponentAttribute().UserFriendlyName, Tag = machineComp, ImageKey = machineComp.GetType().Name.ToLower() }); devices.Items.Add(new ListViewItem() { Text = eeprom.GetComponentAttribute().UserFriendlyName, Tag = eeprom, ImageKey = eeprom.GetType().Name.ToLower() }); devices.Items.Add(new ListViewItem() { Text = scr.GetComponentAttribute().UserFriendlyName, Tag = scr, ImageKey = scr.GetType().Name.ToLower() }); devices.Items.Add(new ListViewItem() { Text = gpu.GetComponentAttribute().UserFriendlyName, Tag = gpu, ImageKey = gpu.GetType().Name.ToLower() }); }
public void RefreshParts(MachineComponent component) { EntityManager.EventBus.RaiseLocalEvent(component.Owner, new RefreshPartsEvent() { Parts = GetAllParts(component), }, true); }
public void AddComponent(MachineComponent component) { lock (Components) { Components.Add(component); } }
public void SetComponentProperties(int MachineComponentId) { try { using (DataContext = new DataContext(StatisModels.ProjectProps.FakeServer)) { var component = DataContext.MachineComponent .Include("ComponentImages") .Include("ComponentStocks") .Where(i => i.Id == MachineComponentId) .First(); DS_Component.DataSource = CurrentComponent = component; if (component.ComponentStocks.Count > 0) { DS_ComponentStock.DataSource = CurrentStock = component.ComponentStocks[0]; } if (component.ComponentImages.Count > 0) { DS_ComponentImage.DataSource = CurrentImage = component.ComponentImages[0]; ComponentPicture.Image = component.ComponentImages[0].Image; } } } catch (Exception ex) { MessageBox.Show("Error while getting data from database"); } }
public override void RunComponent() { lock (Components) { Components.Sort(); foreach (var component in Components) { if (!component.Enabled) continue; if (component.CheckComponent()) { if (_lastRan == null) { _lastRan = component; // Run the enter command or otherwise it won't // trigger on the first run component. component.EnterComponent(); } if (_lastRan != component) { _lastRan.ExitComponent(); _lastRan = component; component.EnterComponent(); } component.RunComponent(); } } } }
void OnTriggerEnter(Collider other) { if (other.transform.parent) { var machine = other.transform.parent.GetComponent <MachineComponent>(); if (machine) { touchingMachine = machine; } } }
void OnTriggerExit(Collider other) { if (other.transform.parent) { var machine = other.transform.parent.GetComponent <MachineComponent>(); if (machine && touchingMachine == machine) { touchingMachine = null; } } }
public static void Main() { MachineComponent dublin = ExampleMachine.Dublin(); OozinozFilter w = new CommaListFilter(new WrapFilter(new ConsoleWriter(), 60)); Set leaves = new RakeVisitor().GetLeaves(dublin); foreach (MachineComponent mc in leaves) { w.Write(mc.ID.ToString()); } w.Close(); }
/// <summary> /// Clears LVM state to prepare for other LVM before run /// </summary> public void ClearState() { if (IsRunning) { throw new MachineClearStateException("Tried to clear state of running machine which could cause big problems in future"); } Processor.Halt(); signals.Clear(); DeviceBus.DisconnectAll(false); machineComponent = null; RunningInstance = null; }
public void AddNewComponent() { try { using (DataContext = new DataContext(StatisModels.ProjectProps.FakeServer)) { var sameComponents = DataContext.MachineComponent .Where(i => i.ComponentCode == CurrentComponent.ComponentCode || i.ComponentName == CurrentComponent.ComponentName); if (sameComponents.Count() > 0) { MessageBox.Show("Component already existed in database"); return; } if (CurrentImage.ImageString == null || CurrentImage.ImageString == string.Empty) { MessageBox.Show("Please insert component image"); return; } MachineComponent MachineComponent = new MachineComponent(CurrentComponent); MachineComponent.ComponentImages = new List <ComponentImage>( new ComponentImage[] { new ComponentImage { ImageString = CurrentImage.ImageString, ImageName = CurrentImage.ImageName } }); MachineComponent.ComponentStocks = new List <ComponentStock>( new ComponentStock[] { new ComponentStock { Quantity = CurrentStock.Quantity, AddUserId = CurrentStock.AddUserId } }); DataContext.MachineComponent.Add(MachineComponent); DataContext.SaveChanges(); } MessageBox.Show("Add new component successfully"); } catch (Exception ex) { MessageBox.Show("Can not add new component"); } }
/// <summary> /// Creates new LVM instance with specified machine address and display /// </summary> /// <param name="machineAddress">Machine address</param> /// <param name="displayInterface">Display interface</param> public Machine(Guid machineAddress, string machineRootDir, MachineComponent machineComp) { IsRunning = false; MachineRootDirectory = machineRootDir; machineComponent = machineComp; DeviceBus = new DeviceBus(); machineComponent.Address = machineAddress; Processor = new LuaProcessor(); Processor.ProcessorHalted += Processor_ProcessorHalted; RunningInstance = this; }
public List <MachinePartComponent> GetAllParts(MachineComponent component) { var parts = new List <MachinePartComponent>(); foreach (var entity in component.PartContainer.ContainedEntities) { if (TryComp <MachinePartComponent?>(entity, out var machinePart)) { parts.Add(machinePart); } } return(parts); }
/// <summary> /// Add a tree node for this component. /// </summary> /// <param name="m">the component to add</param> /// <returns>the new tree node</returns> protected TreeNode AddNode(MachineComponent m) { TreeNode newNode = new TreeNode(m.ToString()); if (_current == null) { _tree = newNode; } else { _current.Nodes.Add(newNode); } return(newNode); }
public void SetComponentProperties(MachineComponent component) { CurrentComponent = component; if (CurrentComponent.ComponentStocks.Count > 0) { CurrentStock = CurrentComponent.ComponentStocks[0]; } DS_Component.DataSource = CurrentComponent; DS_ComponentStock.DataSource = CurrentStock; if (component.ComponentImages.Count > 0) { CurrentImage = component.ComponentImages[0]; ComponentPicture.Image = component.ComponentImages[0].Image; } }
public void Toggle(Entity entity) { ServerComponent server = entity.Get <ServerComponent>(); MachineComponent machine = entity.Get <MachineComponent>(); server.Enabled = !server.Enabled; if (server.Enabled) { machine.Start(); } else { machine.Stop(); } }
public void Toggle(Entity entity) { ClientComponent client = entity.Get <ClientComponent>(); MachineComponent machine = entity.Get <MachineComponent>(); client.Enabled = !client.Enabled; if (client.Enabled) { machine.Start(); } else { machine.Stop(); } }
private void Execute(MachineComponent mc) { Machine m = mc as Machine; if (m != null) { _variable.Assign(new Constant(m)); _body.Execute(); return; } MachineComposite comp = mc as MachineComposite; foreach (MachineComponent child in comp.Children) { Execute(child); } }
private void ClientEditCommand_Executed(object sender, ExecutedRoutedEventArgs e) { DemonSaw.Entity.Entity entity = ClientController.SelectedItem; ClientEditWindow wnd = new ClientEditWindow(entity) { Owner = this }; bool result = (bool)wnd.ShowDialog(); if (result) { // Client ClientComponent client = entity.Get <ClientComponent>(); client.Name = wnd.ClientName.Text; client.Download = wnd.DownloadPath.Text; // Group GroupComponent group = entity.Get <GroupComponent>(); bool groupChanged = (entity == MenuController.Entity) && !group.Path.Equals(wnd.GroupPath.Text); group.Path = wnd.GroupPath.Text; GroupImage.Source = group.Image; // Options ClientOptionsComponent options = entity.Get <ClientOptionsComponent>(); options.MaxDownloads = int.Parse(wnd.MaxDownloads.Text); options.MaxUploads = int.Parse(wnd.MaxUploads.Text); // Machine MachineComponent machine = entity.Get <MachineComponent>(); machine.Restart(); // Controller MenuController.Update(); if (groupChanged) { SearchController.Clear(); BrowseController.Clear(); } } }
private void ClientListView_GroupImageButton_Click(object sender, RoutedEventArgs e) { DemonSaw.Entity.Entity entity = ClientController.SelectedItem; if (entity == null) { return; } // Group GroupComponent group = entity.Get <GroupComponent>(); OpenFileDialog dlg = new OpenFileDialog() { Title = "Browse For Group Image", FileName = group.Path, Filter = "BMP Files (*.bmp)|*.bmp|JPEG Files (*.jpeg)|*.jpeg|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif|ICO Files (*.ico)|*.ico|PNG Files (*.png)|*.png|All files (*.*)|*.*", FilterIndex = 7 }; if (dlg.ShowDialog() == true) { // Group bool groupChanged = (entity == MenuController.Entity) && !group.Path.Equals(dlg.FileName); group.Path = dlg.FileName; GroupImage.Source = group.Image; // Machine MachineComponent machine = entity.Get <MachineComponent>(); machine.Restart(); // Controllers if (groupChanged) { SearchController.Clear(); BrowseController.Clear(); } } }
private void RouterEditCommand_Executed(object sender, ExecutedRoutedEventArgs e) { DemonSaw.Entity.Entity entity = ClientController.SelectedItem; RouterEditWindow wnd = new RouterEditWindow(entity) { Owner = this }; bool result = (bool)wnd.ShowDialog(); if (result) { if (!NetworkUtil.IsPortValid(wnd.Port.Text)) { return; } // Router ServerComponent server = entity.Get <ServerComponent>(); bool nameChanged = !server.Name.Equals(wnd.RouterName.Text); server.Name = wnd.RouterName.Text; server.Address = wnd.Address.Text; server.Port = int.Parse(wnd.Port.Text); server.Passphrase = wnd.Passphrase.Text; // Machine MachineComponent machine = entity.Get <MachineComponent>(); machine.Restart(); // Controller MenuController.Update(); if (nameChanged) { BrowseController.Select(); } } }
private void Run(bool timedOut) { var acquiredLock = false; try { // Thread exit if another thread is handling this event. if (Monitor.IsEntered(Components)) return; // Acquire access to this resource. Monitor.TryEnter(Components, ref acquiredLock); // If we've failed to acquire the lock exit. if (!acquiredLock) return; // Sort the List, States may have updated Priorities. Components.Sort(); // Find a State that says it needs to run. foreach (var mc in Components) { // Stop operations on being signaled to stop. if (!timedOut) { // Make the last state clean up and exit (stops running if travelling) if (_lastRan != null) _lastRan.ExitComponent(); return; } if (mc.Enabled == false) { continue; } // Skip disabled States. if (mc.CheckComponent()) { // Says it needs to run. Same State as before? if (_lastRan == null) { _lastRan = mc; } if (_lastRan != mc) { // Make the previous State clean up and exit. _lastRan.ExitComponent(); _lastRan = mc; mc.EnterComponent(); } // Run this State and stop. mc.RunComponent(); } } } finally { if (acquiredLock) { // Release our resources. Monitor.Exit(Components); } } }
/// <summary> /// Construct a "for" interpreter that will execute the /// provided body, looping through the machines in a context, /// assigning the provided variable to each machine. /// </summary> /// <param name="root">The machine component over which to iterate</param> /// <param name="v">the variable to set for each loop</param> /// <param name="body">the body of the for command</param> public ForCommand(MachineComponent mc, Variable v, Command body) { _root = mc; _variable = v; _body = body; }
public Set GetLeaves(MachineComponent mc) { _leaves = new Set(); mc.Accept(this); return(_leaves); }
public void CreateBoardAndStockParts(MachineComponent component) { // Entity might not be initialized yet. var boardContainer = _container.EnsureContainer <Container>(component.Owner, MachineFrameComponent.BoardContainer); var partContainer = _container.EnsureContainer <Container>(component.Owner, MachineFrameComponent.PartContainer); if (string.IsNullOrEmpty(component.BoardPrototype)) { return; } // We're done here, let's suppose all containers are correct just so we don't screw SaveLoadSave. if (boardContainer.ContainedEntities.Count > 0) { return; } var board = EntityManager.SpawnEntity(component.BoardPrototype, Transform(component.Owner).Coordinates); if (!component.BoardContainer.Insert(board)) { throw new Exception($"Couldn't insert board with prototype {component.BoardPrototype} to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}!"); } if (!TryComp <MachineBoardComponent?>(board, out var machineBoard)) { throw new Exception($"Entity with prototype {component.BoardPrototype} doesn't have a {nameof(MachineBoardComponent)}!"); } foreach (var(part, amount) in machineBoard.Requirements) { for (var i = 0; i < amount; i++) { var p = EntityManager.SpawnEntity(MachinePartComponent.Prototypes[part], Transform(component.Owner).Coordinates); if (!partContainer.Insert(p)) { throw new Exception($"Couldn't insert machine part of type {part} to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}!"); } } } foreach (var(stackType, amount) in machineBoard.MaterialRequirements) { var stack = _stackSystem.Spawn(amount, stackType, Transform(component.Owner).Coordinates); if (!partContainer.Insert(stack)) { throw new Exception($"Couldn't insert machine material of type {stackType} to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}"); } } foreach (var(compName, info) in machineBoard.ComponentRequirements) { for (var i = 0; i < info.Amount; i++) { var c = EntityManager.SpawnEntity(info.DefaultPrototype, Transform(component.Owner).Coordinates); if (!partContainer.Insert(c)) { throw new Exception($"Couldn't insert machine component part with default prototype '{compName}' to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}"); } } } foreach (var(tagName, info) in machineBoard.TagRequirements) { for (var i = 0; i < info.Amount; i++) { var c = EntityManager.SpawnEntity(info.DefaultPrototype, Transform(component.Owner).Coordinates); if (!partContainer.Insert(c)) { throw new Exception($"Couldn't insert machine component part with default prototype '{tagName}' to machine with prototype {MetaData(component.Owner).EntityPrototype?.ID ?? "N/A"}"); } } } }
private void OnMachineMapInit(EntityUid uid, MachineComponent component, MapInitEvent args) { CreateBoardAndStockParts(component); RefreshParts(component); }
void Start() { machine = transform.parent.GetComponent <MachineComponent>(); }
public void Stop(Entity entity) { MachineComponent machine = entity.Get <MachineComponent>(); machine.Stop(); }
private void OnMachineInit(EntityUid uid, MachineComponent component, ComponentInit args) { component.BoardContainer = _container.EnsureContainer <Container>(uid, MachineFrameComponent.BoardContainer); component.PartContainer = _container.EnsureContainer <Container>(uid, MachineFrameComponent.PartContainer); }
public void Restart(Entity entity) { MachineComponent machine = entity.Get <MachineComponent>(); machine.Restart(); }
public static void Main() { MachineComponent c = ExampleMachine.Plant(); Console.WriteLine(c.GetMachineCount()); }
// GET: api/Dashboard public List <Machine> GetMachines() { MachineComponent machineComp = new MachineComponent(); return(machineComp.GetMachines()); }
// Start is called before the first frame update void Start() { machine = transform.parent.transform.parent.GetComponent <MachineComponent>(); //a = Resources.Load<Sprite>("ScrewDriverIcon"); }
void Start() { bar = GetComponent <Image>(); machine = transform.parent.transform.parent.GetComponent <MachineComponent>(); }