File: MonoLiveClient.cs

package info (click to toggle)
monogame 2.5.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 6,060 kB
  • ctags: 10,325
  • sloc: cs: 65,996; xml: 591; makefile: 22; ansic: 8
file content (94 lines) | stat: -rw-r--r-- 2,869 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MonoGame.Framework.MonoLive;

namespace MonoGame.Framework.GamerServices
{
    internal class MonoLiveClient
    {

        private static MonoLiveClient instance = null;

        public static MonoLiveClient Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new MonoLiveClient();
                }
                return instance;
            }
        }
        
        internal MonoLiveClient()
        {
        }

        public delegate void SignInCompletedEventHandler(object sender, SignInCompletedEventArgs e);

        public event SignInCompletedEventHandler SignInCompleted;

        public void SignInAsync(string username, string password)
        {
            MonoLive.MonoLive client = new MonoLive.MonoLive();
            client.SignInCompleted += new MonoLive.SignInCompletedEventHandler(client_SignInCompleted);
            client.SignInAsync(username, password, client);                            
        }

        private void client_SignInCompleted(object sender, MonoLive.SignInCompletedEventArgs e)
        {
            if (SignInCompleted != null && e.Error != null)
            {
                ((IDisposable)e.UserState).Dispose();
                SignInCompleted(this, new SignInCompletedEventArgs(new Microsoft.Xna.Framework.GamerServices.SignedInGamer()
                {
                    Gamertag = e.Result.Gamer.GamerTag,
                    DisplayName = e.Result.Gamer.GamerTag
                }));
                return;
            }
            SignInCompleted(this, null);
            
        }

        public Microsoft.Xna.Framework.GamerServices.Gamer SignIn(string username, string password)
        {
            using (MonoLive.MonoLive client = new MonoLive.MonoLive())
            {
                MonoLive.Result result = client.SignIn(username, password);
                if (result.ok)
                {
                    return new Microsoft.Xna.Framework.GamerServices.SignedInGamer()
                    {
                        Gamertag = result.Gamer.GamerTag,
                        DisplayName = result.Gamer.GamerTag
                    };                    
                }
            }
            return null;
        }

    }

    public partial class SignInCompletedEventArgs : EventArgs
    {
        private Microsoft.Xna.Framework.GamerServices.Gamer gamer;

        internal SignInCompletedEventArgs(Microsoft.Xna.Framework.GamerServices.Gamer gamer) 
        {
            this.gamer = gamer;
        }

        /// <remarks/>
        public Microsoft.Xna.Framework.GamerServices.Gamer Gamer
        {
            get
            {
                return this.gamer;
            }
        }
    }
}