예제 #1
0
        private bool IsValidFolder(FileInfo fi)
        {
            if (!CFile.GetIsFolder(fi))
            {
                throw new Exception(fi.FullName + "은 폴더가 아닌 파일입니다.");
            }


            bool HasDisallowedFolder  = ((this._DisallowedFolder != null) && (this._DisallowedFolder.Length > 0));
            bool HasAllowedOnlyFolder = ((this._AllowedOnlyFolder != null) && (this._AllowedOnlyFolder.Length > 0));

            if (!HasDisallowedFolder && !HasAllowedOnlyFolder)
            {
                return(true);
            }

            if (HasDisallowedFolder && HasAllowedOnlyFolder)
            {
                throw new Exception("IsDisallowedFolder와 IsAllowedOnlyFolder는 둘 중 하나만 값이 있어야 합니다.");
            }


            string Folder = fi.FullName;

            if (HasDisallowedFolder)
            {
                for (int i = 0, i2 = this._DisallowedFolder.Length; i < i2; i++)
                {
                    if (Folder.StartsWith(this._DisallowedFolder[i], StringComparison.CurrentCultureIgnoreCase))
                    {
                        return(false);
                    }
                }

                return(true);
            }
            else
            {
                for (int i = 0, i2 = this._AllowedOnlyFolder.Length; i < i2; i++)
                {
                    if (Folder.StartsWith(this._AllowedOnlyFolder[i], StringComparison.CurrentCultureIgnoreCase))
                    {
                        return(true);
                    }
                }

                return(false);
            }
        }
예제 #2
0
        private bool IsValidExtension(FileInfo fi)
        {
            if (CFile.GetIsFolder(fi))
            {
                return(true);
            }

            bool HasDisallowedExt  = ((this._DisallowedExt != null) && (this._DisallowedExt.Length > 0));
            bool HasAllowedOnlyExt = ((this._AllowedOnlyExt != null) && (this._AllowedOnlyExt.Length > 0));

            if (!HasDisallowedExt && !HasAllowedOnlyExt)
            {
                return(true);
            }

            if (HasDisallowedExt && HasAllowedOnlyExt)
            {
                throw new Exception("IsDisallowedExt와 IsAllowedOnlyExt는 둘 중 하나만 값이 있어야 합니다.");
            }


            string Ext = Path.GetExtension(fi.FullName);

            if (HasDisallowedExt)
            {
                if (string.IsNullOrEmpty(Ext))
                {
                    return(true);
                }

                return(CArray.IndexOf(this._DisallowedExt, Ext, true) == -1);
            }
            else if (HasAllowedOnlyExt)
            {
                if (string.IsNullOrEmpty(Ext))
                {
                    return(false);
                }

                return(CArray.IndexOf(this._AllowedOnlyExt, Ext, true) != -1);
            }

            return(false);
        }
예제 #3
0
        //!!!
        //현재는 쓰이지 않으나 쓰게 되면 CopyAll의 것으로 수정하고 Copy, CopyAll을 공통으로 쓰게 해야 함.
        private void Copy(FileInfo fiSrc)
        {
            bool IsFile = !CFile.GetIsFolder(fiSrc);

            if (_DestType == DestTypes.FileSystem)
            {
                for (int i = 0, i2 = this._aRootFolderDest.Length; i < i2; i++)
                {
                    string FullPathDest = this._aRootFolderDest[i] + fiSrc.FullName.Substring(this._RootFolderSrc.Length);

                    if (IsFile)
                    {
                        _File.CopyFile(fiSrc.FullName, FullPathDest);
                    }
                    else
                    {
                        _File.CopyDirectory(fiSrc.FullName, FullPathDest);
                    }
                }
            }
            else if (_DestType == DestTypes.Ftp)
            {
                for (int i = 0, i2 = this._aFtpInfoDest.Length; i < i2; i++)
                {
                    CFtpInfoSync InfoSync = (CFtpInfoSync)_aFtp[i].Info;

                    if (IsFile)
                    {
                        string FullPathSrc  = fiSrc.FullName;
                        string FullPathDest = CPath.GetFullPathDest(fiSrc.DirectoryName, InfoSync.Folder, FullPathSrc, '/');
                        //FullPathDest의 폴더가 없다면 에러 나나 속도 때문에 무시함.
                        _aFtp[i].UploadFile(FullPathSrc, FullPathDest);
                    }
                    else
                    {
                        _aFtp[i].UploadDirectory(fiSrc.DirectoryName, InfoSync.Folder);
                    }
                }
            }
        }
예제 #4
0
        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);
        }
예제 #5
0
        private void Rename(string FullPathSrcOld, FileInfo fiSrc)
        {
            bool IsFile = !CFile.GetIsFolder(fiSrc);

            for (int i = 0, i2 = this._aRootFolderDest.Length; i < i2; i++)
            {
                string   FullPathDestOld = this._aRootFolderDest[i] + FullPathSrcOld.Substring(this._RootFolderSrc.Length);
                FileInfo fiDestOld       = null;
                if (IsFile)
                {
                    if (File.Exists(FullPathDestOld))
                    {
                        fiDestOld = new FileInfo(FullPathDestOld);
                    }
                }
                else
                {
                    if (Directory.Exists(FullPathDestOld))
                    {
                        fiDestOld = new FileInfo(FullPathDestOld);
                    }
                }

                if (IsFile)
                {
                    if (!IsValidExtension(fiSrc))
                    {
                        continue;
                    }
                }
                else
                {
                    if (!IsValidFolder(fiSrc))
                    {
                        continue;
                    }
                }

                string FullPathDestNew = this._aRootFolderDest[i] + fiSrc.FullName.Substring(this._RootFolderSrc.Length);

                if (fiDestOld == null)
                {
                    try
                    {
                        string Folder = "";
                        if (IsFile)
                        {
                            Folder = Path.GetDirectoryName(FullPathDestNew);
                        }
                        else
                        {
                            Folder = FullPathDestNew;
                        }

                        if (!Directory.Exists(Folder))
                        {
                            Directory.CreateDirectory(Folder);
                        }

                        if (IsFile)
                        {
                            File.Copy(fiSrc.FullName, FullPathDestNew, true);
                        }
                        else
                        {
                            CFile f = new CFile();
                            f.BeforeFileCopy += new EventHandler <CBeforeFileCopyEventArgs>(f_BeforeFileCopy);
                            f.CopyDirectory(fiSrc.FullName, FullPathDestNew);
                        }

                        WriteLog(LogTypes.Copy, fiSrc.FullName, "", FullPathDestNew, null);
                    }
                    catch (Exception ex)
                    {
                        WriteLog(LogTypes.FailCopy, fiSrc.FullName, "", FullPathDestNew, ex);
                    }
                }
                else
                {
                    try
                    {
                        fiDestOld.MoveTo(FullPathDestNew);

                        WriteLog(LogTypes.Rename, FullPathDestOld, "", FullPathDestNew, null);
                    }
                    catch (Exception ex)
                    {
                        WriteLog(LogTypes.FailRename, FullPathDestOld, "", FullPathDestNew, ex);
                    }
                }
            }
        }