November 2007 - Posts

SQL Profiler custom filter
Friday, November 23, 2007 8:13 AM

the tip is simple u need to make a filter that filters and shows only your DB transactions on a server. what u need to do is to change your web.config by adding a string that you can later filter on

   1: <add key="Main.ConnectionString"
   2: value="data source=Server;initial catalog=dbName;
   3: User ID=sa;Password=userName;application name=thisIsTheFilter"
   4: />

 

 

now that you have something to distinct your connection from all other users all you have to do is open the profiler window and start a new trace ==> connect don't start the trace yet

click the image to enlarge

 

and that's all start ur trace

Download FireFox 3 Beta 1 now
Tuesday, November 20, 2007 6:44 AM

 firefox beta1 is out, i am surprised with all the rumors about it being very buggy and that the team will be solving only 20% of the bugs but it's here let's try it now

 download it

Software Needed to create Ajax Applications
Saturday, November 17, 2007 2:56 AM

well there's a lot of approaches to create ajax applications but i like .net and c#, I use asp.net controls to render the initial page and then do all the manipulation using manually coded javascript.

and for the server calls i use normal asmx's and a script manager to generate a javascript that i can use to send and receive data

so this way the tools i need are simple

  1. Visual Studio 2005 : which i use to create asp.net pages and create my web services and handle all server code and database logic
  2. Aptana : an eclipse based IDE that i can use for editing client side javascript it works perfectly has inttellisence feature that treats javascript variables as if they were typed and it tells you what code would run on which browser, i intend to have a sepparate post(s) about it, it has debugging features but i don't really like it
  3. FireFox + FireBug : well this combination proves to be the best way to
    • debug javascript where you can set breakpoints and watch variables and trace call stacks
    • inspect the resulting dynamic html and styles
    • also firebug is a great tool that can be used to trace XMLHTTPRequests and view their contents
  4. for IE i use
by amir.magdy | with no comments
Filed under: , ,
Override IIS Maximum upload size [max upload size in asp.net]
Saturday, November 17, 2007 1:56 AM

by default IIS enables you to upload 2 megabytes and i couldn't seem to figure out how to change that using Internet service manager snap in

but i found this on msdn and it's working perfectly fine

alll you have to do is add this node right under <system.web> section in web.config

   1: <httpRuntime maxRequestLength="size in KiloBytes"
   2:    executionTimeout="seconds"/>

and i managed to upload quite large files.

by amir.magdy | 1 comment(s)
Filed under: , ,
A potentially dangerous Request.Form value was detected from the client
Saturday, November 17, 2007 1:39 AM

by default asp.net checks for the scripts in requests so that if it finds a user that is posting javascript or HTML in a request body it will throw an exception "A potentially dangerous Request.Form value was detected from the client"

but sometimes you need this like when you allow a user to send HTML formatted block like in an article or if you are building a blog engine and u need to enable the user to add affiliation site codes or a google analytics block

in this case all you have to do is to modify your page directive to be

   1: <%@ Page Language="c#" AutoEventWireup="false" ValidateRequest="false" %>

ValidateRequest attribute makes sure that asp.net disables this validation

you can also add this node to the page section in web.config

   1: <pages validateRequest="false" />

but of course this is not recommended as it would disable all validation on all pages.

when using these changes please do not forget to make your own validation

by amir.magdy | 1 comment(s)
Filed under: ,
Are you sure [Prompt User Validation]
Saturday, November 17, 2007 1:26 AM

there's so many times when you need to ask a user "are you sure?" but you want it to be quick and painless you don't want to do one more server round trip just for that

you can always use this the javascript prompt function so confirm() but how to integrate that into your asp.net code

ok.

   1: <asp:Button id="btnDelete" runat="server" click="btnDelete_Click" text="Delete">

that's ur button

now u need some preparation to the page

go to your head tag and add a

   1: <script language="javascript"></script>

inside that tag add this script

   1: function confirmDelete()
   2: {
   3:   return  confirm("Are you sure you want to delete this item?");
   4: }

 

now that you have everything read in your page all you have to do in your c# code is this

   1: btnDelete.Attributes.Add("onclick", "return confirmDelete();"); 
Android platform components
Thursday, November 15, 2007 4:15 PM

 android_adc

Android is the new platform adopted by google for the so called "Gphone" the announcement that google made a week ago that there will be actually a phone platform with the name google on it, and that there's a clean platform open for development is very nice to know

the linux based platform is clean and open source and has a set of features that satisfies every day mobile phone

system-architecture

  • Application framework enabling reuse and replacement of components
  • Dalvik virtual machine optimized for mobile devices
  • Integrated browser based on the open source WebKit engine
  • Optimized graphics powered by a custom 2D graphics library; 3D graphics based on the OpenGL ES 1.0 specification (hardware acceleration optional)
  • SQLite for structured data storage
  • Media support for common audio, video, and still image formats (MPEG4, H.264, MP3, AAC, AMR, JPG, PNG, GIF)
  • GSM Telephony (hardware dependent)
  • Bluetooth, EDGE, 3G, and WiFi (hardware dependent)
  • Camera, GPS, compass, and accelerometer (hardware dependent)
  • Rich development environment including a device emulator, tools for debugging, memory and performance profiling, and a plugin for the Eclipse IDE

well, it's up to open source developers to create a richer killer set of tools that would leverage this platform .., and the competition is here

Subversion vs. Source Safe [VSS vs SVN]
Tuesday, November 13, 2007 3:08 PM

i couldn't beleive that there's anyone still using source safe, anyway here's the comparison

Visual source Safe [VSS]   SubVersion [SVN]
  • Commits are not atomic.
  • Renames Affects the whole history
  • only supports locked checkouts 
  • permissiona are supported but anyone can access shares and mess up files.
  • smallest commit block is a file
  • works only on windows shares making hard to go through routers
  • works only on windows
  • proprietry
 
  • Commits are atomic.
  • Renames are supported.
  • Shared checkouts are defaault but supports locking
  • permissions are assignable to granualar level of folders
  • a line is the smallest commit block
  • supports share http,https using apache
  • works on windows, linux, unix, and even macs and also java which makes it ultimaly portable
  • open source (Apache/BSD-style license.)
Selecting an OR Mapper
Tuesday, November 13, 2007 1:53 PM

it's hard work selecting which OR mapper to use, these are a few steps to help select the appropriate mapper

 

  1. Easy to use and read.
       1: UserEntity entity = new UserEntity();
       2: entity.FirstName = "Amir";
       3: entity.LastName = "Magdy";
       4: entity.Password = PasswordHash;
       5: entity.Save();
  2. No strings used to refrence object names.
       1: new TransactionCollection()
       2:  .GetMulti(TransactionFields.DateOfTransaction > DateTime.Now.AddDays(-1));
    as you can see in the previous code DateOfTransaction is the field name which refrences the original field name in database and also the previous code checks for the type of the field and would break with a compile error if both sides of the expression are the same type this is done by overloading the operator ">"
  3. Expressions are combinable
       1: ISortExpression sort = new SortBLOCKED EXPRESSION;
       2: sort.Add(SubCategoryFields.Name | SortOperator.Ascending);
       3: sort.Add(SubCategoryFields.OldId | SortOperator.Descending);
    you can combine expressions and in filters you can combine with and and with orRelatated objects are mapped in code and are easily accessed.

  4. Related objects are mapped through objects
       1: txtManagerName.Text = DepartmentEntity.Employees[0].FullName;
    when there's a relationship defined in your database it maps related objects in your database

  5. Lazyloading, Prefetch
    resulting code should only access database only when needed to do this and gets the least amount of data needed but at the same time you can also do the opposite and prefetch a lot of records for binding with less database round trips
  6. Transactional Support
    a simple way of creating and enrolling objects in a transaction is needed and isolation level change must be exposed in generated code
  7. Mapping Stored Procedures and functions
    mapping other database objects like stored proceudures and accessing results in typed objects

sample code here is used from generated code by llblgenpro.com

Code generation [why]
Tuesday, November 13, 2007 3:38 AM

"code was meant to be written" to quote a developer friend of mine.

Well i don't think so, there's a lot of code that takes ages to be built and usually was being given to newbies in the team to do a long repeatative task for instance to map all DB objects into code classes something the developers can use.

and you have the problem where someone decides that this DB class is not the best way to do stuff and they go changing the classes on top of that but still some field "employeeId" is written "empolyeeId" and it breaks at runtime, when the client access that page.

there's a better way you can always use a tool that generates code and every time you change something in your database, all you have to do is to regenerate that code based on those DB changes.

there's a lot of frameworks that help you generte code for Database like

u eventually will be able to do this

   1: UserEntity user = new UserEntity();
   2: user.UserName = "Amir";
   3: user.Gender = true;
   4: user.Save();
   5:  
   6: //insteadOf 
   7:  
   8: SqlConnection conn = new SqlConnection(connectionString);
   9: SqlCommand comm = new SqlCommand(string.Format("insert into users (username,gender) values ('{0}',{1})", "Amir", 1),conn);
  10: conn.Open();
  11: comm.ExecuteNonQuery();
  12: conn.Close();
  13:  
  14:  
by amir.magdy | with no comments
Filed under:
SVN [Subversion]
Tuesday, November 13, 2007 2:55 AM

subversion_logo_hor-468x64

subversion or svn is a source control solution that relies on the idea of shared checkout; mmm that means that multiple people can edit the same file at the same time. well if u're using VSS (visual source safe) that might be hard for you to understand

Here's how it works you get the latest version of a file you start editing this file immediatly without the server knowledge.
and then when it's time to checking your changes, your client checks if the file has changed since you started editing if it hadn't changed it will just take your changes in

but if it did it will require you to get the latest version and use document merge algorithm to merge your two documents together and only then you can commit your changes to the repository.
and if it fails to merge a document it asks you to resolve the confilcts manually, and that rarely happens. on y if two people make editions to the very same line


there's a few clients for this most notable for windows are:

  1. tortoise which is an integration plugin to windows explorer, it is the most poularly used. it marks folders and files on your had drive with icons that show their status if edited or same as last checkout. updating repository and check outs/ins are begin done from the normal windows explorer context menu

    tortoisesvn3
  2. Ankh this one is an integration into Visual studio.net all the commands are handled the same way as you would handle your average Source safe commands it implements the standard Visual studio source control interfaces. But it doesn't cache file status. so every time you open a solution it takes ages to update the files statuses

there's also other clients for other platforms including mac OSX and of course linux and all in open source

installation is simple that you can even do it yourself http://svn1clicksetup.tigris.org/, but there's also a lot of options you can install it on windows shares or over SSLed apache but you have to refer to the main package http://subversion.tigris.org/

Reusing custom validator
Monday, November 12, 2007 12:54 PM

do u have custom validation code that u need to resuse, do u find yourself copying code of validation between pages

well here's how to build a custom validator

all you have to do besides inheriting Control is implement the IValidator Interface and here u go

public class ValidatorControl: Control,IValidator {}

Validatable ASP.net WebCustomControl
Monday, November 12, 2007 12:52 PM

when u add a required field validator to your page u get to select which control to validate, so what if u created that control you want to validate...

just add the Attribute

[ValidationProperty("PropertyName")]
to your class and specify which public property of your control to use

flv Files doesn't stream on IIS windows 2003 [fix]
Monday, November 12, 2007 12:20 PM

i was trying to make a flash file stream a flash video file flv it works finew locally and on my XP IIS but not on our windows 2003 server i went to search on line and i found this link
reason is that IIS doens't have one of the most popular streaming mime types you have to go yourself add the mime type

  1. On the Windows 2003 server, open the Internet Information Services Manager.
  2. Expand the Local Computer Server.
  3. Right-click the local computer server and select Properties.
  4. Select the MIME Types tab.
  5. Click New and enter the following information:
    • Associated Extension box: .FLV
    • MIME Type box:flv-application/octet-stream
  6. Click OK.
  7. Restart the World Wide Web Publishing service.

http://kb.adobe.com/selfservice/viewContent.do?externalId=tn_19439&sliceId=1
by amir.magdy | with no comments
Filed under:
Ajax.net cancel a request
Monday, November 12, 2007 12:06 PM

well this is one of my old blog posts i'll be resposting them by time ammong new ones

here we go

this is very important if i have a request that i have issued using asp.net ajax client library this is how to cancel it

   1: serviceHandler = new ServiceName().methodName(param1, param2, completeHendler ,errorHandler );
   2: // just keep the serviceHandler variable in a handy scope
   3: // and when the user doesn't want this request anymore
   4: if (serviceHandler!=null)
   5:     serviceHandler.get_executor().abort();
by amir.magdy | 1 comment(s)
Filed under: , , ,
More Posts Next page »