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...

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...

mardi 21 juillet 2009

Nouveautées de Silverlight 3

Silverlight 3 étant sortit il y a quelques jours, je vais vous en parler un petit peu.

Je vous rapelle que Silverlight est un plugin pour navigateur ressemblant (du point de vu utilisateur) à Adobe Flash et est développé par Microsoft. Les principaux atouts de Silverlight sont les suivants :

  • C'est un format ouvert (XAML) donc théoriquement compatible avec n'importe quel OS et toutes architectures (x86, x64...).
  • Des logiciels de développement gratuits existent (Visual Studio Express). Le XAML étant un format XML, un éditeur de texte suffit presque à créer un composant.
  • L'utilisation du XAML permet à l'application d'être portée sous forme de fenêtre grâce à WPF. (Flash le permet via Adobe Air mais il est difficile de trouver une version x64 pour GNU/Linux... (en fait, il n'y en a pas))

Je vous invite à consulter le web pour plus de détails.

Au passage, voici un White paper édité par Julien Dollon regrouppant les nouveautées de la version 3.

dimanche 8 février 2009

Nouvel Helper qui change la vie

Vous connaissez tous Zend_View_Helper_Url qui permet de créer une url rapidement dans une view. La syntaxe est la suivante : $this->url(array('controller' => 'index', 'action' => 'about', 'arg0' => 'value'));. Il faut avouer que c'est assez sympatique. Mais il est laborieux d'écrire systématiquement la balise <a />. Voici donc un helper très basique reprennant les arguments de url(). La seule modification est l'ajout du premier argument. Celui-ci contiendra la texte à mettre dans la balise <a />

  1. <?php
  2.  
  3. /**
  4.  * An helper to create xhtml links quickly
  5.  *
  6.  * This program is free software: you can redistribute it and/or modify
  7.  * it under the terms of the GNU Lesser General Public License as published by
  8.  * the Free Software Foundation, either version 3 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14.  * GNU Lesser General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU Lesser General Public License
  17.  * along with Foobar. If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  * @author SandRock <antoine.sottiau@gmail.com>
  20.  * @see Zend_View_Helper_Url
  21.  */
  22. class App_View_Helper_Link extends Zend_View_Helper_Abstract {
  23.  
  24. /**
  25. *
  26. * @param string $text the contents of the link
  27. * @param array $urlOptions Options passed to the assemble method of the Route object.
  28. * @param mixed $name The name of a Route to use. If null it will use the current Route
  29. * @param bool $reset Whether or not to reset the route defaults with those provided
  30. * @param boolean $encode
  31. * @return string a xhtml link like '<a href="url">text</a>"
  32. */
  33. public function link($text, array $urlOptions = array(), $name = null, $reset = false, $encode = true) {
  34. $router = Zend_Controller_Front::getInstance()->getRouter();
  35. $url = $router->assemble($urlOptions, $name, $reset, $encode);
  36. return '<a href="'.$url.'">'.$text.'</a>';
  37. }
  38.  
  39. }

Exemple :

  1. <?php
  2. echo $this->link('A propos de...', array('controller' => 'index', 'action' => 'about', 'arg0' => 'value'));?>
  3. <a href="/index/about/arg0/value">A propos de...</a>

- page 1 de 2