Merge branch 'vnext' of github.com:pazof/yavsc into vnext

vnext
Paul Schneider 8 years ago
commit 57ad50a437
4 changed files with 114 additions and 177 deletions

@ -36,6 +36,10 @@ namespace ZicMoove
using Model.Auth;
using Plugin.DeviceInfo;
using Yavsc.Models.Identity;
using System.Json;
using Newtonsoft.Json;
using System.Net.Http;
using System.Text;
public partial class App : Application // superclass new in 1.3
{
@ -196,7 +200,7 @@ namespace ZicMoove
private static UserProfilePage userProfilePage;
public static UserProfilePage UserProfilePage
{ get { return userProfilePage; } }
{ get { return userProfilePage; } }
ChatPage chatPage;
PinPage pinPage;
@ -231,15 +235,20 @@ namespace ZicMoove
BindingContext = bookQueries
};
homePage = new HomePage() {
homePage = new HomePage()
{
Title = "Accueil",
Icon = "icon.png" };
Icon = "icon.png"
};
homePage.BindingContext = new HomeViewModel {
homePage.BindingContext = new HomeViewModel
{
BookQueries = bookQueries,
UserProfile = userprofile };
UserProfile = userprofile
};
userProfilePage = new UserProfilePage {
userProfilePage = new UserProfilePage
{
Title = "Profile utilisateur",
Icon = "ic_corp_icon.png",
BindingContext = userprofile
@ -278,7 +287,7 @@ namespace ZicMoove
() =>
{
ShowPage(userProfilePage);
} )
})
};
ToolbarItem tiHome = new ToolbarItem()
@ -286,12 +295,13 @@ namespace ZicMoove
Text = "Accueil",
Icon = "icon.png",
Command = new Command(
() => {
() =>
{
ShowPage(homePage);
})
};
ToolbarItem tiPubChat= new ToolbarItem()
ToolbarItem tiPubChat = new ToolbarItem()
{
Text = "Chat",
Icon = "chat_icon_s.png",
@ -311,10 +321,10 @@ namespace ZicMoove
masterDetail.ToolbarItems.Add(tiSetts);
masterDetail.ToolbarItems.Add(tiPubChat);
this.MainPage = masterDetail;
NavigationService = new NavigationService(Navigation);
}
public static Task<string> DisplayActionSheet(string title, string cancel, string destruction, string [] buttons)
public static Task<string> DisplayActionSheet(string title, string cancel, string destruction, string[] buttons)
{
var currentPage = Navigation.NavigationStack.Last();
return currentPage.DisplayActionSheet(title, cancel, destruction, buttons);
@ -346,23 +356,23 @@ namespace ZicMoove
}
}
// Start the Hub connection
public static async void StartConnexion ()
public static async void StartConnexion()
{
if (CrossConnectivity.Current.IsConnected)
try
{
{
if (chatHubConnection.State == ConnectionState.Disconnected)
await chatHubConnection.Start();
}
catch (WebException )
{
// TODO use webex, set this cx down status somewhere,
// & display it & maybe try again later.
}
catch (Exception )
{
// TODO use ex
}
await chatHubConnection.Start();
}
catch (WebException)
{
// TODO use webex, set this cx down status somewhere,
// & display it & maybe try again later.
}
catch (Exception)
{
// TODO use ex
}
}
public void SetupHubConnection()
@ -373,7 +383,8 @@ namespace ZicMoove
chatHubConnection.Error += ChatHubConnection_Error;
chatHubProxy = chatHubConnection.CreateHubProxy("ChatHub");
chatHubProxy.On<string, string>("addPV", (n, m) => {
chatHubProxy.On<string, string>("addPV", (n, m) =>
{
var msg = new ChatMessage
{
Message = m,
@ -388,12 +399,12 @@ namespace ZicMoove
DataManager.Instance.ChatUsers.OnPrivateMessage(msg);
});
}
public static void StopConnection()
public static void StopConnection()
{
try
{
if (chatHubConnection.State != ConnectionState.Disconnected)
chatHubConnection.Stop();
chatHubConnection.Stop();
}
catch (WebException)
{
@ -431,24 +442,52 @@ namespace ZicMoove
return chatHubProxy;
}
}
public static Task<bool> HasSomeCloud {
public static Task<bool> HasSomeCloud
{
get
{
return CrossConnectivity.Current.IsReachable(Constants.YavscHomeUrl, Constants.CloudTimeout);
}
}
public static void PostDeviceInfo()
public static async Task PostDeviceInfo()
{
var info = GetDeviceInfo();
if (!string.IsNullOrWhiteSpace(info.GCMRegistrationId))
{
if (MainSettings.CurrentUser != null)
{
InvokeApi("gcm/register", info);
DataManager.Instance.Activities.Execute(null);
using (var client = UserHelpers.CreateJsonClient())
{
try
{
var stringContent = JsonConvert.SerializeObject(info);
HttpContent content = new StringContent(
stringContent, Encoding.UTF8, "application/json"
);
using (var response = await client.PostAsync(Constants.MobileRegistrationUrl, content))
{
if (response.IsSuccessStatusCode)
{
var rcontent = await response.Content.ReadAsStringAsync();
var jvalue = JsonValue.Parse(rcontent);
if (jvalue != null)
if (jvalue.ContainsKey("UpdateActivities"))
if ((bool)jvalue["UpdateActivities"])
{
DataManager.Instance.Activities.Execute(null);
DataManager.Instance.Activities.SaveEntity();
}
}
}
}
catch (Exception)
{
// TODO err reporting
}
}
}
}
}
public static IGCMDeclaration GetDeviceInfo()
@ -457,7 +496,7 @@ namespace ZicMoove
DateTime? lupdate = DataManager.Instance.Activities.Count > 0 ?
DataManager.Instance.Activities.Aggregate(
(a, b) => a.DateModified > b.DateModified ? a : b
).DateModified : (DateTime ?) null;
).DateModified : (DateTime?)null;
return new GCMRegIdDeclaration
{
@ -470,31 +509,8 @@ namespace ZicMoove
};
}
[Obsolete("Use RemoteEntity to manage entities from API")]
public async Task<TAnswer> InvokeApi<TAnswer>(string method, object arg)
{
using (var m =
new SimpleJsonPostMethod(
method, "Bearer " +
MainSettings.CurrentUser.YavscTokens.AccessToken
))
{
return await m.Invoke<TAnswer>(arg);
}
}
public static object InvokeApi(string method, object arg)
{
using (var m =
new SimpleJsonPostMethod(
method, "Bearer " +
MainSettings.CurrentUser.YavscTokens.AccessToken
))
{
return m.InvokeJson(arg);
}
}
public static void ShowBookQuery (BookQuery query)
public static void ShowBookQuery(BookQuery query)
{
var page = new BookQueryPage
{ BindingContext = new BookQueryViewModel(query) };

@ -1,118 +0,0 @@
//
// PostJson.cs
//
// Author:
// Paul Schneider <paulschneider@free.fr>
//
// Copyright (c) 2015 Paul Schneider
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
using System.Net;
using System.IO;
using System.Json;
using System.Threading.Tasks;
using Newtonsoft.Json;
using System;
using System.Diagnostics;
using ZicMoove;
namespace ZicMoove.Helpers
{
/// <summary>
/// Simple json post method.
/// </summary>
public class SimpleJsonPostMethod : IDisposable
{
private HttpWebRequest request=null;
/// <summary>
/// Initializes a new instance of the Yavsc.Helpers.SimpleJsonPostMethod class.
/// </summary>
/// <param name="pathToMethod">Path to method.</param>
public SimpleJsonPostMethod (string pathToMethod, string authorizationHeader = null)
{
request = (HttpWebRequest) WebRequest.Create ($"{BasePath}/{pathToMethod}");
request.Method = "POST";
request.Accept = "application/json";
request.ContentType = "application/json";
if (authorizationHeader != null)
request.Headers["Authorization"] = authorizationHeader;
}
public static string BasePath { get; private set; } = Constants.YavscApiUrl;
public void Dispose()
{
request.Abort();
}
/// <summary>
/// Invoke the specified query.
/// </summary>
/// <param name="query">Query.</param>
public async Task<TAnswer> Invoke<TAnswer>(object query)
{
using (Stream streamQuery = await request.GetRequestStreamAsync()) {
using (StreamWriter writer = new StreamWriter(streamQuery)) {
writer.Write (JsonConvert.SerializeObject(query));
}}
TAnswer ans = default (TAnswer);
using (WebResponse response = await request.GetResponseAsync ()) {
using (Stream responseStream = response.GetResponseStream ()) {
using (StreamReader rdr = new StreamReader (responseStream)) {
ans = (TAnswer) JsonConvert.DeserializeObject<TAnswer> (rdr.ReadToEnd ());
}
}
}
return ans;
}
public async Task<JsonValue> InvokeJson(object query)
{
JsonValue jsonDoc = null;
try
{
using (Stream streamQuery = await request.GetRequestStreamAsync())
{
using (StreamWriter writer = new StreamWriter(streamQuery))
{
writer.Write(JsonConvert.SerializeObject(query));
}
}
using (WebResponse response = await request.GetResponseAsync())
{
using (Stream stream = response.GetResponseStream())
{
if (stream.Length > 0)
jsonDoc = await Task.Run(() => JsonObject.Load(stream));
}
}
}
catch (WebException ex)
{
// TODO err logging
Debug.WriteLine($"Web request failed: {request.ToString()}\n" + ex.ToString());
}
catch (Exception ex)
{
Debug.WriteLine($"Web request failed: {request.ToString()}\n" + ex.ToString());
}
return jsonDoc;
}
}
}

@ -0,0 +1,39 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using Xamarin.Forms;
using ZicMoove.Model.Workflow;
namespace ZicMoove.Views
{
public class CommandFormView : ContentView
{
public static readonly BindableProperty CommandType = BindableProperty.Create(
"Type",
typeof(string),
typeof(CommandFormView)
);
public string Type
{
get
{
return GetValue(CommandType) as string;
}
set {
SetValue(CommandType, value);
}
}
CommandForm Context { get { return BindingContext as CommandForm; } }
public CommandFormView()
{
Content = new Label { Text = Context?.Title };
}
}
}

@ -67,7 +67,6 @@
<Compile Include="Data\ApiCallFailedException.cs" />
<Compile Include="Data\EstimateEntity.cs" />
<Compile Include="Data\NonCrUD\RemoteFiles.cs" />
<Compile Include="Helpers\SimpleJsonPostMethod.cs" />
<Compile Include="Model\Access\BlackListed.cs" />
<Compile Include="Model\Auth\GCRegIdDeclaration.cs" />
<Compile Include="Model\Booking\MusicalPreference.cs" />
@ -130,6 +129,7 @@
<Compile Include="ViewModels\UserProfile\UserProfileViewModel.cs" />
<Compile Include="ViewModels\UserProfile\DirectoryInfoViewModel.cs" />
<Compile Include="ViewModels\Validation\ErrorSeverity.cs" />
<Compile Include="Views\CommandFormView.cs" />
<Compile Include="Views\EnumPicker.cs" />
<Compile Include="Converters\BooleanToObjectConverter.cs" />
<Compile Include="Converters\EnumConverter.cs" />

Loading…