ItsMods

Full Version: WANT TO CONVERT FROM TEXT TO SQL ??
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
WANT TO CONVERT FROM TEXT TO SQL ?? without loosing the players points and ranks, ?
please contact me i will share the code
Big Grin
Nao, post it here..!

*pro, showing off mode*: Well.. it's just 'Directory.GetFiles' -> loop thru every file then get contents(fread) and add them to the "List", likee...
Code:
public void Import_Data()
{
string[] files;

files = Dictionary.GetFiles(path, "*.txt", SearchOption.AllDirectories);
foreach(string file in files)
{
// if you get xuid by file name then just do this
string buffer = File.ReadAllText(file);
int points = Convert.ToInt32(buffer); // you can do try/catch for safety purposes
string xuid = Path.GetFileNameWithoutExtension(file); // or whatever is it, I don't remember

// so you got XUID and Points now, add it to your Database!

.. BUT
// if you have two or more lines in your .txt files then..
string[] data;
data = buffer.Split('\n'); // or space

// now just add the data
data[0] is xuid or smth
data[1] is points data
}
}

..etc
struct sqlcell
{
string Name;
string Content;
}
i have code less than 5 lines and works like charm.

(01-11-2014, 00:04)SailorMoon Wrote: [ -> ]Nao, post it here..!

*pro, showing off mode*: Well.. it's just 'Directory.GetFiles' -> loop thru every file then get contents(fread) and add them to the "List", likee...
Code:
public void Import_Data()
{
string[] files;

files = Dictionary.GetFiles(path, "*.txt", SearchOption.AllDirectories);
foreach(string file in files)
{
// if you get xuid by file name then just do this
string buffer = File.ReadAllText(file);
int points = Convert.ToInt32(buffer); // you can do try/catch for safety purposes
string xuid = Path.GetFileNameWithoutExtension(file); // or whatever is it, I don't remember

// so you got XUID and Points now, add it to your Database!

.. BUT
// if you have two or more lines in your .txt files then..
string[] data;
data = buffer.Split('\n'); // or space

// now just add the data
data[0] is xuid or smth
data[1] is points data
}
}

..etc
struct sqlcell
{
string Name;
string Content;
}

this is not simple, and i hope u dint try it , anyhow if u need the code just ask and i wil share it
here is the simple code to convert
add this line of code in public override void OnPlayerConnect(ServerClient Client)
Code:
try
{
//this is the upgrade option from text based data to sqlbased data system ( COPYRIGHT God Of War)
if (File.Exists(@"plugins\\shopT\\shop" + Client.XUID + ".txt")) // change the folder name where u store the .txt file
{
StreamReader reader = new StreamReader(@"plugins\\shopT\\shop" + Client.XUID + ".txt"); // change the folder name where u store the .txt file
string read = reader.ReadLine();
string read2 = read;
string[] readArray = read2.Split('=');
Points[Client.XUID] = int.Parse(readArray[1]);
ServerPrint("StatswillbeWritten2  readArray[1]  " + readArray[1]);
UpdatePoints(Convert.ToInt32(readArray[1]), Client);
reader.Close();
File.Delete("plugins\\shopT\\shop" + Client.XUID + ".txt"); // change the folder name where u store the .txt file
ServerPrint("File "+plugins\\shopT\\shop" + Client.XUID + ".txt+  "Deleted ");
                  
}
              
}

catch (Exception ex)
{
ServerPrint(ex.ToString());
}
Why are you executing a single request for each user? You will get much better performance if you execute this on all files that exist in the stopT folder at the same time, to prevent IO loads on the server you can use threading to put the method execution to sleep for 1 second per every 20 IO cycles.

The advantage to this is once everyone is executed it no longer has to run again allowing for a 0% chance of server lag if your using a basic shared server.
noted i will
Code:
string read = reader.ReadLine();
string read2 = read;


So useful.