A day with .Net

My day to day experince in .net

Archive for November, 2012

Windows server appfabric cluster configuration using two work group machines

Posted by vivekcek on November 24, 2012

Read my post about installing windows server app fabric caching in a single WoRKGROUP computer.
Link To Post

In this post i am going to explain how to install appfabric in 2 networked WORKGROUP computer.

Configure the 2 system.
—————————————

1. Ensure that both systems are in a work group named ‘WORKGROUP’.
2. Down load and save the appfabric set up in 2 systems.
3. Create an Administrator account in both systems with same username.

Install appfabric in first machine.

——————————————-

1. Log in to first machine using the WORKGROUP\Administrator account. Simply type WORKGROUP\Administrator in Username text box.

2. By pressing SHIFT Right click the setup. Then select ‘Run As Different User’ use WORKGROUP\Administrator. Complete the installation.

3. Click Start, click All Programs, click Windows Server AppFabric, and then press SHIFT and right-click Configure AppFabric. Click Run as a different user. Enter \ and the password, and then click OK.

4. For Caching Service account, click Change. Click Custom account, click Browse, select WORKGROUP\Administrator

5. In the Caching Service configuration provider box, select XML.

6.In the File Share box, enter the computer name and share name for the file share that you created in the “Preparing Workgroup Computers for Installing AppFabric” topic for the XML file that will store caching configuration information. The path and name must be in the UNC format, i.e., \\\. On this first computer that will contain the share, you can browse to it.

7.Keep the default settings of New cluster selected and Cluster size set to Small (1-5 Machines). Click Next.

8.On the Configure AppFabric Cache Node page, keep the default port settings, and select the Windows Server AppFabric: AppFabric Caching Service and Remote Service Management firewall exceptions. Click Next and then Yes.

9. Open the Windows PowerShell console with the ApplicationServer module by clicking Start, clicking Control Panel, clicking Administrative Tools, and then double-clicking Windows PowerShell Modules.

10. To start the cache cluster, execute the Use-CacheCluster cmdlet to determine the cluster that this computer can administer, and then execute the Start-CacheCluster cmdlet.

Install appfabric in second machine.
—————————————————–

1. Log in to second machine using the WORKGROUP\Administrator account. Simply type WORKGROUP\Administrator in Username text box.

2. By pressing SHIFT Right click the setup. Then select ‘Run As Different User’ use WORKGROUP\Administrator. Complete the installtion.

3. Click Start, click All Programs, click Windows Server AppFabric, and then press SHIFT and right-click Configure AppFabric. Click Run as a different user. Enter \ and the password, and then click OK.

4. For Caching Service account, click Change. Click Custom account, click Browse, select WORKGROUP\Administrator

5. In the Caching Service configuration provider box, select XML.

6. In the File Share box, enter the computer name and share name for the file share created for the XML file that will store caching configuration information on the first computer added to the workgroup. The path and name must be in the UNC format, i.e., \\\.

7.Select Join cluster, and then select the cluster. Click Next.

8.On the Configure AppFabric Cache Node page, keep the default port settings, and select the Windows Server AppFabric: AppFabric Caching Service and Remote Service Management firewall exceptions. Click Next and then Yes.

9.On the Configure Application page, click Finish.To start the cache cluster, execute the Use-CacheCluster cmdlet to determine the cluster that this computer can administer, and then execute the Start-CacheCluster cmdlet.

GO to first machine and give power shell command.

Grant-CacheAllowedClientAccount everyone

Advertisements

Posted in Windows Server AppFabric Caching | Leave a Comment »

Remove TFS binding – The solution you are opening bound to source control

Posted by vivekcek on November 23, 2012

I was planning to move my project from TFS to SVN. So first i check out my code from TFS and copy the solution folder to some other place. But unfortunately when i open my solution a warning message like, ‘The solution you are opening bound to source control’.

I hate this massage. My code is check out from TFS still this message. I want to remove so tried the below code. Create a console application with this code.

using System;
using System.IO;

namespace Unbind
{
  class Program
  {
    static void RemoveBindings(string[] files,StreamWriter Log)
    {
      foreach (string file in files)
      {
        try
        {
          Log.WriteLine(file);
          string line;
          bool startDeleting = false;
          StreamReader SR = new StreamReader(file);
          StreamWriter SW = new StreamWriter(file + ".new.txt", false);
          while ((line = SR.ReadLine()) != null)
          {
            if (line.ToLower().Contains("globalsection(teamfoundationversioncontrol)"))
            {
              startDeleting = true;
              Log.WriteLine("  Removed: " + line.Trim());
            }
            else if (startDeleting && line.ToLower().Contains("endglobalsection"))
            {
              startDeleting = false;
              Log.WriteLine("  Removed: " + line.Trim());
            }
            else if (startDeleting)
            {
              Log.WriteLine("  Removed: " + line.Trim());
            }
            else if (line.ToLower().Contains("\tscc") || line.ToLower().Contains("<scc"))
            {
              Log.WriteLine("  Removed: " + line.Trim());
            }
            else
            {
              SW.WriteLine(line);
            }
          }
          SR.Close();
          SW.Close();
          File.Copy(file + ".new.txt", file, true);
          File.Delete(file + ".new.txt");
        }
        catch (Exception)
        {
        }
      }
    }

    static void Main(string[] args)
    {
      Console.WriteLine("Have you made a backup first? Y=continue");
      string prompt = Console.ReadLine();
      if (prompt.ToLower() != "y")
      {
        return;
      }

      // Looks in current directory and below for *.sln and *.proj files
      // For testing, I set the Project's startup folder properties to C:\FF\FabrikamFiber

      StreamWriter Log = new StreamWriter("log.txt", false);
      RemoveBindings(Directory.GetFiles(".", "*.sln", SearchOption.AllDirectories),Log);
      RemoveBindings(Directory.GetFiles(".", "*.*proj",SearchOption.AllDirectories),Log);
      Log.Close();
    }
  }
}

In the project properties set your working directory as the directory hold your solution. This solution find all .sln and .proj files inside that folder and remove TFS binding.

Use thi App.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <startup> 
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
    </startup>
</configuration>

Posted in TFS 2012 | Tagged: , | Leave a Comment »

Macro for copying dll to any directory visual studio

Posted by vivekcek on November 21, 2012

I have class library project in the below folder.

I:\SolutionTest\Main\Source\MyApp1\Source\ClassLibrary1

I want to copy the class library dll to the below folder

I:\SolutionTest\Main\Source\Builds

The Post-Buid macro for that

copy "$(TargetDir)\$(TargetFileName)" "$(SolutionDir)\..\Builds"

Posted in c#.net | Leave a Comment »

Create a virtual machine in azure and host an asp.net web site.

Posted by vivekcek on November 18, 2012

From this post you will learn how to create a virtual machine in windows azure.Virtual machine’s are the new IaaS(Infrastructure as a Service) feature in azure.Don’t confuse it with VM Role in PaaS(Platform as a Service).

So what is the advantage over PaaS?.
—————————————————–

PaaS constitute Web Role and Worker Role. When you deploy a Web Role azure will create a virtual machine for you and deploy your ASP.NET web site in that virtual machine.

Consider you have a big ASP.NET application. it will be hard to convert that to a web role project. in that case you can create a virtual machine and host your existing application without any change.

Another advantage deploy a share point farm with domain controller can be achieved using VM’s.

You can install 3rd party software like MySQL.

Simply you will get a virtual server you can do anything with that. Not just hosting asp.net.

STEPS
———————

1. Log in to your azure portal.

2. From Menu select ‘Virtual Machines->Create a virtual machine’.

3. From the next window select ‘COMPUTE->VIRTUAL MACHINE->FROM GALLERY’.

4. From gallery select your OS for virtual machine.

5. Give name and credentials for your virtual machine.

6. Give your DNS name for virtual machine. Through this DNS you can access your IIS hosted application. You should associate a storage account with the virtual machine to store OS installation file. In this example i have a storage account named ‘vivu’. If you don’t have any storage account azure will create one automatically when you create a virtual machine.

7. Next you can create an availability set. If you have only one virtual machine you don’t need to specify an availability set. This feature is used for placing virtual machines in different fault domains.

8. After your virtual machine create you can connect to your machine through remote desktop. Which is very simple don’t need any certificates uploaded.

Click connect and save .rdp file and click on that.

9. Give username and password

10. Enable Web Server Role.

11. Enable ASP.NET

12. Now you need to log back your azure management portal. Select your virtual machine and

select EndPoint.Then click ‘AddEndpoint’.You must configure port 80 TCP endpoint for external communication.

13. Select AddEndpoint.

14. Give details of end point.

16. After endpoint is create access ‘.cloudapp.net’

Posted in Azure | Tagged: , , | Leave a Comment »

Cannot delete storage account – azure Virtual Machine

Posted by vivekcek on November 13, 2012

I create a new VM, which automatically created a Storage account.

I then closed and deleted the VM, but the storage account remained.

When I try and delete it I get:

“Storage account *********** has 1 container(s) which have an active image and/or disk artifacts. Ensure those artifacts are removed from the image repository before deleting this storage account.”

To fix this

Go to Virtual Machines -> “Disks” or “Images” tab -> select the images/disks that you have located in the Storage Account you want to delete -> then hit the “Delete disk” or “delete image” command. Back these up if you need before hitting the delete.

Once the images/disks in the storage account have been deleted, you should be able to delete the storage account. Hope this helps.

Posted in Azure | Leave a Comment »

Access Windows Server AppFabric Cache through c# code

Posted by vivekcek on November 12, 2012

In this post i will explain how to add data to Windows Server AppFabric Cache.

1. Create a console application.

2. Add reference to Caching dll’s.

3. Use the below code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ApplicationServer.Caching;

namespace AppFabricCache
{
    class Program
    {
        static DataCacheFactory _cacheFactory = Initialize();  
        static void Main(string[] args)
        {
            var cache = _cacheFactory.GetDefaultCache();
            var Key = "mykey";
            var obj = cache[Key];
            if (obj == null)
            {
                obj = "hai";
                cache.Add(Key, obj);
                Console.WriteLine("Object added");

            }
            else
            {
                Console.WriteLine("Object was already in cache");
            }
            Console.ReadLine();
        }
        static DataCacheFactory Initialize()
        {
            var Config = new DataCacheFactoryConfiguration();
            var Servers = new List<DataCacheServerEndpoint>();
            Servers.Add(new DataCacheServerEndpoint("Poomala",22233));
            Config.Servers = Servers;
            var temp=new DataCacheFactory(Config);

            return temp;
        }
    }
}

Posted in Windows Server AppFabric Caching | Leave a Comment »

AppFabric Caching Admin Tool

Posted by vivekcek on November 10, 2012

Hope you read about my blog on installing and configuring Windows Server AppFabric.If not read here Install Windows Server AppFabric Caching.
Now i am gonna introduce you an open source AppFabric Caching Admin Tool from codeplex.

Download it http://mdcadmintool.codeplex.com/

Use it add cache cluster, regions, etc.

Use it with Admin privileges

Posted in Windows Server AppFabric Caching | Leave a Comment »

Install Windows Server AppFabric Caching

Posted by vivekcek on November 10, 2012

In this post i am going to explain how Windows Server AppFabric, the distributed caching solution from Microsoft can be installed and configured in a WORK-GROUP computer.WORK GROUP computers came under category of your stand alone home PC. In another post i will explain how AppFabric can be configured in domain system.

So what is AppFabric?
————————————-

AppFabric is a Microsoft solution for distributed caching. Currently two AppFabric’s are available one in windows azure and other Windows Server AppFabric.Both have some feature changes you can search about it in web.

Install
————————

Need windows 7(32 bit or 64 bit) or Windows Server 2008 R2.

1. Download (WindowsServerAppFabricSetup_x86.exe) Microsoft AppFabric 1.1 for Windows Server Microsoft AppFabric 1.1 for Windows Server .

2. Run Setup.

3. Select all features.

4. After installation the configuration window will be opened OR you can select config window from program menu.

5. In a Work Group computer you have to use XML as caching service provider.

6. Now create a network share folder named ‘Share’ with write permission.

7. Use browse button to set the shared folder path as UNC path.

8. In the case of Work Group computer change the service account to your user account.

9. Click next don’t change default ports. Finish installation

10. Open the Cache administration power shell with Run as Administrator command.

11. Use the Start-CacheCluster command.

In another post i will explain how to use this in .NET applications.

Posted in Windows Server AppFabric Caching | Tagged: | Leave a Comment »

LINQ to XML – Null handling by extension method

Posted by vivekcek on November 5, 2012

I am using extension methods to handle blank or null elements in xml processing using LINQ.
My methods are given below.

        
	private static string isElementNull(this XElement element)
        {
            if (element != null)
                return element.Value;
            else
                return "";
        }

        private static string isAttributeNull(this XElement element, string attributeName)
        {
            if (element == null)
                return "";
            else
            {
                XAttribute attribute = element.Attribute(attributeName);
                return attribute == null ? "" : attribute.Value;
            }
        }

Now how to access element and its attribute in linq.

strng name=q.Element("Name").isElementNull();
string id=q.isAttributeNull("id");

where q is an element.

Posted in LINQ | Tagged: , | Leave a Comment »