Tech Blog

Jay's Technical blog

Atlas: Starting to grasp control development...

21 May 2006
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

[out of date post... this deals with MS Atlas CTP... which has been change drastically and is now MS Ajax Extensions]

This is the type of post you don’t really want to write.  You always want to speak from great knowledge from on high to the masses.  Unfortunately, I did something stupid tonight.  I decided that I could extend the DragOverlayExtender in about an hour and could easily start to add some features like grabbing the position of the element (mind you I have really only given this aspect of Atlas a cursory look before tonight).  In the process I learned quite a bit, but not quite what I wanted to know.

So let’s start with the extenders.  Atlas has these really cool “extenders” that when dropped on a web form will extend additional functionality to every control on the form.  For instance, the new rounded corners extender (part of the Atlas Control Toolkit) lets you round the edges of your panels to have a more rounded look as opposed to the standard box with sharp corners.

The DragOverlayExtender let’s you make panels movable and can store this information back to a user profile (which is part of the whole new membership security model… I know a lot more about that than I have written)

So my goal tonight was relatively simple (or so I thought).  I wanted to create a drag-able region and:

  • Detect the position of the element on the server via the new TimerControl’s tick event
  • Update a label with this information
  • (optionally) detect when this movable region was on top of another region

Ultimately, while I think drag is cool, what I really want is drag/drop.  So I need to be able to detect if the dragged region is now on top of another drop zone panel. 

So the first attempt ended up with nothing but a form that ticks back to the server and let’s me drag the “Move Me” panel all over the screen.  But, I can’t detect the position.  There’s no place to detect it on the server.

So my next thought was to inherit the DragOverlayExtender.  I was looking for some hidden property; I even went so far as to run it through Reflector to take a look at the source code… It was at this point that I realized the fundamental nature of Atlas components.  Ready?  I know this will come as a big revelation to you.  The server side component of Atlas controls is minimal.  Much of the work is on the client side… Duhhh!

This has lead me to a place where I now think I understand how to really develop an Atlas control.  Play around in the client side first; get your idea working there.  Learn how to build the client side behaviour and then build your server side control to take advantage of these behaviours.  You will save yourself a lot of headaches…

BTW, my investigation has shown me that that while there is currently only a DragOverlayExtender the float behavior (which is what the DragOverlayExtender is built on top of) is most certainly capable of Drag and Drop (complete with Drop Zones!)

When I work out the code (if MS doesn’t beat me first) I’ll post it here.

[tags: Atlas, ASP.Net, Ajax]


How to Add Atlas to an existing site (For Brendan)

19 May 2006
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

[Old article warning... you are probably looking for this.]

[Brendan and I were chatting earlier today and he asked me how to enable Atlas on an existing site.  Since I had done this once, I told him what I did, and promised to blog a better set of instructions, so here they are]

There are a bunch of changes that you have to make to your web.config to enable Atlas support on an existing site.

Add the following elements to your configSections section:

<sectionGroupname="microsoft.web"type="Microsoft.Web.Configuration.MicrosoftWebSectionGroup">
  <
sectionname="converters"type="Microsoft.Web.Configuration.ConvertersSection" 
            requirePermission
="false"/>
  <
sectionname="webServices"type="Microsoft.Web.Configuration.WebServicesSection" 
            requirePermission
="false"/>
  <
sectionname="authenticationService"type="Microsoft.Web.Configuration.AuthenticationServiceSection"
           
requirePermission="false"/>
  <
sectionname="profileService"type="Microsoft.Web.Configuration.ProfileServiceSection" 
            requirePermission
="false"/>
</
sectionGroup>

Add the following Section right after the configSections section

<!--
The microsoft.web section defines items required for the Atlas framework.
-->
<
microsoft.web>
  <
converters>
   
<addtype="Microsoft.Web.Script.Serialization.Converters.DataSetConverter"/>
   
<addtype="Microsoft.Web.Script.Serialization.Converters.DataRowConverter"/>
    <
addtype="Microsoft.Web.Script.Serialization.Converters.DataTableConverter"/>
  </
converters>
  <
webServicesenableBrowserAccess="true"/>
<!--
Uncomment this line to enable the authentication service.
  <authenticationService enabled="true" />
-->

<!--Uncomment these lines to enable the profile service. To allow profile properties to be retrieved
and modified in Atlas applications, you need to add each property name to the setProperties and
getProperties attributes. If you intend for all properties to be available, you can use "*"
as a shorthand rather than enumerating each property
-->

<!--
 
  <profileService enabled="true" 
      setProperties="propertyname1;propertyname2" 
      getProperties="propertyname1;propertyname2" />
-->
</
microsoft.web>

Add the following lines inside the system.web section (this lets you use Atlas tags in pages without referencing the assembly in the page):

<pages>
  <
controls>
    <
addnamespace="Microsoft.Web.UI"assembly="Microsoft.Web.Atlas"tagPrefix="atlas"/>
    <
addnamespace="Microsoft.Web.UI.Controls"assembly="Microsoft.Web.Atlas"tagPrefix="atlas"/>
  </
controls>
</
pages>

Inside the system.web section you will need to modify your compilation setting.  It should look like this (to enable the asbx extension — which is for mashups, I believe… yes, I left the comment in on purpose):

<!--
Set compilation debug="true" to insert debugging
symbols into the compiled page. Because this
affects performance, set this value to true only
during development.
-->

<compilationdebug="true">
  <
buildProviders>
    <
addextension=".asbx"type="Microsoft.Web.Services.BridgeBuildProvider"/>
  </
buildProviders>
</
compilation>

Also in the system.web section, you also need to add some handlers to the httpHandlers section (I’ve shown you the complete httpHandlers section in case you don’t have one — you may only need the additional stuff between the httpHandlers tags.nodes):

<!--
ASMX is mapped to a new handler so that proxy javascripts can also be served.
-->

<httpHandlers>
  <
removeverb="*"path="*.asmx"/>
  <
addverb="*"path="*.asmx"type="Microsoft.Web.Services.ScriptHandlerFactory"validate="false"/>

<!--
The MultiRequestHandler enables multiple requests to be handled in one
roundtrip to the server. Its use requires Full Trust.
-->
  <
addverb="*"path="atlasbatchcall.axd"type="Microsoft.Web.Services.MultiRequestHandler" 
            validate
="false"/>
  <
addverb="*"path="atlasglob.axd"type="Microsoft.Web.Globalization.GlobalizationHandler" 
            validate
="false"/>

<!--
The IFrameHandler enables a limited form of cross-domain calls to 'Atlas' web services.
This should only be enabled if you need this functionality and you're willing to expose
the data publicly on the Internet.
To use it, you will also need to add the attribute [WebOperation(true, ResponseFormatMode.Json, true)]
on the methods that you want to be called cross-domain.
This attribute is by default on any DataService's GetData method.

  <add verb="*" path="iframecall.axd" type="Microsoft.Web.Services.IFrameHandler" validate="false"/>
-->

  <addverb="*"path="*.asbx"type="Microsoft.Web.Services.ScriptHandlerFactory"validate="false"/>
</
httpHandlers>

Finally (well for the web.config), you will need to add some items to your httpModules section which is in the system.web section  (you more than likely don’t have any currently, so I’ve given you the complete section again… if you do have a httpModules section in your web.config you will want to simply add the stuff between the httpModules tags/nodes):

<httpModules>
  <
addname="ScriptModule"type="Microsoft.Web.Services.ScriptModule"/>
  <
addname="BridgeModule"type="Microsoft.Web.Services.BridgeModule"/>
  <
addname="WebResourceCompression" 
          type
="Microsoft.Web.Services.WebResourceCompressionModule"/>
</
httpModules>

The last step is easy!  Reference the Microsoft.Web.Atlas.dll in the web project.

[UPDATE: I decided due to the comments I'm getting that I should add a section on what do if you are having problems]

If you are having problems, here are some troubleshooting tips.  Make sure that you have the Atlas April release installed properly.  Make sure you can build Atlas web site first.  If you can't then you're problem lies elsewhere (you will need to do a little research to fix your individual issue).

If you are having a problem with a specific features and are able to build Atlas web sites using the Atlas Web Project, make sure that you aren't having a problem with that feature with an Atlas web project.  If you can, did you forget the last step which is to add a project reference to the Atlas.dll.

[tags: Atlas, Ajax, ASP.Net]


ReSharper 2.0 Release Candidate 2...

19 May 2006
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

Somehow I missed the first Release Candidate (yesterday).  ReSharper is in release candidate mode!  We should be seeing release soon (I bet).  For those of you interested in trying it out, the EAP Page,  contains a license info that will let you use the RC for a bit longer than the normal trial.  So download it and get hooked like me!

[UPDATE: this stupid American (me) misread the date on the ReSharper EAP site… the license is only good until June 1st… 01/06/2006 sounds like January 6th to me, but the JetBrains guys “ain’t from ‘merica” so they use that other format for dates <grin />]

[tags: Visual Studio.NET, Dev Tools]


The one security demo you should watch...

17 May 2006
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

I'm sure I've posted this before, but David Hayden's post prompted me to make sure this video resurfaces on the top of the CodeBetter feed (instead of buried in my comments).

If you have ever thought, "hey defending the network is not my problem... that's networking or security problem" then you are wrong!  It's your job as the programmer... go watch this

If you think the whole encrypting passwords or SQL Injection is a lot of hot air or even if some of this security religion we've all been fed, go watch this (same link).

If you want a good laugh and a reminder that security is important... you guessed it! go watch this (still the same link).

It's about 40 minutes that you don't need to be 100% focussed on, but you need to watch the earliest part of the discussion and listen to the rest... (if you have the 40 minutes then watch the whole thing... you won't be sorry)

[tags: ASP.Net, Security]


Documenting the Atlas Runtime JS... Function Class and Object Class

10 May 2006
Jay Kimble

[WARNING! This is an archived post and as such there may be things broken/missing here.. you have been warned.]

[out of date post... this deals with MS Atlas CTP... which has been change drastically and is now MS Ajax Extensions]

[Ok, so I’m changing tactics… I’m going to document the individual objects not documented currently by the Atlas Docs… some of this will be repeats, but at least we’ll get a full view]

Function Class – all classes (and functions) derive from this JS object , so MS modifies this object and therefore all your Javascript functions… Think of this as a listing of methods available to all Atlas objects/classes.  This class is assigned to the Type member of the window object making it top-level.

  • Statics
    • abstractMethod — Used to define a method that is abstract and needs to be created by inheritors (it throws an error to this effect)
    • createCallback – [params: method, context] returns a new function that calls the method parameter (which is a function) with the context parameter like this:
      method(context). 
      This is used to create callback functions (similar to delegates or events) that are passed some context of the operation
    • createDelegate – [params: instance, method] – returns a new function that calls the method param (which is a function) that is within the instance param (which is an object).  Parameters are passed from the new function directly to the method.  (This code makes use of the function.apply method) 
    • emptyFunction – returns a function with no code in it
    • parse - [params: functionName] – this does 2 things.  First of all it adds an internal static/shared _htClasses array to the object tree if it doesn’t exist (at the Function level).  Next it uses Eval to locate the function with a name matching the functionName param. Finally if it finds a function it adds this function to the _htClasses array.  [Notes: Basically, the Atlas runtime will learn about your classes/functions on it’s own even if you build standard Javascript and then simply call an Atlas function… From what I have seen parse is a very common function within the Atlas framework]
    • CreateInstance – [params: type] – instances a class (using the new operator).  The parse method is used to do this
    • registerNamespace – [params: namespacePath] – builds a tree of empty objects by splitting into an array on the “.” and then creates a child member (object) of the window object named after the first element in the array… each subsequent element is made into a child member (object) of the object that was just created… so… Sys.Some.Namespace will create a Sys member of the window object, and Some member of the Sys object, and a NameSpace member of the Some object. [NOTE: this method is also exported as a globally available function called “registerNamespace”]
  • Instanced
    • getBaseMethod – [params: instance, methodName, baseTypeName] – scans the internal inheritance arrays in the instance param (put there by Atlas) for a ancestor class having a name that matches the baseTypeName param.  It then searches this type for a particular method having a name mathcing the methodName param.  It will either return a function or null
    • getBaseType – returns the internal _baseType (which is the last ancestor type in the inheritance tree)
    • _copyProps – [params: p_objFnc] – simply copies the properties/functions from one object to another (the “_” prefix signifies that this is probably not meant for public use)
    • _setBases – [params: p_objRoot] – As with the last method this is probably not for normal public use (so use with care).  I believe that this function is used to build the internal inheritance trees/arrays; it does this using parse and a number of additional methods.  [I don’t really have a complete understanding of this function as it is a support function for several other routines.  I don’t think this is a function you would want to call in normal clientside development… let the Atlas framework call it for you]
    • _callBaseConstructors – [params: p_objInstance, p_objArgs] – calls all the base constructors when an object is created with the p_objArgs parameter
    • callBaseMethod – [params:instance, methodName, baseArguments] – use getBaseMethod to return a method from a base and then call it with the baseArguments param
    • implementsInterface – [params: interfaceType] – determines if the object implements a particular interface (so it returns true or false) [uses the internal Atlas “metadata” arrays to determine this information]
    • inheritsFrom – [params: parentType] – Determines if the object implements a particular interface [_setBases and the internal Atlas “metadata” arrays]
    • initializeBase – [params: instance, baseArguments] – calls the constructors for all implemented interfaces, sets up some internal “metadata” arrays and calls the _callBaseConstructors method
    • isImplementedBy – [params: instance] – determines if the instance param (which is an object) implements the interface (this object).  This is sort of the opposite direction of the implementsInterface method
    • isInstanceOfType – [params: instance] – determines if the instance param (which is an object) is an instance of this class. This is sort of the opposite direction of the inheritsFrom method
    • registerBaseMethod – [params: instance, methodName] – registers a method as a baseMethod in the internal metadata
    • registerClass– [params: typeName, baseType, interfaceType] – registers a class and builds it’s internal metadata arrays.
    • registerAbstractClass – [params: typeName, baseType] – simply calls registerClass and sets the internal _abstract variable to true
    • registerSealedClass – [params: typeName, baseType] – simply calls registerClass and sets the internal _sealed variable to true
    • registerInterface – [params: typeName] – simply calls registerClass, sets the internal _interface, _abstract, and _sealed variables to true, and sets the internal _typename variable to the typeName parameter
    • _typeName – “Function”
  • Additional “built-in” members
    • length property – number of named arguments
    • prototype property – let’s you add methods/members that will be available to instances of this class
    • apply method – invokes a method on an instanced object
    • call – invokes a function
    • toString – returns the string representation of this function

Object class – all JS classes derive from this class

  • statics
    • getType – returns the defining class for the object
    • getTypeName – returns the results of the getName function for the object (getType is called first)
    • _typeName – “Object”
  • Additional “built-in” members
    • constructor property
    • hasOwnProperty 
    • isPrototypeOf
    • propertyIsEnumerable
    • toLocaleString
    • toString
    • valueOf

[tags: Atlas, Ajax, ASP.Net]