public override async void AsyncFun(HttpPkg pack) { if (pack == null) { throw new Exception("要发送的http结构包为null"); } HttpWebRequest req = PrepareHttpWebRequest(pack); byte[] buffer = GetContentBytes(pack.Content, pack.EncodingName); try { // 有要提交的数据时通过Post方法提交,需要添加没有需要提交的数据时的处理 using (Stream s = await req.GetRequestStreamAsync()) { await s.WriteAsync(buffer, 0, buffer.Length); } using (HttpWebResponse response = await req.GetResponseAsync() as HttpWebResponse) { OnResponseCallback(await req.GetResponseAsync() as HttpWebResponse, pack.ResponseCallback); } } catch (Exception e) { throw e; } }
public static void DeletePackage(string name, string version) { HttpPkg.DeletePkg(name, version, (m) => { FreshWebCollection(); }); }
public override void SyncFun(HttpPkg pack) { HttpWebRequest req; byte[] buffer = GetUserBytes(pack); // 设置Http头 PrepareHttpHead(ref mHttpRequest, pack.Method, pack.ContentType, pack.AcceptType); try { // 有要提交的数据时通过Post方法提交,需要添加没有需要提交的数据时的处理 using (Stream s = mHttpRequest.GetRequestStream()) { s.Write(buffer, 0, buffer.Length); } HttpWebResponse response = mHttpRequest.GetResponse() as HttpWebResponse; if (pack.ResponseCallback != null) { pack.ResponseCallback(response.GetResponseStream(), response.StatusCode); } response.Close(); } catch (Exception e) { throw e; } }
internal static void UpdatePakage(string name) { string path = string.Format("{0}/{1}_{2}.unitypackage", pkgPath, name, "_lasted"); HttpPkg.DownloadPkg(name, null, path, () => { AssetDatabase.ImportPackage(path, true); }); }
public static void Signup(RegisterInfo info) { HttpPkg.SignupFormEmail(info.nick_name, info.email, info.password, (model) => { WriteUserJson(info.email, model.data.token, info.nick_name); LoginWithToken(); }); }
private HttpWebRequest PrepareHttpWebRequest(HttpPkg pkg) { HttpWebRequest req = WebRequest.Create(pkg.Url) as HttpWebRequest; req.Method = pkg.Method; req.ContentType = pkg.ContentType; req.Accept = pkg.AcceptType; return(req); }
public static void TryLogin(LoginInfo info) { window.multyDrawersInfo.login = false; HttpPkg.LoginFormEmail(info.email, info.password, (model) => { window.multyDrawersInfo.login = true; WriteUserJson(info.email, model.data.token, model.data.nick_name); FreshWebCollection(); }); }
private HttpWebRequest GetHttpRequest(HttpPkg pkg) { string content = pkg.Content; if (!string.IsNullOrEmpty(content)) { content = string.Format("{0}?{1}", pkg.Url, pkg.Content); } return(WebRequest.Create(content) as HttpWebRequest); }
private byte[] GetUserBytes(HttpPkg pkg) { if (pkg == null) { throw new Exception("自定义Http包结构对象为null"); } Encoding encoding = Encoding.GetEncoding(pkg.EncodingName); int len = encoding.GetByteCount(pkg.Content); mHttpRequest = WebRequest.Create(pkg.Url) as HttpWebRequest; return(encoding.GetBytes(pkg.Content)); }
public static void LoginWithToken() { window.multyDrawersInfo.login = false; HttpPkg.CheckToken( token , (model) => { window.multyDrawersInfo.login = true; WriteUserJson(model.data.email, model.data.token, model.data.nick_name); FreshWebCollection(); }); }
public static void InstallPackage(string name, string version) { string path = string.Format("{0}/{1}_{2}.unitypackage", pkgPath, name, version); HttpPkg.DownloadPkg(name, version, path, () => { AssetDatabase.ImportPackage(path, true); window.multyDrawersInfo.FreshInPorject(); if (onPackagesChange != null) { onPackagesChange(); } }); }
private HttpWebRequest GetRequestInstance(HttpPkg pack) { if (pack == null) { throw new Exception("自定义Http包结构对象为null"); } string content = pack.Content; if (!string.IsNullOrEmpty(content)) { content = string.Format("{0}?{1}", pack.Url, pack.Content); } HttpWebRequest req = WebRequest.Create(content) as HttpWebRequest; PrepareHttpHead(ref req, pack.Method, pack.ContentType, pack.AcceptType); return(req); }
public override async void AsyncFun(HttpPkg pack) { if (pack == null) { throw new Exception("自定义Http包结构对象为null"); } HttpWebRequest req = GetHttpRequest(pack); try { using (HttpWebResponse resp = await req.GetResponseAsync() as HttpWebResponse) { OnResponseCallback(resp, pack.ResponseCallback); } } catch (Exception e) { throw e; } }
public override void SyncFun(HttpPkg pack) { HttpWebRequest req = GetRequestInstance(pack); try { using (WebResponse resp = req.GetResponse()) { HttpWebResponse httpResp = resp as HttpWebResponse; if (pack.ResponseCallback != null) { // pack.ResponseCallback(httpResp.GetResponseStream()); } } } catch (Exception e) { throw e; } }
public static void UploadPackage(UploadInfo uploadInfo) { // MultyFrameworkEditorTool.CreateVersionJson(uploadInfo.assetPath, uploadInfo); AssetDatabase.ExportPackage(uploadInfo.assetPath, uploadInfo.name + ".unitypackage", ExportPackageOptions.Recurse); byte[] bytes = File.ReadAllBytes("Assets/../" + uploadInfo.name + ".unitypackage"); PkgInfo form = new PkgInfo() { unity_version = uploadInfo.unityVersion, author = uploadInfo.author, pkg_path = uploadInfo.assetPath, pkg_name = uploadInfo.name, version = uploadInfo.version, dependences = "", permissions = uploadInfo.isPublic ? PkgConstant.PKG_PERMISSIONS_PUBLIC : PkgConstant.PKG_PERMISSIONS_PRIVATE, help_url = uploadInfo.helpurl, describtion = uploadInfo.describtion, }; for (int i = 0; i < uploadInfo.dependences.Count; i++) { form.AddDependences(uploadInfo.dependences[i]); } HttpPkg.UploadPkg(form, bytes, (m) => { string source = "Assets/../" + uploadInfo.name + ".unitypackage"; string dest = Path.Combine(localPkgPath, uploadInfo.name + "_" + uploadInfo.version + ".unitypackage"); if (File.Exists(dest)) { File.Delete(dest); } File.Move(source, dest); FreshWebCollection(); }); }
public abstract void SyncFun(HttpPkg pack);
public static void ForgetEmailPassword(ForgetPasswordInfo info) { HttpPkg.ForgePasswordRequestFormEmail(info.email, (model) => { }); }
public override void AsyncFun(HttpPkg pack) { throw new NotImplementedException(); }
public static void ChangeEmailPassword(ForgetPasswordInfo info) { HttpPkg.ForgePasswordFormEmail(info.email, info.newPsd, info.code, (model) => { ClearUserJson(); }); }
public override void AsyncFun(HttpPkg pack) { }
private static void FreshWebCollection() { window.multyDrawersInfo.selfInfos.Clear(); window.multyDrawersInfo.infos.Clear(); HttpPkg.GetPkgInfoList((m) => { var datas = m.data; List <PkgInfoListModel.Data> localDatas = new List <PkgInfoListModel.Data>(); if (File.Exists(pkgjsonPath)) { localDatas = JsonUtility.FromJson <PkgInfoListModel>(File.ReadAllText(pkgjsonPath)).data; } File.WriteAllText(pkgjsonPath, JsonUtility.ToJson(m, true)); for (int i = 0; i < datas.Count; i++) { var _data = datas[i]; var _tmp = localDatas.Find((d) => { return(d.pkg_name == _data.pkg_name && d.last_time == _data.last_time && d.last_version == _data.last_version); }); localDatas.RemoveAll((d) => { return(d.pkg_name == _data.pkg_name); }); if (_tmp != null) { string path = Path.Combine(pkgversionjsonPath, _data.pkg_name + ".json"); WebCollectionInfo info = JsonUtility.FromJson <WebCollectionInfo>(File.ReadAllText(path)); TryFinish(info, localDatas, datas); } else { HttpPkg.GetPkgInfos(_data.pkg_name, (model) => { WebCollectionInfo info = new WebCollectionInfo() { name = model.data[0].pkg_name, author = model.data[0].author, }; WebCollectionInfo.Version[] versions = new WebCollectionInfo.Version[model.data.Count]; for (int j = 0; j < model.data.Count; j++) { versions[j] = new WebCollectionInfo.Version() { version = model.data[j].version, describtion = model.data[j].describtion, dependences = model.data[j].GetDependences().ToArray(), helpurl = model.data[j].help_url, unityVersion = model.data[j].unity_version, assetPath = model.data[j].pkg_path, }; } info.versions = versions; File.WriteAllText(Path.Combine(pkgversionjsonPath, info.name + ".json"), JsonUtility.ToJson(info, true)); TryFinish(info, localDatas, datas); }); } } }); }