コード例 #1
0
        private void SetProxyHandlers()
        {
            Servers.OnPingUpdateRequired     += Proxy.PingServers;
            __ServiceProxy.ServerListChanged += (VpnServersInfo servers) =>
            {
                __SyncInvoke.BeginInvoke(new Action(() =>
                {
                    // Update servers information
                    Servers.UpdateServers(servers);

                    // update API services: alternate host IPs
                    if (servers?.Config?.Api?.IPs != null)
                    {
                        IVPNCommon.Api.ApiServices.Instance.SetAlternateHostIPs(new List <string> (servers.Config.Api.IPs));
                    }
                }), null);
            };

            __ServiceProxy.ServersPingsUpdated += (Dictionary <string, int> pingResults) =>
            {
                __SyncInvoke.BeginInvoke(new Action(() =>
                {
                    Servers.UpdateServersPings(pingResults);
                }), null);
            };

            __ServiceProxy.Preferences += (Dictionary <string, string> preferences) =>
            {
                // ignore preferences from service.
                // client will set its own settings
            };

            __ServiceProxy.ServiceStatusChange += (bool connected) =>
            {
                __SyncInvoke.BeginInvoke(new Action(() =>
                {
                    ServiceStatusChange(connected);
                }), null);
            };

            __ServiceProxy.ServiceExiting += () =>
            {
                __SyncInvoke.BeginInvoke(new Action(ServiceExiting), null);
            };

            __ServiceProxy.ClientException += ProcessProxyException;

            __ServiceProxy.ClientProxyDisconnected += ServiceProxy_ClientProxyDisconnected;

            __ServiceProxy.EventsEnabled = true;
        }
コード例 #2
0
ファイル: Service.cs プロジェクト: nschonni/desktop-app-ui
        private void SetProxyHandlers()
        {
            Servers.OnPingUpdateRequired += Proxy.PingServers;

            __ServiceProxy.SessionInfoChanged    += (SessionInfo s) => AppState.Instance().SetSession(s);
            __ServiceProxy.AccountStatusReceived += (string sessionToken, AccountStatus accountInfo) => AppState.Instance().SetAccountStatus(sessionToken, accountInfo);

            __ServiceProxy.ServerListChanged += (VpnServersInfo servers) =>
            {
                // If still no servers info - save it immediately (do not use "Invoke" mechanism)
                // It needed for situations when VPN already connected (on application start)
                //      All servers must be initialised on the moment when VPN connection status will be received.
                if (Servers.ServersList == null || Servers.ServersList.Count == 0)
                {
                    Servers.UpdateServers(servers);
                }

                __SyncInvoke.BeginInvoke(new Action(() =>
                {
                    // Update servers information
                    Servers.UpdateServers(servers);

                    // update API services: alternate host IPs
                    if (servers?.Config?.Api?.IPs != null)
                    {
                        IVPNCommon.Api.ApiServices.Instance.SetAlternateHostIPs(new List <string> (servers.Config.Api.IPs));
                    }
                }), null);
            };

            __ServiceProxy.ServersPingsUpdated += (Dictionary <string, int> pingResults) =>
            {
                __SyncInvoke.BeginInvoke(new Action(() =>
                {
                    Servers.UpdateServersPings(pingResults);
                }), null);
            };

            __ServiceProxy.Preferences += (Dictionary <string, string> preferences) =>
            {
                // ignore preferences from service.
                // client will set its own settings
            };

            __ServiceProxy.ServiceStatusChange += (bool connected) =>
            {
                __SyncInvoke.BeginInvoke(new Action(() =>
                {
                    ServiceStatusChange(connected);
                }), null);
            };

            __ServiceProxy.ServiceExiting += () =>
            {
                __SyncInvoke.BeginInvoke(new Action(ServiceExiting), null);
            };

            __ServiceProxy.ClientException += ProcessProxyException;

            __ServiceProxy.ClientProxyDisconnected += ServiceProxy_ClientProxyDisconnected;

            __ServiceProxy.EventsEnabled = true;
        }