Beispiel #1
0
        private void LoadCommands()
        {
            foreach (var type in Assembly.GetCallingAssembly().GetTypes().Where(t => t.IsSubclassOf(typeof(CommandBase))))
            {
                SystemCommands.Add(type.FullName, type);
            }

            var dlls = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location)).ToList().FindAll(s => Path.GetExtension(s) == ".dll");

            dlls.RemoveAll(s => Path.GetFileName(s) == "BlendoBot.dll" || Path.GetFileName(s) == "BlendoBotLib.dll");

            foreach (string dll in dlls)
            {
                var assembly = Assembly.LoadFrom(dll);
                var types    = assembly.ExportedTypes.ToList().FindAll(t => t.IsSubclassOf(typeof(CommandBase)));
                foreach (var type in types)
                {
                    LoadedCommands.Add(type.FullName, type);
                    Log(this, new LogEventArgs {
                        Type    = LogType.Log,
                        Message = $"Detected command {type.FullName}"
                    });
                }
            }
        }
Beispiel #2
0
        public void Send(string command, string onResult = null)
        {
            lock (_lockObject)
            {
                _uiContext.Send(
                    x =>
                {
                    CommunicationLog.Insert(0, "grbl <=" + command);
                    if (CommunicationLog.Count > 500)
                    {
                        CommunicationLog.Remove(CommunicationLog.Last());
                    }
                }, null);
            }

            OnCommunicationLogUpdated();

            var cmd = new Command {
                Data = command, CommandOnResult = onResult
            };

            _commandPreProcessor.Process(ref cmd);

            switch (cmd.Type)
            {
            case RequestType.Realtime:
                Send(cmd);
                break;

            case RequestType.System:
            {
                lock (_lockObject)
                {
                    if (!SystemCommands.DataInQueue(cmd.Data, 3))
                    {
                        SystemCommands.Add(command);
                    }
                }

                break;
            }

            default:
            {
                lock (_lockObject)
                {
                    ManualCommands.Add(command);
                }

                break;
            }
            }
        }
Beispiel #3
0
        /// <summary>
        /// Indexes the <see cref="ModelInputs"/> and <see cref="SystemEvents"/>,
        /// plus <see cref="ModelOutputs"/> and <see cref="SystemCommands"/>,
        /// whenever a <see cref="TransitionSystem"/> is added or removed.
        /// </summary>
        private void IndexSystems()
        {
            ModelInputs.Clear();
            ModelOutputs.Clear();
            SystemCommands.Clear();
            SystemEvents.Clear();

            foreach (TransitionSystem system in Systems)
            {
                foreach (Transition transition in system.Transitions)
                {
                    if (transition is ReactiveTransition reactive)
                    {
                        if (typeof(ModelAction).IsAssignableFrom(reactive.Action))
                        {
                            ModelInputs.Add(reactive.Action);
                        }
                        else if (typeof(ISystemAction).IsAssignableFrom(reactive.Action))
                        {
                            SystemEvents.Add(reactive.Action);
                        }
                    }
                    else if (transition is ProactiveTransition proactive)
                    {
                        if (typeof(ModelAction).IsAssignableFrom(proactive.Action))
                        {
                            ModelOutputs.Add(proactive.Action);
                        }
                        else if (typeof(ISystemAction).IsAssignableFrom(proactive.Action))
                        {
                            SystemCommands.Add(proactive.Action);
                        }
                    }
                }
            }
        }