Ejemplo n.º 1
0
        public void TestRemoveAsyncEmptyFiles()
        {
            systemUnderTest = new HttpUploader(sourceOptions);

            var result = systemUnderTest.RemoveAsync(null).GetAwaiter().GetResult();

            Assert.True(result == null, "Unexpected Result");
        }
Ejemplo n.º 2
0
        public void TestUploadAsyncEmptyFiles()
        {
            systemUnderTest = new HttpUploader(sourceOptions);

            var result = systemUnderTest.UploadAsync(null).GetAwaiter().GetResult();

            Assert.True(result == null, "Result is not null");
        }
Ejemplo n.º 3
0
        public void TestConstructUrl(string source, string expected)
        {
            // init Test
            sourceOptions.SourceFolder = @"c:\Temp";

            systemUnderTest = new HttpUploader(sourceOptions);
            var result = systemUnderTest.ConstructUrl(source);

            Assert.Equal(expected, result.ToString());
        }
Ejemplo n.º 4
0
        public void TestUploadAsyncUrlNotFound()
        {
            sourceOptions.RepositoryUrl = "http://www.bing.de";
            systemUnderTest             = new HttpUploader(sourceOptions);
            var sourceFiles = Filehelper.GetFilePaths(sourceOptions.SourceFolder, out var resultMessage);

            var result = systemUnderTest.UploadAsync(sourceFiles).GetAwaiter().GetResult();

            Assert.Equal(Types.EExitCode.INVALID_PARAMS, result.Code);
        }
Ejemplo n.º 5
0
        private static void UploadByDFIS(object sender, UploadEventArgs args)
        {
            using (var ms = new MemoryStream())
            {
                args.UploadImage.Save(ms, ImageFormat.Jpeg);

                ms.Seek(0, SeekOrigin.Begin);

                HttpUploader.UploadFile(ms, args.FileName, UploadURL, FileGroup, args.MidFilepath, "", UserName, UploadMethod.Update);
            }
        }
Ejemplo n.º 6
0
        public void TestUploadAsyncSomeFiles()
        {
            // init Test
            systemUnderTest = new HttpUploader(sourceOptions);
            var sourceFiles = Filehelper.GetFilePaths(sourceOptions.SourceFolder, out var resultMessage);

            // perform action
            var result = systemUnderTest.UploadAsync(sourceFiles).GetAwaiter().GetResult();

            // check result
            Assert.True(result.Code == Types.EExitCode.UPLOAD_ERROR, "Unexpected Upload Success");
        }
Ejemplo n.º 7
0
        public void TestRemoveAsyncSomeFiles()
        {
            // init Test
            systemUnderTest = new HttpUploader(sourceOptions);

            var sourceFiles = Filehelper.GetFilePaths(sourceOptions.SourceFolder, out var resultMessage);

            // perform action
            var result = systemUnderTest.RemoveAsync(sourceFiles).GetAwaiter().GetResult();

            // check result
            Assert.True(result == null, "Unexpected Result");
        }
Ejemplo n.º 8
0
        public static void OriginalImageSaveByDFIS(string fileIdentity, string destFileName)
        {
            if (string.IsNullOrWhiteSpace(fileIdentity) || string.IsNullOrWhiteSpace(destFileName))
            {
                return;
            }
            var result = FileUploadManager.FileExists(fileIdentity);

            if (result)
            {
                var filePath = FileUploadManager.GetFilePhysicalFullPath(fileIdentity);
                CreateStandardImages(fileIdentity, destFileName);

                HttpUploader.UploadFile(UploadURL, FileGroup, "Original", filePath, destFileName, "", UserName, UploadMethod.Update);
            }
        }
Ejemplo n.º 9
0
        public override FileUploadProcessResult ProcessUploadedFile(object sender, FileUploadCompletedEventArgs args)
        {
            if (!args.UploadParams.ContainsKey("DFISUploadURL"))
            {
                throw new ArgumentException("Please Specify UploadParams[\"DFISUploadURL\"] ");
            }

            if (!args.UploadParams.ContainsKey("DFISGroup"))
            {
                throw new ArgumentException("Please Specify UploadParams[\"DFISGroup\"] ");
            }

            if (!args.UploadParams.ContainsKey("DFISType"))
            {
                throw new ArgumentException("Please Specify UploadParams[\"DFISType\"] ");
            }

            if (!args.UploadParams.ContainsKey("DFISUserName"))
            {
                throw new ArgumentException("Please Specify UploadParams[\"DFISUserName\"] ");
            }

            if (!args.UploadParams.ContainsKey("DFISFileName"))
            {
                throw new ArgumentException("Please Specify UploadParams[\"DFISFileName\"] ");
            }

            string url       = args.UploadParams["DFISUploadURL"];
            string fileGroup = args.UploadParams["DFISGroup"];
            string fileType  = args.UploadParams["DFISType"];
            string userName  = args.UploadParams["DFISUserName"];
            string fileName  = args.UploadParams["DFISFileName"];

            using (FileStream fileStream = new FileStream(args.FilePath, FileMode.Open, FileAccess.Read, FileShare.Read))
            {
                HttpUploader.UploadFile(fileStream, fileName, url, fileGroup, fileType, string.Empty, userName, UploadMethod.Update);
            }


            FileUploadProcessResult result = new FileUploadProcessResult();

            result.Status      = Newegg.Oversea.Silverlight.FileUploadHandler.ProcessStatus.Success;
            result.ResponseMsg = fileName;
            return(result);
        }
Ejemplo n.º 10
0
        public static void UploadStatusWithPic(SocialType type, string status, string imgPath, Action <bool, Exception> action)
        {
            HttpUploader uploader = new HttpUploader();

            uploader.parameters = new Dictionary <string, object>();
            switch (type)
            {
            case SocialType.Weibo:
            {
                uploader.url = "https://api.weibo.com/2/statuses/upload.json";
                uploader.parameters.Add("status", status);
                uploader.parameters.Add("access_token", WeiboAccessToken.Token);
            }
            break;

            case SocialType.Tencent:
            {
                uploader.url = "https://open.t.qq.com/api/t/add_pic";
                uploader.parameters.Add("oauth_consumer_key", Client.ClientId);
                uploader.parameters.Add("access_token", TencentAccessToken.Token);
                uploader.parameters.Add("openid", TencentAccessToken.OpenId);
                uploader.parameters.Add("oauth_version", "2.a");
                uploader.parameters.Add("scope", "all");
                uploader.parameters.Add("format", "json");
                uploader.parameters.Add("content", status);
            }
            break;

            case SocialType.Renren:
            {
                uploader.url = "http://api.renren.com/restserver.do";
                uploader.parameters.Add("method", "photos.upload");
                uploader.parameters.Add("v", "1.0");
                uploader.parameters.Add("access_token", RenrenAccessToken.Token);
                uploader.parameters.Add("format", "JSON");
                uploader.parameters.Add("caption", status);
                uploader.parameters.Add("aid", "0");

                List <APIParameter> para = new List <APIParameter>();
                para.Add(new APIParameter("access_token", RenrenAccessToken.Token));
                para.Add(new APIParameter("method", "photos.upload"));
                para.Add(new APIParameter("v", "1.0"));
                para.Add(new APIParameter("format", "JSON"));
                para.Add(new APIParameter("caption", status));
                para.Add(new APIParameter("aid", "0"));
                uploader.parameters.Add("sig", CalSig(para));
            }
            break;

            case SocialType.QZone:
            {
                uploader.url = "https://graph.qq.com/share/add_share";
                uploader.parameters.Add("title", status);
                uploader.parameters.Add("title", "");
                uploader.parameters.Add("title", "");
                uploader.parameters.Add("title", "");
            }
            break;

            case SocialType.Douban:
                break;

            case SocialType.Net:
                break;

            case SocialType.Sohu:
                break;

            default:
                break;
            }

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (store.FileExists(imgPath))
                {
                    using (var stream = store.OpenFile(imgPath, FileMode.Open, FileAccess.Read))
                    {
                        byte[] bytes = new byte[stream.Length];
                        stream.Read(bytes, 0, bytes.Length);
                        if (type == SocialType.Renren)
                        {
                            uploader.parameters.Add("upload", bytes);
                        }
                        else
                        {
                            uploader.parameters.Add("pic", bytes);
                        }
                    }
                }
                else
                {
                    //image do not exists
                    //TODO
                }
            }
            uploader.Submit();
            uploader.UploadCompleted += (e1, e2) =>
            {
                if (e1 is string && e1.ToString() == "ok")
                {
                    action(true, null);
                }
                else
                {
                    action(false, e1 as Exception);
                }
            };
        }
Ejemplo n.º 11
0
 /// <summary>
 /// 支持多服务器保存
 /// </summary>
 /// <param name="filePath"></param>
 /// <param name="newFileName"></param>
 /// <param name="fileSize"></param>
 /// <param name="userName"></param>
 public static void Save(string filePath, string newFileName, string fileSize, string userName)
 {
     //重命名文件
     HttpUploader.UploadFile(UploadURL, SaveTitle, fileSize, filePath, newFileName, "", userName, UploadMethod.Update);
 }
Ejemplo n.º 12
0
        /// <summary>
        ///  send with params  share 56 video
        ///  created by lulee007 2014-6-13
        /// </summary>
        /// <param name="type"></param>
        /// <param name="status"></param>
        /// <param name="imgPath"></param>
        /// <param name="action"></param>
        public static void UploadStatusWithParams(SocialType type, Dictionary <string, object> parameters, Action <bool, Exception> action)
        {
            HttpUploader uploader = new HttpUploader();

            uploader.parameters = new Dictionary <string, object>();
            switch (type)
            {
            case SocialType.Weibo:
            {
                uploader.url = "https://api.weibo.com/2/statuses/upload.json";
                object status = null;
                parameters.TryGetValue("status", out status);
                uploader.parameters.Add("status", status.ToString());
                uploader.parameters.Add("access_token", WeiboAccessToken.Token);
            }
            break;

            case SocialType.Tencent:
            {
                uploader.url = "https://open.t.qq.com/api/t/add_pic";
                uploader.parameters.Add("oauth_consumer_key", Client.ClientId);
                uploader.parameters.Add("access_token", TencentAccessToken.Token);
                uploader.parameters.Add("openid", TencentAccessToken.OpenId);
                uploader.parameters.Add("oauth_version", "2.a");
                uploader.parameters.Add("scope", "all");
                uploader.parameters.Add("format", "json");
                object status = null;
                parameters.TryGetValue("status", out status);
                uploader.parameters.Add("content", status.ToString());
            }
            break;

            case SocialType.Renren:
            {
                parameters.Add("access_token", RenrenAccessToken.Token);
                string paramString = "?";
                foreach (string key in parameters.Keys)
                {
                    paramString += key + "=" + parameters[key].ToString() + "&";
                }

                uploader.url = string.Format("https://api.renren.com/v2/share/url/put" + paramString);
            }
            break;

            case SocialType.QZone:
            {
                uploader.url = "https://graph.qq.com/share/add_share";
                object status = null;
                parameters.TryGetValue("status", out status);
                uploader.parameters.Add("title", status.ToString());
                uploader.parameters.Add("oauth_consumer_key", Client.ClientId);
                uploader.parameters.Add("format", "json");
            }
            break;

            case SocialType.Twitter:
            {
                uploader.url = "https://api.twitter.com/1.1/statuses/update_with_media";
                object status = null;
                parameters.TryGetValue("status", out status);
                uploader.parameters.Add("status", status.ToString());
            }
            break;

            case SocialType.Facebook:
            {
            }
            break;

            case SocialType.Douban:
                break;

            case SocialType.Net:
                break;

            case SocialType.Sohu:
                break;

            case SocialType.WeChatCircle:
                break;

            case SocialType.WeChatMsg:
                break;

            default:
                break;
            }

            using (var store = IsolatedStorageFile.GetUserStoreForApplication())
            {
                object img     = null;
                string imgPath = "";

                if (parameters.TryGetValue("imgPath", out img))
                {
                    imgPath = img.ToString();
                }
                if (store.FileExists(imgPath))
                {
                    using (var stream = store.OpenFile(imgPath, FileMode.Open, FileAccess.Read))
                    {
                        byte[] bytes = new byte[stream.Length];
                        stream.Read(bytes, 0, bytes.Length);
                        if (type == SocialType.Renren)
                        {
                            uploader.parameters.Add("upload", bytes);
                        }
                        else
                        {
                            uploader.parameters.Add("pic", bytes);
                        }
                    }
                }
                else
                {
                    //image do not exists
                    //TODO
                }
            }
            uploader.Submit();
            uploader.UploadCompleted += (e1, e2) =>
            {
                if (e1 is string && e1.ToString() == "ok")
                {
                    action(true, null);
                }
                else
                {
                    action(false, e1 as Exception);
                }
            };
        }