Пример #1
0
        /// <summary>
        /// Returns all available Linker channels
        /// </summary>
        /// <param name="callback"></param>
        /// <returns></returns>
        public JArray GetAllChannels(EventHandler <FinsembleEventArgs> callback)
        {
            var args = new FinsembleEventArgs(null, JObject.Parse(JsonConvert.SerializeObject(allChannels)));

            callback(this, args);
            return(this.allChannels);
        }
Пример #2
0
 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"]));
     });
 }
Пример #3
0
        private void handleListeners(object sender, FinsembleEventArgs args)
        {
            var topic = args.response["data"]?["type"].ToString();

            if (linkerSubscribers.ContainsKey(topic))
            {
                linkerSubscribers[topic]?.Invoke(this, new FinsembleEventArgs(null, new JObject
                {
                    ["data"]      = args.response["data"]?["data"],
                    ["header"]    = args.response["header"],
                    ["channelid"] = args.response["header"]["channel"],
                    ["origin"]    = args.response["header"]["origin"]
                }));
            }
        }
Пример #4
0
        // All messages from Finsemble are handled by this.
        private void MessageHandler(string topic, object message)
        {
            dynamic            m = JsonConvert.DeserializeObject(message.ToString());
            FinsembleEventArgs args;
            FinsembleQueryArgs qargs;
            var type = m.header.type.Value as string;

            switch (type)
            {
            case "transmit":
                args = new FinsembleEventArgs(null, message as JObject);
                if (transmitListeners.ContainsKey(m.header.channel.Value))
                {
                    transmitListeners[m.header.channel.Value]?.Invoke(this, args);
                }
                break;

            case "query":
                qargs = new FinsembleQueryArgs(null, message as JObject, (e) =>
                {
                    var queryMessage = new JObject
                    {
                        ["header"] = new JObject
                        {
                            ["origin"]  = clientName,
                            ["type"]    = "queryResponse",
                            ["queryID"] = m.header.queryID,
                            ["error"]   = m.error
                        },
                        ["data"] = e
                    };
                    bridge.Publish("RouterService", queryMessage);
                });
                if (responderMap.ContainsKey(m.header.channel.Value))
                {
                    responderMap[m.header.channel.Value]?.Invoke(this, qargs);
                }
                break;

            case "queryResponse":
                args = new FinsembleEventArgs(null, message as JObject);                         // TODO: Handle Errors
                if (queryIDResponseHandlerMap.ContainsKey(m.header.queryID.Value))
                {
                    queryIDResponseHandlerMap[m.header.queryID.Value]?.Invoke(this, args);
                    queryIDResponseHandlerMap.Remove(m.header.queryID.Value);
                }
                break;

            case "notify":
                args = new FinsembleEventArgs(null, message as JObject);
                if (publishListeners.ContainsKey(m.header.topic.Value))
                {
                    publishListeners[m.header.topic.Value]?.Invoke(this, args);
                }
                break;

            case "initialHandshakeResponse":
                if (connected)
                {
                    break;
                }
                Debug.WriteLine("Router Connected");
                connected = true;
                if (bridge.window != null)
                {
                    Application.Current.Dispatcher.Invoke(delegate                             //main thread
                    {
                        this.bridge.window.Loaded += (s, a) =>
                        {
                            Debug.WriteLine("Window loaded, sending registration message");
                            var handle = (new WindowInteropHelper(this.bridge.window).Handle).ToString("X");
                            this.Transmit("Finsemble.Assimilation.register", new JObject
                            {
                                ["windowName"]   = this.bridge.windowName,
                                ["windowHandle"] = handle
                            });
                        };
                    });
                }
                else
                {
                    this.Transmit("Finsemble.Assimilation.register", new JObject
                    {
                        ["windowName"]   = this.bridge.windowName,
                        ["windowHandle"] = null
                    });
                    // Quit WindowLess Application
                    this.AddListener("Finsemble.Assimilation.close." + this.bridge.windowName, (s, a) =>
                    {
                        Environment.Exit(0);
                    });
                }

                connectHandler(this, true);
                break;
            }
        }
Пример #5
0
 private void Got_Docking_Message_Over_Router(object sender, FinsembleEventArgs e)
 {
     Got_Docking_Message(null, e.response["data"] as JObject);
 }
        private void Linker_StateChange(object sender2, FinsembleEventArgs args)
        {
            /** DH 4/25/2019
             * The below block was throwing exceptions occasionally as the app was shutting down
             * we admittedly don't fully understand, so we're adding this null operator as a quick
             * fix.
             */
            Application.Current?.Dispatcher?.Invoke(delegate //main thread
            {
                try
                {
                    var channels    = args.response["channels"] as JArray;
                    var allChannels = args.response["allChannels"] as JArray;

                    // Hide all LinkerGroups
                    foreach (var item in LinkerGroups)
                    {
                        item.Value.Visibility = Visibility.Hidden;
                    }
                    if (LinkerButton.Visibility != Visibility.Visible)
                    {
                        return;
                    }

                    // Loop through Channels
                    Double baseLeft = buttonWidth + 4;
                    if (!showLinker)
                    {
                        baseLeft -= buttonWidth;
                    }
                    Double increment = 12;
                    foreach (JObject item in allChannels)
                    {
                        var groupName = (string)item["name"];
                        // check if in this group
                        if (channels.Where(jt => jt.Value <string>() == groupName).Count() > 0)
                        {
                            if (!LinkerGroups.ContainsKey(groupName))
                            {
                                var groupRectangle = new Button();
                                groupRectangle.HorizontalAlignment = HorizontalAlignment.Left;
                                groupRectangle.VerticalAlignment   = VerticalAlignment.Center;
                                groupRectangle.Width      = 7;
                                groupRectangle.Height     = 20;
                                groupRectangle.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString((string)item["color"]));
                                Toolbar.Children.Add(groupRectangle);
                                groupRectangle.SetValue(Canvas.TopProperty, (Toolbar.ActualHeight - groupRectangle.Height) / 2);
                                groupRectangle.Name = groupName;
                                var style           = this.Resources["LinkerPillStyle"];
                                groupRectangle.SetValue(StyleProperty, style);
                                LinkerGroups[groupName] = groupRectangle;
                                groupRectangle.Click   += LinkerPill_Click;
                            }
                            LinkerGroups[groupName].SetValue(Canvas.LeftProperty, baseLeft);
                            baseLeft += increment;
                            LinkerGroups[groupName].Visibility = Visibility.Visible;
                        }
                    }
                    Window_Size_Changed();
                }
                catch
                {
                }
            });
        }