public void SendSupportedTypes(XenType[] types) { var r = XenMessage.Create <SupportedTypesRequest>(); r.Types = types; _socket.Send(r); }
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); } }
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}"); } }
protected override void OnExecute(XenMessage message) { var response = message as GetWidgetEventsResponse; if (response == null) { Log.Warn($"{nameof(GetWidgetEventsResponse)} was not correctly parsed."); return; } var root = VisualTree.Root; if (root == null) { Log.Warn("Cannot attach events when a visual tree does not exist."); return; } var match = root.Find(response.WidgetId); match.Events = response.Events; Bus.Notify(new ShowWidgetEvents(match)); Log.Trace($"Properties set for {match.Events}."); }
public void GetAttachedProperties(string widgetId) { var r = XenMessage.Create <GetAttachedPropertiesRequest>(); r.WidgetId = widgetId; _socket.Send(r); }
public void Read_action_property_and_create_the_corresponding_object_from_json() { // Json.Net requires you know the .NET object type when attempting to deserialize the json // This method inspects the XenMessage's action property, and creates an object of that type. var json = @"{ 'stringProperty': 'Michael Davis', 'intProperty': 31, 'time': '2015-05-03T00:00:00', 'action': 'SomeXenMessage', 'messageId': '123' }"; var finder = new XenMessageFinder(); // Act XenMessage msg; var created = XenMessage.TryParseFromAction(finder, json, out msg); Assert.IsTrue(created, "The json did not parse."); Assert.IsInstanceOf <SomeXenMessage>(msg, "The resultant XenMessage was not the right type."); var castedMsg = msg as SomeXenMessage; if (castedMsg == null) { Assert.Fail("Stopping test execution for failed conversion."); } Assert.IsTrue ( castedMsg.IntProperty == 31 && castedMsg.StringProperty == "Michael Davis", "Property inspection failed." ); }
protected override void OnExecute(XenMessageContext ctx) { var r = XenMessage.Create <GetVisualTreeResponse>(); r.Root = Surface.Root; ctx.Response = r; }
protected override void OnExecute(XenMessage message) { if (message.Is <ObjectResponse>()) { HandleObject(message as ObjectResponse); } }
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; }
protected override void OnExecute(XenMessage message) { var res = message as GetWidgetPropertiesResponse; if (res == null) { Log.Warn($"{nameof(GetWidgetPropertiesResponse)} was not correctly parsed."); return; } var root = VisualTree.Root; if (root == null) { Log.Warn("Cannot attach properties to a widget when the visual tree does not exist."); return; } var match = root.Find(res.Widget.Id); match.Properties = res.Properties; Log.Trace($"Properties set for {match.Name}."); Bus.Notify(new ShowWidgetPropertyEditors(match)); Bus.Notify(new ReplacedWidgetCollection(match)); Log.Trace($"{nameof(ShowWidgetPropertyEditors)} published."); Log.Trace($"{nameof(ReplacedWidgetCollection)} published."); }
public void GetWidgetEvents(string widgetId) { var r = XenMessage.Create <GetWidgetEventsRequest>(); r.WidgetId = widgetId; _socket.Send(r); }
protected override void OnAppearing() { base.OnAppearing(); var msg = XenMessage.Create <DesignerReady>(); _server.Send(msg.ToJson()); }
public void CreateWidget(string parentId, string typeName) { var r = XenMessage.Create <CreateWidgetRequest>(); r.ParentId = parentId; r.TypeName = typeName; _socket.Send(r); }
public void GetObjectProperties(string widgetId, params string[] path) { var r = XenMessage.Create <GetObjectRequest>(); r.WidgetId = widgetId; r.Path = path; _socket.Send(r); }
/// <summary> /// Send a <see cref="XenMessage"/> to the design server. /// The message is serialized to JSON before sending. /// </summary> /// <param name="message"></param> public virtual void Send(XenMessage message) { if (string.IsNullOrWhiteSpace(message.MessageId)) { message.MessageId = Guid.NewGuid().ToString(); } SendImplementation(message.ToJson()); }
public void GetWidgetProperties(string widgetId) { var r = XenMessage.Create <GetWidgetPropertiesRequest>(); r.WidgetId = widgetId; r.IncludeValues = true; _socket.Send(r); }
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); }
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); }
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); }
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); }
protected override void OnExecute(XenMessage message) { var res = message as XamlResponse; if (res == null) { return; } Bus.Notify(new XamlElementDefaultsReceived(res.XamlDefaults)); }
protected override void OnExecute(XenMessage message) { var res = message as DesignerReady; if (res == null) { return; } Bus.Notify(new DesignerReadyEvent()); }
/// <summary> /// Return the corresponding XenMessage. /// </summary> /// <param name="message"></param> /// <returns></returns> private XenMessage Parse(string message) { XenMessage request = null; if (!string.IsNullOrWhiteSpace(message)) { XenMessage.TryParseFromAction(_messageFinder, message, out request); } return(request); }
protected override void OnExecute(XenMessage message) { var res = message as OpenXamlResponse; if (res == null) { return; } Bus.Notify(new OpenXamlResponseReceived(res.XamlDefaults, res.FileName)); }
public void GetConstructors(string typeName) { if (string.IsNullOrWhiteSpace(typeName)) { return; } var r = XenMessage.Create <GetConstructorsRequest>(); r.TypeName = typeName; _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); }
public void AddSupportedType(string typeName) { var r = XenMessage.Create <AddSupportedTypeRequest>(); r.Type = new XenType { FullName = typeName, Descriptor = XenPropertyDescriptors.ValueType }; _socket.Send(r); }
protected override void OnExecute(XenMessage message) { var response = message as GetConstructorsResponse; if (response == null) { return; } var args = new ConstructorsReceived(response.Type); Bus.Notify(args); }
private void OnNextSuggestedMessage(XenMessage msg) { if (msg.Is <GetVisualTreeRequest>()) { Designer.GetVisualTree(); } if (msg.Is <GetWidgetPropertiesRequest>()) { var r = msg as GetWidgetPropertiesRequest; GetWidgetProperties(r?.WidgetId); } }
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); }