More actions
No edit summary |
Categorized this as a technical guideline |
||
Line 23: | Line 23: | ||
- Otherwise, if it is used for a specific class only, it can be placed in the namespace where it is used. | - Otherwise, if it is used for a specific class only, it can be placed in the namespace where it is used. | ||
== Working with threads == | == Working with threads == | ||
*Usages of threads must be specified in the Technical design and approved by PMs. | *Usages of threads must be specified in the Technical design and approved by PMs. | ||
*Use CatGlobe.Framework.Security.AsyncHelper class to start a thread with auto-impersonate, access factory and webconfig manager. | *Use CatGlobe.Framework.Security.AsyncHelper class to start a thread with auto-impersonate, access factory and webconfig manager. | ||
== Web pages – web controls == | == Web pages – web controls == | ||
=== Code behind (ASPX and ASCX) === | === Code behind (ASPX and ASCX) === | ||
*Code behind must be documented with request parameters, usage, purpose. | *Code behind must be documented with request parameters, usage, purpose. | ||
*Use Register…(JavascriptConstant…) to include javascript files in the code behind. | *Use Register…(JavascriptConstant…) to include javascript files in the code behind. | ||
*Web page must inherit from the PageBase class, control must inherit from the ControlBase class and Web Service must inherit from the WebServiceBase class. | *Web page must inherit from the PageBase class, control must inherit from the ControlBase class and Web Service must inherit from the WebServiceBase class. | ||
*DO NOT override the OnError event, unless it is approved in the technical design. | *DO NOT override the OnError event, unless it is approved in the technical design. | ||
=== ASPX file === | === ASPX file === | ||
*Replace the auto-generated DOCTYPE by this one: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > | *Replace the auto-generated DOCTYPE by this one: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" > | ||
*A page must have a title using text resource. | *A page must have a title using text resource. | ||
*All the validation warnings which the Visual Studio shows must be fixed. | *All the validation warnings which the Visual Studio shows must be fixed. | ||
*Adding references to user controls and using of tagPrefixes: must following this guideline [[Tag prefixes for user controls and web controls]] | *Adding references to user controls and using of tagPrefixes: must following this guideline [[Tag prefixes for user controls and web controls]] | ||
*You are allowed to reference to javascript files in the aspx files directly. However, you must use the JavascriptConstant to reference to them. | *You are allowed to reference to javascript files in the aspx files directly. However, you must use the JavascriptConstant to reference to them. | ||
*If a page or a control contains more than 3 methods or more than 20 lines, move it to a separate js file. | *If a page or a control contains more than 3 methods or more than 20 lines, move it to a separate js file. | ||
=== ASCX file === | === ASCX file === | ||
*DO NOT reference to javascript files in the ascx files. | *DO NOT reference to javascript files in the ascx files. | ||
=== Text resources === | === Text resources === | ||
*When you need to register a text resource to the client side, use the PageBase.CGClientScript.RegisterTextResource method. The method will encode registered text resources for you. | *When you need to register a text resource to the client side, use the PageBase.CGClientScript.RegisterTextResource method. The method will encode registered text resources for you. | ||
*Setting for text resource files of web pages: | *Setting for text resource files of web pages: | ||
- Need to be set to the [filename].aspx.resx file only. | - Need to be set to the [filename].aspx.resx file only. | ||
- Custom tool namespace: x (yes, only the letter 'x'). | - Custom tool namespace: x (yes, only the letter 'x'). | ||
- Build action: None | - Build action: None | ||
- Custom tool: ResXFileCodeGeneratorEx | - Custom tool: ResXFileCodeGeneratorEx | ||
*Setting for text resource files of an enumeration file: | *Setting for text resource files of an enumeration file: | ||
- Custom tool namespace: aenum | - Custom tool namespace: aenum | ||
- Build action: Embedded Resource | - Build action: Embedded Resource | ||
- Custom tool: ResXFileCodeGeneratorEx | - Custom tool: ResXFileCodeGeneratorEx | ||
[[Category:Technical guidelines]] |
Revision as of 03:31, 17 December 2008
Introduction
This guideline contains CatGlobe-specific coding rules.
Exception
Exception handling
- Only catch exception if you can do some thing with it.
- All re-thrown exception must include the original exception in its inner exception.
- DO: always catch specific exception type. You are allowed to catch generic exception and re-throw a specific exception; for example in CGScript all exceptions are caught and a RuntimeException is re-thrown afterward.
- DO NOT: empty and undocumented catches; using unspecific catches, unless they are documented well in the design document and are approved by the PMs.
Create a new custom of exception
- Naming rule: the new exception must be suffixed with “Exception”.
- All custom exceptions must inherit from another exception class.
- The exception should be serializable in order to use in CatTask service. Refer to Serializable exceptions for more details. Notice: when the new CatTask service is done, this may be obsolete.
- Namespace rule:
- If the being created exception is used in multiple places, it must be placed in the CatGlobe.Framework.Exceptions namespace.
- Otherwise, if it is used for a specific class only, it can be placed in the namespace where it is used.
Working with threads
- Usages of threads must be specified in the Technical design and approved by PMs.
- Use CatGlobe.Framework.Security.AsyncHelper class to start a thread with auto-impersonate, access factory and webconfig manager.
Web pages – web controls
Code behind (ASPX and ASCX)
- Code behind must be documented with request parameters, usage, purpose.
- Use Register…(JavascriptConstant…) to include javascript files in the code behind.
- Web page must inherit from the PageBase class, control must inherit from the ControlBase class and Web Service must inherit from the WebServiceBase class.
- DO NOT override the OnError event, unless it is approved in the technical design.
ASPX file
- Replace the auto-generated DOCTYPE by this one: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
- A page must have a title using text resource.
- All the validation warnings which the Visual Studio shows must be fixed.
- Adding references to user controls and using of tagPrefixes: must following this guideline Tag prefixes for user controls and web controls
- You are allowed to reference to javascript files in the aspx files directly. However, you must use the JavascriptConstant to reference to them.
- If a page or a control contains more than 3 methods or more than 20 lines, move it to a separate js file.
ASCX file
- DO NOT reference to javascript files in the ascx files.
Text resources
- When you need to register a text resource to the client side, use the PageBase.CGClientScript.RegisterTextResource method. The method will encode registered text resources for you.
- Setting for text resource files of web pages:
- Need to be set to the [filename].aspx.resx file only.
- Custom tool namespace: x (yes, only the letter 'x').
- Build action: None
- Custom tool: ResXFileCodeGeneratorEx
- Setting for text resource files of an enumeration file:
- Custom tool namespace: aenum
- Build action: Embedded Resource
- Custom tool: ResXFileCodeGeneratorEx