Esempio n. 1
0
        static void AddNew()
        {
            string filePath = @"D:\KP097R_R206_18_1CONV.mdb";
            Stream file     = new FileStream(filePath, FileMode.Open);
            var    dict     = new DictionaryInfo
            {
                // Dictionary_id =,
                Category_id  = 1,
                Description  = "Тестовый словарь",
                FriendlyName = "Словарь1",
                FileName     = "KP097R_R206_18_1CONV.mdb",
                Action       = ActionEnum.AddDict,
                SenderLogin  = "******"
            };
            FileUploadClient client = new FileUploadClient();

            Thread.Sleep(1000);
            client.Open();
            try
            {
                client.Upload(dict, file);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
                Console.ReadKey();
            }
            client.Close();
        }
Esempio n. 2
0
        public void TestUploadAndDeleteImage()
        {
            string        filename = "IMG_0001.JPG";
            ImageResponse response = _uploadClient.Upload(filename);

            Assert.IsNotNull(response);
            Assert.IsFalse(string.IsNullOrEmpty(response.ImageUrl));
            Assert.IsTrue(File.Exists(response.ImageUrl));

            var update = new ImageUpdate
            {
                ImageUrl = response.ImageUrl
            };
            var delResponse = _client.Delete <ImageResponse>(update);

            Assert.IsNotNull(delResponse);
            Assert.IsFalse(File.Exists(response.ImageUrl));
        }
        /// <summary>
        /// 上传文件
        /// </summary>
        private void UpLoad()
        {
            var client = new FileUploadClient(_domainName, CurrentFile, 1);

            client.AppName = AppName;
            client.UploadProgressChanged += (se, args) =>
            {
                long t = args.TotalUploadedDataLength;                   // 已经上传的数据大小
                UploadProgressBar.Value = (float)t / CurrentFile.Length; // 上传数据的百分比
            };
            client.UploadErrorOccured += (se, args) =>
            {
                CurrentWindow.Alert(args.Exception.Message);
            };
            client.UploadCompleted += (se, args) =>
            {
                string imageUrl = System.IO.Path.Combine(UploadUrl, args.ServerFilePath);

                Dialog.ResultArgs.DialogResult = DialogResultType.OK;
                Dialog.ResultArgs.Data         = new { ImageUrl = imageUrl, ImageName = string.IsNullOrEmpty(txtUpLoadFile.Text) ? txtSelectFile.Text : txtUpLoadFile.Text };
                Dialog.Close(true);
            };
            client.Upload();
        }
Esempio n. 4
0
        /// <summary>
        /// 上传
        /// </summary>
        /// <param name="entity"></param>
        /// <param name="productResources"></param>
        /// <param name="count"></param>
        private void UpLoad(ProductResourcesVM entity, List <ProductResourceForNewegg> productResources, int count)
        {
            if (productResources == null)
            {
                productResources = new List <ProductResourceForNewegg>();
            }
            if (entity.FileUploadProcessStates != FileUploadProcessStates.WaitingToUpload)
            {
                entity.FileIdentity = "-1";
                return;
            }
            var client = new FileUploadClient(ConstValue.DomainName_IM, entity.File, 1);

            //if (entity.FileType == ResourcesType.Image)
            //{
            //    client.AppName = "product";
            //}
            //if (entity.FileType == ResourcesType.Image360)
            //{
            //    client.AppName = "ProductImage360";
            //}

            //if (entity.FileType == ResourcesType.Video)
            //{
            //    client.AppName = "ProductVideo";
            //}
            client.AppName = "product";
            entity.FileUploadProcessStates = FileUploadProcessStates.Uploading;
            client.UploadProgressChanged  += (se, args) =>
            {
                long t = args.TotalUploadedDataLength;                   // 已经上传的数据大小
                entity.UploadedPercentage = (float)t / entity.ImageSize; // 上传数据的百分比
            };
            client.UploadErrorOccured += (se, args) =>
            {
                entity.FileUploadProcessStates = FileUploadProcessStates.UploadFailed;
                entity.Remark = args.Exception.Message;
                CPApplication.Current.CurrentPage.Context.Window.Alert(args.Exception.Message);
                entity.FileIdentity = "-1";
            };
            client.UploadCompleted += (se, args) =>
            {
                entity.FileUploadProcessStates = FileUploadProcessStates.Uploaded;
                entity.Remark       = "";
                entity.FileIdentity = args.FileIdentity;
                var source = GetProductResource(entity);
                source.Resource.ResourceURL = args.ServerFilePath;
                source.IsNeedWatermark      = _productResources.IsNeedWatermark;
                productResources.Add(source);
                if (count == productResources.Count)
                {
                    _productResources.ResourceCollection.ForEach(v =>
                    {
                        if (v.FileUploadProcessStates == FileUploadProcessStates.Uploaded)
                        {
                            v.FileUploadProcessStates =
                                FileUploadProcessStates.Processing;
                        }
                    });
                    CreateProductResources(productResources);
                }
            };
            client.Upload();
        }