public static decimal ParseDecimal(string input)
        {
            var decRegex = new System.Text.RegularExpressions.Regex("(?<LEADINGZERO>[0]*)(?<VALUE>[1-9]{1}[0-9]*)*");
            var match    = decRegex.Match(input);

            if (match.Success &&
                decRegex.GetGroupNames().Contains("VALUE") &&
                match.Groups["VALUE"].Success)
            {
                return(Convert.ToInt32(match.Groups["VALUE"].Value) / new Decimal(100));
            }
            if (match.Success &&
                decRegex.GetGroupNames().Contains("LEADINGZERO") &&
                match.Groups["LEADINGZERO"].Success)
            {
                return(new Decimal(0.00));
            }

            TraceProvider.Logger.TraceError(string.Format("Unable to parse <{0}> as decimal.", input));

            throw new Exception(string.Format("Unable to parse <{0}> as decimal.", input));
        }
Example #2
0
        protected override void BeginProcessing()
        {
            if (Where is ScriptBlock)
            {
                whereIsScriptBlock = true;
                whereAsScriptBlock = (ScriptBlock)Where;
            }
            else if (Where != null && !String.IsNullOrWhiteSpace(Where.ToString()))
            {
                whereIsString = true;
                whereAsString = Where.ToString();
            }
            if (Value is ScriptBlock)
            {
                valueIsScriptBlock = true;
                valueAsScriptBlock = (ScriptBlock)Value;
            }

            if (Match != null)
            {
                matchRegex      = new System.Text.RegularExpressions.Regex(Match, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
                matchGroupNames = matchRegex.GetGroupNames();
            }
        }
Example #3
0
        public async void conectar(bool enBaseDatos = true)
        {
            try {
                await cliente.ConnectAsync(new Uri("ws://irc-ws.chat.twitch.tv"), cancellationToken);

                if (cliente.State == System.Net.WebSockets.WebSocketState.Open)
                {
                    byte[]   bufferByte = new byte[6000];
                    int      estado     = 0;
                    string[] ESPERAS    = { ":tmi.twitch.tv 376 " + canal + " :>", ":End of /NAMES list" };
                    System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(@"(.*)\!(.*)@(.*)\.tmi\.twitch\.tv (PRIVMSG|PART) #(.*) :(.*)", System.Text.RegularExpressions.RegexOptions.RightToLeft);

                    ArraySegment <byte> buffer = new ArraySegment <byte>(bufferByte);
                    await cliente.SendAsync(new ArraySegment <byte>(arrayBytes("PASS oauth:" + oauth)), System.Net.WebSockets.WebSocketMessageType.Text, true, cancellationToken);

                    await cliente.SendAsync(new ArraySegment <byte>(arrayBytes("NICK " + canal)), System.Net.WebSockets.WebSocketMessageType.Text, true, cancellationToken);

                    //cliente.Options.
                    //a cliente.ReceiveAsync(buffer, cancellationToken);
                    //envioDatos.
                    System.Net.WebSockets.WebSocketReceiveResult resultado = await cliente.ReceiveAsync(buffer, cancellationToken);

                    while (cliente.State == System.Net.WebSockets.WebSocketState.Open)
                    {
                        string[] respuestas = arrayString(bufferByte, resultado.Count).Replace("\n", "\r").Replace("\r\r", "\r").Split('\r');
                        for (int i = 0; i < respuestas.Length; i++)
                        {
                            string respuesta = respuestas[i];
                            if (respuesta == ESPERAS[0])
                            {
                                estado++;
                            }
                            string mensaje = "";
                            if (respuesta.Length > 0)
                            {
                                switch (estado)
                                {
                                case 1:
                                    estado++;
                                    mensaje = "JOIN #" + canal;
                                    await cliente.SendAsync(new ArraySegment <byte>(arrayBytes(mensaje)), System.Net.WebSockets.WebSocketMessageType.Text, true, cancellationToken);

                                    break;
                                }
                                if (respuesta == "PING :tmi.twitch.tv")
                                {
                                    await cliente.SendAsync(new ArraySegment <byte>(arrayBytes("PONG :tmi.twitch.tv")), System.Net.WebSockets.WebSocketMessageType.Text, true, cancellationToken);
                                }
                                else
                                {
                                    if (estado > 0)
                                    {
                                        //System.Diagnostics.Trace.WriteLine(respuesta);
                                        //System.Diagnostics.Trace.WriteLine(toxicidad(respuesta));
                                        while (mensajesEnviar.Count > 0)
                                        {
                                            string mensajeTexto = "PRIVMSG #" + Configuracion.parametro("canal") + " :" + mensajesEnviar[0];
                                            await cliente.SendAsync(new ArraySegment <byte>(arrayBytes(mensajeTexto)), System.Net.WebSockets.WebSocketMessageType.Text, true, cancellationToken);

                                            mensajesEnviar.RemoveAt(0);
                                        }
                                        System.Text.RegularExpressions.Match coincidencias = regEx.Match(respuesta);
                                        if (coincidencias.Success)
                                        {
                                            string[] partes = regEx.GetGroupNames();
                                            //System.Text.RegularExpressions.Group grp

                                            /*foreach (string nombre in partes) {
                                             * System.Text.RegularExpressions.Group grp = coincidencias.Groups[nombre];
                                             * //Console.WriteLine("   {0}: '{1}'", name, grp.Value);
                                             * }*/
                                            System.Diagnostics.Trace.WriteLine((coincidencias.Groups["0"].Value));
                                            System.Diagnostics.Trace.WriteLine("" + (coincidencias.Groups["2"].Value) + " = " + (coincidencias.Groups["6"].Value));
                                            string aliasUsuario = coincidencias.Groups["2"].Value.ToLower();
                                            long   idUsuario    = -1;
                                            try {
                                                Datos usuarios = BD.consulta("select id,avatar from usuarios where alias='" + aliasUsuario + "'");
                                                if (usuarios.Length == 0)
                                                {
                                                    String avatar  = null;
                                                    JSON   usuario = infoUsuario(aliasUsuario);
                                                    try {
                                                        avatar = usuario["data"][0]["profile_image_url"].ToString();
                                                    } catch { }

                                                    int numeroAfectados = BD.ejecutar("insert into usuarios (alias, avatar, nombre, userID) values ('" + aliasUsuario + "'," + (avatar != null ? "'" + avatar + "'" : "null") + ",'" + usuario["data"][0]["display_name"].ToString() + "','" + usuario["data"][0]["id"].ToString() + "')");
                                                    if (numeroAfectados == 1)
                                                    {
                                                        idUsuario = BD.id;
                                                    }
                                                }
                                                else
                                                {
                                                    if (usuarios[0]["avatar"] == null || usuarios[0]["avatar"].ToString().Length == 0)
                                                    {
                                                        JSON   usuario = infoUsuario(aliasUsuario);
                                                        string avatar  = usuario["data"][0]["profile_image_url"].ToString();
                                                        BD.ejecutar("update usuarios set avatar='" + avatar + "' where alias='" + aliasUsuario + "'");
                                                    }
                                                    idUsuario = long.Parse(usuarios[0]["id"].ToString());
                                                }
                                                string texto      = coincidencias.Groups["6"].Value;
                                                double puntuacion = toxicidad(texto);

                                                texto = tratarMensaje(texto, puntuacion);
                                                if (enBaseDatos)
                                                {
                                                    try {
                                                        texto = texto.Replace("\"", "\\\"").Replace("'", "''");
                                                        BD.ejecutar("insert into mensajes (idEstado, idUsuario, mensaje,puntuacion) values (1," + idUsuario + ", '" + texto + "'," + puntuacion.ToString().Replace(",", ".") + ")");
                                                    }catch (Exception ex1) {
                                                        BD.ejecutar("insert into mensajes (idEstado, idUsuario, mensaje,puntuacion) values (1," + idUsuario + ", '" + aUTF8(texto) + "'," + puntuacion.ToString().Replace(",", ".") + ")");
                                                    }
                                                }
                                            } catch (Exception ex) {
                                                LOG.debug(ex.Message, "Conectar a twitch");
                                            }
                                        }
                                    }
                                }
                            }
                        }
                        resultado = await cliente.ReceiveAsync(buffer, cancellationToken);
                    }
                    //resultado.
                    //System.Diagnostics.Trace.WriteLine(arrayString(bufferByte));
                }
            } catch (Exception ex) {
                System.Diagnostics.Trace.WriteLine(ex.Message);
            }
        }
Example #4
0
        public Program(string[] arg)
        {
            /*	Pattern regExPattern =
                "^\\s*" +
                new Group("def",
                    new Group("identifier", Provider.identifier) +
                    "\\s*\\(" +
                    new Group("params", "[a-zA-Z_0-9*\\+/!&|%()=,\\s]*") +
                    "\\)\\s*") +
                ";";*/
            //	Pattern regExPattern = new Group("operator", "\\+|-|/|\\*|==|!=|>=|<=|>|<|\\||\\|\\|");

            Pattern regExPattern =
                "^\\s*" +
                new Group("def", "(\\+|\\*)");

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

            System.Text.RegularExpressions.Match match = regEx.Match("  tetsfunc(2134, 1412);");
            if (!match.Success)
                Console.WriteLine ("No match found.");
            else
            {
                foreach (String gname in regEx.GetGroupNames())
                {
                    if (match.Groups[gname].Success)
                        Console.WriteLine(gname + ": "+match.Groups[gname]);
                    else
                        Console.WriteLine(gname + ": not found");
                }
            }

            Console.WriteLine();
            Console.WriteLine();

            //	Console.ReadKey();
            //	return;

            //Int32 foo = 10.2e12;

            string test = File.ReadAllText ("test.c");
            Document doc = new Document(test);

            foreach (FunctionDeclaration node in doc.Functions.Values)
            {
                Console.WriteLine("function "+node.Identifier);

                if (node.HasBody)
                {
                    foreach (ISyntaxNode child in node.Body)
                    {
                        Console.WriteLine(child.ToString());
                    }
                }
            }/*
            foreach (VariableDeclaration node in doc.Variables.Values)
            {
                Console.WriteLine("variable " + node.Identifier);
            }
            foreach (ConstantDeclaration node in doc.Constants.Values)
            {
                Console.WriteLine("constant " + node.Identifier);
            }*/

            Console.ReadKey();
        }
Example #5
0
        public Program(string[] arg)
        {
            /*	Pattern regExPattern =
             *              "^\\s*" +
             *              new Group("def",
             *                      new Group("identifier", Provider.identifier) +
             *                      "\\s*\\(" +
             *                      new Group("params", "[a-zA-Z_0-9*\\+/!&|%()=,\\s]*") +
             *                      "\\)\\s*") +
             *              ";";*/
            //	Pattern regExPattern = new Group("operator", "\\+|-|/|\\*|==|!=|>=|<=|>|<|\\||\\|\\|");


            Pattern regExPattern =
                "^\\s*" +
                new Group("def", "(\\+|\\*)");

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

            System.Text.RegularExpressions.Match match = regEx.Match("  tetsfunc(2134, 1412);");
            if (!match.Success)
            {
                Console.WriteLine("No match found.");
            }
            else
            {
                foreach (String gname in regEx.GetGroupNames())
                {
                    if (match.Groups[gname].Success)
                    {
                        Console.WriteLine(gname + ": " + match.Groups[gname]);
                    }
                    else
                    {
                        Console.WriteLine(gname + ": not found");
                    }
                }
            }

            Console.WriteLine();
            Console.WriteLine();

            //	Console.ReadKey();
            //	return;

            //Int32 foo = 10.2e12;

            string   test = File.ReadAllText("test.c");
            Document doc  = new Document(test);

            foreach (FunctionDeclaration node in doc.Functions.Values)
            {
                Console.WriteLine("function " + node.Identifier);

                if (node.HasBody)
                {
                    foreach (ISyntaxNode child in node.Body)
                    {
                        Console.WriteLine(child.ToString());
                    }
                }
            }            /*
                          * foreach (VariableDeclaration node in doc.Variables.Values)
                          * {
                          *     Console.WriteLine("variable " + node.Identifier);
                          * }
                          * foreach (ConstantDeclaration node in doc.Constants.Values)
                          * {
                          *     Console.WriteLine("constant " + node.Identifier);
                          * }*/


            Console.ReadKey();
        }