Saturday, July 14, 2012

an automated build system to refresh and rebuild the dataaccess layer (DAL) for LLBL


 The LLBL gen pro has two command line tools which are :-
CliGenerator.exe for generating code from the command line and CliRefresher.exe for refreshing the relational meta-data from the command line. These tools are available in the LLBLGen Pro installation folder.

We can have an automated  build system to refresh and rebuild the data Access layer (DAL) by:

1) first refreshing: "CliRefresher.exe" 0 "C:\LLBL GEN\myDal.lgp"

2) next rebuilding: 
"CliGenerator.exe" "C:\LLBL GEN\ myDal.lgp" "C:\Visual Studio 2010\Projects\NSA\my.Data.DAL.DLL" 0

3) compiling DAL solution

4) copying DAL dll files to my VS2010 solution. 

 Note that these command line tools are available for LLBL having version 3. onwards.

Wednesday, June 27, 2012

Zooming in, zooming out with mouse scrolling and fit to screen


private System.Windows.Forms.PictureBox PictureBox;
 private System.Windows.Forms.Panel OuterPanel;
 private System.Windows.Forms.ToolStripButton FitToWidthButton;

 private double ZOOMFACTOR = 1.25;   
 private int MINMAX = 5;           
 
Add the following event handler

 this.OuterPanel.MouseEnter += new System.EventHandler(PicBox_MouseEnter);
            this.PictureBox.MouseEnter += new EventHandler(PicBox_MouseEnter);
            this.OuterPanel.MouseWheel += new MouseEventHandler(PicBox_MouseWheel);
   this.FitToWidthButton.Click += new System.EventHandler(this.FitToWidthButton_Click);
       

   private void PicBox_MouseWheel(object sender, MouseEventArgs e)
        {
            if (e.Delta < 0)
            {
                ZoomIn();
             
            }
            else
            {
                ZoomOut();
             
            }
        }
 private void PicBox_MouseEnter(object sender, EventArgs e)
        {
            if (PictureBox.Focused == false)
            {
                PictureBox.Focus();
            }
        }

     
  Zooming Methods

        /// <summary>
        /// Make the PictureBox dimensions larger to effect the Zoom.
        /// </summary>
        /// <remarks>Maximum 5 times bigger</remarks>
        private void ZoomIn()
        {
            if ((PictureBox.Width < (MINMAX * OuterPanel.Width)) &&
                (PictureBox.Height < (MINMAX * OuterPanel.Height)))
            {
                 PictureBox.Width = Convert.ToInt32(PictureBox.Width * ZOOMFACTOR);
                PictureBox.Height = Convert.ToInt32(PictureBox.Height * ZOOMFACTOR);
                PictureBox.SizeMode = PictureBoxSizeMode.Zoom;
             
            }
        }

        /// <summary>
        /// Make the PictureBox dimensions smaller to effect the Zoom.
        /// </summary>
        /// <remarks>Minimum 5 times smaller</remarks>
        private void ZoomOut()
        {
            if ((PictureBox.Width > (OuterPanel.Width / MINMAX)) &&
                (PictureBox.Height > (OuterPanel.Height / MINMAX)))
            {
                PictureBox.SizeMode = PictureBoxSizeMode.Zoom;      
                PictureBox.Width = Convert.ToInt32(PictureBox.Width / ZOOMFACTOR);
                PictureBox.Height = Convert.ToInt32(PictureBox.Height / ZOOMFACTOR);
            }
        }

  private void FitToWidthButton_Click(object sender, EventArgs e)
      {
          if (FitToWidthButton.Text == "Fit to Screen")
          {
              handleFitToWindow(true);
              FitToWidthButton.Text = "Actual Size";
          }
          else
          {
              handleFitToWindow(false);
              FitToWidthButton.Text = "Fit to Screen";
          }
      }
      private void handleFitToWindow(bool doFit)
      {
          try
          {
              /* Don’t perform any operation if no image is loaded. */
              if (this.PictureBox.Tag != null)
              {
                  if (doFit)  /* We’re fitting it to the window, and centering it. */
                  {
                      /* Create a temporary Image.

                      * Always work from the original image, stored in the Tag.
                      */

                      Image tempImage = (Image)this.PictureBox.Tag;

                      /* Calculate the dimensions necessary for an image to fit. */
                      Size fitImageSize = this.getScaledImageDimensions(
                      tempImage.Width, tempImage.Height, this.PictureBox.Width, this.PictureBox.Height);

                      /* Create a new Bitmap from the original image with the new dimensions.

                      * The constructor for the Bitmap object automatically scales as necessary.
                      */

                      Bitmap imgOutput = new Bitmap(tempImage, fitImageSize.Width, fitImageSize.Height);

                      /* Clear any existing image in the PictureBox. */
                      this.PictureBox.Image = null;

                      /* When fitting the image to the window, we want to keep it centered. */

                      this.PictureBox.SizeMode = PictureBoxSizeMode.CenterImage;
                    
                      /* Finally, set the Image property to point to the new, resized image. */
                      this.PictureBox.Image = imgOutput;
                 
                  }

                  else  /* Restore the image to its original size */
                  {
                      /* Clear any existing image int he PictureBox. */
                      this.PictureBox.Image = null;

                      /* Set the resize more to Normal; this will place the image

                      * in the upper left-hand corner, clipping the image as required.
                      */
                      Image tempImage = (Image)this.PictureBox.Tag;
                 
                      this.PictureBox.SizeMode = PictureBoxSizeMode.Normal;
                  
                      /* Finally, set the Image property to point to the original image. */

                      this.PictureBox.Image = (Image)this.PictureBox.Tag;
                   
                  }
              }
          }
          catch (System.Exception e)
          {
              Console.WriteLine(e);
          }
      }

 

Tuesday, May 29, 2012

.NET 4.0 Fails When sending emails with attachments larger than 3MB



SMTPClient class throws "System.IndexOutOfRangeException: Index was outside the bounds of the array." exception while sending mails with attachment file size more than 3MB.
Recently I encounter a bug in .net while testing mail sending feature in our app. Upon little googling, found that it is a bug in SMTPClient class available in .NET 4.0.

Check below link for details of the bug:
https://connect.microsoft.com/VisualStudio/feedback/details/620785/important-bug-system-net-mail-smtpclient-send-mailmessage-causes-index-was-outside-the-bounds-of-the-array-because-of-the-content-of-an-attachment?wa=wsignin1.0

http://stackoverflow.com/questions/9703675/random-index-was-outside-the-bounds-of-the-array-as-an-smtpexception

Below is the link for Hot fix for .NET Framework to fix this issue:
https://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=30226




Wednesday, May 16, 2012

Using XML path to get the emailaddress of contacts


 CREATE TABLE #Email
            (
              FKGUID UNIQUEIDENTIFIER,
              EmailAddress VARCHAR(2500)
            )  
               
        CREATE TABLE #EmailAddressTable
            (
              EmailAddress VARCHAR(2500),
              IsDefault INT DEFAULT ( 0 ),
              FKGUID UNIQUEIDENTIFIER
            )  


  INSERT  #EmailAddressTable ( EmailAddress, FKGUID )
                                SELECT   EmailAddress ,
                                        EmployeeGUID
                                FROM    dbo.Employee


 INSERT  #Email
                SELECT  fkGUId,
                        SUBSTRING(( SELECT  ',' + s.EmailAddress
                                    FROM    #EmailAddressTable s
                                    WHERE   ISNULL(s.EmailAddress, '') != ''
                                            AND a.FKGUID = s.FKGUID
                                    ORDER BY s.EmailAddress
                                  FOR
                                    XML PATH('')
                                  ), 2, 200000)
                FROM    #EmailAddressTable a
                WHERE   ISNULL(a.EmailAddress, '') != ''
                GROUP BY a.FKGUID

The temp table #Email contains all the email addresses of each employee.



Saturday, April 21, 2012


Is Silverlight dead?
Microsoft has recently released Silverlight 5 though it is moving away from Silverlight to HTML5. So, is this the last release of SilverLight?The big question is "Is Silverlight dead?"
Silverlight is a browser plugin which works well on a desktop environment. But as we are now in the world of smart phones/tab devices where plugins are considered as evil, Silverlight would have hard time to survive.Though silverlight is cross platform but only for desktop environment. As we are now in the world of smart phones/tab devices, the meaning of cross platform solution has changed. HTML5 is the true cross platform solution for everything. So, it might be good to consider HTML5/css3.

Monday, April 16, 2012

Integrating Security into Development, No Pain Required

Integrating Security into Development, No Pain Required
Sponsored by IBM

Developers and security have traditionally been like oil and water. For developers, their key concern is making deadlines and enabling new lines of business. Meanwhile, the state of coding flaws, bug announcements and undiscovered zero day vulnerabilities are driving most security professionals to the brink. While both groups know they should be working together to improve code, development processes and application management, this type of coordination is still the exception rather than the norm.

Read more on clicking the link below.
http://www.sans.org/reading_room/analysts_program/ibm-appsec.pdf

Thursday, March 8, 2012

How to get the full-text search working for Office document (docx) in SQL Server


Run the following query in SQL Server Management Studio.

SELECT document_type, class_id,[path] FROM sys.fulltext_document_types

WHERE document_type = N'.docx';

SELECT *

FROM TableName

WHERE FREETEXT(*, 'ram') and filetype='docx'

If the free text is not giving the result for documents(docx), then download the Microsoft Filer pack from the following links.

Microsoft Office 2007 Filter Packs

http://www.microsoft.com/downloads/details.aspx?FamilyId=60C92A37-719C-4077-B5C6-CAC34F4227CC&displaylang=en


Microsoft Office 2010 Filter Packs

http://go.microsoft.com/fwlink/?LinkId=179530

1. Download and install Microsoft Filter Pack,

2. Enable IFilters, and then run the following command in that instance:

sp_fulltext_service 'load_os_resources', 1

3. Restart the SQL Server service.

4. Refresh the document Catalog of the database.

5. Disable and Re-enable the Full Text Index of the table.

For more information, please see

How to register Microsoft Filter Pack IFilters with SQL Server 2005 and with SQL Server 2008

If you had registered, I think we need to verify whether the file name extension correct.