SandRock.getBlog();

Aller au contenu | Aller au menu | Aller à la recherche

mardi 4 janvier 2011

WP7 app for Windows Phone 7 about to be released

Hi people.

I've been working since half November on a WP7 application. It's called "Betaseries WPC" and is linked with Betaseries.com.

Betaseries.com permits to manage a list of TV shows that you are watching. You can set the last episode you've seen for each show. And you can share with your friends. I like the place because it's pretty friendly and the website is ad-free and well realized.

My application does basic stuff: you start by logging-in with your account, then some information show up. You can see the next episode to watch for each show you follow. You can also see a small description of episodes. You've got friends updates (what they watch, what they do). Finally some statistics about you and an small "About" page.

Here are some screenshots:

This is gonna make more things in future. I'd like to publish as soon as possible on the marketplace. Once it's done, sources will be opened. I'm also helped by a few friends which will show up later.

As you understood, the application is not yet available. I'm waiting for my publisher account to be ready. But here are some links:

* Project home
* Screenshots

A .NET/Silverlight library will be set under a GNU GPL license for those who want to create more stuff with betaseries.

My main profile is albator, but you might prefer to look at srktest which is specific for the application (and public btw).

lundi 20 décembre 2010

Take screenshots by code in your Windows Phone 7 application with auto-upload to your machine

Hello there,

Here a simple code I tried to make to take screenshots inside a Windows Phone 7 application. This works in the emulator. I'm pretty sure it will work with a phone.

I found this article to take screenshots with few lines of code: Screen Capture on Windows Phone 7.

The issue here is that you only have a Bitmap image in the phone's memory. What I did is:

  • a simple web application for IIS able to receive a screenshot (you may host it on your local IIS)
  • a class for your WP7 application to send screenshots to the web server

You will find an attached file named Wp7Screenshots.rar. It contains a Visual Studio 2010 solution to build & publish on your local IIS (or anywhere you like).

If you look at the code, you will find a simple IHttpHandler. It's main goal is to detect files in a HTTP POST query and to save them on your hard drive.

After publishing, make sure the web application contains a Files folder and verify IIS have permission to create files into it.

Now, let's see you WP7 application. This only apply to Silverlight projects. So if you are using XNA, perhaps this blog entry is not for you.

The only configuration you have to do is to set the URL of your deployed HttpHandler. You can do this anywhere.

Tools.ScreenshotSender.UploadUrl = "http://172.24.1.32/wp7/Upload.ashx?key=fvkjorejv";

Then, you have to call the magic method to take the screenshot. You need a reference to a PhoneApplicationPage. Here is a code to take a screenshot 5 seconds after the application startup. You can of course use any event to take more screenshots (mouse click, navigation event, timer...).

public partial class MainPage : PhoneApplicationPage {
        public MainPage() {
            InitializeComponent();
 
            Tools.ScreenshotSender.UploadUrl = "http://172.24.1.32/wp7/Upload.ashx?key=fvkjorejv";
 
            // go off-thread to wait
            ThreadPool.QueueUserWorkItem(r => {
                Thread.Sleep(5000);
                var dispatcher = r as Dispatcher;
 
                // go on the UI thread to take a screenshot
                dispatcher.BeginInvoke(new Action(() => {
                    Tools.ScreenshotSender.TakeAndSend(this);
                }));
            }, Deployment.Current.Dispatcher);
        }
    }

Don't forget this code was made from scratch. It is NOT ready for production. I wrote this to take screenshots for documentation purpose. If you want to use this in a published application, you might want to read the whole code file (for the silverlight application). And the server code IS INSECURE: anyone can upload any file to your webserver. The only simple protection is a hard-coded key. So again, sample insecure code here. You are free to enhance (and optionally post your own code).

Here is my C:\inetpub\wwwroot\wp7\Files folder with screenshots from the emulator.

screenshots.jpg

Hope this can help. I'm still searching how to take a screenshot of a whole panorama control...

mardi 14 septembre 2010

Mail notification for subversion repository

I was searching for a little script able to email my collaborators and myself when someone commits something to my SVN repositories.

SVN commit email - sample email

There seem to be a popular perl script commit-email.pl. But I had several errors when implementing it. This is why I decided to make one. Because it's useful and easy to configure, I'll share my entire script here.

Download commit-email.php

As you can see, there is a little configuration section.

  1. <?php
  2.  
  3. // CONFIGURATION
  4. $svnlook = '/usr/bin/svnlook';
  5. $globaladdress = 'someone+logs@gmail.com';
  6. $repoaddress = array(
  7. 'repoAAA' => 'user1@aaa.com, user2@aaa.com',
  8. 'repoBBB' => 'user1@b.com, user2@b.com',
  9. );
  10. $from = 'svn-noreply@svn-hosting.lol';
  11. $replyto = 'admin@svn-hosting.lol';
  12. //

Nothing fancy here. $svnlook is the path where the svnlook command can be run. $globaladdress is a email address where all commit will be notified. $repoaddress is a field for specific repositories to add email addresses. $from and $replyto are what they are.

It's following the svn postcommit hook. My SVN repos are located in /home/svn. You can create a hook in /home/svn/repoX/hooks/post-commit containing:

  1. #!/bin/sh
  2.  
  3. REPOS="$1"
  4. REV="$2"
  5.  
  6. /usr/bin/php /home/svn/commit-email.php "$REPOS"

Don't forget to place my script in /home/svn and to install php5-cli.

samedi 12 juin 2010

Deletion confirmation with ASP.NET MVC

Here is my approach for deleting stuff with ASP.NET MVC 2.

As mentioned here, the default Delete view isn't quite correct. What I wanted is a deletion solution that:

  • is powered with Ajax for a better user experience
    • we will make a HTTP DELETE on /Items/Delete/12 to delete item #12
  • is accessible for non-JS enabled browsers (we need a confirmation form)
    • when confirmed, the deletion occurs with HTTP POST on /Items/Delete/12 to delete item #12

With those specifications, we can write the following (wrong) controller code:

  1. public class ItemsController : Controller
  2. {
  3. [HttpGet]
  4. public ActionResult Delete(int id) {
  5.  
  6. ViewData.Model = new ConfirmFormModel {
  7. Id = id.ToString(),
  8. BackAction = "Index"
  9. };
  10.  
  11. return View();
  12. }
  13.  
  14. [HttpDelete]
  15. [HttpPost]
  16. public ActionResult Delete(ConfirmFormModel model) {
  17. ViewData.Model = model;
  18.  
  19. // business action here
  20.  
  21. // if we use Ajax, backaction will be null and have
  22. // to prevent a secondary GET request
  23. return model.BackAction == null ? null : RedirectToAction(model.BackAction);
  24. }
  25.  
  26. }
  1. /// <summary>
  2. /// Simple model class to store the Id for a confirmation form.
  3. /// </summary>
  4. public class ConfirmFormModel {
  5.  
  6. /// <summary>
  7. /// Item's ID
  8. /// </summary>
  9. public string Id { get; set; }
  10.  
  11. /// <summary>
  12. /// Confirmation message.
  13. /// </summary>
  14. public string Message { get; set; }
  15.  
  16. /// <summary>
  17. /// The controller action to redirect to if the user wants to cancel.
  18. /// </summary>
  19. public string BackAction { get; set; }
  20.  
  21. }

A created a little model class to store the confirmation message and the item ID; this way I can use it all over my project. You can notice the [HttpDelete] and [HttpPost] on the second Delete() method. Obviously this won't work as asked here. You have to create your own attribute.

So I created the related views with (not-included) javascript. Here is the index:

  1. <!-- Index page -->
  2.  
  3. <ul>
  4. <% for (int i = 0; i < 10; i++) { %>
  5. <li><%= Html.ActionLink("Delete #" + i, "Delete", new { id = i }, new { @class = "deleteLink" })%></li>
  6. <% } %>
  7. </ul>

The delete page where I include a generic partial-view:

  1. <!-- Delete page -->
  2.  
  3. <h3>Confirmation</h3>
  4.  
  5. <% Html.RenderPartial("ConfirmForm", Model); %>

Finally, the partial view:

  1. <!-- Delete form in a partial view -->
  2.  
  3. <% Html.BeginForm(); %>
  4. <fieldset>
  5. <legend>Confirmation</legend>
  6.  
  7. <p><%= Html.Encode(Model.Message ?? "Are you sure you want to delete this?")%></p>
  8.  
  9. <p>
  10. <%= Html.HiddenFor(m => m.Id) %>
  11. <%= Html.HiddenFor(m => m.BackAction) %>
  12. <%= Html.ActionLink("Cancel", Model.BackAction ?? "Index") %>
  13. <input type="submit" name="Continue" value="Continue" />
  14. </p>
  15. </fieldset>
  16. <% Html.EndForm(); %>

Now we have a working solution to confirm some action on a website. Sources attached...

jeudi 7 janvier 2010

Test de VS.PHP 2010

Bonjour à tous.

Dans le but de créer un petit projet perso en PHP + ZF, j'ai décidé de tester pour de bon VS.PHP 2010 actuellement en développement. Le test est réalisé sur le build 2.8.1.6090.

VS.PHP est une extension pour Microsoft Visual Studio conçue pour écrire des applis PHP. Je m'attend globalement à la même expérience qu'avec Netbeans 6.5+. VS.PHP 2008 coûte $99.99 ou €73.99. Notez que Visual Studio existe sous une forme gratuite ; si vous n'êtes pas développeur .NET, VS.PHP ne nécessitera pas de version payante de VS.

A noter que je ne connais presque pas le logiciel, je pars à sa découverte.

Installation

Depuis le site de dev, récupérez l'installateur le plus récemment compilé. L'installateur est un web install.

Installation...

Première utilisation

Quelle surprise de voir qu'un projet de type 'Zend MVC Project' m'est proposé ! Effectivement, dans le fenêtre de nouveau projet, on peut créer un projet classique ou un projet ZF. Ca tombe bien, c'est mon framework préféré !

New project window

En plus de tout ça, je vais utiliser AnkhSVN pour versionner mon projet...

Voilà mon projet PHP+ZF créé. La structure de fichiers proposée ne me convient déjà pas. Le template de projet crée quelques malheureux fichiers. Rien de transcendant... De plus, la colorisation syntaxique est très mal intégrée...

Ma colorisation C# PHP colors and ZF structure

Impossible de trouver les options de colorisation pour le code PHP. Une recherche sur le web m'indique qu'elles devraient s'afficher avec VS démarré en administrateur... Même pas... Petite restructuration de l'appli :

The application is ready to run Built-in web server displays an error

Un mini server web de debug est inclus. J'imagine que le but est de fournir un debug pas-à-pas. Très bon point.

Malheureusement, de nombreux bugs surviennent avec cette version beta. Actuellement VS a gardé un lock sur le fichier .phpproj et n'arrive pas à sauvegarder la structure du projet (cette action est nécessaire pour démarrer l'appli).

Néanmoins, l'IntelliSense est au rendez-vous. Vous pouvez dans un premier temps définir un include_path pour spécifier l'emplacement de votre framework.

PHP include path

Par la suite, l'IDE affichera un IntelliSense digne de celui que l'on a en developpement .NET : le meilleur.

PHP IntelliSense

Conclusion

Le bug cité ayant détruit mon projet ; considérons qu'il est trop tôt pour tester cette version. D'ici quelques jours je ferai un test avec VS 2008 si j'arrive à négocier l'extension de la durée d'évaluation...

Bug bug bug bug bug bug

- page 1 de 5