예제 #1
0
        internal LauncherClient(Finsemble bridge)
        {
            this.bridge  = bridge;
            routerClient = bridge.RouterClient;
            windowClient = bridge.WindowClient;
            // Window Groups
            windowClient.GetComponentState(new JObject
            {
                ["field"] = "finsemble:windowGroups"
            }, (err, groups) => {
                if (groups.response != null)
                {
                    AddToGroups(new JObject
                    {
                        ["groupNames"] = groups.response
                    }, SubscribeToGroupUpdates);
                }
            });

            // Heartbeat
            timer.Interval = 1000;
            timer.Elapsed += (sender, e) => {
                routerClient.Transmit("Finsemble.heartbeat", new JObject
                {
                    ["type"]          = "component",
                    ["componentType"] = "finsemble",
                    ["windowName"]    = bridge.windowName
                });
            };
            timer.Enabled = true;
        }
예제 #2
0
        private void Connect(object sender, bool connected)
        {
            // Do not attempt to connect more than once. This causes the Window to close prematurely from responders firing because of errors.
            if (isFinsembleConnected)
            {
                return;
            }
            isFinsembleConnected = true;

            logger               = new Logger(this);
            storageClient        = new StorageClient(this);
            authenticationClient = new AuthenticationClient(this);
            ConfigClient         = new ConfigClient(this);
            ShareClient          = new Share(this);
            ConfigClient.GetValue(new JObject
            {
                ["field"] = "finsemble.components." + this.componentType
            }, (s, a) =>
            {
                if (!(a.response["data"] is JObject))
                {
                    // Data isn't a JObject
                    //logger.Warn(string.Format(
                    //"Response data object does not have the correct type. Type: \"{0}\", Value: \"{1}\"",
                    ////a.response["data"].GetType().ToString(),
                    //a.response["data"].ToString()));
                }

                this.componentConfig = a.response["data"] as JObject;
                if (this.componentConfig == null)
                {
                    this.componentConfig = new JObject();
                }
                WindowClient           = new WindowClient(this);
                LauncherClient         = new LauncherClient(this);
                distributedStoreClient = new DistributedStoreClient(this);
                if (window != null)
                {
                    DragAndDropClient = new DragAndDropClient(this);
                }
                if (window != null)
                {
                    docking = new Docking(this, windowName + "-channel");
                }

                LinkerClient = new LinkerClient(this, (s2, a2) =>
                {
                    Connected?.Invoke(this, EventArgs.Empty);
                });

                // Notify listeners that connection is complete.
                // ToDo, wait for clients to be ready??
            });
        }
예제 #3
0
        //private bool _useExplicitChannels = false;
        internal LinkerClient(Finsemble bridge, EventHandler <bool> readyCallback)
        {
            this.bridge    = bridge;
            windowClient   = bridge.WindowClient;
            routerClient   = bridge.RouterClient;
            launcherClient = bridge.LauncherClient;
            key            = (bridge.windowName + "::" + bridge.uuid).Replace('.', '_');

            var storehandler = (EventHandler <StoreModel>) delegate(object sender, StoreModel store)
            {
                linkerStore = store;
                linkerStore.GetValue(new JObject {
                    ["field"] = "channels"
                }, delegate(object sender2, FinsembleEventArgs args)
                {
                    allChannels = args.response?["data"] as JArray;

                    var linkerStateHandler = (EventHandler <FinsembleEventArgs>) delegate(object sender3, FinsembleEventArgs args3)
                    {
                        //MessageBox.Show(args3?.response.ToString());
                        if (args3.response != null && args3.response.HasValues)
                        {
                            channels = args3.response as JArray;
                        }
                        else
                        {
                            channels = new JArray {
                            };
                        }

                        //MessageBox.Show(bridge.window, channels.ToString(), "", MessageBoxButton.YesNo);
                        //if (channels == null)
                        var clientsInStore = new JObject {
                        };
                        foreach (var item in channels)
                        {
                            clientsInStore[(string)item] = true;
                        }
                        clients[key] = new JObject
                        {
                            ["client"]   = windowClient.windowIdentifier,
                            ["active"]   = true,
                            ["channels"] = clientsInStore
                        };

                        readyToPersistState = true;
                        UpdateClientInStore(key);

                        stateChangeListeners?.Invoke(this, new FinsembleEventArgs
                                                     (
                                                         null, new JObject
                        {
                            ["channels"]    = channels,
                            ["allChannels"] = allChannels
                        }
                                                     ));

                        readyCallback(this, true);
                    };
                    bridge.WindowClient.GetComponentState(new JObject {
                        ["field"] = "Finsemble_Linker"
                    }, linkerStateHandler);
                });

                linkerStore.AddListener(new JObject
                {
                    ["field"] = "clients." + key
                }, delegate(object sender4, FinsembleEventArgs args4)
                {
                    var newChannelsObject = args4.response?["data"]?["value"]?["channels"] as JObject;
                    var newChannelsArray  = new JArray {
                    };
                    if (newChannelsObject != null)
                    {
                        foreach (var item in newChannelsObject)
                        {
                            newChannelsArray.Add(item.Key);
                        }
                    }
                    channels = newChannelsArray;

                    stateChangeListeners?.Invoke(this, new FinsembleEventArgs
                                                 (
                                                     null, new JObject
                    {
                        ["channels"]    = channels,
                        ["allChannels"] = allChannels
                    }
                                                 ));

                    if (readyToPersistState)
                    {
                        PersistState();
                    }

                    UpdateListeners();
                });

                linkerStore.AddListener(null,
                                        delegate(object sender4, FinsembleEventArgs args4)
                {
                    var newAllChannels = args4.response?["data"]?["storeData"]?["values"]?["channels"] as JArray;
                    if (newAllChannels != null)
                    {
                        allChannels = newAllChannels;
                    }
                    clients = args4.response?["data"]?["storeData"]?["values"]?["clients"] as JObject;
                    if (clients == null)
                    {
                        clients = new JObject {
                        }
                    }
                    ;
                });
            };

            bridge.distributedStoreClient.GetStore(new JObject {
                ["store"] = "Finsemble_Linker", ["global"] = true
            }, storehandler);
        }