Monday, October 21, 2013

Windows Azure Database dimensions in Mb

If you use a Windows Azure database, you know that you can't easily know its dimension (in term of used space) by the Sql Management Studio, you have to use the Azure Portal. But the portal is not update in real time... So, if you wanna know the database used space, you can use this query:

/*Database dimension in MB*/
SELECT SUM(reserved_page_count) * 8.0 / 1024
FROM sys.dm_db_partition_stats


Instead, if you wanna know the dimension in MB for each table in the Database, use the query below:

/* Tables Dimensions in MB */
SELECT sys.objects.name AS 'Table Name', SUM(reserved_page_count) * 8.0 / 1024 AS 'Mb'
FROM sys.dm_db_partition_stats
INNER JOIN sys.objects ON sys.dm_db_partition_stats.object_id = sys.objects.object_id
WHERE sys.objects.type = 'U'
GROUP BY sys.objects.name

Saturday, August 10, 2013

Delete a project from Team Foundation Service

Since the "Team Foundation Service" hasn't an administrative console, it's not possible to use it to delete a hosted project.

So to delete a team project from one Team Foundation Service collection you have to use the "tfsdeleteproject.exe" command line tool:

tfsdeleteproject /collection:https://<your collection>.VisualStudio.com/DefaultCollection <"Project Name">

For further information, see: http://social.msdn.microsoft.com/Forums/en-US/TFService/thread/81997146-a64f-43fb-9952-57d71542cd11

Wednesday, June 5, 2013

GridView Scroll to a desired group in a Windows Store App

By default, in a Windows Store App, the focus in a GridView is given to the element "0" of the group "0". But what if you wanto to change this behaviour and make it "open" to another element?

To do it, you have to manage the  itemGridView_Loaded event and use the CollectionView:

In XAML:
<GridView
    x:Name="itemGridView"
    AutomationProperties.AutomationId="ItemGridView"
    AutomationProperties.Name="Grouped Items"
    Grid.RowSpan="2"
    Padding="116,137,40,46"
    ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
    ItemTemplate="{StaticResource Standard250x250ItemTemplate}"
    SelectionMode="None"
    IsSwipeEnabled="false"
    IsItemClickEnabled="True"
    ItemClick="ItemView_ItemClick"
    Loaded="itemGridView_Loaded">

Incode-behind:
private bool firstTime = true;
        
   private void itemGridView_Loaded(object sender, RoutedEventArgs e)
   {
        ICollectionView view;
        ICollectionViewGroup myGroup;
        Data.MyDataType myItem;
 
        if (!this.firstTime) return; else firstTime = false;
        view = itemGridView.ItemsSource as ICollectionView;
        view.CurrentChanged += view_CurrentChanged;
        int groupIndex = 2; // an integer value between 0 and # of items in the groups collection
        myGroup = view.CollectionGroups[groupIndex] as ICollectionViewGroup;
        myItem = recipeGroup.GroupItems[0] as Data.MyDataType;
        view.MoveCurrentTo(myItem);
    }
     
    private void view_CurrentChanged(object sender, object e)
    {
        ICollectionView view;
        Data.MyDataType  myItem;
         
        view = itemGridView.ItemsSource as ICollectionView;
        view.CurrentChanged -= view_CurrentChanged;
        myItem = view.CurrentItem as Data.MyDataType;
        itemGridView.ScrollIntoView(view.CurrentItem, ScrollIntoViewAlignment.Leading);
    }

Wednesday, May 29, 2013

Privacy Policy in Charm Bar: the easiest way

When you make a Windows Store App, if it uses any Network connection, you have to specify your Privacy Settings in both Store page and Charm Bar.

But how to do it? What's the simplest way?

So, here's the answers.

Do the following in your App.xaml.cs:

1) Add the namespaces
using Windows.UI.ApplicationSettings;
using Windows.UI.Popups;


2) Add the handler during app initialization (into OnLaunched())
SettingsPane.GetForCurrentView().CommandsRequested += SettingCharmManager_CommandsRequested;


3) Add my handler that shows the privacy text
private void SettingCharmManager_CommandsRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
{

    args.Request.ApplicationCommands.Add(new SettingsCommand("privacypolicy", "Privacy policy", OpenPrivacyPolicy));

}

4) Add OpenPrivacyPolicy method
private async void OpenPrivacyPolicy(IUICommand command)

{

    Uri uri = new Uri("http://my_website/my_privacy.html");
    await Windows.System.Launcher.LaunchUriAsync(uri);

}


Tuesday, May 14, 2013

Free technical e-book on the Microsoft platform


While a lot of information on application development is available on the internet and in books, that information is becoming harder to digest. If you do not enjoy reading several 500+ page books, or scouring the web for relevant blog posts and articles, you have come to the right place.
Syncfusion publishes the Succinctly series concise technical books that target developers working on the Microsoft platform. Each book is around 100 pages and is guaranteed to enlighten you on the topic of interest. Download a copy, get a cup of your favorite beverage, and enjoy!

Monday, April 8, 2013

SharePoint 2013: The username is invalid. The account must be a valid domain account

When configuring SharePoint 2013 in “Complete” mode you get a “The username is invalid. The account mist be a valid domain account” when using a local account to configure the farm…


Out of the box SharePoint only supports “Stand-alone” mode for non domain environments, but this forces you to use SQL Server 2008 R2 Express Edition which is most cases is unacceptable.

The solution is to use a PowerShell command to create the initial configuration of the farm with a local account:


1) Start the SharePoint PowerShell (not the "standard" one)

2) Run “New-SPConfigurationDatabase” from the command line and follow the instructions. This will create the farm and configure the necessary accounts.


3) Rerun the Configuration wizard. After it finishes start the Config Wizard (interactive or not) and configure your server with all components


Tuesday, March 12, 2013

LINQ Optimization tips

1. Any or Count?
When you have to test for the presence of at least one element into a list, use
        if (query.Any())
Instead of
        if (query.Count() > 0)
That way it only needs to find the first match.

2. Conditions
Use
        query.FirstOrDefault(x => x.value > 1);
        query.SingleOrDefault(x => x.value > 1);
Instead of
        query.Where(x => x.value > 1).FirstOrDefault();
        query.Where(x => x.value > 1).SingleOrDefault();
That way it only does one operation instead of two concatenated operations

3. Understand how it works
You always need to struggle for performance as a LINQ Developer; perhaps because to understand better how internal mechanism works.
        using (MYDataContext context = new MYDataContext())
        {
            var customers = from cust in context.Customers
                            select cust;
            foreach (var customer in customer)
                Response.Write(customer.CustomerAddresses.Count().ToString());
        }
In above example, you will see in Sql Server Profiler that for each customer one query will be executed additional each times to get the total addresses count for that customer when you enumerates in foreach loop. Now, consider below re-written snippet:
        using (MYDataContext context = new MYDataContext())
        {
            var customers = from cust in context.Customers
                            select cust;
            DataLoadOptions dataLoadOptions = new DataLoadOptions();
            dataLoadOptions.LoadWith(A => A.CustomerAddresses);
            context.LoadOptions = dataLoadOptions;
            foreach (var customer in customer)
                Response.Write(customer.CustomerAddresses.Count().ToString());
        }
Simply in above example, with DataLoadingOptions we are infect just telling LINQ Query engine that while it fetches the Customer data; also fetch associated CustomerAddresses table record count for that particular Customer. The benefit is; only ONE query will be executed to get the final result.

4. Finally
The success behind a LINQ application that you develop lies behind the performance of the query that you formulate. You can use any third party tool like I prefer to use LINQPad (by Joseph Albahari) while my development with LINQ. Actually, quick since a long time after I got to know about this tool and I was impressed so much that I thought to why not I get aware something about such nice and intelligent tool before. Life would have become easier!

Friday, March 8, 2013

Architectural pattern survey


I've started a survey (see on the right side) to know which architectural patter is the best, for you, between MVC, MVP and MVVM.

The survey will be active untile 31/03/2013 at 23.59

Use this post to comment the survey or to add notes it you chose the "Other" option.

Thanks :)

Friday, February 22, 2013

Drop constraint for Default Value


Assign a default value to a column via  T-SQL scripts is really simple. Its deletion, instead, isn't so simple 'cause of the variable constraint name (in a multi-server environment or on different environments it will never have the same name).

This script retrieve the constraint name and drop it.


DECLARE @name nvarchar(100)

SELECT @name =  name FROM sys.objects WHERE type = 'D' AND object_id IN
(
SELECT default_object_id
FROM [sys].[all_columns]
WHERE name = 'column_name'
AND object_id =
(
SELECT  object_id FROM sys.objects WHERE type = 'U' AND name = 'table_name'
)
)

EXEC ('ALTER TABLE table_name DROP CONSTRAINT ' + @name)