public void SaveDataByProcToCache(string Key, object DataToSave) { string FullPathTemp = CFile.GetTempFileName(); if (this.mUseAdo) { Recordset RsToSave = DataToSave as Recordset; RsToSave.Save(FullPathTemp, PersistFormatEnum.adPersistXML); SaveToCacheRs(Key, FullPathTemp); } else { DataTable DtToSave = DataToSave as DataTable; DtToSave.TableName = "Content"; if (DtToSave.DataSet == null) { DtToSave.WriteXml(FullPathTemp, XmlWriteMode.WriteSchema); } else { DtToSave.DataSet.WriteXml(FullPathTemp, XmlWriteMode.WriteSchema); } SaveToCacheDt(Key, FullPathTemp); } }
private string GetFullPathCacheContent(string Key) { if (string.IsNullOrEmpty(this.mCacheFolder)) { throw new Exception("CacheFolder 값이 없습니다"); } string FullPathTemp = ""; if (this.mUseAdo) { string FullPathCache = GetFullPathCacheRs(Key); //Remove 메쏘드로 삭제하다 더 이상 행이 없으면 파일 자체가 삭제됨 if (!File.Exists(FullPathCache)) { return(""); } Recordset Rs = new Recordset(); Rs.Open(FullPathCache, Missing.Value, CursorTypeEnum.adOpenStatic, LockTypeEnum.adLockPessimistic, -1); string Criteria = "Key = '" + Key.Replace("'", "''") + "'"; Rs.Find(Criteria, 0, SearchDirectionEnum.adSearchForward, Missing.Value); if (Rs.EOF) { Rs.Close(); return(""); } FullPathTemp = CFile.GetTempFileName(); CAdo.GetFileFromField(Rs.Fields["Content"], FullPathTemp); } else { string FullPathCache = GetFullPathCacheDt(Key); //Remove 메쏘드로 삭제하다 더 이상 행이 없으면 파일 자체가 삭제됨 if (!File.Exists(FullPathCache)) { return(""); } DataTable dt = new DataTable(); dt.ReadXml(FullPathCache); string Criteria = "Key = '" + Key.Replace("'", "''") + "'"; DataRow[] adr = dt.Select(Criteria); if (adr.Length == 0) { dt = null; return(""); } DataRow dr = adr[0]; FullPathTemp = CFile.GetTempFileName(); CFile.WriteByteToFile(FullPathTemp, (byte[])dr["Content"]); } return(FullPathTemp); }
/// <summary> /// HTML을 임시파일에 저장하고, 그 파일을 Navigate해서 내용을 표시함. /// </summary> /// <remarks> /// 내용이 많으면서 IMG의 SRC 속성, A의 HREF 속성에 전체 경로를 가진 이메일의 내용을 표시할 때 유용함. /// </remarks> /// <param name="web">WebBrowser 컨트롤</param> /// <param name="Html">파일로 저장해서 보여질 HTML 내용</param> /// <example> /// 다음은 이메일의 내용을 표시합니다. /// <code> /// EmailBody = GetEmailBody(); /// CHtml.ShowHtmlByNavigate(webContent, EmailBody); /// </code> /// </example> public static void ShowHtmlByNavigate(WebBrowser web, string Html) { string TempFile = CFile.GetTempFileName(); TempFile = Path.GetDirectoryName(TempFile) + Path.GetFileNameWithoutExtension(TempFile) + ".htm"; CFile.WriteTextToFile(TempFile, Html); web.Navigate(TempFile); }
public static void Compile(CCscOptions Options) { string CodeFullPath = Options.CodeFullPath; if (!CCollection.IsNullOr0Count(Options.RegionNameAndValue)) { string Code = CFile.GetTextInFile(CodeFullPath); foreach (string Key in Options.RegionNameAndValue.AllKeys) { string Pattern = @"\#region\s" + Key + @"\s+(?<Value>.+)\n\s+\#endregion\s" + Key; Regex r = new Regex(Pattern, RegexOptions.Singleline | RegexOptions.IgnoreCase); Code = r.Replace(Code, Options.RegionNameAndValue[Key]); } CodeFullPath = CFile.GetTempFileName(".cs"); CFile.WriteTextToFile(CodeFullPath, Code); } string FullPathCsc = Path.Combine(System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), "csc.exe"); string Arguments = ""; if (!CCollection.IsNullOr0Count <string>(Options.ReferenceFullPathList)) { Arguments += " /reference:"; string FullPathList = ""; foreach (string FullPathCur in Options.ReferenceFullPathList) { FullPathList += ";\"" + FullPathCur + "\""; } FullPathList = FullPathList.Substring(1); Arguments += FullPathList; } if (!CCollection.IsNullOr0Count(Options.ResourceFullPathAndIdentifier)) { foreach (string FullPathCur in Options.ResourceFullPathAndIdentifier) { Arguments += @" /resource:""" + FullPathCur + @""""; string Identifier = Options.ResourceFullPathAndIdentifier[FullPathCur]; if (!string.IsNullOrEmpty(Identifier)) { Arguments += "," + Identifier; } } } Arguments += " /out:\"" + Options.OutFullPath + "\""; Arguments += " \"" + CodeFullPath + "\""; Process p = Process.Start("\"" + FullPathCsc + "\"", Arguments); }
/// <summary> /// FTP 서버의 텍스트 파일의 내용을 리턴함. /// </summary> /// <param name="sRemote">서버에 있는 텍스트 파일의 경로</param> /// <returns>텍스트 파일의 내용</returns> public string GetText(string sRemote) { string TempPathFile = CFile.GetTempFileName(); GetFile(TempPathFile, sRemote); StreamReader sr = new StreamReader(TempPathFile, Encoding.UTF8); string s = sr.ReadToEnd(); sr.Close(); return(s); }
public void SaveInternetFileToCache(string Url) { string FullPathTemp = CFile.GetTempFileName(); CNet Net = new CNet(); Net.DownloadFile(Url, FullPathTemp, true); if (this.mUseAdo) { SaveToCacheRs(Url, FullPathTemp); } else { SaveToCacheDt(Url, FullPathTemp); } }
private List <Tuple <string, string, CFtpInfoSync> > GetPathAndHtmlAndFtpInfoDest(string[] aFullPathReferencingJs, FileInfo fiSrc) { List <Tuple <string, string, CFtpInfoSync> > tpPathAndHtml = new List <Tuple <string, string, CFtpInfoSync> >(); if (aFullPathReferencingJs.Length == 0) { return(tpPathAndHtml); } List <Tuple <string, string, CFtpInfoSync> > tpFullPathReferencingDest = GetFullPathReferencingDest(aFullPathReferencingJs); if (tpFullPathReferencingDest.Count == 0) { return(tpPathAndHtml); } foreach (Tuple <string, string, CFtpInfoSync> kv in tpFullPathReferencingDest) { string FullPathSrc = kv.Item1; string FullPathDest = kv.Item2; CFtpInfoSync FtpInfo = kv.Item3; string Html = ""; if (_DestType == DestTypes.FileSystem) { if (!File.Exists(FullPathDest)) { continue; } Html = CFile.GetTextInFile(FullPathDest); } else if (_DestType == DestTypes.Ftp) { CFtp2 Ftp = new CFtp2(FtpInfo); if (!Ftp.FileExists(FullPathDest)) { continue; } string TmpFullPath = CFile.GetTempFileName(); Ftp.DownloadFile(TmpFullPath, FullPathDest); Html = CFile.GetTextInFile(TmpFullPath); } List <string> aHtmlNew = new List <string>(); string Pattern = string.Format(_PatternUrlSpecific, fiSrc.Name.Replace(".", "\\.")); Regex r = new Regex(Pattern, CRegex.Options.Compiled_Multiline_IgnoreCase_IgnorePatternWhitespace); bool IsFound = false; foreach (CMatchInfo mi in CRegex.GetMatchResult(r, Html)) { aHtmlNew.Add(mi.ValueBeforeMatch); Match m = mi.Match; if (m == null) { break; } string Url = m.Groups["Url"].Value; CQueryString qs = new CQueryString(Url); //Commented because v parameter can be setted to empty when referencing file uploaded alone. //When that situation, v parameter will get value of 1 again. //qs["v"] = (CFindRep.IfNotNumberThen0(qs["v"]) + 1).ToString(); qs["v"] = DateTime.Now.ToString(CConst.Format_yyyyMMddHHmmss); aHtmlNew.Add(m.Value.Replace(m.Groups["Url"].Value, qs.PathAndQuery)); IsFound = true; } if (IsFound) { string HtmlNew = string.Join("", aHtmlNew); tpPathAndHtml.Add(new Tuple <string, string, CFtpInfoSync>(FullPathDest, HtmlNew, FtpInfo)); } } return(tpPathAndHtml); }
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); }