Sunday 27 May 2012

Nuget Commands





NuGet

When you use NuGet to install a package, it copies the library files to your solution and automatically updates your project (add references, change config files, etc.). If you remove a package, NuGet reverses whatever changes it made so that no clutter is left, but make sure your changes are not removed.
 

Open Package manager

From the Tools menu, select Library Package Manager and then click Package Manager Console. 
 
 

Get existing packages in your project


command: Get-Package

Display list of all packages you have in selected project.

Get all packages available







Command: Get-Package -ListAvailable 

Gets you list of all packages that are available for you to install. 
Executing the command looks like: 
 



Get existing packages in your project

Command:  Get-Package -ListAvailable -Filter [package name]
Example Command:  Get-Package -ListAvailable -Filter Castle.Core
 
 
 Search for name based on contains filter. Where instead of [search Package] 
you use name you are looking for.
 
 
 

Get existing packages in your project

Command:  install-package [package name] 
 
Example Command:  install-package Castle.Core
 
 
Notice the highlighted are on image below. Make sure you select the project where you want to install the package.
 
 
 
And after installing you will get message.
 
 

Remove package from your project

Command:  uninstall-package [package name] 
 
Example Command:  uninstall-package Castle.Core
 
  
Remove the package from project, again make sure that you have selected project you want to remove the package from, as highlighted on image below.
 
 
 
Hint: 
If you do not already know the name of the package you want to remove, enter Get-Package at the prompt 
without any flags to see a list of all of the packages that are currently installed.  
 
 

Include pre-release package

If you are like me, you want to get your hands on data that are still in beta version. This command will allow you to do this.
 
 
Command:  install-package [package name] -includeprerelease 
Example Command:  uninstall-package EntityFramework -includeprerelease  

Install specific version

Quite often you need to install package specific to your project, from time you have started to write it. 
  

Command
Install-Package EntityFramework -Version 1.2.0



Commands:


Enable migrations:

 
Command:  Enable-Migrations 

To see more go and visit Package Manager Console Powershell Reference



Wednesday 9 May 2012

.net4 connection to oracle database using entity framework

ORACLE and Entity Framework

I have small console app to check wheter my db connection works with .NET.
But as you can see below my code throwing errors.



After little of googling answer is here:


What you need to do is go to this page:

http://www.oracle.com/technetwork/topics/dotnet/utilsoft-086879.html


download
ODAC xxx Release 4 and Oracle Developer Tools for Visual Studio
mine is: ODAC 11.2 Release 4 and Oracle Developer Tools for Visual Studio (11.2.0.3.0)

Run it on your pc.

and complete with

After then your code should be working.

Friday 4 May 2012

MS SQL Cheat Sheet

My small MS SQL Cheat Sheet of sql commands



Find table by column name:


Exact match on column name:

SELECT 
  * 
FROM 
   sysobjects 
WHERE 
   id IN
    (SELECT id FROM syscolumns WHERE name ='your column name')


Part of column name to search:

SELECT 
  * 
FROM 
   sysobjects 
WHERE 
   id IN
    (SELECT id FROM syscolumns WHERE name LIKE '%your column name%')


MS SQL 2000 transacion

in this version of sql the transaction is just beginning and is not as clear as it is in later versions of sql. To create transaciton we need to use command TRAN. Which later is used as TRANSACTION.


SQL Search for table name in database by part of table name


SELECT
*
FROM
information_schema.tables
WHERE
table_name like '%partOFTableName%'



Select into another table


SELECT Suppliers.Name, Product, Products.UnitPrice
INTO [Mexican Suppliers]
FROM Suppliers




Select rows with repeating value

If you need to get all values that are used more than once in table you can use following query:

  SELECT
    [column],
    count([column]) 'Count'
    FROM
    [TSTT_Subscribers].[dbo].[tblGSM_subscribers]
    GROUP BY [column]
    HAVING COUNT([column]) > 1



Search for text in all stored procedures for specific database


SELECT ROUTINE_NAME, ROUTINE_DEFINITION
FROM INFORMATION_SCHEMA.ROUTINES
WHERE ROUTINE_DEFINITION LIKE '%Searched_Text_InsertHere%'
AND ROUTINE_TYPE='PROCEDURE'


Get all parameters for stored procedure


ALTER procedure [sys].[sp_procedures_rowset]
(
    @procedure_name     sysname,
    @group_number       int = 1,
    @procedure_schema   sysname = null
)
as
    select
        PROCEDURE_CATALOG       = db_name(),
        PROCEDURE_SCHEMA        = schema_name(pro.schema_id),
        PROCEDURE_NAME          = convert(nvarchar(134),pro.name +';'+ ltrim(str(pro.procedure_number,5))),
        PROCEDURE_TYPE          = convert(smallint, 3), -- DB_PT_FUNCTION
        PROCEDURE_DEFINITION    = convert(nvarchar(1),null),
        DESCRIPTION             = convert(nvarchar(1),null),
        DATE_CREATED            = pro.create_date,
        DATE_MODIFIED           = convert(datetime,null)
    from
        sys.spt_all_procedures pro
    where
        (
            (@procedure_schema is null and pro.name = @procedure_name) or
            object_id(quotename(@procedure_schema) + '.' + quotename(@procedure_name)) = pro.object_id
        ) and
        (@group_number is null or pro.procedure_number = @group_number)
    order by 2, 3

What is file location of database

I needed to find out location of the db files (mdf, ldf). I have used following command to get that information:


SELECT name, physical_name AS current_file_location
FROM sys.master_files

Working with cursors

Here is example of using cursor

code:

DECLARE @processingId int =0
DECLARE ExistingRequests_Cursor CURSOR FOR
SELECT primaryKey FROM table
OPEN ExistingRequests_Cursor
FETCH NEXT FROM ExistingRequests_Cursor INTO @processingId  
WHILE @@FETCH_STATUS = 0
BEGIN


 SELECT @processingId
   END  
  
   FETCH NEXT FROM ExistingRequests_Cursor
END
CLOSE ExistingRequests_Cursor
DEALLOCATE ExistingRequests_Cursor

Copy one column of table into another

Memory glitch? Here you are
 
UPDATE <tablename>
SET <destination column name> = <source column name>

Truncate table

Want to delete table fast? use command:

truncate table replaceWithYourTableName

Display information into console

run command: 
PRINT 'Hello, world!'

  Get All talbes that are for specific database

Each Database have its own sys.objects, so you have to get the databases from sys.databases, and
 
 
select from {dbname}.sys.objects
 
Example : SELECT * FROM HomeSite..sysobjects WHERE [type] = 'U'


Thursday 3 May 2012

Workflow tracking

Workflow tracking

is adding tracking participant to workflow run-time, so you can track and record status and events related to each workflow, where tracking can be enabled by configuration in App.config.

Visibility of tracking is key reason to use workflow tracking, as you can peak under the hood of existing workflow, which enable us to test and validate workflow behavior, monitor status in production, performance monitoring etc.

About Architecture

tracking is mechanism designed to use flexible publish and subscribe architecture. The workflow runtime is publishing raw tracking records that can be consumed by one or more tracking participants. For that is used Class derived from Tracking provider.

Tracking profiles

acts as a filter for raw tracking data, that is passed to each participant.Each profile contains definitions for tracking queries that specify the type of tracking records. The queries allow you to limit the flow data based on attributes of each tracking record. You can also filter tracking data by activity name.





Wednesday 2 May 2012

Unit test of workflow for code action

Unit testing workflow code action


As part of my recent project I needed to do unit testing of a project. I have read article http://msdn.microsoft.com/en-us/magazine/dd179724.aspx#id0400009. This does not seem to be too bad, but it does not fit with my requirement.

I have created a CodeActivity for which I need to create unit test.

For our purpose I have created simple activity to do simple math. Pass two parameters and return result.

public sealed class ParameterActivity : CodeActivity
    {
        public InArgument<int> Argument1 { getset; }
        public InArgument<int> Argument2 { getset; }
        public OutArgument<int> Result { getset; }
 
        protected override void Execute(CodeActivityContext context)
        {
            int a = context.GetValue(Argument1);
            int b = context.GetValue(Argument2);
 
            context.SetValue(Result, a + b);
        }
    }


I have added this into my workflow and as good developer, I want to verify that my code works as expected and therefore i want to create a unit test for this.

Great, right button on the method and generate unit test for this method.
you will get generated code as follows.

ParameterActivity_Accessor target = new ParameterActivity_Accessor(); // TODO: Initialize to an appropriate value
CodeActivityContext context = null// TODO: Initialize to an appropriate value
target.Execute(context);
Assert.Inconclusive("A method that does not return a value cannot be verified.");

Little of background.

Every action is component itself and you can add them into workflow or sequence, but any action can be stand alone.

Therefore I have made decision to progress to invoke workflow on only the action.
using Workflow Invoker and setting parameters to this action.

Now I know that results of Invoke will return results (if the action contains) which I can access using array.
Every result has pair <string, object>.
Now we know enough to create our test.

var results = WorkflowInvoker.Invoke(new ParameterActivity() {Argument1 = 2, Argument2 = 2});
int val;
 
int.TryParse(results["Result"].ToString(), out val);
            
Assert.AreEqual(val, 4);


Now you can try this, and let me know how you get on.