From 7d98c0b7de38999cfc0b81540d0ce425c7a0e15e Mon Sep 17 00:00:00 2001 From: k0st1x Date: Sat, 26 Dec 2015 01:11:34 +0300 Subject: migrate to WNS --- Juick/App.xaml.cs | 12 ---- Juick/Classes/TileHelper.cs | 52 ----------------- Juick/Juick.csproj | 5 +- Juick/MainPage.xaml.cs | 14 +---- Juick/NewPostView.xaml.cs | 22 ++----- Juick/Package.appxmanifest | 3 + Juick/Properties/WMAppManifest.xml | 2 +- Juick/ViewModels/AppViewModel.cs | 117 +++++++++---------------------------- Juick/ViewModels/LoginViewModel.cs | 3 +- Juick/packages.config | 2 +- 10 files changed, 43 insertions(+), 189 deletions(-) delete mode 100644 Juick/Classes/TileHelper.cs diff --git a/Juick/App.xaml.cs b/Juick/App.xaml.cs index 100f0e3..96e2ecd 100644 --- a/Juick/App.xaml.cs +++ b/Juick/App.xaml.cs @@ -83,18 +83,6 @@ namespace Juick // This code will not execute when the application is reactivated private void Application_Launching(object sender, LaunchingEventArgs e) { - const string JuickCaption = "Juick"; - TileHelper.UpdateFlipTile( - JuickCaption, - string.Empty, - JuickCaption, - JuickCaption, - null, - "/ApplicationSmallTile.png", - "/ApplicationTile.png", - null, - "/ApplicationWideTile.png", - null); RootFrame.UriMapper = new MyUriMapper(); } diff --git a/Juick/Classes/TileHelper.cs b/Juick/Classes/TileHelper.cs deleted file mode 100644 index aa26690..0000000 --- a/Juick/Classes/TileHelper.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using Microsoft.Phone.Shell; - -namespace Juick.Classes -{ - static class TileHelper - { - public static void UpdateFlipTile( - string title, - string backTitle, - string backContent, - string wideBackContent, - int? count, - string smallBackgroundImageStringUri, - string backgroundImageStringUri, - string backBackgroundImageStringUri, - string wideBackgroundImageStringUri, - string wideBackBackgroundImageStringUri) - { - var smallBackgroundImage = CreateRelativeUri(smallBackgroundImageStringUri); - var backgroundImage = CreateRelativeUri(backgroundImageStringUri); - var backBackgroundImage = CreateRelativeUri(backBackgroundImageStringUri); - var wideBackgroundImage = CreateRelativeUri(wideBackgroundImageStringUri); - var wideBackBackgroundImage = CreateRelativeUri(wideBackBackgroundImageStringUri); - - // Loop through any existing Tiles that are pinned to Start. - foreach (var tileToUpdate in ShellTile.ActiveTiles) - { - var updateTileData = new FlipTileData - { - Title = title, - Count = count, - BackTitle = backTitle, - BackContent = backContent, - SmallBackgroundImage = smallBackgroundImage, - BackgroundImage = backgroundImage, - BackBackgroundImage = backBackgroundImage, - WideBackgroundImage = wideBackgroundImage, - WideBackBackgroundImage = wideBackBackgroundImage, - WideBackContent = wideBackContent - }; - - tileToUpdate.Update(updateTileData); - } - } - - static Uri CreateRelativeUri(string uriString) - { - return !string.IsNullOrEmpty(uriString) ? new Uri(uriString, UriKind.Relative) : null; - } - } -} diff --git a/Juick/Juick.csproj b/Juick/Juick.csproj index b50ccdf..fe72b05 100644 --- a/Juick/Juick.csproj +++ b/Juick/Juick.csproj @@ -108,8 +108,8 @@ - - ..\packages\RestSharp.105.1.0\lib\windowsphone8\RestSharp.WindowsPhone.dll + + ..\packages\RestSharp.105.2.3\lib\windowsphone81\RestSharp.dll True @@ -132,7 +132,6 @@ - MessageList.xaml diff --git a/Juick/MainPage.xaml.cs b/Juick/MainPage.xaml.cs index 4da88ec..f85ec97 100644 --- a/Juick/MainPage.xaml.cs +++ b/Juick/MainPage.xaml.cs @@ -1,11 +1,8 @@ using System; -using System.Collections.Generic; -using System.Windows; using System.Windows.Data; using Microsoft.Phone.Controls; using Microsoft.Phone.Shell; -using Juick.ViewModels; -using RestSharp; +using RestSharp.Authenticators; namespace Juick { @@ -15,11 +12,8 @@ namespace Juick public MainPage() { // Holds the push channel that is created or found. - - InitializeComponent(); - DataContext = App.AppContext; Loaded += (o, args) => @@ -52,12 +46,10 @@ namespace Juick } protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) - { - App.AppContext.Client.Authenticator = new HttpBasicAuthenticator(App.AppContext.Account.UserName, App.AppContext.Account.Password); + { + App.AppContext.Client.Authenticator = new HttpBasicAuthenticator(App.AppContext.Account.UserName, App.AppContext.Account.Password); } - - private void ApplicationBarIconButtonClick(object sender, EventArgs e) { App.AppContext.Pages[Pages.SelectedIndex].Items.Clear(); diff --git a/Juick/NewPostView.xaml.cs b/Juick/NewPostView.xaml.cs index dbc45c4..95fe7f1 100644 --- a/Juick/NewPostView.xaml.cs +++ b/Juick/NewPostView.xaml.cs @@ -1,29 +1,17 @@ using System; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Net; -using System.Net.Browser; -using System.Reflection; -using System.Text; using System.Windows; -using System.Windows.Controls; -using System.Windows.Documents; -using System.Windows.Input; -using System.Windows.Media; -using System.Windows.Media.Animation; using System.Windows.Media.Imaging; using System.Windows.Navigation; -using System.Windows.Resources; -using System.Windows.Shapes; -using Juick.Classes; using Microsoft.Phone.Controls; using Microsoft.Phone.Tasks; -using RestSharp; using Microsoft.Xna.Framework.Media; +using RestSharp; +using RestSharp.Authenticators; -namespace Juick -{ +namespace Juick { public partial class NewPostView : PhoneApplicationPage { private readonly BitmapImage _attachedPhoto = new BitmapImage(); @@ -37,9 +25,9 @@ namespace Juick protected override void OnNavigatedTo(NavigationEventArgs e) { // Get a dictionary of query string keys and values. - IDictionary queryStrings = this.NavigationContext.QueryString; + IDictionary queryStrings = NavigationContext.QueryString; - // Ensure that there is at least one key in the query string, and check + // Ensure that there is at least one key in the query string, and check // whether the "FileId" key is present. if (queryStrings.ContainsKey("FileId")) { diff --git a/Juick/Package.appxmanifest b/Juick/Package.appxmanifest index dac5dc8..4d683bb 100644 --- a/Juick/Package.appxmanifest +++ b/Juick/Package.appxmanifest @@ -39,4 +39,7 @@ + + + \ No newline at end of file diff --git a/Juick/Properties/WMAppManifest.xml b/Juick/Properties/WMAppManifest.xml index 67457fb..416159e 100644 --- a/Juick/Properties/WMAppManifest.xml +++ b/Juick/Properties/WMAppManifest.xml @@ -1,7 +1,7 @@  - + Assets\ApplicationIcon.png diff --git a/Juick/ViewModels/AppViewModel.cs b/Juick/ViewModels/AppViewModel.cs index 4aa9321..b4b287b 100644 --- a/Juick/ViewModels/AppViewModel.cs +++ b/Juick/ViewModels/AppViewModel.cs @@ -1,26 +1,19 @@ using System; -using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Linq; +using System.Diagnostics; using System.Net.NetworkInformation; +using System.Windows.Controls; using Juick.Classes; -using JuickApi; using Microsoft.Phone.Net.NetworkInformation; using RestSharp; -using Microsoft.Phone.Notification; -using System.Diagnostics; -using System.Text; -using System.Windows.Controls; +using Windows.Networking.PushNotifications; namespace Juick.ViewModels { public class AppViewModel : ViewModelBase { static readonly string IsNetworkAvailablePropertyName = ExpressionHelper.GetPropertyName(x => x.NetworkUnavailable); - readonly HttpNotificationChannel pushChannel; - - // The name of our push channel. - string channelName = "JuickChannel"; + PushNotificationChannel pushNotificationChannel; public void UpdateNetworkStatus() { @@ -31,77 +24,23 @@ namespace Juick.ViewModels { UpdateNetworkStatus(); NetworkChange.NetworkAddressChanged += (sender, args) => UpdateNetworkStatus(); - pushChannel = HttpNotificationChannel.Find(channelName); - - // If the channel was not found, then create a new connection to the push service. - if (pushChannel == null) - { - pushChannel = new HttpNotificationChannel(channelName); - - // Register for all the events before attempting to open the channel. - pushChannel.ChannelUriUpdated += (sender, e) => EnableNotifications(); - pushChannel.ErrorOccurred += (sender, e) => DisableNotifications(); - - // Register for this notification only if you need to receive the notifications while your application is running. - // Register for this notification only if you need to receive the notifications while your application is running. - pushChannel.ShellToastNotificationReceived += (sender, e) => - { - StringBuilder message = new StringBuilder(); - string relativeUri = string.Empty; - - message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString()); - - // Parse out the information that was part of the message. - foreach (string key in e.Collection.Keys) - { - message.AppendFormat("{0}: {1}\n", key, e.Collection[key]); - - if (string.Compare( - key, - "wp:Param", - System.Globalization.CultureInfo.InvariantCulture, - System.Globalization.CompareOptions.IgnoreCase) == 0) - { - relativeUri = e.Collection[key]; - } + PushNotificationChannelManager.CreatePushNotificationChannelForApplicationAsync() + .AsTask() + .ContinueWith(x => { + if(x.IsFaulted) { + Debug.WriteLine(x.Exception.GetBaseException().ToString()); + } else { + pushNotificationChannel = x.Result; + pushNotificationChannel.PushNotificationReceived += PushNotificationChannel_PushNotificationReceived; } - Debug.WriteLine("Received: " + message.ToString()); - }; - pushChannel.Open(); - } - else - { - // The channel was already open, so just register for all the events. - pushChannel.ChannelUriUpdated += (sender, e) => EnableNotifications(); - pushChannel.ErrorOccurred += (sender, e) => DisableNotifications(); - - // Register for this notification only if you need to receive the notifications while your application is running. - pushChannel.ShellToastNotificationReceived += (sender, e) => - { - StringBuilder message = new StringBuilder(); - string relativeUri = string.Empty; - - message.AppendFormat("Received Toast {0}:\n", DateTime.Now.ToShortTimeString()); - - // Parse out the information that was part of the message. - foreach (string key in e.Collection.Keys) - { - message.AppendFormat("{0}: {1}\n", key, e.Collection[key]); - - if (string.Compare( - key, - "wp:Param", - System.Globalization.CultureInfo.InvariantCulture, - System.Globalization.CompareOptions.IgnoreCase) == 0) - { - relativeUri = e.Collection[key]; - } - } - Debug.WriteLine("Received: " + message.ToString()); - }; - } + }); CheckNewDataCommand = new DelegateCommand(CheckNewData, () => Account.IsAuthenticated); } + + void PushNotificationChannel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) { + Debug.WriteLine("PushNotificationReceived: " + args.NotificationType); + } + private ObservableCollection _pages; public ObservableCollection Pages { @@ -144,10 +83,8 @@ namespace Juick.ViewModels get { return _acc ?? (_acc = new AccountManager()); } } - private RestClient _cl; - private readonly string _juickUri = HttpsHelper.CanUseHttps ? "https://api.juick.com" : "http://api.juick.com"; - + private RestClient _cl; public RestClient Client { get @@ -162,21 +99,19 @@ namespace Juick.ViewModels public void EnableNotifications() { if (!Account.IsAuthenticated) return; - if (pushChannel.ChannelUri == null) return; - var channelUri = pushChannel.ChannelUri.ToString(); + if(pushNotificationChannel == null || pushNotificationChannel.Uri == null) + return; + var channelUri = pushNotificationChannel.Uri; if (channelUri == Account.NotificationUri) return; - Account.NotificationUri = channelUri; - if (!pushChannel.IsShellToastBound) - // Bind this new channel for toast events. - pushChannel.BindToShellToast(); + Account.NotificationUri = channelUri; } public void DisableNotifications() { - if (pushChannel.IsShellToastBound) - pushChannel.UnbindToShellToast(); - Account.NotificationUri = string.Empty; + if(pushNotificationChannel != null) + pushNotificationChannel.Close(); + Account.NotificationUri = string.Empty; } public void CheckNewData(SelectionChangedEventArgs param) diff --git a/Juick/ViewModels/LoginViewModel.cs b/Juick/ViewModels/LoginViewModel.cs index f6f50ec..c593c06 100644 --- a/Juick/ViewModels/LoginViewModel.cs +++ b/Juick/ViewModels/LoginViewModel.cs @@ -3,10 +3,11 @@ using System.Net; using System.Windows; using Juick.Classes; using RestSharp; +using RestSharp.Authenticators; namespace Juick.ViewModels { - public class LoginViewModel : ViewModelBase + public class LoginViewModel : ViewModelBase { private string _username; private string _password; diff --git a/Juick/packages.config b/Juick/packages.config index 6d3a4f2..deb06bb 100644 --- a/Juick/packages.config +++ b/Juick/packages.config @@ -1,4 +1,4 @@  - + \ No newline at end of file -- cgit v1.2.3