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 23:53:56 UTC

incubator-usergrid git commit: refactor properties in winphone client

Repository: incubator-usergrid
Updated Branches:
  refs/heads/USERGRID-323-Win-phone c5acbfc90 -> 7b904751f


refactor properties in winphone client


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

Branch: refs/heads/USERGRID-323-Win-phone
Commit: 7b904751f524ec51fdd841ed03f74b83e6dd0960
Parents: c5acbfc
Author: Shawn Feldman <sf...@apache.org>
Authored: Fri Jan 23 15:53:49 2015 -0700
Committer: Shawn Feldman <sf...@apache.org>
Committed: Fri Jan 23 15:53:49 2015 -0700

----------------------------------------------------------------------
 .../Client/IUsergridClient.cs                   | 14 +++------
 .../Usergrid.Notifications/Client/PushClient.cs | 32 +++++++++++---------
 .../Usergrid.Notifications/Client/Usergrid.cs   | 24 +++++++--------
 .../Usergrid.Notifications/MainPage.xaml.cs     | 11 ++++---
 .../Package.StoreAssociation.xml                | 21 -------------
 .../Usergrid.Notifications/Package.appxmanifest |  2 +-
 6 files changed, 43 insertions(+), 61 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b904751/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs
index 986b2a1..3f4fb82 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/IUsergridClient.cs
@@ -59,6 +59,9 @@ namespace Usergrid.Notifications.Client
         /// Reference the push client, you should call register before using
         /// </summary>
         IPushClient Push { get; }
+
+        Exception LastException { get; }
+
     }
 
     /// <summary>
@@ -99,14 +102,6 @@ namespace Usergrid.Notifications.Client
         /// Device id in usergrid
         /// </summary>
         Guid DeviceId { get; set; }
-
-        /// <summary>
-        /// Register your device, you should call this everytime you start the app
-        /// </summary>
-        /// <param name="notifier"></param>
-        /// <returns></returns>
-        Task RegisterDevice(string notifier);
-        
         /// <summary>
         /// send a toast
         /// </summary>
@@ -121,7 +116,8 @@ namespace Usergrid.Notifications.Client
         /// <returns></returns>
         Task<bool> SendBadge<T>(T message);
 
-        Task InitializeChannel(PushNotificationChannel channel);
+        Exception LastException { get; }
+
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b904751/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 01d283d..8668626 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/PushClient.cs
@@ -36,12 +36,19 @@ namespace Usergrid.Notifications.Client
         private ApplicationDataContainer settings;
         private PushNotificationChannel channel;
 
-        public PushClient(IUsergridHttpClient usergrid)
+        public PushClient(IUsergridHttpClient usergrid, string notifier)
         {
             this.usergrid = usergrid;
             this.settings = ApplicationData.Current.LocalSettings;
+            this.Notifier = notifier;
+            this.init().ContinueWith(t =>
+                  {
+                      LastException = t.Exception;
+                  }  
+                );
         }
 
+
         public async Task<bool> SendToast(string message)
         {
             if (DeviceId == null)
@@ -76,13 +83,12 @@ namespace Usergrid.Notifications.Client
             return jsonResponse.StatusIsOk;
         }
 
-        public async Task RegisterDevice(string notifier)
+        private async Task init()
         {
-            await InitializeChannel(channel);
-            this.Notifier = notifier;
+            channel = await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync().AsTask<PushNotificationChannel>();
             if (settings.Values[DEVICE_KEY] == null)
             {
-                Guid uuid = await registerDevice(notifier, channel.Uri,true);
+                Guid uuid = await registerDevice(true);
                 settings.Values.Add(DEVICE_KEY, uuid);
                 this.DeviceId = uuid;
             }
@@ -94,22 +100,18 @@ namespace Usergrid.Notifications.Client
                 var device = await GetDevice(DeviceId);
                 if (device == null)
                 {
-                    Guid uuid = await registerDevice(notifier, channel.Uri,true);
+                    Guid uuid = await registerDevice(true);
                     settings.Values[DEVICE_KEY] = uuid;
                     this.DeviceId = uuid;
                 }
                 else
                 {
-
+                    await registerDevice(false);
                 }
             }
         }
 
-        public async Task InitializeChannel(PushNotificationChannel channel)
-        {
-            channel = channel != null ? channel : await PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync().AsTask<PushNotificationChannel>();
-        }
-
+       
         private async Task<JToken> GetDevice(Guid deviceId)
         {
             var jsonResponse = await usergrid.SendAsync(HttpMethod.Get, "devices/" + deviceId, null);
@@ -122,10 +124,10 @@ namespace Usergrid.Notifications.Client
             else { return null; }
         }
 
-        private async Task<Guid> registerDevice(string notifier, string channelUri, bool isNew)
+        private async Task<Guid> registerDevice(bool isNew)
         {
             JObject obj = new JObject();
-            obj.Add(notifier + ".notifier.id", new JValue(channelUri));
+            obj.Add(Notifier + ".notifier.id", new JValue(channel.Uri));
             var jsonResponse = await usergrid.SendAsync(
                 (isNew ? HttpMethod.Post : HttpMethod.Put), 
                 "devices/" +   (isNew ? "" : this.DeviceId.ToString()), 
@@ -145,5 +147,7 @@ namespace Usergrid.Notifications.Client
 
         public string Notifier { get; set; }
         public Guid DeviceId { get; set; }
+        public Exception LastException { get; set; }
+
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b904751/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs
index a2d637d..cd0330d 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Client/Usergrid.cs
@@ -28,19 +28,12 @@ using System.Net.Http.Headers;
 
 namespace Usergrid.Notifications.Client
 {
-    public class UsergridFactory
-    {
-        public static  IUsergridClient GetInstance(string serverUrl, string org, string app)
-        {
-            return new Usergrid(serverUrl, org, app);
-        }
-
-    }
-
+ 
     /// <summary>
     /// Usergrid client 
     /// </summary>
-    internal class Usergrid : IUsergridHttpClient, IUsergridClient
+
+    public class Usergrid : IUsergridHttpClient, IUsergridClient
     {
         private string appUrl;
         private string token;
@@ -55,13 +48,13 @@ namespace Usergrid.Notifications.Client
         /// <param name="org"></param>
         /// <param name="app"></param>
         /// <param name="channel"></param>
-        internal Usergrid(string serverUrl, string org, string app)
+        internal Usergrid(string serverUrl, string org, string app, string notifier)
         {
             string serverUrlWithSlash = serverUrl.EndsWith("/", StringComparison.CurrentCulture) ? serverUrl : serverUrl + "/";
             this.appUrl = String.Format("{0}{1}/{2}/", serverUrlWithSlash, org, app);
             this.managementUrl = serverUrlWithSlash + "management/";
             this.client = new HttpClient();
-            this.push = new PushClient(this);
+            this.push = new PushClient(this,notifier);
         }
 
         public async Task Authenticate(string user, string password, bool isManagement)
@@ -115,6 +108,13 @@ namespace Usergrid.Notifications.Client
         {
             return new StringContent(JsonConvert.SerializeObject(jsonObject));
         }
+
+
+        public Exception LastException
+        {
+            get;
+            set;
+        }
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b904751/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 e867f2c..7e03c79 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/MainPage.xaml.cs
@@ -44,7 +44,7 @@ namespace Usergrid.Notifications
         {
             this.InitializeComponent();
             //TODO: change me to your server
-            serverUrl = "http://192.168.130.54:8080";
+            serverUrl = "http://10.0.1.20:8080";
             //TODO: change me to your org
             org = "mobile";
             //TODO: change me to your app
@@ -56,14 +56,15 @@ namespace Usergrid.Notifications
             //TODO: change me to your password
             password = "test";
             this.NavigationCacheMode = NavigationCacheMode.Required;
-            Task t = this.setup();
+            this.setup().ContinueWith(t => {
+                LastException = t.Exception;
+            });
         }
 
         private async Task setup()
         {
-            usergrid = Client.UsergridFactory.GetInstance(serverUrl, org, app);
+            usergrid = new Client.Usergrid(serverUrl, org, app, notifier);
             await usergrid.Authenticate(user, password, true);
-            await usergrid.Push.RegisterDevice(notifier);
         }
 
         /// <summary>
@@ -120,5 +121,7 @@ namespace Usergrid.Notifications
         {
 
         }
+
+        public AggregateException LastException { get; set; }
     }
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b904751/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.StoreAssociation.xml
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.StoreAssociation.xml b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.StoreAssociation.xml
index 56bb3a6..c6278a4 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.StoreAssociation.xml
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.StoreAssociation.xml
@@ -1,26 +1,5 @@
 <?xml version="1.0" encoding="utf-8"?>
 <StoreAssociation xmlns="http://schemas.microsoft.com/appx/2010/storeassociation">
-  <!--
-    /*
- *
- *  * 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.
- *
- */
-    -->
   <Publisher>CN=AC3A1EB7-E4EA-48C0-9556-C37AA8BAE0CF</Publisher>
   <PublisherDisplayName>feldrocker</PublisherDisplayName>
   <GeneratePackageHash>http://www.w3.org/2001/04/xmlenc#sha256</GeneratePackageHash>

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/7b904751/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.appxmanifest
----------------------------------------------------------------------
diff --git a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.appxmanifest b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.appxmanifest
index bf51901..03165e6 100644
--- a/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.appxmanifest
+++ b/sdks/dotnet/samples/notifications/Usergrid.Notifications/Package.appxmanifest
@@ -21,7 +21,7 @@
  *
  */
     -->
-  <Identity Name="15661feldrocker.usergridsample" Publisher="CN=AC3A1EB7-E4EA-48C0-9556-C37AA8BAE0CF" Version="1.1.0.0" />
+  <Identity Name="15661feldrocker.usergridsample" Publisher="CN=AC3A1EB7-E4EA-48C0-9556-C37AA8BAE0CF" Version="1.1.0.1" />
   <mp:PhoneIdentity PhoneProductId="c05b658a-0b41-4187-a6e4-ca186c2338de" PhonePublisherId="00000000-0000-0000-0000-000000000000" />
   <Properties>
     <DisplayName>usergrid sample</DisplayName>