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_MACHINESOFTWAREMicrosoftShared ToolsWeb Server Extensions12.0InstalledLanguages 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 FilesCommon FilesMicrosoft Sharedweb server extensions12TEMPLATE

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