archiveren

Tagarchief: c#

Quick post

I’ve posted the code of TrafficCamsFlanders & WOL on codeplex 🙂

http://trafficcamsflanders.codeplex.com/
http://wolwp7.codeplex.com/

No idea if anyone would ever use it…
But there it is! 🙂

Advertenties

My 5th wp7 app just went live 🙂

Its purpose: sending a text message from your browser!

Download the application from the WP marketplace, login, take another device (desktop, laptop, tablet, another phone, …) and browse to http://mendel.somee.com (my current free asp host 🙂 ), login with the same credentials as before, type your message, send it to your phone, and send it again! 🙂

This makes you can write an entire book-long message, on another device (maybe even with physical keyboard 🙂 )

More info on the SMSer project page: https://mendel129.wordpress.com/projects/smser/

Today, I’ve submitted my 5th application the Windows Phone 7 marketplace 🙂

Basically, it gives you the ability to type a text message on your computer and send it to your phone for sending it to someone…

You can find some screenshots and links to the app on this project page.

 

I’m impressed my msdn account is still valid, so I’m happy for that 🙂 (but that’s another story)

Anyway, the app is in a pretty rough form, but it works, and it’s something you might use as well 🙂

23 years old, and I still didn’t know how to connect a microsoft sql with c#
That needed to change!

In the end, it’s almost exact the same as php/mysql or in netbeans…
You define a connection, you open it, and you’re ready to query 🙂

The hardest part was getting the data source (my local computer) right ^^
Plus, you can connect using your windows credentials (just run it), or define some specific user authentication.

In code, it looks like this:

private void button2_Click(object sender, EventArgs e)
{
 SqlConnection myConnection = new SqlConnection("server=mendelportable\\sqlexpress;Trusted_Connection=yes;database=master;connection timeout=30");

 myConnection.Open();
 SqlCommand myCommand = new SqlCommand("select * from Table1", myConnection);
 SqlDataReader dr = myCommand.ExecuteReader();
 textBox1.Text = "";
 while (dr.Read())
 {
  textBox1.Text=textBox1.Text+dr["messages"].ToString()+"\r\n";
 }
}

And once you’re connected, you’re ready to query the hell out of that database 😎

It’s absolutely nothing special, and it’s good to know!

Mission accomplished 🙂

Apparently, when you create a live tile, and you use an external URI to point to an image for the tile, the operating system removes the tile after a reboot…
This behaviour doesn’t occur when you use a local resource to instantiate the tile…

Just something you don’t actually know until you see it happening ^^

Jeah, it contains prefabricated sms-messages :mrgreen:

Because my previous “reloader” app was denied from the marketplace because of some weird reasons… (promoting other mobile providers) I build around this issue…

The results is PrefabSMS.

It’s an application in which you can store sms-messages, and afterwards send them with one click of a button 🙂

So, you can create a messages, let’s say “sim topup 15”, to be send to a receiving side, lets say “8989”, and you can save this in PrefabSMS 🙂

Ofcourse you can use it for other things as wel, sending “<3” to your girlfriend or “spam” to random people ^^


Some usefull numbers and messages:

DL

I’ve been programming again!
This time on soms apps called “PrefabSMS” and “WOL”.
More info about the app later, but now I just want to share some code snippets about sockets en live tiles!

UDP sockets

Sockets is something introduced since WP7.5’s update mango.
Something that should have been there since the beginngin… But hey, it’s here now, so enjoy it from now on!
Anyway, a first thing to do is include the namespace.

using System.Net.Sockets;

After that we can declare some new things 🙂

Socket _socket = null;
static ManualResetEvent _clientDone = new ManualResetEvent(false);
const int TIMEOUT_MILLISECONDS = 5000;
const int MAX_BUFFER_SIZE = 2048;

Which meaning is all pretty obvious I think…

After this the socket is initialized with

_socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

The 3rd thing we need is a send() function.
This should be something as follows:

public string Send(byte[] payload))
{
     string response = "Operation Timeout";

     if (_socket != null)
     {
          SocketAsyncEventArgs socketEventArg = new SocketAsyncEventArgs();
          socketEventArg.RemoteEndPoint = new IPEndPoint(IPAddress.Broadcast, 11000);
          socketEventArg.Completed += new EventHandler(delegate(object s, SocketAsyncEventArgs e)
          {
          response = e.SocketError.ToString();
          _clientDone.Set();
          });
          socketEventArg.SetBuffer(payload, 0, payload.Length);
          _clientDone.Reset();
          _socket.SendToAsync(socketEventArg);
          _clientDone.WaitOne(TIMEOUT_MILLISECONDS);
     }
     else
     {
          response = "Socket is not initialized";
     }

     return response;
}

So, after initialisation, you can call send to send your byte array into the wild!

You can change the IPEndPoint in the send function into IPEndPoint(“192.168.1.100”, 80) or something else, just an ip address and a port for the packet! 🙂

Live tiles

I’ve also been playing with the live tiles. In mango you can setup live tiles to enter a deep state of your application. With this you can open a specific page with specific data in your application instead of just “regularly” opening your app…

Add following reference.

using Microsoft.Phone.Shell;

Creation

StandardTileData NewTileData = new StandardTileData
{
     BackgroundImage = new Uri("ftgxmessage.png", UriKind.Relative),
     Title = temp.sendBody,
     BackTitle = temp.sendTo,
     BackContent = temp.sendBody,
     //BackBackgroundImage = new Uri("Blue.jpg", UriKind.Relative) 
};
ShellTile.Create(new Uri("/MainPage.xaml?action="+listBox1.SelectedIndex, UriKind.Relative), NewTileData);

This piece of code instantiates a standard tile with some info. Notice: you have a front and a back of the live tile (it flips around on the home screen 🙂 )

And the create() puts it on the homescreen.

An action can be included in the create function: here we call mainpage with a specified action to execute, this is done by a QueryString – see further.
Adjust at your own needs 🙂

At the page data can be passed from the tile into the app (this is done by a so called QueryString). This can be accessed in the Loaded function for the program with following code:

int id = Convert.ToInt32(NavigationContext.QueryString["action"]);

Et voila, you have your action variable at hand! 🙂

Deletion

When you want to delete a tile, you first have to find your tile 😛

If we put the tile from above on the homescreen, it can be identified with the action variable in the QueryString. So we use this to find our tile and identify it. And to delete it 🙂

string tempstring = "action=" + listBox1.SelectedIndex;
ShellTile TileToFind = ShellTile.ActiveTiles.FirstOrDefault(x => x.NavigationUri.ToString().Contains(tempstring));

That’s all for today 🙂