コード例 #1
0
ファイル: CSyncFile.cs プロジェクト: doctorgu/MadeIn9
        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);
        }
コード例 #2
0
        /// <summary>
        /// SQL 서버용 키워드는 소문자 또는 대문자로 변경해서 리턴함.
        /// </summary>
        /// <param name="Stmt">SQL문 자체, 또는 SQL문을 포함하는 문자열</param>
        /// <returns>변환된 문자열</returns>
        /// <example>
        /// <code>
        /// string Sql = "select * from mytable where id = 'between a to b' and name like '박%'";
        /// string s = CSql.GetSqlServerKeywordTo(Sql, true);
        /// Console.WriteLine(s);
        /// //--결과
        /// //SELECT * FROM mytable WHERE id = 'between a to b' AND name LIKE '박%'
        /// </code>
        /// </example>
        private static string GetSqlServerKeywordTo(string Stmt, bool IsUcase)
        {
            string[] aKeywords = GetSqlServerKeyword();

            SortedList slIndexValue = new SortedList();

            // \w+: 연속된(+) 글자(w), 즉 단어
            // ': 작은 따옴표

            int   QuoteEnd = -1;
            Regex r        = new Regex(@"\w+|'", RegexOptions.Compiled);

            for (Match m = r.Match(Stmt); m.Success; m = m.NextMatch())
            {
                if (m.Index <= QuoteEnd)
                {
                    continue;
                }

                switch (m.Value)
                {
                case "'":
                    QuoteEnd = CDelim.GetQuoteEnd(Stmt, m.Index, '\'');
                    break;

                default:
                    if (CArray.IndexOf(aKeywords, m.Value, true) >= 0)
                    {
                        slIndexValue.Add(m.Index, new string[] { m.Value, (IsUcase ? m.Value.ToUpper() : m.Value.ToLower()) });
                    }
                    else
                    {
                        slIndexValue.Add(m.Index, new string[] { m.Value, m.Value });
                    }
                    break;
                }
            }

            string s = GetIndexValueMerged(Stmt, slIndexValue);

            return(s);
        }
コード例 #3
0
        /// <summary>
        /// HTML 태그로 구성된 문자열은 BR, P 등을 행의 구분자로,
        /// 일반 텍스트 문자열은 줄바꿈을 구분자로 취급해서 각 행을 항목으로 하는 배열을 리턴함.
        /// </summary>
        /// <param name="Value">문자열</param>
        /// <param name="MaxColumnCount">한글을 2Byte로 취급하는 최대 열너비(이 값을 초과한 문자열은 같은 줄에 있어도 다음 줄로 인식됨)</param>
        /// <param name="Include_BR_P_AsSeparator">BR, P 태그를 행 구분자로 취급할 지 여부</param>
        /// <returns>각 행을 항목으로 하는 배열</returns>
        /// <example>
        /// <code>
        /// <![CDATA[
        /// string Html = "1줄<br>2줄<p>3줄";
        ///
        /// string[] aHtml = CHtml.SplitLine(Html, 2, true);
        /// Console.WriteLine(aHtml[0]); // "1"
        ///
        /// string[] aHtml2 = CHtml.SplitLine(Html, 3, true);
        /// Console.WriteLine(aHtml2[0]); // "1줄"
        /// ]]>
        /// </code>
        /// </example>
        public static string[] SplitLine(string Value, int MaxColumnCount, bool Include_BR_P_AsSeparator)
        {
            List <string> aValueList = new List <string>();

            string[] aLineSep = null;
            if (Include_BR_P_AsSeparator)
            {
                aLineSep = new string[] { "<p>", "<p/>", "<p />", "<br>", "<br/>", "<br />" };
            }
            else
            {
                Value    = Value.Replace("\r", "");
                aLineSep = new string[] { "\n" };
            }

            string[] aValue = Value.Split(aLineSep, StringSplitOptions.None);
            for (int i = 0, i2 = aValue.Length; i < i2; i++)
            {
                if (MaxColumnCount != 0)
                {
                    string[] aValueInner = CArray.SplitByLength(aValue[i], MaxColumnCount, true);
                    if (aValueInner.Length > 1)
                    {
                        for (int j = 0, j2 = aValueInner.Length; j < j2; j++)
                        {
                            aValueList.Add(aValueInner[j]);
                        }
                    }
                    else
                    {
                        aValueList.Add(aValue[i]);
                    }
                }
                else
                {
                    aValueList.Add(aValue[i]);
                }
            }

            return(aValueList.ToArray());
        }
コード例 #4
0
        public static string GetPropertiesInHtml(object Value)
        {
            if (Value == null)
            {
                return("(null)");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("<table border=1 cellpadding=0 cellspacing=0>");

            PropertyInfo[] api = Value.GetType().GetProperties();
            foreach (PropertyInfo pi in api)
            {
                object oValueCur = pi.GetValue(Value, null);
                string ValueCur  = "";
                if (oValueCur == null)
                {
                    ValueCur = "(null)";
                }
                if (oValueCur.GetType() == typeof(string[]))
                {
                    ValueCur = CArray.ToHtml((string[])oValueCur);
                }
                else
                {
                    ValueCur = oValueCur.ToString();
                }

                if (ValueCur == "")
                {
                    ValueCur = "&nbsp;";
                }

                sb.Append("<tr><td>" + pi.Name + "</td><td>" + ValueCur + "</tr>");
            }
            sb.Append("</table>");

            return(sb.ToString());
        }
コード例 #5
0
ファイル: CErWin.cs プロジェクト: doctorgu/MadeIn9
        private static Version GetVersion(XmlDocument XDoc)
        {
            XmlAttribute Attr = XDoc.DocumentElement.Attributes["FileVersion"];

            if (Attr == null)
            {
                return(new Version());
            }

            int Version = CFindRep.IfNotNumberThen0(Attr.Value);

            if (Version > 0)
            {
                //4255 -> 4.2.5.5
                string[] aVersion = CArray.SplitByLength(Attr.Value, 1);
                return(new Version(Convert.ToInt32(aVersion[0]), Convert.ToInt32(aVersion[1]), Convert.ToInt32(aVersion[2]), Convert.ToInt32(aVersion[3])));
            }
            else
            {
                return(new Version(Attr.Value));
            }
        }
コード例 #6
0
ファイル: CSyncFile.cs プロジェクト: doctorgu/MadeIn9
        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);
        }
コード例 #7
0
ファイル: CParagraph.cs プロジェクト: doctorgu/MadeIn9
        public Dictionary <int, string> GetIndexAndWords(string Value, bool IncludeDelimeter)
        {
            Dictionary <int, string> dicWords = new Dictionary <int, string>();
            string Word = "", Delim = "";
            int    IndexWord = -1, IndexDelim = -1;

            for (int i = 0; i < Value.Length; i++)
            {
                char c = Value[i];
                if ((this.mWordSolo != null) && (CArray.IndexOf(this.mWordSolo, c) != -1))
                {
                    if ((Delim != "") && IncludeDelimeter)
                    {
                        dicWords.Add(IndexDelim, Delim);
                    }

                    if (Word != "")
                    {
                        dicWords.Add(IndexWord, Word);
                    }

                    Delim      = "";
                    IndexDelim = -1;

                    Word      = "";
                    IndexWord = -1;


                    dicWords.Add(i, c.ToString());

                    continue;
                }

                if (this.IsDelimeter(c))
                {
                    Delim += c.ToString();

                    if (IndexDelim == -1)
                    {
                        IndexDelim = i;
                    }

                    if (Word != "")
                    {
                        dicWords.Add(IndexWord, Word);
                    }

                    Word      = "";
                    IndexWord = -1;
                }
                else
                {
                    Word += c.ToString();

                    if (IndexWord == -1)
                    {
                        IndexWord = i;
                    }

                    if ((Delim != "") && IncludeDelimeter)
                    {
                        dicWords.Add(IndexDelim, Delim);
                    }

                    Delim      = "";
                    IndexDelim = -1;
                }
            }

            if (Word != "")
            {
                dicWords.Add(IndexWord, Word);
            }
            else if ((Delim != "") && IncludeDelimeter)
            {
                dicWords.Add(IndexDelim, Delim);
            }

            return(dicWords);
        }
コード例 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Stmt"></param>
        /// <param name="aTableFieldName"></param>
        /// <param name="CaseFrom"></param>
        /// <param name="CaseTo"></param>
        /// <param name="IsReplaceOnlyInDoubleQuote"></param>
        /// <returns></returns>
        /// <example>
        /// <code>
        /// string[] aNamePascal = new string[] { "UserName", "UserId" };
        /// string s = "SELECT a.UserName, a.UserId, a.UserJumin FROM UserInfo AS a WHERE a.UserId LIKE 'UserId%'";
        ///
        /// string s2 = CSql.GetTableFieldNameToCase(s, aNamePascal, CSql.CaseTypes.PascalCase, CSql.CaseTypes.UpperCaseUnderbar);
        /// Console.WriteLine(s2);
        /// //--결과
        /// //SELECT a.USER_NAME, a.USER_ID, a.UserJumin FROM UserInfo AS a WHERE a.USER_ID LIKE 'UserId%'
        ///
        /// string[] aNameUpper = new string[] { "USER_NAME", "USER_ID" };
        /// string s3 = CSql.GetTableFieldNameToCase(s2, aNameUpper, CSql.CaseTypes.UpperCaseUnderbar, CSql.CaseTypes.PascalCase);
        /// Console.WriteLine(s3);
        /// //--결과
        /// //SELECT a.UserName, a.UserId, a.UserJumin FROM UserInfo AS a WHERE a.UserId LIKE 'UserId%'
        /// </code>
        /// </example>
        public static string GetTableFieldNameToCase(string Stmt, string[] aTableFieldName,
                                                     CaseTypes CaseFrom, CaseTypes CaseTo, bool IsReplaceOnlyInDoubleQuote)
        {
            string[] aKeywords = GetSqlServerKeyword();

            SortedList slIndexValue = new SortedList();

            // \w+: 연속된(+) 글자(w), 즉 단어
            // ': 작은 따옴표
            // ": 큰 따옴표

            bool  IsDoubleQuotStarted = false;
            int   QuoteEnd            = -1;
            Regex r = new Regex(@"\w+|'|""", RegexOptions.Compiled);

            for (Match m = r.Match(Stmt); m.Success; m = m.NextMatch())
            {
                if (m.Index <= QuoteEnd)
                {
                    continue;
                }

                switch (m.Value)
                {
                case "\"":
                    if (IsDoubleQuotStarted)
                    {
                        IsDoubleQuotStarted = false;
                    }
                    else
                    {
                        IsDoubleQuotStarted = true;
                    }

                    break;

                case "'":
                    QuoteEnd = CDelim.GetQuoteEnd(Stmt, m.Index, '\'');
                    break;

                default:
                    bool IsReplace = true;
                    //따옴표 안의 문자열만 변경하는 옵션일 때 따옴표 안에 있지 않거나,
                    //현재 Value가 Table, Field 이름이 아닌 경우.
                    if ((IsReplaceOnlyInDoubleQuote && !IsDoubleQuotStarted) ||
                        (CArray.IndexOf(aTableFieldName, m.Value, true) == -1))
                    {
                        IsReplace = false;
                    }

                    if (IsReplace)
                    {
                        string Value = GetCaseConverted(m.Value, CaseFrom, CaseTo);
                        slIndexValue.Add(m.Index, new string[] { m.Value, Value });
                    }
                    else
                    {
                        slIndexValue.Add(m.Index, new string[] { m.Value, m.Value });
                    }
                    break;
                }
            }

            string s = GetIndexValueMerged(Stmt, slIndexValue);

            return(s);
        }
コード例 #9
0
        /// <summary>
        /// 태그를 삽입할 위치와 태그 문자열 정보를 NameValueCollection으로 리턴함.
        /// </summary>
        /// <param name="Code"></param>
        /// <returns></returns>
        private NameValueCollection GetPosAndTag(string Code)
        {
            NameValueCollection nv = new NameValueCollection();


            // \w+: 연속된(+) 글자(w), 즉 단어
            // //: 한줄 주석
            // /\*: 여러줄 주석 시작
            // @": @-quoted
            // ": quoted
            // ': single quoted

            int   PosCur = 0;
            Regex r      = new Regex(@"\w+|//|/\*|@""|""|'", RegexOptions.Compiled);

            for (Match m = r.Match(Code) /*1*/; m.Success /*2*/; m = m.NextMatch())             /*3*/
            {
                if (m.Index < PosCur)
                {
                    continue;
                }

                switch (m.Value)
                {
                case @"//":
                    PosCur = GetCommentEnd(Code, m.Index) + 1;
                    if (PosCur != 0)
                    {
                        nv.Add(m.Index.ToString(), drCommentTagStart);
                        nv.Add(PosCur.ToString(), drTagEnd);
                    }
                    else
                    {
                        return(GetErrInfo(nv, m.Index, Code.Length));
                    }
                    break;

                case @"/*":
                    PosCur = GetMultiCommentEnd(Code, m.Index) + 1;
                    if (PosCur != 0)
                    {
                        nv.Add(m.Index.ToString(), drCommentTagStart);
                        nv.Add(PosCur.ToString(), drTagEnd);
                    }
                    else
                    {
                        return(GetErrInfo(nv, m.Index, Code.Length));
                    }
                    break;

                case @"@""":
                    PosCur = GetAtQuoteEnd(Code, m.Index) + 1;
                    if (PosCur != 0)
                    {
                        nv.Add(m.Index.ToString(), drQuoteTagStart);
                        nv.Add(PosCur.ToString(), drTagEnd);
                    }
                    else
                    {
                        return(GetErrInfo(nv, m.Index, Code.Length));
                    }
                    break;

                case @"""":
                    PosCur = CDelim.GetQuoteEnd(Code, m.Index, '"') + 1;
                    if (PosCur != 0)
                    {
                        nv.Add(m.Index.ToString(), drQuoteTagStart);
                        nv.Add(PosCur.ToString(), drTagEnd);
                    }
                    else
                    {
                        return(GetErrInfo(nv, m.Index, Code.Length));
                    }
                    break;

                case @"'":
                    PosCur = CDelim.GetQuoteEnd(Code, m.Index, '\'') + 1;
                    if (PosCur != 0)
                    {
                        nv.Add(m.Index.ToString(), drQuoteTagStart);
                        nv.Add(PosCur.ToString(), drTagEnd);
                    }
                    else
                    {
                        return(GetErrInfo(nv, m.Index, Code.Length));
                    }
                    break;

                default:
                    // \w+
                    if ((CArray.IndexOf(aKeywords, m.Value, true) >= 0) ||
                        (CArray.IndexOf(aDataTypes, m.Value, true) >= 0) ||
                        (CArray.IndexOf(aOperators, m.Value, true) >= 0) ||
                        (CArray.IndexOf(aLiterals, m.Value, true) >= 0))
                    {
                        nv.Add(m.Index.ToString(), drKeywordTagStart);
                        nv.Add((m.Index + m.Value.Length).ToString(), drTagEnd);
                    }
                    break;
                }
            }

            //마지막 문자열을 GetNewCode에서 읽을 수 있도록 위치만을 지정함.
            //if (!DrCollection.HasKey(nv, Code.Length.ToString()))
            if (nv[Code.Length.ToString()] == null)
            {
                nv.Add(Code.Length.ToString(), "");
            }

            return(nv);
        }
コード例 #10
0
ファイル: CValid.cs プロジェクト: doctorgu/MadeIn9
        public static bool IsEmail(string Email, string[] aDisallowedServer, out string ErrMsgIs)
        {
            ErrMsgIs = "";

            int PosApos = Email.IndexOf('@');

            if (PosApos == -1)
            {
                ErrMsgIs = "@ 기호가 없으므로 잘못된 Email 형식입니다.";
                return(false);
            }

            int Pos2nd = PosApos + 1;

            int PosDot = Email.IndexOf('.', Pos2nd);

            if (PosDot == -1)
            {
                ErrMsgIs = "Email의 '아이디@서버주소.도메인형식'의 서버주소와 도메인형식 사이에는 점(.)이 있어야 합니다";
                return(false);
            }

            int Pos3rd = PosDot + 1;

            string Word1st = Email.Substring(0, PosApos);
            string Word2nd = Email.Substring(Pos2nd, Pos3rd - Pos2nd - 1);
            string Word3rd = Email.Substring(Pos3rd);

            if (Word1st.Length == 0)
            {
                ErrMsgIs = "Email의 '아이디@서버주소.도메인형식'의 아이디가 비었습니다.";
                return(false);
            }
            if (Word2nd.Length == 0)
            {
                ErrMsgIs = "Email의 '아이디@서버주소.도메인형식'의 서버주소가 비었습니다.";
                return(false);
            }
            if (Word3rd.Length == 0)
            {
                ErrMsgIs = "Email의 '아이디@서버주소.도메인형식'의 도메인형식이 비었습니다.";
                return(false);
            }

            if (Email.IndexOf("@@") != -1)
            {
                ErrMsgIs = "Email에 '@' 문자열이 연속으로 2개 이상 있습니다.";
                return(false);
            }
            else if (Email.IndexOf("..") != -1)
            {
                ErrMsgIs = "Email에 '.' 문자열이 연속으로 2개 이상 있습니다.";
                return(false);
            }

            if ((aDisallowedServer != null) && (aDisallowedServer.Length > 0))
            {
                int Idx = CArray.IndexOf(aDisallowedServer, Word2nd + "." + Word3rd, true);
                if (Idx != -1)
                {
                    ErrMsgIs = aDisallowedServer[Idx] + " 서버는 메일 주소로 사용할 수 없습니다.";
                    return(false);
                }
            }

            return(true);
        }