Exemplo n.º 1
0
        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);
 }
Exemplo n.º 3
0
 public void AddComponent(MachineComponent component)
 {
     lock (Components)
     {
         Components.Add(component);
     }
 }
Exemplo n.º 4
0
        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");
            }
        }
Exemplo n.º 5
0
        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();
                    }
                }
            }
        }
Exemplo n.º 6
0
 void OnTriggerEnter(Collider other)
 {
     if (other.transform.parent)
     {
         var machine = other.transform.parent.GetComponent <MachineComponent>();
         if (machine)
         {
             touchingMachine = machine;
         }
     }
 }
Exemplo n.º 7
0
 void OnTriggerExit(Collider other)
 {
     if (other.transform.parent)
     {
         var machine = other.transform.parent.GetComponent <MachineComponent>();
         if (machine && touchingMachine == machine)
         {
             touchingMachine = null;
         }
     }
 }
Exemplo n.º 8
0
    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();
    }
Exemplo n.º 9
0
        /// <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;
        }
Exemplo n.º 10
0
        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");
            }
        }
Exemplo n.º 11
0
        /// <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);
    }
Exemplo n.º 13
0
    /// <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);
    }
Exemplo n.º 14
0
 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;
     }
 }
Exemplo n.º 15
0
        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();
            }
        }
Exemplo n.º 16
0
        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();
            }
        }
Exemplo n.º 17
0
        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);
            }
        }
Exemplo n.º 18
0
        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();
                }
            }
        }
Exemplo n.º 19
0
        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();
                }
            }
        }
Exemplo n.º 20
0
        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();
                }
            }
        }
Exemplo n.º 21
0
        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);
                }
            }
        }
Exemplo n.º 22
0
 /// <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;
 }
Exemplo n.º 23
0
 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);
 }
Exemplo n.º 26
0
 void Start()
 {
     machine = transform.parent.GetComponent <MachineComponent>();
 }
Exemplo n.º 27
0
        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);
 }
Exemplo n.º 29
0
        public void Restart(Entity entity)
        {
            MachineComponent machine = entity.Get <MachineComponent>();

            machine.Restart();
        }
Exemplo n.º 30
0
    public static void Main()
    {
        MachineComponent c = ExampleMachine.Plant();

        Console.WriteLine(c.GetMachineCount());
    }
Exemplo n.º 31
0
        // GET: api/Dashboard
        public List <Machine> GetMachines()
        {
            MachineComponent machineComp = new MachineComponent();

            return(machineComp.GetMachines());
        }
Exemplo n.º 32
0
    // Start is called before the first frame update
    void Start()
    {
        machine = transform.parent.transform.parent.GetComponent <MachineComponent>();

        //a = Resources.Load<Sprite>("ScrewDriverIcon");
    }
Exemplo n.º 33
0
 void Start()
 {
     bar     = GetComponent <Image>();
     machine = transform.parent.transform.parent.GetComponent <MachineComponent>();
 }