Exemplo n.º 1
0
 /// <summary>
 /// 从指定的对象还原为此类型的实例。
 /// </summary>
 /// <param name="obj">从其还原对象的数据。</param>
 /// <returns>一个 <see cref="FileUploadResult"/> 实例。</returns>
 /// <exception cref="System.NotSupportedException">当无法反序列化对象时引发的异常。</exception>
 public static FileUploadResult ConvertFrom(object obj)
 {
     Thinksea.Net.FileUploader_WinFormDemo.FileUploadResult fileUploadResult = obj as Thinksea.Net.FileUploader_WinFormDemo.FileUploadResult;
     if (fileUploadResult == null)
     {
         /*
          * if (obj is Newtonsoft.Json.Linq.JObject) //如果是 Newtonsoft.Json.Linq.JObject 对象。
          * {
          *  Newtonsoft.Json.Linq.JObject jobj = (Newtonsoft.Json.Linq.JObject)obj;
          *  fileUploadResult = jobj.ToObject<Thinksea.Net.FileUploader_WinFormDemo.FileUploadResult>();
          * }
          * else
          */
         if (obj is System.Text.Json.JsonElement) //如果是 System.Text.Json.JsonElement 对象。
         {
             System.Text.Json.JsonElement jobj = (System.Text.Json.JsonElement)obj;
             fileUploadResult = System.Text.Json.JsonSerializer.Deserialize <Thinksea.Net.FileUploader_WinFormDemo.FileUploadResult>(jobj);
         }
         else
         {
             throw new System.NotSupportedException("无法将指定的数据还原为“" + typeof(Thinksea.Net.FileUploader_WinFormDemo.FileUploadResult).FullName + "”类型或从其集成的子类型的对象实例。");
         }
     }
     return(fileUploadResult);
 }
Exemplo n.º 2
0
        private void uploadFileRaw_UploadCompleted(object sender, UploadCompletedEventArgs e)
        {
            this.uploadFileRaw.Hide();
            this.btnUploadRaw.Show();
            string file = this.openFileDialog1.FileName;
            string ext  = System.IO.Path.GetExtension(file).ToLower();

            Thinksea.Net.FileUploader_WinFormDemo.FileUploadResult data = Thinksea.Net.FileUploader_WinFormDemo.FileUploadResult.ConvertFrom(e.ResultData);
            string fileSavePath = data.SavePath;

            this.lFileSize_Raw.Text = Thinksea.General.ConvertToFileSize(data.FileLength);
            this.lFormats.Text      = ext;
            if (data.IsFastUpload)
            {
                MessageBox.Show(this, "秒传完成!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }