Ejemplo n.º 1
0
        private void UploadFile(string filepath, int flag)
        {
            var    fi       = new System.IO.FileInfo(filepath);
            string filename = fi.Name;

            MetroUIExtender.Progress("正在上传文件......", "请稍等......", true,
                                     (controller) =>
            {
                controller.Canceled += (ss, ee) =>
                {
                    controller.CloseAsync();
                };
                controller.Closed += (ss, ee) =>
                {
                    if (!controller.IsCanceled)
                    {
                        //显示图片
                        var fs      = System.IO.File.OpenRead(filepath);
                        var decoder = BitmapDecoder.Create(fs, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
                        switch (flag)
                        {
                        case 1:
                            imageFirst.Source = decoder.Frames[0];
                            break;

                        case 2:
                            imageSecond.Source = decoder.Frames[0];
                            break;

                        case 3:
                            imageThird.Source = decoder.Frames[0];
                            break;
                        }
                    }
                };
            },
                                     (controller) =>
            {
                var data    = System.IO.File.ReadAllBytes(filepath);
                var service = new Service.PhotoImageService();
                service.OnUploadCompleted += (file) =>
                {
                    if (null != current)
                    {
                        switch (flag)
                        {
                        case 1:
                            current.FirstPhoto = file;
                            break;

                        case 2:
                            current.SecondPhoto = file;
                            break;

                        case 3:
                            current.ThirdPhoto = file;
                            break;
                        }
                    }
                    controller.CloseAsync();
                };
                service.Upload(data, filename, (exp) =>
                {
                    controller.SetMessage(exp.Message);
                    controller.SetCancelable(true);
                });
            });
        }
        private void ChangeLogo(string filepath, Camera camera)
        {
            if (null == camera)
            {
                return;
            }

            var    fi       = new System.IO.FileInfo(filepath);
            string filename = fi.Name;

            MetroUIExtender.Progress("正在上传文件......", "请稍等......", true,
                                     (controller) =>
            {
                controller.Canceled += (ss, ee) =>
                {
                    controller.CloseAsync();
                };
                controller.Closed += (ss, ee) =>
                {
                    if (!controller.IsCanceled)
                    {
                        CameraUI ui = null;
                        foreach (var v in cameraList)
                        {
                            if (v.Camera.ID == camera.ID)
                            {
                                ui = v;
                                break;
                            }
                        }
                        if (ui != null)
                        {
                            ui.ChangeLogo(camera.Logo);
                        }
                    }
                };
            },
                                     (controller) =>
            {
                var data    = System.IO.File.ReadAllBytes(filepath);
                var service = new Service.PhotoImageService();
                service.OnUploadCompleted += (file) =>
                {
                    //在设备中更改数据
                    if (file != null)
                    {
                        camera.Logo                     = file;
                        camera.PhotoImageID             = file.ID;
                        var serviceC                    = new Service.CameraService();
                        serviceC.OnChangeLogoCompleted += () => {
                            controller.CloseAsync();
                        };
                        serviceC.ChangeLogo(camera, (exp) => {
                            controller.SetMessage(exp.Message);
                            controller.SetCancelable(true);
                        });
                    }
                    else
                    {
                        controller.CloseAsync();
                    }
                };
                service.Upload(data, filename, (exp) =>
                {
                    controller.SetMessage(exp.Message);
                    controller.SetCancelable(true);
                });
            });
        }