You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@usergrid.apache.org by sf...@apache.org on 2015/01/23 22:02:25 UTC

incubator-usergrid git commit: update uri

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-323-Win-phone 801bae266 -> 2bb0b74eb


update uri


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/2bb0b74e
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/2bb0b74e
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/2bb0b74e

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 2bb0b74eb12c395c52215c078953f703d6f2468b
Parents: 801bae2
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Jan 23 14:02:05 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Jan 23 14:02:05 2015 -0700

----------------------------------------------------------------------
 .../Usergrid.Notifications/Client/PushClient.cs | 37 ++++++++------
 .../Usergrid.Notifications/MainPage.xaml        |  7 +--
 .../Usergrid.Notifications/MainPage.xaml.cs     | 45 ++++++++++++++---
 .../wns/TranslatedNotification.java             | 53 ++++++++++++++++++++
 .../services/notifications/wns/WNSAdapter.java  | 23 +++------
 5 files changed, 122 insertions(+), 43 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2bb0b74e/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
index 8d23823..01d283d 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
@@ -80,9 +80,9 @@ namespace Usergrid.Notifications.Client
         {
             await InitializeChannel(channel);
             this.Notifier = notifier;
-            if (settings.Values[DEVICE_KEY] != null)
+            if (settings.Values[DEVICE_KEY] == null)
             {
-                Guid uuid = await registerDevice(notifier, channel.Uri);
+                Guid uuid = await registerDevice(notifier, channel.Uri,true);
                 settings.Values.Add(DEVICE_KEY, uuid);
                 this.DeviceId = uuid;
             }
@@ -91,12 +91,17 @@ namespace Usergrid.Notifications.Client
                 object tempId;
                 settings.Values.TryGetValue(DEVICE_KEY, out tempId);
                 this.DeviceId = Guid.Parse(tempId.ToString());
-                if (!await DeviceExists(DeviceId))
+                var device = await GetDevice(DeviceId);
+                if (device == null)
                 {
-                    Guid uuid = await registerDevice(notifier, channel.Uri);
+                    Guid uuid = await registerDevice(notifier, channel.Uri,true);
                     settings.Values[DEVICE_KEY] = uuid;
                     this.DeviceId = uuid;
                 }
+                else
+                {
+
+                }
             }
         }
 
@@ -105,23 +110,27 @@ namespace Usergrid.Notifications.Client
             channel = channel != null ? channel : await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync().AsTask<PushNotificationChannel>();
         }
 
-        private async Task<bool> DeviceExists(Guid deviceId)
+        private async Task<JToken> GetDevice(Guid deviceId)
         {
             var jsonResponse = await usergrid.SendAsync(HttpMethod.Get, "devices/" + deviceId, null);
 
             if (jsonResponse.StatusIsOk)
             {
                 var body = jsonResponse.GetValue("entities");
-                return body != null && body.Value<JArray>().Count > 0;
+                return body != null &&  body.Value<JArray>().Count > 0 ? body.Value<JArray>()[0] : null;
             }
-            else { return false; }
+            else { return null; }
         }
 
-        private async Task<Guid> registerDevice(string notifier, string uri)
+        private async Task<Guid> registerDevice(string notifier, string channelUri, bool isNew)
         {
             JObject obj = new JObject();
-            obj.Add(notifier + ".notifier.id", new JValue(uri));
-            var jsonResponse = await usergrid.SendAsync(HttpMethod.Post, "devices/", obj);
+            obj.Add(notifier + ".notifier.id", new JValue(channelUri));
+            var jsonResponse = await usergrid.SendAsync(
+                (isNew ? HttpMethod.Post : HttpMethod.Put), 
+                "devices/" +   (isNew ? "" : this.DeviceId.ToString()), 
+                obj
+                );
             
             if (jsonResponse.StatusIsOk)
             {
@@ -129,14 +138,12 @@ namespace Usergrid.Notifications.Client
                 var uuid = Guid.Parse(entity.Value<String>("uuid"));
                 return uuid;
             }
-            else { return Guid.Empty; }
+            else { 
+                return Guid.Empty; 
+            }
         }
 
         public string Notifier { get; set; }
         public Guid DeviceId { get; set; }
-
-
-
-    
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2bb0b74e/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml
index a3597ba..f22c8b6 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml
@@ -29,9 +29,10 @@
  */
     -->
     <Grid>
-        <TextBox x:Name="pushText" HorizontalAlignment="Left" Margin="75,46,0,0" TextWrapping="Wrap" Text="Push Text" VerticalAlignment="Top" Width="261" TextChanged="pushText_TextChanged"/>
-        <Button x:Name="SendToast"  Content="Toast" HorizontalAlignment="Left" Margin="75,118,0,0" VerticalAlignment="Top" Click="Button_Click" Width="39"/>
-        <Button x:Name="Badge" Content="Badge" HorizontalAlignment="Left" Margin="208,118,0,0" VerticalAlignment="Top" Click="Badge_Click"/>
+        <TextBox x:Name="pushText" HorizontalAlignment="Left" Margin="46,10,0,0" TextWrapping="Wrap" Text="Push Text" VerticalAlignment="Top" Width="261" TextChanged="pushText_TextChanged"/>
+        <Button x:Name="SendToast"  Content="Toast" HorizontalAlignment="Left" Margin="114,88,0,0" VerticalAlignment="Top" Click="Button_Click" Width="39"/>
+        <Button x:Name="Badge" Content="Badge" HorizontalAlignment="Left" Margin="114,157,0,0" VerticalAlignment="Top" Click="Badge_Click"/>
+        <TextBlock x:Name="Result" HorizontalAlignment="Left" Margin="46,295,0,0" TextWrapping="Wrap" Text="Did it work? " VerticalAlignment="Top" Height="49" Width="261" FontSize="25" SelectionChanged="Result_SelectionChanged"/>
 
     </Grid>
 </Page>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2bb0b74e/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
index e79dee3..e867f2c 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
@@ -43,12 +43,18 @@ namespace Usergrid.Notifications
         public MainPage()
         {
             this.InitializeComponent();
-            serverUrl = "http://yourserverurl";
-            org = "yourorg";
-            app = "yourapp";
-            notifier = "yournotifiername";
-            user = "youruser";
-            password = "password";
+            //TODO: change me to your server
+            serverUrl = "http://192.168.130.54:8080";
+            //TODO: change me to your org
+            org = "mobile";
+            //TODO: change me to your app
+            app = "sandbox";
+            //TODO: change me to your notifier name
+            notifier = "winphone";
+            //TODO: change me to your user
+            user = "superuser";
+            //TODO: change me to your password
+            password = "test";
             this.NavigationCacheMode = NavigationCacheMode.Required;
             Task t = this.setup();
         }
@@ -83,13 +89,36 @@ namespace Usergrid.Notifications
 
         private async void Button_Click(object sender, RoutedEventArgs e)
         {
+            Result.Text = "Sending....";
+
             var message = this.pushText.Text;
-            await usergrid.Push.SendToast(message);
+            if (await usergrid.Push.SendToast(message))
+            {
+                Result.Text = "It did! :)";
+            }
+            else
+            {
+                Result.Text = "It did not! :(";
+            }
         }
 
         private async void Badge_Click(object sender, RoutedEventArgs e)
         {
-            await usergrid.Push.SendBadge<int>(10);
+            Result.Text = "Sending....";
+
+            if (await usergrid.Push.SendBadge<int>(new Random().Next(1,100)))
+            {
+                Result.Text = "It did! :)";
+            }
+            else
+            {
+                Result.Text = "It did not! :(";
+            }
+        }
+
+        private void Result_SelectionChanged(object sender, RoutedEventArgs e)
+        {
+
         }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2bb0b74e/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/TranslatedNotification.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/TranslatedNotification.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/TranslatedNotification.java
new file mode 100644
index 0000000..1fc4d83
--- /dev/null
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/TranslatedNotification.java
@@ -0,0 +1,53 @@
+/*
+ *
+ *  * Licensed to the Apache Software Foundation (ASF) under one or more
+ *  *  contributor license agreements.  The ASF licenses this file to You
+ *  * under the Apache License, Version 2.0 (the "License"); you may not
+ *  * use this file except in compliance with the License.
+ *  * You may obtain a copy of the License at
+ *  *
+ *  *     http://www.apache.org/licenses/LICENSE-2.0
+ *  *
+ *  * Unless required by applicable law or agreed to in writing, software
+ *  * distributed under the License is distributed on an "AS IS" BASIS,
+ *  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  * See the License for the specific language governing permissions and
+ *  * limitations under the License.  For additional information regarding
+ *  * copyright in this work, please see the NOTICE file in the top level
+ *  * directory of this distribution.
+ *
+ */
+
+package org.apache.usergrid.services.notifications.wns;
+
+import org.apache.usergrid.persistence.model.entity.Entity;
+
+import java.io.Serializable;
+
+/**
+ * Classy class class.
+ */
+public class TranslatedNotification extends Entity implements Serializable {
+
+    private  Object payload;
+
+    private  String type;
+
+    public TranslatedNotification() {
+        super();
+    }
+
+    public TranslatedNotification(Object payload, String type) {
+        super();
+        this.payload = payload;
+        this.type = type;
+    }
+
+    public Object getPayload() {
+        return payload;
+    }
+
+    public String getType() {
+        return type;
+    }
+}

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/2bb0b74e/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
----------------------------------------------------------------------
diff --git a/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java b/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
index 227f633..5242e6f 100644
--- a/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
+++ b/stack/services/src/main/java/org/apache/usergrid/services/notifications/wns/WNSAdapter.java
@@ -76,7 +76,7 @@ public class WNSAdapter implements ProviderAdapter {
         try {
             List<TranslatedNotification> translatedNotifications = ( List<TranslatedNotification>) payload;
             for(TranslatedNotification translatedNotification : translatedNotifications) {
-                switch (translatedNotification.type) {
+                switch (translatedNotification.getType()) {
                     case "toast":
                         WnsToast toast = new WnsToastBuilder().bindingTemplateToastText01(translatedNotification.getPayload().toString()).build();
                         service.pushToast(providerId, toast);
@@ -116,12 +116,12 @@ public class WNSAdapter implements ProviderAdapter {
         if (payload instanceof Map) {
             //{payloads:{winphone:{toast:"mymessage",badge:1}}}
             Map<String, Object> map = (Map<String, Object>) payload;
-            if(map.containsKey("toast")) {
-                translatedNotifications.add(new TranslatedNotification( map.get("toast").toString(),"toast"));
+            if (map.containsKey("toast")) {
+                translatedNotifications.add(new TranslatedNotification(map.get("toast").toString(), "toast"));
+            }
+            if (map.containsKey("badge")) {
+                translatedNotifications.add(new TranslatedNotification(map.get("badge"), "badge"));
             }
-                if(map.containsKey("badge")){
-                    translatedNotifications.add(new TranslatedNotification( map.get("badge"),"badge"));
-                }
 
         } else {
             //{payloads:{winphone:"mymessage"}}
@@ -160,17 +160,6 @@ public class WNSAdapter implements ProviderAdapter {
     public Notifier getNotifier() {
         return notifier;
     }
-    public class TranslatedNotification{
-        private final Object payload;
-        private final String type;
 
-        public TranslatedNotification(Object payload, String type){
-            this.payload = payload;
-            this.type = type;
-        }
-
-        public Object getPayload(){return payload;}
-        public String getType(){return type;}
-    }
 
 }