Key components that you need to figure out before federating your Windows Azure web role with your domain Active Directory.

by wenyuz 5. August 2011 14:53

If you are not sure what all the settings are, federate your first web application in Windows Azure with your domain ADFS could be very painful. There are a couple of key components that you would need to watch out for to ensure that this process is successful.

  1. Proper Realm settings. When you are adding STS reference, it is one of the fields that you would need to enter. And it is how ADFS identifies which web application this request is from, and then redirect after authentication to the Return URL that you have setup with the ADFS federated services. So when you put in a request to your ADFS setup team, ensure that the realm is entered properly to prevent delay.
  2. Return URLs (It most likely is just the domain of the web application, most likely not specific to a page, you probably would need to add the code for the claim in your default page. )
  3. Ensure to put in request to your ADFS setup team to have the claimtypes that you need properly setup so you can consume in your web role.
  4. Access level. You need to ensure that your ADFS setup team sets up the access level for your particular onboard is broad enough to fit your needs. They can probably setup the access level in a Security Group level, or all corp net users, or only a set of specific users/service accounts.
  5. SSL ( you have to ensure that you have SSL installed in your application. And you need to ensure that it is only specific to your particular cloudapp when you request the SSL). At deployment, you would need to upload it into your own personal certificate store, and then export with a private key and upload into the Windows azure hosted services certificates. If the certificate is chained, you either need to break the chain or include all the certificates in the chain when you do the export from your personal certificate store.
  6. In your web role, you would need to include the Microsoft.identityModel dll. But if you only set the property to copy always, it is definitely not enough. The web application would need the Microsoft.identityModel to be in the GAC as well as in the bin directory. So you would need to following the steps in this blog: to ensure that the identityModel is installed in the GAC when you deploy the web role. The basic steps for doing so is to add a start-up cmd and then include the gacutil.exe in the project as well as the startup cmd file, so at deployment time, the Microsoft.IdentityModel is installed to the GAC to ensure that the web role runs properly.

Using MS Chart Control and file access in Windows Azure

by wenyuz 11. July 2011 17:49

If your web site was built using Entity Framework and .Net 4, migrating your web application is surprisingly easy. But if you are currently using a MSChart control such as Stackedbar chart control or line control, you might encounter some server errors. So first thing that you need to check is your web.config. When you create a chart, VS automatically put in a ChartImageHandler in your appsettings in the web.config along with some other attributes.  You could change ChartImageHandler value to storage=session from the default file system c drive temp folder. However, since Windows azure highly recommend multiple instances of the webrole, you probably will encounter problems at chart generation runtime. You would probably see random image not found on the pages.

In search of solution, I have found that this blog to be really helpful, he uses Windows Azure blob storage instead of file system/session/memory.  Here is the  http://visitmix.com/writings/using-the-asp-net-chart-control-with-multiple-web-roles-in-windows-azure. One thing that I found out when i am trying the method is that when you modify the web.config to use the custom ChartImageHandler, you have to specify the handler as well as the assembly name for the handler. if not it would assume the handler is in System.Web.DataVisualization.

Here is another blog that is very helpful to solve this issue: http://social.msdn.microsoft.com/forums/en-us/MSWinWebChart/thread/51E117FE-6F23-428F-B5F5-8BA287F97371. if you want to learn how to properly configure the assembly qualified name. you can read about it here: http://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname.aspx.   You should also check to ensure that the attribute Copy Local is set to be true for the dlls in your references to ensure that the references are migrated to Windows Azure.

If you are trying to use Server.MapPath in Windows Azure, you would need to ensure that the file that you are trying to access has the Build Action attribute to be set to Content, and Copy to Output Directory is set to Copy Always.

Adding multiple Lync Contacts to Existing Web Page

by wenyuz 6. June 2011 11:05

In order to add Lync contacts to existing web pages, you would need to add a Lync Silverlight project to your existing web pages. And then add the Silverlight objects onto your web page. The issue that I was experiencing was that if you only have the contact presenceindicator with the display name onto the page and you want to be able to have the contact detail on hover as well, the object cannot display inline with the rest of the page. One way is to call a javascript function from within the Silverlight object to resize the Silverlight object, but it would still push the rest of the page down if you get the Silverlight object to resize on the fly. So the other work around that I have used was to create two Silverlight objects per contact, one for detail and one for presence indicator, and on the page, you can add a javascript to toggle the detail page. The only draw back was that you would have to add multiple Silverlight objects onto the page, and if there are a lot of contact objects on the page, it would slow down the performance. Of course, if you are adding other contacts onto the same page, you would need to add a contactID to each one and specify the ContactID in the javascript.

Cool little Done for you features in Windows 7 Phone App Development

by wenyuz 2. May 2011 11:45

In the past about a month, I have been working on a windows 7 phone application. And I found a couple of unexpected cool little done for you features built in to the windows 7 phone that made my life so much easier. First of all, I was trying to put in an animated splash screen at the application load, and I was really pleased to find that it is already automated, you just need to replace the SplashScreenImage.jpg in the project root folder, and wala the splashscreen is done. To change the default application icon, and the tile when you have the application pinned on the front page, all what you need to do is to replace the ApplicationIcon.png and the Background.png in the project folder. Of course, then you will have to create some cool images to get people’s attention… since I am a developer, not much of a designer, Thank God for my creative team with great and awesome talents to make my app look beautiful.

For most apps, you would need to use the ApplicationBar with ApplicationBarIconButton for settings, navigation and such. Coming from a .net, css background, I was expecting to animate it in Silverlight so it would have the press state and hover state. And surprisingly, I found out, you just need to create an image that is 48x48 with transparent background with white/color on the icon, and reference it in the ApplicationBarIconButton as iconUri. At runtime, the program would replace the white with black and also transparent with white when you press on the button, and also it has a nice round circle with it, so you don’t need to create an icon that has a round circle with two or three states. But in order for the image to show up in the emulator and on the phone, you need to go to the property for each image and then change the Build Action to Content and Copy to Output Directory to Copy Always. If not, it will always fall back to the default application icon. There are also some default icons that came with the SDK, so you don’t need to have them custom created, and you can find them at:

  • C:\Program Files\Microsoft SDKs\Windows Phone\v7.0\Icons\dark
  • C:\Program Files (x86)\Microsoft SDKs\Windows Phone\v7.0\Icons\dark

Once you find out what the file name of the icon that you want to use. They are mostly formated as appbar.xxx.rest.png, then in the IconUri, you can just simply reference them as IconUri="/Images/appbar.xxx.rest.png". then you don't even need to add them into your application's images folder for the icons to work.

 

My take on MIX11

by wenyuz 21. April 2011 12:22

Last week, some of my colleagues and I went to the MIX11 at Las Vegas. Overall the conference was very helpful for me as a dev. I have to say, I constantly being amazed by the speed of our current technological advancement. There were some great demos in the keynote on what people have been doing with Kinect from the Kinect driven lounge chair car, to helping the visually impaired, to exploring the universe through gestures. I remember several years back, I watched a movie called Minority Report where Tom Cruise used Gestures to interact with everything in the computer. With Kinect exploring the universe demo, I really feel like the future is now. All what we need is some holographic projection and tie up with Kinect. LOL Doesn’t that sound simple… of course… not…

In the conference, Microsoft announced the new windows Phone 7 Mango, there are definitely some really cool new features coming out such as enhanced programmability of the Tile, being able to save tile at a page level, and better notifications and built in SQL DB. All are great features, but I kept on wondering why they come up with the name Mango…. It kept on reminding me of the SNL skit… every time when they mentioned it.

If you are fairly new to windows phone development, you should definitely watch the session: Expert Lessons: Top Tips for Building a Successful Windows Phone Application Even if you have developed some apps already, this session would be very helpful for you as well. But here are some highlights for your preview:

  • Login page: Instead of a page, put it in a usercontrol
  • Don’t add a home button in your app to create circular navigation.
  • Always persist data from tombstone (OnNavigatedFrom to persist data and OnNavigatedTo to restore data)
  • Always test every page for tombstoning.
  • Understand the various states and always test on real device in real situations such as when you receive a call, in and out of internet connectivity
  • Always test your app with the changes of Language settings and also theme changes.
  • Make sure that your app supports Orientation change. Just simply change the SupportedOrientations = “Portrait” to SupportedOrientations=”PortraitOrLandscape” on the top of each of the page
  • Always add a send Feedback button so you can better improve your app, since there are always something that you might not have considered.

So there are 7 things to check before you hit submit for the market place.

  • No network, no problem
  • <90MB
  • Theme aware
  • Handle Exceptions
  • Back button works as expected
  • User consent dialogs & settings
  • Pauses/resumes user’s music

Analyzing and Improving Windows Phone Application Performance is also a very helpful session as well which helps you through how to improve the performance of your phone app not just using the profiler, but how to code better and what to consider because of the windows phone resource limitations and such.

I also found the session: Enhanced Push Notifications and Tiles for Windows Phone to be very helpful as well which talks about how to take the advantage of the push notifications and tile updates to better improve the usability of the app.

Of course, there are many other sessions that were very helpful, you should definitely check them out

SharePoint Deployment/Development Tips

by wenyuz 1. April 2011 17:15

When developing against SharePoint, sometimes you will encounter issues at deployment. Here is some info and tips that I found quite helpful.

  1. Always try to reset your IIS first. A lot of times, simply resetting IIS would resolve a lot of issues at deployment.
  2. If you are encountering error while doing a wsp deployment. Make sure that the SharePoint Administration service is running. You should probably set it as auto start.
  3. If you are getting the error stating that a deployment or retraction is already under way and it is not allowing you to redeploy. Most likely your previous deployment is hung, and you can cancel the job and re-deploy your solution by getting to the stsadm in your command line and then run the following two commands. Stsadm is located in The GUID JobID is provided by the first step.
    1. stsadm -o enumdeployments
    2. stsadm -o canceldeployment –id “GUID jobid”
  4. If you are seeing the general SharePoint error and not giving you any specifics on what the issue that you are having, and you do have access to the SharePoint site as admin. You can turn it off by going to web.config. Of course if you are in a production environment. Make sure to change it back after debugging.
    1. Debug=”true” instead of the default of Debug=”false”
    2. CallStack=”true” instead of the default of CallStack=”false”
    3. CustomErrors=”Off” instead of the default of CustomErrors=”On”
  5. At deployment, your usercontrols are deployed to C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\CONTROLTEMPLATES, so you can always double check to ensure that the deployment of your usercontrols are done correct. However, they are all read only, and cannot be updated unless by a new deployment.

Cloning Slides including Images and Charts in PowerPoint presentations & Using Open XML SDK 2.0 Productivity Tool

by wenyuz 21. March 2011 12:37

Since Microsoft used Open XML as their document format for the office products since 2007. You can rename the file to a .zip file and then explore the content of the office. Programming against office files is now more of an XML manipulation. Unless you want to purchase additional controls such as Apose which is currently support to up to 2007, Open XML SDK productivity tool is definitely your best friend.

I was working on cloning slides for a complex slide deck this past a couple of weeks which I need to clone the content of the slide as well as charts and images. So I was looking through resources online and I found a couple of good resources such as http://www.prowareness.com/blog/?p=392 and also http://msdn.microsoft.com/en-us/library/dd469465(v=office.12).aspx. However the Chartspace cloning part did not work for me in Anand’s blog, and I couldn’t find any other good resources to clone the charts. In Anand’s blog, he uses the ExternalData in the chartspace which does not resolve in my code, and I also tried to get the node and set the ID as a work around, however it does not work either. The PowerPoint slide would run an error when you try to open the file and requests a repair, and after repair, the content is no longer valid. So as a work around, I used the Open XML SDK Productivity Tool.

Here is what you can do to generate the charts on the fly. In cloning the slides, you need to clone all aspects of the slide. If you have two charts in the slide, you would need to clone both of them for the slide to work, chartspace as well as the external embedded excel worksheet for each of the chart. When you open the slide in the Productivity Tool, you need to explore to the chart xml that you want to clone. Normally if there is only one slide, then you need to open the node under ppt/presentation.xml -> ppt/slides/slide1.xml -> /ppt/charts/chart1.xml. When you select /ppt/charts/chart1.xml, and then click Reflect Code. In the reflect code pane, you will be able to find the code that you would need to create the chart on the fly. It would include CreateChartPart(ChartPart part) function that would call something similar to these five lines of code. And of course you would need to include the rest of the functions in the reflect code pane that the CreateChartPart function calls. If you have multiple charts in the slide that you need to clone, then you would need to get the CreateChartPart function for the second chart as well. This only works if you are cloning the charts onto a separate slide. Because in openxml , charts are indexed within the slide, so you can use the same code in the previous slide including the indexing.

public void CreateChartPart(ChartPart part) {
ChartDrawingPart chartDrawingPart1 = part.AddNewPart("rId2");
GenerateChartDrawingPart1Content(chartDrawingPart1);
EmbeddedPackagePart embeddedPackagePart1 = part.AddNewPart("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "rId1");
GenerateEmbeddedPackagePart1Content(embeddedPackagePart1);
GeneratePartContent(part); }

Here is the function to clone the charts, images and slides:

public static SlidePart CloneSlidePartWithImagesAndCharts(PresentationPart presentationPart, SlidePart slideTemplate) {
int i = presentationPart.SlideParts.Count(); //Create a new slide part in the presentation.
SlidePart newSlidePart = presentationPart.AddNewPart(”newSlide” + i);
i++; //Add the source slide content into the new slide.
newSlidePart.FeedData(slideTemplate.GetStream(FileMode.Open)); //Make sure the new slide references the proper slide layout.
newSlidePart.AddPart(slideTemplate.SlideLayoutPart, slideTemplate.GetIdOfPart(slideTemplate.SlideLayoutPart)); // copy the image parts
foreach (ImagePart ipart in slideTemplate.ImageParts) {
ImagePart newipart = newSlidePart.AddImagePart(ipart.ContentType, slideTemplate.GetIdOfPart(ipart));
newipart.FeedData(ipart.GetStream()); } // copy the chart parts
ChartPart cpart1 = slideTemplate.ChartParts.FirstOrDefault();
ChartPart newcpart1 = newSlidePart.AddNewPart(slideTemplate.GetIdOfPart(cpart1));
CreateChartPart(newcpart1);
newcpart1.ChartSpace.Save(); //Get the list of slide ids.
SlideIdList slideIdList = presentationPart.Presentation.SlideIdList; //Deternmine where to add the next slide (find max number of slides).
uint maxSlideId = 1;
SlideId prevSlideId = null;
foreach (SlideId slideId in slideIdList.ChildElements) {
if (slideId.Id > maxSlideId) {
maxSlideId = slideId.Id;
prevSlideId = slideId; } }
maxSlideId++; //Add the new slide at the end of the deck.
SlideId newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId); //Make sure the id and relid are set appropriately.
newSlideId.Id = maxSlideId; newSlideId.RelationshipId = presentationPart.GetIdOfPart(newSlidePart);
newSlidePart.Slide.Save();
return newSlidePart; }

After you clone the slide, you probably would need to edit the chart data, one way to edit each of the chart series is to remove the series and then create the series on the fly. If you have a line chart, you can get the code for creating the linechart by browsing to the ChartSpace, then c:chart (Chart) -> c:linechart (LineChart) -> LineChartSeries, and click Reflect code. If there are multiple LineChartSeries, then you would need to get the code for all series. Most of the code for generating the LineChartSeries are very similar. You could consolidate the functions into one function, however, you would need to make sure that the index for each LineChartSeries is correct, if there are not correct, the slide would not work. You would need to modify the function to include the new data for the new charts on the fly at the GenerateLineChartSeries function. So here is how you can remove the series and then add a new series in it’s place. However, one draw-back for updating the chart series this way is that the backend xslx for each chart is not updated.

ChartPart ChartPart1 = Slide1.ChartParts.FirstOrDefault();
Drawing.Charts.Chart Chart1 = ChartPart1.ChartSpace.Descendants().First();
Drawing.Charts.LineChart LineChart1 = Chart1.Descendants().First();
Drawing.Charts.LineChartSeries ChartSeries1 = Chart1.Descendants().First();
LineChart1.RemoveChild(ChartSeries1);
Drawing.Charts.LineChartSeries NewChartSeries1 = GenerateLineChartSeries(); //You would need to modify the function to either take in parameters in the function call and then add in the data according.
LineChart1.AppendChild(NewChartSeries1);
ChartPart1.ChartSpace.Save();

A little Tip and Trick on SSRS Reports using URL Access Parameters

by wenyuz 4. March 2011 17:37

SSRS reports are very useful in generating reports on the fly.  Most of the SSRS reports have parameter fields and toolbar. If you want to embed it in a separate page, you might want to hide them. You can simply pass in the Toolbar=false parameter   in the URL to hide the whole tool bar. Such as this: http://servername/reportserver?/Sales/YearlySalesSummary&rs:Command=Render&rs:Format=HTML4.0&rc:Toolbar=false. You can also style the toolbar and the parameter fields using the style sheet and apply it on the fly. For example,   you can accomplish the same as the toolbar=false by adding the following two classes in the stylesheet:

.MenuBarBkGnd{display: none;}
.ToolBarButtonsCell{display: none;}

Of course you can also change the background color, font color and etc. in the toolbar in the style sheet.  The easiest way to find out what to change is by using F12 in the Internet Explorer. Find the class for the area that you want to change, and then override the class by adding it into the style sheet. You would then need to save the style sheet in the styles folder under C:\Program Files\Microsoft SQL Server\xxx\Reporting Services\ReportServer\Styles\ and name it as stylesheetname.css. You can access the report with the new style by URL:   http://servername/reportserver?/Sales/YearlySalesSummary&rs:Command=Render&rs:Format=HTML4.0&rc:stylesheet=stylesheetname 

Tags: