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

2021-05-12 07:28

阅读:668

标签:idt   image   wan   eid   一段   ted   file   bin   ffline   

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 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 calback)
    {
        if (isSuccess)
        {
            UploadEditedFileReturnJson uploadEditedFileReturnJson = JsonConvert.DeserializeObject(json);
            if (uploadEditedFileReturnJson.status == 0)
            {
                img.workId = uploadEditedFileReturnJson.data.workId;
                calback(img);
            }
        }
        else
        {
            //:上传失败
        }
    }

 

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

标签:idt   image   wan   eid   一段   ted   file   bin   ffline   

原文地址:http://www.cnblogs.com/qianxinxu/p/7577525.html


评论


亲,登录后才可以留言!