This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class SlowPageRelationRepository | |
{ | |
private static readonly SlowPageDatabaseHandler PageDatabaseHandler = new SlowPageDatabaseHandler(); | |
public static ICollection<Page> GetPagesRelatedTo(int page, string language) | |
{ | |
return PageDatabaseHandler.GetRelatedPages(page, language); | |
} | |
public static CategorizedPageCollection GetCategorizedPagesRelatedTo(int page, string language) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
foreach(var relatedPage in SlowPageRelationRepository.GetPagesRelatedTo(this.PageId, "en"") | |
{ | |
// ... | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import evdev | |
from evdev import * | |
from azure.storage.queue import QueueService, QueueMessageFormat | |
import threading | |
import time | |
from queue import * | |
import datetime | |
# responsible for uploading the barcodes to the azure storage queue. | |
class BarcodeUploader: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task Run(string message, TraceWriter log) | |
{ | |
log.Info($"Processing incoming barcode: {message}"); | |
var incoming = IncomingBarcode.FromMessage(message); | |
var httpClient = await CreateKolonialHttpClientAsync(); | |
var kolonialProduct = await GetKolonialProductAsync(httpClient, incoming.Barcode); | |
if(kolonialProduct == null) | |
log.Warning($"Product with barcode {incoming.Barcode} is not available at Kolonial."); | |
else | |
await AddProductToCartAsync (httpClient, kolonialProduct, log); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<HttpClient> CreateKolonialHttpClientAsync(){ | |
var httpClient = new HttpClient(); | |
// The kolonial API requires a client token and a user agent (supplied by kolonial) to work | |
httpClient.DefaultRequestHeaders.Add("X-Client-Token", ConfigurationManager.AppSettings["KolonialToken"]); | |
httpClient.DefaultRequestHeaders.Add("User-Agent", ConfigurationManager.AppSettings["KolonialUserAgent"]); | |
// Modifying the cart requires a valid, active session | |
string sessionId = await GetSessionIdAsync(httpClient); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<KolonialProduct> GetKolonialProductAsync(HttpClient client, string barcode) | |
{ | |
var httpResult = await client.GetAsync(ConfigurationManager.AppSettings["GetKolonialProductUri"] + "&barcode=" + barcode); | |
if (httpResult.IsSuccessStatusCode) | |
{ | |
var json = await httpResult.Content.ReadAsStringAsync(); | |
if (json != null) | |
return JsonConvert.DeserializeObject<KolonialProduct>(json); | |
} | |
return null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task AddProductToCartAsync(HttpClient httpClient, KolonialProduct kolonialProduct, TraceWriter log) | |
{ | |
var productsJson = JsonConvert.SerializeObject( | |
new { items = new []{ new { product_id = kolonialProduct.Id, quantity = 1 } }}); | |
log.Info($"Updating Kolonial with {productsJson}"); | |
var response = await httpClient.PostAsync( | |
"https://kolonial.no/api/v1/cart/items/", | |
new StringContent(productsJson, Encoding.UTF8, "application/json")); | |
response.EnsureSuccessStatusCode(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "Newtonsoft.Json" | |
using System; | |
using System.Configuration; | |
using Newtonsoft.Json; | |
using System.Net; | |
// These are the (interesting parts) of the models returned from the kolonial API. | |
// The actual JSON returned contains more properties, but I see no reason to bother the deserializer | |
// with more than what we actually need. | |
public class KolonialSearchResponse { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r "SendGrid" | |
using System.Net; | |
using SendGrid.Helpers.Mail; | |
public static HttpResponseMessage Run(HttpRequestMessage req, TraceWriter log, out Mail message) | |
{ | |
log.Info("C# HTTP trigger function processed a request."); | |
// parse query parameter | |
string name = req.GetQueryNameValuePairs() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Threading; | |
using Xunit; | |
namespace Xunit.ContextPoC | |
{ | |
public class UnitTest1 : IClassFixture<Context> | |
{ | |
public UnitTest1(Context ctx) | |
{ |
OlderNewer