Save the private ..data

I was copying a vmware workstation virtual machine when ..blue death screen ! a problem with the USB drivers.

A .vmsn file (vmware snapshot) was ruined, vanished, i tried an undelete software but nothing to do.

The vmware vm was obviously unable to start, and there were 2 disks.

Ok, some work hours for the creation of a new vm, reinstalling all and rescuing the data from the old vm.

For the original vm second disk no problem, i opened the disk from the vmware workstation console, map the content to a drive :


and i was able to recover everything.

But with the main disk (the c: on vm) there is a problem : no way to access the Users folder , or the linked “Documents and settings” one.

I tried to change the perms , but without success: it seems that there are strange permissions linkings between the host and the virtual machine under Windows (if the host and the vm are both Windows based, in my case 2 Windows 7) and i’m not very expert in these issues.

But in the users folder there were some documents , especially on the Desktop folder, and i was needing those files.

How to do ? The solution is to add the vmware windows disk (.vmdk) ,our vm c:, to an Ubuntu virtual machine:


then the disk is immediately mapped and is possible to explore the user folders without permissions problems:


Then , via Samba or more simple with an external drive connected to the network, is possible to save the data.

Categories: VmWare

SQL Server 2012 Sp1 install

After installing a new pc with Sql Server 2012 Express at a certain point in Windows Update there were the option of installing the Service Pack 1 for Sql Server.

The package was heavy, more than 900 Mb, and after some attemps always the same error: 80072F78.

The solution is the manual download of sp1 from http://www.microsoft.com/en-us/download/details.aspx?id=35575

After this , i tried to launch the setup but there is not a linear, simple installation… It seems the normal installation of an SQL Instance and is not clear what to do.

The solution is to launch manually from a command line the setup with this syntax:

setup.exe /q /action=patch /allinstances /IAcceptSQLServerLicenseTerms

Done this , in Windows Update there is an cumulative update and at the end my SQL version is 11.0.3128 (X64)

Categories: SQL Server

Skype via Outlook.com

I was not aware of the strict integration that has now Skype in Microsoft products.

Casually i discovered in SkyDrive that now you have access to Skype without installing the Skype client.

After accessing Skydrive you can switch to Outlook.com, People, Calendar



 
 

In every contest to the right there is an icon as this


Clicking on the icon is possible to access to the Skype interface in the browser, a list to the right.

 
 


Clicking on “start new conservation” appears the contact list and after choosing one is possible to start a session


Below the textbox where to write messages:


If you have the real Skype client on another pc you can see the messaging activity done on the browser , in real time; if someone send a message to you is received in the Skype client and also in the browser.

For a voice call is requested to download a Skype plugin for Outlook.

Categories: Uncategorized

Upgrade of Durandal projects

I’m working with Durandal , and i need to upgrade some old (old..2013…) code.
But this code was written when there was Durandal 1.x , now with NuGet in a Visual Studio 2013 project the version is 2.01 , and are changed a lot of things.

Fortunately in this Durandal site page and in this Papa’s page there are useful guidelines.

Categories: .NET, Durandal, JQuery, MVC, SPA

RequireJS with Visual Studio 2013 & WebAPI

Now that the SPA is the mainstream technology of the moment, i was wondering how really are useful Knockout, Durandal, RequireJS and so on.

These new buzzwords are javascript frameworks, founded (RequireIS no) on the well knowed jQuery.

I have done many web applications with jQuery and SPA concepts , using web forms (.aspx) as html/json generators and then decoding/evaluating the resulted html or JSON by hand.

So i started a lot of tests, trying to convert some old web applications in “à la page” SPA apps.

This is not a simple task , because the technologies are rapidly changing and evolving (as the jQuery versions): so the sample probably working at the time of the publications three months after is not working because jQuery changes, new library versions and so on.

I tried to evaluate RequireJs, the first step was to create with Visual Studio 2013 a new ASP.NET Web Application, using the WebAPI template:


Note that i explicity chosen Web API.

Then the first thing that seems obvious is to add a WebAPI controller:


naming it “TestController”

The generated TestController.cs contains

namespace RequireJsTest.Controllers
{
    public class TestController : ApiController
    {
        // GET api/<controller>
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/<controller>/5
        public string Get(int id)
        {
            return "hi this is the test " + id.ToString();
        }
........


In this case i changed the default “value” string with “hi this is the test ” + id.ToString().

By adding the WebAPI there is a new class WebApiConfig in App_Start, called in the global.asax.

Note the comment above // GET api/<controller>/5 : this will be be the path for the call, with the template defined in the WebApiConfig class.

If you try http://localhost:<yourport>/api/test/5 you get a file named 5.json , that contains “hi this is the test 5″ (using the default Visual Studio web server).

Now, in the past in a complex web application with many .js sources it was requested a manual and complex management in order to provide the requested js modules in a certain situation, for example we are deleting a db record and it is necessary to provide the infrastructure for the ajax call vs the db and the messaging framework to the user.

With RequireJS the dependencies management in javascript is simplified, the pages http://requirejs.org/docs/start.html and http://requirejs.org/docs/api.html#data-main explains very well the concepts.

So we can install RequireJS from TOOLS->Library Package Manager->Manage NuGet Packages for Solution…

and search online:


Done this , to the HomeController.cs we can add a new method

public ActionResult Test()
{
    ViewBag.Title = "Test Page";
    return View();
}

Right clicking this method we can Add View for this Controller method,


That creates an Test.cshtml file under Views/Home :


By default there is only an <h2> , we change to

@{
    ViewBag.Title = "Test";
}

<h2>@ViewBag.Title.</h2>
<h3>@ViewBag.Message</h3>

<div id="msgplaceholder"></div>
<script data-main="/app/main" src="@Url.Content("~/Scripts/require.js")"></script>

Require.js is the script added from RequireJS, and now we see what is the “data-main” attribute.

A SPA app typically uses a folder named “app” , immediately under the root, as the main placeholder of the SPA structure.

And another commonly used standard is to use a main.js file as the SPA core.

As the requireJS site write, “The data-main attribute is a special attribute that require.js will check to start script loading”.

So the last <script> loads a file named main.js using the require.js library.

At this point we need to create the main.js , and a structure for the separation of the concepts.

In this case:


In main.js we define some aliases for other js modules, specifying the path:

(function () {
    requirejs.config(
        {
            paths: {
                'testview': '/app/viewmodels/test',
                'datasvc': '/app/services/testsvc',
                'config': '/app/configs/config'
            }
        }
    );

    require(['testview'],
        function (testvw) {
            //debugger;
            var id = 10;
            testvw.showMessage(id);
        }
    );
})();

Here the function decorated with require(['testview'] is automatically executed, if you place another function for example

require(
    ['testview'],
    function (testvw) {
        //debugger;
        var id = 10;
        testvw.showMessage(id);
    }
);

require(
    ['testview'],
    function (testvw) {
        var id = 20;
        testvw.showMessage(id);
    }
);

is automatically executed after the first has finished (the result depend from the callbacks timings).

Note that the function define as required the module that we aliased with ‘testview’, that points to /app/viewmodels/test.js

Here in test.is we can write

define('testview',
    ['jquery', 'datasvc'],
    function ($, datasvc) {
        var showMessage = function (id) {
            datasvc.getTest(id, function (message) {
                $("#msgplaceholder").html(message);
            });
        };

        return {
            showMessage: showMessage
        };
    }
);

That is we define that the current module will be publicy knowed as “testview” with “define”, and so in main.js we can write “require([testview]“

In test.js we note that this module is defined with the public name “testview”, and internally requires jQuery , which is already publicy knowed with the $ symbol, and our other module “datasvc”,

Here we can define some functions, the ones that we need public are defined public with the “return” keyword (a sample of Module Pattern).

We know now that datasvc is the alias defined in /app/services/testsvc.js where we can write something as

define('datasvc',
    ['jquery', 'config'],
    function ($, config) {
           var callWebApi = function (url, type, callbackfunc) {
                //debugger;
                $.ajax({
                    url: url,
                    type: type,
                    dataType: 'json',
                    success: function (data) {
                        callbackfunc(data);
                    },
                    error: function (jqXHR, textStatus, errorThrown) {
                        callbackfunc(jqXHR.responseText);
                    }
                });
            },

            getTest = function (id, callback) {
                url = config.baseUrl + id;
                callWebApi(url, 'GET', callback);
            };

        return {
            getTest: getTest
        };
    }
);

That requires “config” defined in /app/configs/config.js

define('config',
    [],
    function () {
        var baseUrl = '/api/test/';  //important ! Verify that the name must be the same of the controller

        return {
            baseUrl: baseUrl
        };
    }
);

Note that config.js is not requiring other libraries, so we can write define(‘config’, []

That is nothing in the square brackets.

if we try to run our app and point the browser to /home/test ( for example http://localhost:29404/home/test)


Conclusion: effectively some of these new frameworks are really useful and RequireIS leads to a less “spaghetti” javascript code.

Execute SSIS package from SQL Server Job

In order to execute a SSIS package from a SQL Server job there are some security issues.

You develop the package in Sql Server Data Tools (or the old SQL Server Business Intelligence Development Studio) and it works; in the package for example there are some trasformations from CSV files to an SQL Server server instance , and in the package the Connection Manager for SQL Server uses the SQL Server authentication.

The first step that seems logical to try is to insert a step in the SQL Server job as this:


But the job fails ,and in the job log is written :Failed to decrypt protected XML node “DTS:Password”

The problem is that in the SSIS project all sensitive informations are available , instead when the package is executed from the SQL job this uses the dtsexec utility, for which you need to pass in the command line the credentials.

If the security is a concern, an approach can be to open the SSIS project and in the project properties (open the dtsx on Control Flow visual editor, clic on the empty space, press F4) , where there is the security section


By default the ProtectionLevel is EncryptSensitiveWithUserKey , but in this case we use EncryptSensitiveWithPassword.

Then clicking on PackagePassword we are requested for the password:


Which is important to remember, the password will be requested opening the solution:


The package will be opened if you press Cancel, but is not possible to save changes:


At this point , going on our SQL Job definitions we will be required for the password by clicking on the “Command Line” tab:


We see an dtexec command line, in this case by default

/FILE “E:\PkgSSISHecPool\PkgSSISHecPool\PkgSSISHecPool\HecPool.dtsx” /DECRYPT /CHECKPOINTING OFF /REPORTING E

Clicking on “Edit the command line manually” we can change as


Save , and the package step works when called from the SQL Server job.

Categories: SQL Server, SSIS

Brain-Computer interface

From a certain point of view some new technologies seems a first step towards Skynet…but from the points of view explained in this article , especially the medical field, could be very useful in the near future.

Categories: Uncategorized

Quick & Dirty Windows Service

The problem was a pc for my use in a customer intranet, behind a proxy, no webmail: and i was needing to read my emails.

So i need someone that put on the pc (no, is not possible to leave it working..), then from a VPN i can use the pc via remote desktop.

First problem: via VPN i can’t use the BIOS name.

Second problem: the ping, perhaps a trouble caused from the proxy, gives an erratic IP from all others pc on site.

The only possibility to have the right IP is by login locally and run ipconfig…

But to give away my user and password to the first available clerk is not beautiful.

After a while i thinked that an Windows Service automatically started without the need to make login, was the only possibility.

In Visual Studio 2012 File->New Project->Templates->Visual C#->Windows->Windows Service, using MyIpReminderSvc as name, .NET 4.5

The first interesting thing is that by default is created an Service1.cs file which has a Designer.

I will study in future what means that i can drag&drop an textbox, for example…a Windows Service is by definition something that works without user interface and does not run directly, if you try an F5 this is the result:


A Windows service needs an mechanism that permits his installation, and this is done by right clic the Service1.cs designer and choosing

“Add Installer”.

This action creates another class, by default is named ProjectInstaller.cs; pressing F7 we can see the code behind:

using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Threading.Tasks;

namespace MyIpReminderSvc
{
    [RunInstaller(true)]
    public partial class ProjectInstaller : System.Configuration.Install.Installer
    {
        public ProjectInstaller()
        {
            InitializeComponent();
        }
    }
}

Below “InitializeComponent();” we can add these lines :

this.serviceProcessInstaller1.Account = System.ServiceProcess.ServiceAccount.LocalSystem;
this.serviceProcessInstaller1.Password = null;
this.serviceProcessInstaller1.Username = null;
// 
this.serviceInstaller1.Description = "Get current IP and send it to an email account";
this.serviceInstaller1.DisplayName = "My pc IP service";
this.serviceInstaller1.ServiceName = "MyPcIpService";
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;

Here we specify that by default the service is running as LocalSystem user, that tipically has no user and password.

Don’t use special chars in the ServiceName (for example “ä”) or you will be in troubles trying to manage the service with batch files (using NET START, NET STOP and so on).

In this step we have defined the administrative items of our service, now opening the Service1.cs we can define the core activity or the service: pressing F7 we see the code automatically created (i don’t write the “using” part):

namespace MyIpReminderSvc
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
        }

        protected override void OnStop()
        {
        }
    }
}

The code is obvious, in OnStart we can write what happens when our service is starting , and obviously OnStop is called when the service is stopping.

In the class constructor we can define other administrative properties.

So the code could be, in this case where i need to know the pc IP, something as:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Net;
using System.Net.Mail;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;

namespace MyIpReminderSvc
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
            this.ServiceName = "MyNetworkIPSendmail"; // short name used to identify the service to the system
            this.EventLog.Log = "Application";
            //
            this.CanHandlePowerEvent = true; //for example the system is running on battery, caused from a power shortage
            this.CanHandleSessionChangeEvent = true; //change events from terminal session
            this.CanPauseAndContinue = true;
            this.CanShutdown = true; //service notified when the system is shutting down
            this.CanStop = true;
        }

        protected override void OnStart(string[] args)
        {
            MailMessage objHtmlMsg;
            SmtpClient objClient;
            //
            String strHostName = string.Empty;
            // First get the host name of local machine.
            strHostName = Dns.GetHostName();
            // Then using host name, get the IP address list..
            IPHostEntry ipEntry = Dns.GetHostEntry(strHostName);
            IPAddress[] addr = ipEntry.AddressList;
            //
            for (int i = 0; i < addr.Length; i++)
            {
                strHostName += String.Format("IP Address {0}: {1}<br/>", i, addr[i].ToString());
            }
            // in this case a "jolly" intranet user name (ok, the domain name is a fake) without password
            objHtmlMsg = new MailMessage("dummyuser@acme.com", "youraccount@yourdomain.com", "Today IP from my pc", strHostName);
            objClient = new SmtpClient("10.87.11.9"); // ip or netbios name of the mail server
            objHtmlMsg.IsBodyHtml = true;
            objClient.Credentials = CredentialCache.DefaultNetworkCredentials;
            objClient.Send(objHtmlMsg);
        }

        protected override void OnStop()
        {
        }
    }
}

In the Build menu of Visual Studio 2012 we can compile our solution, and now the problem is how to insert our service in the Windows Services list.

First, we must copy the bin\Debug or bin\Release (depending how the solution was built) folder or our solution in another folder: is a bad practice to publish directly the solution folder.

In the copied folder, for our solution, we have


In the same folder create 2 bat files: install.bat that contains a call to InstallUtil (the framework must be the same of the solution, of course)

@ECHO OFF
echo Installing Windows Service...
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil /i MyIpReminderSvc.exe
pause

And uninstall.bat

@ECHO OFF
echo Installing Windows Service...
C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\InstallUtil /u MyIpReminderSvc.exe
pause

In practice the only difference is the /u switch.

In the Windows Control Panel in Administrative Tools->Services now we can see


Double clicking it we can read the settings defined in ProjectInstaller.cs

Now rebooting the pc we should receive the mail with a body similar to (verify your spam folder,also…)

sthm0627IP Address 0: fe85::a8a1:62c6:8094:r930%17
IP Address 1: fe87::t57c:e392:c8d3:8248%16
IP Address 2: 192.168.137.7
IP Address 3: 10.87.13.161

The last is my true PC IP on the local network.

You end up with a unuseful running service in this case: but we can provide an initial batch, when the user is logging, with a NET STOP.

Naturally is better to make some code test; for example the service logic can be inserted in another class where we can do Unit Testing or call the class from a Console program.

Well, but if i run into a dreaded problem that occurs only on the true running service, and for example i publish the service not on my own pc but another server ? how to debug ?

You can provide log4net logging for example, but if it is needed a true debug we can insert a function as this in Service1.cs code

[Conditional("DEBUG")]
static void DebugMode()
{
    if (!Debugger.IsAttached)
        Debugger.Launch();
    Debugger.Break();
}

we can insert the call to DebugMode() anywhere in our Service1.cs code; then when the service is launched pops out this window:


And we can debug our code: obviously must be installed something that can act as a .NET debugger (in primis Visual Studio, even an Express version)


The code must be compiled in Debug mode and must be provided the .pdb file.

Categories: .NET, Visual Studio 2012

Test Vms

From Microsoft is possible to download virtual machines for testing at this address.
Obviously you must provide valid serial numbers; very valid if you need to test Ie old versions against a site.

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.