From d8965ed526c1984e328b7f2d397ce898823822d4 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Mon, 30 Nov 2015 19:03:05 +0100 Subject: [PATCH] Fichiers manquant au dernier commit --- Features.md | 53 ++++ web/Views/FrontOffice/Performers.aspx | 23 ++ web/Views/Home/Activity.ascx | 9 + .../FrontOffice/PerformerAvailability.cs | 82 ++++++ yavscModel/Google/Api/ApiClient.cs | 98 +++++++ yavscModel/Google/Api/CalendarApi.cs | 132 ++++++++++ yavscModel/Google/Api/Entity.cs | 55 ++++ yavscModel/Google/Api/EntityQuery.cs | 45 ++++ yavscModel/Google/Api/GoogleHelpers.cs | 136 ++++++++++ yavscModel/Google/Api/MapTracks.cs | 80 ++++++ .../Api/Messaging/MessageWithPayLoad.cs | 98 +++++++ .../Messaging/MessageWithPayloadResponse.cs | 71 +++++ .../Google/Api/Messaging/Notification.cs | 62 +++++ yavscModel/Google/Api/OAuth2.cs | 249 ++++++++++++++++++ yavscModel/Google/Api/PeopleApi.cs | 67 +++++ yavscModel/SimpleJsonPostMethod.cs | 108 ++++++++ yavscModel/Skill/SkillRating.cs | 44 ++++ 17 files changed, 1412 insertions(+) create mode 100644 Features.md create mode 100644 web/Views/FrontOffice/Performers.aspx create mode 100644 web/Views/Home/Activity.ascx create mode 100644 yavscModel/FrontOffice/PerformerAvailability.cs create mode 100644 yavscModel/Google/Api/ApiClient.cs create mode 100644 yavscModel/Google/Api/CalendarApi.cs create mode 100644 yavscModel/Google/Api/Entity.cs create mode 100644 yavscModel/Google/Api/EntityQuery.cs create mode 100644 yavscModel/Google/Api/GoogleHelpers.cs create mode 100644 yavscModel/Google/Api/MapTracks.cs create mode 100644 yavscModel/Google/Api/Messaging/MessageWithPayLoad.cs create mode 100644 yavscModel/Google/Api/Messaging/MessageWithPayloadResponse.cs create mode 100644 yavscModel/Google/Api/Messaging/Notification.cs create mode 100644 yavscModel/Google/Api/OAuth2.cs create mode 100644 yavscModel/Google/Api/PeopleApi.cs create mode 100644 yavscModel/SimpleJsonPostMethod.cs create mode 100644 yavscModel/Skill/SkillRating.cs diff --git a/Features.md b/Features.md new file mode 100644 index 00000000..4c665632 --- /dev/null +++ b/Features.md @@ -0,0 +1,53 @@ +# Fonctionalités + +# Une publication des talent du site + +Des notions de *préstataire*, d'*activité* et de *compténces* +dirigent maintenant le "link juice": + +Sont publiées en home page les descriptions en temps réel des activités soutenues par au mois un préstataire enregistré, ayant déclaré son statut de préstataire par un choix parmis les activités configurée par l'administration du site. + +Le prestataire peut détailler ses compétences, en leur donnant une côte de départ, qui sera modifiée par les clients de ce prestataire, une fois le service rendu. + +# Une reservation de préstataire + +Le préstataire peut renseigner un identifiant de calendrier Google. + +Dans ce cas, à la proposition de la reservation de ses services, +on peut verifier (à l'aide d'un algorythme à rendre modulaire) +sa disponibilité et présenter au client un peu plus de confiance +dans le succès de sa demande de reservation. + +La fiche prestataire presente aussi, le cas échéant, un lien vers son blog (à l'existence de billets publiques). + +Le processus de reservation d'un préstataire peut être conduit par un utilisateur anonyme (non enregistré sur le site) jusqu'à la validation de son panier de commandes. + +## Un blog spot + +On peut poster des billets, avec une mise en forme stockée à la Markdown en base de donnée, +en WYSIWYG depuis l'interface Web grâce à un fork de hallo.js . + +La syntaxe a été etendue pour pouvoir publier, en tant qu'objet du document, des vidéos et fichiers audio. + +On peut attacher toute sorte de document à chacun des billets. + +# Un système de facturation + +Pour l'instant, il est réduit au minimum : un édition d'un devis, qui à la publicaton en LaTeX ou Pdf est présenté comme une facture. + +## Peut-être à desactiver ? à rendre optionnel au niveau administratif et utilisateur : le systeme de fichiers utilisateur + +Tout utilisateur enregistré dispose aussi du moyen de publier des applications de son choix, via son espace de fichiers perso ou ses billet de blog. + + +# La conformité légale + +Hors mis les mentions légales concernant la responsabilité du site, +un système d'avertissement unique par utilisateur à été mis en place. + +Il a été mis en oeuvre pour prévenir tout nouvel utilisateur, qu'en parcourant ce site, + il accèpte le stockage de données persistantes sur son ordinateur, appélées "cookies" + destinées à lui faciliter son expérience du site ... + +Il reste à prévenir de l'utilisation des liens vers les réseaux sociaux (pour l'instant, seulement Google Plus). + diff --git a/web/Views/FrontOffice/Performers.aspx b/web/Views/FrontOffice/Performers.aspx new file mode 100644 index 00000000..09fe87e3 --- /dev/null +++ b/web/Views/FrontOffice/Performers.aspx @@ -0,0 +1,23 @@ +<%@ Page Language="C#" Title="Performers" MasterPageFile="~/Models/App.master" Inherits="System.Web.Mvc.ViewPage>" %> + + +<% foreach (var available in Model) { %> +
+<%= Html.Partial("Performer", available.Profile ) %>
+<% if (available.DateAvailable) { +%> +<%= Html.Translate("ThisPerformerGivesAccessToHisCalendarAndSeemsToBeAvailable") %> +<% +} +else if (available.Profile.HasCalendar()) { +%> +<%= Html.Translate("ThisPerformerGivesAccessToHisCalendarAndItAppearsHeShouldNotBeAvailable") %> +<% +} else { +%> +<%= Html.Translate("ThisPerformerDoesntGiveAccessToHisCalendar") %> + + +<% +} %>
<% } %> +
diff --git a/web/Views/Home/Activity.ascx b/web/Views/Home/Activity.ascx new file mode 100644 index 00000000..922e6746 --- /dev/null +++ b/web/Views/Home/Activity.ascx @@ -0,0 +1,9 @@ +<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %> +
+
+
+

"> +<%=Html.Encode(Model.Title)%>

+

+<%=Html.Markdown(Model.Comment)%> +

diff --git a/yavscModel/FrontOffice/PerformerAvailability.cs b/yavscModel/FrontOffice/PerformerAvailability.cs new file mode 100644 index 00000000..7efd2c7b --- /dev/null +++ b/yavscModel/FrontOffice/PerformerAvailability.cs @@ -0,0 +1,82 @@ +// +// PerformerAvailability.cs +// +// Author: +// Paul Schneider +// +// Copyright (c) 2015 GNU GPL +// +// 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 . + +using System; +using Yavsc.Model.RolesAndMembers; +using Yavsc.Model.Skill; +using System.Web.Security; +using System.Web.Profile; +using System.Collections.Generic; +using Yavsc.Model; +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using Yavsc.Model.Google.Api; +using Yavsc.Model.WorkFlow; + +namespace Yavsc.Model.FrontOffice +{ + /// + /// Performer availability. + /// + public class PerformerAvailability : UserNameBase { + /// + /// Initializes a new instance of the class. + /// + /// Profile. + /// User name. + /// Date. + /// If set to true available. + public PerformerAvailability(PerformerProfile profile, + string userName, DateTime date, bool available) { + DateAvailable = available; + PerformanceDate = date; + UserName = userName; + preformerProfile = profile; + } + + PerformerProfile preformerProfile = null; + /// + /// Gets the profile. + /// + /// The profile. + public PerformerProfile Profile + { + get { + return preformerProfile; + } + } + + /// + /// Gets or sets the performance date. + /// + /// The performance date. + public DateTime PerformanceDate { get; set; } + + /// + /// Gets or sets a value indicating whether this date available. + /// + /// true if date available; otherwise, false. + public bool DateAvailable { get; set; } + + } + +} diff --git a/yavscModel/Google/Api/ApiClient.cs b/yavscModel/Google/Api/ApiClient.cs new file mode 100644 index 00000000..08a89b8f --- /dev/null +++ b/yavscModel/Google/Api/ApiClient.cs @@ -0,0 +1,98 @@ +// +// Manager.cs +// +// Author: +// Paul Schneider +// +// 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 . + +using System; +using System.Web.Profile; +using Yavsc.Model.Google; +using System.Net; +using System.IO; +using System.Text; +using Newtonsoft.Json; +using System.Configuration; + +namespace Yavsc.Model.Google.Api +{ + /// + /// Google base API client. + /// This class implements the identification values for a Google Api, + /// and provides some scope values. + /// + public class ApiClient + { + private static string clientId=null; + private static string clientSecret=null; + private static string clientApiKey=null; + + /// + /// The CLIENT Id. + /// + public static string CLIENT_ID { + get { + if (clientId==null) + clientId = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_ID"]; + return clientId; + } + } + + /// + /// The CLIENt SECREt + /// + public static string CLIENT_SECRET {get { + if (clientSecret==null) + clientSecret = ConfigurationManager.AppSettings ["GOOGLE_CLIENT_SECRET"]; + return clientSecret; + + }} + + /// + /// The API KEY. + /// + public static string API_KEY {get { + if (clientApiKey==null) + clientApiKey = ConfigurationManager.AppSettings ["GOOGLE_API_KEY"]; + return clientApiKey; + + }} + /* // to use in descendence + * + protected static string getPeopleUri = "https://www.googleapis.com/plus/v1/people"; + private static string authUri = "https://accounts.google.com/o/oauth2/auth"; + */ + /// + /// The Map tracks scope . + /// + protected static string scopeTracks = "https://www.googleapis.com/auth/tracks"; + /// + /// The calendar scope. + /// + protected static string scopeCalendar = "https://www.googleapis.com/auth/calendar"; + + /// + /// The scope openid. + /// + protected static string[] scopeOpenid = { + "openid", + "profile", + "email" + }; + } + +} diff --git a/yavscModel/Google/Api/CalendarApi.cs b/yavscModel/Google/Api/CalendarApi.cs new file mode 100644 index 00000000..24278ff1 --- /dev/null +++ b/yavscModel/Google/Api/CalendarApi.cs @@ -0,0 +1,132 @@ +// +// Calendar.cs +// +// Author: +// Paul Schneider +// +// 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 . + +using System; +using System.Web.Profile; +using Yavsc.Model.Google; +using System.Net; +using System.IO; +using System.Text; +using Newtonsoft.Json; +using System.Web; +using Yavsc.Model; +using System.Runtime.Serialization.Json; + +namespace Yavsc.Model.Google.Api +{ + /// + /// Google Calendar API client. + /// + public class CalendarApi : ApiClient + { + public CalendarApi() + { + } + /// + /// The get cal list URI. + /// + protected static string getCalListUri = "https://www.googleapis.com/calendar/v3/users/me/calendarList"; + /// + /// The get cal entries URI. + /// + protected static string getCalEntriesUri = "https://www.googleapis.com/calendar/v3/calendars/{0}/events"; + + /// + /// The date format. + /// + private static string dateFormat = "yyyy-MM-ddTHH:mm:ss"; + + /// + /// The time zone. TODO Fixme with machine time zone + /// + private string timeZone = "+01:00"; + + /// + /// Gets the calendar list. + /// + /// The calendars. + /// Cred. + public CalendarList GetCalendars (string cred) + { + CalendarList res = null; + HttpWebRequest webreq = WebRequest.CreateHttp (getCalListUri); + webreq.Headers.Add (HttpRequestHeader.Authorization, cred); + webreq.Method = "GET"; + webreq.ContentType = "application/http"; + using (WebResponse resp = webreq.GetResponse ()) { + using (Stream respstream = resp.GetResponseStream ()) { + res = (CalendarList) new DataContractJsonSerializer(typeof(CalendarList)).ReadObject (respstream); + } + resp.Close (); + } + webreq.Abort (); + return res; + } + + /// + /// Gets a calendar event list, between the given dates. + /// + /// The calendar. + /// Calendar identifier. + /// Mindate. + /// Maxdate. + /// credential string. + public CalendarEventList GetCalendar (string calid, DateTime mindate, DateTime maxdate,string cred) + { + if (string.IsNullOrWhiteSpace (calid)) + throw new Exception ("the calendar identifier is not specified"); + + string uri = string.Format ( + getCalEntriesUri, HttpUtility.UrlEncode (calid)) + + string.Format ("?orderBy=startTime&singleEvents=true&timeMin={0}&timeMax={1}&key=" + API_KEY, + HttpUtility.UrlEncode (mindate.ToString (dateFormat) + timeZone), + HttpUtility.UrlEncode (maxdate.ToString (dateFormat) + timeZone)); + + HttpWebRequest webreq = WebRequest.CreateHttp (uri); + + webreq.Headers.Add (HttpRequestHeader.Authorization, cred); + webreq.Method = "GET"; + webreq.ContentType = "application/http"; + CalendarEventList res = null; + try { + using (WebResponse resp = webreq.GetResponse ()) { + using (Stream respstream = resp.GetResponseStream ()) { + try { + res = (CalendarEventList) new DataContractJsonSerializer(typeof(CalendarEventList)).ReadObject (respstream); + } catch (Exception ) { + respstream.Close (); + resp.Close (); + webreq.Abort (); + throw ; + } + } + resp.Close (); + } + } catch (WebException ) { + webreq.Abort (); + throw; + } + webreq.Abort (); + return res; + } + + } +} diff --git a/yavscModel/Google/Api/Entity.cs b/yavscModel/Google/Api/Entity.cs new file mode 100644 index 00000000..553584e0 --- /dev/null +++ b/yavscModel/Google/Api/Entity.cs @@ -0,0 +1,55 @@ +// +// Entity.cs +// +// Author: +// Paul Schneider +// +// 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 . + +using System; +using System.Web.Profile; +using Yavsc.Model.Google; +using System.Net; +using System.IO; +using System.Text; +using Newtonsoft.Json; + +namespace Yavsc.Model.Google.Api +{ + /// + /// Entity. + /// + public class Entity + { + /// + /// The I. + /// + public string ID; + /// + /// The name. + /// + public string Name; + + /// + /// The type: AUTOMOBILE: A car or passenger vehicle. + /// * TRUCK: A truck or cargo vehicle. + /// * WATERCRAFT: A boat or other waterborne vehicle. + /// * PERSON: A person. + /// + public string Type; + } + +} diff --git a/yavscModel/Google/Api/EntityQuery.cs b/yavscModel/Google/Api/EntityQuery.cs new file mode 100644 index 00000000..551b372e --- /dev/null +++ b/yavscModel/Google/Api/EntityQuery.cs @@ -0,0 +1,45 @@ +// +// EntityQuery.cs +// +// Author: +// Paul Schneider +// +// 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 . + +using System; +using System.Web.Profile; +using Yavsc.Model.Google; +using System.Net; +using System.IO; +using System.Text; +using Newtonsoft.Json; + +namespace Yavsc.Model.Google.Api +{ + /// + /// Entity query. + /// + public class EntityQuery { + /// + /// The entity identifiers. + /// + public string [] EntityIds; + /// + /// The minimum identifier. + /// + public string MinId; + } +} diff --git a/yavscModel/Google/Api/GoogleHelpers.cs b/yavscModel/Google/Api/GoogleHelpers.cs new file mode 100644 index 00000000..6c67b0d6 --- /dev/null +++ b/yavscModel/Google/Api/GoogleHelpers.cs @@ -0,0 +1,136 @@ +// +// GoogleHelpers.cs +// +// Author: +// Paul Schneider +// +// Copyright (c) 2015 GNU GPL +// +// 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 . +using System; +using Yavsc.Model.Google; +using System.Web.Profile; +using System.Configuration; +using System.Web; +using Yavsc.Model.Calendar; +using Yavsc.Model.Circles; +using System.Collections.Generic; +using System.Web.Security; +using Yavsc.Model.Google.Api.Messaging; + +namespace Yavsc.Model.Google.Api +{ + /// + /// Google helpers. + /// + public static class GoogleHelpers + { + /// + /// Gets the events. + /// + /// The events. + /// Profile. + /// Mindate. + /// Maxdate. + public static CalendarEventList GetEvents(this ProfileBase profile, DateTime mindate, DateTime maxdate) + { + string gcalid = (string) profile.GetPropertyValue ("gcalid"); + if (string.IsNullOrWhiteSpace (gcalid)) + throw new ArgumentException ("NULL gcalid"); + CalendarApi c = new CalendarApi (); + string creds = OAuth2.GetFreshGoogleCredential (profile); + return c.GetCalendar (gcalid, mindate, maxdate, creds); + } + + /// + /// Gets the calendars. + /// + /// The calendars. + /// Profile. + public static CalendarList GetCalendars (this ProfileBase profile) + { + string cred = OAuth2.GetFreshGoogleCredential (profile); + CalendarApi c = new CalendarApi (); + return c.GetCalendars (cred); + } + + /// + /// Login the specified response, state and callBack. + /// + /// Response. + /// State. + /// Call back. + public static void Login(this HttpResponseBase response, string state, string callBack) + { + OAuth2 oa = new OAuth2 (callBack); + oa.Login (response, state); + } + /// + /// Cals the login. + /// + /// Response. + /// State. + /// Call back. + public static void CalLogin(this HttpResponseBase response, string state, string callBack) + { + OAuth2 oa = new OAuth2 (callBack); + oa.GetCalendarScope (response, state); + } + /// + /// Creates the O auth2. + /// + /// The O auth2. + /// Call back. + public static OAuth2 CreateOAuth2(string callBack) + { + return new OAuth2 (callBack); + } + + /// + /// Notifies the event. + /// + /// The event. + /// Evpub. + public static MessageWithPayloadResponse NotifyEvent(EventPub evpub) { + using (var r = + new SimpleJsonPostMethod,MessageWithPayloadResponse>( + "https://gcm-http.googleapis.com/gcm/send")) { + var users = Circle.Union (evpub.CircleIds); + var regids = new List (); + var to = new List (); + foreach (var u in users) { + var p = ProfileBase.Create (u); + if (p != null) { + var regid = p.GetPropertyValue("gregid"); + if (regid == null) { + var muser = Membership.GetUser (u); + to.Add (muser.Email); + } + else regids.Add ((string)regid); + } + } + if (regids.Count == 0) + throw new InvalidOperationException + ("No recipient where found for this circle list"); + + var msg = new MessageWithPayload () { + notification = new Notification() { title = evpub.Title, body = evpub.Description, icon = "event" }, + data = new YaEvent[] { (YaEvent)evpub }, registration_ids = regids.ToArray() }; + return r.Invoke (msg); + } + } + + } +} + diff --git a/yavscModel/Google/Api/MapTracks.cs b/yavscModel/Google/Api/MapTracks.cs new file mode 100644 index 00000000..1f060a3b --- /dev/null +++ b/yavscModel/Google/Api/MapTracks.cs @@ -0,0 +1,80 @@ +// +// Google.cs +// +// Author: +// Paul Schneider +// +// 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 . +using System; +using System.Web.Profile; +using Yavsc.Model.Google; +using System.Net; +using System.IO; +using System.Text; +using Newtonsoft.Json; + +namespace Yavsc.Model.Google.Api +{ + /// + /// Google Map tracks Api client. + /// + public class MapTracks:ApiClient { + + /// + /// The google map tracks path (uri of the service). + /// + protected static string googleMapTracksPath = "https://www.googleapis.com/tracks/v1/"; + // entities/[create|list|delete] + // collections/[list|create|[add|remove]entities|delete] + // crumbs/[record|getrecent|gethistory|report|summarize|getlocationinfo|delete + + + // entities/[create|list|delete] + // collections/[list|create|[add|remove]entities|delete] + // crumbs/[record|getrecent|gethistory|report|summarize|getlocationinfo|delete + + /// + /// Creates the entity. + /// + /// The entity. + /// Entities. + public static string [] CreateEntity( Entity[] entities ) { + string [] ans = null; + using (SimpleJsonPostMethod< Entity[] ,string []> wr = + new SimpleJsonPostMethod< Entity[] ,string[]> (googleMapTracksPath + "entities/create")) + { + ans = wr.Invoke (entities); + } + return ans; + } + + /// + /// Lists the entities. + /// + /// The entities. + /// Eq. + static Entity[] ListEntities (EntityQuery eq) + { + Entity [] ans = null; + using (SimpleJsonPostMethod wr = + new SimpleJsonPostMethod (googleMapTracksPath + "entities/create")) + { + ans = wr.Invoke (eq); + } + return ans; + } + } +} diff --git a/yavscModel/Google/Api/Messaging/MessageWithPayLoad.cs b/yavscModel/Google/Api/Messaging/MessageWithPayLoad.cs new file mode 100644 index 00000000..42f80f05 --- /dev/null +++ b/yavscModel/Google/Api/Messaging/MessageWithPayLoad.cs @@ -0,0 +1,98 @@ +// +// MessageWithPayLoad.cs +// +// Author: +// paul <> +// +// Copyright (c) 2015 paul +// +// 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 . +using System; +using System.Web.Mvc; + +namespace Yavsc.Model.Google.Api.Messaging +{ + // https://gcm-http.googleapis.com/gcm/send + /// + /// Message with payload. + /// + public class MessageWithPayload { + /// + /// To. + /// + public string to; + /// + /// The registration identifiers. + /// + public string [] registration_ids; + /// + /// The data. + /// + public T[] data ; + /// + /// The notification. + /// + public Notification notification; + /// + /// The collapse key. + /// + public string collapse_key; // in order to collapse ... + /// + /// The priority. + /// + public int priority; // between 0 and 10, 10 is the lowest! + /// + /// The content available. + /// + public bool content_available; + /// + /// The delay while idle. + /// + public bool delay_while_idle; + /// + /// The time to live. + /// + public int time_to_live; // seconds + /// + /// The name of the restricted package. + /// + public string restricted_package_name; + /// + /// The dry run. + /// + public bool dry_run; + /// + /// Validate the specified modelState. + /// + /// Model state. + public void Validate(ModelStateDictionary modelState) { + if (to==null && registration_ids == null) { + modelState.AddModelError ("to", "One of \"to\" or \"registration_ids\" parameters must be specified"); + modelState.AddModelError ("registration_ids", "*"); + modelState.AddModelError ("to", "*"); + } + if (notification == null && data == null) { + modelState.AddModelError ("notification", "At least one of \"notification\" or \"data\" parameters must be specified"); + modelState.AddModelError ("data", "*"); + } + if (notification != null) { + if (notification.icon == null) + modelState.AddModelError ("notification.icon", "please, specify an icon resoure name"); + if (notification.title == null) + modelState.AddModelError ("notification.title", "please, specify a title"); + } + } + } +} + diff --git a/yavscModel/Google/Api/Messaging/MessageWithPayloadResponse.cs b/yavscModel/Google/Api/Messaging/MessageWithPayloadResponse.cs new file mode 100644 index 00000000..67737b46 --- /dev/null +++ b/yavscModel/Google/Api/Messaging/MessageWithPayloadResponse.cs @@ -0,0 +1,71 @@ +// +// MessageWithPayloadResponse.cs +// +// Author: +// paul +// +// Copyright (c) 2015 paul +// +// 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 . + +using System; + +namespace Yavsc.Model.Google.Api.Messaging +{ + // https://gcm-http.googleapis.com/gcm/send + + /// + /// Message with payload response. + /// + public class MessageWithPayloadResponse { + /// + /// The multicast identifier. + /// + public int multicast_id; + /// + /// The success count. + /// + public int success; + /// + /// The failure count. + /// + public int failure; + /// + /// The canonical identifiers... ?!? + /// + public int canonical_ids; + /// + /// Detailled result. + /// + public class Result { + /// + /// The message identifier. + /// + public string message_id; + /// + /// The registration identifier. + /// + public string registration_id; + /// + /// The error. + /// + public string error; + } + + /// + /// The results. + /// + public Result [] results; + } +} diff --git a/yavscModel/Google/Api/Messaging/Notification.cs b/yavscModel/Google/Api/Messaging/Notification.cs new file mode 100644 index 00000000..77527f7b --- /dev/null +++ b/yavscModel/Google/Api/Messaging/Notification.cs @@ -0,0 +1,62 @@ +// +// Notification.cs +// +// Author: +// paul <> +// +// Copyright (c) 2015 paul +// +// 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 . + +using System; + +namespace Yavsc.Model.Google.Api.Messaging +{ + /// + /// Notification. + /// + public class Notification { + /// + /// The title. + /// + public string title; + /// + /// The body. + /// + public string body; + /// + /// The icon. + /// + public string icon; + /// + /// The sound. + /// + public string sound; + /// + /// The tag. + /// + public string tag; + /// + /// The color. + /// + public string color; + /// + /// The click action. + /// + public string click_action; + + } + // https://gcm-http.googleapis.com/gcm/send + +} diff --git a/yavscModel/Google/Api/OAuth2.cs b/yavscModel/Google/Api/OAuth2.cs new file mode 100644 index 00000000..4769df71 --- /dev/null +++ b/yavscModel/Google/Api/OAuth2.cs @@ -0,0 +1,249 @@ +// +// OAuth2.cs +// +// Author: +// Paul Schneider +// +// 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 . +using System; +using System.IO; +using System.Net; +using System.Text; +using Newtonsoft.Json; +using Yavsc.Model.Google; +using System.Web.Profile; +using System.Web; +using Yavsc.Model; +using System.Runtime.Serialization.Json; + +namespace Yavsc.Model.Google.Api +{ + + /// + /// Google O auth2 client. + /// + public class OAuth2 : ApiClient + { + /// + /// The URI used to get tokens. + /// + protected static string tokenUri = "https://accounts.google.com/o/oauth2/token"; + + /// + /// The URI used to get authorized to. + /// + protected static string authUri = "https://accounts.google.com/o/oauth2/auth"; + + /// + /// Gets or sets the redirect URI sent to Google. + /// + /// The redirect URI. + public string RedirectUri { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// Redirect URI. + /// Client identifier. + /// Client secret. + public OAuth2 (string redirectUri) + { + RedirectUri = redirectUri; + } + + /// + /// Login with Google + /// by redirecting the specified http web response bresp, + /// and using the specified session state. + /// + /// Bresp. + /// State. + public void Login (HttpResponseBase bresp, string state) + { + string scope = string.Join ("%20", scopeOpenid); + + string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=false&approval_prompt=force", + CLIENT_ID, RedirectUri, scope, state); + GetAuthResponse (bresp, prms); + } + + /// + /// Gets the cal authorization. + /// + /// Bresp. + /// State. + public void GetCalendarScope (HttpResponseBase bresp, string state) + { + string prms = String.Format ("response_type=code&client_id={0}&redirect_uri={1}&scope={2}&state={3}&include_granted_scopes=true&access_type=offline&approval_prompt=force", + CLIENT_ID, RedirectUri, scopeCalendar, state); + GetAuthResponse (bresp, prms); + } + + private void GetAuthResponse (HttpResponseBase bresp, string prms) + { + string cont = null; + WebRequest wr = WebRequest.Create (authUri + "?" + prms); + wr.Method = "GET"; + using (WebResponse response = wr.GetResponse ()) { + string resQuery = response.ResponseUri.Query; + cont = HttpUtility.ParseQueryString (resQuery) ["continue"]; + response.Close (); + } + wr.Abort (); + bresp.Redirect (cont); + } + + /// + /// Builds the post data, from code given + /// by Google in the request parameters, + /// and using the given redirectUri. + /// This request body is used to get a new + /// OAuth2 token from Google, it is Url encoded. + /// + /// The post data from code. + /// Redirect URI. + /// Code. + public static string TokenPostDataFromCode (string redirectUri, string code) + { + string postdata = + string.Format ( + "redirect_uri={0}&client_id={1}&client_secret={2}&code={3}&grant_type=authorization_code", + HttpUtility.UrlEncode (redirectUri), + HttpUtility.UrlEncode (CLIENT_ID), + HttpUtility.UrlEncode (CLIENT_SECRET), + HttpUtility.UrlEncode (code)); + return postdata; + } + + /// + /// Gets the Google Authorization token. + /// + /// The token. + /// Rq. + /// State. + /// Message. + public AuthToken GetToken (HttpRequestBase rq, string state, out string message) + { + string code = OAuth2.GetCodeFromRequest (rq, state, out message); + string postdata = OAuth2.TokenPostDataFromCode (RedirectUri, code); + return GetTokenPosting (postdata); + } + + internal static AuthToken GetTokenPosting (string postdata) + { + HttpWebRequest webreq = WebRequest.CreateHttp (tokenUri); + webreq.Method = "POST"; + webreq.Accept = "application/json"; + webreq.ContentType = "application/x-www-form-urlencoded"; + Byte[] bytes = System.Text.Encoding.UTF8.GetBytes (postdata); + webreq.ContentLength = bytes.Length; + + using (Stream dataStream = webreq.GetRequestStream ()) { + dataStream.Write (bytes, 0, bytes.Length); + dataStream.Close (); + } + + AuthToken gat = null; + using (WebResponse response = webreq.GetResponse ()) { + using (Stream responseStream = response.GetResponseStream ()) { + gat = (AuthToken)new DataContractJsonSerializer (typeof(AuthToken)).ReadObject (responseStream); + responseStream.Close (); + } + response.Close (); + } + webreq.Abort (); + return gat; + } + + /// + /// Gets the code from the Google request. + /// + /// The code from request. + /// Rq. + /// State. + /// Message. + public static string GetCodeFromRequest (HttpRequestBase rq, string state, out string message) + { + message = ""; + string code = rq.Params ["code"]; + string error = rq.Params ["error"]; + if (error != null) { + message = + string.Format (LocalizedText.Google_error, + LocalizedText.ResourceManager.GetString (error)); + return null; + } + string rqstate = rq.Params ["state"]; + if (state != null && string.Compare (rqstate, state) != 0) { + message = + LocalizedText.ResourceManager.GetString ("invalid request state"); + return null; + } + return code; + } + + /// + /// Invalid O auth2 refresh token. + /// + public class InvalidOAuth2RefreshToken: Exception + { + /// + /// Initializes a new instance of the class. + /// + /// Message. + public InvalidOAuth2RefreshToken(string message):base(message) + { + } + /// + /// Initializes a new instance of the class. + /// + /// Message. + /// Inner exception. + public InvalidOAuth2RefreshToken(string message,Exception innerException):base(message,innerException) + { + } + } + + /// + /// Gets fresh google credential. + /// + /// The fresh google credential. + /// Pr. + public static string GetFreshGoogleCredential (ProfileBase pr) + { + string token = (string)pr.GetPropertyValue ("gtoken"); + string token_type = (string) pr.GetPropertyValue ("gtokentype"); + DateTime token_exp = (DateTime) pr.GetPropertyValue ("gtokenexpir"); + if (token_exp < DateTime.Now) { + object ort = pr.GetPropertyValue ("grefreshtoken"); + if (ort is DBNull || string.IsNullOrWhiteSpace((string)ort)) { + throw new InvalidOAuth2RefreshToken ("Google"); + } + string refresh_token = ort as string; + AuthToken gat = OAuth2.GetTokenPosting ( + string.Format ("grant_type=refresh_token&client_id={0}&client_secret={1}&refresh_token={2}", + CLIENT_ID, CLIENT_SECRET, refresh_token)); + token = gat.access_token; + pr.SetPropertyValue ("gtoken", token); + pr.Save (); + // ASSERT gat.token_type == pr.GetPropertyValue("gtokentype") + } + return token_type + " " + token; + } + + } +} + diff --git a/yavscModel/Google/Api/PeopleApi.cs b/yavscModel/Google/Api/PeopleApi.cs new file mode 100644 index 00000000..aaecb3b8 --- /dev/null +++ b/yavscModel/Google/Api/PeopleApi.cs @@ -0,0 +1,67 @@ +// +// PeopleApi.cs +// +// Author: +// Paul Schneider +// +// Copyright (c) 2015 GNU GPL +// +// 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 . + +using System; +using System.IO; +using System.Net; +using System.Text; +using Newtonsoft.Json; +using Yavsc.Model.Google; +using System.Web.Profile; +using System.Web; +using Yavsc.Model; +using System.Runtime.Serialization.Json; + +namespace Yavsc.Model.Google.Api +{ + /// + /// Google People API. + /// + public class PeopleApi: ApiClient + { + private static string getPeopleUri = "https://www.googleapis.com/plus/v1/people"; + + /// + /// Gets the People object associated to the given Google Access Token + /// + /// The me. + /// The Google Access Token object class. + public static People GetMe (AuthToken gat) + { + People me; + DataContractJsonSerializer ppser = new DataContractJsonSerializer (typeof(People)); + HttpWebRequest webreppro = WebRequest.CreateHttp (getPeopleUri + "/me"); + webreppro.ContentType = "application/http"; + webreppro.Headers.Add (HttpRequestHeader.Authorization, gat.token_type + " " + gat.access_token); + webreppro.Method = "GET"; + using (WebResponse proresp = webreppro.GetResponse ()) { + using (Stream prresponseStream = proresp.GetResponseStream ()) { + me = (People)ppser.ReadObject (prresponseStream); + prresponseStream.Close (); + } + proresp.Close (); + } + webreppro.Abort (); + return me; + } + } + +} diff --git a/yavscModel/SimpleJsonPostMethod.cs b/yavscModel/SimpleJsonPostMethod.cs new file mode 100644 index 00000000..691144a0 --- /dev/null +++ b/yavscModel/SimpleJsonPostMethod.cs @@ -0,0 +1,108 @@ +// +// PostJson.cs +// +// Author: +// Paul Schneider +// +// 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 . +using System; +using System.Net; +using System.Text; +using System.IO; +using System.Runtime.Serialization.Json; + +namespace Yavsc.Model +{ + /// + /// Simple json post method. + /// + public class SimpleJsonPostMethod: IDisposable + { + internal HttpWebRequest request = null; + internal HttpWebRequest Request { get { return request; } } + + string CharSet { + get { return Request.TransferEncoding; } + set { Request.TransferEncoding=value;} + } + string Method { get { return Request.Method; } } + /// + /// Gets the path. + /// + /// The path. + public string Path { + get{ return Request.RequestUri.ToString(); } + } + /// + /// Sets the credential. + /// + /// Cred. + public void SetCredential(string cred) { + Request.Headers.Set(HttpRequestHeader.Authorization,cred); + } + + /// + /// Initializes a new instance of the Yavsc.Helpers.SimpleJsonPostMethod class. + /// + /// Path to method. + public SimpleJsonPostMethod (string pathToMethod) + { + // ASSERT Request == null + request = (HttpWebRequest) WebRequest.Create (pathToMethod); + + Request.Method = "POST"; + Request.Accept = "application/json"; + Request.ContentType = "application/json"; + Request.SendChunked = true; + Request.TransferEncoding = "UTF-8"; + } + /// + /// Invoke the specified query. + /// + /// Query. + public TAnswer Invoke(TQuery query) + { + + DataContractJsonSerializer serquery = new DataContractJsonSerializer (typeof(TQuery)); + DataContractJsonSerializer seransw = new DataContractJsonSerializer (typeof(TAnswer)); + + using (Stream streamQuery = request.GetRequestStream()) { + serquery.WriteObject (streamQuery, query); + } + + TAnswer ans = default (TAnswer); + using (WebResponse response = Request.GetResponse ()) { + using (Stream responseStream = response.GetResponseStream ()) { + ans = (TAnswer) seransw.ReadObject(responseStream); + } + response.Close(); + } + return ans; + } + + #region IDisposable implementation + + /// + /// Releases all resource used by the Yavsc.Helpers.SimpleJsonPostMethod object. + /// + public void Dispose () + { + if (Request != null) Request.Abort (); + } + #endregion + } +} + diff --git a/yavscModel/Skill/SkillRating.cs b/yavscModel/Skill/SkillRating.cs new file mode 100644 index 00000000..4c980ee6 --- /dev/null +++ b/yavscModel/Skill/SkillRating.cs @@ -0,0 +1,44 @@ +// +// SkillRating.cs +// +// Author: +// Paul Schneider +// +// Copyright (c) 2015 GNU GPL +// +// 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 . + +using System; + +namespace Yavsc.Model.Skill +{ + /// + /// Skill rating. + /// + public class SkillRating : IRating { + + /// + /// Gets or sets the skill identifier. + /// + /// The skill identifier. + public long Id { get;set ; } + + /// + /// Gets or sets the rate. + /// + /// The rate. + public int Rate { get; set; } + } + +}