Archive

Archive for the ‘development’ Category

Email from friends (invsqrt)

December 15th, 2006 1 comment

Don’t you just love getting email from your friends.  I am sure that as you read this you may think about past jokes and humerous anecdotes received.

I don’t get many like that, this is what I got from a friend of mine today,

How bout this for a fast invsqrt…

float InvSqrt(float x)
{
      float xhalf = 0.5f * x;
      int i = *(int *)&x;
      i = 0x5f3759df – (i >> 1);
      x = *(float *)&i;
      x = x * (1.5f – xhalf * x * x);
      return x;
}

Explanation given here (not for the faint of heartr)

http://www.math.purdue.edu/~clomont/Math/Papers/2003/InvSqrt.pdf

You have to see the explanation and Steve’s right its not for the faint of heart.

So any XNA peeps who stumble along here might you be interested.

Categories: development Tags:

SPSite.LastContentModifiedDate

November 24th, 2006 2 comments

This can’t be right, it’s insane.  What’s insane ? Well it appears that the LastContentModifiedDate gets updated when the Site Usage is re-calculated.  So my Last Modified webpart is made pretty much useless by having the SiteUsage data enabled.

That blows. Hope its just coincidence.

 

Technorati tags: , ,
Categories: development, Sharepoint Tags:

That Todd Bleeker

November 23rd, 2006 No comments

menupart.jpg 

Whilst poking about on sharepoint sites I was looking at Todd’s site again, and stumbled across another of his CEWP again, this one was for a menu part, its great , as they always are leveraging the power of sharepoints built-in functionality but what I never knew before was just how easy it was to generate sharepoint menus.

This is the html for two menu items and its opening link

<menu id=”myLinks” class=”ms-SrvMenuUI”>

<ie:menuitem

iiconSrc=”http://www.highdots.com/website-ranking-checker/images/search_engines/google.gif”

onMenuClick=”window.location.href=’http://google.com’;”

>Google</ie:menuitem>

<ie:menuitem

iiconSrc=”http://www.highdots.com/website-ranking-checker/images/search_engines/msn.gif”

onMenuClick=”window.location.href=’http://msn.com’;”

>MSN</ie:menuitem>

</menu>

<div class=”ms-HoverCellInActive”

onmouseover=”this.className=’ms-HoverCellActive’”

onmouseout=”this.className=’ms-HoverCellInActive’”>

<a id=”menuLink”

style=”CURSOR: hand”

onclick=”JavaScript: if(!myLinks.isOpen())

myLinks.show(this, true, 0, 0, 0);”

tabindex=”0″>

Search Engines

</a>

</div>

 Taken from http://mindsharpblogs.com/todd/archive/2006/08/15/1242.aspx

Now because I spend my time writing dynamic webparts (ie not fixed content) I can name the menu based on the webparts clientId and have these littered all over a page.

Must think up some use for it now.

Technorati tags: , ,

Categories: development, Sharepoint Tags:

Ajax and Sharepoint 2

November 17th, 2006 2 comments

Subtitle:Don’t you think the way lists display suck ?

Well I do, no in the web parts themselves, but in the inevitable postback to a crappy looking list item page.

In the previous post you could see the web part I was working on, well its just a demo piece and needs a lot of work, but I figure why should I do all that work I’ll let you do some.  Actually I may not have time to finish this one so I thought I’d put out what I had done.

The web part allows you to select a list that is currently available on this current site. You have to enter the Main field name in the Text box below and its away.  This part will rip through the list contents and spit them out with a link in the web part.  When you click that link the Ajax stuff fetches the list data item and displays it in the box, fast.

Now there is a lot to do here, things like provide html editing for the list display both list and popup designs.  Use the ID instead of the “Title” field (duplicates won’t work in this version)

Also figure out the field type and display appropriately being the main one.

Lots left to do but you can do it.

When you create this you MUST GAC IT.  It was developed with Sharepoint security at FULL, figure it out for yourself if you want a better config.

The web.config needs the HTTP Handler adding (you own key remember)

<httpHandlers>
<add verb=”GET” path=”DynamicCustomListPart.ashx” type=”DynamicCustomListPart.DynamicCustomListWebPart, DynamicCustomListPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=*************” />
</httpHandlers>

Source Code

*NB.  This is a demo and not production software, use at own risk.

 

Technorati tags: , , ,
Categories: development, Sharepoint Tags:

AssemblyFolders in 64bit

October 18th, 2006 No comments

To add assemblies into the list of assemblies for references in Visual Studio 2003 you can edit the registry and add them there

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\7.1\AssemblyFolders\MyLibrary]
@=”D:\\Development\\BinaryJam\\MyLibrary”

Well in 64bit land this is changed to

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\7.1\AssemblyFolders\MyLibrary]
@=”D:\\Development\\BinaryJam\\MyLibrary”

Hey presto there they are in the References Dialog

 

Technorati:

Categories: development Tags:

Sharepoint and Custom HttpHandlers

October 12th, 2006 No comments

If you are daft enough to remove your HttpHandler from the GAC don’t be surprised if sharepoint goes bang.

I did just that and hit Site Settings and got a plain file not found message, not very helpful.

I narrowed it down to the last scarey thing I did which was HttpHandlers, deleted the entries and all was working I then figured I removed it from the GAC and sps bin folder so Sharepoint was not finding the dll.  Pretty poor message though.

Categories: development, Sharepoint Tags:

WebParts and Ajax

October 5th, 2006 No comments

I have been playing about with ajax recently,  actually I’ve been doing ajax and dynamic web applications since IE4 was released, I was lucky enough to spend 9 months programming a client side dynamic application back then using RDS MTS and dhtml classes, its just this .NET postback model dragged me away from it.  But anyway I’ve been playnig with it again.

What I wanted to do was use ajax in a webpart however its the same old story, having to have a seperate web site to host the data side of the relationship then configure sharepoint to allow that site as an exclusion url…….

Well no need I can do it with HttpHandlers in the same web part that is making the request, this should overcome the security issue of cross website posting, instead of having to resort to Dynanic Script calling using JSON (see links below)

http://tagneto.org/how/reference/js/DynamicScriptRequest.html

http://ajaxpatterns.org/On-Demand_Javascript

Now I haven’t tried it yet, bit busy at the minute, but I have no reason to believe it won’t work, after all the images thing did and this is very similar.

*Update* : It worked just fine, however I used Json output instead of trying to parse XML the end product seemed faster.  Also I still used the dynamic calling method, so this is not a full test of security bypassing but it keeps all code together, except for the remote data web service, as the json object is a web service proxy also.
Again you need to check that sharepoint is not being overloaded by your webpart being a httphandler

*Update Again* : I have more posts on this site and some working source code.  See
Ajax and Sharepoint
Ajax and Sharepoint 2
Yet another Ajax Sharepoint Part

tags: , , ,

Categories: development, Sharepoint Tags:

Dynamic Images from Web Parts

September 27th, 2006 No comments

What are you mad !! You can’t do it, how on earth are you going to suddenly be called again as an image and write binary data out.  

If you’ve read previous posts you will see that I have been writing a web part that gets SiteUsageData and displays it.  It uses some nasty COM+.  I got to thinking how on earth am I going to graph this dynamic data that changes per site?

HttpHandlers – for a bit more info on HttpHandlers see here on Scott Hanselman’s blog.

Now your up to speed on them, how can we use them with a part. 

First we have to spit out the IMG tag in your render section.

textWriter(“<img src=’_layouts/MyWebPartImage.ashx/’>”);

Of course that on its own does nothing, but note the url “_layouts”, not “/_layouts” this is very important as your part will run in the Site context of “/” if you do, instead of the current site.

Second you need to register this HttpHandler in web.config

<add verb=”GET” path=”MyWebPartImage.ashx” type=”Binaryjam.MyWebPartNs.MyWebPart, Binaryjam.MyWebPartNs, Version=1.0.0.0, Culture=neutral, PublicKeyToken=5**************d” />

Replace those details with your own namespace, typename, public key.  Ahh Did I say you need to GAC this part.  I haven’t experimented with not GACing this feel free to but to be sure GAC IT.

Third add the IHttpHAndler interface to your web part class

public class MyWebPart: WebPart, IHttpHandler

Nearly there now add your Interface methods, remember Scott’s article ? Here is a simple example of this:

public void ProcessRequest(HttpContext context)
{
    HttpResponse response=context.Response;
    HttpRequest request=context.Request;
    response.ContentType=”image/jpeg”

    Graphics g=null;
    System.Drawing.Image image=null;
    image=new Bitmap(Width,Height,PixelFormat.Format32bppArgb);
    g=Graphics.FromImage(image);
    g.FillRectangle(new SolidBrush
            (Color.White),0,0,image.Width,image.Height);
    g.DrawString(“YooHoo”,new Font(“Verdana”, 10.0f),
             new SolidBrush(Color.Black),0,0);
    image.Save(response.OutputStream,ImageFormat.Jpeg);

}

public bool IsReusable
{
  get
  {
    return true;
  }
}

These pieces of code give you the basics to dynamically generate an image from a web part.  Now because the webpart is being created again in the context of the site its running in in theory its Properties are populated, however you would need to check this.  For my use I only needed to now the site Context, I could then use the Sharepoint API and the site context

SPWeb thisWeb = SPControl.GetContextWeb(Context);

To get the data I need.  You could use the API to access list information in a site and graph that too.

And no I don’t have a full code example, my graphics code is too embarrassing.
:-)

 

Its here I might point out that doing this might be a really bad idea, lets face it we don’t know what’s happening behind the scenes, but lets have a guess.  You have already hit this page once to display the web part. To display the image the site is visited a second time, admittedly not the rendered page but the site all the same.  Now what could be happening here is that the Sharepoint httphandlers, because remember its not the aspx ones running, initialise loads of Sharepoint stuff.  Then you create a webpart, now either the Sharepoint context exists already of the webpart creates it, considering that on a page could be multiple web parts are they all creating contexts ? or calling a static to get it ?  Anything could be happening here.   On the other hand is it as bad as hosting an image held in a site list in a CWP part on your site ?  Probably very similar.

If there are any Sharepoint under-the-covers experts who know what’s happening, let me know please.

tags: sharepoint+webparts, sharepoint, GetUsageData, evil+voodoo+in+sharepoint

Categories: development, Sharepoint Tags:

Installing the COM+ .NET component

September 22nd, 2006 No comments

A couple of posts ago I talked about a GetUsageData webpart and how to access the data when not a site admin by using COM+ to retrieve the data.

But of course this needs to be installed.  Luckily for me we have a MSI library that Dan developed, which does all the sharepoint web part installation, as well as a host of other web based installation tasks that do not come out of the box with MS’s installation project.  But this only helps me with the webpart.

The earlier articles mention using Regsvsc to register the COM+ component or to allow lazy regristation.  Whilst manually registering is certainly better than lazy its still yet one more task that could be done as an MSI.

Here is a great article about registering COM+ components from start to finish with multiple methods. There is a section on writing an MSI installer class to acheive this using the .NET Library RegistrationHelper, it won’t take a genious for you to figure out how you can extend this to install your web part.

Note specifically the custom actions bit,  also look at custom action data as this is how you can get data into the MSI from the command line enabling unattended installations.  Also you can create a form in your dll to capture data in interactive mode to be fed into your installer (check /SILENT).

But is it enough, for me no.  RegistrationHelper does not let you configure the admin user details.  To achieve this you can do more.  First capture those details either from CustomActionData or your form. Then use techniques I found here

For those who hate vb.net here is some c#

Set a reference to COMAdmin library (its a COM one not .NET),  Have already registered the component in COM+ and stored the Package name in appID

catalog=new COMAdmin.COMAdminCatalog();
applications = (COMAdmin.COMAdminCatalogCollection)catalog.GetCollection(“Applications”);
applications.Populate();

foreach (COMAdmin.COMAdminCatalogObject applicationItem in applications)
{
    string s=applicationItem.Name.ToString() ;
    if (s==appID)
    {
        application=applicationItem;
        bGotOne=true;
        break;
    }
}

if (!bGotOne) return//I’m so slack !!

if (login.Length>0 && loginpwd.Length>0)
{
    application.set_Value(“Identity”, login);
    application.set_Value(“Password”,loginpwd);

    applications.SaveChanges();
}

Remember to Have GAC’d your component in code, and remember to uninstall all this too in the correct order.

Full list of articles I used to get here

http://www.carlosag.net/Articles/configureComPlus.aspx
http://www.15seconds.com/issue/030501.htm
http://blog.u2u.info/DottextWeb/patrick/archive/2004/10/20/235.aspx
http://blogs.microsoft.fr/rlondner/articles/7089.aspx

tags: , , , ,

Categories: development, Sharepoint Tags:

XNA Physics API

September 15th, 2006 No comments

Can’t speak for it but I found the link on the forum and thought I’d publish it, just to raise its profile a little more.

Project is here

tags: , ,

Categories: development, xna Tags: