DCSIMG
July 2011 - Posts - Shai Raiten's Blog

Shai Raiten's Blog

It's all about code...

July 2011 - Posts

WP7 Restoration Error - C101002E

תמיכה בעיברית וכיון כתיבה ב–Microsoft Test Manager

Kinect-Could not load file or assembly 'INuiInstanceHelper.dll’

Create Your Own WP7 Deployment Application

image

Couple of days ago Microsoft opened AppHub for Israel as well, I’ve started to write more game and applications for WP7 (WP7 Submit Application - The [NeutralResourceLanguage] attribute is missing on the entry assembly).

While working on several applications I noticed that I want to see the application properties before deploying them inside my WP7 device, when working in Visual Studio 2010 It’s easy because you can deploy your project from Visual Studio himself but I’m also working with many XAP file out side of Visual Studio and the default application deployment didn’t give me what I wanted.

zip Download Demo Project

How To Build Your Own WP7 Deployment Application

Before we get started how to deploy XAP file to WP7 Application?
There is a method called InstallApplication that gets the application guide, the genre of the application, the path for the Application Icon and the Xap file itself.

public RemoteApplication InstallApplication(Guid productId, 
Guid instanceId, string applicationGenre, string iconPath,
string xapPackage);

First how to get all WP7 devices connect to your machine?

Add “Microsoft.SmartDevice.Connectivity.dll” to your project
(C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.SmartDevice.Connectivity\
v4.0_10.0.0.0__b03f5f7f11d50a3a\Microsoft.SmartDevice.Connectivity.dll)

Then I used the DatastoreManager to obtain all Platforms and for each platform get the devices.

image

static IEnumerable<object> GetDevices()
{
    var manager = new DatastoreManager(CultureInfo.CurrentUICulture.LCID);
    return manager.GetPlatforms().SelectMany(platform =>
      platform.GetDevices()).Cast<object>().ToArray();
}

Each XAP file (basically zip file) contains “WMAppManifest.xml” the with all the application information inside.

<App xmlns="" ProductID="{GUID}" Title="Raise My Dog"
RuntimeType="Silverlight" Version="1.0.0.0" Genre="apps.normal"
Author="Shai Raiten" Description="Raise My Dog is an interactive game
for WP7 that allows you to
raise a dog inside you mobile device.
"
  Publisher="RaisePets"
>

Now I’ve enable Drag&Drop on my window to accept XAP files and extract the information I wanted from the “WMAppManifest.xml” file located inside the XAP.

private const string FileFilter = "WMAppManifest.xml";


private
 XapInfo GetXapInformation(string xapPath)
{
    try
    {
        var fastZip = new FastZip();
        var tempFile = Path.Combine(Path.GetTempPath(),
          Path.GetRandomFileName());
        fastZip.ExtractZip(xapPath, tempFile, FileFilter);
        var files = Directory.GetFiles(tempFile);

        if (files.Length == 0) return null;

        using (Stream stream2 = File.OpenRead(files[0]))
        {
            var document = new XPathDocument(stream2);
            var selectSingleNode = document.CreateNavigator()
              .SelectSingleNode("//App");
            if (selectSingleNode != null)
            {
                return new XapInfo(selectSingleNode, files[0], xapPath);
            }
        }
    }
    catch
    {

    }

    return null;
}

So I’ve create XapInfo class to contain the entire data for the deployment

public XapInfo(XPathNavigator node, string filePath, string xapFile)
{
  this.Guid = new Guid(node.GetAttribute("ProductID", string.Empty));
  this.Title = node.GetAttribute("Title", string.Empty);
  this.Description = node.GetAttribute("Description", string.Empty);
  this.Version = node.GetAttribute("Version", string.Empty);
  this.Author = node.GetAttribute("Author", string.Empty);
  this.Publisher = node.GetAttribute("Publisher", string.Empty);
  this.IconPath = GetXapIcon(xapFile);
  this.XapFilePath = xapFile;
}

Inside the XapInfo class I had another Zip operation to extract the Application Icon.

private const string IconFilter = "ApplicationIcon.png";

private
 string GetXapIcon(string xapPath)
{
  string iconPath;
  try
  {
    var fastZip = new FastZip();
    var tempFile = Path.Combine(Path.GetTempPath(),
      Path.GetRandomFileName());
    fastZip.ExtractZip(xapPath, tempFile, IconFilter);

    var files = Directory.GetFiles(tempFile);

    if (files.Length == 0) return null;

    var fileStream = File.OpenRead(files[0]) ??
                        Assembly.GetExecutingAssembly().
                        GetManifestResourceStream(IconFilter);

    var tempFileName = Path.GetTempFileName();
    using (var stream3 = new FileStream(tempFileName,
      FileMode.Create))
    {
      fileStream.CopyTo(stream3);
    }
    iconPath = tempFileName;
  }
  catch (Exception)
  {
    iconPath = null;
  }
  return iconPath;
}

Now when you have all the information for the XAP file you can install the application on your device.
The below method will also make sure that if the application is already installed then Uninstall it and then perform the new installation.

var device = (Device) e.Argument;
try
{
    device.Connect();

    if (device.IsApplicationInstalled(_xapInfo.Guid.Value))
    {
        device.GetApplication(_xapInfo.Guid.Value).Uninstall();
    }
    device.InstallApplication(_xapInfo.Guid.Value, _xapInfo.Guid.Value,
"NormalApp", _xapInfo.IconPath, _xapInfo.XapFilePath);
    device.Disconnect();

}
catch (SmartDeviceException ex)
{
    MessageBox.Show(ex.Message, "Deploy Application", MessageBoxButton.OK,
MessageBoxImage.Information);
}

zip Download Demo Project

איך מוסיפים מקלדת עיברית מובנת למכשירי WP7

יש לי מכשיר HTC HD 7 כבר חצי שנה, מהרגע שפתחתי אותו לפיתוח התקנתי תוסף למקלדת עיברית מובנת.

ראיתי מספר אנשים עובדים עם תוכנה שהורידו אשר מאפשרת להם לכתוב בעיברית בתוכנה ולהעתיק את הטקסט לאפליקצייה הנחוצה, זה תהליך ממש לא נוח כל פעם לפתוח את התוכנה לכתוב את מה שאתם רוצים ולהעתיק את הטקסט, לסגור את התוכנה לפתוח את האפליקצייה המיועדת ולהדביק את הטקסט.

אתמול קיבלתי הודעה מחבר לעבודה אשר ראה על המכשיר שלי מקלדת עיברית מובנת שמאפשרת לי לכתוב עיברית בכל אפליקציה.

image

המאמר המקורי הגיע מ – XDADevelopers, אני ממליץ להיכנס ולהתעדכן על גרסאות חדשות.

איך מתקינים מקלדת עיברית מובנת למכשירי WP7

על מנת לבצע פעולה זאת אתה חייב מכשיר פתוח לפיתוח

1. הפעל Application Deployment
(C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.1\Tools\XAP Deployment\XapDeploy.exe)

2. לפי סוג המכשיר הורד וטען את החבילה המתאימה

NativeKeyboard-v3.3.zip - עבור מכשירי Samsung בלבד

NativeKeyboard-v2.16.xap

image

3. המתן עד לסיום ההתקנה

  image

4. הפעל את תוכנת Native Keyboard

image

5. לאחר הפעלת התוכנה בחר בשפה הרצויה (עיברית)

image

6. לאחר סיום ההתקנה יופיע מסך עם תוצאות ההתקנה:
לא לפחד מההודעת שגיאה, חשוב לוודא שאכן מופיע שה – Patching …ok

image 


7. לאחר הדלקה מחודשת של המכשיר תראו תוסף עיברית במקלדת

image

8. עכשיו אתם יכולים לכתוב עיברית בכל מסך בלי העתק הדבק.

image

תהנו!

Cannot Create Database Project - Cannot load file or assembly "Microsoft.SqlServer.Management.SqlParser"

Couple of days ago I’ve format my computer, a fresh start Smile.

Today I tried to open a Database project I’m working on and I got the following error message:

image 

Of course I’ve installed SQL 2008 + with Management Studio and all the other things coming with Visual Studio 2010, but I did make some changes to the 2008 R2 installation… I wanted to remove the Default SQL Express coming with Visual Studio and install the complete suite.

During this process I’ve removed several SQL installations from my machine and this what cause the problem, the SQL Management is working just fine but there are still something missing….

So after couple of minutes investigating the Visual Studio modules I found which installations required for Creating Database Project in Visual Studio 2010.

Enter Microsoft® SQL Server® 2008 R2 Data-Tier Application Framework v1.1 Feature Pack download site, download and install the following:

64bit:

  1. DACFramework.msi
  2. TSqlLanguageService.msi
  3. SQLSysClrTypes.msi
  4. SharedManagementObjects.msi

32bit:

  1. DACFramework.msi
  2. TSqlLanguageService.msi
  3. SQLSysClrTypes.msi
  4. SharedManagementObjects.msi

Enjoy

    WP7 Submit Application - The [NeutralResourceLanguage] attribute is missing on the entry assembly

    As you know AppHub is open for Israel (Now It's Official (I think) - Israeli Developers Can Register to Develop WP7 Apps) and several other countries.

    So I decide to move my WP7 Games and Applications I wrote and publish using YallaApps to my own AppHub, when I started to upload the first XAP file I got this message:

    image

    I’ve used the same XAP as I used in YallaApps so what happened?

    Just add the below attribute to your WP7 Application assembly file and you’re Done!

    [assembly: NeutralResourcesLanguage("en-US",
    UltimateResourceFallbackLocation.Satellite)]

    Enjoy

    How To Change TFS 2010 Attachment Size

    Here is a post from 2008 on how to change attachment size in TFS 2008, the same concept is available in 2010 but there is a small confusion about 2010.

    Many people had problems changing the attachment size in TFS 2010 using the same web service because the following error: 500 Internal Server Error

    image

    There where people who changes the attachment size using code:

    TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(@"yourtfsserver/.../DefaultCollection");
    ITeamFoundationRegistry rw = tfs.GetService<ITeamFoundationRegistry>();
    RegistryEntryCollection rc = rw.ReadEntries(@"/Service/WorkItemTracking/Settings/MaxAttachmentSize");
    RegistryEntry re = new RegistryEntry(@"/Service/WorkItemTracking/Settings/MaxAttachmentSize", "20971520");//20MB
           
    if (rc.Count != 0)
    {   
        re = rc.First();   
        re.Value = "20971520";
    }
           
    rw.WriteEntries(new List<RegistryEntry>() { re });

    But the only thing you had to do in order to change the attachment size in TFS 2010 is to change _tfs_resources to the collection name, as follow:

    http://localhost:8080/tfs/_tfs_resources/WorkItemTracking/v1.0/ConfigurationSettingsService.asmx?op=SetMaxAttachmentSize 

    TO:

    http://localhost:8080/tfs/<CollectionName>/WorkItemTracking/v1.0/ConfigurationSettingsService.asmx?op=SetMaxAttachmentSize

    Enjoy

    You Can Upgrade TFS 2010 to SQL 2008 R2





    sr2

    You probably know that when you buy TFS 2010 your license also includes SQL Server 2008 Standard Edition, couple of weeks after TFS 2010 was released the SQL team released SQL 2008 R2, many customers ran and upgrade their TFS 2010 To SQL 2008 R2 because they think the SQL Server is included.

    But if you didn’t bought license for SQL 2008 R2 you’re not allowed to installed R2 on TFS 2010.

    However, because some feedbacks from MSDN Subscribers Microsoft has change the license and updated the Product Use Rights document.

    The Full Article from –> Brian Harry - MSDN Subscribers can now upgrade their TFS 2010 SQLServer to SQL 2008 R2

    License terms for SQL Server 2008 R2 Technology.  If your edition of the server software includes other SQL Server 2008 R2 technology (for example, SQL Server 2008 R2 Standard Edition), you may run, at any one time, one instance of that technology in one physical or virtual OSE on one server solely to support that software. You do not need SQL Server CALs for that use.  You may create and store any number of instances of SQL Server 2008 R2 technology on any of your servers or storage media solely to exercise your right to run an instance of SQL Server 2008 R2 technology under these  license terms.

    Team Foundation Server MSSCCI Provider 2010





    Even so TFS exists for several years I still  get those questions a lot: Does TFS integrate with other tools?integration

    Of course!, Microsoft release a long time ago the MSSCCI Provider  - The Team Foundation Server MSSCCI Provider enables integrated use of Team Foundation Version Control with products that do not support Team Explorer integration.

    And Microsoft Visual Studio Team Explorer Everywhere 2010 - Eclipse plug-in and cross-platform command-line client for Visual Studio 2010 Team Foundation Server (Microsoft Visual Studio Team Explorer Everywhere 2010 with SP1)

    MSSCCI current version [14/07/2011] (3.3) includes:

    • Updated provider to link against VS 2010 RTM TFS assemblies
    • Improved functionality and performance when used inside PowerBuilder
    • Improved handling of branched solutions in SQL Server Management Studio
    • Decreased number of server prompts
    • Improved error reporting

    Before you install the plug ensure that all instances of Mainframe Express, Microsoft Visual Studio, and TFS Team Explorer are closed

    Download

    • Visual Studio .NET 2003    
    • Visual C++ 6 SP6      
    • Visual Visual Basic 6 SP6  
    • Visual FoxPro 9 SP2        
    • Microsoft Access 2007      
    • SQL Server Management Studio
    • Enterprise Architect 7.5   
    • PowerBuilder 11.5          
    • Microsoft eMbedded VC++ 4.0

    Web Test Manager For TFS 2010




    Couple of months ago Sela Collage were a sponsor in Microsoft ALM Summit in Seattle, there we announced on ALM Products and the first version of Web Test Manager -

    Innovative approach to managing and running your tests - Any Test – AnyWhere - Anytime (by Everyone) under TFS 2010.

    WTM =  Manage your tests directly from your browser in TFS 2010

    Now, for the first time you can manage your tests without the need for any local installation, WTM is a web application integrated in VS 2010 Team Web Access™.

    With WTM you can:

    • Run & Edit Tests from any remote computer
    • Run tests on heterogeneous testing environments (Mac, Linux, AS400 and more)
    • Save 80% or more of the standard costs
    • Requires only a one time installation on the TFS server (no local installations are required)
    • Easy to use and light to run
    • Fast running with quick responsiveness
    • Allows developers to easily run tests as well

    I’m glad to announce that Sela Collage has released Web Test Manager 1.0, and It’s now available to download from Sela ALM Products Page

    Here some Screen Shots

    Manage you Plans and Suites

    image

    Edit and Running Test Cases

    imageimage

    View Test Runs Results

    image

    Add, Create Shared Steps To Suites

    image

    http://www.sela.co.il/alm/products_WTM.html

    Enjoy

    Community TFS Build Extensions





    Yesterday (4/6/2010) the Community released 100 Activities / Actions for TFS 2010, here is some of the new activities

    Download Page

    Code Quality :CodeMetrics, NUnit, StyleCop

    Web : Iis7Website,Iis7AppPool,Iis7Binding,Iis7Application

    Communication: Email

    Compression: Zip

    Virtualization

    • HyperV - An activity to perform HyperV operations within a TFS 2010 build

      Valid Action values are: Start,Shutdown,Turnoff,Pause,Suspend,Restart,Snapshot,ApplyLastSnapshot,ApplyNamedSnapshot

    • VirtualPC - A set of tools to manage VirtualPCs

      Valid Action values are: AddHardDiskConnection, DiscardSavedState, DiscardUndoDisks, IsHeartBeating,IsScreenLocked, List,LogOff, MergeUndoDisks,Pause, RemoveHardDiskConnection, Reset,Restart,Resume,Save,Shutdown,Startup, TakeScreenshot,Turnoff,WaitForLowCpuUtilization, RunScript

    Download Page

    Release Notes

    This is our first Stable release providing in the region of 100 Activities / Actions

    • This release contains assemblies and a CHM file.
    • We anticipate shipping every 2 to 3 months with ad-hoc updates provided to the documentation.
    • We welcome your candid and constructive feedback and look forward to improving the quality with and for you.

    Enjoy


    Kinect – Calculator – Adjust Skeleton Movements To Mouse





    In my previous post Kinect – Create Buttons I’ve showed one approach how to create Kinect Buttons for Windows, over the next posts I’ll show more ways to accomplish that by moving windows Cursor based on Kinect Skeleton Right Hand Position.

    Why To Create Kinect Button?

    Why not using windows cursor and create brilliant hand or head (Smile) movement to simulate Click, so we don’t need to create designated Kinect Buttons.

    Answers:

    1. You had to stand at least 1 meter from the computer screen and even so I’m young I can’t see very well from that distance…
    2. Kinect precision is still not perfect and it’s hard to hit a 48x48 button from that distance.
    3. Even if you increase desktop resolution it’s not easy and not practical to work with both hands to perform Click.
    4. But, I’m going to do that anyway! Magnifying glass, Cool Head or Hand movements etc…

    In this post I’ll take those Kinect Button(working on Timer) implement on a simple Calculator I’ve built and hook the Windows mouse to the Skeleton movement.

    The only major issue with that is to adjust the Skeleton Position to your Screen Resolution, as you know the Skeleton coordinates are expressed in meters and comes from 640x480 screen, so I’ve create new class called Positions that will help me to do it.

    The AdjustToScreen method gets the Joint (and based on the current screen resolution) and another gets the Joint and specific screen width and height.

    public static class Positions
    {
        //For - Resolution640x480
        private const float SkeletonMaxX = 0.6f;
        private const float SkeletonMaxY = 0.4f;
     
        private static float Adjust(int primaryScreenResolution, float maxJointPosition, float jointPosition)
        {
            var value = (((((float)primaryScreenResolution) / maxJointPosition) / 2f) * jointPosition) 
                + (primaryScreenResolution / 2);
                
            if (value > primaryScreenResolution || value < 0f) return 0f;
     
            return value;
        }
     
        /// <summary>
        /// Get the current Joint position and Adjust the Skeleton joint position to the current Screen resolution.
        /// </summary>
        /// <param name="joint">Joint to Adjust</param>
        /// <returns></returns>
        public static Vector AdjustToScreen(Joint joint)
        {
            var newVector = new Vector
            {
                X = Adjust((int)SystemParameters.PrimaryScreenWidth, SkeletonMaxX, joint.Position.X),
                Y = Adjust((int)SystemParameters.PrimaryScreenHeight, SkeletonMaxY, -joint.Position.Y),
                Z = joint.Position.Z,
                W = joint.Position.W
            };
     
            return newVector;
        }
        /// <summary>
        /// Get the current Joint position and Adjust the Skeleton joint position to a specific Screen Size.
        /// </summary>
        /// <param name="joint">Joint to Adjust</param>
        /// <param name="screenWidth">Screen Width</param>
        /// <param name="screenHeight">Screen Height</param>
        /// <returns></returns>
        public static Vector AdjustToScreen(Joint joint, int screenWidth, int screenHeight)
        {
            var newVector = new Vector
            {
                X = Adjust(screenWidth, SkeletonMaxX, joint.Position.X),
                Y = Adjust(screenHeight, SkeletonMaxY, -joint.Position.Y),
                Z = joint.Position.Z,
                W = joint.Position.W
            };
     
            return newVector;
        }
    }

    Now I’ve create another helper class called – NativeMethods to move the set the Cursor  Position based on Skeleton Joint position.

    public static class NativeMethods
    {
        public partial class MouseOperations
        {
            [DllImport("user32.dll")]
            public static extern bool SetCursorPos(int x, int y);
     
            [DllImport("user32.dll")]
            public static extern bool GetCursorPos(out Point pt);
        }
    }

    In the SkeletonFrameReady I’ve added another quality check, also check the Joint TrakingState and not just the Data TrakingState, also make sure the joint position quality (W) is high enough before moving the mouse.

    The quality check will prevent that mouse from jumping around.

    void SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
    {
        foreach (SkeletonData data in e.SkeletonFrame.Skeletons)
        {
            //Tracked that defines whether a skeleton is 'tracked' or not. The untracked skeletons only give their position. 
            if (data.TrackingState != SkeletonTrackingState.Tracked) continue;
     
            //Each joint has a Position property that is defined by a Vector4: (x, y, z, w). 
            //The first three attributes define the position in camera space. The last attribute (w)
            //gives the quality level (between 0 and 1) of the 
            foreach (Joint joint in data.Joints)
            {
                switch (joint.ID)
                {
                    case JointID.HandRight:
                        if (joint.Position.W < 0.6f || joint.TrackingState != JointTrackingState.Tracked) return;// Quality check 
     
                        //Based on Skeleton Right Hand Position adjust the location to the screen
                        var newPos = Positions.AdjustToScreen(joint);
     
                        if (newPos.X == 0f || newPos.Y == 0f) return;
     
                        NativeMethods.MouseOperations.SetCursorPos(Convert.ToInt32(newPos.X), Convert.ToInt32(newPos.Y));
     
                        break;
                }
            }
        }
    }

    Make sure you enable TransformSmooth, you don’t want the mouse jumping around. (Kinect–How to Apply Smooths Frame Display Using TransformSmoothParameters)

    _kinectNui.SkeletonEngine.TransformSmooth = true;
    var parameters = new TransformSmoothParameters
    {
        Smoothing = 1.0f,
        Correction = 0.1f,
        Prediction = 0.1f,
        JitterRadius = 0.05f,
        MaxDeviationRadius = 0.05f
    };
    _kinectNui.SkeletonEngine.SmoothParameters = parameters;

    Live Demo

    Demo Project

    This project includes a Common class with this post main methods, from Moving and mouse and adjusting Kinect Skeleton to desktop resolution.

    image

    Enjoy