internal static void ClearImageCache() { using (var isoStore = IsolatedStorageFile.GetUserStoreForApplication()) { if (isoStore.DirectoryExists("Images\\")) { IsoStoreUtil.DeleteFileFromFolder("Images\\*"); } } }
public string UploadImage(string filepath) { var url = "https://note.youdao.com/yws/open/resource/upload.json?oauth_token=" + _accessToken; var postData = new PostData(); // Read file data var data = IsoStoreUtil.ReadFileAsByte(filepath); var filename = FileUtils.GetFileName(filepath); postData.Params.Add(new PostDataParam(filename, data, filepath, PostDataParamType.File)); var requestResult = HttpUtils.SendPostRequestWithMultipart(url, _accessToken, postData); if (requestResult.OperateResult == OperateResultEnum.Fail) { throw new YoudaoNoteException(requestResult.Code, requestResult.ErrorMsg); } var jObject = JsonConvert.DeserializeObject(requestResult.Result, typeof(JObject)) as JObject; return(jObject != null ? jObject["url"].ToString() : string.Empty); }
void photoChooserTask_Completed(object sender, PhotoResult e) { if (e.TaskResult == TaskResult.OK) { var imageName = Path.Combine("Images", Path.GetFileName(e.OriginalFileName)); string imagePath = string.Empty; if (IsoStoreUtil.FileExists(imageName)) { imagePath = IsoStoreUtil.GetFileAbsolutePath(imageName); } else { var tempBuffer = new byte[e.ChosenPhoto.Length]; e.ChosenPhoto.Read(tempBuffer, 0, tempBuffer.Length); imagePath = IsoStoreUtil.SaveToIsoStore(imageName, tempBuffer); } _noteEntity.Content = rtbContent.InsertImage(imagePath); } rtbContent.SetFocus(); }
/// <summary> /// Download and save image to local. /// </summary> /// <param name="belongedNotePath">The path of belonged note.</param> /// <param name="imgNode">The image HtmlNode object.</param> /// <param name="imgRemoteUrl">The remote url of the image.</param> /// <param name="imgNameWithoutExt">The image name without extension.</param> /// <returns></returns> private string downloadAndSaveImageToLocal(string belongedNotePath, HtmlNode imgNode, string imgRemoteUrl, string imgNameWithoutExt) { Debug.WriteLine("Thread Id: " + Thread.CurrentThread.ManagedThreadId + " downloadAndSaveImageToLocal: " + imgRemoteUrl); var res = _api.DownloadAttach(imgRemoteUrl); var imgType = ImageUtil.GetImageType(res.Buffer); var localPath = "Images\\" + imgNameWithoutExt + "." + imgType; double width; if (imgNode.Attributes.Contains("width")) { if (Double.TryParse(imgNode.Attributes["width"].Value, out width)) { if (width > _screenWidth) { width = _screenWidth - 25; } } imgNode.Attributes["width"].Value = width.ToString(CultureInfo.InvariantCulture); } else { var actualSize = ImageUtil.GetImageSize(imgType, res.Buffer); width = actualSize.Width > _screenWidth ? _screenWidth - 25 : actualSize.Width; imgNode.Attributes.Add("width", width.ToString(CultureInfo.InvariantCulture)); } // Save to disk. var savePath = IsoStoreUtil.SaveToIsoStore(localPath, res.Buffer); // Save to db. var imageEntity = new ImageEntity(imgNameWithoutExt, imgType.ToString(), savePath, imgRemoteUrl, belongedNotePath); ImageDao.InsertIfNotExist(imageEntity); return(savePath); }
internal static long GetCacheSize() { return(IsoStoreUtil.GetFolderSize("Images\\*")); }
// 应用程序启动(例如,从“开始”菜单启动)时执行的代码 // 此代码在重新激活应用程序时不执行 private void Application_Launching(object sender, LaunchingEventArgs e) { SyncCore.GetInst().InitializeSyncCore(ConstantPool.AccessToken, ConstantPool.ScreenWidth); IsoStoreUtil.SaveFilesToIsoStore("style"); //Task.Factory.StartNew(ImageDao.DeleteNoRootImages); }
public static string TideHtml(string html) { if (string.IsNullOrEmpty(html)) { throw new ArgumentNullException("html"); } var doc = new HtmlDocument(); doc.LoadHtml(html); // remove all script and style tags. doc.DocumentNode.Descendants() .Where(n => n.Name == "script" || n.Name == "style") .ToList() .ForEach(n => n.Remove()); // remove all class and style attributes. doc.DocumentNode.Descendants() .Where(n => n.Attributes.Contains("class") || n.Attributes.Contains("style")) .ToList() .ForEach(n => { if (n.Attributes.Contains("class")) { n.Attributes.Remove("class"); } if (n.Attributes.Contains("style")) { n.Attributes.Remove("style"); } }); var headTag = doc.DocumentNode.SelectSingleNode("//head"); if (null == headTag) { headTag = HtmlNode.CreateNode("<head></head>"); doc.DocumentNode.InsertBefore(headTag, doc.DocumentNode.FirstChild); } var viewportTag = doc.DocumentNode.SelectSingleNode("//meta[@name=\"viewport\"]"); if (null == viewportTag) { viewportTag = HtmlNode.CreateNode("<meta name=\"viewport\" content=\"user-scalable=no\" />"); headTag.AppendChild(viewportTag); } else { viewportTag.SetAttributeValue("content", "user-scalable=no"); } if (string.IsNullOrEmpty(StyleStr)) { StyleStr = IsoStoreUtil.ReadFileAsString("style/global.css"); } var styleNode = HtmlNode.CreateNode("<style type=\"text/css\">" + StyleStr + "</style>"); headTag.AppendChild(styleNode); return(doc.DocumentNode.InnerHtml); }