summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar k0st1x2015-12-26 01:11:34 +0300
committerGravatar k0st1x2015-12-26 01:11:34 +0300
commit7d98c0b7de38999cfc0b81540d0ce425c7a0e15e (patch)
treebcf100fcf152d4675c64b9ebb399cd90366fbab2
parent73443e2fd916747e9d6c0bc5b0365e50813207e0 (diff)
migrate to WNS
-rw-r--r--Juick/App.xaml.cs12
-rw-r--r--Juick/Classes/TileHelper.cs52
-rw-r--r--Juick/Juick.csproj5
-rw-r--r--Juick/MainPage.xaml.cs14
-rw-r--r--Juick/NewPostView.xaml.cs22
-rw-r--r--Juick/Package.appxmanifest3
-rw-r--r--Juick/Properties/WMAppManifest.xml2
-rw-r--r--Juick/ViewModels/AppViewModel.cs117
-rw-r--r--Juick/ViewModels/LoginViewModel.cs3
-rw-r--r--Juick/packages.config2
10 files changed, 43 insertions, 189 deletions
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 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Phone.Controls, Version=8.0.0.0, Culture=neutral, PublicKeyToken=24eec0d8c86cda1e, processorArchitecture=MSIL" />
- <Reference Include="RestSharp.WindowsPhone, Version=105.1.0.0, Culture=neutral, processorArchitecture=MSIL">
- <HintPath>..\packages\RestSharp.105.1.0\lib\windowsphone8\RestSharp.WindowsPhone.dll</HintPath>
+ <Reference Include="RestSharp, Version=105.2.3.0, Culture=neutral, processorArchitecture=MSIL">
+ <HintPath>..\packages\RestSharp.105.2.3\lib\windowsphone81\RestSharp.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System.Windows.Interactivity">
@@ -132,7 +132,6 @@
<Compile Include="Classes\InvokeDelegateCommandAction.cs" />
<Compile Include="Classes\LowProfileImageLoader.cs" />
<Compile Include="Classes\MyUriMapper.cs" />
- <Compile Include="Classes\TileHelper.cs" />
<Compile Include="Controls\HyperLinkRichTextBox.cs" />
<Compile Include="Controls\MessageList.xaml.cs">
<DependentUpon>MessageList.xaml</DependentUpon>
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<string, string> queryStrings = this.NavigationContext.QueryString;
+ IDictionary<string, string> 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 @@
</InProcessServer>
</Extension>
</Extensions>
+ <Capabilities>
+ <Capability Name="internetClientServer" />
+ </Capabilities>
</Package> \ 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 @@
<?xml version="1.0" encoding="utf-8"?>
<Deployment xmlns="http://schemas.microsoft.com/windowsphone/2014/deployment" AppPlatformVersion="8.1">
<DefaultLanguage xmlns="" code="en-US" />
- <App xmlns="" ProductID="{ba7895cf-3f11-4459-9f91-6fe7df26e202}" Title="Juick" RuntimeType="Silverlight" Version="2.1.1" Genre="apps.normal" Author="Juick author" Description="Client for the juick.com service" Publisher="Juick" PublisherID="{bfbcb16e-c78a-4595-afc6-6ada592f1adc}" NotificationService="MPN">
+ <App xmlns="" ProductID="{ba7895cf-3f11-4459-9f91-6fe7df26e202}" Title="Juick" RuntimeType="Silverlight" Version="2.1.1" Genre="apps.normal" Author="Juick author" Description="Client for the juick.com service" Publisher="Juick" PublisherID="{bfbcb16e-c78a-4595-afc6-6ada592f1adc}" NotificationService="WNS">
<IconPath IsRelative="true" IsResource="false">Assets\ApplicationIcon.png</IconPath>
<Capabilities>
<Capability Name="ID_CAP_IDENTITY_DEVICE" />
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<AppViewModel>(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<SelectionChangedEventArgs>(CheckNewData, () => Account.IsAuthenticated);
}
+
+ void PushNotificationChannel_PushNotificationReceived(PushNotificationChannel sender, PushNotificationReceivedEventArgs args) {
+ Debug.WriteLine("PushNotificationReceived: " + args.NotificationType);
+ }
+
private ObservableCollection<PageViewModel> _pages;
public ObservableCollection<PageViewModel> 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 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="RestSharp" version="105.1.0" targetFramework="wp81" />
+ <package id="RestSharp" version="105.2.3" targetFramework="wp81" />
</packages> \ No newline at end of file