Esempio n. 1
0
        public async Task <IActionResult> Upload()
        {
            // receive file from phone via cache
            //Logger.ConsoleRouterLog("Post", "/api/file/upload", DateTime.Now);

            var f = await Request.ReadFormAsync();

            var  files = new List <IFormFile>(f.Files);
            long size  = files.Sum(f => f.Length);

            foreach (var file in files)
            {
                //set file path
                string filePath;
                Console.WriteLine($"Now processing {file.FileName}");
                if (file.FileName != null)
                {
                    //filePath = "./SAVE/" + file.FileName;
                    filePath = config.StorePath + file.FileName;
                }
                else
                {
                    //filePath = "./SAVE/TEMP.unknow";
                    filePath = config.StorePath + "TEMP.unknow";
                }
                //set buffer_size
                int buffer_size = Utils.GetBufferSize(size);
                //Console.WriteLine($"buffer_size:{buffer_size}");

                if (file.Length > 0)
                {
                    using var stream = System.IO.File.Create(filePath);
                    using (var bar = new MProgressBar(file.FileName)) {
                        //add progress Bar

                        byte[] buffer = new byte[buffer_size];
                        int    times = (int)(size / buffer_size) + 1, cnt = 0;
                        var    formFileStream = file.OpenReadStream();

                        //read formfile and write into target
                        int readCnt = formFileStream.Read(buffer, 0, buffer_size);
                        while (readCnt == buffer_size)
                        {
                            stream.Write(buffer, 0, buffer_size);

                            readCnt = formFileStream.Read(buffer, 0, buffer_size);
                            bar.Tick(100 * cnt++ / times);
                        }
                        stream.Write(buffer, 0, readCnt);
                        bar.Tick(100);
                    }

                    Console.WriteLine($"Save file  in : {filePath}");
                }
            }
            return(Ok(new { count = files.Count, size, state = "success" }));
        }
Esempio n. 2
0
        public MapPage()
        {
            try
            {
                InitializeComponent();
                if (AlreadyLoaded)
                {
                    MProgressBar.IsVisible = false;
                }
                else
                {
//                    MMap.IsVisible = false;
                    Device.StartTimer(TimeSpan.FromSeconds(.5), () =>
                    {
                        if (!(MProgressBar.Progress < 1))
                        {
                            return(false);
                        }
                        Device.BeginInvokeOnMainThread(() =>
                                                       MProgressBar.ProgressTo(MProgressBar.Progress + 0.005, 500, Easing.Linear));
                        return(true);
                    });
                }
#if __ANDROID__
                NavigationPage.SetHasNavigationBar(this, false);
#endif
#if __IOS__
                StackLayout NavStack = new StackLayout()
                {
                    Children =
                    {
                        new Label()
                        {
                            Text = "Cycles"
                        }
                    }
                };
                NavigationPage.SetTitleView(this, NavStack);
#endif
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
//                Crashlytics.Crashlytics.LogException(Java.Lang.Throwable.FromException(ex));
            }

            BindingContext = this;

            var pin = new CustomPin
            {
                Type     = PinType.Place,
                PinType  = CustomPin.CustomType.Park,
                Position = new Position(6.672219, 3.161639),
                Label    = "Cycles Point @Cafe 2",
                Address  = "Cafeteria 2, Goodness Rd, Canaan Land, Ota",
                MarkerId = "P2"
            };
            var pin2 = new CustomPin
            {
                Type     = PinType.Place,
                PinType  = CustomPin.CustomType.Park,
                Position = new Position(6.67369, 3.15922),
                Label    = "Cycles Point @CST",
                Address  = "College of Science and Tech, CU, Canaan Land, Ota",
                MarkerId = "P3"
            };
            MMap.CustomPins = new List <CustomPin> {
                pin, pin2
            };
            MMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(LAGOS_LATITUDE, LAGOS_LONGITUDE), new Distance(15000d)));

//            MMap.Pins.Add(pin);
//            MMap.Pins.Add(pin2);
            MessagingCenter.Subscribe <MapPageRenderer>(this, "Scanner Opened", async(mainActivity) =>
            {
                var scanPage = new CustomBarcodeScanner();
                if (Application.Current.MainPage.Navigation.ModalStack.Count == 0)
                {
                    await Application.Current.MainPage.Navigation.PushModalAsync(scanPage);
                }
            });
            MessagingCenter.Subscribe <MainActivity>(this, "Close Scanner", async(sender) =>
            {
                if (Application.Current.MainPage.Navigation.ModalStack.Count > 0)
                {
                    await Application.Current.MainPage.Navigation.PopModalAsync();
                }
            });
            MessagingCenter.Subscribe <GraphicBarcodeTracker>(this, "Close Scanner", async(sender) =>
            {
                if (Application.Current.MainPage.Navigation.ModalStack.Count > 0)
                {
                    await Application.Current.MainPage.Navigation.PopModalAsync();
                }
            });
        }