Archive for the ‘Computers’ Category.

Why uptime on WP7 cannot be longer than 24.9 days?

This morning I saw in System View on my Samsung Omnia 7 that uptime is “more than 24.9 days”, and boot time is “earlier than 30-Dec-11 13:07:24”. At first I was amazed, how can it be “earlier than”, and how that reference in time is not fixed (it was 29-Dec yesterday). Then I realized that phone does not “remember” its time of boot, but has some sort of incrementing register for counting uptime, and it hits its limit on 24.9 days. It would be interesting for how long this phone can work without reboot, as it seems very stable, but it seems that cannot be known without manual recording of boot time Disappointed smile.

I did some calculations, and it seems that phone is using SIGNED int as register value which counts number of MILISECONDS since boot. As 25 days has about 2’160’000’000 milliseconds, and 2^31 is 2’147’483’648, it starts to seem logical where did number 24.9 days came from Nerd smile. It is logical that boot time itself is not recorded, as there it would be a possibility of reporting “fake” uptimes by setting the clock on the phone. However, in my opinion, method used is also not optimal.

So, what could be better here? Light bulb

- For start, it could be unsigned int, so the OS would be able to keep track for more than 49 days of uptime.
- It could also count seconds instead of milliseconds, that would make possible to count more than 1300 years of uptime Smile, or if for some reason needs to keep milliseconds (i.e. does not want to break all existing functionalities?), unsigned long (int64) could be used (although I don’t remember if it is available in WP7), to give overkilling amount of almost 585 millions of years Hot smile.

All this considered, it seems that 49 days would be enough, change would not break anything, and it requires changing only one variable declaration.

Solution for VHD_BOOT_HOST_VOLUME_NOT_ENOUGH_SPACE error in windows 8

If you are using VHD method of installing windows 8 to virtual disk on physical machine (Scot Hansellman has great tutorial: http://www.hanselman.com/blog/GuideToInstallingAndBootingWindows8DeveloperPreviewOffAVHDVirtualHardDisk.aspx) and you get VHD_BOOT_HOST_VOLUME_NOT_ENOUGH_SPACE error after installation, then your problem is probably dynamic VHD and not enough free space on disk containing that drive. I had the same problem, and googling for it did not solve it, as there is one little catch that is not very known:

You need to have enough free space on physical disk containing VHD that it can contain whole VHD IF IT WOULD GROW TO MAXIMUM DECLARED SIZE! So 100GB VHD on a 90GB free space is a no-go, it does not matter that Windows 8 will use only about 11GB after clean installation.

Windows 8 setup does not check for this, so you may be able to install it, and not able to boot it :)

Log on to windows as a local user without computer name

Yes, you all know that you can use computername\user or 192.168.x.y\user, or even domain\user when logging on to machine.

But, when you want to login as local user and don’t know computer name, and do not want to type IP address, you can use any\user where any can be anything.

Nice little security flaw?

ASP.NET MVC3 app (part 1) – Entity Framework and code first

How often you need to have cascading choices on UI in order to make your application user friendly? In my experience, almost every modern application has some form of hierarchy, and that is where cascading dropdowns are used. But, I want to make this less repetitive and more elegant. So, let’s begin. In first part (this) I will create an simple web app using entity framework code-first and make simple model which will be used for creating this functionality. It is one speedy run-through of new features, without advanced topics, so mind some bad practices, this blog post is not about good programming, first part is for MVC3/.NET 4 beginners with experience with older versions of MVC and .NET.

It will be an mvc3 razor internet application:

image

With latest MVC tools update there are already almost all necessary NuGet packages installed in new project:

image

I will just update all of jQuery packages as they have updates at the moment, and add EntityFramework.SqlServerCompact (NuGet will add dependencies), so SQL server won’t be needed.

As this is demo app, I will put everything into single project. It will be an product catalogue.

This is data model:

image

Central object will be product model (I will use vehicles domain), which has type, version, trim level and manufacturer. Simple enough. Objects on diagram are simple POCO objects with collection properties marked as virtual, so entity framework can override them and inject DynamicProxy objects for lazy loading.

This will be my repository:

image

For this DbContext to work, I need to do one more thing – to put connection string into my web.config:

image

As I don’t want to create test data every time I change my model, I can use database initializer class to create test data (this is useful for unit testing):

image

And this is it. I now have database and data. Actually, I will have it when I start my application, if I add this to global.asax:

image

To test this, I will use controller autoscaffold feature of new MVC tools update:

image

This will autocreate controller and all views Smile. After this action, starting app and visiting http://localhost:57095/Manufacturer will give:

image

Note that only manufacturers for which I created Models are in database. This is because I only added Models, and EF added all related objects, and BMW was not among them.

Using auto scaffold I created controllers for all model objects in couple of minutes.

This is end of part 1, I now have application which will I use to create unobtrusive cascading dropdowns. In the next part I will make cascading dropdown loading using standard methods (jQuery and ajax).

For more info about EF Code First, visit

http://www.hanselman.com/blog/SimpleCodeFirstWithEntityFramework4MagicUnicornFeatureCTP4.aspx

and

http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx

UPDATE: Added part 2

Take my work with me

How often did I need to copy whole virtual machine because I needed to continue work on another location? A way too often. And moments when I wait for 20-30GB to copy, sometimes seem like eternity.

Well, I spent couple minutes last night to prevent that :)

Here is a batch script which copies folder with my work from hdd and takes backup of database. Even more, it restores everything back when I arrive at another location :)

So, save this script as common.bat:

@echo off
set server=HOSTNAME\INSTANCE
set dbName=DATABASE
set projFolder="C:\Users\gorano\Documents\visual studio 2010\Projects"
set backupFolder=%CD%
 
if "%1"=="leaving" GOTO backup
if "%1"=="arriving" GOTO restore
echo Invalid first argument, must be "leaving" or "arriving"
GOTO end
 
:backup
echo backup database %dbName%
@echo on
sqlcmd -E -S %server% -Q "BACKUP DATABASE [%dbName%] TO  DISK = N'%backupFolder%\%dbName%.bak' WITH NOFORMAT, INIT, NAME = N'%dbName%-Full Database Backup', SKIP, NOREWIND, NOUNLOAD, STATS = 10"
xcopy %projfolder% %backupFolder%\Projects  /E /I /Y /Q
GOTO end
 
:restore
if "%2"=="DeleteOld" GOTO deleteold
:restoreNoDelete
echo restore database %dbName%
sqlcmd -E -S %server% -Q "RESTORE DATABASE [%dbName%] FROM DISK = N'%backupFolder%\%dbName%.bak' WITH  FILE = 1,  NOUNLOAD,  REPLACE,  STATS = 10"
xcopy %projfolder% %projfolder%.backup  /E /I /Y /Q
xcopy %backupFolder%\Projects %projfolder%  /E /I /Y /Q
GOTO end
 
:deleteold
@echo Press any key to delete database %dbName% on sql server %server%
pause
sqlcmd -E -S %server% -Q "ALTER DATABASE [%dbName%] SET  SINGLE_USER WITH ROLLBACK IMMEDIATE"
sqlcmd -E -S %server% -Q "DROP REMOVETHISWORD DATABASE [%dbName%]"
GOTO restoreNoDelete
 
:end
pause

To run this easily, make “i’mleaving.bat” with

common leaving

and “i arrived.bat” with

common arriving DeleteOld

All you need to change is to set your server\instance, database name, folder with projects, and to delete “REMOVETHISWORD” under :deleteold, as words DROP and DATABASE does not stand well together (I don’t want to hack wordpress script injection protection to post this) :)
In combination with DropBox, this is great thing. You can also add 7z line to compress/decompress these files so dropbox sharing is more meaningfull (if you have large database).

Fix selected tab in SharePoint top links menu

Fastest way to accomplish this is to use jquery! :)

function fixTabs(){
    $.each($(".customNavTabActive"), function() {
        $(this).removeClass("customNavTabActive");
        $(this).parentsUntil("table").each(function() {
            $(this).removeClass("customNavTabActive");
        });
    });
    $.each($("a.customNavTab"), function() {
        if (this.href == document.location.href || this.href + "/default.aspx" == document.location.href) {
            $(this).parent("td").addClass("customNavTabActive");
        }
    });
}

Update: I have improved this code a little bit :)

function fixTabs(){
    var normalNavTavCss = "customNavTab";
    var firstCellActiveCss = "customNavTabActive";
    var firstCellCss = "customNavTab";
    var lastCellActiveCss = "customNavTabActive";
    var lastCellCss = "customNavTab";
    var cellActiveCss = "customNavTabActive";
    $.each($("." + cellActiveCss), function() {
        $(this).removeClass(cellActiveCss);
        $(this).parentsUntil("table").each(function() {
        $(this).removeClass(cellActiveCss);
        });
    });
    var lastCell;
    var lastCellSelected;
    $.each($("." + normalNavTavCss + " a"), function(i) {
        lastCell = $(this).parent("td");
        var location = document.location.href.replace("/default.aspx", "");
        var link = this.href.replace("/default.aspx", "");
        lastCellSelected = (link == location || location.indexOf(link) > -1);
        if (lastCellSelected) {
            if (i == 0) {
                lastCell.addClass(firstCellActiveCss);
            }
            else {
                lastCell.addClass(cellActiveCss);
            }
        }
        else if (i == 0) {
            lastCell.addClass(firstCellCss);
        }
    });
    if (lastCellSelected) {
        lastCell.removeClass(cellActiveCss);
        lastCell.removeClass(firstCellActiveCss);
        lastCell.addClass(lastCellActiveCss);
    }
    else {
        lastCell.addClass(lastCellCss);
    }
}

Localizing Sharepoint resources – transliteration to Cyrillic

Recently I tried to localize MS WSS 3.0 site collection to unsupported language – Serbian, cyrillic (Serbia). LCID of this culture is 3098. This language is almost the same as existing latin localization to Serbian (Serbia) with LCID 2074. To get cyrillic version of resource files (resx), I installed Serbian latin language pack and searched wwwroot and 12 folders for “sr-latn-cs”, and took following files: core.sr-latn-cs.resx, resources.sr-latn-cs.resx, spadmin.sr-latn-cs.resx, spcore.sr-latn-cs.resx, spsearchadmin.sr-latn-cs.resx and wss.sr-latn-cs.resx

I got Search Center and language pack for it installed, so in an environment without search center, there should be some of these files missing.

To get sr-cyrl-cs.resx versions of theese files, I made small console application which parsed through xml files and replaced latin letters with cyrillic. Character swap is simple, and to parse xml I used following code:

static void Main(string[] args)
        {
            if (args.Length == 0) args = new string[]{"source", "destination"};
            DirectoryInfo source = new DirectoryInfo(args[0]);
            foreach (FileInfo file in source.EnumerateFiles())
            {
                XmlTextReader reader = new XmlTextReader(file.OpenText());
                XmlDocument doc = new XmlDocument();
                doc.Load(reader);
                reader.Close();
                FileInfo dest = file.CopyTo(Path.Combine(args[1], file.Name.Replace(SourceLang, DestLang)), true);
                XmlDocument destination = new XmlDocument();
                foreach (XmlNode node in doc.ChildNodes)
                {
                    ParseChildren(node);
                }
 
                XmlTextWriter writer = new XmlTextWriter(dest.OpenWrite(), Encoding.Unicode);
                doc.Save(writer);
                writer.Close();
            }
        }
 
        private static void ParseChildren(XmlNode sourceNode)
        {
            foreach (XmlNode node in sourceNode.ChildNodes)
            {
                switch (node.NodeType)
                {
                    case XmlNodeType.Text:
                        if (node.Name == "#text" && node.HasChildNodes == false 
                            && node.Value.Length > 0 && node.ParentNode.ParentNode.Name == "data")
                        {
                            if (!node.ParentNode.ParentNode.Attributes["name"].Value.ToUpper().Contains("accesskey".ToUpper())
                                && !node.ParentNode.ParentNode.Attributes["name"].Value.ToUpper().Contains("_AK".ToUpper()))
                            {
                                node.Value = SmartConvertToCyrillic(node.Value);
                            }
                            else
                            {
                                break;
                            }
                        }
                        break;
                    default:
                        break;
                }
                if (node.HasChildNodes)
                    ParseChildren(node);
            }
        }

Important lines here are in case XmlNodeType.Text:

Those lines discriminate nodes which are values and need to be transliterated to Cyrillic.

When new resx files have been placed back to same respective folders where their sources for transliteration were found, then new language had to be enabled in Sharepoint.

Registry key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Shared Tools\Web Server Extensions\12.0\InstalledLanguages contains string values whose names are LCID-s of installed languages, and value is version of satellite assembly of microsoft.sharepoint.intl.resources.dll in GAC. I added new string value named “3098″ with value “12.0.0.0″. I even disassembled latin version of this dll and made cyrillic but I have what it seems unsolvable problem of impossibility to build that dll in Language version other than “Language neutral”, and I believe that is the key to enable localization of administration pages and parts of UI that is not localized.

Adding 3098 registry value enabled “Serbian Cyrillic” language in “New Web Site” SharePoint page, but to get templates for Team site, Blank, etc, it is necessary to make “3098″ folder in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\

I used 2074 folder as a template, and edited files in 2074/XML subfolder to get site templates in site creation wizard.

Newly created site was mostly localized – parts which are visible to users, but administrative pages are localized from satellite dll, and I did not succeed in building language specific version of dll to use it for this purpose. Also, this dll must be signed for SharePoint to use it, and to circumvent this I used delay sign, and then added exception for signature verification using gacutil.

This was very useful resource http://social.msdn.microsoft.com/Forums/en/sharepointdevelopmentprerelease/thread/023d1fb9-c415-405a-8944-c709c0cc8f01

Useful links

Page with bunch of useful software (Stranica sa hrpom korisnog softvera)

http://www.weethet.nl/english/download.php

Find alternatives to well known programs:

http://alternativeto.net/

Windows 7 hotkeys:

http://hubka.net/archive/2009/03/29/windows-7-hotkeys.aspx

Fix MSN pop-up on minimizing Firefox:

http://jonathanhu.com/2009/05/15/how-to-fix-windows-live-msn-pop-up-when-minimize-firefox-in-windows-7/

Change default location for Windows 7 Windows Explorer:

http://www.windows7hacker.com/index.php/2009/05/how-to-change-the-default-location-in-windows-explorer-to-my-computer-in-windows-7/

PID/VID database – info on any unknown hardware

http://www.pcidatabase.com/

Fix Vista TCP/IP after clicking on “Remove outdated LSP”:

Reinstall and Reset TCP/IP (Internet Protocol) in Windows Vista, 2003 and XP » My Digital Life

Many pdf books on computer sciences:

FlazX – Welcome to your Computer & IT learning center

Convert .nrg to .iso

Great free tool to convert nero image files to .iso (besplatan alat za konverziju nerinih imidža u iso)

http://3d2f.com/download/33-522-nrg2iso-free-download.shtml