예제 #1
0
        private XmlDocument GetDocument()
        {
            if (_XDocForReadOnly == null)
            {
                XmlDocument XDoc = new XmlDocument();
                try
                {
                    XDoc.Load(_XmlFullPath);
                }
                catch (Exception)
                {
                    if (File.Exists(_XmlFullPath))
                    {
                        File.Delete(_XmlFullPath);
                    }

                    XDoc = CXml.CreateUtf8XmlDocument("config");
                }

                return(XDoc);
            }
            else
            {
                return(_XDocForReadOnly);
            }
        }
예제 #2
0
        public static string CreateElementWithAttribute(string ElementName, NameValueCollection nvAttr)
        {
            string s = "";

            s += "<" + ElementName;

            foreach (string Name in nvAttr)
            {
                s += " " + Name + " = \"" + CXml.ReplaceNotAllowedForAttributeValue(nvAttr[Name]) + "\"";
            }

            s += " />";

            return(s);
        }
예제 #3
0
파일: CTts.cs 프로젝트: doctorgu/MadeIn9
        public string ConvertToSsml(string TextToSpeak)
        {
            //숫자 읽는 방식은 say-as로 변경 가능함. (telephone으로 설정해도 전화번호 형식이 아니면 안됨)
            //<say-as interpret-as="telephone">1-800-282-0114</say-as>
            //http://msdn.microsoft.com/en-us/library/dd450828(v=office.13).aspx

            //속도는 <prosody rate="+100%">two time fast.</prosody>

            //원래는 xmlns="http://www.w3.org/2001/10/synthesis" 이나 xmlns 속성이 자동으로 생겨 :w를 추가함.
            string XmlTemplate =
                @"<?xml version=""1.0""?>
<speak version=""1.0""
	xmlns:w=""http://www.w3.org/2001/10/synthesis""
	xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
	xsi:schemaLocation=""http://www.w3.org/2001/10/synthesis
	http://www.w3.org/TR/speech-synthesis/synthesis.xsd""
	xml:lang=""en-US"">
</speak>";
            XmlDocument XDoc = new XmlDocument();

            XDoc.LoadXml(XmlTemplate);
            XmlElement Doc = XDoc.DocumentElement;


            //string Pattern = "(^" + VarMan + ")|(^" + VarWoman + ")|(^" + VarBreak + "(?<Seconds>\\d+[\\.\\d]*))";
            string Pattern = string.Format("(?<Man>{0})|(?<Woman>{1})|(?<Break>{2})|(?<Ignore>{3})", _Variable.Man, _Variable.Woman, _Variable.Break, _Variable.Ignore);
            Regex  r       = new Regex(Pattern, CRegex.Options.Compiled_Multiline_IgnoreCase_IgnorePatternWhitespace);

            List <XmlAttribute> aAttr      = new List <XmlAttribute>();
            List <XmlElement>   aElemBreak = new List <XmlElement>();

            XmlElement VoiceCur = XDoc.CreateElement("voice");

            foreach (CMatchInfo mi in CRegex.GetMatchResult(r, TextToSpeak))
            {
                Match m = mi.Match;

                string Value = CFindRep.TrimWhiteSpace(mi.ValueBeforeMatch);
                if (!string.IsNullOrEmpty(Value))
                {
                    //int PosColon = Value.IndexOf(":");
                    //if (PosColon != -1)
                    //{
                    //    CParagraph p = new CParagraph();
                    //    List<string> aWord = p.GetWords(Value.Substring(0, PosColon + 1), false);
                    //    throw new Exception(aWord[aWord.Count - 1] + ":은 잘못된 변수명입니다. ':' 문자열을 지우거나 허용된 변수명을 입력하세요.");
                    //}

                    AddElementVoice(XDoc, Value, VoiceCur);
                    VoiceCur = XDoc.CreateElement("voice");
                }

                if (m == null)
                {
                    break;
                }

                if (!string.IsNullOrEmpty(m.Groups["Man"].Value))
                {
                    foreach (XmlAttribute AttrCur in GetAttrNameGender(XDoc, false))
                    {
                        VoiceCur.Attributes.Append(AttrCur);
                    }
                }
                else if (!string.IsNullOrEmpty(m.Groups["Woman"].Value))
                {
                    foreach (XmlAttribute AttrCur in GetAttrNameGender(XDoc, true))
                    {
                        VoiceCur.Attributes.Append(AttrCur);
                    }
                }
                else if (!string.IsNullOrEmpty(m.Groups["Break"].Value))
                {
                    VoiceCur.AppendChild(GetElementBreak(XDoc, m.Groups["Seconds"].Value));
                }
                else if (!string.IsNullOrEmpty(m.Groups["Ignore"].Value))
                {
                    //
                }
            }

            string Indented = CXml.GetIndentedContent(XDoc);

            return(Indented);
            //return XDoc.OuterXml;
        }
예제 #4
0
파일: CErWin.cs 프로젝트: doctorgu/MadeIn9
        //private struct SWordInfo
        //{
        //    public int Index, Length;
        //    public string Value, ValueNew;
        //}

        ///// <summary>
        ///// SQL 스크립트를 읽어 테이블 이름과 테이블 설명, 열 이름과 열 설명을 가진 NameValueCollection 개체를 리턴함.
        ///// ReplaceNameWithComment 함수를 호출하기 위해 사용됨.
        ///// </summary>
        ///// <param name="Script">SQL 스크립트</param>
        ///// <returns>NameValueCollection 개체</returns>
        //public static void GetTableColumnAndComment(string Script,
        //    out Dictionary<string, string> dicTable, out Dictionary<string, Dictionary<string, string>> dicColumn)
        //{
        //    dicTable = new Dictionary<string, string>();
        //    dicColumn = new Dictionary<string, Dictionary<string, string>>();

        //    SWordInfo[] awi = GetWordInfo(Script);

        //    for (int n = 0, n2 = awi.Length; n < n2; n++)
        //    {
        //        switch (awi[n].Value.ToLower())
        //        {
        //            case "comment":
        //                bool IsTableIs;
        //                string TableIs, TableCommentIs, ColumnIs, ColumnCommentIs;
        //                if (GetTableOrColumnComment(Script, awi, n, out IsTableIs,
        //                    out TableIs, out TableCommentIs,
        //                    out ColumnIs, out ColumnCommentIs))
        //                {
        //                    if (IsTableIs)
        //                    {
        //                        dicTable.Add(TableIs, TableCommentIs);
        //                    }
        //                    else
        //                    {
        //                        if (dicColumn.ContainsKey(TableIs))
        //                        {
        //                            dicColumn[TableIs].Add(ColumnIs, ColumnCommentIs);
        //                        }
        //                        else
        //                        {
        //                            Dictionary<string, string> dicSub = new Dictionary<string,string>();
        //                            dicSub.Add(ColumnIs, ColumnCommentIs);
        //                            dicColumn.Add(TableIs, dicSub);
        //                        }
        //                    }
        //                }
        //                break;
        //        }
        //    }
        //}

        //private static SWordInfo[] GetWordInfo(string Script, params char[] ValueToIncludeAsWord)
        //{
        //    List<SWordInfo> awi = new List<SWordInfo>();

        //    string Pattern = @"\w+";
        //    if (ValueToIncludeAsWord != null)
        //    {
        //        for (int i = 0, i2 = ValueToIncludeAsWord.Length; i < i2; i++)
        //        {
        //            Pattern += "|\\" + ValueToIncludeAsWord[i].ToString();
        //        }
        //    }

        //    Regex r = new Regex(Pattern, RegexOptions.Compiled);
        //    for (Match m = r.Match(Script); m.Success; m = m.NextMatch())
        //    {
        //        SWordInfo wi = new SWordInfo();
        //        wi.Index = m.Index;
        //        wi.Length = m.Length;
        //        wi.Value = m.Value;
        //        awi.Add(wi);
        //    }

        //    return awi.ToArray();
        //}
        //private static SWordInfo[] GetWordInfo(string Script)
        //{
        //    return GetWordInfo(Script, null);
        //}

        //private static bool GetTableOrColumnComment(string Script, SWordInfo[] awi, int Idx,
        //    out bool IsTable,
        //    out string TableIs, out string TableCommentIs,
        //    out string ColumnIs, out string ColumnCommentIs)
        //{
        //    IsTable = false;
        //    TableIs = "";
        //    TableCommentIs = "";
        //    ColumnIs = "";
        //    ColumnCommentIs = "";

        //    if (awi.Length < (Idx + 3))
        //    {
        //        return false;
        //    }

        //    if (awi[Idx + 1].Value.ToLower() != "on")
        //    {
        //        return false;
        //    }

        //    string ObjType = awi[Idx + 2].Value;
        //    if ((ObjType.ToLower() != "table")
        //        && (ObjType.ToLower() != "column"))
        //    {
        //        return false;
        //    }

        //    IsTable = (ObjType.ToLower() == "table");
        //    int IndexIs = 0;
        //    if (IsTable)
        //    {
        //        TableIs = awi[Idx + 3].Value;
        //        IndexIs = Script.IndexOf("is", awi[Idx + 3].Index + 1, StringComparison.CurrentCultureIgnoreCase);
        //    }
        //    else
        //    {
        //        TableIs = awi[Idx + 3].Value;
        //        ColumnIs = awi[Idx + 4].Value;
        //        IndexIs = Script.IndexOf("is", awi[Idx + 4].Index + 1, StringComparison.CurrentCultureIgnoreCase);
        //    }

        //    if (IndexIs == -1)
        //    {
        //        return false;
        //    }

        //    string Comment = CDelim.GetFirstQuotedValue(Script, IndexIs);

        //    if (IsTable)
        //    {
        //        TableCommentIs = Comment;
        //    }
        //    else
        //    {
        //        ColumnCommentIs = Comment;
        //    }

        //    return true;
        //}

        //private static bool SetTableValue(SWordInfo[] awi, int Idx, string Table, string TableComment)
        //{
        //    bool IsFound = false;
        //    for (int i = 0, i2 = awi.Length; i < i2; i++)
        //    {
        //        if (String.Compare(awi[i].Value, Table, true) == 0)
        //        {
        //            if (awi[i - 1].Value.ToLower() == "table")
        //            {
        //                if ((awi[i - 2].Value.ToLower() == "create") || (awi[i - 2].Value.ToLower() == "alter"))
        //                {
        //                    IsFound = true;
        //                    awi[i].ValueNew = "\"" + TableComment + "\"";
        //                }
        //            }
        //            else if (awi[i - 1].Value.ToLower() == "references")
        //            {
        //                IsFound = true;
        //                awi[i].ValueNew = "\"" + TableComment + "\"";
        //            }
        //            else if ((awi[i - 1].Value.ToLower() == "on") && (awi[i - 3].Value.ToLower() == "index"))
        //            {
        //                IsFound = true;
        //                awi[i].ValueNew = "\"" + TableComment + "\"";
        //            }
        //        }
        //    }

        //    return IsFound;
        //}

        //private static bool SetColumnValue(SWordInfo[] awi, int Idx, string Table, string Column, string ColumnComment)
        //{
        //    bool IsFound = false;
        //    for (int i = 0, i2 = awi.Length; i < i2; i++)
        //    {
        //        if (string.Compare(awi[i].Value, Table, true) == 0)
        //        {
        //            if (awi[i - 1].Value.ToLower() == "table")
        //            {
        //                if ((awi[i - 2].Value.ToLower() == "create") || (awi[i - 2].Value.ToLower() == "alter"))
        //                {
        //                    if (SetColumnValueFromPos(i, awi, Column, ColumnComment))
        //                    {
        //                        IsFound = true;
        //                    }
        //                }
        //            }
        //            else if (awi[i - 1].Value.ToLower() == "references")
        //            {
        //                if (SetColumnValueFromPos(i, awi, Column, ColumnComment))
        //                {
        //                    IsFound = true;
        //                }
        //            }
        //            else if ((awi[i - 1].Value.ToLower() == "on") && (awi[i - 3].Value.ToLower() == "index"))
        //            {
        //                if (SetColumnValueFromPos(i, awi, Column, ColumnComment))
        //                {
        //                    IsFound = true;
        //                }
        //            }
        //        }
        //    }

        //    return IsFound;
        //}
        //private static bool SetColumnValueFromPos(int PosFrom, SWordInfo[] awi,
        //    string Column, string ColumnComment)
        //{
        //    bool IsFound = false;
        //    bool IsQuoteStarted = false;
        //    for (int j = (PosFrom + 1), j2 = awi.Length; j < j2; j++)
        //    {
        //        if (awi[j].Value == "\"")
        //        {
        //            IsQuoteStarted = !IsQuoteStarted;
        //        }

        //        if (IsQuoteStarted) continue;

        //        if (string.Compare(awi[j].Value, Column, true) == 0)
        //        {
        //            awi[j].ValueNew = "\"" + ColumnComment + "\"";
        //            IsFound = true;
        //            //break를 하지 않으면 다른 테이블의 같은 Column까지 찾게 됨.
        //            break;
        //        }
        //        else if (awi[j].Value == ";")
        //        {
        //            break;
        //        }
        //    }

        //    return IsFound;
        //}

        //버전 7에서 속성이 많이 바뀌어 사용 안함.
        ///// <summary>
        ///// ERwin에서 저장한 XML 파일의 내용 중 글꼴이름, 글꼴크기 관련 값을 새로운 값으로 변경함.
        ///// </summary>
        ///// <param name="XmlFullPath">ERwin에서 저장한 XML 파일</param>
        ///// <param name="FontName">새 글꼴 이름</param>
        ///// <param name="FontSize">새 글꼴 크기</param>
        ///// <returns>글꼴 정보가 변경되었는 지 여부</returns>
        //public static bool ChangeFontNameSize(string XmlFullPath, string FontName, int FontSize)
        //{
        //    XmlDocument XDoc = new XmlDocument();
        //    XDoc.Load(XmlFullPath);

        //    string NameText = GetNameTextByVersion(XDoc);

        //    string NewValue = FontName + "-" + FontSize.ToString() + "-0-0-0-0";
        //    bool IsChanged = false;

        //    string XPath = "//Font[@" + NameText + "]";
        //    XmlNodeList List = XDoc.SelectNodes(XPath);
        //    foreach (XmlNode NodeCur in List)
        //    {
        //        if (NodeCur.Attributes[NameText].Value != NewValue)
        //        {
        //            NodeCur.Attributes[NameText].Value = NewValue;
        //            IsChanged = true;
        //        }

        //        XPath = "FontProps/" + NameText;
        //        XmlElement ElemName = (XmlElement)NodeCur.SelectSingleNode(XPath);
        //        if (ElemName.InnerText != NewValue)
        //        {
        //            ElemName.InnerText = NewValue;
        //            IsChanged = true;
        //        }

        //        XPath = "FontProps/Font_Name";
        //        XmlElement ElemFontName = (XmlElement)NodeCur.SelectSingleNode(XPath);
        //        if (ElemFontName.InnerText != FontName)
        //        {
        //            ElemFontName.InnerText = FontName;
        //            IsChanged = true;
        //        }

        //        XPath = "FontProps/Font_Size";
        //        XmlElement ElemFontSize = (XmlElement)NodeCur.SelectSingleNode(XPath);
        //        if (ElemFontSize.InnerText != FontSize.ToString())
        //        {
        //            ElemFontSize.InnerText = FontSize.ToString();
        //            IsChanged = true;
        //        }
        //    }

        //    if (IsChanged)
        //    {
        //        XDoc.Save(XmlFullPath);
        //    }

        //    return IsChanged;
        //}

        public static void ReplaceNameWithComment(DbServerType DbType, string XmlFullPath,
                                                  Dictionary <string, string> dicTable,
                                                  Dictionary <string, Dictionary <string, string> > dicColumn)
        {
            XmlDocument XDoc = new XmlDocument();

            XDoc.Load(XmlFullPath);

            Version v = GetVersion(XDoc);

            // 7 버전에서는 Physical을 추가하면 Logical의 필드 양쪽에 _가 붙는 현상 있어 포기.
            if (v.Major >= 7)
            {
                throw new Exception("7 버전은 지원하지 않습니다.");
            }

            XmlNamespaceManager ns = (v.Major >= 7) ? CXml.AddNamespace(XDoc) : null;
            string Prefix          = (v.Major >= 7) ? "EMX:" : "";

            string NameText = "";

            switch (DbType)
            {
            case DbServerType.SQLServer:
                NameText = "name";
                break;

            case DbServerType.Oracle:
                NameText = "Name";
                break;

            default:
                throw new Exception(string.Format("Wrong DbType:{0}", DbType));
            }

            foreach (KeyValuePair <string, string> kvTable in dicTable)
            {
                XmlNode nodEntity          = XDoc.SelectSingleNode("//" + Prefix + "Entity[@" + NameText + "='" + kvTable.Key + "']", ns);
                XmlNode nodEntityPropsName = nodEntity.SelectSingleNode(Prefix + "EntityProps/" + Prefix + "Name", ns);

                nodEntity.Attributes[NameText].Value   = kvTable.Value;
                nodEntityPropsName.ChildNodes[0].Value = kvTable.Value;

                if (v.Major >= 7)
                {
                    //XmlNode nodModelProps = XDoc.SelectSingleNode("//" + Prefix + "ModelProps", ns);
                    //XmlNode nodStandards = nodModelProps.SelectSingleNode(Prefix + "Suspend_Naming_Standards", ns);
                    //if (nodStandards == null)
                    //{
                    //    nodModelProps.AppendChild(XDoc.CreateElement("Suspend_Naming_Standards")).InnerText = "false";
                    //}

                    //XmlNode nodPhysicalOnly = nodEntityPropsName.SelectSingleNode(Prefix + "Physical_Only", ns);
                    //if (nodPhysicalOnly == null)
                    //{
                    //    nodEntityPropsName.AppendChild(XDoc.CreateElement("Physical_Only")).InnerText = "false";
                    //    nodEntityPropsName.AppendChild(XDoc.CreateElement("Physical_Name")).InnerText = kvTable.Key;
                    //}

                    XmlNode nodDrawingObjectEntity = XDoc.SelectSingleNode("//" + Prefix + "Drawing_Object_Entity_Groups/" + Prefix + "Drawing_Object_Entity[@" + NameText + "='" + kvTable.Key + "']", ns);
                    if (nodDrawingObjectEntity != null)
                    {
                        nodDrawingObjectEntity.Attributes[NameText].Value = kvTable.Value;
                    }
                }


                foreach (KeyValuePair <string, Dictionary <string, string> > kvColumn in dicColumn)
                {
                    if (kvColumn.Key != kvTable.Key)
                    {
                        continue;
                    }

                    foreach (KeyValuePair <string, string> kvColumnSub in kvColumn.Value)
                    {
                        XmlNode nodAttribute          = nodEntity.SelectSingleNode(Prefix + "Attribute_Groups/" + Prefix + "Attribute[@" + NameText + "='" + kvColumnSub.Key + "']", ns);
                        XmlNode nodAttributePropsName = nodAttribute.SelectSingleNode(Prefix + "AttributeProps/" + Prefix + "Name", ns);

                        nodAttribute.Attributes[NameText].Value   = kvColumnSub.Value;
                        nodAttributePropsName.ChildNodes[0].Value = kvColumnSub.Value;
                    }
                }
            }

            XDoc.PreserveWhitespace = true;
            XDoc.Save(XmlFullPath);
        }