/*-------------------------------------------------------------------------
 * 功能描述：UrlFileKeyParse
 * 作者：xulisong
 * 创建时间： 2019/4/28 10:26:25
 * 版本号：v1.0
 *  -------------------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FirmHttpDao;
using Newtonsoft.Json;
using SAGA.DotNetUtils.Data;

namespace Com.FirmLib.UI
{
    public class UrlFileKeyParse
    {
        /// <summary>
        /// 创建文件key
        /// </summary>
        /// <param name="urlFile"></param>
        /// <returns></returns>
        public static string CreatKey(UrlFile urlFile)
        {
            if (urlFile == null)
                return string.Empty;
            return JsonConvert.SerializeObject(urlFile);
        }
        /// <summary>
        /// 解析文件key
        /// </summary>
        /// <param name="urlKey"></param>
        /// <returns></returns>
        public static UrlFile ParseKey(string urlKey)
        {
            UrlFile urlFile = null;
            try
            {
                urlFile = JsonConvert.DeserializeObject<UrlFile>(urlKey);
            }
            catch (Exception)
            {
            }
            if (urlFile == null)
            {
                urlFile = new UrlFile();
                urlFile.FileType = "image";
                urlFile.Key = urlKey;
                urlFile.SystemId = BllHttpSetting.Instance.Default.SystemId;
            }
            return urlFile;
        }
        /// <summary>
        /// 创建UrlFile文件
        /// </summary>
        /// <param name="fileKey"></param>
        /// <returns></returns>
        public static UrlFile CreateImageUrlFile(string fileKey)
        {
            UrlFile urlFile = new UrlFile();
            urlFile.FileType = "image";
            urlFile.Key = fileKey;
            urlFile.SystemId = BllHttpSetting.Instance.Default.SystemId;
            return urlFile;
        }
    }
}
