예제 #1
0
        private string GetHtmlVersionReplaced(string HtmlSrc, string HtmlDest)
        {
            Dictionary <string, string> dicUrlAndVer = new Dictionary <string, string>();

            Regex rDest = new Regex(_PatternUrl, CRegex.Options.Compiled_Multiline_IgnoreCase_IgnorePatternWhitespace);

            foreach (Match m in rDest.Matches(HtmlDest))
            {
                string       Url = m.Groups["Url"].Value;
                CQueryString qs  = new CQueryString(Url);
                if (string.IsNullOrEmpty(qs["v"]))
                {
                    continue;
                }

                dicUrlAndVer.Add(qs.PathOnly, qs["v"]);
            }


            StringBuilder sbHtml = new StringBuilder();

            List <string> aUrl = new List <string>();

            bool  IsFound = false;
            Regex rSrc    = new Regex(_PatternUrl, CRegex.Options.Compiled_Multiline_IgnoreCase_IgnorePatternWhitespace);

            foreach (CMatchInfo mi in CRegex.GetMatchResult(rSrc, HtmlSrc))
            {
                sbHtml.Append(mi.ValueBeforeMatch);

                if (mi.Match == null)
                {
                    break;
                }

                string Url = mi.Match.Groups["Url"].Value;

                CQueryString qs = new CQueryString(Url);
                string       VersionIs;
                dicUrlAndVer.TryGetValue(qs.PathOnly, out VersionIs);

                if (string.IsNullOrEmpty(VersionIs))
                {
                    sbHtml.Append(mi.Match.Value);
                }
                else
                {
                    IsFound = true;
                    sbHtml.Append(mi.Match.Value.Replace(mi.Match.Groups["Url"].Value, qs.PathOnly + "?v=" + VersionIs));
                }
            }

            if (!IsFound)
            {
                return("");
            }


            return(sbHtml.ToString());
        }
예제 #2
0
        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);
        }
예제 #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;
        }