Exemplo n.º 1
0
        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!");
        }
Exemplo n.º 2
0
        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);
        }
Exemplo n.º 3
0
        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();
                        }
                    }
                }
            }
        }
Exemplo n.º 4
0
 /// <summary>
 /// Parses body of the request including form and multi-part form data.
 /// </summary>
 /// <param name="request">HTTP request.</param>
 /// <param name="args">Key-value pairs populated by the form data by this function.</param>
 /// <returns>Name-file pair collection.</returns>
 public static Dictionary <string, HttpFile> ParseBody(this HttpListenerRequest request, Dictionary <string, string> args)
 {
     return(request.ParseBody(args, (n, fn, ct) => new MemoryStream()));
 }