示例#1
0
        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;
            }
        }
示例#2
0
 public static void DeletePackage(string name, string version)
 {
     HttpPkg.DeletePkg(name, version, (m) =>
     {
         FreshWebCollection();
     });
 }
示例#3
0
        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;
            }
        }
示例#4
0
        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);
            });
        }
示例#5
0
 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();
     });
 }
示例#6
0
        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);
        }
示例#7
0
 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);
        }
示例#9
0
        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));
        }
示例#10
0
 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();
     });
 }
示例#11
0
        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();
                }
            });
        }
示例#12
0
        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;
            }
        }
示例#14
0
        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;
            }
        }
示例#15
0
        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();
            });
        }
示例#16
0
 public abstract void SyncFun(HttpPkg pack);
示例#17
0
 public static void ForgetEmailPassword(ForgetPasswordInfo info)
 {
     HttpPkg.ForgePasswordRequestFormEmail(info.email, (model) => { });
 }
示例#18
0
 public override void AsyncFun(HttpPkg pack)
 {
     throw new NotImplementedException();
 }
示例#19
0
 public static void ChangeEmailPassword(ForgetPasswordInfo info)
 {
     HttpPkg.ForgePasswordFormEmail(info.email, info.newPsd, info.code, (model) => {
         ClearUserJson();
     });
 }
示例#20
0
 public override void AsyncFun(HttpPkg pack)
 {
 }
示例#21
0
        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);
                        });
                    }
                }
            });
        }