Пример #1
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??
            });
        }
Пример #2
0
        private void Disconnect()
        {
            if (disconnecting)
            {
                return;
            }

            disconnecting = true;
            Logger.Info("Disconnect called");

            // Clean up clients that require disposing
            try
            {
                if (logger != null)
                {
                    logger.Dispose();
                }
            }
            catch
            { }
            finally
            {
                logger = null;
            }

            try
            {
                if (LauncherClient != null)
                {
                    LauncherClient.Dispose();
                }
            }
            catch
            { }
            finally
            {
                LauncherClient = null;
            }

            try
            {
                if (RouterClient != null)
                {
                    RouterClient.Transmit("Finsemble.Assimilation.closed." + this.windowName, true);
                    RouterClient.Dispose();
                }
            }
            catch { }
            finally { }

            // Close appropriate connection


            if (socket != null)
            {
                socket.Close();
                socket = null;
            }

            // Notify listeners bridge is disconnected from OpenFin
            Disconnected?.Invoke(this, EventArgs.Empty);
        }
Пример #3
0
        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");
            }
        }
Пример #4
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);
        }