public bool TryParse(string lineInput, out SessionTalk sessionTalk) { sessionTalk = null; if (string.IsNullOrWhiteSpace(lineInput)) { return(false); } var parsedLine = ParseLine(lineInput); // Looks like lighting but not quite right if (parsedLine.IsLightning && !string.Equals(parsedLine.Value, LightningTalkToken, StringComparison.InvariantCultureIgnoreCase)) { // evil return(false); } int minutes = 0; // Number in another galaxy ? if (!parsedLine.IsLightning && !int.TryParse(parsedLine.Value, out minutes)) // invalid number { //evil return(false); } sessionTalk = new SessionTalk(parsedLine.Name, parsedLine.IsLightning ? LightningTalkMinutes : minutes); return(true); }
/// <summary> /// Evil data checker /// </summary> /// <param name="line"></param> /// <param name="talk"></param> /// <returns></returns> private bool IsValidLine(string line, out SessionTalk talk) { talk = null; if (string.IsNullOrWhiteSpace(line)) { return(false); } var parsedLine = ParseLine(line); // Parsing magic here // Looks like lighting but not quite right if (parsedLine.IsLightning && !string.Equals(parsedLine.Value, LightningTalkToken, StringComparison.InvariantCultureIgnoreCase)) { // evil return(false); } int minutes = 0; // Number in another galaxy ? if (!parsedLine.IsLightning && !int.TryParse(parsedLine.Value, out minutes)) // invalid number { //evil return(false); } talk = MapParsedTalkToSessionTalk(parsedLine, minutes); return(true); // Yay }
/// <summary> /// WEBAPP and WEBAPI are in a different AAD APP /// Use this method if this app is protected by ADD-Application: CalcEnterpriseClient /// Authenticate to the API by using a service principal aka AAD App (with Delegate Permissions to /// CalcEnterpriseAPI) /// </summary> /// <returns></returns> public ActionResult Index() { string _ClientID = "<CalcEnterpriseClient AAD CLientID>"; // CalcEnterpriseClient - Client ID string _ClientSecret = "<CalcEnterpriseClient AAD App Secret/Key>"; // CalcEnterpriseClient - Client Secret string _Ressource = "<CalcEnterpriseAPI AAD CLientID>"; // CalcEnterpriseAPI - Client ID to be used if we call from middle tier! /* * https://azure.microsoft.com/en-us/documentation/articles/app-service-api-dotnet-service-principal-auth/ * ida:ClientId and ida:Resource are different values for this tutorial because you're using separate Azure AD * applications for the middle tier and data tier. If you were using a single Azure AD application for the calling * API app and the protected API app, you would use the same value in both ida:ClientId and ida:Resource */ string _Authority = "https://login.microsoftonline.com/<yourTenantName>.onmicrosoft.com"; SessionTalk[] contacts = null; var clientCredential = new ClientCredential(_ClientID, _ClientSecret); Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext context = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(_Authority, false); AuthenticationResult authenticationResult = context.AcquireToken( _Ressource, clientCredential); using (HttpClient client = new HttpClient()) { client.BaseAddress = new Uri(C_BASE_SERVICE_URI); client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", C_CALC_API_SUBSCRIPTION_KEY); client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(authenticationResult.AccessTokenType, authenticationResult.AccessToken); string path = C_SERVICE_PATH; try { var json = client.GetStringAsync(path).Result; contacts = JsonConvert.DeserializeObject <SessionTalk[]>(json); } catch (Exception ed) { contacts = new SessionTalk[] { new SessionTalk() { Title = ed.ToString() } }; } } return(View(contacts)); }
public void RemoveTalklFromAfternoonSession(SessionTalk talk) { AfternoonSession.RemoveTalk(talk); }
public void RemoveTalklFromMorningSession(SessionTalk talk) { MorningSession.RemoveTalk(talk); }
public bool TryAddTalkToAfternoonSession(SessionTalk talk) { return(AfternoonSession.TryAddTalk(talk)); }
public bool TryAddTalkToMorningSession(SessionTalk talk) { return(MorningSession.TryAddTalk(talk)); }