Example #1
0
        private async Task <CodeResult> ExecuteInternally()
        {
            CodeResult result = null;

            // Preprocess this code
            if (!Flags.HasFlag(CodeFlags.IsPreProcessed))
            {
                result = await Interception.Intercept(this, InterceptionMode.Pre);

                Flags |= CodeFlags.IsPreProcessed;

                if (result != null)
                {
                    InternallyExecuted = true;
                    return(await OnCodeExecuted(result));
                }
            }

            // Attempt to process the code internally
            switch (Type)
            {
            case CodeType.GCode:
                result = await GCodes.Process(this);

                break;

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

                break;

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

                break;
            }

            if (result != null)
            {
                InternallyExecuted = true;
                return(await OnCodeExecuted(result));
            }

            // If the could not be interpreted, post-process it
            if (!Flags.HasFlag(CodeFlags.IsPostProcessed))
            {
                result = await Interception.Intercept(this, InterceptionMode.Post);

                Flags |= CodeFlags.IsPostProcessed;

                if (result != null)
                {
                    InternallyExecuted = true;
                    return(await OnCodeExecuted(result));
                }
            }

            // Code has not been interpreted yet
            return(null);
        }
Example #2
0
        private async Task <bool> ProcessInternally()
        {
            // Pre-process this code
            if (!Flags.HasFlag(CodeFlags.IsPreProcessed))
            {
                bool intercepted = await Interception.Intercept(this, InterceptionMode.Pre);

                Flags |= CodeFlags.IsPreProcessed;

                if (intercepted)
                {
                    InternallyProcessed = true;
                    return(true);
                }
            }

            // Attempt to process the code internally
            switch (Type)
            {
            case CodeType.GCode:
                Result = await GCodes.Process(this);

                break;

            case CodeType.MCode:
                Result = await MCodes.Process(this);

                break;

            case CodeType.TCode:
                Result = await TCodes.Process(this);

                break;
            }

            if (Result != null)
            {
                InternallyProcessed = true;
                return(true);
            }

            // If the code could not be interpreted internally, post-process it
            if (!Flags.HasFlag(CodeFlags.IsPostProcessed))
            {
                bool intercepted = await Interception.Intercept(this, InterceptionMode.Post);

                Flags |= CodeFlags.IsPostProcessed;

                if (intercepted)
                {
                    InternallyProcessed = true;
                    return(true);
                }
            }

            // Code has not been interpreted yet - let RRF deal with it
            return(false);
        }
Example #3
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);
        }