• C# 中写得很不错的一段代码摘出来


    private void LikeMyworkEvent(EditedImg img, bool islike)  //点赞自己的作品
        {
            if (ApplicationModel.userInfo != null)
            {
                OffLineController.Instance.OffLine();
                return;
            }
            if(img.workId == null || img.workId == "")     //这个作品还没有自己的作品id,需要先上传
            {
                UploadUserEditedFileCo(img , image => { LikeMyworkEvent(image, islike);});
            }
            else
            {
                NetLoadcontroller.Instance.RequestUrlWidthMethodGet(
                ApplicationModel.HOST + "/image/like?uid=" + ApplicationModel.userInfo.Uid +
                         "&authorUid=" + ApplicationModel.userInfo.Uid + "&workId=" + img.workId + "&action=" + GetActionStrByBool(islike) + "&sessionId=" + ApplicationModel.userInfo.SessionId,
                            (json, isSuccess) => { LikeRequestCallback(json, isSuccess); }
                );
            }
        }
        public IEnumerator UploadUserEditedFileCo(EditedImg img, Action<EditedImg> calback)
        {
            yield return new WaitForSeconds(2f);
            //TODO:daiwancheng
            WWWForm postForm = GetPostFormByEditedImg(img);
            WWW upload = new WWW(ApplicationModel.HOST + "/image/saveWork", postForm);
            yield return upload;
            NetLoadcontroller.Instance.RequestUrlWidthMethodPost(
                    ApplicationModel.HOST + "/image/saveWork",
                    postForm,
                    (json, isSuccess) => { UploadUserEditedFileCallback(json, isSuccess, img, calback); }
                );
        }
     private WWWForm GetPostFormByEditedImg(EditedImg img)
        {
            WWWForm postForm = new WWWForm();
            postForm.AddField("imageId", img.imageId);
            postForm.AddBinaryData("clickPos", GetClickPosFromImg(img.imageId).EncodeToPNG(), img.imageId + "_pos");
            postForm.AddBinaryData("palette", GetPaletteFromImg(img.imageId).EncodeToPNG(), img.imageId + "_ed");
            postForm.AddField("deviceId", ApplicationModel.device_id);
            postForm.AddField("uid", ApplicationModel.userInfo.Uid);
            postForm.AddBinaryData("finalImg", GetTex2dFromImg(img.imageId).EncodeToPNG(), img.imageId);
            postForm.AddField("sessionId", ApplicationModel.userInfo.SessionId);
            return postForm;
        }
    private void UploadUserEditedFileCallback(string json, bool isSuccess, EditedImg img, Action<EditedImg> calback)
        {
            if (isSuccess)
            {
                UploadEditedFileReturnJson uploadEditedFileReturnJson = JsonConvert.DeserializeObject<UploadEditedFileReturnJson>(json);
                if (uploadEditedFileReturnJson.status == 0)
                {
                    img.workId = uploadEditedFileReturnJson.data.workId;
                    calback(img);
                }
            }
            else
            {
                //:上传失败
            }
        }
  • 相关阅读:
    2020/10/23-大族激光
    Windows权限维持总结
    了解蓝军--jsonhijack漏洞学习
    white-space、word-break、word-wrap傻傻分不清楚
    Vue其他指令(v-cloak和v-text,v-html,v-pre,v-once)
    Vue循环渲染(v-for)
    Vue条件渲染(v-if)
    Vue绑定事件监听器(v-on)
    Vue绑定数据和元素属性(v-bind)
    记录一下,破解idea
  • 原文地址:https://www.cnblogs.com/qianxinxu/p/7577525.html
Copyright © 2020-2023  润新知