Example #1
0
 public static long getByteFromGMKBString(String text)
 {
     long result = 0;
     System.Text.RegularExpressions.Regex gbReg = new System.Text.RegularExpressions.Regex(@"(\d+)GB", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex kbReg = new System.Text.RegularExpressions.Regex(@"(\d+)KB", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex mbReg = new System.Text.RegularExpressions.Regex(@"(\d+)MB", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex bReg = new System.Text.RegularExpressions.Regex(@"(\d+)B", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     if (bReg.IsMatch(text)) {
         var m = bReg.Match(text);
         result += long.Parse(m.Groups[1].Value);
     }
     if (kbReg.IsMatch(text)) {
         var m = kbReg.Match(text);
         result += long.Parse(m.Groups[1].Value) * BaseByte;
     }
     if (mbReg.IsMatch(text)) {
         var m = mbReg.Match(text);
         result += long.Parse(m.Groups[1].Value) * BaseByte * BaseByte;
     }
     if (gbReg.IsMatch(text)) {
         var m = gbReg.Match(text);
         result += long.Parse(m.Groups[1].Value) * BaseByte * BaseByte * BaseByte;
     }
     return result;
 }
Example #2
0
 /// <summary>
 /// 清除HTML代码
 /// </summary>
 /// <param name="text"></param>
 /// <returns></returns>
 public static string CleanHTML(string text)
 {
     var regex = new System.Text.RegularExpressions.Regex(@"(<[a-zA-Z].*?>)|(<[\/][a-zA-Z].*?>)");
         var content = regex.Replace(text, string.Empty);
         content = content.Replace("&nbsp;", " ");
         return content;
 }
Example #3
0
        /// <summary>
        /// Handling label_value_numeric
        /// </summary>
        public static Double ConvertToDouble(string s)
        {
            try
            {
                string result = "";
                System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("[1-9][0-9,.]*");
                var arr = reg.Match(s).Value.Split('.');

                if (arr.Length == 1)
                    result = arr[0];
                else
                    result = arr[0] + "." + arr[1];

                result = result.Trim('.');

                if (String.IsNullOrWhiteSpace(result))
                    return 0;

                return Convert.ToDouble(result);
            }
            catch (Exception ex)
            {
                logger.Info("Error occured in ConvertToDouble for label_value_numeric - "+ex.Message);
                return 0;
            }
        }
Example #4
0
        public RegexTermEnum(IndexReader reader, Term term)
            : base()
        {
            field = term.Field();
            System.String text = term.Text();

            pattern = new Pattern(text);

            // Find the first regex character position, to find the
            // maximum prefix to use for term enumeration
            int index = 0;
            while (index < text.Length)
            {
                char c = text[index];

                if (!System.Char.IsLetterOrDigit(c))
                    break;

                index++;
            }

            pre = text.Substring(0, (index) - (0));

            SetEnum(reader.Terms(new Term(term.Field(), pre)));
        }
Example #5
0
 /// <summary>
 /// Html到文本
 /// </summary>
 /// <param name="Html"></param>
 /// <param name="html"></param>
 /// <returns></returns>
 public static string Html2String(this HtmlHelper Html, string html)
 {
     System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[/s/S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[/s/S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[/s/S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[/s/S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[/s/S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"/<img[^/>]+/>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     html = regex1.Replace(html, ""); //过滤<script></script>标记
     html = regex1.Replace(html, ""); //过滤<script></script>标记
     html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
     html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
     html = regex4.Replace(html, ""); //过滤iframe
     html = regex5.Replace(html, ""); //过滤frameset
     html = regex6.Replace(html, ""); //过滤frameset
     html = regex7.Replace(html, ""); //过滤frameset
     html = regex8.Replace(html, ""); //过滤frameset
     html = regex9.Replace(html, "");
     html = html.Replace("&nbsp;", " ");
     html = html.Replace("</strong>", "");
     html = html.Replace("<strong>", "");
     return html;
 }
Example #6
0
 public bool ValidateEmail()
 {
     bool result = true;
     try
     {
         if (txtMailId.Text.Trim() != string.Empty)
         {
             System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");//^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$
             if (txtMailId.Text.Length > 0)
             {
                 if (!rEMail.IsMatch(txtMailId.Text))
                 {
                     MessageBox.Show("Invalid Email", "Pharmasoft", MessageBoxButtons.OK, MessageBoxIcon.Information);
                     result = false;
                     txtMailId.Focus();
                 }
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("SM" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
     return result;
 }
 private static string ReplaceSpriteMetaData(string metafileText, string oldPrefix, string newPrefix)
 {
     string spritenamePattern = "(- name: )" + oldPrefix;
     var spritenameRegex = new System.Text.RegularExpressions.Regex(spritenamePattern);
     string replacementText = "$1" + newPrefix;
     return spritenameRegex.Replace(metafileText, replacementText);
 }
Example #8
0
        public static string GetDefaultDomain(string tnsNamePath)
        {
            if (string.IsNullOrEmpty(tnsNamePath)) return "";

            if (File.Exists(tnsNamePath) == false) return "";

            tnsNamePath = tnsNamePath.ToLower();
            if (tnsNamePath.LastIndexOf("tnsnames.ora") < 0) return "";

            string sqlnetora = tnsNamePath.Replace("tnsnames.ora", "sqlnet.ora");

            if (File.Exists(sqlnetora) == false) return "";

            try
            {
                string sqlnet = File.ReadAllText(sqlnetora);

                var reg = new System.Text.RegularExpressions.Regex(@"([#]*)[\t\ ]*NAMES.DEFAULT_DOMAIN\s*=\s*([a-zA-Z0-9_.]+)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);

                var m = reg.Match(sqlnet);
                if (m.Success)
                {
                    if (m.Groups.Count >= 3)
                    {
                        if (m.Groups[1].Value != null && m.Groups[1].Value.IndexOf('#') >= 0) return "";

                        if (m.Groups[2].Value == null) return "";
                        return m.Groups[2].Value.Trim().ToUpper();
                    }
                }
                return "";
            }
            catch { return ""; }
        }
Example #9
0
 /// 过滤html,js,css代码
 /// <summary>
 /// 过滤html,js,css代码
 /// </summary>
 /// <param name="html">参数传入</param>
 /// <returns></returns>
 public static string CheckStr(string html)
 {
     System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script. *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script. *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe. *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
     html = regex1.Replace(html, ""); //过滤<script></script>标记
     html = regex2.Replace(html, ""); //过滤href=java script. (<A>) 属性
     html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
     html = regex4.Replace(html, ""); //过滤iframe
     html = regex5.Replace(html, ""); //过滤frameset
     html = regex6.Replace(html, ""); //过滤frameset
     html = regex7.Replace(html, ""); //过滤frameset
     html = regex8.Replace(html, ""); //过滤frameset
     html = regex9.Replace(html, "");
     html = html.Replace(" ", "");
     html = html.Replace("</strong>", "");
     html = html.Replace("<strong>", "");
     html = html.Replace("'", "'");
     return html;
 }
        /// <summary>
        /// このクラスでの実行すること。
        /// </summary>
        /// <param name="runChildren"></param>
        public override void Run(bool runChildren)
        {
            System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("<input [^>]*>");
            System.Text.RegularExpressions.Regex r2 = new System.Text.RegularExpressions.Regex(@"(\w)*\s*=\s*"+"\"([^\"]*)\"");

            var p = this.GetAncestorRawler().OfType<Page>();
            if (p.Any() == false)
            {
                ReportManage.ErrReport(this, "上流にPageがありません");
                return;
            }
            var page = p.First();
            List<KeyValue> list = new List<KeyValue>();
            foreach (System.Text.RegularExpressions.Match item in r.Matches(GetText()))
            {
                var dic = GetParameter(item.Value);
                if (dic.ContainsKey("type") && dic["type"] == "hidden")
                {
                    if (dic.ContainsKey("name") && dic.ContainsKey("value"))
                    {
                        page.AddParameter(dic["name"], dic["value"]);
                        list.Add(new KeyValue() { Key = dic["name"], Value = dic["value"] });
                    }
                }

            }
            base.Run(runChildren);
        }
Example #11
0
        public static IUnaryOperator Parse(ISyntaxNode parent, ref string Input, IRightValue firstOperand)
        {
            string temp = Input;

            Pattern regExPattern =
                "^\\s*" +
                new Group("def", "(\\+|-|!|~|\\*|&)");//|\\("+Provider.type+"\\)

            System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(regExPattern);
            System.Text.RegularExpressions.Match match = regEx.Match(Input);

            if (!match.Success)
            {
                Input = temp;
                return null;
            }

            Input = Input.Remove(0, match.Index + match.Length);

            string Operator = match.Groups["def"].Value;

            switch (Operator)
            {

                default:
                    Input = temp;
                    throw new NotImplementedException();
            }
        }
Example #12
0
 private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
 {
     String filePath = openFileDialog1.FileName;
     openFileDialog1.InitialDirectory = filePath;
     mobiles.Clear();
     listBox1.Items.Clear();
     if (File.Exists(filePath)){              
         using (StreamReader sr = File.OpenText(filePath))
         {
             string s = "";
             while ((s = sr.ReadLine()) != null)
             {
                 System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$");
                 if (s.Length == 11&& rex.IsMatch(s))
                 {
                     if (!mobiles.Contains(s))
                     {
                         mobiles.Add(s);
                         listBox1.Items.Add(s);
                     }
                 }
             }
         }
     }
     msgLab.Text = "你将给 " + mobiles.Count + " 个人群发信息,短信字数共计为 " + contentTxt.Text.Length + " 个";
 }
Example #13
0
        private static string HandleCreateAccount(HttpServer server, HttpListenerRequest request, Dictionary<string, string> parameters)
        {
            if (!parameters.ContainsKey("username")) throw new Exception("Missing username.");
            if (!parameters.ContainsKey("password")) throw new Exception("Missing password.");

            string username = parameters["username"];
            string password = parameters["password"];

            if (Databases.AccountTable.Count(a => a.Username.ToLower() == username.ToLower()) > 0) return JsonEncode("Username already in use!");

            System.Text.RegularExpressions.Regex invalidCharacterRegex = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]");
            if (invalidCharacterRegex.IsMatch(username)) return JsonEncode("Invalid characters detected in username!");

            Random getrandom = new Random();
            String token = getrandom.Next(10000000, 99999999).ToString();
            AccountEntry entry = new AccountEntry();
            entry.Index = Databases.AccountTable.GenerateIndex();
            entry.Username = username;
            entry.Password = password;
            entry.Verifier = "";
            entry.Salt = "";
            entry.RTW_Points = 0;
            entry.IsAdmin = 0;
            entry.IsBanned = 0;
            entry.InUse = 0;
            entry.extrn_login = 0;
            entry.CanHostDistrict = 1;
            entry.Token = token;
            Databases.AccountTable.Add(entry);

            Log.Succes("HTTP", "Successfully created account '" + username + "'");
            return JsonEncode("Account created!\n\nYour token is: " + token + ".\nCopy and paste given token in \"_rtoken.id\" file and put it in the same folder where your \"APB.exe\" is located.");
        }
Example #14
0
        public NumberRange(string range)
            : this()
        {
            if (String.IsNullOrEmpty(range))
                return;

            if (regex == null)
                regex = new System.Text.RegularExpressions.Regex("[0-9][0-9]*");
            int matchNumber = 1;
            foreach (System.Text.RegularExpressions.Match match in regex.Matches(range))
            {
                switch (matchNumber)
                {
                    case 1:
                        minimum = maximum = System.Convert.ToInt32(match.Value);
                        break;
                    case 2:
                        maximum = System.Convert.ToInt32(match.Value);
                        break;
                    default:
                        throw new Exception("Invalid number range \"" + range + "\".");
                }
                matchNumber++;
            }

            if(matchNumber == 1)
                throw new Exception("Invalid number range \"" + range + "\".");

            isSet = true;
        }
Example #15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            ////get the expired cookie
            //System.Web.Security.FormsAuthentication.SignOut();
            ////set the cookie Domain
            //HttpCookie lcookie2 = Context.Response.Cookies[System.Web.Security.FormsAuthentication.FormsCookieName];
            //lcookie2.Domain = Core.Global.CookieDomain;

            OnlineUserBlock.Components.oluMonitor.MemberSignout();
            Session.Clear();
            if (Request.Cookies["sid"] != null || Request.Cookies["sso"] != null)
            {
                Response.Cookies["sid"].Expires = DateTime.Now;
                Response.Cookies["sso"].Expires = DateTime.Now;//单点登录的Cookie
            }

            string url = CY.Utility.Common.RequestUtility.GetCookieValue("CurrentUrl");

            Response.Cookies["CurrentUrl"].Expires = DateTime.Now;//用户访问过的上个页面地址

            System.Text.RegularExpressions.Regex R = new System.Text.RegularExpressions.Regex("(" + url + ")+"); //查找"Abc"

            System.Text.RegularExpressions.Match M = R.Match("Logout.aspx"); //设定要查找的字符串

            if (M.Index > 0 || url.Length <= 4)
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "logout", "<script type='text/javascript'>window.location.href='Login.aspx';</script>");
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "logout", "<script type='text/javascript'>window.location.href='" + url + "';</script>");
            }
        }
Example #16
0
        private void btnTest_Click(object sender, EventArgs e)
        {
            if (txtRegEx.Text.Trim().Length == 0)
            {
                MessageBox.Show("Regular Expression is empty", "Test Regular Expression", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRegEx.Focus();
                return;
            }
            System.Text.RegularExpressions.Regex rx;
            try
            {
                rx = new System.Text.RegularExpressions.Regex(txtRegEx.Text.Trim());
            }
            catch
            {
                MessageBox.Show("Invalid regular expression", "Test Regular Expression", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtRegEx.Focus();
                return;
            }

            string s = Microsoft.VisualBasic.Interaction.InputBox("Enter domain name to test:", "Test Regular Expression", LastTestStr).Trim();
            if (s.Length == 0) return;
            LastTestStr = s.ToLower();

            if (rx.IsMatch(LastTestStr))
            {
                MessageBox.Show("TEST SUCCESSFUL\n\nDomain name matches regular expression", "Test Regular Expression", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
            else
            {
                MessageBox.Show("TEST FAILED\n\nDomain name does NOT match regular expression", "Test Regular Expression", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
Example #17
0
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            // 只读, 不处理
            if (this.ReadOnly) return;

            string regex = @"^[\w ]+$"; //匹配数字、字母、汉字
            if (isNumber) regex = "^[0-9]*$";  //匹配数字 
            var reg = new System.Text.RegularExpressions.Regex(regex);// 
            var str = this.Text.Replace(" ", "");
            var sb = new StringBuilder();
            if (!reg.IsMatch(str))
            {
                for (int i = 0; i < str.Length; i++)
                {
                    if (reg.IsMatch(str[i].ToString()))
                    {
                        sb.Append(str[i].ToString());
                    }
                }
                this.Text = sb.ToString();
                this.SelectionStart = this.Text.Length;    //定义输入焦点在最后一个字符          
            }
        }
 /// <summary>
 /// ajax method for chek routing
 /// </summary>
 /// <param name="pattern"></param>
 /// <param name="replaceStr"></param>
 public void CheckRouting(string pattern, string replaceStr)
 {
     System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(pattern);
     string flag = reg.IsMatch(replaceStr) ? "匹配" : "不匹配";
     RenderText(flag);
     CancelView();
 }
 private static string ReplaceFileIDRecycleNames(string metafileText, string oldPrefix, string newPrefix)
 {
     string fileIDPattern = "([\\d]{8}: )" + oldPrefix;
     var fileIDRegex = new System.Text.RegularExpressions.Regex(fileIDPattern);
     string replacementText = "$1" + newPrefix;
     return fileIDRegex.Replace(metafileText, replacementText);
 }
Example #20
0
 /// <summary>
 /// 获取双色球开奖结果
 /// </summary>
 /// <returns></returns>
 private void GetSSQResult()
 {
     string ssqResult = "";
     try
     {
         System.Threading.Thread.Sleep(3000);
         string html = new System.Net.WebClient().DownloadString("http://www.zhcw.com/kaijiang/index_kj.html");
         html = html.Substring(html.IndexOf("<dd>"), html.IndexOf("</dd>") - html.IndexOf("<dd>") + 4).Replace("\r\n","");
         string regStr = "<li class=\"qiured\">(.*?)</li>          <li class=\"qiured\">(.*?)</li>          <li class=\"qiured\">(.*?)</li>          <li class=\"qiured\">(.*?)</li>          <li class=\"qiured\">(.*?)</li>          <li class=\"qiured\">(.*?)</li>          <li class=\"qiublud\">(.*?)</li>";
         var regex = new System.Text.RegularExpressions.Regex(regStr);
         System.Text.RegularExpressions.Match m;
         if ((m = regex.Match(html)).Success && m.Groups.Count == 8)
         {
             for (int i = 1; i < 8; i++)
             {
                 ssqResult += "," + m.Groups[i].Value;
             }
             ssqResult = ssqResult.Substring(1);
         }
     }
     catch (Exception ex)
     {
         ssqResult = ex.Message;
     }
     Response.Write(ssqResult);
     Response.Flush();
     Response.End();
 }
        public void TestBodyAnswerParcer()
        {
            string testAnswer = "<123:-22 NOSENSOR>";
            var answerParceRegX = new System.Text.RegularExpressions.Regex(ANSWERPARCE_EXPR, System.Text.RegularExpressions.RegexOptions.Compiled);
            var match = answerParceRegX.Match(testAnswer);

            if (!match.Success)
                throw new Exception("Error parcing answer");

            string body = match.Groups["BODY"].Value;
            if (body == "OK")
                Assert.Fail();
            else
            {
                var bodyParcerRegX = new System.Text.RegularExpressions.Regex(BODYPARCE_EXPR, System.Text.RegularExpressions.RegexOptions.Compiled);
                var matchArg = bodyParcerRegX.Match(body);
                if (!matchArg.Success)
                    Assert.Fail();
                foreach (System.Text.RegularExpressions.Capture argument in matchArg.Groups["ARG"].Captures)
                {
                    if (argument.Value != "-22" & argument.Value != "NOSENSOR")
                        Assert.Fail();
                }
            }
        }
Example #22
0
 private string GetLanguageFromConfluenceClassAttribute(HtmlNode node)
 {
     string val = node.GetAttributeValue("class", "");
     var rx = new System.Text.RegularExpressions.Regex(@"brush:\s?(:?.*);");
     var res = rx.Match(val);
     return res.Success ? res.Value : "";
 }
Example #23
0
		/// <summary>
		/// Default constructor that registers default content handlers
		/// </summary>
		public RestClient()
		{
            var asmName = this.GetType().AssemblyQualifiedName;
            var versionExpression = new System.Text.RegularExpressions.Regex("Version=(?<version>[0-9.]*)");
            var m = versionExpression.Match(asmName);
            if (m.Success)
            {
                version = new Version(m.Groups["version"].Value);
            }

			ContentHandlers = new Dictionary<string, IDeserializer>();
			AcceptTypes = new List<string>();
			DefaultParameters = new List<Parameter>();

			// register default handlers
			AddHandler("application/json", new JsonDeserializer());
			AddHandler("application/xml", new XmlDeserializer());
			AddHandler("text/json", new JsonDeserializer());
			AddHandler("text/x-json", new JsonDeserializer());
			AddHandler("text/javascript", new JsonDeserializer());
			AddHandler("text/xml", new XmlDeserializer());
			AddHandler("*", new XmlDeserializer());

			FollowRedirects = true;
		}
Example #24
0
 private string GetLanguageFromHighlightClassAttribute(HtmlNode node)
 {
     string val = node.GetAttributeValue("class", "");
     var rx = new System.Text.RegularExpressions.Regex("highlight-([a-zA-Z0-9]+)");
     var res = rx.Match(val);
     return res.Success ? res.Value : "";
 }
Example #25
0
        private string GetOutput(string res, string file_name)
        {
            try {

               	        WebClient client = new WebClient();
                NameValueCollection form = new NameValueCollection();

                form.Add("login", Properties.Settings.Default.login);
                form.Add("token", Properties.Settings.Default.api);
                form.Add(String.Format("file_ext[{0}]", file_name), Path.GetExtension(file_name));
                form.Add(String.Format("file_name[{0}]", file_name),file_name );
                form.Add(String.Format("file_contents[{0}]", file_name), res);
                byte[] responseData = client.UploadValues(API_URL, form);
                String s =  Encoding.UTF8.GetString(responseData);
                System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("\"repo\":\"(\\d+)\"");
                System.Text.RegularExpressions.Match m = r.Match(s);

                if(m.Success){
                    return String.Format("<script src=\"http://gist.github.com/{0}.js\"></script>", m.Groups[1].Value);
                }
                return null;
            }
            catch (Exception webEx) {
              	    Console.WriteLine(webEx.ToString());

            }

            return null;
        }
 public string GetTableName(Type entityType)
 {
     var sql = this.Set(entityType).ToString();
     var regex = new System.Text.RegularExpressions.Regex(@"FROM \[dbo\]\.\[(?<table>.*)\] AS");
     var match = regex.Match(sql);
     return match.Groups["table"].Value;
 }
Example #27
0
        /// <summary>
        /// Search Running Object Table for a running VisualStudio instance which has open a particular solution.
        /// Typical usage might be EnvDTE.Solution sln = DesignTime.GetVisualStudioInstanceBySolution(@"\\My Solution\.sln$")
        /// </summary>
        /// <param name="solution_file_regex">Regular expression matching the solution fullname</param>
        /// <returns>The Solution object if a match was found, null otherwise</returns>
        public static EnvDTE.Solution GetVisualStudioInstanceBySolution(string solution_file_regex)
        {
            System.Text.RegularExpressions.Regex re = new System.Text.RegularExpressions.Regex(solution_file_regex);

            IRunningObjectTable runningObjectTable;
            GetRunningObjectTable(0, out runningObjectTable);

            IEnumMoniker monikerEnumerator;
            runningObjectTable.EnumRunning(out monikerEnumerator);
            monikerEnumerator.Reset();

            IMoniker[] monikers = new IMoniker[1];
            IntPtr numFetched = IntPtr.Zero;
            while (monikerEnumerator.Next(1, monikers, numFetched) == 0)
            {
                IBindCtx ctx;
                CreateBindCtx(0, out ctx);

                string runningObjectName;
                monikers[0].GetDisplayName(ctx, null, out runningObjectName);
                if (re.IsMatch(runningObjectName))
                {
                    object runningObjectVal;
                    runningObjectTable.GetObject(monikers[0], out runningObjectVal);
                    EnvDTE.Solution sln = runningObjectVal as EnvDTE.Solution;
                    if (sln != null)
                        return sln;
                }
            }

            return null;
        }
        private string createResponse(string rawline)
        {
            System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex("(GET )(/)([^ ]+)");
            var result = regex.Match(rawline);
            if (result.Success && result.Groups.Count == 4)
            {
                string command = result.Groups[3].Value;
                string headers = "HTTP/1.1 200 OK\r\n" +
                "Content-Type: text/plain\r\n" +
                "Accept-Ranges: bytes\r\n" +
                "Vary: Accept-Encoding\r\n";
                if (command == "get_server_data")
                {
                    string response = "name=" + Server.instance.config.getString("server_name") + "\nmax_players=" + Server.instance.config.getString("max_players") + "\ngame_port=" + Server.instance.config.getString("game_port") + "\nplayers=" +
                        Server.instance.playerpool.Count;

                    return headers + "Content-Length: " + response.Length + "\r\n\r\n" + response + "\r\n\r\n";
                }
            }
            else
            {
                string headers = "HTTP/1.1 200 OK\r\n" +
                "Content-Type: text/HTML\r\n" +
                "Accept-Ranges: bytes\r\n" +
                "Vary: Accept-Encoding\r\n" +
                "refresh:5;url=http://gta.vdgtech.eu\r\n\r\nThat command is invalid. Redirecting to gta.vdgtech.eu in 5 seconds.\r\n\r\n";
                return headers;
            }
            return null;
        }
Example #29
0
        public static bool validarCorreo(string cadenaUsuario)
        {
            bool val = true;
            bool result = false;
            foreach (char c in cadenaUsuario)
            {
                if (c == '"')
                {
                    val = false;
                    break;
                }
            }

            if (val == true)
            {
                patron = @"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
                auto = new System.Text.RegularExpressions.Regex(patron);
                result = auto.IsMatch(cadenaUsuario);
            }
            else
            {
                result = false;
            }

            return result;
        }
Example #30
0
        private string VerifSaisie(string numero)
        {
            Boolean plusEnPremier = false;
            String resultatfinal = "";
            numero = numero.Trim();
            //filtre regex on ne garde que ce qui est chiffre et '+'
            System.Text.RegularExpressions.Regex myRegex = new System.Text.RegularExpressions.Regex("[^0-9+]");
            string resultat1 = myRegex.Replace(numero, "");

            if (resultat1.Length > 0)//Si le résultat du premier chiffre donne autre chose qu'une chainbe vide on continue
            {
                if (resultat1[0] == '+')//on verifie si le premier élement de la collection de caractére est un "+", si oui on valorise un booleen
                { plusEnPremier = true; }
                myRegex = new System.Text.RegularExpressions.Regex("[^0-9]");//on garde que les chiffres dans la chaine
            }
            //test du boleen si oui on rajoute le caractére '+'
            if (plusEnPremier)
            {
                resultatfinal = "+" + myRegex.Replace(resultat1, "");
            }
            else
            {
                resultatfinal = myRegex.Replace(resultat1, "");
            }

            return resultatfinal; //renvoi la chaine modifiée
        }