Posts


I have ported the c# xwt samples to vb.net. They are currently hosted at https://github.com/majorsilence/xwt in the SamplesVB folder. I have no idea if they will be accepted into the main code. If they are not I will create a branch in my fork and move the vb.net samples there for anyone that is interested.

The main .net xwt project is https://github.com/mono/xwt.

“Xwt is a new .NET framework for creating desktop applications that run on multiple platforms from the same codebase. Xwt works by exposing one unified API across all environments that is mapped to a set of native controls on each platform.”


Update (Feb 21, 2015) New blog post covering Get, Put, Post to service stack.

Connecting to a servicestack (see servicestack.net) service from php is very easy. If you go to https://github.com/majorsilence/WebServiceDotNetTesting there is a c# project that has one service called Hello. This service will listen on http://localhost:9200.

In the php folder there is a script servicestack-php.php that will connect to the c# servicestack web service.

The main function that can be used is get_data_curl. This function can be used with both HTTP, HTTPS, and can connect to open services and services protected with basic authentication.


/**
* Generic curl function to POST to a servicestack.net service.  This function
* will work with both HTTP and HTTPS but does not validate an HTTPS connection.
*
* @param string $base_url the base url of the service.  It must not end with a / character.
* @param string $service_name the name of the service.  This is case sensitive.
* @param json $post_data the data to post.  Should already be encoded json using the json_encode function.
* @param string $credentials the username and password to login to the webservice. A string in Format "Username:Password"
* @ return json
*/
function get_data_curl($base_url, $service_name, $post_data, $credentials)
{

	
	// Will create a string like "http://localhost:9200/servicestack/json/syncreply/Hello";
	$url = $base_url . '/json/syncreply/' . $service_name;
	$contentLength = strlen($post_data);
	
	$ch = curl_init();
	curl_setopt($ch, CURLOPT_URL, $url);
	
	// Override the default headers
	curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', 
		'Accept: application/json', "Expect: 100-continue"));
    // 0 do not include header in output, 1 include header in output
	curl_setopt($ch, CURLOPT_HEADER, 0);   
	
	// Set username and password
	if ($credentials != "")
	{
		curl_setopt($ch,CURLOPT_USERPWD, $credentials); 
	}
	
	curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
	
	// if you are not running with SSL or if you don't have valid SSL
	$verify_peer = false;
	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $verify_peer);
	
	// Disable HOST (the site you are sending request to) SSL Verification,
	// if Host can have certificate which is invalid / expired / not signed by authorized CA.
	$verify_host = false;
	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $verify_host);
	
	// Set the post variables
	curl_setopt($ch, CURLOPT_POST, 1);
	curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
	
	// Set so curl_exec returns the result instead of outputting it.
	curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

	
	// Get the response and close the channel.
	$response = curl_exec($ch);
	curl_close($ch);
	
	$json_obj = json_decode($response);
	return $json_obj;
}


You can use the get_data_curl function like this:


	/*
	$username = "user";
	$password = "password";
	$cred = "{$username}:{$password}";
	*/
	// If you are connecting to a service that uses basic authentication 
	// you can use the code above to set the credentials.
	$cred = "";

	$json = get_data_curl("http://localhost:9200", "Hello", $json_str, $cred);
	echo 'Result: ' . $json->{'Result'} . "<br />";


My-FyiReporting 4.5.0 has been released.

Main new features:

  • Gtk Viewer based on cairo
  • Barcodes QR Codes, Code39, EAN8
  • Menu Insert* Upgraded to visual studio 2010
  • Helper to select SQLite database
  • Helper to select SQL Server 2005/2008 server and database
  • Enable drag and drop of reports into designer when designer had no other reports open
  • Wpf report viewer control

BUG fixes: Issue 12 - Aggregate Function First() returns data from wrong dataset Issue 8 - Field place holders in Expression builder Issue 7 - Setting Paper Size Issue 13 - Print multiple copies not working

Download source code packages from https://github.com/majorsilence/My-FyiReporting/tags and binary packages from https://github.com/majorsilence/My-FyiReporting/downloads.


To create a QR code using C# or any .net language first go to http://code.google.com/p/zxing/ and download the C# library and build it. Direct link for version 2 source (http://code.google.com/p/zxing/downloads/detail?name=ZXing-2.0.zip&can=2&q=)

Add the zxing.dll file as a reference to your project.

        using System.Drawing;
        Bitmap bmp = QRCode("The Message To Encode");

        public Bitmap QRCode(string codeMessage)
        {
            com.google.zxing.qrcode.QRCodeWriter writer = new com.google.zxing.qrcode.QRCodeWriter();
            com.google.zxing.common.ByteMatrix matrix;

            int size = 180;
            matrix = writer.encode(codeMessage, com.google.zxing.BarcodeFormat.QR_CODE, size, size, null);


            Bitmap img = new Bitmap(size, size);
            Color Color = Color.FromArgb(0, 0, 0);

            for (int y = 0; y < matrix.Height; ++y)
            {
                for (int x = 0; x < matrix.Width; ++x)
                {
                    Color pixelColor = img.GetPixel(x, y);

                    //Find the colour of the dot
                    if (matrix.get_Renamed(x, y) == -1)
                    {
                        img.SetPixel(x, y, Color.White );
                    }
                    else
                    {
                        img.SetPixel(x, y, Color.Black);
                    }
                }
            }

            
            return img;

       }

To create a Code39 barcode using C# or any .net language first go to http://code.google.com/p/zxing/ and download the C# library and build it. Direct link for version 2 source (http://code.google.com/p/zxing/downloads/detail?name=ZXing-2.0.zip&can=2&q=)

Add the zxing.dll file as a reference to your project.

        using System.Drawing;
        Bitmap bmp = BarCode39("Message");

        public Bitmap BarCode39(string codeMessage)
        {
            com.google.zxing.oned.Code39Writer writer = new com.google.zxing.oned.Code39Writer();
            com.google.zxing.common.ByteMatrix matrix;

            int width = 180;
            int height = 120;
            matrix = writer.encode(codeMessage, com.google.zxing.BarcodeFormat.CODE_39, 
                width, height, null);


            Bitmap img = new Bitmap(width, height);
            Color Color = Color.FromArgb(0, 0, 0);

            for (int y = 0; y < matrix.Height; ++y)
            {
                for (int x = 0; x < matrix.Width; ++x)
                {
                    Color pixelColor = img.GetPixel(x, y);

                    //Find the colour of the dot
                    if (matrix.get_Renamed(x, y) == -1)
                    {
                        img.SetPixel(x, y, Color.White);
                    }
                    else
                    {
                        img.SetPixel(x, y, Color.Black);
                    }
                }
            }


            return img;

        }

       }