Exemplo n.º 1
0
        private async Task <string> CreateAssetObjForFile(AssetFileModel file, StreamWriter loger)
        {
            if (file == null)
            {
                return("");
            }
            string apiname = SvrDataMan.GetApiNameByTypeName(file.Type);

            if (apiname == "")
            {
                loger.WriteLine($"{DateTime.Now}, CREATE, {file.Package}, {file.Type}, apiname is empty. skip create object");
                return("");
            }

            //update dependencies after all files uploaded.
            if (file.Dependencies?.Count > 0)
            {
                updateFileDependencies(file);
            }

            ApiResponseStr  res  = null;
            StaticMeshModel mesh = null;

            //create
            var obj = new StaticMeshModel(); //all assets has same structure. but use staticmesh for safety for staticmesh case.

            obj.name        = file.Name;
            obj.packageName = file.Package;

            obj.fileAssetId     = file.cookedfid;
            obj.unCookedAssetId = file.uncookedfid;
            obj.srcFileAssetId  = file.srcfid;
            obj.iconAssetId     = file.iconfid;
            obj.dependencies    = file.dependencies;
            obj.properties      = file.properties;
            obj.parameters      = file.properties;
            res = await api.PostAsync($"/{apiname}", obj);

            if (res.IsSuccess && string.IsNullOrEmpty(res.Content) == false)
            {
                ClientAssetModel resobj = Newtonsoft.Json.JsonConvert.DeserializeObject <ClientAssetModel>(res.Content);
                file.ObjId = resobj?.id;
                obj.id     = resobj?.id;
                loger.WriteLine($"{DateTime.Now}, CREATE, {file.Package}, {file.Type}, {file.ObjId}");
                cache.New(file.ObjId, file.Type, obj);
            }
            else
            {
                loger.WriteLine($"{DateTime.Now}, CREATE, {file.Package}, {file.Type}, create failed. {res.StatusCode}, {res.Content}");
            }
            mesh = obj as StaticMeshModel;
            return(res.IsSuccess ? "ok" : "failed " + res.StatusCode);
        }
Exemplo n.º 2
0
        private async Task <int> DeleteSelectedItems()
        {
            ProgressModel progress = new ProgressModel();

            BindProgressObj(progress);
            progress.Total = listFiles.SelectedItems.Count;

            UploadLoger loger = new UploadLoger();

            loger.BeginWrite();
            var api = Logic.BambooEditor.Instance.api;
            List <AssetFileModel> items = new List <AssetFileModel>();

            foreach (AssetFileModel item in listFiles.SelectedItems)
            {
                progress.CurPos++;
                items.Add(item);
                if (string.IsNullOrEmpty(item.ObjId))
                {
                    continue;
                }
                string apiname = SvrDataMan.GetApiNameByTypeName(item.Type);
                var    res     = await api.DeleteAsync($"/{apiname}/{item.ObjId}");

                string resstr = res.IsSuccess ? " ok" : res.StatusCode.ToString();
                progress.Status = item.ObjId + " " + resstr;
                loger.Write(item, "delete", resstr);
            }
            foreach (var item in items)
            {
                man.RemoveFile(item);
            }
            man.svrdataMan.SaveCache();

            progress.Status = "ok";
            loger.EndWrite();
            return((int)progress.Total);
        }
Exemplo n.º 3
0
        private async Task <string> UpdateAssetObjForFile(AssetFileModel file, string assetObjid, StreamWriter loger)
        {
            if (file == null)
            {
                return("");
            }
            string apiname = SvrDataMan.GetApiNameByTypeName(file.Type);

            if (apiname == "")
            {
                loger.WriteLine($"{DateTime.Now}, CREATE, {file.Package}, {file.Type}, apiname is empty. skip create object");
                return("");
            }

            //update dependencies after all files uploaded.
            if (file.Dependencies?.Count > 0)
            {
                updateFileDependencies(file);
            }

            ApiResponseStr  res  = null;
            StaticMeshModel mesh = null;

            var obj = cache.Parsed.GetById(assetObjid) as ClientAssetModel;

            if (obj == null)
            {
                return("");
            }
            mesh = obj as StaticMeshModel;
            if (string.IsNullOrEmpty(file.cookedfid) == false)
            {
                obj.fileAssetId = file.cookedfid;
            }
            if (string.IsNullOrEmpty(file.uncookedfid) == false)
            {
                obj.unCookedAssetId = file.uncookedfid;
            }
            if (string.IsNullOrEmpty(file.srcfid) == false)
            {
                obj.srcFileAssetId = file.srcfid;
            }
            if (string.IsNullOrEmpty(file.iconfid) == false)
            {
                obj.iconAssetId = file.iconfid;
            }
            obj.id           = assetObjid;
            obj.name         = file.Name;
            obj.dependencies = file.dependencies;
            obj.parameters   = file.properties;
            res = await api.PutAsync($"/{apiname}", obj); //现在的api版本,put 不需要id

            //res = await api.PutAsync($"/{apiname}/{assetObjid}", obj);
            file.ObjId = assetObjid;

            if (res.IsSuccess && string.IsNullOrEmpty(res.Content) == false)
            {
                loger.WriteLine($"{DateTime.Now}, UPDATE, {file.Package}, {file.Type}, {assetObjid}, OK");
                cache.Update(assetObjid, obj);
            }
            else
            {
                loger.WriteLine($"{DateTime.Now}, UPDATE, {file.Package}, {file.Type}, {assetObjid}, failed {res.StatusCode} {res.Content}");
            }
            return(res.IsSuccess ? "ok" : "failed " + res.StatusCode);
        }