Protected: Node / PostgreSQL – Performance and Security

This content is password protected. To view it please enter your password below:

Enter your password to view comments.  

Load an external image in a universal app

When I was playing with a Universal App, an app with code shared between Windows Phone 8.1 and Windows 8.1, I noticed that loading an image from an externel source isn’t as easy as it should be.
What seems logical is:

View:

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <Image VerticalAlignment="Center" Stretch="UniformToFill" Source="{Binding TheImage}"/>
 
    </Grid>

ViewModel:

        private BitmapImage _TheImage
        public BitmapImage TheImage
        {
            get
            {
                return _TheImage;
            }
 
            private set
            {
                if (_TheImage!= value)
                {
                    _TheImage= value;
 
                    NotifyPropertyChanged("TheImage");
                }
            }
        }
 
        public void LoadImage()
        {
             this.TheImage = new BitmapImage(new Uri("http://www.feron.it/images/Apestaartje.png", UriKind.Relative));
 
        }

After you call the LoadImage method, the image in the grid stays awfully empty. It took serval partial solution that I had to put together to solve this problem and be able to load the image from my server. We need to create a function that loads the images and creates the bitmap. The view isn’t modified.

Viewmodel:

        private WriteableBitmap _TheImage
        public WriteableBitmap TheImage
        {
            get
            {
                return _TheImage;
            }
 
            private set
            {
                if (_TheImage!= value)
                {
                    _TheImage= value;
 
                    NotifyPropertyChanged("TheImage");
                }
            }
        }
 
        async public void LoadImage()
        {
             this.TheImage= await GetWebImageByUrl("http://www.feron.it/images/Apestaartje.png");
        }
 
        public static async Task<BitmapImage> GetWebImageByUrl(string imageUrl)
        {
            HttpClient client = new HttpClient();
            var byteArray = await client.GetByteArrayAsync(imageUrl);
            BitmapImage bitmapImage = new BitmapImage();
            using (MemoryStream ms = new MemoryStream(byteArray))
            {
                try
                {
                    await bitmapImage.SetSourceAsync(ms.AsRandomAccessStream());
                }
                catch (Exception e)
                { 
                }
            }
            return bitmapImage;
        }

As you can see the LoadImage method is not async so it won’t block the UI thread. When this method is called the image is correctly loaded and displayed, remember to require the “Internet (client & server)” capability, otherwise you’ll get an “access denied” error.

0  

Call an ASMX web service from PHP

If you need to call an ASMX web service with several parameter from an PHP environment you’ll need to pass those parameters in a specific way in order to get this working. Suppose we have a web service with a method GetProducts which requires three parameters, which is defined like:

[WebMethod]
public array[products] GetProducts(string SearchTerm, int Skip, int Take)

Most people will try to call this method from PHP with code that looks like:

$WSDL_URI = "https://api.company.com/Products.asmx?WSDL";
$client = new SoapClient($WSDL_URI);
$ProductData = $client->GetProducts($SearchFor,0,12);

And you’ll notice the this call fails with an error or it doesn’t fail, but it doesn’t return what you expect. The solution is remarkably simple, just put the parameters in a named array:

$WSDL_URI = "https://api.company.com/Products.asmx?WSDL";
$params = array("SearchTerm" => $SearchFor, "Skip" => 0, “Take” => 12);
$client = new SoapClient($WSDL_URI);
$ProductData = $client->GetProducts($params );

And then you’ll notice the you called the ASMX service from PHP and it works just like you expect.

0  

TortoiseGit remember password

Since we migrate our source control from SubVersion (SVN) to Git hosted on Bitbucket there was one thing that I thought was very very annoying. This is the fact the the Git client I use, because several people recommended it, TortoiseGit just won’t remember my password.

There are several ways to solve this “problem”, generation SSH keys, using different SSH clients combined with a text file that contains the username and password. But there is a much easier solution, in the URL of the repository:

https://username@bitbucket.org/team/repository.git

You can add the password after the username, separated by a colon “;”

https://username:password@bitbucket.org/team/repository.git

After this, TortoiseGit remembers the password and you’re happy.

0  

Migrate SVN to Bitbucket, the easy way

In this blog post I’ll show you how you can transfer/convert/migrate a SubVersion repository to a Git repository hosted on Bitbucket. Most tutorials, including the official one are complex, have many steps to perform and haven’t worked for me. In my case the all failed for different reasons.

Luckily there is a very simple method to perform this migration, for starters you need to install these 2 tools:

  • TortoiseGit
  • Git
  • TortoiseGit is a very decent Git client which you can use after the conversion to perform all the interaction with Git.

The first step is to convert the SVN repository to Git:

  • Create a new folder
  • Right-click –> Git clone:
  • image
  • In the dialog that appears, fill use the SVN URL in the URL field, uncheck “Load Putty Key”,”check “From SVN Repository” and uncheck “Trunk”, “Tags” and “Branches”:

image

The might a message about an invalid certificate which you can ignore. You might be asked for credentials, if so enter the your SVN credentials. After a while, depending on the size of the repository, the conversion is done and you can close the dialog

The next step is to create the Git repository on Bitbucket:

image

Fill out the form, click the “Create repository” button. On the next dialog you can see the URL of the repository:

image

Copy this URL to the clipboard, go back to the folder where you created the clone of the SVN repository, right-click on the folder –> TortoiseGit –> Push

image

On the dialog that appears click on the “Manage” button:

image

A new dialog appears, only past the URL in the URL field:

image

Press “OK” to close the dialog, and press “OK” in the previous dialog. If asked, enter the Bit Bucket credentials, wait a few seconds and you have migrated the SVN repository to Bitbucket.

0