Пример #1
0
        protected override void CreateRenderGraphs(RenderGraphCollection graphs, HashSet <string> reportingTags)
        {
            // define source
            object source;

            switch (Path.GetExtension(_options.FileName.ToLower()))
            {
            case ".png":
            case ".jpg":
                source = new ImageSourceBitmap(_options.FileName);
                break;

            case ".gif":
                source = new GifSource(_options.FileName);
                break;

            case ".bin":
                source = new RawSource(_options.FileName);
                break;

            default:
                throw new UnknownFormatException("Unknown format " + Path.GetExtension(_options.FileName.ToLower()) +
                                                 ". Known formats: png, jpg, gif, bin.");
            }

            // define renderers
            var renderers   = GetRenderers(_config, reportingTags);
            var frameSource = source as ISource;

            if (frameSource != null)
            {
                // chain them up
                graphs.Add(new RenderGraph {
                    Source           = frameSource,
                    Destinations     = renderers,
                    Resize           = _config.Global.Resize,
                    FlipHorizontally = _config.Global.FlipHorizontally,
                    FlipVertically   = _config.Global.FlipVertically
                });
                return;
            }

            // not an ISource, so it must be a IRawSource.
            var        rawSource = (IRawSource)source;
            IRawOutput rawOutput = null;

            foreach (var dest in renderers.OfType <IRawOutput>())
            {
                if (rawOutput != null)
                {
                    throw new MultipleRawSourcesException("Cannot use multiple destinations when using a raw source.");
                }
                rawOutput = dest;
            }
            if (rawOutput == null)
            {
                throw new NoRawDestinationException("No device supporting raw data available.");
            }
            graphs.Add(new RawRenderer(rawSource, rawOutput));
        }
Пример #2
0
        private string ExtractLuaSource(int linenumber)
        {
            var lines = RawSource.Split('\n').ToList();
            var lua   = $"## {lines[linenumber - 2]}\n## --->{lines[linenumber - 1]}\n";

            if (linenumber < lines.Count)
            {
                lua = $"{lua}## {lines[linenumber]}";
            }
            return(lua);
        }
Пример #3
0
        private string HumanizeException(Exception ex)
        {
            var lines   = RawSource.Split('\n').ToList();
            var summary = string.Empty;

            if (ex is InterpreterException ie)
            {
                // Get information from decorated message. CallStack is only available for
                // certain lua exceptions; decorated message / innerexception always has what
                // is needed.
                var e = ParseException(ie.DecoratedMessage);
                if (!string.IsNullOrEmpty(e.Filename))
                {
                    summary = $"Line {e.LineNumber}: {e.Error}\n{ExtractLuaSource(e.LineNumber)}";
                }
                else
                {
                    summary = $"Could not be parsed, raw message follows {ie.DecoratedMessage}";
                }
                if (ie is SyntaxErrorException)
                {
                    return($"\nSyntax error: {summary}");
                }
                if (ie is ScriptRuntimeException)
                {
                    return($"\nScripting runtime error: {summary}");
                }
                if (ie is DynamicExpressionException)
                {
                    return($"\nLua type error: {summary}");
                }
                else
                {
                    return($"\nInternal error from Lua code: STACK: {summary}\nERR: {ie.DecoratedMessage}");
                }
            }
            else
            {
                var retstr = string.Empty;
                retstr = $"\nC# exception, perhaps caused by Lua script code: STACK: {ex.StackTrace}\n ERR:{ex.Message}";
                if (ex.InnerException != null)
                {
                    retstr = $"{retstr}\nINNER STACK TRACE: {ex.InnerException.StackTrace}\n INNER ERR: {ex.InnerException.Message}";
                }
                return(retstr);
            }
        }
Пример #4
0
 public override int GetHashCode()
 {
     return(RawSource != null ? RawSource.GetHashCode() : 0);
 }