Monday, February 26, 2018

Run InstallShield Setup (InstallScript MSI) with logging

Setup.exe /debuglog"C:\PathToLog\setupexe.log" /V"/L*v c:\PathToLog\SetupMSI.log"

Thursday, February 22, 2018

Async Await support for Console Applications

Nito.AsyncEx is the library which can be used to add support for Console application. (not limited to console application.)
Add the nuget package - Nite.AsyncEx

And then call your function as

AsyncContext.Run(() => ExecuteMethodAsync());

private static async Task ExecuteMethodAsync()
{
//do something
}

Happy Coding!

Thursday, February 15, 2018

Sample Code to open PDF File in Browser instead of download



public HttpResponseMessage Get(int id)
{
try
{
string filename = "File.pdf";
string filepath = System.Web.HttpContext.Current.Server.MapPath("~") + "/" + filename;
byte[] filedata = System.IO.File.ReadAllBytes(filepath);
string contentType = MimeMapping.GetMimeMapping(filepath);

HttpResponseMessage result = new HttpResponseMessage(HttpStatusCode.OK);
result.Content = new ByteArrayContent(filedata); ;
result.Content.Headers.ContentType = new MediaTypeHeaderValue(MimeMapping.GetMimeMapping(filepath));
var cd = new System.Net.Mime.ContentDisposition
{
FileName = filename,
Inline = true,
};

HttpContext.Current.Response.Headers.Add("Content-Disposition", cd.ToString());
return result;

}
catch (Exception)
{
throw new HttpResponseException(HttpStatusCode.InternalServerError);
}
}

Converting a guest user to member in Azure AD

To convert a guest user into a member in Azure Ad run the following command.


Connect-MsolService
login with Global admin of the AD in which guest user exists.

Get-MsolUser -UserPrincipalName hpatel#EXT#@yourdomain.onmicrosoft.com -UserType Member

This should convert the user to member.
hpatel#EXT#@yourdomain.onmicrosoft.com is the guest user. remember Microsoft adds #EXT# to the email. so if you get error that says that user not found, run the following command and validate the upn.
Get-MsolUser --UnlicensedUserOnly

Tuesday, November 21, 2017

TFS - ReParenting a Branch.

Here is how you can do Reparenting for TFS branch. 
Scenario: Before 
  • Development
    • Release 1
      • Release 2
Scenario: After
  • Development
    • Release 1
    • Release 2

Now you want to bring Release 2 under development, then you need to do re parenting. 


  1. Create Release 2 branch from Release  
  2. Get the latest version of Release 2 locally. 
  3. Get the latest version of Development branch locally. 
  4. Add location of tf command (generally “C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE”) to your PATH.
  5. Open command prompt and go to the working folder of Release 2. If you don’t do this then you may get error related to workspace while running commands mentioned below.
  6. Now you need to perform a baseless merge from the development branch to Release 2. Make sure it is recursive. (why recursive ? because if  you don’t do it recursive then while merging your changes from Release2 to development, and if you do it from the folder level, it would show you Release 1 as the parent. In that case, you should always start your merge by right clicking on the “Release 2” level. Which is annoying. So go for recursive. )
  7. Here is the command.
  8. Tf merge /baseless /recursive “$/Development” “$/Development/Release2”
  9. This command may take a while depending on the size of your source code.
  10. Once done, it will show you resolve conflict window. In my case, I don’t want changes from development branch to be merged into Release 2, so I choose Keep destination files. And resolve the conflict for all. 
  11. Once done, you will have a big chunk of files ready for check in in Release 2 branch. 
  12. Go ahead and check in. 
  13. Once check in is done, right click on Release 2 and then select ReParenting (under branch and merging menu)
  14. You should be able to see Development branch there. 
  15. Select it. And hit ok. 
  16. All done. Release 2 has now Development as its parent. 
Thanks

Thursday, May 11, 2017

Exponential backoff for retry mechanism

For retry mechanism, rather than retrying on a specific interval of time, it is advisable to handle it with exponential backoff. This is important in the world of Azure, Pass or any where you are communicating with external resources, as there are more chances of transient errors compared to local resources. 

All communicating with the external resources should have retry mechanism. There are some nuget packages available to handle the transient errors but following articles shows a nice and neat implementation of handling them with exponential backoff. And give us control to change the code as per our requirements.