Beispiel #1
0
        public void Present(Proposal action)
        {
            var needsRefresh = false;

            if (action is SetFile)
            {
                _filename    = ((SetFile)action).FileName;
                _source      = ((SetFile)action).Source;
                needsRefresh = true;
                _lastError   = null;
            }
            else if (action is RefreshFromFile)
            {
                _source      = ((RefreshFromFile)action).Source;
                needsRefresh = true;
                _lastError   = null;
            }
            else if (action is SelectElement)
            {
                var elem = ((SelectElement)action).Element;
                _selected  = elem;
                _lastError = null;
            }
            else if (action is ShowError)
            {
                var act = ((ShowError)action);
                _lastError = new Exception(act.Context, act.Exception);
            }
            else
            {
                throw new Exception("Unsupported action type: " + action.GetType().Name);
            }

            if (needsRefresh)
            {
                try
                {
                    var render = new XamlRenderer(null);

                    byte[] byteArray = Encoding.UTF8.GetBytes(_source);
                    using (var stream = new System.IO.MemoryStream(byteArray))
                    {
                        var tree = render.Render(stream);

                        this._selected = tree;
                        this._tree     = tree;
                    }
                }
                catch (Exception e)
                {
                    // keep everything else intact
                    this._lastError = new Exception("Failed to refresh from file", e);
                }
            }
        }
Beispiel #2
0
 public void Store(Proposal toStore)
 {
     Console.WriteLine($"Writing proposal of type {toStore.GetType().Name}...");
 }