示例#1
0
        private void ExecuteNextMessage(XenMessage response)
        {
            if (string.IsNullOrWhiteSpace(response?.NextSuggestedMessage))
            {
                return;
            }

            var nextType = MessageFinder.Find(response.NextSuggestedMessage);

            if (nextType == null)
            {
                return;
            }

            var nextMessage = XenMessage.Create(nextType);

            if (nextMessage != null)
            {
                // copy over the widget id.
                var wResponse    = response as IWidgetMessage;
                var wNextRequest = nextMessage as IWidgetMessage;

                if (wResponse != null && wNextRequest != null)
                {
                    wNextRequest.WidgetId = wResponse.WidgetId;
                }

                _callback?.Invoke(nextMessage);
            }
        }
示例#2
0
        public void GetWidgetEvents(string widgetId)
        {
            var r = XenMessage.Create <GetWidgetEventsRequest>();

            r.WidgetId = widgetId;
            _socket.Send(r);
        }
示例#3
0
        public void GetAttachedProperties(string widgetId)
        {
            var r = XenMessage.Create <GetAttachedPropertiesRequest>();

            r.WidgetId = widgetId;
            _socket.Send(r);
        }
示例#4
0
        protected override void OnExecute(XenMessageContext ctx)
        {
            var req = ctx.Get <AddSupportedTypeRequest>();

            if (req == null)
            {
                return;
            }

            var res = XenMessage.Create <AddSupportedTypeResponse>();

            try
            {
                if (TypeRegistrar.Instance.IsRegistered(req.Type))
                {
                    res.AlreadyRegistered = true;
                    res.DisplayMessage    = $"The type '{req.Type.FullName} is already registered.";
                }
                else
                {
                    if (!string.IsNullOrWhiteSpace(req.Type?.FullName))
                    {
                        var match = TypeFinder.Find(req.Type.FullName);

                        if (match == null)
                        {
                            res.DisplayMessage = $"The type '{req.Type.FullName}' was not found.";
                        }
                        else
                        {
                            if (match.GetTypeInfo().IsValueType)
                            {
                                res.Added = TypeRegistrar.Instance.AddType(req.Type);
                                res.Suggest <GetVisualTreeRequest>();

                                if (res.Added)
                                {
                                    res.DisplayMessage = $"The type '{req.Type.FullName}' can now be used.";
                                }
                            }
                            else
                            {
                                res.DisplayMessage = "You can only add value types in the beta.";
                            }
                        }
                    }
                    else
                    {
                        res.DisplayMessage = "You must enter a type name.";
                    }
                }
            }
            catch (Exception ex)
            {
                res.UnhandledExceptionOccurred = true;
                res.ExceptionMessage           = ex.ToString();
            }

            ctx.Response = res;
        }
示例#5
0
        protected override void OnExecuted(EventArgs e)
        {
            base.OnExecuted(e);

            if (!Node.Widget.CanDelete)
            {
                MessageBox.Show(Application.Instance.MainForm,
                                "This view cannot be removed.", "XenForms",
                                MessageBoxButtons.OK, MessageBoxType.Question);

                return;
            }

            var count   = Node.Widget.Children?.Count;
            var warning = $"Are you sure you want to remove this {Node.DisplayName}?";

            if (count != null && count > 0)
            {
                warning += $"\nIt has {count} " + (count == 1 ? "child." : "children.");
            }

            var response = MessageBox.Show(Application.Instance.MainForm,
                                           warning, "XenForms",
                                           MessageBoxButtons.YesNo,
                                           MessageBoxType.Question);

            if (response == DialogResult.Yes)
            {
                var msg = XenMessage.Create <DeleteWidgetRequest>();
                msg.WidgetId = Node.Widget.Id;
                Socket.Send(msg);

                Log.Info($"Removing widget: {Node.DisplayName}");
            }
        }
示例#6
0
        protected override void OnExecute(XenMessageContext ctx)
        {
            var r = XenMessage.Create <GetVisualTreeResponse>();

            r.Root       = Surface.Root;
            ctx.Response = r;
        }
示例#7
0
        public void SendSupportedTypes(XenType[] types)
        {
            var r = XenMessage.Create <SupportedTypesRequest>();

            r.Types = types;
            _socket.Send(r);
        }
示例#8
0
        public void CreateWidget(string parentId, string typeName)
        {
            var r = XenMessage.Create <CreateWidgetRequest>();

            r.ParentId = parentId;
            r.TypeName = typeName;
            _socket.Send(r);
        }
示例#9
0
        protected override void OnAppearing()
        {
            base.OnAppearing();

            var msg = XenMessage.Create <DesignerReady>();

            _server.Send(msg.ToJson());
        }
示例#10
0
        public void GetObjectProperties(string widgetId, params string[] path)
        {
            var r = XenMessage.Create <GetObjectRequest>();

            r.WidgetId = widgetId;
            r.Path     = path;

            _socket.Send(r);
        }
示例#11
0
        public void GetWidgetProperties(string widgetId)
        {
            var r = XenMessage.Create <GetWidgetPropertiesRequest>();

            r.WidgetId      = widgetId;
            r.IncludeValues = true;

            _socket.Send(r);
        }
示例#12
0
        public void EditCollection(string widgetId, EditCollectionType type, params string[] path)
        {
            var r = XenMessage.Create <EditCollectionRequest>();

            r.WidgetId = widgetId;
            r.Type     = type;
            r.Path     = path;

            _socket.Send(r);
        }
示例#13
0
        public static T SetRequest <T>(this XenMessageContext ctx, Action <T> action = null) where T : Request, new()
        {
            var request = XenMessage.Create <T>();

            ctx.Request = request;

            action?.Invoke(request);

            return((T)ctx.Request);
        }
示例#14
0
        public void Builder_should_populate_properties()
        {
            // Act
            var msg = XenMessage.Create <SomeXenMessage>();

            Assert.IsNotNull(msg);
            Assert.IsTrue(msg.MessageId.Length > 0);
            Assert.AreEqual(msg.Action, nameof(SomeXenMessage));
            Assert.IsTrue(msg.Time.Year == DateTime.Now.Year);
        }
示例#15
0
        public static T SetResponse <T>(this XenMessageContext ctx, Action <T> action = null) where T : Response, new()
        {
            var response = XenMessage.Create <T>();

            ctx.Response = response;

            action?.Invoke(response);

            return((T)ctx.Response);
        }
示例#16
0
        public void GetConstructors(string typeName)
        {
            if (string.IsNullOrWhiteSpace(typeName))
            {
                return;
            }
            var r = XenMessage.Create <GetConstructorsRequest>();

            r.TypeName = typeName;
            _socket.Send(r);
        }
示例#17
0
        public void AddSupportedType(string typeName)
        {
            var r = XenMessage.Create <AddSupportedTypeRequest>();

            r.Type = new XenType
            {
                FullName   = typeName,
                Descriptor = XenPropertyDescriptors.ValueType
            };

            _socket.Send(r);
        }
        public void Queing_one_message_without_handler_registered()
        {
            var msg = XenMessage.Create <FakeQueueRequest>();

            var json     = msg.ToJson();
            var workflow = new DefaultDesignWorkflow(_finder, null);

            workflow.Start();
            workflow.Queue(json);
            SpinWait.SpinUntil(() => workflow.QueuedMessages > 1, TimeSpan.FromSeconds(3));
            Assert.AreEqual(1, workflow.QueuedMessages);
        }
示例#19
0
        public void Test_execute_called_and_no_action_found()
        {
            // Note how FakeCompletedRequest and FakeSimpleRequest are different types
            Reaction.Register <FakeSimpleRequest, FakeAttachReaction>();
            var request = XenMessage.Create <FakeCompletedRequest>();
            var ctx     = new XenMessageContext {
                Request = request
            };

            var handled = Reaction.Execute(ctx);

            Assert.IsFalse(handled);
        }
示例#20
0
        public void OpenXaml(string xaml, string selectedFile)
        {
            if (string.IsNullOrWhiteSpace(xaml))
            {
                return;
            }
            var r = XenMessage.Create <OpenXamlRequest>();

            r.Xaml     = xaml;
            r.FileName = selectedFile;

            _socket.Send(r);
        }
示例#21
0
        public void Execution_of_Register_with_lambda_passed_and_success()
        {
            var request = XenMessage.Create <FakeSimpleRequest>();
            var ctx     = new XenMessageContext {
                Request = request
            };

            Reaction.Register <FakeSimpleRequest, FakeTrackRequestReaction>(() => new FakeTrackRequestReaction("Hello!"));
            var handled = Reaction.Execute(ctx);

            Assert.IsTrue(handled, "The OnExecute method should have returned true.");
            Assert.AreEqual(ctx.Message, "Hello!", "Data did not flow through the context.");
        }
示例#22
0
        public void SetProperty(XenWidget widget, XenProperty property, object value, bool isBase64 = false, bool isAp = false, object metadata = null)
        {
            var r = XenMessage.Create <SetPropertyRequest>();

            r.Metadata           = metadata;
            r.Path               = property.Path;
            r.Value              = value;
            r.WidgetId           = widget.Id;
            r.IsBase64           = isBase64;
            r.IsAttachedProperty = isAp;

            _socket.Send(r);
        }
示例#23
0
        public void CallConstructor(string widgetId, XenProperty property, XenConstructor ctor)
        {
            if (ctor == null)
            {
                return;
            }
            var r = XenMessage.Create <CallConstructorRequest>();

            r.Constructor = ctor;
            r.Property    = property;
            r.WidgetId    = widgetId;

            _socket.Send(r);
        }
示例#24
0
        public void Send_method()
        {
            var socket = new FakeToolboxSocket();

            // Act
            socket.Send("Testing...");

            Assert.AreEqual("Testing...", socket.Incoming, "The string overload failed.");

            var msg = XenMessage.Create <FakeSimpleMessage>();

            // Act
            socket.Send(msg);

            StringAssert.Contains(nameof(FakeSimpleMessage), socket.Incoming, "XenMessage overload failed.");
        }
        public void Queing_message_with_handler_registered()
        {
            var msg      = XenMessage.Create <FakeQueueRequest>();
            var json     = msg.ToJson();
            var workflow = new DefaultDesignWorkflow(_finder, _server.Object);

            var reaction = new FakeQueueReaction();

            Reaction.Register <FakeQueueRequest, FakeQueueReaction>(() => reaction);
            workflow.Start();
            workflow.Queue(json);

            SpinWait.SpinUntil(() => reaction.Context != null, TimeSpan.FromSeconds(3));
            Assert.IsNotNull(reaction.Context);

            _server.Verify(r => r.Send(It.IsAny <string>()), Times.AtMostOnce);
        }
        public void OkResponse_set_when_reaction_didnt_set_a_response()
        {
            var msg      = XenMessage.Create <FakeQueueRequest>();
            var json     = msg.ToJson();
            var workflow = new DefaultDesignWorkflow(_finder, _server.Object);

            var reaction = new FakeNoResponseReaction();

            Reaction.Register <FakeQueueRequest, FakeNoResponseReaction>(() => reaction);

            workflow.Start();
            workflow.Queue(json);

            SpinWait.SpinUntil(() => reaction.Completed, TimeSpan.FromSeconds(3));
            Assert.IsTrue(reaction.Completed);
            Assert.IsInstanceOf(typeof(OkResponse), reaction.Context.Response);
        }
示例#27
0
        public void Execution_of_Register_called_without_passing_lambda_when_needed()
        {
            var request = XenMessage.Create <FakeSimpleRequest>();
            var ctx     = new XenMessageContext {
                Request = request
            };

            Reaction.Register <FakeSimpleRequest, FakeTrackRequestReaction>();

            /*
             *  The FakeTrackRequestDesignerAction class does not have a parameterless constructor.
             *  It should either:
             *      1) Have a parameterless ctor created
             *      2) Have invoked the DesignerAction.Register overload to create an object
             */

            // Acting & Assert
            Assert.Throws <InvalidOperationException>(() => Reaction.Execute(ctx));
        }
示例#28
0
        public bool UploadAssemblies()
        {
            if (IncludedAssemblies == null)
            {
                return(false);
            }

            foreach (var assembly in IncludedAssemblies.Where(a => !a.Sent))
            {
                var data = File.ReadAllBytes(assembly.FullPath);
                var b64  = Convert.ToBase64String(data);

                var req = XenMessage.Create <LoadProjectRequest>();
                req.AssemblyData = b64;

                ToolboxApp.SocketManager.Socket.Send(req);
                assembly.Sent = true;
            }

            return(true);
        }
示例#29
0
        private void OnFileWriteTimeCheck(object state)
        {
            lock (_lock)
            {
                try
                {
                    if (!File.Exists(_watchingFile))
                    {
                        return;
                    }

                    if (SelectedFile == null)
                    {
                        return;
                    }

                    var now = File.GetLastWriteTime(SelectedFile);
                    if (now == _lastWriteTime)
                    {
                        return;
                    }
                    _lastWriteTime = now;

                    Messaging.Notify(new ShowStatusMessage($"Reloading {SelectedFile}"));

                    var msg = XenMessage.Create <OpenXamlRequest>();
                    msg.Xaml = File.ReadAllText(_watchingFile);
                    Socket.Send(msg);
                }
                catch (Exception)
                {
                    lock (_lock)
                    {
                        _timer.Dispose();
                    }
                }
            }
        }
示例#30
0
        public void NewPage()
        {
            var r = XenMessage.Create <NewPageRequest>();

            _socket.Send(r);
        }