Ejemplo n.º 1
0
 public void Insert(string tbl, string values)
 {
     if (tbl != null)
     {
         if (this._connector._DirectExecute)
         {
             this._connector.OpenScript(null);
         }
         string s = "Table:" + tbl + ".Insert";
         this._connector.Push(s);
         foreach (string str2 in values.Split(new char[] { ';' }))
         {
             string[] strArray = str2.Split(new char[] { ',' });
             strArray[0] = KMString.trim(strArray[0].ToLower());
             strArray[1] = KMString.trim(strArray[1]);
             this._connector.Push(strArray[0]);
             this._connector.Push(strArray[1]);
         }
         this._connector.Push("endLine");
         this._connector.AddFunction();
         if (this._connector._DirectExecute)
         {
             this._connector.DoIt();
         }
     }
 }
Ejemplo n.º 2
0
 public void Insert(string tbl, string[] values)
 {
     if (tbl != null)
     {
         if (this._connector._DirectExecute)
         {
             this._connector.OpenScript(null);
         }
         string s = "Table:" + tbl + ".Insert";
         this._connector.Push(s);
         for (int i = 0; i < (values.Length - 1); i += 2)
         {
             string str2 = values[i].ToLower();
             string str3 = values[i + 1];
             str2 = KMString.trim(str2);
             str3 = KMString.trim(str3);
             this._connector.Push(str2);
             this._connector.Push(str3);
         }
         this._connector.Push("endLine");
         this._connector.AddFunction();
         if (this._connector._DirectExecute)
         {
             this._connector.DoIt();
         }
     }
 }
Ejemplo n.º 3
0
 public Connector(string aName, bool log)
 {
     this.kmstring    = new KMString();
     this.localParams = new ArrayList();
     this._name       = aName;
     this.Initialize(log);
 }
Ejemplo n.º 4
0
 public Connector(bool log)
 {
     this.kmstring    = new KMString();
     this.localParams = new ArrayList();
     this._name       = "Connector#" + ID++;
     this.Initialize(log);
 }
Ejemplo n.º 5
0
        public void AddFunction(string[] param)
        {
            int index = 0;


            while (index < param.Length)
            {
                if (index == param.Length)
                {
                    return;
                }
                this.toSend = this.toSend + param[index] + "(";
                index++;
                while (!param[index].Equals("endLine"))
                {
                    if (index >= param.Length)
                    {
                        break;
                    }
                    string str = param[index]; //.ToLower();
                    if (!str.Equals("null") && !str.Equals("default"))
                    {
                        str = KMString.ToGPBinary(str);
                    }
                    this.toSend = this.toSend + str;
                    index++;
                    if (!param[index].Equals("endLine"))
                    {
                        this.toSend = this.toSend + ", ";
                    }
                }
                index++;
                this.toSend = this.toSend + "); ";
            }
        }
Ejemplo n.º 6
0
        public bool ExecuteCommand(string str)
        {
            bool error = false;

            str         = KMString.stringToGPBinary(str, error);
            this.toSend = this.KMScriptSession + " " + str;
            error       = this.ExecuteScript();
            return(error);
        }
 public ServerResponse()
 {
     this._lines     = new ArrayList();
     this._columns   = new ArrayList();
     this._data      = new ArrayList();
     this._names     = new ArrayList();
     this._types     = new ArrayList();
     this._sizes     = new ArrayList();
     this.session_id = "-1";
     this.kmstring   = new KMString();
 }
Ejemplo n.º 8
0
        public bool ExecuteScript(string script)
        {
            while (script.Contains("\n") || script.Contains("\r"))
            {
                script = script.Replace('\r', ' ').Replace('\n', ' ');
            }
            string[] strArray = script.Split(new char[] { ';' });
            this.toSend = "";
            bool error = false;

            for (int i = 0; i < strArray.Length; i++)
            {
                if (!string.IsNullOrEmpty(strArray[i]))
                {
                    this.toSend = this.toSend + KMString.stringToGPBinary(strArray[i] + "; ", error);
                }
            }
            this.toSend = this.KMScriptSession + " " + this.toSend;
            return(this.ExecuteScript());
        }
Ejemplo n.º 9
0
        public static void RawStringToGPBinaryString(string inStr, ref string outStr)
        {
            int idx = 0;
            //inStr = Encoding.UTF32.GetString(Encoding.Unicode.GetBytes(inStr));
            string command, p = "";

            System.Char c;
            outStr = "";
            int start = 0, end = 0;

            inStr = inStr.Replace("\n", " ");
            inStr = inStr.Replace("\r", " ");

            while (idx < inStr.Length)
            {
                while (idx < inStr.Length && (c = inStr[idx]) == ' ')
                {
                    idx++;
                }
                if (idx >= inStr.Length)
                {
                    break;
                }
                start = idx;
                while (idx < inStr.Length && (c = inStr[idx]) != '(')
                {
                    idx++;
                }
                if (idx >= inStr.Length - 1)
                {
                    idx--;
                }
                end     = idx;
                command = inStr.Substring(start, end - start + 1);
                outStr += command;
                idx++;
                while (idx < inStr.Length && inStr[idx] == ' ')
                {
                    idx++;
                }
                // les paramètres
                while (idx < inStr.Length)
                {
                    if (inStr[idx] == '"') // on commence un texte
                    {
                        idx++;
                        p = "";
                        while (idx < inStr.Length && (c = inStr[idx]) != '"')
                        {
                            p += c;
                            idx++;
                        }
                        if (idx >= inStr.Length - 1)
                        {
                            break;
                        }
                        p = GetUnicodeString(p);
                        p = KMString.ToGPBinary(p);
                        idx++;
                        outStr += p; // "\"" + p + "\"";

                        while (idx < inStr.Length && (c = inStr[idx]) == ' ')
                        {
                            idx++;
                        }
                        // premier cas on a terminé la ligne de commande
                        if ((c = inStr[idx]) == ')')
                        {
                            outStr += "); ";
                            while (idx < inStr.Length && (c = inStr[idx]) != ';') // on cherche la fin de la ligne
                            {
                                idx++;
                            }
                            if (idx >= inStr.Length - 1)
                            {
                                break;
                            }
                        }
                        outStr += ", ";
                    }
                    //sinon on process le prochain paramètre
                    p = "";
                    while (idx < inStr.Length && (c = inStr[idx]) != ',')
                    {
                        if (c == ')')
                        {
                            break;
                        }
                        p += c;
                        idx++;
                    }
                    if (!string.IsNullOrEmpty(p))
                    {
                        p = KMString.ToGPBinary(p);
                    }
                    if ((c = inStr[idx]) == ')')
                    {
                        outStr += p;
                        idx--;
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(p))
                        {
                            outStr += p + ", ";
                        }
                    }
                    idx++;
                    if (idx >= inStr.Length - 1)
                    {
                        break;
                    }
                    while (idx < inStr.Length && inStr[idx] == ' ')
                    {
                        idx++;
                    }
                    if (idx >= inStr.Length - 1)
                    {
                        break;
                    }
                    if (inStr[idx] == ')')
                    {
                        outStr += "); ";
                        idx++;
                    }
                    if (idx >= inStr.Length - 1)
                    {
                        break;
                    }
                    while (idx < inStr.Length && inStr[idx] == ' ')
                    {
                        idx++;
                    }
                    if (idx >= inStr.Length - 1)
                    {
                        break;
                    }
                    if (inStr[idx] == ';')
                    {
                        //outStr += "; ";
                        idx++;
                        break;
                    }
                }
                while (idx < inStr.Length && inStr[idx] == ' ')
                {
                    idx++;
                }
                if (idx >= inStr.Length - 1)
                {
                    break;
                }
            }
        }
Ejemplo n.º 10
0
        public static String cleantext(String s)
        {
            //s = suppBaliseFast("{|","|}", s);
            //s = suppBaliseFast("{{","}}", s);
            // s = s.replace("#REDIRECTION","");
            //   s = s.replace("#REDIRECT","");
            //( "(<my:string>).*?(</my:string>)" , "$1whatever$2" );
            s = s.Replace("\n", "");

            s = s.Replace("{|", "<clean>");
            s = s.Replace("|}", "<cleanend>");

            s = s.Replace("{{", "<clean2>");
            s = s.Replace("}}", "<cleanend2>");

            string pattern = "(&lt;).*?(&gt;)";

            s       = System.Text.RegularExpressions.Regex.Replace(s, pattern, "$1 $2");
            pattern = "(<clean>).*?(<cleanend>)";
            s       = System.Text.RegularExpressions.Regex.Replace(s, pattern, "$1 $2");
            pattern = "(<clean2>).*?(<cleanend2>)";
            s       = System.Text.RegularExpressions.Regex.Replace(s, pattern, "$1 $2");
            //s = s.replaceAll("(\\{|).*?(\\|})", "$1 $2");
            s = s.Replace("<clean>", " ");
            s = s.Replace("<cleanend>", " ");
            s = s.Replace("<clean2>", " ");
            s = s.Replace("<cleanend2>", " ");
            //s = s.replaceAll("({|).*?(|})", "$1 $2");

            //s = s.replaceAll("({).*?(})", "$1 $2");
            //s = s.replaceAll("({).*?(\\})", "$1+$2");
            // s = s.replaceAll("(\\{\\{).*?(\\}\\})", "$1 $2");
            pattern = "(&lt;).*?(&gt;)";
            s       = System.Text.RegularExpressions.Regex.Replace(s, pattern, " ");
            //s = s.replaceAll("(\\{).*?(\\})", " ");

            //s = s.replaceAll("(\\{|).*?(|\\})", " ");
            //s = s.replaceAll("({{).*?(}})", " ");
            //s = s.replaceAll("(&quot;).*?(&quot;)", "beurkbeurk");
            s = s.Replace("'''", " ");
            s = s.Replace("’", "'");

            //ÀàÁáÂâÃãÄäÅåÆæÇçÈèÉéÊêËëÌìÍíÎîÏïÐðÑñÒòÓóÔôÕõÖöØøÙùÚúÛûÜ üÝýÞþ


            s = s.Replace("image:", " ");
            s = s.Replace("Image:", " ");
            s = s.Replace("thumb ", " ");
            s = s.Replace("class=", " ");
            s = s.Replace("style=", " ");
            s = s.Replace("align=", " ");
            s = s.Replace("id=", " ");
            s = s.Replace("class=", " ");
            s = s.Replace("amp;lt;", "");
            s = s.Replace("|", " ");
            s = s.Replace("*", " ");
            s = s.Replace("[[", " ");
            s = s.Replace("]]", " ");
            s = s.Replace("]", " ");
            s = s.Replace("[", " ");
            s = s.Replace("????", " ");
            s = s.Replace("???", " ");
            s = s.Replace("??", " ");
            s = s.Replace(" #39;", " ");
            s = s.Replace(" #91;", " ");
            s = s.Replace(" amp;gt", " ");
            s = s.Replace("&amp;", " ");
            s = s.Replace("< revision>", " ");
            s = s.Replace("&quot;", " ");
            s = s.Replace("</text>", " ");
            s = s.Replace("Modéle:", " ");
            s = s.Replace("Catégorie:", " ");
            s = s.Replace("Wikipédia:", " ");
            s = s.Replace("== Définition ==", " ");
            s = s.Replace("{{Infobox", " ");
            s = s.Replace("{{homonymie", " ");
            s = s.Replace("{{Homonymie", " ");
            s = s.Replace("Lumière sur", " ");
            s = s.Replace("Voir homonymes", " ");
            s = s.Replace("voir homonymes", " ");
            s = s.Replace("Voir famille", " ");
            s = s.Replace("Taxobox Début", " ");
            s = s.Replace("Taxobox Fin", " ");
            s = s.Replace("Taxobox ", " ");
            s = s.Replace("Fichier:", " ");
            s = s.Replace("{{", " ");
            s = s.Replace("}}", " ");
            s = s.Replace("/", " ");
            s = s.Replace("\\", " ");
            s = KMString.trim(s);
            return(s);
        }
        public void AnalyseLine(string line)
        {
            if (!string.IsNullOrEmpty(line) && (line.Length != 0))
            {
                ArrayList list  = new ArrayList();
                ArrayList list2 = new ArrayList();
                ArrayList list3 = new ArrayList();
                Dictionary <string, ArrayList> dictionary = new Dictionary <string, ArrayList>();
                string[] strArray;
                int      num3 = -1;
                int      num4 = -1;
                while (line.StartsWith(" ") || line.EndsWith(" "))
                {
                    line = line.Trim();
                }
                int index = line.IndexOf('<');
                // attention au cas où une colonne contient "null" !!!!
                int indexNull = line.ToLower().IndexOf("null");
                if (indexNull != -1)
                {
                    if (indexNull < index)
                    {
                        index = indexNull;
                    }
                }
                if (index == -1)
                {
                    strArray = line.Split(new char[] { ' ' });
                    num3     = int.Parse(strArray[0]);
                    num4     = int.Parse(strArray[1]);
                    this._lines.Add(num3);
                    this._columns.Add(num4);
                    this._types.Add(list);
                    this._names.Add(list2);
                    this._sizes.Add(list3);

                    if (num3 == 0 && num4 == 0)
                    {
                        this._data.Add(dictionary);
                        this.mScriptSize++;
                        return;
                    }
                    strArray = line.Split(new char[] { ' ' });
                }
                else
                {
                    index--;
                    strArray = line.Substring(0, index).Split(new char[] { ' ' });
                }

                if (num3 == -1 && num4 == -1)
                {
                    num3 = int.Parse(strArray[0]);
                    num4 = int.Parse(strArray[1]);
                    this._lines.Add(num3);
                    this._columns.Add(num4);
                    this._types.Add(list);
                    this._names.Add(list2);
                    this._sizes.Add(list3);
                }

                int num5 = 2;
                // on récupère les infos de type et de noms des variables de la ligne courante
                for (int i = 0; i < num4; i++)
                {
                    int num7 = int.Parse(strArray[num5]);
                    num5++;
                    list.Add(Connector.KMTypeLabel[num7]);
                    num7 = int.Parse(strArray[num5]);
                    list3.Add(num7);
                    num5++;
                    list2.Add(strArray[num5]);
                    num5++;
                }

                if (index != -1)
                {
                    strArray = new KMString(line.Substring(index)).Split();

                    for (index = 0; index < list2.Count; index++)
                    {
                        ArrayList list4 = new ArrayList();
                        for (int j = 0; j < num3; j++)
                        {
                            num5 = index + (j * num4);
                            list4.Add(strArray[num5]);
                        }
                        dictionary.Add((string)list2[index], list4);
                    }
                }

                this._data.Add(dictionary);
                this.mScriptSize++;
            }
        }
        // obsolète !!!!
        public void Analyze(string ret)
        {
            string[] strArray;
            int      num2 = 0;

            this.mError        = false;
            this.mErrorMessage = "";
            this.mScriptSize   = 0;
            this.toReceive     = ret;
            while (this.toReceive.StartsWith(" ") || this.toReceive.EndsWith(" "))
            {
                this.toReceive = this.toReceive.Trim();
            }
            string toReceive = this.toReceive;
            // on élimine toutes les lignes 0 1 0 0  ; qui ne servent à rien



            // Console.WriteLine("Analyze toReceive = '" + this.toReceive + "'");

            int indexBegin        = toReceive.IndexOf('<');
            int pointvirguleIndex = toReceive.IndexOf(';');
            int indexEnd          = toReceive.IndexOf("/>");

            if (((pointvirguleIndex == -1) || (indexBegin == -1)) || (indexEnd == -1))
            {
                strArray = new string[] { this.toReceive };
            }
            else
            {
                bool flag = false;

                List <int> list = new List <int>();
                int        jj = 0, kk = 0, ll = -1;

                int current = 0;
                // on élimine toutes les lignes vides

                while (!flag)
                {
                    jj = toReceive.IndexOf("0 1 0 0  ;", current);
                    kk = toReceive.IndexOf("0 0  ;", current);

                    if (jj == -1 && kk == -1)  // il n'y a plus de lignes vides canoniques mais on cherche une ligne avec un tableau de 0 lignes
                    {
                        ll = toReceive.IndexOf("0 ", current);
                        char llm2 = ' ';
                        if (ll != -1 && current > 2)
                        {
                            llm2 = toReceive[ll - 2];
                        }
                        if (ll != -1 && ll < pointvirguleIndex && llm2 == ';')
                        {
                            current = toReceive.IndexOf(";", ll) + 1;
                            list.Add(current - 1);
                            goto nextPattern;
                        }
                    }

                    // existe t il un ';' après le ';' courant ?
                    int tmp = toReceive.IndexOf(";", pointvirguleIndex + 1);
                    if (tmp != -1)
                    {
                        // s'agit il de "; 0 0  ;" ou "; 0 1 0 0  ;" ???
                        if (kk - pointvirguleIndex > 4 || jj - pointvirguleIndex > 4)
                        // non
                        {
                            int tmpb = toReceive.IndexOf("/>", tmp);
                            // si ce ';' est avant un "/>" on passe
                            if (tmp < tmpb)
                            {
                                // on cherche ts les ';' qui suive le ';' courant avant le "/>"
                                int t = -1;
                                while (tmp != -1 && tmp < tmpb)
                                {
                                    t   = tmp;
                                    tmp = toReceive.IndexOf(";", tmp + 1);
                                }
                                if (t != -1)
                                {
                                    tmp = t;
                                }

                                current = tmp + 1;
                                goto nextPattern;
                            }
                        }
                    }

                    if (jj != -1 && (pointvirguleIndex > 0 && jj > 0 && jj < pointvirguleIndex))  // on a une ligne qui ne sert à rien
                    {
                        list.Add(jj + 10);
                        current = jj + 11;
                        goto nextPattern;
                    }
                    else if (kk != -1 && (pointvirguleIndex > 0 && kk > 0 && kk < pointvirguleIndex))
                    {
                        list.Add(kk + 6);
                        current = kk + 7;
                        goto nextPattern;
                    }
                    else
                    {
                        // 1er cas il existe un "/>" après le ';' courant
                        int tmp1 = toReceive.IndexOf("/>", pointvirguleIndex + 1);
                        if (tmp1 != -1)
                        {
                            tmp = toReceive.IndexOf(";", pointvirguleIndex + 1);
                            // on cherche ts les ';' qui suive le ';' courant avant le "/>"
                            int t = -1;
                            while (tmp != -1 && tmp < tmp1)
                            {
                                t   = tmp;
                                tmp = toReceive.IndexOf(";", tmp + 1);
                            }
                            if (t != -1)
                            {
                                tmp = t;
                            }

                            if (kk != -1 || jj != -1)
                            {
                                if (kk > pointvirguleIndex && kk < tmp || jj > pointvirguleIndex && jj < tmp)
                                {
                                    // do nothing
                                }
                                else
                                {
                                    current = tmp + 1;
                                    goto nextPattern;
                                }
                            }
                        }
                        // 2eme cas  '<' ';' '/>'
                        if (indexBegin > 0 && indexEnd > 0 && pointvirguleIndex > 0 && (indexBegin < pointvirguleIndex && pointvirguleIndex < indexEnd))
                        {
                            // ';' est dans une chaine de caractères, on passe
                            current = indexEnd + 2;
                            goto nextPattern;
                        }
                        // 3eme cas '/>' ';' '<'
                        if (indexBegin > 0 && indexEnd > 0 && pointvirguleIndex > 0 && (indexEnd < pointvirguleIndex && pointvirguleIndex < indexBegin))
                        {
                            // ';' est dans une chaine de caractères, on passe
                            current = pointvirguleIndex + 1;
                            list.Add(pointvirguleIndex);
                            goto nextPattern;
                        }
                        // 4eme cas '<' '/>' ';'
                        if (indexBegin > 0 && indexEnd > 0 && pointvirguleIndex > 0 && (indexBegin < indexEnd && indexEnd < pointvirguleIndex))
                        {
                            // ';' est il dans une chaine de caractères ?
                            tmp1 = toReceive.IndexOf('<', indexBegin + 1);
                            // on cherche le '<' le plus proche de ';'
                            jj = -1;
                            while (tmp1 != -1 && tmp1 < pointvirguleIndex)
                            {
                                jj   = tmp1;
                                tmp1 = toReceive.IndexOf('<', tmp1 + 1);
                            }
                            if (jj != -1)
                            {
                                tmp1 = jj;
                            }
                            int tmp2 = toReceive.IndexOf("/>", pointvirguleIndex);
                            int tmp3 = toReceive.IndexOf("/>", indexBegin);
                            int tmp4 = -1;
                            if (tmp1 != -1)
                            {
                                tmp4 = toReceive.IndexOf("/>", tmp1);
                            }
                            // 1er cas
                            // '<'  '/>' ';'
                            if (tmp4 != -1 && tmp4 < pointvirguleIndex)   // oui on passe
                            {
                                current = pointvirguleIndex + 1;
                                list.Add(pointvirguleIndex);
                                goto nextPattern;
                            }
                            //else if ( tmp2 != -1 )
                            // 1er cas
                            // '<' ';' '/>'
                            if (tmp2 != -1 && tmp1 != -1 && tmp1 < tmp2)  // && tmp3 >= tmp2) // oui on passe
                            {
                                current = tmp2 + 2;
                                goto nextPattern;
                            }

                            // non

                            //if ( tmp1 * tmp2 != 1 && pointvirguleIndex < tmp1 && pointvirguleIndex < tmp2)
                            //{
                            current = pointvirguleIndex + 1;
                            list.Add(pointvirguleIndex);
                            //}
                        }
                    }

nextPattern:

                    pointvirguleIndex = toReceive.IndexOf(';', current);
                    if (pointvirguleIndex == -1)
                    {
                        break;
                    }
                    indexBegin = toReceive.IndexOf('<', current);
                    if (indexBegin == -1)
                    {
                        break;
                    }
                    indexEnd = toReceive.IndexOf("/>", indexBegin);
                    if (((indexBegin == -1) && (pointvirguleIndex == -1)) && (indexEnd == -1))
                    {
                        flag = true;
                    }
                }
                strArray = new string[list.Count];
                int num8 = 0;
                for (int i = 0; i < list.Count; i++)
                {
                    //Console.WriteLine("num8 " + num8 + " list[i] = " + (int) (list[i] - num8 + 1) );
                    strArray[i] = this.toReceive.Substring(num8, list[i] - num8 + 1);
                    num8        = list[i] + 1;
                }
            }
            if (strArray.Length == 0)
            {
                strArray = new string[1] {
                    this.toReceive
                };
            }

            string[] strArray2 = strArray[0].Split(new char[] { ' ' });
            this.session_id = strArray2[0];
            // Console.WriteLine("session id received from mARC server : " + this.session_id);
            num2 = int.Parse(strArray2[1]);
            this.mErrorMessage = "Ok";
            if (num2 == 0)
            {
                this.mErrorMessage = " error code : ";
                this.mErrorMessage = this.mErrorMessage + strArray2[2];
                this.mErrorMessage = this.mErrorMessage + " '";
                toReceive          = "";
                for (int j = 3; j < strArray2.Length; j++)
                {
                    toReceive = toReceive + strArray2[j] + " ";
                }
                strArray2 = new KMString(toReceive).Split();
                if (strArray2 != null)
                {
                    this.mErrorMessage = this.mErrorMessage + strArray2[0];
                }
                this.mError = true;
            }
            else if (this._analyse)
            {
                if (strArray[0].IndexOf('<') != -1)
                {
                    int num11 = strArray[0].IndexOf(' ');
                    strArray[0] = strArray[0].Substring(num11 + 1);
                    num11       = strArray[0].IndexOf(' ');
                    strArray[0] = strArray[0].Substring(num11 + 1);
                    // Console.WriteLine("on analyse la ligne 0 : '" + strArray[0] + "'");
                    this.AnalyseLine(strArray[0]);
                }
                else
                {
                    //ligne vide
                    this._lines.Add(0);
                    this._columns.Add(0);
                    ArrayList list  = new ArrayList();
                    ArrayList list3 = new ArrayList();
                    ArrayList list2 = new ArrayList();
                    this._types.Add(list);
                    this._names.Add(list2);
                    this._sizes.Add(list3);
                    Dictionary <string, ArrayList> dictionary2 = new Dictionary <string, ArrayList>();
                    this._data.Add(dictionary2);
                    mScriptSize++;
                }
                for (int k = 1; k < strArray.Length; k++)
                {
                    this.AnalyseLine(strArray[k]);
                }
            }
        }