Exemple #1
0
        private void loginAsync(string serverID, string server, int port)
        {
            // Save the login in preferences
            var settings = new Settings(this);
            var connections = settings.GetConnections();
            var existingPreference = connections.FirstOrDefault(p => p.Server == server);

            if (string.IsNullOrEmpty(existingPreference.Server))
            {
                connections.Add(new HmdPreferences()
                {
                    Server = server,
                    ServerID = serverID,
                    Port = port
                });
            }
            else
            {
                existingPreference.ServerID = serverID;
                existingPreference.Port = port;
            }

            settings.SaveConnections(connections);

            // Start connection
            Thread t = new Thread(new ParameterizedThreadStart(delegate
            {
                var hmdServer = TinyIoCContainer.Current.Resolve<IHmdServer>();
                var connectionState = true;
                var connectionError = string.Empty;
                try
                {
                    hmdServer.Connect(serverID, server, port);
                }
                catch (Exception exc)
                {
                    connectionError = exc.Message;
                    connectionState = false;
                }

                this.RunOnUiThread(delegate
                {
                    this.progressDialog.Dismiss();
                    if (!connectionState)
                    {
                        // Display the errror message to the user
                        AlertDialog.Builder builder = new AlertDialog.Builder(this);
                        builder.SetTitle("Erreur de connexion");
                        builder.SetMessage(connectionError);
                        builder.SetCancelable(false);
                        builder.SetNeutralButton("Fermer", delegate(object sender, DialogClickEventArgs e)
                        {

                        });
                        builder.Show();
                    }
                    else
                    {
                        // Start the main activity
                        //Intent intent = new Intent(this, typeof(MainActivity));
                        //this.StartActivity(intent);
                        this.refreshAsync();
                    }
                });
            }));

            this.progressDialog = ProgressDialog.Show(this, "Veuillez patienter", "Connexion...", true);
            t.Start();
        }
Exemple #2
0
        private void showPreferencePopup()
        {
            var settings = new Settings(this);
            var connections = settings.GetConnections();

            if (connections.Count == 0)
                return; // not yet any items

            string[] items = connections.Select(p => p.Server + ":" + p.Port).ToArray();

            AlertDialog.Builder builder = new AlertDialog.Builder(this);

            builder.SetTitle("Choix du serveur");
            builder.SetPositiveButton("Ajouter", delegate(object sender, DialogClickEventArgs e)
            {
                // Let the popup close and show the normal login form
            });
            builder.SetNegativeButton("Gérer", delegate(object sender, DialogClickEventArgs e)
            {
                this.openConnectionManager();
            });
            builder.SetItems(items, delegate(object sender, DialogClickEventArgs e)
            {
                var index     = (int)e.Which;
                var connection = connections[index];
                this.loginAsync(connection.ServerID, connection.Server, connection.Port);
            });

            var alert = builder.Create();
            alert.Show();
        }