Wednesday, 22 December 2010

SharePoint Authentication

Microsoft Kerberos (Negotiate)
Microsoft NTLM

Forms-based Authentication:

Claims-baed authentication:

Thursday, 16 December 2010

How to: Configure a Port with an SSL Certificate

http://msdn.microsoft.com/en-us/library/ms733791.aspx

Prerequisites

  • You must have imported a certificate in your LocalMachine or CurrentUser certificate location and find out its thumbprint identifier
  • You must have an application with an ID as GUID e.g. a Windows Service
  • You must know to which Store your certificate is stored.


Add a certificate binding:
netsh http add sslcert ipport=0.0.0.0:6080 certhash=bcb0d7372d065fdb4047d6fdde64b1c84f6e12c2 appid={00000000-0000-0000-0000-000000000000} clientcertnegotiation=enable certstorename=Personal

Delete a certificate binding:
netsh http delete sslcert ipport=0.0.0.0:6080

Display current port binding
netsh http show sslcert ipport=0.0.0.0:6080

Show all current port configurations:

netsh http show sslcert

Thursday, 2 December 2010

MMS Video Live Streaming

List of some live mms video streams: http://www.kensfi.com/watch-live-tv-channels-streams-with-vlc-media-player/

VLC Player can display mms video streams.

An Example for IE:

<object id="MediaPlayer" width="500" height="400"

classid="CLSID:6BF52A52-394A-11D3-B153-00C04F79FAA6" standby="Loading

Windows Media Player components..." type="application/x-oleobject">

<param name="url" value="mms://81.89.49.210/musicbox" />

<param Name="FileName" Value="mms://81.89.49.210/musicbox">

<param name="controller" value="true" />

<param name="autoplay" value="true" />

<param name="autoStart" value="true"/>

</object>

How to Modify the Url Programmatically


More info about properties, methods and events of this Activex object, please refer to this: http://msdn.microsoft.com/en-us/library/dd564034(v=VS.85).aspx

Thursday, 25 November 2010

SharePoint ULS Log

ULS: Unified Logging Service

Location:
SharePoint logs are located here by default:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\LOGS

ULS Viewer tool: http://ulsviewer.codeplex.com/

Configure logging level in SharePoint:

A hotfix for Sharepoint Shared Services:

Thursday, 18 November 2010

How to Deploy a SharePoint 2010 Web Application/Site from One Server to the Other?

Option1
1. Use SQL Management Studio to backup the Content Database

How to: Back Up a Database (SQL Server Management Studio):
http://msdn.microsoft.com/en-us/library/ms187510.aspx

2. Restore the Content Database to your new SQL server

How to: Restore a Database Backup (SQL Server Management Studio):
http://msdn.microsoft.com/en-us/library/ms177429.aspx

3. Create a new web application in Central Admin on the new farm:

Create a Web application (SharePoint Foundation 2010):
http://technet.microsoft.com/en-us/library/cc288705.aspx

4. Delete the content Database that get's created by the new web application(from step 4)

Central Admin > Application Management > Content Databases > delete the empty db from your web application (created in step 3)

5. Use SharePoint Management Shell(Mount-SPContentDatabase), Stsadm(-o addcontentdb) or Central Admin to add the contentdatabase:

Add a content database (SharePoint Server 2010):
http://technet.microsoft.com/en-us/library/cc825314.aspx

6. Make sure that your account has administrative permissions on the site collection(update site collection administrator)
Add or remove site collection administrators (SharePoint Server 2010):

Option 2: Site Collection Backup

1. Create a backup of your site collection which gives you a .bak file using stsadm tool or using the Central Administration

2. use the following command line tool to restore this backup file

stsadm -o restore -url http://servername/sites/sitename -filename C:\Backups\siteCollectionBackup.bak -restoremethod overwrite -overwrite

http://technet.microsoft.com/en-us/library/cc262087(office.12).aspx

Option 3: Deploy Custom WebParts
Option 3: Deploy Custom Html or ASP pages

One manual way is to create a virtual directory inside your web application and put the pages there.


Friday, 29 October 2010

Friday, 22 October 2010

Ways to Add Cookie for WCF

Approaches to add cookie for WCF responses:

1)
Use HttpContext.Current.Response.Cookies.Add

2)
Use the MessageHeader section of MessageContract

3)
Use WebOperationContext.Current.OutgoingResponse.Headers.Add

Thursday, 21 October 2010

HTML 5.0

HTML 5.0 elements and their examples: http://simon.html5.org/html5-elements

Sunday, 10 October 2010

StyleCopCmd

StyleCopCmd provides a command line interface and NAnt task for interacting with StyleCop. StyleCopCmd also creates beautiful HTML reports, making it easy to integrate with continuous integration servers such as TeamCity.

Friday, 1 October 2010

Patterns of Naming Unit Tests

How would you name your test project, test fixtures and test cases?
  • Make sure your naming approach is consistent throughout your project.
  • Make sure names are clear and specific.
  • Each person can invent his/her own pattern of course but these are some common ones:
1) Test Project

Pattern 1
Create a test project per production project and postfix it with "Tests" e.g. "Model.Tests" for the "Model" project. so if you have 10 production projects, create 10 test projects and put then inside a "UnitTests" Visual Studio folder for better grouping.

Example:
  • Project name: Model (as you don't put the name of the Company to the project name)
  • Namespace: Company.Model (namespace would contain the Company name)
  • Assembly name: Company.Model.dll
  • Test project name: Model.Tests
  • Test namespace: Company.Model.Tests
  • Test assembly name: Company.Model.Tests.dll
Pattern 2
Another pattern (or better anti-pattern) is to have one project containing all tests for all projects; I think Pattern 1 is better for simplicity and maintainability so that one would be my preferable choice.

2) Test Fixtures

1 Test fixture per production class.

Pattern 1: "Tests" or "Fixture" Suffix
"Model.Tests.CalculatorTests" or "Model.Tests.CalculatorFixture" for the production class of "Model.Calculator"

Pattern 2: "For." Prefix
"Model.Tests.For.Calculator" for the production class of "Model.Calculator".

The benefit of this naming is that you won't have to repeat the word "Tests" for your fixtures also it would have a nicer readability as you can read it like a sentence "Tests for Calculator" but at the same time, you're adding extra "For." for your classes.

Pattern 1 is often my preferred choice.

3) Test Names

Pattern 1: MethodName_ScenarioOrCondition_ExpectedBehaviour or GivenX_WhenY_ThenZ
  • This pattern has "_" that FXCop doesn't like.
  • It's simple to map which class or method to which test, however, if method names change, you'd want to change your test names as well. Another option is not using the "method name under test" but instead using "behavior under test".
  • This patterns says that, when someone looks at your test name, he should easily find out 1) what is the unit which is being tested? 2) under what condition is it tested? 3) what is the expected behaviour for this condition?
e.g.
public void AnalyzeFile_FileTooShort_ThrowTooShortException()
{
...
}

or

public void GivenAnalyzeFile_WhenFileTooShort_ThenThrowTooShortException()
{
...
}

The second option is easier to read, isn't it?

Pattern 2: WithXShouldY or WhenXExpectY
  • In this pattern, there is no "_" so it makes FXCop happy but of course it reduces readability.
  • The test name has no indication of what method or action therefore, you'd need to put the method name in the test class instead e.g.
Example:

WithEmptyFileNameShouldThrowException or
WhenEmptyFileNameExpectThrowException or
WhenEmptyFileName_ExpectThrowException

ProductionProjectName.Tests
.For.Foobar (test fixture for production feature/component/class/class)
.WhenAnalysing (method, action or behavior)
.WhenEmptyFileNameExpectThrowException (test method name)

Pattern 3: Separate Each Word!
  • This is a very old pattern.
Example:
AnalyzeFile_File_Too_Short_Throw_Too_Short_Exception()

Pattern 4: End method names with "Test"
  • Why would you want to add "Test" to the test name which is attributed with "TestMethod" already?
  • Not my choice.
Example:
AnalyzeFileTest()




Monday, 27 September 2010

Microsoft OCS

Office Communication Service (OCS):

Thursday, 9 September 2010

Bug Fixing

Bug fixing is most often easy and straightforward if you follow this pattern.

Bug Template:

Every bug should be written using the following template

Title:
[text]

Description:
[text]

Steps to reproduce:
[numeric list of the steps to clarify how to reproduce the bug]

Actual:
[what is the actual behavior which happens]

Expected:
[what is the expected behavior]

Supporting info:
[text, attachments, images, stack trace, etc]

Bug Fixing Strategy

The general strategy for bug fixing is as following:

  1. Make sure the bug details is in your bug tracking tool (e.g. Jira, BugZilla, etc); if it's not add it using the bug template provided above
  2. Assign the bug to yourself or the person who will be in charge of the bug fixing
  3. Investigate and understand what the bug is - if it's not clear ask the person who raised the bug for further clarification and completing the template above
  4. Investigate and understand how to reproduce the error
  5. observe the bug is reproduced in code
  6. Investigate and understand why the bug exists
  7. Propose possible solutions
  8. Choose the best solution; if required consult
  9. Fix it and write unit test or integration test for it - in some cases you can write the test first which is a better practice if possible
  10. Retest and observe that the bug doesn't get reproduced
  11. Set the bug status in your bug tracking tool to "Fixed" and assign it to your testing manager

Wednesday, 1 September 2010

How to Check Multiple Email Accounts Quickly

Problem:
You have a number of email accounts with gmail, yahoo, msn, etc and each time you want to check your emails it takes some time logging into these accounts. Your bright mind tells you that there must be an easier and quicker way to check all these email accounts at once!

Free Solutions:

Desktop-based tools:
Thunderbird, YPOPs, Zimbra Desktop, WebMail

Web-based tools:
Fuser, Mail2Web

My notes:
Use a more reliable & popular tool such as Thunderbird or Zimbra rather than using any tools you see on search engines randomly + if you use these tools it would be slower than checking your emails directly on google for instance.

Saturday, 21 August 2010

Updating UI Elements using ProgressChanged event of BackgroundWorker

As you probably know, the only thread which can update a UI element, such as a Label, is the main thread which created that UI element.

In my previous article, I wrote about an approach to update the UI elements using the Dispatcher object of the UI element. Here I’d like to show you another approach which is to use ProgressChanged event of the BackgroundWorker:

public partial class Window1 : Window
{
BackgroundWorker aWorker = new BackgroundWorker();

public Window1()
{
InitializeComponent();
aWorker.WorkerSupportsCancellation = true;
aWorker.WorkerReportsProgress = true;
aWorker.DoWork += aWorker_DoWork;
aWorker.RunWorkerCompleted += aWorker_RunWorkerCompleted;
aWorker.ProgressChanged += new ProgressChangedEventHandler(aWorker_ProgressChanged);
}

/// <summary>
/// Handles the ProgressChanged event of the aWorker control. this runs on the main thread
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.ComponentModel.ProgressChangedEventArgs"/> instance containing the event data.</param>
void aWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
UpdateLabel(Int32.Parse(e.UserState.ToString()));
}

/// <summary>
/// Handles the DoWork event of the aWorker control.
/// This runs in a new thread
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.ComponentModel.DoWorkEventArgs"/> instance containing the event data.</param>
private void aWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
for (int i = 0; i <= 500; i++)
{
Thread.Sleep(100);

if (aWorker.CancellationPending)
{
e.Cancel = true;
return;
}
aWorker.ReportProgress(0, i);
}
}

private void aWorker_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
if (!(e.Cancelled))
Label2.Content = "Run Completed!";
else
Label2.Content = "Run Cancelled!";
}

private void UpdateLabel(int i)
{
Label1.Content = "Cycles: " + i.ToString();
}

private void btnStart_Click(object sender, RoutedEventArgs e)
{
aWorker.RunWorkerAsync();
}

private void btnCancel_Click(object sender, RoutedEventArgs e)
{
aWorker.CancelAsync();
}
}

Notes:
  • There are 3 easy steps you need to take to enable this:

    • Set WorkerReportsProgress property

    • Subscribe to ProgressChanged event

    • Call ReportProgress() method from the worker thread

WPF: How to Enable Journal When Using PageFunctions

PageFunctions are xamle pages which enable us to create complex journal and navigations. Unlike Page, PageFunction can be used to return an object to the caller page.

Caller Page:

public partial class Page1 : Page
{
public Page1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
PageFunction1 apage = new PageFunction1();
apage.Return += new ReturnEventHandler<object>(apage_Return);
NavigationService.Navigate(apage);
}

void apage_Return(object sender, ReturnEventArgs<object> e)
{
List<string> alist = (List<string>)e.Result;
foreach (string s in alist)
listBox1.Items.Add(s);
}
}

Notes:
  • Return event of a PageFunction is raised when the data is returned back from the PageFunction

CustomContentState:

This class helps to store the state for the contents of the journal when navigating forward or backward in a PageFunction:

[Serializable()]
public class CustomJournalEntry : CustomContentState
{
private List<ListBoxItem> atops;
private List<ListBoxItem> ctops;
public List<ListBoxItem> AvailableToppings
{
get
{
return atops;
}
set
{
atops = value;
}
}
public List<ListBoxItem> ChosenToppings
{
get
{
return ctops;
}
set
{
ctops = value;
}
}
public override string JournalEntryName
{
get
{
return "Custom Journal Entry";
}
}
public delegate void ReplayDelegate(CustomJournalEntry c);
private ReplayDelegate replaydelegate;
public override void Replay(NavigationService navigationService, NavigationMode mode)
{
this.replaydelegate(this);
}
public CustomJournalEntry(List<ListBoxItem> available, List<ListBoxItem> chosen, ReplayDelegate replay)
{
atops = available;
ctops = chosen;
replaydelegate = replay;
}
}

Notes:
  • This class inherits from CustomContentState class and is Serializable

  • Replay method has been overridden and it’s called by the navigation engine when moving forward or backward on the journal

PageFunction class:

public partial class PageFunction1 : PageFunction<Object>, IProvideCustomContentState
{
public PageFunction1()
{
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e)
{
List<ListBoxItem> alist = new List<ListBoxItem>();
List<ListBoxItem> blist = new List<ListBoxItem>();
foreach (ListBoxItem lll in listBox1.Items)
alist.Add(lll);
foreach (ListBoxItem ll in listBox2.Items)
blist.Add(ll);
NavigationService.AddBackEntry(new CustomJournalEntry(alist, blist, ReplayCallback));
ListBoxItem l = (ListBoxItem)listBox1.SelectedItem;
listBox1.Items.Remove(l);
listBox2.Items.Add(l);
}

private void button2_Click(object sender, RoutedEventArgs e)
{
List<ListBoxItem> alist = new List<ListBoxItem>();
List<ListBoxItem> blist = new List<ListBoxItem>();
foreach (ListBoxItem lll in listBox1.Items)
alist.Add(lll);
foreach (ListBoxItem ll in listBox2.Items)
blist.Add(ll);
NavigationService.AddBackEntry(new CustomJournalEntry(alist, blist, ReplayCallback));
ListBoxItem l = (ListBoxItem)listBox2.SelectedItem;
listBox2.Items.Remove(l);
listBox1.Items.Add(l);

}

private void Button3_Click(object sender, RoutedEventArgs e)
{
List<string> alist = new List<string>();
foreach (ListBoxItem l in listBox2.Items)
alist.Add(l.Content.ToString());
ReturnEventArgs<object> ee = new ReturnEventArgs<object>((object)alist);
OnReturn(ee);
}
private void ReplayCallback(CustomJournalEntry c)
{
listBox1.Items.Clear();
listBox2.Items.Clear();
foreach (ListBoxItem l in c.AvailableToppings)
listBox1.Items.Add(l);
foreach (ListBoxItem ll in c.ChosenToppings)
listBox2.Items.Add(ll);
}
public System.Windows.Navigation.CustomContentState GetContentState()
{
List<ListBoxItem> alist = new List<ListBoxItem>();
List<ListBoxItem> blist = new List<ListBoxItem>();
foreach (ListBoxItem l in listBox1.Items)
alist.Add(l);
foreach (ListBoxItem ll in listBox2.Items)
blist.Add(ll);
return new CustomJournalEntry(alist, blist, ReplayCallback);
}

}

Notes:
  • This PageFunction should implement IProvideCustomContentState so that GetContentState is implemented. This method is called when moving backward and forward

  • OnReturn() method is called when you want to return the result of the PageFunction to the caller page

  • NavigationService.AddBackEntry() is used to add a current state of the PageFunction to the journal.

Thursday, 19 August 2010

Java

C# and Java language syntax comparison: http://www.25hoursaday.com/CsharpVsJava.html

Wednesday, 18 August 2010

IPhone Development


Environments/Tools:
Languages supported:
  • C, C++, Objective-C, JavaScript
Learn about Objective-C:

Monday, 2 August 2010

How to Connect 3D Points With Each Other in WPF?

 

Imagine you have some 3D spheres that you want them to be connected to each other such as:

image

Assuming you know a point in each of these spheres, the following Code uses a 3D cube to connect 2 3D Points with each other:

private void ConnectPoints(Point3D firstPoint, Point3D secondPoint, DiffuseMaterial diffuseMaterial, double thickness)
{
MeshGeometry3D linkCube = GetCube(firstPoint, secondPoint, thickness);

GeometryModel3D mGeometryLink = new GeometryModel3D(linkCube, diffuseMaterial);
mGeometryLink.Transform = new Transform3DGroup();

ModelVisual3D modelVisual3D = new ModelVisual3D();
modelVisual3D.Content = mGeometryLink;

_models.Add(modelVisual3D);
}

private MeshGeometry3D GetCube(Point3D firstPoint, Point3D secondPoint, double thickness)
{
MeshGeometry3D mesh = new MeshGeometry3D();
mesh.Positions.Add(new Point3D(firstPoint.X, firstPoint.Y, firstPoint.Z));
mesh.Positions.Add(new Point3D(firstPoint.X + thickness, firstPoint.Y, firstPoint.Z));
mesh.Positions.Add(new Point3D(firstPoint.X + thickness, firstPoint.Y - thickness, firstPoint.Z));
mesh.Positions.Add(new Point3D(firstPoint.X, firstPoint.Y - thickness, firstPoint.Z));

mesh.Positions.Add(new Point3D(secondPoint.X, secondPoint.Y, secondPoint.Z));
mesh.Positions.Add(new Point3D(secondPoint.X + thickness, secondPoint.Y, secondPoint.Z));
mesh.Positions.Add(new Point3D(secondPoint.X + thickness, secondPoint.Y - thickness, secondPoint.Z));
mesh.Positions.Add(new Point3D(secondPoint.X, secondPoint.Y - thickness, secondPoint.Z));

int k = mesh.Positions.Count - 8;
// Front face
mesh.TriangleIndices.Add(0 + k);
mesh.TriangleIndices.Add(1 + k);
mesh.TriangleIndices.Add(2 + k);
mesh.TriangleIndices.Add(2 + k);
mesh.TriangleIndices.Add(3 + k);
mesh.TriangleIndices.Add(0 + k);

// Back face
mesh.TriangleIndices.Add(6 + k);
mesh.TriangleIndices.Add(5 + k);
mesh.TriangleIndices.Add(4 + k);
mesh.TriangleIndices.Add(4 + k);
mesh.TriangleIndices.Add(7 + k);
mesh.TriangleIndices.Add(6 + k);

// Right face
mesh.TriangleIndices.Add(1 + k);
mesh.TriangleIndices.Add(5 + k);
mesh.TriangleIndices.Add(2 + k);
mesh.TriangleIndices.Add(5 + k);
mesh.TriangleIndices.Add(6 + k);
mesh.TriangleIndices.Add(2 + k);

// Top face
mesh.TriangleIndices.Add(2 + k);
mesh.TriangleIndices.Add(6 + k);
mesh.TriangleIndices.Add(3 + k);
mesh.TriangleIndices.Add(3 + k);
mesh.TriangleIndices.Add(6 + k);
mesh.TriangleIndices.Add(7 + k);

// Bottom face
mesh.TriangleIndices.Add(5 + k);
mesh.TriangleIndices.Add(1 + k);
mesh.TriangleIndices.Add(0 + k);
mesh.TriangleIndices.Add(0 + k);
mesh.TriangleIndices.Add(4 + k);
mesh.TriangleIndices.Add(5 + k);

// Right face
mesh.TriangleIndices.Add(4 + k);
mesh.TriangleIndices.Add(0 + k);
mesh.TriangleIndices.Add(3 + k);
mesh.TriangleIndices.Add(3 + k);
mesh.TriangleIndices.Add(7 + k);
mesh.TriangleIndices.Add(4 + k);
return mesh;
}