public HttpResponse UploadRepair(UploadRepairRequest request) { return(Task.Run(async() => { request.ContentStream = await IoCContainer.Instance.Resolve <IDirectory>().OpenFile(request.xmlName, FileModeEnum.Open); return await ServiceAgent.RestFullServiceJsonRequest1(base.GetTargetUri(), ServiceConfig.UploadRepair, request.ContentStream); }).Result); }
public void saveRepair(string deviceid, string faultDesc, string imgUrls) { try { UploadRepairRequest request = new UploadRepairRequest(); XElement root = new XElement("Repair"); XElement Imgs = new XElement("Imgs"); var imgpaths = JsonConvert.DeserializeObject <List <string> >(imgUrls); request.imgs = new List <string>(); foreach (var imgpath in imgpaths) { using (var stream = IoCContainer.Instance.Resolve <IDirectory>().OpenFile1(imgpath, Common.BusinessModel.FileModeEnum.Open).Result) { byte[] arr = new byte[stream.Length]; stream.Read(arr, 0, arr.Length); var imgcontent = Convert.ToBase64String(arr); Imgs.Add(new XElement("Img", imgcontent)); request.imgs.Add(imgcontent); } } root.Add(new XElement("deviceid", deviceid)); root.Add(new XElement("faultDesc", faultDesc)); root.Add(new XElement("username", GlobalAccess.Instance.CurrentUserInfo.Email)); root.Add(new XElement("userid", GlobalAccess.Instance.CurrentUserInfo.FullName)); root.Add(Imgs); request.userid = GlobalAccess.Instance.CurrentUserInfo.FullName; request.username = GlobalAccess.Instance.CurrentUserInfo.Email; request.faultDesc = faultDesc; request.deviceid = deviceid; request.xmlName = Guid.NewGuid().ToString("N") + ".xml"; request.Content = System.Text.Encoding.UTF8.GetBytes(root.ToString()); SaveToLocal(request.xmlName, request.Content); var response = IoCContainer.Instance.Resolve <IDeliveryService>().UploadRepair(request); if (response.Content.Contains("操作成功")) { wvContent.LoadUrl("javascript:SubmitRepairResult('0')"); Toast.MakeText(this, "保存成功", ToastLength.Short).Show(); } else { Toast.MakeText(this, "保存出错,请重试", ToastLength.Short).Show(); } } catch (System.Exception ex) { Toast.MakeText(this, "保存出错,请重试" + ex.Message, ToastLength.Short).Show(); } }