Esempio n. 1
0
        void ParseSVG()
        {
            Task.Run(() => {
                string svg = null;
                CoreGraphics.CGRect previewSize = CoreGraphics.CGRect.Empty;
                string error = null;

                this.InvokeOnMainThread(() => {
                    Prev.Drawables = null;
                    previewSize    = Prev.Bounds;
                    svg            = Code;
                });

                DateTime startParse = DateTime.Now;
                try {
                    var reader = new SvgReader(new System.IO.StringReader(svg));
                    if (reader.Graphic != null)
                    {
                        if (reader.Graphic.Size.Height == 0 || reader.Graphic.Size.Width == 0)
                        {
                            reader.Graphic.Size = new Size(previewSize.Width, previewSize.Height);
                        }
                        Prev.Drawables = new IDrawable[] { reader.Graphic };
                    }
                } catch (Exception ex) {
                    error = ex.Message;
                }
                this.BeginInvokeOnMainThread(() => {
                    if (!string.IsNullOrEmpty(error))
                    {
                        Errors.TextColor = NSColor.Red;
                        Errors.Value     = error;
                    }
                    else
                    {
                        Errors.TextColor = NSColor.Black;
                        Errors.Value     = "Content parsed in " + (DateTime.Now - startParse).TotalMilliseconds.ToString() + "ms";
                    }

                    Prev.SetNeedsDisplayInRect(previewSize);
                });
            });
        }
Esempio n. 2
0
        void AcceptCompileResult(CompileResult result)
        {
            this.BeginInvokeOnMainThread(() => {
                try {
                    if (result.Code == Code)
                    {
                        Console.WriteLine("NEW RESULT {0}", this.result);
                        this.result = result;

                        Errors.Value     = result.Errors ?? "";
                        Errors.TextColor = NSColor.Red;

                        if (string.IsNullOrEmpty(result.Errors))
                        {
                            Prev.Drawables = result.Drawables;
                            Prev.SetNeedsDisplayInRect(Prev.Bounds);
                        }
                    }
                } catch (Exception ex) {
                    Console.WriteLine(ex);
                }
            });
        }