private async void HandleBarcodeScanAddItem(HttpListenerRequest req, HttpListenerResponse res, Dictionary <string, string> args) { var p = req.ParseBody(args); res.AsText("Thanks!"); string barcodeData = args["data"]; /*FileStream fs = new FileStream("test.jpeg", FileMode.OpenOrCreate); * fs.Write(new byte[] { 0xFF, 0xD8 }); * p["barcode_bmp"].Value.CopyTo(fs); * fs.Close();*/ var ms = new MemoryStream(); ms.Write(new byte[] { 0xFF, 0xD8 }); p["barcode_bmp"].Value.CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); Model.BarcodeBitmap = new Bitmap(ms); ms.Close(); barcodeData = barcodeData.Replace('\u001e', '\u241E').Replace('\u001d', '\u241D'); Model.BarcodeData = await DKClient.GetBarcodeData(barcodeData); var partDetails = await DKClient.GetPartDetails(Model.BarcodeData.DigiKeyPartNumber); }
private async void HandleBarcodeScanAddItem(HttpListenerRequest req, HttpListenerResponse res, Dictionary <string, string> args) { var p = req.ParseBody(args); string barcodeData = args["data"]; FileStream fs = new FileStream("test.jpeg", FileMode.OpenOrCreate); fs.Write(new byte[] { 0xFF, 0xD8 }); p["barcode_bmp"].Value.CopyTo(fs); fs.Close(); using (var ms = new MemoryStream()) { ms.Write(new byte[] { 0xFF, 0xD8 }); p["barcode_bmp"].Value.CopyTo(ms); ms.Seek(0, SeekOrigin.Begin); Dispatcher.UIThread.Post(() => { this.Get <Image>("barcodeImage").Source = new Bitmap(ms); }); } //var barcodeResp = await DKClient.GetBarcodeData(barcodeData); res.AsText("Thanks!"); }
private async void HandleOAuthCallback(HttpListenerRequest req, HttpListenerResponse res, Dictionary <string, string> args) { string code = req.QueryString["code"]; var tokensResp = await DKClient.GetTokens(code); Console.WriteLine(tokensResp); res.AsText($"Your tokens: {tokensResp}"); }
private static void TransferMethodResult(object result, HttpListenerResponse res) { if (result is string s) { res.AsText(s); } //ToDo: check for View else { res.AsJson(result); } }
private void SaveFile(HttpListenerRequest req, HttpListenerResponse res, Dictionary <string, string> args) { var files = req.ParseBody(args); //save files foreach (var f in files.Values) { try { using (var file = new FileStream( $"{Config.AppSettings.Settings["currentSavePath"].Value}/{f.FileName}", FileMode.CreateNew, FileAccess.Write)) { f.Value.CopyTo(file); res.AsText( $"Copied {Convert.ToString(f.FileName)} to the {Config.AppSettings.Settings["currentSavePath"].Value} folder."); file.Dispose(); file.Close(); } } catch (Exception ex) { if (ex.HResult == -2147024816) { var path = getFileName(f.FileName, Config.AppSettings.Settings["currentSavePath"].Value, 0); using (var file = new FileStream(path, FileMode.CreateNew, FileAccess.Write)) { f.Value.CopyTo(file); res.AsText( $"Copied {Convert.ToString(f.FileName)} to the {Config.AppSettings.Settings["currentSavePath"].Value} folder."); file.Dispose(); file.Close(); } } } } }
public static void AsJson(this HttpListenerResponse response, string txt) { response.AsText(txt, "application/json"); }