RSS
 

[Release] AutoLoL

25 Jul

Thanks to SaphuA (my Dutch buddy) Mastery Clicker v2.0 is ready to go… However it has happened to change its name to AutoLoL in the process.

AutoLoL can be found at http://autolol.codeplex.com/
Feel free to download and enjoy the greatness of AutoLoL

A new page regarding all the features will be up shortly…. for now look at Mastery Clicker Page

 
No Comments

Posted in Random

 

Epic Battle

22 Jul

I can’t believe I’m uploading this to my site but I just got done with an Epic battle in League of Legends. So epic that I had to take a screenshot of the results. This match was so well balanced and came down to the last minute, too bad recording games doesn’t work yet!

 
No Comments

Posted in Random

 

Near Disaster — Thanks Arvixe

21 Jul

So, I was messing with my FTP accounts and every time I delete an account there is a little checkbox… Remove accounts home directory… well thats bad if the home directory of the account is public_html and did I mention the box is checked by default… Well anyways, as you can see its all back up. Thanks Arvixe for keeping a backup! Their tech support was quick and I didn’t even have to call them (I used their online chat). My host has been great so anyone looking for a great host should check out http://www.arvixe.com

 
No Comments

Posted in Random

 

Return JSON from Web Services, Capture with jQuery

17 Jul

Many times now I have banged my head against the keyboard because I can’t get JSON to return correctly from my web service… Or is it the other way around? Is my service setup correctly but my Ajax call breaking things… Hopefully this can help people that were in my situation.

I have seen many people using a JSON serializer in their code. This is not normally necessary since WebServices should have the cabapility to serialize your object directly. Now lets get started… Your Web Service should look something like this.

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService] //Make sure this is uncommented
public class MyWebService: System.Web.Services.WebService
{
        [WebMethod]
        [ScriptMethod(ResponseFormat = ResponseFormat.Json)] //This line is optional!
        public string MyJSONString()
        {
            return "MyJSONString!";
        }

        [WebMethod]
        public List<KeyValuePair<int, string>> MyJSONList(string sample)
        {
            return new List<KeyValuePair<int,string>>(){
                new KeyValuePair<int,string>(0,"MyValue1"),
                new KeyValuePair<int,string>(1,"MyValue2"),
                new KeyValuePair<int,string>(2,"MyValue3"),
                new KeyValuePair<int,string>(3,"MyValue4"),
                new KeyValuePair<int,string>(4,"MyValue5"),
            };

        }
}

Once you have that ready to go, and it looks like this you should be able to make an AJax call to return it as JSON. This is were a lot of people get caught up. You can’t use Jquery’s built in getJSON for reasons unknown to me webservices can only return JSON with a POST not a GET so here is a sample call that works for me. First the string, then the more advanced list.

 $.ajax({
    type: "POST",
    url: "http://localhost/WebServices/MyWebService.asmx/MyJSONString",
    data: "{}", //This is the KEY, Send in an empty object as the data
    contentType: "application/json; charset=utf-8", //this must be added in order to request json
    dataType: "json", //as well as this.
    success: function (data) {
        alert(data.d); //Should = "MyJSONString!"
    }
 });

Now the List, sometimes things get tricky here because as you can see the method requires a string as a parameter. This string needs to be sent in the Data… but remember we have to have a json object in the Data field. so we must send our parameters as a certain way… ‘{sample:value}’ just like that, if there are more you just add a comma ‘{sample:value, arg2:value}’.

 $.ajax({
    type: "POST",
    url: "http://localhost/WebServices/MyWebService.asmx/MyJSONList",
    data: '{sample:"' + myVar +'"}', //This is the KEY if you require arguments
    contentType: "application/json; charset=utf-8", //this must be added in order to request json
    dataType: "json", //as well as this.
    success: function (data) {
        alert(data.d); //Should = "[object],[object],etc"
    }
 });

using FireBug you can see the results of the query

As you can see web services adds a d to the json object… not sure why, but it does. Therefore you might not be able to implement this directly into a plugin that isn’t expecting the d you will have to modify it and then pass it back into the plugin.
But if you are having issues let me know… I’m more than happy to help.

 

Mastery Clicker & League of Legends Season One

13 Jul

I thought Season One would give us the option to save our masteries… Apparently I was wrong. I am currently in Hawaii so I won’t be able to release a patch for mastery clicker until I get home from vacation. In fact Mastery Clicker 2.0 or should I say AutoLOL should be released in the short future adding a lot more features then just clicking masteries.

 
No Comments

Posted in Random

 

Quick Serialization of an Object in C#

23 Jun

Sometimes I just post code snippets for myself.

Serializing 2 objects

try
{
	BinaryFormatter bf = new BinaryFormatter();
	using (Stream output = File.OpenWrite("File.txt")){
		bf.Serialize(output, object1);
		bf.Serialize(output, object2);
	}
}
catch (Exception ex)
{
	MessageBox.Show("Unable to save the file\r\n" + ex.Message,
	"File Save Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

De-serializing the file

try
{
	BinaryFormatter bf = new BinaryFormatter();
	using (Stream output = File.OpenRead(openDialog.FileName)){
		object1 = (object1)bf.Deserialize(output);
		object2  = (object2)bf.Deserialize(output);
	}
}
catch (Exception ex)
{
	MessageBox.Show("Unable to read the file\r\n" + ex.Message,
	"File Open Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
 
No Comments

Posted in C#

 

Read Web Page

17 May

Simple C# method to grab a webpage and read its contents… The following is used to get an external IP address easily…


System.Net.WebClient myWebClient = new System.Net.WebClient();

using( System.IO.Stream myStream = myWebClient.OpenRead("http://www.geekpedia.com/ip.php")){

System.IO.StreamReader myStreamReader = new System.IO.StreamReader(myStream);

string IP = myStreamReader.ReadToEnd();

}
 
No Comments

Posted in C#

 

Graduated

17 May
Well, It’s finally over, school is complete and I feel I did a pretty good job this semester getting 2 A’s and 2 B’s for a final Grade-point  of 3.00. Check AJ’s blog if you really care to see photos or anything like that
 
No Comments

Posted in Random

 

TanksXNA

05 May

The TanksXNA game is good enough for an initial release, I need to add a Bugs board so people can add bugs they find there.

Anyways without further ado here it is

The XNA redistributable is required in order to run the game, a check is coming later for that.

TanksXNA

Redistributable

 
No Comments

Posted in C#, XNA

 

Working With BackgroundWorker Part 2: Populating Treeviews

14 Apr

I ran into an issue the other day populating a Treeview with a bunch of data that took quite some time to retrieve. The problem wasn’t populating the tree, it was waiting for the data to come back, then populating the tree all at once that was bothering me. No one wants to wait forever for the treeview to become available. I figured a backgroundworker would be extremely useful at a time like this…

Let’s start by creating a simple method called PopulateTree and generating a BackgroundWorker… Make sure you generate the missing methods


private void PopulateTreeView()

{

BackgroundWorker bw = new BackgroundWorker();

bw.WorkerReportsProgress = true;

bw.WorkerSupportsCancellation = false;

bw.DoWork += new DoWorkEventHandler(bw_DoWork);

bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);

bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);

You should already have a TreeView added to the Form. Lets just call it treeView1 for now. What we will do is populate the treeview with nodes 0 – a given number passed into the bw_DoWork method


//continuing inside the PopulateTreeView method

bw.RunWorkerAsync(10000);

}

//Now inside of our bw_DoWork method

void bw_DoWork(object sender, DoWorkEventArgs e)

{

//This is where the work you want the backgroundworker to do will be preformed

//DO NOT UPDATE THE GUI FROM HERE!

//The sender is the Background worker that called this Do Work

//Lets safely cast the backgroundwoker to bw

BackgroundWorker bw = sender as BackgroundWorker;

//The argument passed in is the number we want to count to.

int countTo = int.Parse(e.Argument.ToString());

//Loop through the numbers adding each one to the listview

for (int i = 1; i < countTo; i++)

{

//Calculate the percentage of numbers gone through

double percentComplete = (double) i / countTo) * 100;

//Report our progress

//This is where we tell the UI to update

//Lets pass the percentage and the number we want to add to the listview

bw.ReportProgress((int)percentComplete,i);

//Found it best to sleep for 1ms so the ui can update itself.

System.Threading.Thread.Sleep(1);

}

}

void bw_ProgressChanged(object sender, ProgressChangedEventArgs e)

{

//This is where progress from the bw will be handled

//You CAN update the UI from this method.

int progressComplete = e.ProgressPercentage;

//this is the number to add to the TreeView

int number = (int)e.UserState;

treeView1.Nodes.Add(number.ToString());

}

So, basically what we did here was boxed up an int and sent it through background workers ReportProgress method and unboxed that number inside the ProgressChanged method, then added it to our listview.

This is the proper way to update the UI from a backgroundworker. What’s great is we are not limited to sending a single object through the report progress, we could send a collection or even any object through that… Part III will show an example of something more complex. This is a good start though.

Download Source BackgroundWorkers Populate Treeview

 
No Comments

Posted in C#, Threading