public override void LogVersion(HtmlBlock o) { locker.EnterWriteLock(); try { VersionPath versionPath = new VersionPath(o, NextVersionId(o)); IOUtility.EnsureDirectoryExists(versionPath.PhysicalPath); var versionDataFile = Path.Combine(versionPath.PhysicalPath, DataFileName); HtmlBlockProvider provider = new HtmlBlockProvider(); IO.IOUtility.SaveStringToFile(versionDataFile, o.Body); } finally { locker.ExitWriteLock(); } }
public override void LogVersion(Page o) { locker.EnterWriteLock(); try { VersionPath versionPath = new VersionPath(o, NextVersionId(o)); IOUtility.EnsureDirectoryExists(versionPath.PhysicalPath); var versionDataFile = Path.Combine(versionPath.PhysicalPath, o.DataFileName); PageProvider provider = new PageProvider(); provider.Serialize(o, versionDataFile); } finally { locker.ExitWriteLock(); } }
public override void LogVersion(T o) { var locker = GetLock(); locker.EnterWriteLock(); try { VersionPath versionPath = new VersionPath(o, NextVersionId(o)); IOUtility.EnsureDirectoryExists(versionPath.PhysicalPath); var versionDataFile = Path.Combine(versionPath.PhysicalPath, Path.GetFileName(o.DataFile)); var versionTemplateFile = Path.Combine(versionPath.PhysicalPath, Path.GetFileName(o.TemplateFileName)); File.Copy(o.DataFile, versionDataFile); File.Copy(o.PhysicalTemplateFileName, versionTemplateFile); } finally { locker.ExitWriteLock(); } }
static public void Download(string url, string toFile, bool overwriteFile) { if ( !File.Exists(toFile) || overwriteFile ) { if (Path.GetFullPath(toFile) != toFile) { toFile = Path.GetFullPath(toFile); } Console.WriteLine("Downloading:"); Console.WriteLine(" " + url); Console.WriteLine("To:"); Console.WriteLine(" " + toFile); WebClient webClient = new WebClient(); webClient.Headers.Add("USER-AGENT", "csAnt"); webClient.Credentials = CredentialCache.DefaultCredentials; Console.WriteLine(" Please wait...(this may take some time)..."); IOUtility.EnsureDirectoryExists(Path.GetDirectoryName(toFile)); webClient.DownloadFile( url, toFile ); OutputSize(webClient); Console.WriteLine("Download complete."); Console.WriteLine(""); } }
/// <summary> /// Resizes the image. /// </summary> /// <param name="url">The URL.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="preserverAspectRatio">The preserver aspect ratio.保持比例</param> /// <param name="quality">The quality.</param> /// <returns></returns> public virtual ActionResult ResizeImage(string url, int width, int height, bool?preserverAspectRatio, int?quality) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException(url); } url = HttpUtility.UrlDecode(url); var index = url.IndexOf("?"); if (index != -1) { url = url.Substring(0, index); } var imageFullPath = Server.MapPath(url); preserverAspectRatio = preserverAspectRatio ?? true; quality = quality ?? 80; var cachingPath = GetCachingFilePath(imageFullPath, width, height, preserverAspectRatio.Value, quality.Value); if (!System.IO.File.Exists(cachingPath)) { lock (resizeImageLocker) { if (!System.IO.File.Exists(cachingPath)) { var dir = Path.GetDirectoryName(cachingPath); IOUtility.EnsureDirectoryExists(dir); var success = ImageTools.ResizeImage(imageFullPath, cachingPath, width, height, preserverAspectRatio.Value, quality.Value); if (!success) { cachingPath = imageFullPath; } } } } SetCache(HttpContext.Response, 2592000, "*"); return(File(cachingPath, IOUtility.MimeType(imageFullPath))); }
public IsolatedStorageFileStream OpenFile(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) { string fullPath = Path.Combine(this.storagePath, path); var dir = Path.GetDirectoryName(fullPath); if (mode == FileMode.Create || mode == FileMode.CreateNew || mode == FileMode.OpenOrCreate) { IOUtility.EnsureDirectoryExists(dir); } var storageFileStream = new IsolatedStorageFileStream(); storageFileStream.StorageFile = new IsolatedStorageFile(Path.GetFileName(path), path, this.Name); using (var fileStream = File.Open(fullPath, mode, access, share)) { var memoryStream = new MemoryStream(); fileStream.CopyTo(memoryStream); memoryStream.Position = 0; storageFileStream.Stream = memoryStream; } return(storageFileStream); }
/// <summary> /// Resizes the image. /// </summary> /// <param name="url">The URL.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> /// <param name="preserverAspectRatio">The preserver aspect ratio.保持比例</param> /// <param name="quality">The quality.</param> /// <returns></returns> public virtual ActionResult ResizeImage(string url, int width, int height, bool?preserverAspectRatio, int?quality) { if (string.IsNullOrEmpty(url)) { throw new ArgumentNullException(url); } if (!ImageTools.IsImageExtension(Path.GetExtension(url))) { throw new HttpException(403, ""); } url = HttpUtility.UrlDecode(url); var index = url.IndexOf("?"); if (index != -1) { url = url.Substring(0, index); } preserverAspectRatio = preserverAspectRatio ?? true; quality = quality ?? 80; if (url.StartsWith("http://") || url.StartsWith("https://")) { //now no image cache for azure blob var provider = Kooboo.CMS.Content.Persistence.Providers.DefaultProviderFactory.GetProvider <Kooboo.CMS.Content.Persistence.IMediaContentProvider>(); var mediaContent = new MediaContent() { VirtualPath = url }; var data = provider.GetContentStream(mediaContent); if (data != null) { using (var imageStream = new MemoryStream(data)) { var imageFormat = ImageTools.ConvertToImageFormat(Path.GetExtension(mediaContent.VirtualPath)); Stream outStream = new MemoryStream(); ImageTools.ResizeImage(imageStream, outStream, imageFormat, width, height, preserverAspectRatio.Value, quality.Value); outStream.Position = 0; return(File(outStream, IOUtility.MimeType(url))); } } else { return(null); } } else { var imageFullPath = Server.MapPath(url); var cachingPath = GetCachingFilePath(imageFullPath, width, height, preserverAspectRatio.Value, quality.Value); if (!System.IO.File.Exists(cachingPath)) { if (!System.IO.File.Exists(cachingPath)) { var dir = Path.GetDirectoryName(cachingPath); IOUtility.EnsureDirectoryExists(dir); var success = ImageTools.ResizeImage(imageFullPath, cachingPath, width, height, preserverAspectRatio.Value, quality.Value); if (!success) { cachingPath = imageFullPath; } } } SetCache(HttpContext.Response, 2592000, "*"); return(File(cachingPath, IOUtility.MimeType(imageFullPath))); } }
public void CreateDirectory(string dir) { var physicalPath = Path.Combine(this.storagePath, dir); IOUtility.EnsureDirectoryExists(physicalPath); }
public void Add(Theme item) { IOUtility.EnsureDirectoryExists(item.PhysicalPath); }