Creating a .NET class file from a WSDL

by Kyle Ballard 11/1/2009 4:13:59 PM

A common approach when adding a web service to an ASP.net application, is to right click "Add Web Reference" and specify the path of the WSDL which outlines the interface for the service.   An alternative, and relatively simple to accomplish, alternative to this approach is to create a class that represents the xml contract outlined in a WSDL (Web Service Definition Language) file.   This WSDL could be stored locally, or specified via a full URL.  This is accomplished by using the wsdl.exe command line utility.  

The WSDL.exe command is available in the following path:
C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\wsdl.exe

An simple example use of this command is:
wsdl.exe /out:WeatherService.vb /l:VB http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl

A full description of the wsdl.exe command line utility is available here: 
http://msdn.microsoft.com/en-us/library/7h3ystb6(VS.80).aspx

There are many advantages to this, including but not limited to:

  • Achieving better understanding of underlying system calls to service
  • Including an audit/trace of service calls easily
  • Examining data being transmitted and received
  • Programmatically specify a sandbox/production URL interchangeably (this I find frequently useful)

I hope this helps in your programming endeavors, it has certainly helped me.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Palm Developer Community Site Navigation

by Kyle Ballard 9/24/2009 9:37:00 AM
Based on a recent forum posting The community site needs better navigation, forum member Snapperfish put together this very useful document. I have posted it here for easy reference.
 

Developer Guide

Application Basics
Application Basics Covers basic application structure, configuration, lifecycle, scenes, stages and assistants.
Launch Cycle Examines the lifecycle of an application from launch through the details of pushing and popping scenes
Application Lifecycle A look at the installation, launch, execution and removal of an application
Events Mojo leverages the DOM event model and extends it with custom Mojo events and methods
Storage The HTML 5 Database object is supported by webOS, along with the Mojo storage objects: Depot and Cookie
All About Widgets
Anatomy of a Widget Defines the basic organization of an application and the function of the configuration file and each of it's properties.
Buttons and Selectors Overview of the Button, CheckBox, ToggleButton, RadioButton, ListSelector, and Slider widgets.
Dialogs and Containers Covers showDialog, showAlertDialog, and showErrorDialog functions, and Drawer and Scroller widgets.
Indicators Overview of indicators; describes the Spinner and the ProgressPill, ProgressBar, Progress, and ProgressSlider widgets.
Lists Overview of the List widget and FilterList.
Media Objects
HTML 5 compliant objects for embedding video and audio.
Menus Describes Menu functions and handlers, including AppMenu, Command Menu, View Menu, and Submenu.
Pickers Describes Pickers, including Date, Time, Integer, and the FilePicker application.
Text Fields TextField, PasswordField, FilterField, and RichTextEdit widgets are described here.
Viewers

Describes Web and Image viewers.

Services Describes webOS services design and access methods; summarizes the service offerings and indexes reference documentation.
Advanced Applications
Multi-Stage Applications Describes the Application Assistant in detail and how to build noWindow applications and applications with stages.
Dashboards and Notifications Provides detail examples on usings Dashboard windows and both banner and popup notifications.
Background Applications Explains how to work in the background and the proper behavior for both minimized and background applications
Internationalization and Localization Review of internationalization features and localization techniques.
Tips and Techniques
Animation Tips Some basic information regarding animations.
appinfo.json The appinfo.json file is located in the root of the application folder. It is a JavaScript file containing a JSON object that defines key configuration options for the application.
Application Loading Detailed walk-through the sequence of events and actions when loading an application.
Canvas Tag Support Some support for the HTML5 Canvas tag is included, but not all features are supported.
Commander Chain Review of the commander chain. How it works, how to manage it, and common techniques.
Creating a List Creating a list where each item contains an image and text.
Creating Widgets in JavaScript Brief description about how to create widgets dynamically without using HTML.
Developing Palm webOS Browser Content Compatibility information and things that a website designer might want to know.
Escaping HTML in Apps Comments about how to escape HTML content within webOS apps.
Event Handlers How to safely set up listeners and stop listening.
framework_config.json An optional configuration file for some very useful developer aids, including logging, debugging features, and timing reports.
Initialization and Allocations Tips for making your variable initializations and memory allocations more efficient.
Lightweight Stages Lightweight stages save up to 4 seconds on the time it takes to open, and reduces the amount of memory it consumes to a small fraction of a heavyweight stage.
Logging How to set up logging in your app. Covers the use of the framework_config.json file, and discusses Mojo.timing, which adds timing statistics to the framework for scene transitions.
Media Extensions To support extended Web browser features, Palm added extensions for HTML5 media objects, including a .palm sub-object to the Audio or Video objects.
Smart Text Features Mojo™ includes support for smart text replacement for AutoCaps and common mistyping. This page tells you how to control these features.
UI-SysMgr Statistics Get information on runtime statistics for your card on image sizes, and DOM and Render nodes used.
Web View Indicator How to add a page loading indicator to your webView widget.

API Reference

APIs
Mojo.Animation Holds the infrastructure for coordinating timers for multiple animations, and animating DOM element styles and numeric values over time.
Mojo.Asserts & Requires Contains some methods to debug your applications and other utility functions (e.g., assert, require, loadScriptWithCallback, etc.).
Mojo.Char Holds character code values and some useful key code checking methods.
Mojo.Controller Controller functions designed to assist in managing stages and scenes.
Mojo.Cookie Creates a cookie object with a particular name.
Mojo.Depot Stores JavaScript objects in a database. Currently implemented as a framework wrapper around HTML5 active record access.
Mojo.Drag Creates container destinations and draggers for drag and drop items.
Mojo.Event Holds functionality related to the UI Toolkit Events.
Mojo.Format Functions related to formatting dates, times, and numbers.
Mojo.Function Used to "debounce" multiple calls to a function.
Mojo.Function.Synchronize Used to ensure that a set of callback functions are all called at the same time.
Mojo.Log Provides an efficient way to output interesting information from a running application, but not have it slow down the application.
Mojo.Model Contains helper functions for dealing with data in a JSON object.
Mojo.PatternMatching Contains helper functions for matching some common device API's when filtering or when getting data back. Does highlighting of matched filter text for contacts per the HI spec; also does matching of address types to their display string.
Mojo.Service An on-device "server" for any resource, data, or configuration that can be exposed for developers to use with their applications.
Mojo.Timing Controls for timing.
Mojo.Transition Contains public constants for the graphical transitions usually used for pushing and popping scenes.
Mojo.View All UI layout files are located in the views folder of your application. Much of the user interface in the SDK is assembled out of text files containing fragments of HTML and special tags indicating locations to insert dynamic data.
Mojo.Widget The actual widget implementations are "widget assistants" in the various widget_*.js files, and common widget behavior is mostly encapsulated in widget_controller.js.
Widgets
Button Pushbutton with optional activity indicator and callback.
CheckBox Simple bi-state checkbox.
DatePicker Provides UI for selecting a date.
Dialogs General Dialog function with specialty functions for alerts and errors.
Drawer A container that toggles between a hidden or shown view.
FilePicker Provides UI for selecting a file from the available files on the device.
FilterField A text field design for acting as a filter on application-specific data.
FilterList A filter field integrated with a list.
ImageView Views an image full screen with support for zooming and panning, with an option to scroll to other images.
IntegerPicker Provides UI for selecting a number from a range.
List The main list widget for editable, static, and dynamic lists with many options.
ListSelector Provides a multiple-choice pop-up selector.
Menu Functions for setting up and responding to the App, Command, and View menus.
PasswordField A special TextField for password entry.
ProgressBar Progress indicator using a bar graphic background.
ProgressPill Progress indicator using a View menu style background.
ProgressSlider Progress indicator integrated with a Slider widget; useful for streaming data indicators.
RadioButton Multiple choice selector in the form of a button array.
RichTextEdit A TextField with support for rich text editing.
Scroller Apply horizontal and/or vertical scrolling to a DIV's contents with snap options.
Slider Selector for a numerical range of values in the form of a horizontal slider.
Spinner Activity indicator that is manually started and stopped.
TextField The main text entry and edit widget with many options. You can combine this into forms.
TimePicker Provides UI for selecting an Email, IM, or other address from a contacts list.
ToggleButton Provides UI for selecting a time setting.
WebView Embeddable Web view for use within a scene.
Services API
Accelerometer Orientation events and accelerometer data access.
Accounts Returns information on established user accounts for use with the Palm® Synergy™ information manager.
Alarms Sets a timer to activate on the device either after a specified interval or at a specified date and time.
Application Manager Invokes default handlers for the common resource types or basic device operations.
Audio Plays or streams audio by using common audio formats.
Browser Loads and views the target specified by a URL.
Calendar Various methods for accessing or creating Calendar data.
Camera Launches the Camera application to take a picture.
Connection Manager Gets connection status and subscribes to notifications of connection status changes.
Contacts Various methods for accessing or creating Contacts data.
Document Viewers Launches the DocViewer application to browse and view common document file types.
Email Sends an email, and includes options for pre-populating the email contents.
GPS Gets the current location coordinates and registers for continuous updates.
Maps Displays a map based on the various input options.
Messaging Sends an IM/SMS/MMS, and includes options for pre-populating the message contents.
Mojo Messaging Service An XMPP-based service to asynchronously send requests, information, and content to cloud-based recipients.
Phone Makes a phone call with or without a pre-populated dial string.
Photos Views an image in various common image formats.
System Properties Gets the named system properties, including device ID.
System Service Accesses various system settings, including systemTime.
System Sounds Plays audio feedback in response to user interaction. The sounds play when the message is played, with low latency.
Video Plays or streams video by using the common video formats.
View File Downloads and/or views a file in various formats or resource types.

User Interface Guidelines

User Interface Summary Summarizes how to plan and create the UI for your application.
Web Design Guidelines Describes the platform services design and access methods; summarizes the service offerings and indexes reference documentation.
Styles and CSS Reference Describes widgets, how to instantiate, set up, and use any widget; summarizes the widget set and indexes reference documentation.
Human Interface Guidelines A complete guide to designing webOS applications (PDF).

FAQ and Resources

Getting Started Start here to get the latest Palm® Mojo™ SDK and tools.
Common Questions FAQs and help.
Release Notes Latest SDK Release Notes.
Glossary SDK terms defined.
Index Alphabetical listing of articles.
Terms of Service
End-user license agreement.
References

Videos

JavaScript video lectures Presented by Douglas Crockford, senior JavaScript architect at Yahoo!®, known for his work on JSON. The link is to a blog that links to the videos and also provides details summaries and comments about the content.
Yahoo UI Theater Some excellent presentations by Web architects and JavaScript gurus.
Steve Souders blog Steve Souders is the head of site performance at Yahoo. Very good info.
High Performance Web Sites Includes a link to Steve Souders' "High Performance Web Sites: 14 Rules for Faster Pages" video.
Google Expo Slides Power point slides for the Performant website.
Alphabetical Directory of Linux Commands For users new to Linux, an alphabetical directory of Linux commands is provided by O'Reilly®.

References

W3 Schools Our references cover all Web-building technologies, including W3C standards like HTML, XHTML, CSS, XML. They also detail other technologies like JavaScript, PHP, ASP, SQL and much more.
Google Doctype Google? Doctype is an open encyclopedia and reference library. Written by Web developers for Web developers, it includes articles on web security, JavaScript DOM manipulation, CSS tips and tricks, and more. The reference section includes a growing library of test cases for checking cross-browser and cross-platform compatibility.
Prototype Featuring a unique, easy-to-use toolkit for class-driven development and the nicest AJAX library around, Prototype is quickly becoming the codebase of choice for Web application developers everywhere.
Scriptaculous script.aculo.us provides you with easy-to-use, cross-browser user interface JavaScript libraries to make your websites and Web applications fly.

Eclipse

If you are new to Eclipse, review An Introduction to Eclipse for Visual Studio Users on the IBM® DeveloperWorks website.

Articles

Unobstructive Javascript Validation Information on unobstructive JavaScript validation.
An introduction to JSON Introduction to JSON.

Blogs

Ajaxian AJAX development community blog.
Planet Ajaxian Planet Ajaxian is your one stop shop for all AJAX content.
Steve Souders' blog Steve Soulders is the head of site performance at Yahoo.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: ,

An argument against Amazon's Kindle

by Kyle Ballard 5/26/2009 3:58:00 PM

I subscribe to a lot of magazines.  I'm kind of a junkie for being able to read a paper copy of materials, and I find my eye strain is a lot lower when reading from print.   As a result, I'm excited about the possibility of owning one of Amazon's Kindle devices and not having to lug 10 magazine issues around with me.   That was until I did some searching and found this.

Print magazines run a lower cost than their electronic counterpart!    How much does it cost to print, distribute, and mail each individual issue?   How much does it cost to electronitcally distribute.

Here is the Amazon listing for the print version of Fortune magazine:



And here is the same magazine in Kindle format:



It is 35 cents more expensive per month ($1.15 vs. $1.50), or roughly $4.50 more per year to get the electronic version than the print version.  

I'm sure there is some reason this is being done, but one thing is for sure, it has nothing to do with the fact that it costs more to distribute electronically, and that irritates the hell out of me.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Becoming a Technical Leader: Book Review

by Kyle Ballard 5/2/2009 2:34:23 PM

0932633021

It's no secret that I am a big fan of Dale Carnegie's - How to Win Friends and Influence People, and this book extends upon the principles in Carnegie's book and applies them directly to any technical job. 

Personally, I would still advise reading Carnegie's book first as a business book, but if you have read that already and are looking to further your development as a leader, this book does a great job at applying a more niche approach to the concept of leadership.  The subtitle of the book is "An Organic Problem-Solving Approach".   I would agree with that assessment.  Gerald Weinberg, the author, does a great job at outlining the differences between a technical leader position, and a traditional management position, and is probably one of the very few books out there who tackle those topics.

 

The book begins by outlining the concept of a leader, what it takes to be a leader, and how leaders develop their character.  He uses several analogies, such as his youthful experiences with a pinball machine, through the ravines and plateaus to which adjustments to his game where made, to outline how his later career as a technical leader would develop. 

The leadership overview segueways into the topics: motivation, innovation, and organization which guide the central theme of the book.  He recommends keeping a daily 5 minute journal (which I have done, and agree is a great idea), notes it is important to recognize that self-confidence is a pre-requisite for success, and he also talks about the trade-offs between technical ability and leadership ability, and how to successfully motivate others.

The final chapters of the book outline the transformative process by which technically able people become leaders.  How to handle other people, who can and will, challenge your leadership, as well as finding time to continually change and improve yourself as a leader to maintain your position.  The ability to lead in the technical field requires continual movement and improvement, without which, one will fall by the wayside.

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Code Complete 2: Book Review

by Kyle Ballard 4/29/2009 7:40:00 AM

 

This book is the de-facto standard for best practices as it relates to source code and programming. User ratings and industry leaders will also concur, that this book, now in it's second edition leads the pack as a guide.

The book is a long read, but it is by no means simply a filler to increase the weight of the book. Each chapter is significant and important in it's own way.

Every programmer upon entering the workforce should receive a copy of this book, at a minimum, because it paves the way for your career and sets you on the right path with ideal guidelines for good programming practice. I'm sure others who have read the book feel this strongly about it also. 

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Vacation, Random Thoughts, and Bookmarks

by Kyle Ballard 3/15/2009 1:00:52 PM

Just got back from vacation.  Cubs spring training, city touring in San Francisco, and wine tasting in Sonoma.  It was quite an experience, but I feel at the end of the trip I needed a vacation from my vacation.  Anyone who has been gone for any extended period of time probably knows exactly what I mean.  Danielle and I took some great photos, which I will be posting on my Facebook account shortly.  I was amazed by the weather and feeling of being at the ballpark in Arizona (we even hiked camelback mountain), and also enjoyed my second trip to SF.  Last stop was Sonoma, and I have always been a wine novice, but now feel like I am a wine beginner.  Who knew there was so much science behind the process of making a beverage?

Some changes for me at work, which I haven't had time to write about are that I picked up a Herman Miller Mirra chair, switched Visual Studio into a black background, and have decided to familiarize myself with the DotNetNuke5 project so I can hopefully move my small college alumni project into other universities as well.  We'll see how that goes.

How to Link Facebook to Twitter
I have been putting this off for some time, and once I realized how simple this was I took care of it in 5 minutes.  Great, easy to follow tutorial.
http://www.ajvaynerchuk.com/how-to-link-twitter-to-facebook-a-twitter-tutorial/

We Follow
Simple premise for this site is just an aggregator that lists the most popular twitter uses and categorizes them by tag, # of followers, etc.
http://wefollow.com/

TechCrunch's 60 second "elevator" pitches
Need some inspiration, I find a good amount here watching other's foster their ideas and getting feedback.
http://pitches.techcrunch.com/

Photoshop Phriday
I have always enjoyed the photoshop collections which get posted on digg.com as a way to entertain myself, and a friend pointed me to this site which I have apparently missed under the radar.  A new collection is posted every friday.
http://www.somethingawful.com/d/photoshop-phriday/

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

ItemDataBound in a Nested Repeater

by Kyle Ballard 1/24/2009 7:21:29 PM

Something I struggled with early in my ASP.net development was how to handle ItemDataBound event (or any repeater event) when it was inside another repeater in the code behind logic.  I am presenting my code here so that it may be of use to anyone else having the same problem.

 

Given MyPage.aspx

<asp:Repeater id="rptMyOuterRepeater" runat="server"> 
<HeaderTemplate> 
  <h1>My Repeater</h1> 
</HeaderTemplate> 
<ItemTemplate> 
  <asp:literal id="ltlCategory" runat="server" /> 

  <asp:Repeater ID="rptMyInnerRepeater" runat="server"> 
  <ItemTemplate> 
     <asp:Literal ID="ltlItem" runat="server" /> 
  </ItemTemplate> 
  </asp:Repeater> 

</ItemTemplate> 
</asp:Repeater>

 

Given MyPage.aspx.vb

' **** Please note functions CategoriesDataLayer.GetList() And ItemsDataLayer.GetCategories(CategoryId)
' ****   are used for demonstration only.  You may use any collection of data (datatable, collection, etc)

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    rptMyOuterRepeater.DataSource = CategoriesDataLayer.GetList()
    rptMyOuterRepeater.DataBind()
End Sub

Protected Sub rptMyOuterRepeater_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs) Handles rptMyOuterRepeater.ItemDataBound
    ' Exit function if this is not in ItemTemplate
    If Not e.Item.ItemType = ListItemType.AlternatingItem AndAlso Not e.Item.ItemType = ListItemType.Item Then Exit Sub

    Dim rptMyInnerRepeater As Repeater = e.Item.FindControl("rptMyInnerRepeater")
    rptMyInnerRepeater.DataSource = ItemsDataLayer.GetItemsByCategory(e.Item.DataItem("CategoryId"))
    AddHandler rptMyInnerRepeater.ItemDataBound, AddressOf rptMyInnerRepeater_ItemDataBound
    rptMyInnerRepeater.DataBind()

End Sub

Protected Sub rptMyInnerRepeater_ItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
    ' Exit function if this is not in ItemTemplate
    If Not e.Item.ItemType = ListItemType.AlternatingItem AndAlso Not e.Item.ItemType = ListItemType.Item Then Exit Sub

    CType(e.Item.FindControl("ltlItem"), Literal).Text = e.Item.DataItem("ItemName")
End Sub

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

SQL Server 2005 Database Design & Optimization

by Kyle Ballard 12/27/2008 7:38:16 PM

The following are some basic design guidelines to use when implementing a SQL 2005 database.

1.  Enforce foreign and unique key constraints.

Foreign and unique key constraints will maintain your database integrity.  Think of it as insurance against orphaned records and duplicate data.  If you know a column is to be unique, or a relationship to another table, entering it as a constraint can be one way for your database to police your application and catch errors early on before they become a problem.

 

2.  Identify poorly performing queries and optimize them.

SQL Profiler is a great tool and provides access to meaningful data regarding the execution time and resources required to run each of your queries.  As a general rule, I try to weed out queries which take over 200 milliseconds to execute.  This may seem like a small amount of time, but when you have an large number of visitors (such as after an email blast) this can quickly become a bottleneck.  SQL Profiler can be setup to track all queries executing over X number of milliseconds, X number of reads, and you can target specific databases so it returns only the data you are looking for. 

Performance inefficient statements (LIKE, IN, NOT IN, DISTINCT) can (and probably should if possible) be rewritten using proper join operations, using EXISTS, or using temporary tables in multiple SQL statements.  This will reduce the number of reads and ultimately decrease the time to return the data you are requesting.

 

3.  Use non-clustered indexes.

Using indexes is not an exact science.  It requires a calculated effort to ascertain the advantage of using the index versus the impact which will be incurred when updating, inserting, or deleting records.  A good rule of thumb is to index foreign keys as these columns are often used frequently when performing joins on tables.  Other good candidates for indexes are columns used for data ordering ("order by") and columns used in frequent look-ups (filtering fields).

Additionally, any administrative reports which contain filtering options should be considered candidates for indexes, especially if the table has 500,000 records or more.  Be careful though, to be aware that admin reporting is used exponentially less than the table data on the front-end of the website.  Try to weigh the benefits of each, and never place a filter field for a table that has millions of records without an index.  Scanning every row in a database for a certain value is a performance nightmare.

Lastly, be careful not to cover the entire table with indexes.  Every index added results in an increase of performance when reading data, but every index also carries with a performance hit when updating, deleting, or inserting data

 

4.  Use clustered indexes.

A table is ordered physically (on the file system) by the clustered index.  As a result, it is by far the most optimal way to search for data in the table.  In a common e-commerce example, if you have order headers, shipment recipients, and line items as 3 separate tables, then each may be joined together by the OrderId column.  Making the OrderId column the clustered index, instead of the LineItemId column in the LineItems database table would make sense logically if you were always pulling data from the LineItems table using the OrderId.  Additionally, if you wanted to pull an single record from the LineItems table, if you were to specify the LineItemId in conjunction with the OrderId, your query would execute very fast in that case also since you were aware of the OrderId at the time of the lookup.

 

5.  Avoid using wildcard characters on the left side of an indexed column.

If you have an index on the field "FirstName" but you perform a look-up on that column using wild-card characters on both sides of a lookup value, then you are negating that index (ex: WHERE FirstName LIKE '%yl%' OR FirstName LIKE '%yle').  In this case, you could think of the index like the first few letters of each persons name at the top of the phone book.  If you start at the beginning, then you know to look, but if someone says that this is the middle of the name, or the end, then you won't be able to use that index to lookup the person in the phone book.  The database indexes in a similar fashion, so be aware when using wildcard characters.
(Note:  SQL 2005 may still use an INDEX SEEK, but it is unlikely that will happen when a wildcard appears as the first character in the LIKE clause).

 

6.  Avoid using SELECT * whenever possible.

SQL server database records are logically ordered on the file-system in 8kb chunks.  Any data over that 8kb is stored in what is referred to as an "Overflow page".  At the end of the 8kb page, there is a 16 byte pointer to where the overflow page data is stored (think 'text', varchar(max), etc).  When you use SELECT * to retrieve all columns, the overflow data must also be retrieved as part of the query and as a result, the performance is impacted.

 

7.  Periodically de-fragment your indexes.

Indexes could theoretically be thought of like a fragmented hard drive.  When you create the index the first time, everything is neatly ordered and compact for quick access.  Over time however, indexes become fragmented through deletes, updates, and inserts.  Gaps find their way into the index and the CPU has to work harder to lookup the data being requested.

It is good practice to run DBCC SHOWCONTIG as a command on a recent backup of your database.  When executing this command you will see data returned about the indexes currently active in your database.  As a rule of thumb, look for indexes which have a page count > 10,000 and  (logical scan fragmentation > 20% or avg. page density < 60%).

You have three options available to de-fragment your indexes. 

  • DROP INDEX and CREATE INDEX to re-create indexes
  • DBCC DBREINDEX - Offline operation, table is unavailable when this command is running on it.  Atomic transaction, passes or fails.  Defragments all indexes on a table.
  • DBCC INDEXDEFRAG - Online operation, database can continue to function when running.  Can be stopped at anytime.  Defragments one index at a time.

Provided below is a chart showing the performance of each method.  

http://www.microsoft.com/library/media/1033/technet/images/prodtechnol/sql/2000/maintain/ss2kbp09_big.gif

8.  Use consistent naming conventions.

I don't think there is a universal rule against a certain type of convention (plural vs. singular table names, etc), but maintaining consistency will aid in your development.  Having to keep referring back to your database to see if your column is named Desc, Description, Descrptn, etc. will prolong your develop as will having to check if a table is StoreItem or StoreItems, etc. 

 

9.  Maintain the database.

Writing a simple task (i.e.  SystemMaintenence.exe) which periodically purges old un-useful data, removes leftover image files, and generally tidies up the system is a good process to use to ensure your site is running as efficiently and effectively as possible.   If done properly, you could be removing loads of unused data, which in turn allows your system to operate at an optimal level.  Even moving data out of commonly used tables into 'Archive' tables where it won't be accessed as frequently offers performance gains.

 

10.  Don't abuse the cache.

Some people may disagree with me on this, but I would recommend not using caching at all until after a project has been live for a while and the performance bottlenecks have been identified.  Famous computer scientist Donald Knuth was quoted as saying "We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil.".  Many developers spend hours and hours pouring over code in a pre-release format looking for ways to optimize the code.  I personally believe that if you do your best to write it well the first time, and take the time to write it properly, then any necessary re-factoring or optimization can be done once the bottleneck is identified.

Additionally, I see many developers who have a tendency to cache as much data as they can without realizing that this cache data has to be stored in the server's physical memory.   If that wasn't bad enough, the system may periodically remove data from the cache if too much data is stored in the cache so that the system can continue operating properly.  Relying on the cache as a crutch for poorly designed queries/code is not a good approach to development.  However, using caching mechanisms properly,  and conservatively, is effective, especially if you are using it to address a performance problem which has presented itself in production code.

 

11.  Use the SqlBulkCopy class.

SqlBulkCopy should (in my opinion) always be used when inserting data over a couple of hundred records.  I have used this class in numerous projects in the past and it can handle tens of thousands of records in just seconds.  It doesn't take long to use, and when reading data from your data source you can perform all your necessary computations before storing it in the in memory table (which will later be sent to the server).  Another method, would be to load everything into a temporary table, and then perform the necessary T-SQL on that temporary table to move the data into your application.  I've used for this moving data from an old system to a new one, reading customer uploaded .csv files before processing them in the system, and taking large files off an FTP account for processing.  I honestly can't think of a good reason to not use this when dealing with any reasonable amount of data.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

7 Healthy Habits of Highly Effective Web Workers

by Kyle Ballard 12/2/2008 9:24:56 PM

I doubt Steven Covey will ever read my blog post, but I'm glad you found your way here.  Presented below, is my best effort, to provide you with the concepts that have worked for me.  All these suggestions, are merely suggestions, but they have worked well for me, so I am sharing them with you.

1.  Exercise

If it seems obvious, and not a secret, well, that is because it isn't.  If you exercise an hour a day, you will lose weight, have increased energy levels, and a decrease in health problems.  You will be more confident, reduce your daily stress, and find yourself with deeper affection for those friends and family who are around you. 

I understand it can be a challenge to be motivated to exercise when there are a hundred other things on your plate: work, kids, wife, friends.  You might think to yourself, 'Hey! I'm too busy to work out'.  Think of it as insurance on your number one possession: your health.  High blood pressure, high cholesterol, and stress all result in a number of very undesirable effects to your health like heart attack, stroke, diabetes, and on an on.  An hour a day may seem like a lot, but try not to think of it that way.  Think of it as investing an hour in your day to maximize the other 23 hours of your day, and insuring your body against the negative elements so you can live out your golden years writing code, reading books, or spending it with your grand-kids.  Work hard enough at it, and you could even live out your retirement running marathons.

It can be daunting to start an exercise program, and there will be days you don't want to drag yourself out of bed.  Commit yourself to just doing something, anything, when it comes time to your exercise.  If you planned to run for an hour, and you really aren't feeling up to it, commit to just going for a 30 minute walk.  Hey, at least you did something right?  Just committing yourself to living a healthy lifestyle is an important step to your overall health and a determining factor on how effective your efforts are.

Exercise is a great investment in yourself and your number #1 asset: your health.  As an added bonus, you'll have a more productive work day, find yourself feeling more relaxed, and having more energy to get through those marathon coding sessions or play with your kids.

2.  Eat right

I'm from Chicago, and we have more steak houses, fast food establishments (like the infamous Portillo's), and bars than I care to admit.  It can be very, very tempting to eat unhealthy.  You could be nervous about being mocked by your friends and colleagues for eating a salad, have a stressful day and use food to relieve the stress, or you could simply not have any other alternatives around you.

Unfortunately, there are plenty of good reasons why people choose not to eat healthy, however of those good reasons, there are no reasons good enough to justify damaging your health.  Eating large amounts of high calorie, high fat food produces unhealthy blood sugar levels, increases stress, and ultimately results in lower energy levels.  We all know what that post-Thanksgiving food coma feels like. 

Simple strategies like keeping unhealthy food out of your house/apartment, office, and car are a great first step.  Another wonderful strategy is to keep healthy snacks in your desk.  Freeze dried fruit, natural granola, pretzels, and others will help you stave off those desires to gorge yourself on a double cheeseburger and fries because you are so hungry your stomach hurts by the time lunch hour arrives.  Many offices have quick access to stores which sell fresh fruit and vegetables.

It can be hard to go for a long time without eating unhealthy, but you will find that the longer you go eating healthy, the easier it becomes.  It will, as strange as it sounds, actually become easier to eat healthy than to eat unhealthy.  Your body will have a strong reaction (upset stomach, acid-reflux) to unhealthy foods if you go long enough without them and just the thought of going through that will have you wanting to avoid that feeling altogether.

3.  Healthy Sleep

I could say sleep 8 hours, sleep 9 hours, sleep 7 hours, but I think everyone is different.   Work works for you may not work for someone else.  The important thing is to not oversleep and not sleep too little.  Your body simply will not function effectively if you do not get the correct amount of sleep.  You will make more mistakes, become more irritable and find it harder to make the right decisions about your health (drinking too much caffeine to stay awake, making poor food choices).

Just trying to get into a routine, as boring as that sounds, can have you rising with an increased energy level each day.  For me, it's bed at 10 and up at 6.  Does that ever change?  Sure it does.  I go out with friends, hit up a late night movie, but overall I try to stick to that as close as I can.  Nothing really good ever happens after 10pm, and 6 is the perfect time for me to get my workout in before heading to work.

I understand this can be hard with kids, and with those who travel frequently, but the bottom line of it all is getting a good amount of sleep is simply important to your overall health.  You will be more productive, alert, and ready to face the day when you have had the right amount of sleep.

4.  Moderation

All things in moderation.  I'm sure you've heard that before.  Have a drink or two and you'll feel fine at work the next day.  Get sloppy drunk and you will feel miserable, make poor eating choices, skip your exercise, and not get a good nights sleep.   Split a small piece of cheesecake with your friend/significant other on a special occasion and it gives you a reason to celebrate and enjoy a great tasting food item, but have McDonald's for breakfast lunch & dinner and you'll end up feeling like Morgan Spurlock.

Having a glass of really good tasting wine can have you really appreciating the work that went into producing that drink, or having a really good desert item on a rare occasion can have you really have your taste buds savoring that flavor.  Drink every day, watch television for hours, play video games for hours, or doing anything in excess and you will find yourself losing track of what really drew you to that in the first place. It loses it's value and ultimately its enjoyment.

The basic premise is, enjoy the finer things in life, but don't abuse them because then they lose their value.  Addiction isn't something to be taken lightly, and this blog is no substitute for professional medical advice, which I encourage you to seek that advice if you feel you have a problem battling an addiction. 

5.  Spirituality

I'm sure I'll be ostracized to some extend for including this suggestion, however I am very open about my faith.  I'm a Christian, however I am not the same Christian you see on television giving the rest of us a bad name, picketing funerals, and generally acting like someone who just got the wrong information about what it meant to be a Christian.  I encourage others to read the bible, and attend church, but I don't force my beliefs on anyone else.  I don't feel that is the right way to approach life and it certainly gives organized religion a bad name when others act that way.

That being said, I did title this subject 'spirituality' because regardless of your beliefs:  Christian, Catholic, Muslim, Jewish, or simply those who are enlightened spiritually, I find that connecting with those around me, donating my time to a worthy cause, and simply praying all give me piece of mind and put things in perspective for me. 

Going to church puts my life in check, and keeps me on the right track mentally.  Hearing prayer requests for those who are struggling with medical conditions, family problems, or drug addictions helps you become more comfortable with your own mortality, be grateful for what you have in your life instead of focusing on what you don't have, and encourages you to be a better person.  It's enlightening and humbling at the same time. 

6.  No Television

I sometimes struggle with this myself.  I'm a diehard Chicago Cubs fan, and it is hard to not want to tune the game on, but I still feel that television is a waste of the precious (and little) time we have.  I don't suppose it is really the point that television is terrible, rather that television is not a better alternative to reading a book, creative writing, art, photography, computer programming, or any other of a million things which all increase your overall well being.

Find a hobby, follow your dreams.  Don't want to be a programmer?  Hey, it's not for everyone.  Maybe you wanted to be an accountant (hahaha!).  All jokes aside, maybe you wanted to be a chef, artist, or simply just learn about history, lose yourself in a great story perhaps.  Wouldn't that be a more enjoyable way to spend your time instead of watching someone else on t.v. live out your dream?

Think about how much time you have spent watching television in the past year.  Now try to picture how much knowledge, and experience you would possess in regard to any of those aforementioned hobbies, if you had used that same number of hours pursuing that which is important to you.  That statement is reason enough to unplug.

7.  Socialize

Being a programmer, it's really hard for me to sit at a desk, and problem solve all day and then come home and work more.  This happened more in the beginning of my career when I was writing code for about 100% of the day, and it is less now, but it is still important for me to actively keep up friendships, keep up with friends and family, and actively communicate with other developers. 

For some, it can be nerve-wracking, or even anxiety-inducing to be in social situations, but there are plenty of strategies to be a good communicator.  You will find that by actively socializing with others, and keeping a strong social support system, you will have plenty of opportunities to have a good laugh, enjoy life and all it has to offer, get through the hard times in life, and also help others through as well.

Like anything in life, you get out what you put in.  If you put little or no effort into maintaining any level of friendships with anyone, well then you are unfortunately going to be a very lonely person.  If, on the other hand, you actively make it a point to pursue and keep up relations with those close to you, then you will find yourself benefiting from the effort you are putting in as well.

Currently rated 5.0 by 1 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Remove Surrounding White Space From An Image

by Kyle Ballard 11/22/2008 5:15:02 PM

The following is from my post on StackOverflow.com

I have a block of product images we received from a customer. Each product image is a picture of something and it was taken with a white background. I would like to crop all the surrounding parts of the image but leave only the product in the middle. Is this possible?

As an example: http://www.5dnet.de/media/catalog/product/d/r/dress_shoes_5.jpg

I don't want all white pixels removed, however I do want the image cropped so that the top-most row of pixels contains one non-white pixel, the left-most vertical row of pixels contains one non-white pixel, bottom-most horizontal row of pixels contains one non-white pixel, etc.

Below is the solution to my problem.  It is not the most glamorous approach, but it works.  I could have use Bitmap.Lockbits() to lock the bitmap in memory and do my processing there, but this approach below sufficed my needs.  It is a pixel by pixel scan of the image. 

Some recommended additions/changes if you are feeling inclined:

- Use Bitmap.Lockbits() to improve performance
- Perform image resizing after the trimming is completed.
- Instead of looking for straight white pixels, you could also exclude near-white pixels (for any shadows).

Start.vb

Imports System.Drawing 
Imports System.IO 
Imports System.Configuration.ConfigurationManager 

Module Start 

    Sub Main() 
        Try 
            Console.WriteLine("") 
            Console.WriteLine("Begin:  Crop Images") 
            CropAllImages() 
        Catch e As Exception 
            Console.WriteLine("Error Message: " & e.Message) 
            Console.WriteLine("----------") 
            Console.WriteLine("Error Stack: " & e.StackTrace) 
        End Try 
    End Sub 

    Sub CropAllImages() 
        Dim iTopMostPixel As Integer, iLeftMostPixel As Integer, iRightMostPixel As Integer, iBottomMostPixel As Integer 
        Dim objBmp As Bitmap, objNewBmp As Bitmap 
        Dim rect As Rectangle 
        For Each oFile As FileInfo In New DirectoryInfo(AppSettings("ImagePath")).GetFiles("*.jpg") 
            objBmp = CType(Bitmap.FromFile(AppSettings("ImagePath") & oFile.Name), Image) 

            iTopMostPixel = GetNonWhitePixel(objBmp, 1) + AppSettings("PaddingTop") ' Get the top most pixel and add any optional padding 
            iLeftMostPixel = GetNonWhitePixel(objBmp, 2) + AppSettings("PaddingLeft") ' Get the left most pixel and add any optional padding 
            iBottomMostPixel = GetNonWhitePixel(objBmp, 3) + AppSettings("PaddingBottom") 
            iRightMostPixel = GetNonWhitePixel(objBmp, 4) + AppSettings("PaddingRight") 

            rect = New Rectangle(iLeftMostPixel, iTopMostPixel, iRightMostPixel - iLeftMostPixel, iBottomMostPixel - iTopMostPixel) 
            objNewBmp = objBmp.Clone(rect, objBmp.PixelFormat) 
            objNewBmp.Save(AppSettings("ImagePath") & Replace(oFile.Name, oFile.Extension, "_cropped" & oFile.Extension), Imaging.ImageFormat.Jpeg) 

            Console.WriteLine("Saved: " & AppSettings("ImagePath") & Replace(oFile.Name, oFile.Extension, "_cropped" & oFile.Extension)) 

            objNewBmp.Dispose() 
            objBmp.Dispose() 
        Next 
    End Sub 

    Function GetNonWhitePixel(ByVal objBmp As Bitmap, ByVal iPixelType As Integer) As Integer 
        Dim objColor As Color 

        Select Case iPixelType 
            Case 1 

                ' Top pixel 
                For y = 0 To objBmp.Height - 1 
                    For x = 0 To objBmp.Width - 1 
                        objColor = objBmp.GetPixel(x, y) 
                        If Hex(objColor.R) & Hex(objColor.G) & Hex(objColor.B) <> "FFFFFF" Then Return y 
                    Next 
                Next 

            Case 2 

                ' Left pixel 
                For x = 0 To objBmp.Width - 1 
                    For y = 0 To objBmp.Height - 1 
                        objColor = objBmp.GetPixel(x, y) 
                        If Hex(objColor.R) & Hex(objColor.G) & Hex(objColor.B) <> "FFFFFF" Then Return x 
                    Next 
                Next 

            Case 3 

                ' Bottom pixel 
                For y = objBmp.Height - 1 To 0 Step -1 
                    For x = 0 To objBmp.Width - 1 
                        objColor = objBmp.GetPixel(x, y) 
                        If Hex(objColor.R) & Hex(objColor.G) & Hex(objColor.B) <> "FFFFFF" Then Return y 
                    Next 
                Next 

            Case 4 

                ' Right pixel 
                For x = objBmp.Width - 1 To 0 Step -1 
                    For y = 0 To objBmp.Height - 1 
                        objColor = objBmp.GetPixel(x, y) 
                        If Hex(objColor.R) & Hex(objColor.G) & Hex(objColor.B) <> "FFFFFF" Then Return x 
                    Next 
                Next 

        End Select 

        ' Nothing found 
        Return 0 
    End Function 
End Module

app.config

<?xml version="1.0" encoding="utf-8" ?> 
<configuration> 
    <appSettings> 
        <add key="ImagePath" value="C:\Path\To\My\Images\"/> 

        <add key="PaddingLeft" value="10" /> 
        <add key="PaddingRight" value="10" /> 
        <add key="PaddingBottom" value="100" /> 
        <add key="PaddingTop" value="0" /> 
    </appSettings> 
</configuration>

kick it on DotNetKicks.com

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags:

Powered by BlogEngine.NET 1.2.0.0
Theme by Mads Kristensen

About the author

My lovely wife and I at a wedding I am a web developer living in the Chicagoland area. I mainly focus on developing e-commerce applications and work with asp.net on a regular basis.


Send mail Facebook Twitter LinkedIn

Calendar

<<  February 2010  >>
MoTuWeThFrSaSu
25262728293031
1234567
891011121314
15161718192021
22232425262728
1234567

View posts in large calendar

Recent comments

Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2010

    Sign in