Murtaza Fazal's Blog

Murtaza Fazal's Blog
Murtaza Fazal's Blog
Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Wednesday, June 15, 2011

Alarm in Windows Phone 7.1 (Mango)

How often we want to create an application which could generate Alarm in the background and play it on the specified time? Once me and my brother were investigating this same task on iPhone and what we found was... the audio won't play for more then 40 seconds . Implementing the same thing on Windows Phone 7.1 (Mango) is piece of cake :) Just few lines of code and you are done.

I'll demonstrate how to write a simple program which plays any audio which you want :)


  1. Create a new Project
  2. Select Target Framework as 7.1
  3. In you Main.xaml.cs , include the library  "Microsoft.Phone.Scheduler".
  4. I've placed the audio file on the root , if you want you can create a folder as audio and place your file there. Then you should navigate as per your need. 
  5. Now write the following code 
    • Alarm myAlarm = new Alarm("mmfAlarmTest");   
      • // You need to specify a name for the alarm
    • myAlarm.BeginTime = DateTime.Now.AddMinutes(1);  
      • // I would like it to play after 1 minute of execution
    • myAlarm .Sound = new Uri("/toss-the-feathers.mp3",UriKind.RelativeOrAbsolute); 
      • // Remember my audio file is on the root directory?
    • ScheduledActionService.Remove("mmfAlarmTest");  
      • // Remove if there exist a similar alarm
    • ScheduledActionService.Add(myAlarm);   
      • // Register your alarm


And that's it !!! . Test it out and enjoy the fun ;) Using this, you can generate an application which sets alarm through your application

Monday, June 6, 2011

Migrating from 7.0 to 7.1(mango) beta - Windows Phone 7

 MANGO - Database

If you want to use the new built-in database in your already created windows phone 7.0 application. You need to do the following things
  1. Change the Framework from 7.0 to 7.1
  2. Add Reference to System.Data.Linq and mscorlib.extensions (most of the websites do not include this, and if you do not add reference to this, you would not be able to implement the interface INotifyPropertyChanging)
  3. Last but not the least , include the following directives
    • using System.Data.Linq;
    • using System.Data.Linq.Mapping;
    • using System.ComponentModel;
    • using System.Collections.ObjectModel;
Now you are good to go :) you may refer to the following link for assistance in creating database and how to use it:
 http://msdn.microsoft.com/en-us/library/hh202876(v=vs.92).aspx 

Sunday, May 22, 2011

Crystal Report 10.2.3600.00 on Windows Server 2008 R2

After trying almost everything on net to make Crystal report work , finally i got it working on our Production Server which had the following Configuration

OS : Windows Server 2008 R2 (64 bit)
IIS : 7.5

  • Just install Crystal Reports Redistributable Package for 64 bit
  • In IIS, set Application Pool as Classic
  • Set Allow 32 bit Application as FALSE
  • Set Connection User as the NetworkService
  • Assign the user  NetworkService to have write access to your Windows/Temp folder.
  • Assign the user  NetworkService to have write access to your Website folder (if you are writting temporary Crystal Reports inside your application folder as we were doing).  

And that's it :) after delaying the GO LIVE activity for a week, finally found the above settings can  solve the issue :)


Friday, January 15, 2010

Becoming a Great Programmer

You might think that great programmers can type at a thousand words a second, have a mega-sized brain, and are fitted with a socket that lets them connect directly to a computer. This is not true. Especially the socket bit. In my experience, the best programmers are the ones who are the most fun to be with. The ones who you enjoy talking to. The ones who don’t get upset when you find a mistake in their programs and who will sometimes agree that your solution is better than the one that they had invented. I’d much rather work with someone like that than someone who can write a hundred lines of code a minute but who refuses to speak to me if I dare to suggest that one of those lines might be wrong. Great programmers take care to find out that what they are doing is the right thing. If they are working for a customer, they will make sure that the customer gets what the customer wants. They will not assume that they know the best way to do it and just do it their way. They will make sure that what they produce is tested and comes with helpful documentation. They will work in the team, make coffee when it is their turn, and do whatever it takes to make sure that the project has a happy ending. Of course, they might also fill your office with beach balls, superglue your keyboard to the desk, or cover your chair with aluminum foil, but these are all done with a friendly spirit.

I have secured the services of a great programmer who will be adding Programmer’s Points to our text. These are truly words of wisdom, so make sure to take note when you see them.

--
Rob Miles
In his book : Microsoft XNA Game Studio 2.0 Learn Programming NOW

Saturday, December 5, 2009

Tracing Recursive calls in Fibonacci Series


In mathematics, the Fibonacci numbers are the numbers in the following sequence:

0 , 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, ...


By definition, the first two Fibonacci numbers are 0 and 1, and each remaining number is the sum of the previous two. Some sources omit the initial 0, instead beginning the sequence with two 1s.

int F(int num)
{
      if ( num <=1)
           z = num;
     else
           z =  F(n-1) + F(n-2);
     return z;
}

In this function , if we pass n, it should return n+1th term , e.g passing 6 will return 8 so let suppose we pass 5 to the function F then in this case, it will call the function for 5. It will test either if num (which is 5 at the moment) is with <= 1? NO, hence it will move to the else part where it will call the function F again for 2 new values and their final sum will be restored in z. so the equation will become like this

z = F(4) + F(3);

Now we’ll use the first come first bases rule and go and evaluate F(4) then F(3) . Hence F(4) will be called exactly as F(5) was called, it will again test for <=1 which is NO again and then it will call again the 2 recursive functions for F(4) i.e

z = F(3) + F(2);

This can be better explained in terms of a TREE






The bold objects are the values returned by the if clause of the function F. Blue color numbers are the one being returned to the previous state from the stack.

Tuesday, September 1, 2009

Nullable Type in Visual Studio 2005+

Many of us learn programming through books or in some programming course. They course starts with simple data types and ends with a good looking application but one thing most of the books or instructors forget that the first and farmost requirement of a good looking application is to have good backend programming as well. I’ve being working on C# since a long time but I never came across this Nullable type in any of the books for beginners or Professionals and to me it seemed as one of the basic knowledge that was missing.

What does Nullable do? So far when we write a small piece of code, like for instance we are taking bio-data from the user in a console based application and if he presses enter without typing anything i.e. entered nothing in that field, what would happen? And what should have happened? The user pressed enter which means it should be a null field whereas a character 13 (ASCII CODE) is saved in its place. Is that the correct thing? Definitely not, and to overcome this state most of the books teaches us to use conditions that if its equal to 13 then ignore it or do something.

In Framework 2.0 and onwards, Microsoft has provided us with Nullable type through which we can allow null values in our simple datatypes. Nullable types represent value-type variables that can be assigned the value of null. You cannot create a nullable type based on a reference type. (Reference types already support the null value.)

Nullable < T >   variable;

Here T is a value type. The two forms are interchangeable. As in our example, we can use following code:

Nullable < string >  name = null;

Or what if we want to have a 3 state Boolean variable? True, False and Null? Thanks to Nullable type we can implement this within seconds by declaring our boolean variable under nullable type

Nullable < bool >  flag;

Microsoft added this feature but what’s the use of it?  Why to add another state even if we could do it through some conditions? With the use of Nullable, we can have the normal range of values of the underlying value type with additional of null value. Two fundamental members of the Nullable structure are “HasValue” and “Value” properties. If the HasValue property for a Nullable(T) object is true, the value of the object can be accessed with the Value property. If the HasValue property is false, the value of the object is undefined and an attempt to access the Value property throws an InvalidOperationException. The Nullable class supports obtaining the underlying type of a nullable type, and comparison and equality operations on pairs of nullable types whose underlying value type does not support generic comparison and equality operations.