public static string GetFullUrlDest(string FolderSrc, string FolderDest, string FullPathSrc) { if (!FullPathSrc.StartsWith(FolderSrc)) { return(""); } string FullPathRest = FullPathSrc.Substring(FolderSrc.Length); if (FullPathRest.StartsWith("/")) { FullPathRest = FullPathRest.Substring(1); } string FullPathDest = CUrl.Combine(FolderDest, FullPathRest); return(FullPathDest); }
/// <summary> public static CFullPathFullUrl GetNumberedFullPathFullUrl(HttpContext ctx, string FullUrl) { CFullPathFullUrl PathUrl = new CFullPathFullUrl(); string FileName = CUrl.GetFileName(FullUrl); string UrlFolder = CUrl.GetParentDirectory(FullUrl); string FullPath = ctx.Server.MapPath(FullUrl); string FullPathNew = CPath.GetNumberedFullPath(FullPath); if (FullPath != FullPathNew) { FileName = Path.GetFileName(FullPathNew); FullUrl = Combine(UrlFolder, FileName); FullPath = FullPathNew; } PathUrl.FullUrl = FullUrl; PathUrl.FullPath = FullPath; return(PathUrl); }
private List <Tuple <string, string, CFtpInfoSync> > GetFullPathReferencingDest(string[] aFullPathReferencing) { List <Tuple <string, string, CFtpInfoSync> > tpFullPathDest = new List <Tuple <string, string, CFtpInfoSync> >(); foreach (string FullPath in aFullPathReferencing) { for (int i = 0; i < this._aRootFolderDest.Length; i++) { if (_DestType == DestTypes.FileSystem) { tpFullPathDest.Add(new Tuple <string, string, CFtpInfoSync>(FullPath, CPath.GetFullPathDest(this._RootFolderSrc, this._aRootFolderDest[i], FullPath), null)); } else { tpFullPathDest.Add(new Tuple <string, string, CFtpInfoSync>(FullPath, CUrl.GetFullUrlDest(this._RootFolderSrc, this._aRootFolderDest[i], FullPath), this._aFtpInfoDest[i])); } } } return(tpFullPathDest); }
private bool IsValidForSync(FileInfo fiSrc, FileInfo fiDest, bool IsFtp, out string FullPathSrcNewIs) { FullPathSrcNewIs = ""; bool IsFile = !CFile.GetIsFolder(fiSrc); bool IsValid = true; if (IsFile) { if (IsValid) { IsValid = IsValidExtension(fiSrc); } if (IsFtp) { if (_SyncType == SyncTypes.CompareTimeBetweenSrcAndDest) { throw new Exception(string.Format("SyncType:{0} disallowed in Ftp.", _SyncType)); } //숨김 속성인 경우 new FileStream 사용할 때 읽지 못함. if (IsValid) { IsValid = ((fiSrc.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden); } if (IsValid) { IsValid = (fiSrc.LastWriteTime > _DateTimeAfter); } } else { if (_SyncType == SyncTypes.CompareTimeBetweenSrcAndDest) { if (fiDest != null) { DateTime DateSrc = fiSrc.LastWriteTime; DateTime DateDest = fiDest.LastWriteTime; long SizeSrc = fiSrc.Length; long SizeDest = fiDest.Length; if (IsValid) { IsValid = ((DateSrc != DateDest) || (SizeSrc != SizeDest)); } } } else { if (IsValid) { IsValid = (fiSrc.LastWriteTime > _DateTimeAfter); } } } } else { if (IsValid) { IsValid = IsValidFolder(fiSrc); } } if (IsValid) { if (this._MinifyJs && (string.Compare(fiSrc.Extension, ".js", true) == 0)) { #if !DotNet35 string JsSource = CFile.GetTextInFile(fiSrc.FullName); Minifier mf = new Minifier(); string JsSourceMinified = mf.MinifyJavaScript(JsSource); FullPathSrcNewIs = CFile.GetTempFileName(fiSrc.Extension); CFile.WriteTextToFile(FullPathSrcNewIs, JsSourceMinified); #else throw new Exception(".Net 3.5 does not support Minifier."); #endif } if ((this._aJsFullPathRefered != null) && (this._aJsFullPathRefered.Length > 0)) { if (CArray.IndexOf(this._aJsFullPathRefered, fiSrc.FullName, true) != -1) { List <Tuple <string, string, CFtpInfoSync> > tpPathAndHtml = GetPathAndHtmlAndFtpInfoDest(this._aFullPathReferencingJs, fiSrc); foreach (Tuple <string, string, CFtpInfoSync> tp in tpPathAndHtml) { string FullPathDest = tp.Item1; string Html = tp.Item2; CFtpInfoSync FtpInfo = tp.Item3; if (_DestType == DestTypes.FileSystem) { CFile.WriteTextToFile(FullPathDest, Html); } else { string TmpFullPath = CFile.GetTempFileName(); CFile.WriteTextToFile(TmpFullPath, Html); CFtp2 Ftp = new CFtp2(FtpInfo); Ftp.UploadFile(TmpFullPath, FullPathDest); } } } else if (CArray.IndexOf(this._aFullPathReferencingJs, fiSrc.FullName, true) != -1) { for (int i = 0; i < this._aRootFolderDest.Length; i++) { string HtmlSrc = CFile.GetTextInFile(fiSrc.FullName); string HtmlDest = ""; string FullPathDest = ""; string FullUrlDest = ""; if (_DestType == DestTypes.FileSystem) { FullPathDest = CPath.GetFullPathDest(this._RootFolderSrc, this._aRootFolderDest[i], fiSrc.FullName); HtmlDest = CFile.GetTextInFile(FullPathDest); } else { CFtp2 Ftp = new CFtp2(this._aFtpInfoDest[i]); FullUrlDest = CUrl.GetFullUrlDest(this._RootFolderSrc, this._aRootFolderDest[i], fiSrc.FullName); HtmlDest = Ftp.GetText(FullUrlDest); } string HtmlSrcNew = GetHtmlVersionReplaced(HtmlSrc, HtmlDest); if (string.IsNullOrEmpty(HtmlSrcNew)) { continue; } FullPathSrcNewIs = CFile.GetTempFileName(fiSrc.Extension); CFile.WriteTextToFile(FullPathSrcNewIs, HtmlSrcNew); } } } } return(IsValid); }
/// <summary> /// 설정된 조건에 따라 원본 폴더의 모든 파일을 대상 폴더에 복사함. /// </summary> public void CopyAll() { string FolderSrc = this._RootFolderSrc; if (_DestType == DestTypes.FileSystem) { List <string> aDirectoryChecked = new List <string>(); for (int i = 0, i2 = this._aRootFolderDest.Length; i < i2; i++) { if (this._aFullPathSrc != null) { for (int j = 0; j < this._aFullPathSrc.Length; j++) { string FullPathSrc = this._aFullPathSrc[j]; string FullPathDest = CPath.GetFullPathDest(FolderSrc, this._aRootFolderDest[i], FullPathSrc); string FolderDest = CPath.GetFolderName(FullPathDest); if (aDirectoryChecked.IndexOf(FolderDest) == -1) { if (!Directory.Exists(FolderDest)) { Directory.CreateDirectory(FolderDest); } aDirectoryChecked.Add(FolderDest); } _File.CopyFile(FullPathSrc, FullPathDest); } } else { _File.CopyDirectory(FolderSrc, this._aRootFolderDest[i]); } } } else if (_DestType == DestTypes.Ftp) { for (int i = 0, i2 = this._aFtpInfoDest.Length; i < i2; i++) { CFtp2 FtpCur = _aFtp[i]; CFtpInfoSync InfoSync = (CFtpInfoSync)FtpCur.Info; List <string> aDirectoryChecked = new List <string>(); if (this._aFullPathSrc != null) { for (int j = 0; j < this._aFullPathSrc.Length; j++) { string FullPathSrc = this._aFullPathSrc[j]; string FullPathDest = CUrl.GetFullUrlDest(FolderSrc, InfoSync.Folder, FullPathSrc); string FolderDest = CUrl.GetDirectoryName(FullPathDest); if (aDirectoryChecked.IndexOf(FolderDest) == -1) { if (!FtpCur.DirectoryExists(FolderDest)) { FtpCur.CreateDirectory(FolderDest); } aDirectoryChecked.Add(FolderDest); } FtpCur.UploadFile(FullPathSrc, FullPathDest); } } else { FtpCur.UploadDirectory(FolderSrc, InfoSync.Folder); } } } }
/// <summary> /// UrlParent가 '/good/manager/'이고 UrlChild가 '../../images/star.gif'인 경우 /// '/images/star.gif'를 리턴함. /// </summary> /// <param name="UrlParent"></param> /// <param name="UrlChild"></param> /// <returns></returns> public static string ConvertRelativeToAbsolute(string UrlParent, string UrlChild) { if (UrlChild.StartsWith("http://") || UrlChild.StartsWith("ftp://")) { return(UrlChild); } // http://www.site.com은 제거 bool IsError = false; Uri u = null; string Scheme = ""; string Authority = ""; try { u = new Uri(UrlParent, UriKind.Absolute); Scheme = u.Scheme; Authority = u.Authority; } catch (Exception) { IsError = true; } if (!IsError) { UrlParent = u.AbsolutePath; } List <string> aUrlParent = new List <string>(UrlParent.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)); List <string> aUrlChild = new List <string>(UrlChild.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries)); //파일은 경로에서 삭제 if (aUrlParent[aUrlParent.Count - 1].IndexOf('.') != -1) { aUrlParent.RemoveAt(aUrlParent.Count - 1); } if (UrlChild.StartsWith("/")) { aUrlParent.Clear(); } else { for (int i = 0; i < aUrlChild.Count; i++) { if (aUrlChild[i] == "..") { aUrlParent.RemoveAt(aUrlParent.Count - 1); aUrlChild.RemoveAt(0); i--; } } } foreach (string UrlChildCur in aUrlChild) { aUrlParent.Add(UrlChildCur); } string UrlNew = string.Join("/", aUrlParent.ToArray()); if (!string.IsNullOrEmpty(Authority)) { UrlNew = CUrl.Combine(Scheme + "//" + Authority, UrlNew); } return(UrlNew); }