Exemple #1
0
        private async Task CodeExecuted()
        {
            // Start the next code if that hasn't happened yet
            StartNextCode();

            if (Result != null)
            {
                // Process the code result
                switch (Type)
                {
                case CodeType.GCode:
                    await GCodes.CodeExecuted(this);

                    break;

                case CodeType.MCode:
                    await MCodes.CodeExecuted(this);

                    break;

                case CodeType.TCode:
                    await TCodes.CodeExecuted(this);

                    break;
                }

                // RepRapFirmware generally prefixes error messages with the code itself.
                // Do this only for error messages that originate either from a print or from a macro file
                if (Flags.HasFlag(CodeFlags.IsFromMacro) || Channel == CodeChannel.File)
                {
                    foreach (Message msg in Result)
                    {
                        if (msg.Type == MessageType.Error)
                        {
                            msg.Content = ToShortString() + ": " + msg.Content;
                        }
                    }
                }

                // Log warning and error replies after the code has been processed internally
                if (InternallyProcessed)
                {
                    foreach (Message msg in Result)
                    {
                        if (msg.Type != MessageType.Success && Channel != CodeChannel.File)
                        {
                            await Utility.Logger.Log(msg);
                        }
                    }
                }
            }

            // Done
            await Interception.Intercept(this, InterceptionMode.Executed);
        }
        private async Task <CodeResult> OnCodeExecuted(CodeResult result)
        {
            // Process code result
            switch (Type)
            {
            case CodeType.GCode:
                result = await GCodes.CodeExecuted(this, result);

                break;

            case CodeType.MCode:
                result = await MCodes.CodeExecuted(this, result);

                break;

            case CodeType.TCode:
                result = await TCodes.CodeExecuted(this, result);

                break;
            }

            // RepRapFirmware generally prefixes error messages with the code itself.
            // Do this only for error messages that come either from a print or from a macro
            if (result != null && (Flags.HasFlag(CodeFlags.IsFromMacro) || Channel == CodeChannel.File))
            {
                foreach (Message msg in result)
                {
                    if (msg.Type == MessageType.Error)
                    {
                        msg.Content = ToShortString() + ": " + msg.Content;
                    }
                }
            }

            // Log warning+error replies if the code could be processed internally
            if (InternallyExecuted && !result.IsEmpty)
            {
                foreach (Message msg in result)
                {
                    if (msg.Type != MessageType.Success || Channel == CodeChannel.File)
                    {
                        await Utility.Logger.Log(msg);
                    }
                }
            }

            // Finished. Optionally an "Executed" interceptor could be called here, but that would only make sense if the code reply was included
            return(result);
        }