changement de candidat à l'investissement

This commit is contained in:
Paul Schneider 2017-01-26 11:04:03 +01:00
commit be3087fff6
351 changed files with 359 additions and 497 deletions

View file

@ -0,0 +1,10 @@
using System;
namespace BookAStar
{
public class NotIdentifiedException : Exception
{
public NotIdentifiedException(string message) : base(message) { }
}
}

View file

@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace BookAStar.Helpers
{
public static class PageHelpers
{
public static async Task<bool> Confirm(this Page page, string title, string procedure)
{
string yes = "Oui", no = "Non";
var answer = await page.DisplayAlert(title,
procedure, yes, no);
return answer;
}
}
}

View file

@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Text;
using System.Threading.Tasks;
namespace BookAStar.Helpers
{
public static class PropertySupport
{
public static string ExtractPropertyName<T>(Expression<Func<T>> propertyExpression)
{
if (propertyExpression == null)
{
throw new ArgumentNullException("propertyExpression");
}
var memberExpression = propertyExpression.Body as MemberExpression;
if (memberExpression == null)
{
throw new ArgumentException("Invalide Expression", "propertyExpression");
}
return memberExpression.Member.Name;
}
}
}

View file

@ -0,0 +1,10 @@
using System;
namespace BookAStar
{
public class ServiceNotAvailable : Exception
{
public ServiceNotAvailable(string message, Exception innerException) : base(message, innerException) { }
}
}

View file

@ -0,0 +1,43 @@
// Helpers/Settings.cs
#if USELESS_but_makes_the_component_removable // this file must exist ^^
namespace BookAStar.Helpers
{
/// <summary>
/// This is the Settings static class that can be used in your Core solution or in any
/// of your client applications. All settings are laid out the same exact way with getters
/// and setters.
/// </summary>
public static class Settings
{
public static ISettings AppSettings
{
get
{
return CrossSettings.Current;
}
}
#region Setting Constants
private const string SettingsKey = "settings_key";
public static readonly string SettingsDefault = string.Empty;
#endregion
public static string GeneralSettings
{
get
{
return AppSettings.GetValueOrDefault<string>(SettingsKey, SettingsDefault);
}
set
{
AppSettings.AddOrUpdateValue<string>(SettingsKey, value);
}
}
}
}
#endif

View file

@ -0,0 +1,80 @@

using System;
using System.Globalization;
using System.IO;
using System.Net.Http;
using System.Threading.Tasks;
using Xamarin.Forms;
namespace BookAStar.Helpers
{
using Data.NonCrUD;
using Model.FileSystem;
public static class UserHelpers
{
public static ImageSource Avatar(string avatarPath)
{
var result = avatarPath == null ?
ImageSource.FromResource( "BookAStar.Images.Users.icon_user.png") :
ImageSource.FromUri(new Uri(Constants.YavscHomeUrl+"/Avatars/"+avatarPath)) ;
return result;
}
public static ImageSource SmallAvatar(string avatarPath, string username)
{
return avatarPath == null ?
ImageSource.FromResource("BookAStar.Images.Users.icon_user.png") :
ImageSource.FromUri(new Uri($"{Constants.YavscHomeUrl}/Avatars/{username}.s.png"));
}
public static ImageSource ExtraSmallAvatar(string avatarPath, string username)
{
return avatarPath == null ?
ImageSource.FromResource("BookAStar.Images.Users.icon_user.png") :
ImageSource.FromUri(new Uri($"{Constants.YavscHomeUrl}/Avatars/{username}.xs.png"));
}
public static HttpClient CreateJsonClient()
{
return CreateJsonClient(MainSettings.CurrentUser.YavscTokens.AccessToken);
}
public static HttpClient CreateJsonClient(string accessToken)
{
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue(
"Bearer", accessToken);
client.DefaultRequestHeaders.Add("Accept", "application/json");
return client;
}
/// <summary>
/// Uploads the given stream to
/// /api/fs, in order to be saved under the given file name
/// </summary>
/// <param name="inputStream"></param>
/// <param name="fileName"></param>
/// <returns></returns>
public static async Task<bool> Upload(Stream inputStream, string fileName)
{
using (var client = CreateJsonClient())
{
using (var content =
new MultipartFormDataContent("Upload----" + DateTime.Now.ToString(CultureInfo.InvariantCulture)))
{
content.Add(new StreamContent(inputStream), "Files", fileName);
using (
var message =
await client.PostAsync(Constants.FsUrl, content))
{
return (message.IsSuccessStatusCode);
}
}
}
}
}
}