Archive for 'Blog'

Use Debug output window to monitor SQL generated by LINQ2SQL

Posted on 28. Jun, 2010 by naresh in .net Programming

In all the examples out there to see the SQL generated by a LINQ2SQL query console.out is used, but to monitor the SQL in a debug window we need to write a special text writer implementation

using System.IO;
using System.Text;
using System.Diagnostics;
using System.Globalization;
using System;
namespace nj.Diagnostics
{
    /// <summary>
    /// Implements a <see cref="TextWriter"/> for writing information to the debugger log.
    /// </summary>
    /// <seealso cref="Debugger.Log"/>
    public class DebuggerWriter : TextWriter
    {
        private bool isOpen;
        private static UnicodeEncoding encoding;
        private readonly int level;
        private readonly string category;
 
        /// <summary>
        /// Initializes a new instance of the <see cref="DebuggerWriter"/> class.
        /// </summary>
        public DebuggerWriter()
            : this(0, Debugger.DefaultCategory)
        {
        }
 
        /// <summary>
        /// Initializes a new instance of the <see cref="DebuggerWriter"/> class with the specified level and category.
        /// </summary>
        /// <param name="level">A description of the importance of the messages.</param>
        /// <param name="category">The category of the messages.</param>
        public DebuggerWriter(int level, string category)
            : this(level, category, CultureInfo.CurrentCulture)
        {
        }
 
        /// <summary>
        /// Initializes a new instance of the <see cref="DebuggerWriter"/> class with the specified level, category and format provider.
        /// </summary>
        /// <param name="level">A description of the importance of the messages.</param>
        /// <param name="category">The category of the messages.</param>
        /// <param name="formatProvider">An <see cref="IFormatProvider"/> object that controls formatting.</param>
        public DebuggerWriter(int level, string category, IFormatProvider formatProvider)
            : base(formatProvider)
        {
            this.level = level;
            this.category = category;
            this.isOpen = true;
        }
 
        protected override void Dispose(bool disposing)
        {
            isOpen = false;
            base.Dispose(disposing);
        }
 
        public override void Write(char value)
        {
            if (!isOpen)
            {
                throw new ObjectDisposedException(null);
            }
            Debugger.Log(level, category, value.ToString());
        }
 
        public override void Write(string value)
        {
            if (!isOpen)
            {
                throw new ObjectDisposedException(null);
            }
            if (value != null)
            {
                Debugger.Log(level, category, value);
            }
        }
 
        public override void Write(char[] buffer, int index, int count)
        {
            if (!isOpen)
            {
                throw new ObjectDisposedException(null);
            }
            if (buffer == null || index < 0 || count < 0 || buffer.Length - index < count)
            {
                base.Write(buffer, index, count); // delegate throw exception to base class
            }
            Debugger.Log(level, category, new string(buffer, index, count));
        }
 
        public override Encoding Encoding
        {
            get
            {
                if (encoding == null)
                {
                    encoding = new UnicodeEncoding(false, false);
                }
                return encoding;
            }
        }
 
        public int Level
        {
            get { return level; }
        }
 
        public string Category
        {
            get { return category; }
        }
    }
}

The you can use

datacontext.log = new DebuggerWriter();

Tags: ,

Forms Authentication fails even when browser accepts cookies

Posted on 15. Jun, 2010 by naresh in .net Programming

While using Forms authentication in ASP.net

<forms name=".ASPXAUTH" loginUrl="login.aspx"
		  defaultUrl="Default.aspx" protection="All" timeout="30" path="/"
		  requireSSL="false" slidingExpiration="true"
		  cookieless="AutoDetect" domain=""
		  enableCrossAppRedirects="false">
		  <credentials passwordFormat="SHA1" />
</forms>

please remeber to set path = “/” or else the cookie based authentication fails, I am yet to figure out why this is happening but atleast this solves the problem.

Tags: ,

How to Add Windows XP to Windows 7 Boot Manager

Posted on 23. Mar, 2010 by naresh in Software

1. Open an elevated command prompt.
2. Type the following to create a boot loader for Windows XP.
bcdedit /create {ntldr} /d “Windows XP”
3. Type the following to set the device to where Windows XP is installed. I used D: in this example. Replace it with the drive letter of your XP installation.
bcdedit /set {ntldr} device partition=D:
4. Type the following to set the path.
bcdedit /set {ntldr} path \ntldr
5. Type the following to add this boot loader to the boot up screen.
bcdedit /displayorder {ntldr} /addlast
6. Reboot the computer
.

Tags: ,

Formula 1 2010 Begins

Posted on 15. Mar, 2010 by naresh in Formula 1

Formula 1 began today and with a bang and there are a lot of changes. From teams, drivers, points, and much more. It would take at least few races we get to know which drivers perform, but the prancing horse Ferrari is back with a bang, they finished top 2 but i really felt for Vettel who according to me at least should have won, i also felt for Karun as this was his first race. The points system is also a bit changed with the winner getting 25 points for 1st which is good, Waiting till the next race I am listing teams and respective drivers.

Ferrari Fernando Alonso
Felipe Massa
McLaren Lewis Hamilton
Jenson Button
Red Bull Sebastian Vettel
Mark Webber
Mercedes GP Michael Schumacher
Nico Rosberg
Force India Vitantonio Liuzzi
Adrian Sutil
Williams Rubens Barrichello
Nico Hulkenberg
Renault Robert Kubica
Vitaly Petrov
Toro Rosso Jaime Alguersuari
Sebastien Buemi
Lotus Heikki Kovalainen
Jarno Trulli
BMW Sauber Pedro de la Rosa
Kamui Kobayashi
HRT Karun Chandhok
Bruno Senna
Virgin Timo Glock
Lucas di Grassi

Tags:

Cascade Delete with Linq2SQL

Posted on 22. Dec, 2009 by naresh in .net Programming, Blog

Consider this, you have Invoice and Invioce details in 2 tables and the details are referenced by InvoiceId, What happens to Invoice Details once you delete the invoice ?, In SQL atleast you can do cascade delete and also set the value to null, but most real life programs would want to delete the details, Linq2SQL by default tries to set a null value which in most cases fails, and there is no visual way to set this the only way to do this is to do some manual xml editing.
Right click and open the .dbml file with the XML Editor and then navigate to the table for which you want to do this, then look for the relation which references the parent table

<association Name="...." Member="...." ThisKey="...." OtherKey="...." Type="...." IsForeignKey="true" />

Now add DeleteOnNull=”true” to this association so this behaves as expected

<association Name="...." Member="...." ThisKey="...." OtherKey="...." Type="...." IsForeignKey="true" DeleteOnNull="true" />

Tags: ,

Scientists spot nearby ‘super-Earth’

Posted on 18. Dec, 2009 by naresh in Blog, Space

This illustration shows how the newly discovered planet may look orbiting its nearby star, which is smaller than Earth's sun

This illustration shows how the newly discovered planet may look orbiting its nearby star, which is smaller than Earth's sun

Astronomers announced this week they found a water-rich and relatively nearby planet that’s similar in size to Earth.

While the planet probably has too thick of an atmosphere and is too hot to support life similar to that found on Earth, the discovery is being heralded as a major breakthrough in humanity’s search for life on other planets.

“The big excitement is that we have found a watery world orbiting a very nearby and very small star,” said David Charbonneau, a Harvard professor of astronomy and lead author of an article on the discovery, which appeared this week in the journal Nature.

The planet, named GJ 1214b, is 2.7 times as large as Earth and orbits a star much smaller and less luminous than our sun. That’s significant, Charbonneau said, because for many years, astronomers assumed that planets only would be found orbiting stars that are similar in size to the sun.

Because of that assumption, researchers didn’t spend much time looking for planets circling small stars, he said. The discovery of this “watery world” helps debunk the notion that Earth-like planets could form only in conditions similar to those in our solar system.

“Nature is just far more inventive in making planets than we were imagining,” he said.

In a way, the newly discovered planet was sitting right in front of astronomers’ faces, just waiting for them to look. Instead of using high-powered telescopes attached to satellites, they spotted the planet using an amateur-sized, 16-inch telescope on the ground.

There were no technological reasons the discovery couldn’t have happened long ago, Charbonneau said.

The planet is also rather near to our solar system — only about 40 light-years away.

Planet GJ 1214b is classified as a “super-Earth” because it is between one and 10 times as large as Earth. Scientists have known about the existence of super-Earths for only a couple of years. Most planets discovered by astronomers have been gassy giants that are much more similar to Jupiter than to Earth.

Charbonneau said it’s unlikely that any life on the newly discovered planet would be similar to life on Earth, but he didn’t discount the idea entirely.

“This planet probably does have liquid water,” he said.

Tags: ,

Biggest Supernova till date Seen

Posted on 04. Dec, 2009 by naresh in Blog, Space

The biggest star explosion yet seen may be the best known example of a rare type of star death that leaves no “body” behind, astronomers say.

The unusual blast, dubbed SN 2007bi, appears to be a textbook example of a pair-instability supernova, a theoretical type of explosion proposed for very massive stars—those more than 140 times the mass of the sun.

Although most supernovae leave behind black holes or dense stellar corpses called neutron stars, pair-instability explosions would be so intense that the whole star would be obliterated.

Pair-instability supernovae have been hard to spot, however, because stars more than a hundred times the sun’s mass are extremely rare.

Spied in images of a distant dwarf galaxy taken by an automated telescope, SN 2007bi was about 40 times brighter than a typical supernova, and it took about three times longer to reach its maximum brightness.

“Anything that takes that long to rise and is that bright has to have a lot of mass,” said study co-author Peter Nugent, an astrophysicist at the Lawrence Berkley National Laboratory in California.

Hot Core, Unstable Star

Massive stars normally die when they run out of material to sustain nuclear fusion, and all that’s left in their cores is inert iron.

This means the core is no longer producing a steady stream of photons, which in a living star creates outward pressure, keeping the star from being crushed by its own gravity.

Without this stable outward pressure, the star collapses, generating a supernova in which the core gets crunched down to form a black hole or a neutron star.

But for even more massive stellar titans, astronomers think the cores quickly get so hot that their photons start to split apart into pairs of electrons and positrons.

This leads to an instability between the star’s temperature and pressure, sparking a devastating explosion that flings the star’s remains into space.

The star effectively vanishes, although a lingering cloud of expanding gas can remain visible for a while.

Star Explosion

Star Explosion

Pair-instability supernovae were first predicted more than 30 years ago. But evidence from previous candidates—including a bright explosion seen in 1999 and another in 2006—were inconclusive, Nugent said.

By contrast, SN 2007bi seems to fit the bill almost perfectly. If confirmed, studies of the newfound supernova could have major implications for computer models of star formation in the early universe, Nugent said.

That’s because pair-instability supernovae were likely much more frequent in the early universe, when stars with masses several hundred times that of our sun are thought to have existed.

When these megastars exploded, the ancient, powerful outbursts scattered debris that might have sown the seeds for future stars.

A pair-instability supernova “may be a one-in-a-trillion type of event,” Nugent said, “but they may actually be very important” in understanding the evolution of the universe.

Tags: ,

Scientists discover massive ring around Saturn

Posted on 20. Nov, 2009 by naresh in Blog, Space

NASA’s Spitzer Space Telescope has spotted a massive, nearly invisible ring around Saturn.

NASA's Spitzer Space Telescope has spotted a massive, nearly invisible ring around Saturn.

NASA's Spitzer Space Telescope has spotted a massive, nearly invisible ring around Saturn.

The ring’s orbit is tilted 27 degrees from the planet’s main ring plane. The bulk of it starts about 3.7 million miles (6 million km) away from the planet and extends outward another 7.4 million miles (12 million km).

Its diameter is equivalent to 300 Saturns lined up side to side. And its entire volume can hold one billion Earths, NASA Jet Propulsion Laboratory said late Tuesday.

“This is one supersized ring,” said Anne Verbiscer, an astronomer at the University of Virginia in Charlottesville.

Verbiscer and two others are authors of a paper about the discovery published Wednesday in the journal Nature.

The obvious question: Why did it take scientists so long to discover something so massive?

The ring is made up of ice and dust particles that are so far apart that “if you were to stand in the ring, you wouldn’t even know it,” Verbiscer said in a statement.

Also, Saturn doesn’t receive a lot of sunlight, and the rings don’t reflect much visible light.

But the cool dust — about 80 Kelvin (minus 316 degrees Fahrenheit) — glows with thermal radiation. NASA’s Spitzer Space Telescope, used to spot the ring, picked up on the heat.
One of Saturn’s moons, Phoebe, orbits within the ring. As Phoebe collides with comets, it kicks up planetary dust. Scientists believe the ice and dust particles that make up the ring stems from those collisions.

The ring may also help explain an age-old mystery surrounding another of Saturn’s moons: Iapetus.

Astronomer Giovanni Cassini, who first spotted Iapetus in 1671, deduced the moon has a white and dark side — akin to a yin-yang symbol. But scientists did not know why.

The new ring orbits in the opposite direction to Iapetus. And, say researchers, it’s possible that the moon’s dark coloring is a result of the ring’s dust particles splattering against Iapetus like bugs on a windshield.

“Astronomers have long suspected that there is a connection between Saturn’s outer moon Phoebe and the dark material on Iapetus,” said Douglas Hamilton of the University of Maryland in College Park — one of the three authors reporting on the findings in the journal Nature.

Tags: ,

32 planets discovered outside solar system

Posted on 20. Nov, 2009 by naresh in Blog, Space

Thirty-two planets have been discovered outside Earth’s solar system through the use of a high-precision instrument installed at a Chilean telescope, an international team announced.

This artist's rendering shows one of the so-called exoplanets, or planets outside our solar system.

This artist's rendering shows one of the so-called exoplanets, or planets outside our solar system.

The existence of the so-called exoplanets — planets outside our solar system — was announced at the European Southern Observatory/Center for Astrophysics, University of Porto conference in Porto, Portugal, according to a statement issued by the observatory.

The announcement was made by a consortium of international researchers, headed by the Geneva Observatory, who built the High Accuracy Radial Velocity Planet Searcher, or HARPS. The device can detect slight wobbles of stars as they respond to tugs from exoplanets’ gravity. That tactic, known as the radial velocity method, “has been the most prolific method in the search for exoplanets,” according to the European Southern Observatory statement.

The instrument detects movements as small as 3.5 km/hr (2.1 mph), a slow walking pace, the observatory said.

With the discovery, the tally of new exoplanets found by HARPS is now at 75, out of about 400 known exoplanets, the organization said, “cementing HARPS’s position as the world’s foremost exoplanet hunter.” The 75 planets are in 30 planetary systems, the European Southern Observatory said.

“HARPS is a unique, extremely high precision instrument that [is] ideal for discovering alien worlds,” Stephane Udry of Geneva University, who made the announcement on behalf of the international consortium that built the instrument, said in the observatory statement. “We have now completed our initial five-year program, which has succeeded well beyond our expectations.”
HARPS has also boosted the discovery of so-called super-Earths — planets with a mass a few times that of Earth. Of the 28 super-Earths known, HARPS facilitated the discovery of 24, the European Southern Observatory statement said. Most reside in multiplanet systems, with up to five planets per system.

Although only 32 were announced Monday, the team knows of many more exoplanets, although more observation is needed before they are formally announced and papers are written about them. “We have tons of them,” Udry said.

In return for building HARPS, the consortium was provided 100 observing nights per year over five years to search for exoplanets, one of the most ambitious searches ever implemented on a global basis, the European Southern Observatory said.

“These observations have given astronomers a great insight into the diversity of planetary system and help us understand how they can form,” team member Nuno Santos said in the statement.

The HARPS findings confirm the predictions of those who study planetary formation, Udry said. “Moreover, those models are also predicting even more … Earth-type planets.”

An important find for the study of planet formation was that three exoplanets were around stars that are metal-deficient, Udry said. Metal-deficient stars are thought to be less favorable for planet formation; however, planets the size of several Jupiters were found orbiting such deficient stars, the European Southern Observatory said.

In addition, the discovery gives “a very strong push” to projects attempting to find and study such exoplanets, Udry said.

According to its Web site, the European Southern Observatory is the foremost intergovernmental astronomy organization in Europe and describes itself as the “world’s most productive astronomical observatory. ” It is supported by 14 European countries

Tags: , ,

India launches satellite for ocean study

Posted on 04. Nov, 2009 by naresh in Blog, Space

India on Wednesday, September 23rd 2009 launched a second satellite to study oceans. The cube-shaped Oceansat-2 will monitor the interaction between oceans and the atmosphere, as part of climate studies, according to the country’s main space agency. The satellite, launched from India’s southeast coast, carried six nanosatellites from European universities as auxiliary payloads, said the Indian Space Research Organization (ISRO). It also is equipped with two solar panels projecting from its sides, for generating power and charging batteries. India says it has the world’s largest constellation of remote-sensing satellites -16, including Oceansat-2. They produce images for uses such as agriculture, rural development, water resources, forestry and disaster management.

Tags: ,