Exemplo n.º 1
0
 public Form1()
 {
     InitializeComponent();
     clsXMLSettings xml      = new clsXMLSettings();
     xmlSettings    settings = xml.ReadSettings();
     clsWeb         web      = new clsWeb(settings);
 }
Exemplo n.º 2
0
        public xmlSettings ReadSettings()
        {
            xmlSettings settings = new xmlSettings();

            if (!File.Exists(xmlSettingsFile))
            {
                settings.success      = false;
                settings.errorMessage = "File not found (" + xmlSettingsFile + ")";
                return(settings);
            }
            string        xmlElement = "";
            XmlTextReader reader     = new XmlTextReader(xmlSettingsFile);

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XmlNodeType.Element:
                    xmlElement = reader.Name;
                    //MessageBox.Show(objXmlTextReader.Name);
                    break;

                case XmlNodeType.Text:
                    switch (xmlElement)
                    {
                    case "SERVER":
                        settings.serverName = reader.Value;
                        Server = settings.serverName;
                        break;

                    case "DATABASE":
                        settings.dbName = reader.Value;
                        break;

                    case "PORT":
                        settings.dbPort = reader.Value;
                        break;

                    case "USER":
                        settings.userName = reader.Value;
                        break;

                    case "PWD":
                        settings.password = reader.Value;
                        break;

                    case "TIMER":
                        settings.timer = reader.Value;
                        break;
                    }
                    break;
                }
            }
            reader.Close();
            settings.success      = true;
            settings.errorMessage = "";
            return(settings);
        }
 public clsWeb(xmlSettings xmlsetting)
 {
     settings   = xmlsetting;
     KeyEncoded = begin();
     // DecryptedValue = Decode();         //Testing
 }
        public Boolean Decode()
        {
            string[] keyarray   = new string[100];
            string[] valuearray = new string[100];
            Verified_Customer = false;
            int j = 0, k = 0, startindex;

            response = clsWeb.responseFromServer;

            // response = "bZmlyYXxic3R4ffGN8bmFtZA10g==ZXxzZWNvbmRfbmFtZXxiaXJ0aF9wbGFjZXxkYXRlX29mX2JpcnRoh3";      //testing
            //response = "dZmlycYXxi$3Rf5bmFtZXxzZWNvb7gmRfbmFtZQ==$$$h1";                       //test

            if (!((response == "0") || (response == "1") || (response == null)))
            {
                clsXMLSettings clsxml = new clsXMLSettings();
                try
                {
                    settings          = clsxml.ReadSettings();
                    DBInfo.ServerName = settings.serverName;
                    DBInfo.DBName     = settings.dbName;
                    DBInfo.DBPort     = settings.dbPort;
                    DBInfo.DBUser     = settings.userName;
                    DBInfo.DBPWD      = settings.password;
                    password          = DBInfo.DBName;

                    connectionstring = clsDBConnection.CreateConnectionString(DBInfo);
                    MySqlConnection cnn = new MySqlConnection(connectionstring);
                    cnn.Open();
                    if (Verified_Customer)
                    {
                        // clsDBConnection.updateVersion(cnn, response);
                        return(true);
                    }
                    else
                    {
                        int      len         = response.Length;
                        string[] stringArray = clsWeb.splitStringToArray(response);
                        string[] stringArr   = { stringArray[1], stringArray[3], stringArray[6] };
                        keyArrayLength   = Convert.ToInt32(stringArray[4]);
                        valueArrayLength = Convert.ToInt32(stringArray[8]);
                        mergedstring     = clsWeb.generateCode(stringArr);
                        int random = Int32.Parse(stringArray[2].ToString());

                        string[] array = clsWeb.splitByIntNum(mergedstring, random);

                        //// Split an Array into two arrays ////

                        /*        if(keyArrayLength<valueArrayLength)
                         *      {
                         *           startindex = 0;
                         *           keyarray = smallStrArray(startindex,array,keyArrayLength);
                         *           valuearray= largeStrArray(startindex+1,array,keyArrayLength);
                         *      }
                         *      else if(keyArrayLength>valueArrayLength)
                         *      {
                         *            startindex = 1;
                         *            keyarray = largeStrArray(startindex-1,array, valueArrayLength);
                         *            valuearray = smallStrArray(startindex,array, valueArrayLength);
                         *       }  */
                        while (keyArrayLength < valueArrayLength)
                        {
                            while (pos < keyArrayLength)
                            {
                                if (index % 2 == 0)
                                {
                                    keyarray[pos] = array[index];
                                    pos++;
                                }
                                else
                                {
                                    valuearray[pos1] = array[index];
                                    pos1++;
                                }
                                index++;
                            }
                            if (pos >= keyArrayLength)
                            {
                                valuearray[pos1] = array[index];
                                index++; pos1++;
                            }
                            if (index >= array.Length)
                            {
                                break;
                            }
                        }
                        while (valueArrayLength < keyArrayLength)
                        {
                            while (pos <= valueArrayLength)
                            {
                                if (index % 2 == 0)
                                {
                                    keyarray[pos] = array[index];
                                    pos++;
                                }
                                else
                                {
                                    valuearray[pos1] = array[index];
                                    pos1++;
                                }
                                index++;
                            }
                            if (index > valueArrayLength)
                            {
                                keyarray[pos] = array[index];
                                index++;
                                pos++;
                            }
                            if (index >= array.Length)
                            {
                                break;
                            }
                        }

                        keyarray   = keyarray.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                        valuearray = valuearray.Where(x => !string.IsNullOrEmpty(x)).ToArray();
                        /////////////////////////

                        //// Find last element from array  and if "$" exist , Remove it    ////

                        keyarray   = removeLastEle(keyarray.Last(), keyarray);
                        valuearray = removeLastEle(valuearray.Last(), valuearray);

                        ////////////////////////

                        string   keystring   = clsWeb.generateCode(keyarray);
                        string   valuestring = clsWeb.generateCode(valuearray);
                        string   keys        = clsWeb.Base64Decode(keystring);
                        string   values      = clsWeb.Base64Decode(valuestring);
                        string[] keysArr     = clsWeb.decodedArray(keys);
                        string[] valuessArr  = clsWeb.decodedArray(values);
                        string   cust        = getValue(keysArr, valuessArr, "cus");
                        string   seq         = getValue(keysArr, valuessArr, "seq");
                        string   prd         = getValue(keysArr, valuessArr, "prd");
                        string   edn         = getValue(keysArr, valuessArr, "edn");

                        clsDBConnection.updateTable(cnn, cust, seq, prd, edn);
                    }
                }
                catch (Exception ex)
                {
                    string error = ex.Message;
                    return(false);
                }
            }
            return(true);
        }