private void SubscribeToGroupUpdates(object sender, FinsembleEventArgs e) { routerClient.Subscribe("Finsemble.LauncherService.updateGroups." + bridge.windowName, (s, fe) => { windowClient.SetComponentState(new JObject { ["field"] = "finsemble:windowGroups", ["value"] = fe.response["data"] }, (s2, e2) => { }); windowGroupUpdateHandler?.Invoke(sender, new FinsembleEventArgs(e.error, e.response?["data"])); }); }
/// <summary> /// Add a listener that fires when a specific value in a store is changed. /// </summary> /// <example> /// <code> /// store.AddListener(new JObject {["field"] = "field1"}, myHandler); /// store.AddListener(new JObject {["field"] = "field1"}, (sender, args) => { /// var valueOfField = args.response?["data"]?["value"] /// }); /// </code> /// </example> /// <param name="parameters"></param> /// <param name="callback"></param> public void AddListener(JObject parameters, EventHandler <FinsembleEventArgs> callback) { string field; if (parameters != null) { field = name + "." + (string)parameters["field"]; //TODO: add ability to add global listener } else { field = name; } routerClient.Subscribe("storeService" + field, callback); }
private void RPC(string endpoint, List <JToken> args, EventHandler <FinsembleEventArgs> cb) { switch (endpoint) { case "RouterClient.transmit": RouterClient.Transmit((string)args[0], args[1]); break; case "RouterClient.addListener": RouterClient.AddListener((string)args[0], cb); break; case "RouterClient.removeListener": RouterClient.RemoveListener((string)args[0], cb); break; case "RouterClient.publish": RouterClient.Publish((string)args[0], args[1]); break; case "RouterClient.subscribe": RouterClient.Subscribe((string)args[0], cb); break; case "RouterClient.unsubscribe": RouterClient.Unsubscribe((string)args[0], cb); break; case "RouterClient.query": RouterClient.Query((string)args[0], args[1], args[2] as JObject, cb); break; case "LinkerClient.publish": LinkerClient.Publish(args[0] as JObject); break; case "LinkerClient.subscribe": LinkerClient.Subscribe((string)args[0], cb); break; case "LauncherClient.spawn": LauncherClient.Spawn((string)args[0], args[1] as JObject, cb); break; case "LauncherClient.showWindow": LauncherClient.ShowWindow(args[0] as JObject, args[1] as JObject, cb); break; case "ConfigClient.getValue": ConfigClient.GetValue(args[0] as JObject, cb); break; case "AuthenticationClient.publishAuthorization": authenticationClient.PublishAuthorization <JObject>((string)args[0], args[1] as JObject); break; case "AuthenticationClient.getCurrentCredentials": authenticationClient.GetCurrentCredentials <JObject>((s, a) => { cb(this, new FinsembleEventArgs(null, a)); }); break; case "Logger.error": JToken[] argsArray = args.ToArray(); logger.Error(argsArray); break; case "Logger.warn": logger.Warn(args.ToArray()); break; case "Logger.log": logger.Log(args.ToArray()); break; case "Logger.info": logger.Info(args.ToArray()); break; case "Logger.debug": logger.Debug(args.ToArray()); break; case "Logger.verbose": logger.Verbose(args.ToArray()); break; default: throw new Exception("This API does not exist or is not yet supported"); } }
private void Window_Loaded(object sender, RoutedEventArgs e) { Application.Current.Dispatcher.Invoke(delegate //main thread { //WindowInteropHelper helper = new WindowInteropHelper(dockingWindow); //HwndSource.FromHwnd(helper.Handle).AddHook(HwndMessageHook); PresentationSource source = PresentationSource.FromVisual(dockingWindow); if (source != null) { dpiX = 96.0 * source.CompositionTarget.TransformToDevice.M11; dpiY = 96.0 * source.CompositionTarget.TransformToDevice.M22; } WindowLocation = new Point(dockingWindow.Left, dockingWindow.Top); WindowBottomRight = new Point(dockingWindow.Left + dockingWindow.Width, dockingWindow.Top + dockingWindow.Height); IntPtr windowHandle = new WindowInteropHelper(dockingWindow).Handle; var props = new JObject { ["windowName"] = dockingWindowName, ["top"] = dockingWindow.Top, ["left"] = dockingWindow.Left, ["width"] = dockingWindow.Width, ["height"] = dockingWindow.Height, ["windowHandle"] = windowHandle.ToString(), ["windowAction"] = "open" }; //bridge.SendRPCCommand("NativeWindow", props.ToString(), dockingChannel); }); routerClient.Subscribe("Finsemble.WorkspaceService.groupUpdate", delegate(object s, FinsembleEventArgs args) { var groupData = args.response?["data"]?["groupData"] as JObject; if (groupData == null) { return; } dynamic thisWindowGroups = new ExpandoObject(); thisWindowGroups.dockingGroup = ""; thisWindowGroups.snappingGroup = ""; thisWindowGroups.topRight = false; foreach (var item in groupData) { var windowsInGroup = item.Value["windowNames"] as JArray; if (windowsInGroup.Where(window => (string)window == bridge.windowName).Count() > 0) { if ((bool)item.Value["isMovable"]) { thisWindowGroups.dockingGroup = item.Key; if ((string)item.Value["topRightWindow"] == bridge.windowName) { thisWindowGroups.topRight = true; } } else { thisWindowGroups.snappingGroup = item.Key; } } } DockingGroupUpdateHandler?.Invoke(this, thisWindowGroups); }); }