summaryrefslogtreecommitdiff
path: root/StoneIsland/plugins/com.parse.cordova.core.pushplugin/src/wp8/ParsePlugin.cs
blob: 58d1c42e66742e1c2b4c1dd8f085f282fddedfa7 (plain)
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
using System;
using System.Collections.Generic;
using Parse;
using WPCordovaClassLib.Cordova;

namespace WPCordovaClassLib.Cordova.Commands
{
    public class ParsePlugin : BaseCommand
    {


        public async void initialize(string args)
        {

            PluginResult result;

            try
            {
                var appId = JSON.JsonHelper.Deserialize<string[]>(args)[0].ToString();
                var clientKey = JSON.JsonHelper.Deserialize<string[]>(args)[1].ToString();

                ParseClient.Initialize(appId, clientKey);

               
                await ParseInstallation.CurrentInstallation.SaveAsync();

             
                DispatchCommandResult( new PluginResult(PluginResult.Status.OK, true));
            }
            catch (Exception e)
            {
                DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, false));
            }




        }

        public void getInstallationId(string args)
        {

            String installationId = ParseInstallation.CurrentInstallation.InstallationId.ToString();
            var result = new PluginResult(PluginResult.Status.OK, installationId);
            DispatchCommandResult(result);

        }

        public void getInstallationObjectId(string args)
        {

            String objectId = ParseInstallation.CurrentInstallation.ObjectId.ToString();
            var result = new PluginResult(PluginResult.Status.OK, objectId);
            DispatchCommandResult(result);

        }

        public void getSubscriptions(string args)
        {


            var installation = ParseInstallation.CurrentInstallation;
            IEnumerable<string> subscribedChannels = installation.Channels;
            var result = new PluginResult(PluginResult.Status.OK, subscribedChannels);
            DispatchCommandResult(result);

        }

        public void subscribe(string args)
        {
            var topic = JSON.JsonHelper.Deserialize<string[]>(args)[0].ToString();
            ParsePush.SubscribeAsync(topic);

                   DispatchCommandResult( new PluginResult(PluginResult.Status.OK, true));
           
            
        }

        public void unsubscribe(string args)
        {
            var topic = JSON.JsonHelper.Deserialize<string[]>(args)[0].ToString();
            ParsePush.UnsubscribeAsync(topic);

            DispatchCommandResult(new PluginResult(PluginResult.Status.OK, true));
        }



    }
}