OSG Community College C# for Programmers Class #3 Log 02/24/2009

1 view
Skip to first unread message

AdelleF

unread,
Mar 3, 2009, 1:37:37 PM3/3/09
to OSG Community College
Pastebin's are at the bottom of the log.

[2009/02/24 12:01] Snowdrop Short: hi
[2009/02/24 12:01] Snowdrop Short: I look cloudy
[2009/02/24 12:01] Snowdrop Short: I know
[2009/02/24 12:02] Snowdrop Short: nothing I can do about it right
now, I'm afraid
[2009/02/24 12:02] Adelle Fitzgerald: not a cloud to me, just wearing
white
[2009/02/24 12:02] Adelle Fitzgerald: M1sha is the same
[2009/02/24 12:02] Adelle Fitzgerald: its wierd, i seem to be
impervious to it
[2009/02/24 12:02] Snowdrop Short: your're the lucky one
[2009/02/24 12:02] Adelle Fitzgerald: maybe its something to do with
me wearing so many prims all the time ;)
[2009/02/24 12:03] Snowdrop Short: I think it has to do with the
database problems we had today
[2009/02/24 12:03] Adelle Fitzgerald: its been on and off since Diva
made the changes to the avatar appearence I think
[2009/02/24 12:03] Adelle Fitzgerald: thats how it seems to me anyway
[2009/02/24 12:03] Snowdrop Short: maybe, I don't really know
[2009/02/24 12:04] Adelle Fitzgerald: its too random to pinpoint it I
think
[2009/02/24 12:04] Snowdrop Short: too many moving parts I think
[2009/02/24 12:04] Snowdrop Short: hello M1sha
[2009/02/24 12:04] Adelle Fitzgerald: anyway, i went over last
thursdays stuff a bit, i havent had much time to yet, but I think i
get it now, at least 99% of it
[2009/02/24 12:05] M1sha Dallin: Hi Snowdrop
[2009/02/24 12:05] Snowdrop Short smiles, that's good to hear
[2009/02/24 12:05] Snowdrop Short: is there anything I can do to
help?
[2009/02/24 12:05] Adelle Fitzgerald: i think if I see a few more
different examples of classes it will sink in a bit more
[2009/02/24 12:05] M1sha Dallin: I revisited my groups solution -
http://www.pastebin.ca/1346078
[2009/02/24 12:06] Adelle Fitzgerald: not yet. I need to see more
working examples of it I think
[2009/02/24 12:06] Adelle Fitzgerald: hi Starky
[2009/02/24 12:06] Starky Rubble: hello all
[2009/02/24 12:06] Adelle Fitzgerald: i will give you a shout though
if I need :)
[2009/02/24 12:06] BlueWall Slade: Hi everyone
[2009/02/24 12:06] M1sha Dallin: Hi Starky, Blue
[2009/02/24 12:06] Snowdrop Short: hello Starky
[2009/02/24 12:07] Adelle Fitzgerald: i dunno why, i seem to learn
better from reverse engineering a fully working example
[2009/02/24 12:07] Adelle Fitzgerald: and i think that is why I
struggled so mych on Thursday, because it wasnt complete
[2009/02/24 12:07] Snowdrop Short: that's not uncommon
[2009/02/24 12:07] Adelle Fitzgerald: its how I tought myself LSL
[2009/02/24 12:07] Starky Rubble: there are many ways up the mountain
lol
[2009/02/24 12:07] Adelle Fitzgerald: but no cablecar hehe
[2009/02/24 12:07] Adelle Fitzgerald P
[2009/02/24 12:08] Snowdrop Short smiles, that would be nice
[2009/02/24 12:08] Starky Rubble: Snowdrop has a towrope perhaps?
[2009/02/24 12:08] Adelle Fitzgerald: all i need is a synaptic
interface to my brain, that would work well hehe
[2009/02/24 12:09] Snowdrop Short: Right now I have an inventory
which is a disaster
[2009/02/24 12:09] Starky Rubble: heh
[2009/02/24 12:09] Adelle Fitzgerald: still not got it sorted
Snowdrop?
[2009/02/24 12:09] Snowdrop Short: it's gotten worse
[2009/02/24 12:09] Adelle Fitzgerald: oh no
[2009/02/24 12:09] Starky Rubble: brb
[2009/02/24 12:09] Snowdrop Short: besides, I've spent a lot of time
out ot world
[2009/02/24 12:09] Adelle Fitzgerald nods
[2009/02/24 12:10] Snowdrop Short: coding on my own little project
[2009/02/24 12:10] Snowdrop Short: have you all done your home work?
[2009/02/24 12:10] M1sha Dallin: yep
[2009/02/24 12:11] Snowdrop Short: ok..
[2009/02/24 12:12] Starky Rubble: yes
[2009/02/24 12:12] Snowdrop Short: the topic of today will be more of
the wonders of classes
[2009/02/24 12:12] M1sha Dallin: :-)
[2009/02/24 12:13] Snowdrop Short: last we had two teams
[2009/02/24 12:13] Snowdrop Short: each working on their part of the
the application
[2009/02/24 12:14] Snowdrop Short: and that gave rise to some
problems and questions, I believe
[2009/02/24 12:15] Snowdrop Short: because, the team working on the
list of groups wondered who was responsible for getting the groups and
group members into their "containers"
[2009/02/24 12:15] Snowdrop Short: because we really had a hierarchy
[2009/02/24 12:15] Snowdrop Short: members inside groups inside a
grouplist
[2009/02/24 12:15] Starky Rubble: yes
[2009/02/24 12:16] Snowdrop Short: so today, we'll look at some some
solutions commonly used in object oriented programming for dealing
with that
[2009/02/24 12:16] Snowdrop Short: and how to write that is c#
[2009/02/24 12:17] Snowdrop Short: lets first think about the
difference between groups and lists of groups
[2009/02/24 12:17] Snowdrop Short: in what way are they different,
and in what ways are they similar?
[2009/02/24 12:17] Starky Rubble: well they're both 'containers'
[2009/02/24 12:18] Adelle Fitzgerald: different because they contain
different information, the same in the fact they are like starky says,
containers
[2009/02/24 12:18] Starky Rubble: of other objects
[2009/02/24 12:18] Adelle Fitzgerald: or objects
[2009/02/24 12:18] Adelle Fitzgerald: a list of groups is the
container for the 'group' object
[2009/02/24 12:18] Starky Rubble: they have similar needs
[2009/02/24 12:18] Snowdrop Short: so maybe we could try to exploit
that they are kind of similar
[2009/02/24 12:19] M1sha Dallin: In principle they are the same -
just slightly different content
[2009/02/24 12:19] Adelle Fitzgerald: and the list of groups is 'the'
container for the groups?
[2009/02/24 12:19] Starky Rubble: both the Group and GroupList
objects, need to add, remove, and list their members
[2009/02/24 12:19] Snowdrop Short: byt the grouplist works on groups
and groups works on members
[2009/02/24 12:20] Starky Rubble: yes
[2009/02/24 12:20] Snowdrop Short: so maybe if we could find some
commonality between groups and members
[2009/02/24 12:20] Starky Rubble: ah
[2009/02/24 12:20] M1sha Dallin: They each have a Guid and Name
[2009/02/24 12:20] Starky Rubble: they are both really collections of
UUID/GUIDs
[2009/02/24 12:20] Adelle Fitzgerald: guid?
[2009/02/24 12:21] Snowdrop Short: guid is a .net/mono term UUID is
the exact same thing
[2009/02/24 12:21] Snowdrop Short: just in OpenSim/SecondLife
[2009/02/24 12:21] Snowdrop Short: some say URI
[2009/02/24 12:21] Snowdrop Short: others URL
[2009/02/24 12:21] Snowdrop Short: but they both mean the same
[2009/02/24 12:21] Snowdrop Short: unless they are very very purists
[2009/02/24 12:22] Starky Rubble: potato potahto
[2009/02/24 12:22] Adelle Fitzgerald: global is different to
universal, but i wont go there now ;)
[2009/02/24 12:22] Snowdrop Short: and the method of genertion is
slightly different
[2009/02/24 12:22] Snowdrop Short: but they still do the same
[2009/02/24 12:22] Adelle Fitzgerald: agreed
[2009/02/24 12:22] Starky Rubble: good
[2009/02/24 12:23] Snowdrop Short: so maybe if we had some container
for holding on to a name and a guid
[2009/02/24 12:23] Snowdrop Short: we could use that in both member
and group
[2009/02/24 12:23] Adelle Fitzgerald: yes, so the member could
reference the group and vice versa
[2009/02/24 12:23] Adelle Fitzgerald: ?
[2009/02/24 12:24] Starky Rubble: ok
[2009/02/24 12:24] Snowdrop Short: hold on pastebinning
[2009/02/24 12:24] M1sha Dallin: A question - may be getting ahead of
myself here
[2009/02/24 12:25] M1sha Dallin: In Ada you can define a generic with
a base type that say contained a Guid and Name
[2009/02/24 12:25] Snowdrop Short: yes
[2009/02/24 12:25] M1sha Dallin: then create an instance that used
the base type but was extended by other data
[2009/02/24 12:25] Starky Rubble: like a struct
[2009/02/24 12:25] M1sha Dallin: can that be done in C#?
[2009/02/24 12:26] Snowdrop Short: yes , it can
[2009/02/24 12:26] Starky Rubble: I bet we are just about to find out
lol
[2009/02/24 12:26] M1sha Dallin: OK - ty :-)
[2009/02/24 12:26] Snowdrop Short: that's what we will be doing now
[2009/02/24 12:28] Starky Rubble: still here?
[2009/02/24 12:28] M1sha Dallin: yep
[2009/02/24 12:28] Adelle Fitzgerald: yep
[2009/02/24 12:28] Starky Rubble: ok
[2009/02/24 12:28] Snowdrop Short: http://www.pastebin.ca/1346151
[2009/02/24 12:28] Snowdrop Short: I have reused some of your
solutions
[2009/02/24 12:29] Starky Rubble: yes
[2009/02/24 12:30] Snowdrop Short: http://www.pastebin.ca/1346153
[2009/02/24 12:30] Snowdrop Short: try this one
[2009/02/24 12:30] Snowdrop Short: I had a slight mistake
[2009/02/24 12:30] Snowdrop Short: notice the differece?
[2009/02/24 12:30] Starky Rubble: yes
[2009/02/24 12:30] Adelle Fitzgerald: i did yes, the lower case 'id'
[2009/02/24 12:31] Snowdrop Short: that's because the first parameter
for the constructor is "ID"
[2009/02/24 12:31] Snowdrop Short: it's always difficult to use that
thing and have propper capitalization
[2009/02/24 12:32] Snowdrop Short: what we have done here is called
"inheritance"
[2009/02/24 12:32] Snowdrop Short: we are saying that we have a class
called "GroupBase"
[2009/02/24 12:32] Snowdrop Short: and that Group is an extension to
"GroupBase"
[2009/02/24 12:33] Snowdrop Short: the terminology is a little
confusing
[2009/02/24 12:33] Snowdrop Short: because we call the more
specialized version as SUB-class
[2009/02/24 12:33] Snowdrop Short: and that we have SUB-classed
GroupBase
[2009/02/24 12:34] Snowdrop Short: so Group is a subclass of
GroupBase
[2009/02/24 12:34] M1sha Dallin: Is naming a group ...base
significant?
[2009/02/24 12:34] Snowdrop Short: no, it's just a name
[2009/02/24 12:34] M1sha Dallin: ok
[2009/02/24 12:34] Snowdrop Short: but it kind of implies that it is
not a complete thing
[2009/02/24 12:35] M1sha Dallin: but base is a keyword?
[2009/02/24 12:35] Starky Rubble: sure
[2009/02/24 12:35] M1sha Dallin: as used in line 21?
[2009/02/24 12:35] Snowdrop Short: when you see something called
"base" it usually implies that it is intended to be extended
[2009/02/24 12:35] Adelle Fitzgerald: does 'this' refer to the class?
[2009/02/24 12:36] Snowdrop Short: base is a way to call the
constructor of the "base" class
[2009/02/24 12:36] Starky Rubble: the current object
[2009/02/24 12:36] Starky Rubble: is this
[2009/02/24 12:36] Snowdrop Short: the one we inherit from
[2009/02/24 12:36] Adelle Fitzgerald: right
[2009/02/24 12:36] Snowdrop Short: it is kind of like this
[2009/02/24 12:36] Snowdrop Short: but in this case refers to
"GroupBase"
[2009/02/24 12:37] Snowdrop Short: hold on.. let me give one more
example of that
[2009/02/24 12:37] Snowdrop Short: brb
[2009/02/24 12:37] Adelle Fitzgerald: kk
[2009/02/24 12:39] Snowdrop Short: http://www.pastebin.ca/1346160
[2009/02/24 12:39] Snowdrop Short: there
[2009/02/24 12:39] Snowdrop Short: notice how I changed
"WriteToConsole"
[2009/02/24 12:40] Starky Rubble: it just writes the base class
[2009/02/24 12:41] Starky Rubble: GroupBase to be precise
[2009/02/24 12:41] M1sha Dallin: and adds on the extras
[2009/02/24 12:41] Snowdrop Short: there is a "new" keyword on the
"WriteToConsole"
[2009/02/24 12:41] Snowdrop Short: so this way, Group delegates to
GroupBase when writing to the console
[2009/02/24 12:42] Snowdrop Short: and then add's the specific
information it has
[2009/02/24 12:42] Snowdrop Short: that way
[2009/02/24 12:42] Snowdrop Short: if you did a change in
"GroupBase", you know "Group" will print the correct information
[2009/02/24 12:42] Starky Rubble: right
[2009/02/24 12:43] Snowdrop Short: we could do the same thing to
GroupList
[2009/02/24 12:44] Snowdrop Short scans the room for confused faces
[2009/02/24 12:44] Starky Rubble: found one!
[2009/02/24 12:44] M1sha Dallin: Think I'm OK :-)
[2009/02/24 12:45] Starky Rubble: Ok so the new in the WriteToConsole
is how one uses inheritance when working with a sub-class
[2009/02/24 12:45] Snowdrop Short: it is one way
[2009/02/24 12:45] Starky Rubble: ok
[2009/02/24 12:45] Snowdrop Short: there are two ways
[2009/02/24 12:45] Starky Rubble: ok
[2009/02/24 12:46] Snowdrop Short: it really depends on what you want
[2009/02/24 12:46] Snowdrop Short: let me give an example
[2009/02/24 12:50] Snowdrop Short: http://www.pastebin.ca/1346171
[2009/02/24 12:50] Snowdrop Short: if you look at this code
[2009/02/24 12:51] M1sha Dallin: you go cross-eyed
[2009/02/24 12:51] M1sha Dallin: too many Groupbases for me :-)
[2009/02/24 12:51] Snowdrop Short: the ToString is the catch here
[2009/02/24 12:51] Starky Rubble: I see it. brb - rl... sorry
[2009/02/24 12:52] Adelle Fitzgerald: so that converts the GroupBase
into a single string?
[2009/02/24 12:52] Snowdrop Short: there are two methods called
ToString
[2009/02/24 12:52] Snowdrop Short: in each class they try to format
the class into some kind of string
[2009/02/24 12:53] Snowdrop Short: so when the WriteToConsole in
Group is called
[2009/02/24 12:54] Snowdrop Short: it calls base.WriteToConsole
[2009/02/24 12:54] Snowdrop Short: which in turn calls it's own
ToString()
[2009/02/24 12:54] Starky Rubble: yes
[2009/02/24 12:55] Snowdrop Short: we handle that using "base"
[2009/02/24 12:55] Snowdrop Short: but we can actually get c# to do
that automatically
[2009/02/24 12:56] Snowdrop Short: we wouldn't have to implement
WriteToConsole in "Group"
[2009/02/24 12:58] Snowdrop Short: it's used with the keywords
"virtual" and "override"
[2009/02/24 13:00] Snowdrop Short: remember almost everything in C#
is an object
[2009/02/24 13:00] Snowdrop Short: http://www.pastebin.ca/1346180
[2009/02/24 13:01] Snowdrop Short: all object inherit implicitly from
a class called "Object"
[2009/02/24 13:01] Snowdrop Short: one of the methods on "Object" is
called "ToString()
[2009/02/24 13:01] Snowdrop Short: in "GroupBase" we have told that
we want to replace that method with our own
[2009/02/24 13:02] Snowdrop Short: and we have done the same think
with Group
[2009/02/24 13:03] M1sha Dallin: cryptic - but OK when you work it
out
[2009/02/24 13:05] Snowdrop Short: I have an example for you here
[2009/02/24 13:05] Snowdrop Short: http://www.pastebin.ca/1346187
[2009/02/24 13:08] Snowdrop Short: try to run this program
[2009/02/24 13:08] Snowdrop Short: http://www.pastebin.ca/1346192
[2009/02/24 13:08] Snowdrop Short: and let me know what you think is
happening
[2009/02/24 13:09] Snowdrop Short: it is a bit surprising
[2009/02/24 13:09] M1sha Dallin: The Guids are wrong
[2009/02/24 13:11] Snowdrop Short: not really
[2009/02/24 13:11] M1sha Dallin: They are identical and zero
[2009/02/24 13:11] Snowdrop Short: if you replace "new Guid()" with
"Guid.NewGuid()"
[2009/02/24 13:11] Snowdrop Short: you will have "non" null guids
[2009/02/24 13:11] M1sha Dallin: That will work - been there
[2009/02/24 13:12] Snowdrop Short: new Guid() produces
"00000000-0000-0000-0000-000000000000"
[2009/02/24 13:12] Snowdrop Short: NewGuid() will generate a new
"Random" one
[2009/02/24 13:13] Snowdrop Short: have you tried running it?
[2009/02/24 13:13] M1sha Dallin: Lines seem to be duplicated
[2009/02/24 13:14] M1sha Dallin: --------------------------------
ID=00000000-0000-0000-0000-000000000000 Name=Base Group
--------------------------------
ID=00000000-0000-0000-0000-000000000000 Name=Base Group
--------------------------------
Description=For cool people, #of Members 0
--------------------------------
Description=For cool people, #of Members 0
Description=For cool people, #of Members 0
--------------------------------
[2009/02/24 13:14] Adelle Fitzgerald: yes, its repeating itself at
least twice.... is that because it is using the WriteToConsole() and
the Console.Writeline to do the same thing?
[2009/02/24 13:15] Snowdrop Short: the first line calls the ToString
() on b
[2009/02/24 13:15] Snowdrop Short: and prints the contents of b
[2009/02/24 13:15] Snowdrop Short: no surprises there
[2009/02/24 13:15] Adelle Fitzgerald nods
[2009/02/24 13:16] Snowdrop Short: the second line, callss
"WriteToConsole" on b, but since b's WriteToConsole, just calls
ToString
[2009/02/24 13:16] Snowdrop Short: it does the same thing
[2009/02/24 13:16] Snowdrop Short: the third calls ToString on g
[2009/02/24 13:16] Snowdrop Short: and no surprises there
[2009/02/24 13:16] Adelle Fitzgerald: yep, i think I understand that
[2009/02/24 13:16] Snowdrop Short: but the forth
[2009/02/24 13:17] Snowdrop Short: fourth
[2009/02/24 13:17] Snowdrop Short: that's the mystery
[2009/02/24 13:17] Snowdrop Short: it calls g's "WriteToConsols"
[2009/02/24 13:17] Adelle Fitzgerald: ahhh
[2009/02/24 13:17] Adelle Fitzgerald: there are two groups
[2009/02/24 13:17] Adelle Fitzgerald: no
[2009/02/24 13:17] Adelle Fitzgerald: hmm
[2009/02/24 13:18] Snowdrop Short: the first line comes from
"base.WriteToConsole"
[2009/02/24 13:18] Snowdrop Short: which delegates to GroupBase's
"WriteToConsole"
[2009/02/24 13:18] Snowdrop Short: but here is the surprise
[2009/02/24 13:18] Snowdrop Short: GroupBases ToString
[2009/02/24 13:19] Snowdrop Short: it does something unexpected
[2009/02/24 13:19] Snowdrop Short: it actually calls back into
"Group"
[2009/02/24 13:19] M1sha Dallin: Why?
[2009/02/24 13:19] Snowdrop Short: because of the keyword "override"
[2009/02/24 13:20] Snowdrop Short: we have override on ToString() and
GroupBase knows that it has been SUB-classed
[2009/02/24 13:20] M1sha Dallin: ok - so it's the tostring used by
the tostring in group?
[2009/02/24 13:21] Snowdrop Short: yes, it is the tostring in group
which is being called, because one "overrides" the other
[2009/02/24 13:22] Snowdrop Short: I have almost the same program
ready for you
[2009/02/24 13:22] Snowdrop Short: http://www.pastebin.ca/1346200
[2009/02/24 13:22] Snowdrop Short: try running this one
[2009/02/24 13:23] Snowdrop Short: I have replaced the keyword
"override" on ToString in Group to "new"
[2009/02/24 13:23] Snowdrop Short: this way we have told "GroupBase"
to ignore that it has been sub-classed
[2009/02/24 13:24] Snowdrop Short: and now it prints the thing we
expected
[2009/02/24 13:24] Snowdrop Short: in object oriented programming we
talk about
[2009/02/24 13:24] Snowdrop Short: virtual and non virtual members
[2009/02/24 13:24] Snowdrop Short: virtual members knows about being
subclassed
[2009/02/24 13:24] Snowdrop Short: and non virtual ones ignores the
subclassing
[2009/02/24 13:25] Snowdrop Short: why is this relevant?
[2009/02/24 13:25] Snowdrop Short: and important to know?
[2009/02/24 13:25] Snowdrop Short: would you venture a guess?
[2009/02/24 13:26] Adelle Fitzgerald: when using the same class for
different information, like when you create the group, or when group
members are added
[2009/02/24 13:27] M1sha Dallin: Need to stop somewhere - something
must be non virtual
[2009/02/24 13:27] Snowdrop Short: yes, both are correct, sometimes
you need to let the inheritance flow, sometimes it needs to stop
[2009/02/24 13:27] Snowdrop Short: I'll give you and example
[2009/02/24 13:27] Snowdrop Short: lets take a look at ArrayList
[2009/02/24 13:28] Snowdrop Short: what is it really?
[2009/02/24 13:28] Adelle Fitzgerald: a table?
[2009/02/24 13:28] Snowdrop Short: and what does that table contain?
[2009/02/24 13:28] Adelle Fitzgerald: rows, columns, information
[2009/02/24 13:29] Snowdrop Short: basically it is an array of
objects
[2009/02/24 13:29] Snowdrop Short: more specifically the class
defined in "System.Object"
[2009/02/24 13:30] Snowdrop Short: like I said, every class in
mono/.net inherits from that class
[2009/02/24 13:30] Snowdrop Short: we haven't written it any where,
in our code, the compiler does that for us automatically
[2009/02/24 13:30] Adelle Fitzgerald: but the arraylist can contain
strings, integers etc, it can contain objects too?
[2009/02/24 13:31] Snowdrop Short: a string is a kind of object
[2009/02/24 13:31] Starky Rubble: pointers prolly
[2009/02/24 13:31] Starky Rubble: an array is a list of references to
objects?
[2009/02/24 13:31] Snowdrop Short: when you put an integer into an
array list it is being "boxed" into an object
[2009/02/24 13:31] Adelle Fitzgerald: and that 'box' is an object?
[2009/02/24 13:31] Snowdrop Short: yes, it references objects
[2009/02/24 13:32] Snowdrop Short: yes, that box is an object
[2009/02/24 13:32] Snowdrop Short: yes, and the term used is "boxing"
and "undboxing"
[2009/02/24 13:32] Adelle Fitzgerald: unboxing meaning?
[2009/02/24 13:32] Snowdrop Short: "unboxing" even
[2009/02/24 13:33] Starky Rubble: really! lol
[2009/02/24 13:33] Snowdrop Short: taking the integer back out of the
object, and restoring it as an integer
[2009/02/24 13:33] Adelle Fitzgerald: hehe, wouldnt that be
'reboxing'? :P
[2009/02/24 13:33] Snowdrop Short: I haven't made up the terms :-)
[2009/02/24 13:33] Adelle Fitzgerald: i understand though
[2009/02/24 13:33] Adelle Fitzgerald: i think
[2009/02/24 13:34] Adelle Fitzgerald: getting there
[2009/02/24 13:34] Snowdrop Short: remember that I sometimes use the
term "handle"
[2009/02/24 13:34] Snowdrop Short: and the variable we use to
reference an object
[2009/02/24 13:34] Snowdrop Short: like the b and g in "Main"
[2009/02/24 13:34] Adelle Fitzgerald: yes, im starting to come to
grips with that
[2009/02/24 13:34] Adelle Fitzgerald: umm, no pun intended
[2009/02/24 13:35] Snowdrop Short: lets take a look at statement 51
[2009/02/24 13:35] Snowdrop Short: foreach (Group GroupMember in
_Members) GroupMember.WriteToConsole();
[2009/02/24 13:35] Snowdrop Short: I could write that another way
[2009/02/24 13:36] Snowdrop Short: foreach (object o in _Members)
Console.WriteLine(o.ToString();
[2009/02/24 13:36] Adelle Fitzgerald nods
[2009/02/24 13:36] M1sha Dallin: I prefer the former
[2009/02/24 13:37] Snowdrop Short: since all classes inherit from
"object"
[2009/02/24 13:37] Snowdrop Short: then a handle to an object can be
used to hold on to anything we get out of the ArrayList
[2009/02/24 13:37] Snowdrop Short: so what would happen
[2009/02/24 13:38] Snowdrop Short: which version of "ToString()"
would be called
[2009/02/24 13:38] Snowdrop Short: the one on object?
[2009/02/24 13:38] Snowdrop Short: the one on "GroupBase"
[2009/02/24 13:38] Snowdrop Short: the one on "Group"=
[2009/02/24 13:38] Snowdrop Short: ?
[2009/02/24 13:38] Starky Rubble: GroupBase because its the lowest
[2009/02/24 13:38] M1sha Dallin: The one to which the object maps?
[2009/02/24 13:38] M1sha Dallin: group
[2009/02/24 13:39] Starky Rubble: heh he
[2009/02/24 13:39] Snowdrop Short: it will start from Object, and
walk as far down the intheritance chain it can
[2009/02/24 13:40] M1sha Dallin: Which is Group? Sine it inherits
from GroupBase
[2009/02/24 13:40] M1sha Dallin: and that inherits from object?
[2009/02/24 13:41] Snowdrop Short: remember in the latest version, we
broke inhertiance at GroupBase
[2009/02/24 13:41] Snowdrop Short: http://www.pastebin.ca/1346222
[2009/02/24 13:41] Starky Rubble: its looking at Members as it goes
right?
[2009/02/24 13:41] Snowdrop Short: yes
[2009/02/24 13:41] Snowdrop Short: take a look at the program I just
uploaded
[2009/02/24 13:42] Snowdrop Short: look in the Main
[2009/02/24 13:42] Snowdrop Short: that last statement:
[2009/02/24 13:42] Snowdrop Short: in 79
[2009/02/24 13:43] Snowdrop Short: Console.WriteLine(o.ToString());
[2009/02/24 13:43] Snowdrop Short: what does it print?
[2009/02/24 13:43] Adelle Fitzgerald: repeats Console.WriteLine
(g.ToString());
[2009/02/24 13:43] M1sha Dallin: OK - Groupbase
[2009/02/24 13:43] M1sha Dallin: since it can't go further
[2009/02/24 13:44] Snowdrop Short: it stops at groupbase, because we
used "new" in the ToString of Group
[2009/02/24 13:44] Snowdrop Short: if we had used "Override" the
result would have been different
[2009/02/24 13:44] M1sha Dallin: my brain hurts :-)
[2009/02/24 13:44] Adelle Fitzgerald: mine too
[2009/02/24 13:44] Snowdrop Short: yes.. this is torture
[2009/02/24 13:45] Starky Rubble: indeed
[2009/02/24 13:45] Snowdrop Short: inhertance is powerfull, but it
must be done with care
[2009/02/24 13:46] Snowdrop Short: what would happen if I had
written:
[2009/02/24 13:46] Snowdrop Short: o.WriteToConsole(); ????
[2009/02/24 13:46] Adelle Fitzgerald: it would fail
[2009/02/24 13:47] Snowdrop Short: why?
[2009/02/24 13:47] Adelle Fitzgerald: there is no WriteToConsole() in
'object'
[2009/02/24 13:48] Snowdrop Short: but we know that it really is a
Group
[2009/02/24 13:48] Adelle Fitzgerald: i kinda cheated there, my IDE
told me that... but....
[2009/02/24 13:48] Adelle Fitzgerald: it is trying to look for an
object within an object that doesnt exist?
[2009/02/24 13:49] Snowdrop Short: the handle "o" is of type "object"
[2009/02/24 13:49] Snowdrop Short: and the handle doesn't know about
"WriteToConsole"
[2009/02/24 13:49] M1sha Dallin: but the object knows what it is?
[2009/02/24 13:49] Snowdrop Short: so if we need to access
"WriteToConsole" we need to put it into a different handle
[2009/02/24 13:50] Snowdrop Short: now I can be mean or not so mean,
what would you prefer?
[2009/02/24 13:50] M1sha Dallin: I'd go not so mean - or less
even :-)
[2009/02/24 13:50] Adelle Fitzgerald: could you use:
o.Group.WriteToConsole();?
[2009/02/24 13:50] Snowdrop Short: something like that
[2009/02/24 13:51] Snowdrop Short: but the way you write it in c# is
this:
[2009/02/24 13:51] Snowdrop Short: Group g2 = (Group)o;
[2009/02/24 13:51] Snowdrop Short: g2.WriteToConsole();
[2009/02/24 13:52] Snowdrop Short: what we are doing is called "type
casting"
[2009/02/24 13:52] Snowdrop Short: we cast or mold the object into a
new handle
[2009/02/24 13:52] Starky Rubble: like typecating in a way - o is now
rederred to as a Group object
[2009/02/24 13:52] Starky Rubble: sheesh
[2009/02/24 13:52] Snowdrop Short: the "(Group)" tells the compiler
what it should mold it to
[2009/02/24 13:53] M1sha Dallin: can that be dangerous?
[2009/02/24 13:53] M1sha Dallin: or will it only allow the cast if
the structures match?
[2009/02/24 13:53] Snowdrop Short: yes, casting in that direction it
can be dangerous
[2009/02/24 13:53] Snowdrop Short: because what if the object held by
"o" isn't really a "group"
[2009/02/24 13:54] Snowdrop Short: remember ArrayList can hold any
kind of object
[2009/02/24 13:54] Snowdrop Short: even boxed integers
[2009/02/24 13:54] M1sha Dallin: A reason not to use an ArrayList
[2009/02/24 13:54] Snowdrop Short: yes
[2009/02/24 13:54] Snowdrop Short: so if you by mistake put an
integer into the arraylist
[2009/02/24 13:55] Snowdrop Short: you will get an error when casting
[2009/02/24 13:55] Snowdrop Short: we talk about "downcasting" and
"upcasting"
[2009/02/24 13:56] Starky Rubble: float -> int and int->float
[2009/02/24 13:56] Adelle Fitzgerald: is that where you would change
the array;list 'box' from say an object, as in group ro an integer, or
vice versa?
[2009/02/24 13:56] Snowdrop Short: all sort of things
[2009/02/24 13:56] Adelle Fitzgerald: *from
[2009/02/24 13:56] Adelle Fitzgerald: umm to...
[2009/02/24 13:57] Adelle Fitzgerald: so what was contained as the
group becomes an interger/string whatever
[2009/02/24 13:57] Snowdrop Short: it would be pretty safe to write
this
[2009/02/24 13:57] Starky Rubble: meaning toward or from a lower
level class?
[2009/02/24 13:57] Snowdrop Short: GroupBase b2 = (GroupBase)g;
[2009/02/24 13:57] Snowdrop Short: yes
[2009/02/24 13:58] Adelle Fitzgerald: ohhh
[2009/02/24 13:58] Adelle Fitzgerald: so changing the hiarachy of the
object?
[2009/02/24 13:58] Snowdrop Short: up casting like this is always
safe
[2009/02/24 13:58] Snowdrop Short: down casting the otherway can
introduce errors
[2009/02/24 13:58] Snowdrop Short: yes
[2009/02/24 13:59] Snowdrop Short: arraylist was introduced in the
very first version of .net
[2009/02/24 13:59] M1sha Dallin: unitialised data in the object?
[2009/02/24 13:59] Snowdrop Short: and a lot of people were unhappy
with it
[2009/02/24 13:59] Snowdrop Short: all data in C# is initialized to a
default value
[2009/02/24 13:59] Snowdrop Short: 0 for numbers
[2009/02/24 13:59] Snowdrop Short: null for strings and object
handles
[2009/02/24 14:00] Snowdrop Short: there are two problems
[2009/02/24 14:00] Snowdrop Short: when you store integers in an
arraylist
[2009/02/24 14:00] Snowdrop Short: they need to be box when entering
[2009/02/24 14:00] Snowdrop Short: and unboxed when leaving
[2009/02/24 14:00] Snowdrop Short: and arraylist only stores objects
[2009/02/24 14:01] Starky Rubble: oh
[2009/02/24 14:01] Snowdrop Short: so you are always forced to
downcast what ever you take out
[2009/02/24 14:01] Snowdrop Short: either downcast or unbox
[2009/02/24 14:01] Snowdrop Short: boxing and unboxing costs cpu time
[2009/02/24 14:01] M1sha Dallin: Dictionary seemed a better choice of
structure to me
[2009/02/24 14:01] Snowdrop Short: and the otherthing can introduce
bugs
[2009/02/24 14:02] Snowdrop Short: so in version 2.0 of .net they
introduced something called generics
[2009/02/24 14:02] Starky Rubble: ok
[2009/02/24 14:02] Snowdrop Short: and introduced some new syntax
[2009/02/24 14:02] Snowdrop Short: changed af few names, in order to
avoid confusion
[2009/02/24 14:02] Snowdrop Short: so in the namespace
[2009/02/24 14:02] Snowdrop Short: System.Collections
[2009/02/24 14:03] Snowdrop Short: (the old one from 1.1)
[2009/02/24 14:03] Snowdrop Short: we have a list of objects called
ArrayList
[2009/02/24 14:03] Snowdrop Short: then in 2.0
[2009/02/24 14:03] Snowdrop Short: they introduced the namespace
[2009/02/24 14:04] Snowdrop Short: System.Collection.Generic
[2009/02/24 14:04] Snowdrop Short: and within that they defined a
List
[2009/02/24 14:04] Snowdrop Short: as List does almost the same as an
array list
[2009/02/24 14:04] Snowdrop Short: but the way you declare it is
different
[2009/02/24 14:04] Snowdrop Short: you write
[2009/02/24 14:05] Snowdrop Short: List<Group> _groups = new
List<Group>();
[2009/02/24 14:05] Snowdrop Short: note the "<Group>"
[2009/02/24 14:05] Snowdrop Short: this way you tell the compiler
that it should make sure that only objects of type "Group" goes in
[2009/02/24 14:06] Snowdrop Short: that that only "Group" types may
leave it again
[2009/02/24 14:06] Starky Rubble: ok so it casts the list when
creating it
[2009/02/24 14:06] Snowdrop Short: yes, and the compiler makes sure
that everything checks out
[2009/02/24 14:06] Snowdrop Short: better safety
[2009/02/24 14:07] Snowdrop Short: and you can also do
[2009/02/24 14:07] Starky Rubble: much more robust
[2009/02/24 14:07] Snowdrop Short: List<int> integers = new List<int>
();
[2009/02/24 14:07] Snowdrop Short: no more boxing and unboxing
[2009/02/24 14:07] Snowdrop Short: that was possibly the greatest
improvement in 2.0
[2009/02/24 14:08] Snowdrop Short: when I started this class I didn't
want to start out with explaining what
[2009/02/24 14:08] Snowdrop Short: List<Group> meant
[2009/02/24 14:08] Snowdrop Short: so I decided to go for ArrayList
in my first examples
[2009/02/24 14:08] Adelle Fitzgerald nods
[2009/02/24 14:08] Starky Rubble: shift happens lol
[2009/02/24 14:09] Snowdrop Short: but now we've learned enough to
understand what it means
[2009/02/24 14:09] Snowdrop Short: and from now on, I would prefer
that you forget that "ArrayList" ever existed
[2009/02/24 14:09] Starky Rubble: ok...
[2009/02/24 14:09] Snowdrop Short: like a bad dream
[2009/02/24 14:09] M1sha Dallin: sounds good to me
[2009/02/24 14:09] Adelle Fitzgerald: so that could be used to stop
malicious code being inputted?
[2009/02/24 14:09] Snowdrop Short: :-)
[2009/02/24 14:09] Snowdrop Short: it protects you from your own
mistakes :-)
[2009/02/24 14:10] Adelle Fitzgerald: okies
[2009/02/24 14:10] Adelle Fitzgerald: :)
[2009/02/24 14:10] Adelle Fitzgerald: but....
[2009/02/24 14:10] Snowdrop Short: which is a lot more common that
malicious code :-)
[2009/02/24 14:10] Snowdrop Short: at least I know my mistakes are
[2009/02/24 14:10] Snowdrop Short: yes ....
[2009/02/24 14:10] Adelle Fitzgerald: if you wanted a 'list' to
contain different objects, strings and integers then you would have to
use ArrayList?
[2009/02/24 14:11] Snowdrop Short: if you really wanted that
[2009/02/24 14:11] Snowdrop Short: then yes
[2009/02/24 14:11] Starky Rubble: or create a class that accomodates
yer need
[2009/02/24 14:11] Adelle Fitzgerald: right
[2009/02/24 14:11] Snowdrop Short: like with all things,
[2009/02/24 14:11] Snowdrop Short: the right tool for the right task
[2009/02/24 14:11] Snowdrop Short: but most of the time "ArrayList"
is not the answer
[2009/02/24 14:11] Snowdrop Short: it can be though
[2009/02/24 14:12] Starky Rubble: got it
[2009/02/24 14:12] M1sha Dallin: and be defensive - your code will
bite back if you aren't :-)
[2009/02/24 14:12] Adelle Fitzgerald: but if you had to create two
List<> to contain integers and strings, would that require more memory
and cpu?
[2009/02/24 14:12] Snowdrop Short: if you really need to mix the two,
then go for an ArrayList
[2009/02/24 14:12] Adelle Fitzgerald nods
[2009/02/24 14:13] Snowdrop Short: there are no real firm rules
[2009/02/24 14:13] Starky Rubble: as they say, "you have been warned"
lol
[2009/02/24 14:13] Snowdrop Short: you know like the "code" in the
Pirates of the Carribian
[2009/02/24 14:13] Snowdrop Short: it's more like guidelines
[2009/02/24 14:13] Snowdrop Short: :-)
[2009/02/24 14:13] M1sha Dallin: :-)
[2009/02/24 14:14] Adelle Fitzgerald: its just with us working on
'groups' there would be lots of different types, DateTime, strings
etc... so it would require a lot more code to produce the end result,
right?
[2009/02/24 14:14] Snowdrop Short: I think not
[2009/02/24 14:14] Snowdrop Short: but we'll see as we progress along
[2009/02/24 14:14] Starky Rubble: make a list of objects that can
hold the data
[2009/02/24 14:14] Adelle Fitzgerald: okies
[2009/02/24 14:14] Adelle Fitzgerald: ahhh
[2009/02/24 14:14] Snowdrop Short: there is nothing preventing us
from writing
[2009/02/24 14:14] Adelle Fitzgerald: i see now
[2009/02/24 14:14] Adelle Fitzgerald: public ArrayList
_PermittedRoles;
public ArrayList _Members;
[2009/02/24 14:15] Adelle Fitzgerald: could become List<> of each
[2009/02/24 14:15] Snowdrop Short: List<GroupBase> gb;
[2009/02/24 14:15] Snowdrop Short: gb = new List<Groupbase>();
[2009/02/24 14:15] Snowdrop Short: gb.Add(new Group("second", "The
second group"));
[2009/02/24 14:16] Snowdrop Short: I know the last one does a lot
[2009/02/24 14:16] Adelle Fitzgerald nods
[2009/02/24 14:16] Snowdrop Short: but since Group is a kind of
GroupBase, everything checks out
[2009/02/24 14:16] Starky Rubble: List must have many predefined
methods
[2009/02/24 14:17] Snowdrop Short: yes, quite a few
[2009/02/24 14:17] Starky Rubble: good
[2009/02/24 14:17] Snowdrop Short: the framework for .net/mono is
huge
[2009/02/24 14:17] Snowdrop Short: I doubt anybody knows it all
[2009/02/24 14:18] Snowdrop Short: maybe a very few people with
incredible good memories does
[2009/02/24 14:18] Snowdrop Short: but I know I certainly don't
[2009/02/24 14:18] Adelle Fitzgerald: its all on MSDN though right?
[2009/02/24 14:18] Snowdrop Short: it all on MSDN
[2009/02/24 14:19] Snowdrop Short: and you can just press f1 in your
IDE
[2009/02/24 14:19] Starky Rubble: theres beauty in that
[2009/02/24 14:19] Snowdrop Short: learing the framework is like
learning the functions available in LSL
[2009/02/24 14:19] Adelle Fitzgerald: oooo
[2009/02/24 14:19] M1sha Dallin: some of MSDN seems ivery opaque
[2009/02/24 14:19] Adelle Fitzgerald: awesome
[2009/02/24 14:19] Adelle Fitzgerald: its like what LL never did with
LSL
[2009/02/24 14:19] Adelle Fitzgerald: ;)
[2009/02/24 14:20] Snowdrop Short: yes ... but then again, LSL is a
specialist language for a special purpose
[2009/02/24 14:20] Snowdrop Short: c# is a full fledged language for
everything
[2009/02/24 14:21] Adelle Fitzgerald: true, but that wouldnt have
been hard for LL to do, and would be very very useful
[2009/02/24 14:21] M1sha Dallin: arrays would have been good in LSL
[2009/02/24 14:21] Snowdrop Short: they have only so many resources
[2009/02/24 14:21] Snowdrop Short: yes, very good
[2009/02/24 14:21] Adelle Fitzgerald: but yes, this is C# and that is
LSL
[2009/02/24 14:21] M1sha Dallin: We can now script in C#
[2009/02/24 14:22] Snowdrop Short: yes, I think the tools for doing
that are a bit primitive
[2009/02/24 14:22] Snowdrop Short: but it can be done
[2009/02/24 14:22] Snowdrop Short: it is pretty difficult to do a
"Console.WriteLine" in a c# opensim script
[2009/02/24 14:23] Starky Rubble: c# is the current incarnation of
ther dream Tim Button and other early MS langauge evangelists were
heading for with Quick Basic back in the 80s
[2009/02/24 14:23] Snowdrop Short: besides, it would be printed on
the console of the server
[2009/02/24 14:23] Starky Rubble: a universal process control
scripting language
[2009/02/24 14:23] Snowdrop Short: maybe
[2009/02/24 14:23] Snowdrop Short: the way I see it, it is an
improved version of java
[2009/02/24 14:24] Adelle Fitzgerald: but couls we not call on the
object that defines 'llSay' ?
[2009/02/24 14:24] Snowdrop Short: yes, and that's what you'll have
to do
[2009/02/24 14:24] Adelle Fitzgerald: cool
[2009/02/24 14:24] Starky Rubble: it was definitely a reply to the
Sun effort
[2009/02/24 14:25] Snowdrop Short: I really don't have much more on
the agenda for today
[2009/02/24 14:25] Snowdrop Short: except handling any questions you
might have
[2009/02/24 14:25] Starky Rubble: cool thanks for straining my brain
[2009/02/24 14:25] Adelle Fitzgerald: mine too
[2009/02/24 14:25] Adelle Fitzgerald: hehe
[2009/02/24 14:26] M1sha Dallin: mine is definitely strained
[2009/02/24 14:26] Adelle Fitzgerald: and i'm deffo getting more to
grips with 'objects' and 'handles'
[2009/02/24 14:26] Snowdrop Short: remember we've covered a huge
thing today
[2009/02/24 14:26] M1sha Dallin: but I think I may be able to do what
I tried to do over the weekend
[2009/02/24 14:26] Snowdrop Short: inheritance is not a simple thing
[2009/02/24 14:26] Adelle Fitzgerald: objects arent for me
[2009/02/24 14:26] Adelle Fitzgerald: but it is becomeing clearer
[2009/02/24 14:27] M1sha Dallin: A class diagram for the groups
problem would help
[2009/02/24 14:27] M1sha Dallin: I keep confusing myself
[2009/02/24 14:27] Snowdrop Short: the thing is, you have to think
completely oppsite in object oriented languages
[2009/02/24 14:27] M1sha Dallin: I'll have a go at drawing one
[2009/02/24 14:27] Snowdrop Short: it takes a while to adjust to that
[2009/02/24 14:27] Adelle Fitzgerald: yes
[2009/02/24 14:28] Adelle Fitzgerald: today, i only thought of LSL
about 3 times ;)
[2009/02/24 14:28] Adelle Fitzgerald: hehe
[2009/02/24 14:28] Snowdrop Short: do you know those bicycles, where
if you turn the handle bar one way, the weels go the opposite
direction?
[2009/02/24 14:29] M1sha Dallin: yep
[2009/02/24 14:29] Adelle Fitzgerald: when i started i kept trying to
compare C# to LSL, andwas just making my brain hurt
[2009/02/24 14:29] M1sha Dallin: everyone falls off
[2009/02/24 14:29] Adelle Fitzgerald: yes Snowdrop
[2009/02/24 14:29] Adelle Fitzgerald: hehe
[2009/02/24 14:29] Snowdrop Short: this is like learinging to ride
one of those
[2009/02/24 14:29] Snowdrop Short: in the beginning it's completely
impossible to do, you always think of it the wrong way
[2009/02/24 14:30] M1sha Dallin: L-) I feel like I fell off and
landed on my head
[2009/02/24 14:30] Adelle Fitzgerald: thing is, that is only one
object with 3 functions, this is loads!
[2009/02/24 14:30] Snowdrop Short: but pretty soon, it feels like the
natural way
[2009/02/24 14:30] Starky Rubble: well - im letting the handlebars be
- Im just peddling like crazy lol
[2009/02/24 14:30] M1sha Dallin: :-)
[2009/02/24 14:31] Snowdrop Short: so, don't get discouraged, it
think it will get easier from here
[2009/02/24 14:31] Adelle Fitzgerald: thats why i come every time, i
know it will all drop into place soon
[2009/02/24 14:31] Starky Rubble: yep
[2009/02/24 14:31] Snowdrop Short: ok.. so see you next time
[2009/02/24 14:32] M1sha Dallin: OK - thankyou Snowdrop
[2009/02/24 14:32] Adelle Fitzgerald: okies Snowdrop, and thank you
[2009/02/24 14:32] BlueWall Slade: I have to read teh log, I was AFK
most all of the session
[2009/02/24 14:32] Snowdrop Short: and as usual if you have any
questions, drop by on IRC
[2009/02/24 14:32] Adelle Fitzgerald nods
[2009/02/24 14:32] M1sha Dallin: will do
[2009/02/24 14:32] BlueWall Slade: thanks
[2009/02/24 14:32] Starky Rubble: Its true Snowdro[
[2009/02/24 14:32] Adelle Fitzgerald: i really appreciate your time
for these classes
[2009/02/24 14:32] Starky Rubble: in 87 I spent a week in Redmond
[2009/02/24 14:32] Snowdrop Short: thank you listening to me babble
along
[2009/02/24 14:32] Adelle Fitzgerald: :)





http://www.pastebin.ca/1346078

using System;
using System.Collections;
using System.Collections.Generic;
using Groups;

namespace Groups
{

//
--------------------------------------------------------------------
public class GroupMember
{
// define the information needed to describe a group member
public GroupMember(Guid memberGuid, string memberTitle,
DateTime memberSince)
{
//_MemberName = memberName; Removed - Name/Guid
translation should be elsewhere, we only need store one
_MemberGuid = memberGuid;
_MemberTitle = memberTitle;
_MemberSince = memberSince;
}

public void WriteToConsole()
{
Console.WriteLine("Member GUID={0}, Title {1}, Last Login
{2}", _MemberGuid, _MemberTitle, _MemberSince);
}


//public string _MemberName;
public Guid _MemberGuid;
public string _MemberTitle;
public DateTime _MemberSince;
}

//
--------------------------------------------------------------------
public class GroupRole
{
// define the information needed to describe a group role
public GroupRole(string roleName, string permissions)
{
_RoleName = roleName;
_RoleGuid = Guid.NewGuid();
_Permissions = permissions; //This should be a bit field
of some form TBD
}

List<GroupRole> GroupRoles = new List<GroupRole>();

public string _RoleName;
public Guid _RoleGuid;
public string _Permissions;

}

//
--------------------------------------------------------------------
public class Group
{
// Constructor
public Group(string name, string description)
{
this._Name = name;
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

// Write Group Details on the Console
public void WriteToConsole()
{
Console.WriteLine("Name={0}, Description={1}, #of Members
{2}", _Name, _Description, _Members.Count);
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}


//
--------------------------------------------------------------------

public class GroupDictionary
{
// The GroupDictionary structure
Dictionary<Guid, Group> _OSGroups = new Dictionary<Guid,Group>
();

//TODO - Locking - this is not thread safe

// Private Methods

// Method: Determine if a group exists in the GroupDictionary,
search on GroupGuid
// Parameters: in GroupName
// Return: true if the group exists
// false if the group does not exist
//
private Boolean GroupExists(Guid GroupGuid)
{
if (_OSGroups.ContainsKey(GroupGuid))
{
return true;
}
return false;
}

// Public Methods

// Method: Determine if a group name exists in the
GroupDictionary and return the Guid
// Parameters: in GroupName
// Return: Guid if a group of that name exists
// Guid.Empty if a group of that name does not
exist
//
public Guid GetGuidFromGroupName(string GroupName)
{
foreach (KeyValuePair<Guid, Group> pair in _OSGroups)
{
if (pair.Value._Name == GroupName)
{
return pair.Key;
}
}
return Guid.Empty;
}


// Method: to add a new group to the GroupDictionary
// Parameters: in Group
// Return: Guid if group is successfully added
// Guid.Empty if a group of the same name already
exists
//
public Guid Add (Group GroupDetail)
{
Guid GroupGuid = Guid.NewGuid();

if ((GetGuidFromGroupName (GroupDetail._Name) !=
Guid.Empty)) return Guid.Empty;

_OSGroups.Add(GroupGuid, GroupDetail);

return GroupGuid;
}


// Method: to delete a group from the GroupDictionary
// Parameters: in GroupGuid
// Return: true if group is successfully deleted
// false if the group cannot be located
//
public Boolean Delete(Guid GroupGuid)
{
if (GroupExists(GroupGuid))
{
_OSGroups.Remove(GroupGuid);
return true;
}
return false;
}


// Method: to delete a group from the GroupDictionary
// Parameters: in GroupName
// Return: true if group is successfully deleted
// false if the group cannot be located
//
public Boolean Delete(string GroupName)
{
return Delete(GetGuidFromGroupName(GroupName));
}



// Method: to update a group in the GroupDictionary
// Parameters: in GroupName
// Return: true if group is successfully updated
// false if the group cannot be located
//
public Boolean UpdateDescription(Guid GroupGuid, string
GroupDescription)
{
if (GroupExists(GroupGuid))
{
_OSGroups [GroupGuid]._Description = GroupDescription;
return true;
}
return false;
}

// Method: to update a group in the GroupDictionary
// Parameters: in Group
// Return: true if group is successfully updated
// false if the group cannot be located
//
public Boolean UpdateDescription(string GroupName, string
GroupDescription)
{
return UpdateDescription(GetGuidFromGroupName(GroupName),
GroupDescription);
}

//Method: to update the Members List for a Group
// ToDo

//Method: To update the PermittedRoles for a Group
// ToDo


// Method: to write details of all groups in the
GroupDictionary to the Console
// Parameters: None
// Return: None
//
public void WriteGroupDictionaryToConsole()
{
foreach (KeyValuePair<Guid, Group> pair in _OSGroups)
{
pair.Value.WriteToConsole();
}
}
}
}



namespace Testing
{

//
--------------------------------------------------------------------
class MainClass
{
public static void Main(string[] args)
{
GroupDictionary AllGroups = new GroupDictionary();

// Test of Method AddToDictionary
if (AllGroups.Add(new Group("Group 1", "Test Group 1")) !=
Guid.Empty) Console.WriteLine("Test 1 Passed");
if (AllGroups.Add(new Group("Group 2", "Test Group 2")) !=
Guid.Empty) Console.WriteLine("Test 2 Passed");
if (AllGroups.Add(new Group("Group 2", "Test Group 2")) ==
Guid.Empty) Console.WriteLine("Test 3 Passed");
if (AllGroups.Add(new Group("Group 3", "Test Group 3")) !=
Guid.Empty) Console.WriteLine("Test 4 Passed");


// Test of Method CheckNameInDictionary
if (AllGroups.GetGuidFromGroupName("Group 1") !=
Guid.Empty) Console.WriteLine("Test 5 Passed");
if (AllGroups.GetGuidFromGroupName("Group 16") ==
Guid.Empty) Console.WriteLine("Test 6 Passed");

// Test of Method DeleteFromDictionary
Console.WriteLine("Groups 1, 2 and 3 should be listed
below");
AllGroups.WriteGroupDictionaryToConsole();

if (AllGroups.Delete("Group 3"))
{
if (!AllGroups.Delete("Group 3"))
{
Console.WriteLine("Test 7 Passed");
}
}

if (AllGroups.Delete("Group 1")) Console.WriteLine("Test 8
Passed");

Console.WriteLine("Groups 2 only should be listed below");
AllGroups.WriteGroupDictionaryToConsole();

// Test of Method UpdateInDictionary
if (AllGroups.UpdateDescription("Group 2", "Changed
Description")) Console.WriteLine("Test 9 Passed");
Console.WriteLine("Group 2 should have a changed
description field");
AllGroups.WriteGroupDictionaryToConsole();
}
}
}



http://www.pastebin.ca/1346151

using System;
using System.Collections;

namespace Groups
{
public class GroupBase
{
public GroupBase(Guid ID, string name)
{
this.ID = id;
this.Name = name;
}

public Guid ID;
public string Name;
}

public class Group : GroupBase
{
// Constructor
public Group(string name, string description) : base(new Guid
(), name)
{
this._Name = name;
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

// Write Group Details on the Console
public void WriteToConsole()
{
Console.WriteLine("Name={0}, Description={1}, #of Members
{2}", _Name, _Description, _Members.Count);
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}


}




http://www.pastebin.ca/1346153

using System;
using System.Collections;

namespace Groups
{
public class GroupBase
{
public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;
}

public class Group : GroupBase
{
// Constructor
public Group(string name, string description) : base(new Guid
(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

// Write Group Details on the Console
public void WriteToConsole()
{
Console.WriteLine("Name={0}, Description={1}, #of Members
{2}", Name, _Description, _Members.Count);
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}


}




http://www.pastebin.ca/1346160

using System;
using System.Collections;

namespace Groups
{
public class GroupBase
{
public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine("ID={0} Name={1}", ID, Name);
}

}

public class Group : GroupBase
{
// Constructor
public Group(string name, string description) : base(new Guid
(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

// Write Group Details on the Console
public new void WriteToConsole()
{
base.WriteToConsole();
Console.WriteLine("Description={1}, #of Members {2}",
_Description, _Members.Count);
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}


}




http://www.pastebin.ca/1346171

using System;
using System.Collections;

namespace Groups
{
public class GroupBase
{
public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}

public class Group : GroupBase
{
// Constructor
public Group(string name, string description) : base(new Guid
(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public string ToString()
{
return string.Format("Description={1}, #of Members {2}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public new void WriteToConsole()
{
base.WriteToConsole();
Console.WriteLine(ToString());
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}


}




http://www.pastebin.ca/1346180

using System;
using System.Collections;

namespace Groups
{
public class GroupBase
{
public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}

public class Group : GroupBase
{
// Constructor
public Group(string name, string description) : base(new Guid
(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

override public string ToString()
{
return string.Format("Description={1}, #of Members {2}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public new void WriteToConsole()
{
base.WriteToConsole();
Console.WriteLine(ToString());
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
public static void Main(string[] args)
{

}
}
}




http://www.pastebin.ca/1346187

using System;
using System.Collections;

namespace Groups
{
public class GroupBase
{
public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}

public class Group : GroupBase
{
// Constructor
public Group(string name, string description) : base(new Guid
(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

override public string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public new void WriteToConsole()
{
base.WriteToConsole();
Console.WriteLine(ToString());
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
public static void Main(string[] args)
{
GroupBase b = new GroupBase(new Guid(), "Base Group");
Console.WriteLine(b.ToString());

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
}
}
}




http://www.pastebin.ca/1346192

using System;
using System.Collections;

namespace Groups
{
public class GroupBase
{
public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}

public class Group : GroupBase
{
// Constructor
public Group(string name, string description) : base(new Guid
(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

override public string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public new void WriteToConsole()
{
base.WriteToConsole();
Console.WriteLine(ToString());
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
public static void Main(string[] args)
{
GroupBase b = new GroupBase(new Guid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole();
Console.WriteLine("--------------------------------");
}
}
}




http://www.pastebin.ca/1346200

using System;
using System.Collections;

namespace Groups
{
public class GroupBase
{
public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}

public class Group : GroupBase
{
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public new void WriteToConsole()
{
base.WriteToConsole();
Console.WriteLine(ToString());
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
public static void Main(string[] args)
{
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole();
Console.WriteLine("--------------------------------");
}
}
}




http://www.pastebin.ca/1346222

using System;
using System.Collections;

namespace Groups
{
public class GroupBase
{
public GroupBase(Guid ID, string name)
{
this.ID = ID;
this.Name = name;
}

public Guid ID;
public string Name;

override public string ToString()
{
return string.Format("ID={0} Name={1}", ID, Name);
}

// Write Bae Details on the Console
public void WriteToConsole()
{
Console.WriteLine(ToString());
}

}

public class Group : GroupBase
{
// Constructor
public Group(string name, string description) : base
(Guid.NewGuid(), name)
{
this._Description = description;
this._PermittedRoles = new ArrayList();
this._Members = new ArrayList();

}

public new string ToString()
{
return string.Format("Description={0}, #of Members {1}",
_Description, _Members.Count);
}

// Write Group Details on the Console
public new void WriteToConsole()
{
base.WriteToConsole();
Console.WriteLine(ToString());
foreach (Group GroupMember in _Members)
GroupMember.WriteToConsole();
}

// Type definitions for the Group Structure
public string _Name;
public string _Description;
public ArrayList _PermittedRoles;
public ArrayList _Members;

}

class MainClass
{
public static void Main(string[] args)
{
GroupBase b = new GroupBase(Guid.NewGuid(), "Base Group");
Console.WriteLine("--------------------------------");
Console.WriteLine(b.ToString());
Console.WriteLine("--------------------------------");
b.WriteToConsole();
Console.WriteLine("--------------------------------");

Group g = new Group("The real group", "For cool people");
Console.WriteLine(g.ToString());
Console.WriteLine("--------------------------------");
g.WriteToConsole();
Console.WriteLine("--------------------------------");
object o = g;
Console.WriteLine(o.ToString());
}
}
}
Reply all
Reply to author
Forward
0 new messages