Re: singleton ienumerable, need to add more...

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi Marc,

I appear at the moment to be taking a lot of knowledge, to the point where
you gave me the sample code. I felt a little guilty about this, however it
has really helped me along and I have learned one or two things along the
way and it is appreciated.

If I was to rerun the query again, you say to take out the Write Lock. How
would I do that?

I have overloaded the GetFolders method as I want to be able to just do
GetFolders (which would select top level parent), then select specifically
child folders of that parent, so that if need be, I can set up a recursive
loop. This appears to work excellent, but I would like you to cast your eye
over it and tell me if I am missing something, or have made an inefficient
mistake.

public static Folder[] GetFolders()
{
return GetFolders(0);
}

public static Folder[] GetFolders(int ParentFolderID)
{

DataTable ChildDT = DT.Copy(); // This line took me a while to work. I
was doing .Clone() but nothing was happening.
DataRow[] RowView = ChildDT.Select("FolderParent=" + ParentFolderID);

ArrayList ChildFolders = new ArrayList();

foreach (DataRow dr in RowView)
{
ChildFolders.Add(new Folder(dr));
}
ChildFolders.TrimToSize();

syncLock.AcquireReaderLock(Timeout.Infinite);
try
{
return (Folder[])ChildFolders.ToArray(typeof(Folder));
}
finally
{
syncLock.ReleaseReaderLock();
}
}

The only thing I can think of is that I am populating the arraylist quite
early on in the previous code, but with this new method, never getting a
chance to read it... Also, do I need to move the syncLock anywhere in the
GetFolders overload? In fact, as I am creating a new arraylist that will
only be around just for that instance, do I even need the syncLock?

When I am happy with this, then I can do the "ParentFolder" using a similar
method.

Would this code be quite easy to do something like...

GetFolders.GetFolders.GetFolders.GetFolders ? (the point being to try and
get the Great Grandchildren of the current folder... I have some sample
code somewhere to do the multiple dotted thing, so I will see if that can
easily be added.)

Once again, thanks for your help.

Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available


"Marc Gravell" <marc.gravell@xxxxxxxxx> wrote in message
news:1163886061.020726.79110@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
obj to DataRow dr
Good call; my "obj" was just a sampl - your code made it clear that
there was a ctor, but it wasn't shown, so I "failed safe"

I really do apologise for not having enough
knowledge in this area to fix it myself
No need to; the only way to obtain useful knowledge is to try things,
and you are showing that you *are* giving it a good go, so no apology.
Sometimes people post what amounts to "please do everything; I haven't
even tried"; you have given it fair effort.

1. static class
It will work identically without it; "static class" is just a handy way
of ensuring static semantics at the compiler level, but this can be
done with or without this new modifier

2. ArrayList, 3. ctor, 4. TrimToSize
Perfect

The array cast is unfortunately expected when using an ArrayList. There
is an overload to enable this cast:
return (Folder[])folders.ToArray(typeof(Folder));

rerun query etc
Fine, but for performance I would run the query first (getting the DT),
and then (once complete) take out the write-lock and update the
collection (probably Clear() and re-build from scratch)

foreach question
The nuicance is supporing the writer in a threaded environment (such as
ASP.NET; *highly* threaded); there are a few tricks, but I think that
they may be a little more troublesome long-term; personally, if I only
needed the data once (i.e. I don't need to loop 3 times), then I would
just use foreach(Folder folder in Folders.GetFolders()) {}.

List vs ArrayList
List<T> (not List) is a generic collection type; this means that it is
stronlgy-typed using a template type "T" (that is only decided by the
programmer later): List<Folder> knows that it is means to hold Folder
items, where-as ArrayList only knows about "object". Firstly this makes
it very easy (and safe) to use; as examples, ToArray() returns
Folder[], and folders[0] would return a Folder. It also means that you
cannot *possibly* add an incorrect typed object (such as a string). For
value-types this also avoids boxing etc, making it more efficient.

Marc



.



Relevant Pages

  • Re: Access th security descriptor
    ... There shouldn't be a problem with the permissions inherited from the parent ... folder, according to the KB article at ... It states that when you set the descriptor for an item, ... The same article contains some sample code, ...
    (microsoft.public.exchange2000.development)
  • Re: Incorporating a 3rd party driver into a BSP/Image
    ... any sample code, I though we were talking about a the Summit binaries. ... folder and run? ... As far as 'making it part of my BSP', I'm not sure what that means ... driver into its own catalog item and add/remove them from any OS ...
    (microsoft.public.windowsce.platbuilder)
  • Re: Creating Directories without AUTO Parent Propagation?
    ... If the parent directory has any specific user settings .. ... Then all new sub folders created below that folder will not have propagation ... As you can see the below script first does as follows.. ... > remove the the check / propagate from parent option.. ...
    (comp.os.ms-windows.nt.admin.security)
  • Re: Creating Directories without AUTO Parent Propagation?
    ... If the parent directory has any specific user settings .. ... Then all new sub folders created below that folder will not have propagation ... As you can see the below script first does as follows.. ... > remove the the check / propagate from parent option.. ...
    (comp.os.ms-windows.nt.admin.security)
  • Re: Containing folder from MailItem
    ... The Parent of the "Reply" has Outbox. ... > The Parent property of any item gives its folder. ... > body of the reply message to get the date/time of the original message. ...
    (microsoft.public.office.developer.outlook.forms)