Again, I find myself going back to basics when trying to make my SenchaTouch2 Project work.  Today, I updated my framework to Sencha’s latest alpha release of the tools (p4).  I often make these examples because I’m trying to prove there is a SenchaTouch bug and usually find out it’s my bug somehow.  So, since I went to the trouble of making a simple example of two stand alone buttons that switch between tab pages, I thought I’d blog it.

Here is what we get ultimately.  When clicking on b1 or b2, the home and the contact tab are selected automatically (same as clicking on those two items in the tab bar).

One thing I find a little odd, is that to create the class, you say Ext.TabPanel and not Ext.tab.Panel. (OK, I just tested that and both work)

 

image

And, here is the code:

<!DOCTYPE html>

<!-- Auto Generated with Sencha Designer -->
<!-- Modifications to this file will be overwritten. -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>AgelessST2</title>
    <link rel="stylesheet" type="text/css" href="sencha-touch-2.0.0-pr3/resources/css/sencha-touch.css"/>
    <script type="text/javascript" src="sencha-touch-2.0.0-pr3/sencha-touch-all-debug.js"></script>
    
    <script type="text/javascript"  >

        Ext.setup({
            onReady: function () {

                var pan = Ext.create('Ext.TabPanel', {
                    height: 150,
                    defaults: {
                        styleHtmlContent: true
                    },
                    items: [
                        {

                            title: 'Home',
                            html: 'Home Screen'
                        },
                        {

                            title: 'Contact',
                            html: 'Contact Screen'
                        }
                    ]
                });

                var buttonPannel = Ext.create('Ext.Panel', {
                    layout: 'hbox',
                    items: [
                            {
                                xtype: 'button',
                                text: 'b1',
                                handler: function (button) {
                                    pan.setActiveItem(0);
                                }
                            },
                            {
                                xtype: 'button',
                                text: 'b2',
                                handler: function (button) {
                                    pan.setActiveItem(2);
                                }
                            }
                ]
                });

                Ext.Viewport.add({
                    fullscreen: true,
                    layout: 'vbox',
                    items: [buttonPannel, pan]
                });
            }
        });

      
    
    
    </script>
</head>
<body></body>
</html>
Hope this helps.

 

So, I know it’s hard to believe, but I am actually considering getting a Macbook to use as my main development computer.  The reason is I’m using some beta mobile development tools that only support the Mac.  The problem is that if I don’t use these tools and incrementally build my app with them, I will get my app far out of wac (wac being a technical term) that I will never be able to get it back in wac again. 

So, I have a good friend who is a Mac wizard and I thought I’d ask him a question.  Below is my question and his answer.  Keep in mind, my friend is very technical in the Mac world.

Question from me (PC Guy):

I’ve been trying to figure that out for myself which Mac model to get.  If I get one, I want SandyBridge or later.  I think that’s quad core, but hard to tell.  Apple just seems to give dates on the refurbished site for their computers.  It’s also good to know they work with 16gb ram.  I need that because I run big fat windows VM’s.  The other thing I can’t quite figure out is if the 15’s support 2 drives internally if you are willing to forego the optical drive.  I like to run the boot drive as SSD (SATA3) and the secondary drive as just a normal SATA2 or SATA3.

My Friends answer (MAC Guy)

You’re talking like a pc guy. Pick the prettiest one.

 

I do not even want to admit how much time I spent today in a more complex application trying to get a button to respond to a tap event in SenchaTouch 2.0 Beta.  I did notice several people like me on the forums with similar issues, but I did not find one concrete example that made the simple “click a button application”.  Of course I’m building this in Microsoft Visual Studio 2010 and debugging with Chrome.  Let me start at the end.  When you are done, you will have a simple two button page that you can click on either button and have your MVC controller react to either button as well as trap the button hit inside the actual Panel.

 

image

 

And for those of you that have read enough, here is the source:  

 

 

The Nitty Gritty

Creating an SenchaTouch project with MVC is a little tricky to setup.  You need to get all the directories right.  My favorite way to do this is to use the Sencha Designer to create the project, then abandon it if I want to strike out on my own.  That is what I’ve done here.  I don’t even think you can tell.

Here is the file layout as seen from Visual Studio:

image

5 Files and 3 directories.

Let’s first take a look at the Panel that contains the buttons.  Here is the code:

Ext.define('MyApp.view.MyPanel', {
    extend: 'Ext.Panel',
    alias: 'widget.mypanel',
    config: {
        items: [
            {
                xtype: 'button',
                itemId: 'mybutton1',
                text: 'MyButton1',
                action: 'b1'
            },
            {
                xtype: 'button',
                itemId: 'mybutton2',
                text: 'MyButton2',
                action: 'b2'
            }
        ],

        listeners: [
            {
                fn: 'onMybutton1Tap',
                event: 'tap',
                delegate: '#mybutton1'
            }
        ]
    },
    onMybutton1Tap: function (button, e, options) {
        console.log('tap from mybutton1');
    }
});

Just a couple things to notice.  1) I’m defining an itemId which we will only be using in the local event (onMybutton1Tap).  If you notice the listener has a property delegate which looks for that.  I’m not sure if this is the best way to do this.  I’ve notice several forum people saying use the “on” syntax.  I did not find an example of that so this is what we have and it works.  Also notice the action property.  If you try and look that up on the SenchaTouch doc’s you will not find it.  I just made it up out of thin air (really!, well, I followed others examples).  I actually asked about this in the forums and I was told that is OK.  As a type safe language guy, it hurts, but I did it.

 

That’s it for the view.  Let’s move over to the controller.  Here is the source for that:

Ext.define('MyApp.controller.MyController', {
    extend: 'Ext.app.Controller',

    views: [
        'MyPanel'
    ],

    refs: [
        {
            ref: 'MyPanel',
            selector: 'mypanel'
        }],

    init: function () {

        this.control({
            'button[action=b1]': {
                tap: this.onButtonTap1
            },
            'button[action=b2]': {
                tap: this.onButtonTap2
            }
        });
    },

    onLaunch: function () {
        console.log('onLaunch');
    },

    onButtonTap1: function () {
        console.log('controller: onButtonTap1');
    },

    onButtonTap2: function () {
        console.log('controller: onButtonTap2');
    },

    config: {

    }
});

Basically, what this is doing is filtering all buttons, then looking at just the buttons that have an action of b1 or b2.  If this was a large application, we’d probably want to do some more fancy component querying, but for now, this is OK.  If you keep your controllers small, this should always work.

 

That’s it for now.  Download the source and run it.  I hope it saves you a ton of time. 

As always any experts want to comment and improve or correct what I’ve done, please feel free to comment. 

 

I’ve known about vaasnet for quite a while.  Basically, vaasnet is a way to almost instantly (OK, it took about 4 seconds to come up) grab a fresh VM (currently 99 cents an hour), do a bunch of stuff and go away.  My bunch of stuff was I need to download a bittorrent file that was about 5 gig and I know if I do it from either home or over my hotspot, bad things will happen.  If I do it at home, Comcast will send me a letter accusing me of stealing something, and if I use my Verizon hotspot, well, it’s a 5 gig per month plan.  You do the math.

Back to vaasnet.  Here is my experience today:

  1. 30 seconds to put my credit card it
  2. 4 seconds to boot a general purpose workstation
  3. 5 seconds to RDP into it
  4. 2 minutes to download bit torrent
  5. 35 minutes to have bit torrent download a 5 gig file!
  6. 35 minutes to have bit torrent download a 5 gig file (had to say it twice)
  7. 1 minute to transfer the file to my ORCSWeb server I already have
  8. $1.70 billed to my credit card.
  9. OMG!

I think that about says it all.  OK, maybe not it all.

I’ll be back!

OK, now that says it all.

 

image

 

This one had me a little stumped, and as usual, there are not enough examples in the Microsoft documentation to be very helpful. I’m using EntityFramework CodeFirst with Visual Studio 2011.  Let’s assume you create a class as follows:

 

public class CongressNumber
    {
        [Key]
        public int CongressNumberValue { get; set; }
    }

Then, you manually set the value of CongressNumberValue to 112.  I’d certainly think that is a reasonable thing to do. I know that the Microsoft guys often special case Id or id, but hard to believe they would take something like CongressNumberValue and assume I meant that to be an autogenerating Identity column.  Well, it seems they do that and the doc’s don’t even mention it. 

After first, finding the page on annotations, I discovered that what we really need to set is this to have it work as we want (with no identity key generation).

 public class CongressNumber
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.None)]
        public int CongressNumberValue { get; set; }
    }

I found this after drilling down some in there doc.  What surprises me is that no where does it mention that if you have a string, that does not get database generated, but if you have an int, that does.  I wonder what happens if you have a Guid? (I’ll leave that up to someone who wants to use a guid).

I would have loved to put in my own comments on the page: http://msdn.microsoft.com/en-us/library/system.componentmodel.dataannotations.databasegeneratedoption(v=vs.103).aspx but there was no user comment section.  Oh well.

To be fair, on the page: http://msdn.microsoft.com/en-us/library/gg197525(v=vs.103).aspx it does explain about identity and integers but when I had my issue, I was already on the detail page.  Seems to me the detail page should have more information on it than the summary page that leads in.  The only reason I found it was because while writing this post, I went back to get the proper links.

 

image

HTH’s.

Problem

So, if you have been doing development with Visual Studio 2010, Entity Framework CodeFirst, SqlServer or SqlServerCE for any amount of time, you’ll quickly run into the problem that the database can not be reinitialized because it is open.  Basically, the scenario is this.

1)  Put in your Global.asax.cs file a line that always recreates the database (naturally because you are in a development mode and as you constantly change your model and seed data).  The line is something like this:  Database.SetInitializer(new DropCreateDatabaseAlways<SiteDB>());

2)  Run your application with something like Debug/Run (All is fine)

3)  Go into the database browser (either in Visual Studio or Enterprise Manager)  and look at some data.

4)  Run your application again and you will get this error: “[SqlException (0x80131904): Cannot drop database "NewYorkTimesDb" because it is currently in use.]”.  This is because your database browser has a connection to the database and until it is dropped, you can not drop the catalog.

 

image

 

Solutions

 

The easiest and guaranteed to work solution is just to restart your SqlServer database server (control panel, services).  This is what I use to do but finally got tired of that because it takes about 20 seconds and, well, I’m very impatient.

The other solution I found in the forums (can’t find the link right now) is to execute the following script from the master database catalog:

use master
ALTER DATABASE NewYorkTimesDb 
   SET SINGLE_USER WITH ROLLBACK IMMEDIATE 
ALTER DATABASE NewYorkTimesDb SET MULTI_USER

Basically, just switching from multi-user to single-user and back clears the connections.

HTH’s!

Not sure if you are like me, but I use both Bing and Google for search.  Lately, my top 10 or so search results on everything I type are from my Google circles people.  The problem is I want the best or most popular answer, not the one that one of my google circles people may have typed.  So, here are the steps:

1.  Search for something on Google.

2.  Click on the little wheel in the upper right

image

3.  Choose Search Settings

image

4. Change the results to not use personal results

image

5. Press Save.

 

That’s it! Now, things are as they were.

It was surprisingly difficult for me to build a very simple Carousel application with SenchaTouch 2.0 so I thought I’d make a short blog post with the example code in the hopes it saves someone else some time.  Basically, since this runs from the Sencha CDN, you should be able to paste this code directly into your web site as an html page and it should run directly.

The fact that you have to have an items array inside an items array is a little confusing as well as having to specify the height or nothing comes out.  I’m used to using flex: 1 to get the width right, but I had forgotten about height.

Here is what is created and the html and JavaScript code.

 

image

 

and the html:

 

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SenchaTouch 2.0 Carousel Example From PeterKellner.net</title>
    <link rel="stylesheet" type="text/css" href="http://extjs.cachefly.net/touch/sencha-touch-designer-edition/resources/css/sencha-touch.css" />
    <script type="text/javascript" src="http://extjs.cachefly.net/touch/sencha-touch-designer-edition/sencha-touch-all-debug.js"></script>
    <script type="text/javascript">

        Ext.setup({
            fullscreen: true,
            onReady: function () {
                Ext.create('Ext.Panel', {
                    fullscreen: true,
                    height: 200,
                    items: [{
                        xtype: 'carousel',
                        height: 200,
                        items: [
                                {
                                    title: 'title card 1',
                                    html: 'card1',
                                    cls: 'card1'
                                },
                                {
                                    title: 'title card 2',
                                    html: 'card2',
                                    cls: 'card2'
                                }
                            ]
                    }]
                });
            }
        });
    </script>
</head>
<body>
</body>
</html>

HTH’s

Yes, this is JavaScript I’m debugging in Visual Studio 2011 Pre Release.  Just like c# and vb!  A picture is worth hundreds of words, so, here is the picture (and of course the words will follow).

 

image

 

About 1 year ago, I did a similar post explaining pinned variable with Visual Studio 2010 and the .net framework.

http://peterkellner.net/2010/12/08/pinning-watch-variables-while-debugging-visual-studio-2010/

I won’t go into all the details again, but suffice it to say, everything is the same, but now I’m debugging in JavaScript!  Up until now, I’ve felt like Firebug, Chrome and IE debuggers in JavaScript were the best way to go.  This really changes my mind.

If you notice, the problem I’m solving is I’m verifying that my min’s and max’s are tracking correctly.  Notice that I can keep pressing “run” and as I do I can see the live new values without having to go search them out.  Those variables are right where I want them.

Totally awesome!  Nice job VS team.

One of the standard things we programmers do is to read static files from our project directory.  That is, say you put a json file such as /data/stats_data.json at the root of your Visual Studio 2011 PreRelease Developer Edition project and you want to read it and convert it to a JavaScript object using WinRT (JSON.parse(..)).  This post explains how to do that using the Metro App Development Framework with JavaScript.

 

By way of background, this post was motivated by two threads I had with a great support helper on the MSDN forums named Jeff Sanders.  The links are here:  Thread 1  and Thread 2.

image

 

First, let’s look at the basic empty project by creating a Blank Application as follows:

 

image

 

Then, drop some JavaScript into a new data directory which is what we plan on reading into our JavaScript.

 

image

 

Now, let’s add some code to the default.js file and one function called ReadAllDataFile that actually does the heavy lifting.  Add to the default.html just one div tag in the body so we can prove we did something good, and run it.  Below is the project that has all this in it.

Link To Download Project:  

 

And the explanation for the code pasted to the bottom with line numbers now (though it’s pretty self explanatory).  If you feel the urge to cut and paste the code, you will get annoyed with my line numbers. I’d suggest grabbing the zip file of the project from above and using that code for pasting purposes.

    • Line 57 simple is the code that executes when the app launches. All it does is call our function ReadAllDataFile with the local path to the file we want.
    • Lines 4 and 5 get the location of our project. Remember, out deployment is actually copied some place totally different and packaged for running.  It is not running in our local directory so it’s important that whatever file you reference be a part of your solution.
    • Lines 7 and 8 basically create a “promise” which when the file is accessed, will return and execute the anonymous function we are passing it (starting with ..(function(stream) {…).
    • Line 15 completes after the promise to read the file.
    • Line 19 should actually be enough, but I found that some json files have wide characters in them causing it to crash.  The workaround is to read the bytes and convert them while stripping out the higher order characters.  Remember, this is a simple example, you may want those high order characters.
    • Lines 36 and 37 grab the population of the state of New York (my home state) from the JSON file.
    • Line 40 displays it on the web page as follows:

image

(Tablet Simulator Screen Shot With Result Above)

default.js:

   1:  // read the file you want
   2:  function ReadAllDataFile(fileNameInLocalTree) {
   3:      
   4:      var package = Windows.ApplicationModel.Package.current;
   5:      var installedLocation = package.installedLocation;
   6:   
   7:      installedLocation.createFileAsync(fileNameInLocalTree, Windows.Storage.CreationCollisionOption.openIfExists).then(function (dataFile) {
   8:          dataFile.openAsync(Windows.Storage.FileAccessMode.read).then(function (stream) {
   9:              var size = stream.size;
  10:              if (size == 0) {
  11:                  // Data not found
  12:              }
  13:              else {
  14:                  var inputStream = stream.getInputStreamAt(0);
  15:                  var reader = new Windows.Storage.Streams.DataReader(inputStream);
  16:   
  17:                  reader.loadAsync(size).then(function () {
  18:   
  19:                      //var contents = reader.readString(size); // fails with multibyte error if bad data (see legislators.getList.json)
  20:   
  21:                      // allocate the full array so readBytes can insert it in full
  22:                      var array = new Array(size);
  23:                      reader.readBytes(array);
  24:                      
  25:                      var newString = "";
  26:                      for (var i = 0; i < array.length; i++) {
  27:                          // only printable characters (include spaces because could be part of names) (very rough here)
  28:                          // http://www.csgnetwork.com/asciiset.html
  29:                          if (array[i] >= 32 && array[i] <= 126) {
  30:                              var c = String.fromCharCode(array[i]);
  31:                              newString += c;
  32:                          }
  33:                      }
  34:   
  35:                      
  36:                      var result = JSON.parse(newString);
  37:                      var newYorkPopulation = result.NY.P001001;
  38:   
  39:                      // output to the screen
  40:                      document.getElementById('outputhere').innerHTML = "New York Population: " + newYorkPopulation;
  41:                      
  42:                  });
  43:              }
  44:          })
  45:      });
  46:  }
  47:   
  48:  (function () {
  49:      'use strict';
  50:      // Uncomment the following line to enable first chance exceptions.
  51:      Debug.enableFirstChanceException(true);
  52:   
  53:      WinJS.Application.onmainwindowactivated = function (e) {
  54:          if (e.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
  55:              
  56:              // start of my insert code            
  57:              ReadAllDataFile("\data\\states_data.json");
  58:              // end of my insert code
  59:          }
  60:      }
  61:   
  62:      WinJS.Application.start();
  63:  })();

 

Hope this Helps!  Remember, these are pre-beta bits so things could change when production comes a long.  Feel free to add comments to this post and let me know if it stops working. 

For the past month or so, I’ve been more involved at stackoverflow than I have ever been.  I’ve accumulated 317 points (not much, but enough to be part of the community) and until this morning, I had forgotten what I don’t like about this community site.

Specifically, I asked a very straight forward question which I feel I asked both respectfully and appropriately.  I created a very succinct title and tagged it in a very reasonable way.  I’m definitely not a JavaScript/IPad wizard, but I do know how to effectively work with community forums.

My Question:  “Heuristically figuring out whether I’m running IPad1 or IPad2

Let me go through the responses 1 by 1 and I think you will see how this really annoyed me.

  1. nnnnn responds with “what do you mean “heuristically”.    Well nnnn, shall I google that for you?  how about if you read my question and looked up heuristically you would know the answer to your own question, but then, nnnnn has over 9000 points so who am I to suggest something like that.
  2. Mitch tells me to “Fix the cause, NOT the symptoms”.  Well Mitch, did you find that in some book of snappy forum retorts?  How do you know that my problems can be fixed by reducing memory usage without killing the usefulness of the solution.  No Mitch, you don’t know that so another unhelpful answer, but again, Mitch has over 11,000 points so again, how am I to criticize.
  3. Finally, the last comment (by definition) says “closed as exact duplicate by Sam152 (5917 points), nnnnn (9527 points), Don Roby (11,854 points), Mitch Wheat (103,375 points) and Ben Voight (66,445 points).  There reason which is that my question is a duplicate is patently false.  Also, the answer they point to is also patently false!  Running IOS 5.0.1 on both IPad1 and IPad2 return identical device strings.  I know because I have both devices and I’ve tested that.  Not only that, I’m guessing none of all those high point people even read my question which explicitly asked for a heuristic solution.

Bottom line, very frustrating.  I’m sure there a lot of good things going on at stackoverflow, however today, I feel like a squashed bug with my question.  On a slightly positive note, 2 people did point out that the question shows research effort and voted up the question so I guess it’s not a lost cause (even though the door has been slammed shut but the 5 stack overflow veterans who marked the question as “exact duplicate”.  I asked for it to be reopened but I suspect after this post I will probably lose my 317 points for questioning the kings.

I’ve been building a small app in Windows 8 Metro so have been learning quite a bit about how to use my desktop efficiently.  One of the big hassles is that Windows 8 really wants you to use the Metro interface to launch programs.  Probably on a single screen device or tablet with no physical keyboard this works well, but in a desktop environment where we all are use to the fast “start” button with search, the Metro interface is quite inconvenient.

So, my solution is to put as many apps on my desktop as I can, then they are just one click away.  The way I have found to do that is to launch file explorer, find the actual program you want to put on your desktop, right click on it and say “Add To Desktop” as is shown in the picture below:

 

image

 

Notice that I’m actually putting the file explorer itself on my desktop.

 

image

 

I’ve found that if I want to bring up multiple file explorers, then this is a good way to do that.  If I bring it up by way of the Metro interface, I can only bring up one instance of file explorer.

*Note 1/3/2012 – I have discovered that if you press shift and launch from your task bar that an additional copy comes up rather than taking you to the first copy you launched.

HTH’s.

 

Background

The new Windows 8 Developer environment is seriously under documented at this point in it’s product life.  Microsoft released a “Developer Preview” at the Build Conference in September, than has not done any noticeable updates or improvement on those bits.  The Video’s online from build are very helpful because you can go through them in slow motion and see how to make things work.  In this article, I’m going to go through the steps necessary in a lot of detail to build a simple list read-only list viewer of US Congress legislators in California.  At the end, we’ll have something like the following working:

 

image

(actual tablet from build running the app)

 

and the completed solution from Visual Studio 2011 (it’s always nice to have source)

 

Getting Visual Studio 2011 Going To Create The Project

First, launch Visual Studio 2011 and give the standard File/New Project choice and chose JavaScript / Windows Metro Style / Fixed Layout Application as follows:

image

 

Notice, there are two files we will primary work with, default.js and default.html.

 

image

The default.html is a very classic html page with just the standard html doctype, some JavaScript includes, a style sheet and a simple div container.  The default.js is actually what gives this page life.

One thing you’ll quickly discover if you have done much web development before (particularly JavaScript) is that unlike XAML in Visual Studio, there is no design view.  This shouldn’t be an entire surprise because in Microsoft’s ASP.NET MVC, there also is know design view for html files.  However, there is a really big difference here that I don’t see people pointing out clearly enough.  I’m going to say it twice for emphasis.  When you run your Metro App, there is no IE Debug, Firebug or Chrome Developer Tools to look at what are running (OK, I’ll spare saying it again, but this is really critical).  The way most of us do web development that depends on a lot of JavaScript is to launch the application in the browser, then dive into the browser’s debugger and do all there debugging from there (that is by running the Visual Studio project outside the Visual Studio debugger.

Blend to the rescue! (more like fire, and without Expression Blend, the house would burn down).  When you right click on the HTML file (as shown below) and open in blend, you will now see the page as if it were being run.  I’ve noticed that if I load my JavaScript data stores from local arrays, those actually render, but if I try to pull data from a live data source they do not.  I’m guessing that’s my misunderstanding for how to do it, rather than a product short coming.

 

image

 

Putting Down the ListView in HTML

Let’s get down to some real work here.  First, let’s open the default.html and put down a listview.  Before though, let’s look at what the template gives us (it’s very simple and boring).

<body>
    <div data-win-control="WinJS.UI.ViewBox">
        <div class="fixed-layout">
            <p>Content goes here</p>
        </div>
    </div>
</body>

We’ll add all our stuff to the “Content goes here”.  Fist, let’s add the listview control as follows:

<div id="listview"
   class="flipView"
   data-win-control="WinJS.UI.ListView" 
   data-win-options="{dataSource: itemDataSource, itemRenderer: personTemplate,
       layout: {type: WinJS.UI.GridLayout, maxRows:2}}"
     style="margin: 15px 15px 15px 15px; left: -3px; top: 10px; height: 100%;width: 100%">
</div>

and the template itself:

<div id="personTemplate" data-win-control="WinJS.Binding.Template">
<div style="width: 100%;height: 100%">
<div style="margin: 15px 15px 15px 15px">
    <img data-win-bind="src: govtrack_id convertGovTrackIdToImgTag" 
        alt="Databound image" />
    <h3>
        Rep <span class="content" data-win-bind="innerText: firstname">
         </span>&nbsp;<span class="letter"
            data-win-bind="innerText: lastname">
         </span>
    </h3>
</div>
</div>
</div>

Remembering that any style that begins with data- is ignored by html and can be handled by the program for doing template type stuff, you see here that we have a windows control declared which is based in the WinRT runtime (WinJS.UI.ListView).  We also have options set declaratively here in the data-win-options.  All those can be set in the default.js file which is often easier because the intellisense helps us.

Explaining the options is as follows:

    1. datasource:  defined in the default.js and is what we refer to this listview’s data source with
    2. itemRenderer: next, I’ll explain this. It points at the div that has the actual rendered template
    3. layout: just says what kind of layout. in our case, GridLayout.
    4. style: should really be set in a class but I got a little lazy since I’m not so good at the CSS stuff

And, don’t forget to update your depencies (namespaces for all your c# folks out there).  Here are the ones you need to replace in your html file.

    <script type="text/javascript" src="WinJS/js/base.js"></script>
    <script type="text/javascript" src="WinJS/js/ui.js"></script>
    <script type="text/javascript" src="WinJS/js/binding.js"></script>
    <script type="text/javascript" src="WinJS/js/controls.js"></script>
    <script type="text/javascript" src="WinJS/js/res.js"></script>
    <script type="text/javascript" src="WinJS/js/animations.js"></script>
    <script type="text/javascript" src="WinJS/js/uicollections.js"></script>
    <script type="text/javascript" src="WinJS/js/wwaapp.js"></script>

 

 

JavaScript File Update

Finally, let’s update the JavaScript file.  First, we need to create a simple array that we will databind to.  Then, we need to associate that array with the itemDataSource and finally execute.  The only thing tricky we have here is a Converter that takes an Id and build an image src tag for the image control itself.  Notice that the converter is called convertGovTrackIdToImgTag.  It takes in a govTrackId and returns the full blown URL to tick in the image url.

All the source is below.

Hope this helps!

 

 

convertGovTrackIdToImgTag = WinJS.Binding.converter(function (govTrackId) {
    var retUrl = 'http://www.govtrack.us/data/photos/' + govTrackId + '-50px.jpeg';
    return retUrl;
});


var itemDataSource = {};

(function () {
    'use strict';
    // Uncomment the following line to enable first chance exceptions.
    Debug.enableFirstChanceException(true);

    //allLegislatorsCreateFile();


    WinJS.Application.onmainwindowactivated = function (e) {
        if (e.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {

            var items = [];
            var itemsFresh = [{
                firstname: "Barack",
                lastname: "Obama",
                govtrack_id: "400629"
            },
            {
                firstname: "Adam",
                lastname: "Smith",
                govtrack_id: "400379"
            },
            {
                firstname: "Adrian",
                lastname: "Smith",
                govtrack_id: "412217"
            }];
            items.push(itemsFresh[0]);
            items.push(itemsFresh[1]);
            items.push(itemsFresh[2]);

            itemDataSource = new WinJS.UI.ArrayDataSource(items);
            WinJS.UI.processAll();
        }
    }
    WinJS.Application.start();
})();

Lots of trial and error, however I think I finally have a repeatable process to install Windows 8 Preview on my Lenovo W520 Laptop Computer.  First, some things that don’t work.

  1. Use the NVidia drivers included with Windows Update
  2. Use the NVidia drivers on the NVidia site
  3. Use the Lenovo ThinkVantage System Update

And, for what does work.

  1. Set the bios mode to Discreet Mode
  2. Boot from the USB key provided at BUILD
  3. Make sure to skip installing the NVidia drivers on Windows Update
  4. ReBoot a lot.  After every possible prompt and update install
  5. Download Just the NVidia Video driver from the Lenovo Web site
  6. Don’t accept the second choice for more installation stuff when the NVidia driver prompts after about 15 minutes

What I Have:

  1. Display Port Attached to Dell 3007 (2560×1600)
  2. VGA Port Attached to Dell 20” monitor (1600×1200)
  3. Built In Video on W520 (1920×1200)

And, yes, all three at the same time (see below picture.

 

3mon

 

I’m still trying to find some kind of touch device that will let me do Metro type stuff.

Hope this helps!

I’ve been working on an HTML5/CSS3 SenchaTouch project for many months now and near the end we our finding that we have problems on an IPad1 only and all I have is an IPad2.

My 700+ twitter buddies to the rescue.

I tweet: 

image

And, within about 5 minutes comes back:

 

image

 

Not to mention from Facebook, another one because my tweets go to Facebook also.

 

image

 

At any rate, I had 3 different people testing my app on an Ipad1 within 15 minutes.

Totally awesome and thank you social buddies!

I’ve been using EntityFramework’s CodeFirst 4.1 on a new project I’ve been working.  I plan to blog quite  bit about it, but in the mean time I just felt the need to share.  I’ve got some fairly complex code where I add an object tree to the database context (which turns into SqlServer data).  When I call db.SaveChanges(), I get an awesome error (see below) telling me exactly why it failed.

I’m currently on the honey moon with EF CodeFirst.  I only have about 10 tables (4 deep at most).  Life is good.

  
image

Yesterday, I turned my Samsung DROID CHARGE 4G from Verizon on and it asked me if I wanted to update.  Always wanting that, I said yes.  After two days, here are the nice things I’ve found (nothing bad so far).  I was surprised when it finished, it did not offer me any idea of what it did though.  I’m pretty sure it’s the Gingerbread update.  My Phone Info now says 2.3.6 Firmware Version

So, here are the features (and screen shots)

 

New Version numbers on main screen. image
Nice transitions for top toggles (wifi,bluetooth, etc).  Before, it was hard to tell if bluetooth was on, coming on, off or going off. image
Shows top in green when phone is active.  That is, it reminds me I have a phone call going while I’m doing something else. image
pinch gives up to 4 browser sessions in carousel mode image
breadcrumb icons showing which screen I’m on. Note at the top. I also has a button next to the screen numbers which brings up the screens all together like in the next screen shot.  Also, when scrolling through the carousel, it now wraps from last to first instead of hitting a wall. image
Allow me to set any screen as home screen. image

 

Feel free to add comments below about other things.

 

I’m always somewhat amazed when I read something from documentation that is not straight forward and it actually works.  So amazed and excited that I often feel the need to blog about it.

So, here is the problem.  I created a CodeFirst implementation of EntityFramework in Visual Studio and created a simple hierarchy in my data model.  That is, without showing all the code, here is what I have:

public class Person
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }

public virtual List<EmailAddressInfo> EmailAddressInfoList { get; set; }
..
}

public class EmailAddressInfo
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }

public string EmailAddress { get; set; }

}

public class EmailAccount
{
[Key]
[DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
...
}

Now, if you execute a LINQ command like the following:

var recs = (from data in db.Persons
select data);
foreach (var rec in recs)
{
foreach (var email in rec.EmailAddressInfoList)
{
Console.WriteLine(email);
}
}

You get the error:

Exception Details: System.InvalidOperationException: There is already an open DataReader associated with this Command which must be closed first.

 

image

 

To solve this, you need to tell EntityFramework/CodeFirst to include the EmailAddressInfoList in the query.  All you need to do is change the db.Persons to db.Persons.Include("EmailAddressInfoList") as follows:

 

var recs = (from data in db.Persons.Include("EmailAddressInfoList")
select data);

 

Then, it all works!

Hope this helps.

Ever since Microsoft released Windows Live Writer, posting articles to this blog (and others) has been really easy.  Even though this blog is powered by WordPress, Microsoft’s Live Writer let’s me author my blog posts, include pictures, format code and do all kinds of other tricks really easily.  One of the side benefits of using Live Writer is it gives you a very easy way to format HTML code.

So, turns out, that when you are writing a post with Live Writer, at the bottom of the page there are three tabs, Edit, Preview and Source.

 

image

 

When you switch to source, you will see the raw html.  You can also modify the source there which is our trick for formatting the HTML.

So, here are the steps:

 

1.  Start Live Writer (it starts with an empty post)

2.  Copy your unformatted HTML into the “Source” tab as shown above (it will look like this below)

image

3.  Click on the “Edit” tab at the bottom of the page

4.  Click Back on the “Source” tab at the bottom of the page

And now, it will look like this:

image

 

Now, you can cut and paste the code and put it anyplace you want.

Hope this helps!

 

I just noticed that in the beta of Google Analytics, you can now see real time statistics of what is going on for a web site.  As a numbers junky, this is totally awesome!  I just have to keep myself from spending all my time looking at this page.  Below is a screen shot of what I’m seeing right now for traffic on http://peterkellner.net.  just to summarize, here is what it is telling me:

    1. 7 people are browsing my site right now.
    2. They got there with searches including “androd samsung epic sprint connection error” among others
    3. The Map shows where in the world they are all connecting from
    4. 82% of these are new and 18% returning
    5. The site is averaging about 3 or 4 page views per minute (not requests)

The other cool new feature is click tracking.  That is, tracking how many people clicked “contact us” from any given post.   As a developer who has a service business and always looking for new customers, it’s important for me to know which pages provoke people into wanting to contact us for help with there projects.

 

That’s it for now!

 

image


© 2012 PeterKellner.net. All Rights Reserved