Nebulae Spiral

Spiralling Golden… and maybe blogging about code.

Archive for August, 2008

Handy SPFolder / SPList / SPFile / SPWhatever interface, using Generics and Elevated Privs.

with one comment

This is a handly little lib I wrote for accessing various types of objects using generics. enjoy :-)

class SPDataAdapter
{
    public static T GetObject(string location)
    {
        object obj = null;
        SPSecurity.RunWithElevatedPrivileges(delegate
        {
            using (var site = new SPSite(location))
            {
                obj = site.OpenWeb().GetObject(location);
            }
        });
        return (T)obj;
    }
 
    public static T GetObject(string location, bool useElevatedPrivs)
    {
        if (useElevatedPrivs) return GetObject(location);
        using (var site = new SPSite(location))
        {
            return (T)site.OpenWeb().GetObject(location);
        }
    }
 
    public static SPList GetList(string location, bool useElevatedPrivs)
    {
        if (useElevatedPrivs) return GetList(location);
        using (var site = new SPSite(location))
        {
            return site.OpenWeb().GetList(location);
        }
    }
 
    public static SPList GetList(string location)
    {
        SPList list = null;
        SPSecurity.RunWithElevatedPrivileges(delegate
       {
            using (var site = new SPSite(location))
            {
                list = site.OpenWeb().GetList(location);
            }
        });
 
        return list;
 
   }
 
}

and to test:

 
[TestMethod()]
public void GetObjectTest1()
{
    GetObjectTest1Helper<SPFolder>();
}
 
public void GetObjectTest1Helper<T>()
{
    const string location = "http://spiral/Lists/Tasks";
    const bool useElevatedPrivs = true;
    var actual = SPDataAdapter.GetObject<T>(location, useElevatedPrivs);
    Assert.IsNotNull(actual);
}
 
[TestMethod()]
public void GetObjectTest()
{
    GetObjectTestHelper<SPFile>();
}
 
public void GetObjectTestHelper<T>()
{
    const string location = "http://spiral/Lists/Tasks/Attachments/1/nebulae.jpg";
    T actual = SPDataAdapter.GetObject<T>(location);
    Assert.IsNotNull(actual);
}

Written by Nebulae

August 28th, 2008 at 11:01 am

Posted in code

Tagged with , ,

YouTube – Martin Luther King, Jr. on War

without comments

Written by Nebulae

August 22nd, 2008 at 12:07 pm

Posted in personal

SPList Factory – singleton access to your lists.

with one comment

A few months ago I was doing a refresher in GOF design patterns.  I have a couple favorites: memento, observer, state, and the factory of course :-)

So I was trying to implement these patterns in a conceptual SPAL ( sp access layer ), and what I’ve found is that having a SPListWrapper object, and a factory to create them and allow static access is *the bees knees*, especially if you want to implement an ajax interface.  Since you only load the list once, its pretty speedy too.

I absolutely love ajax and making the sharepoint interface more robust and seamless.  Any interface for that matter.  there is a library i use exclusively that covers all browsers and addresses the issues found in each of them, even the pesky ie memory leak.

What Im getting at is that I have a bunch of cool stuff to share that probably would become convoluted in a mass array of blog entries, so I think it would be worthwhile to vlog it.  stay tuned, could take a  few days while.

Written by Nebulae

August 6th, 2008 at 1:17 pm

xkcd – A webcomic of romance, sarcasm, math, and language – By Randall Munroe

without comments

Written by Nebulae

August 6th, 2008 at 10:38 am

Posted in personal

Tagged with

Paris Hilton Responds to McCain Ad from Paris Hilton, Chris Henchy, and Adam “Ghost Panther” McKay

without comments

See more Paris Hilton videos at Funny or Die

Written by Nebulae

August 5th, 2008 at 9:35 pm

Posted in personal

sunshine

without comments

a pack of wild butterflies just flew through my yard,
the morning glories are jealous.

Written by Nebulae

August 3rd, 2008 at 4:15 pm

Posted in personal, random

Tagged with , ,

Save Conflict in workflow on SPListItem.Update or SystemUpdate

with one comment

in this scenario, I have a really simple workflow that creates a task, does some infopath approval stuff, then copies that list item to another list. the kicker is when you want to add something about that copied item to the original item, say an id column so you have a reference. after saving the copy, you set a column on the original and try to update the listitem, and get a “save conflict” error.

Ive seen a lot of posts on this error, most of them point to not having access to that listitem because its locked by the workflow itself. I would assume that you can somehow capture the item before the workflow updates it, and set the properties you want. could someone enlighten me if this is true? I’ve seen posts saying to use a delay, to wrap it in a repeating try / catch until the item is unlocked, to try programmatically to check it out, and then save it. I can’t see any of this as being best answer.

What Ive decided is to attach an event handler to the second list to set the id in the first. this seems to be pretty reliable, plus I already had an event handler on that list. I’m really curious to know if there’s a resolution for this.

other info on this issue:
http://forums.msdn.microsoft.com/en-US/sharepointdevelopment/thread/641b40fb-614f-4266-95c0-d61c2f443146/

Written by Nebulae

August 1st, 2008 at 2:16 am

Posted in code

Tagged with , , ,

I think I should start painting.

without comments

I have visions of abstract spirals I can’t find in any art on ebay. anyone else? I’m thinking red and black with a grey borders, mathematically perfect yet chaotic. very large. and planetary. I would attempt it with photoshop, but I don’t think my brain works that way very well. There is something to be said with creating something physically with your hands, as opposed to a kbd+clicker thing. I have some vacation time coming to me, Id like to see what I can come up with. I wanna see what life without code is for long enough to get used to it :)

life without email would sorta kick ass. you know what does kick ass? kexp.

what am i doing here…
alt+t enter w enter space alt+tab F5 F10 F10 F10 F5? repeat?

Written by Nebulae

August 1st, 2008 at 1:44 am

Posted in personal

Tagged with , , ,