Fwd: 25 new messages in 9 topics - digest


TOPIC: Texture.FromBitmap is slow runing from debugger
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/3fad64d6f02d470a?hl=en
==============================================================================

== 1 of 3 ==
Date: Sun, May 11 2008 12:34 pm
From: "Peter Duniho"


On Sun, 11 May 2008 03:45:09 -0700, colin <colin.rowe1@ntworld.NOSPAM.com>
wrote:

> Hi,
> Ive written a 3dmodel editor, and it works fairly well
> it harldy uses any cpu exept when its loading a texture from bitmap
> in the debugger, at all other times it hardly uses any cpu
> but from the debugger even in release mode it takes a second or so
> to load a 65k texture, with a 2ghz pc this is 10k instructions per pixel
> !

Where is the data in the Bitmap located?  If you are copying data that's
in video memory already, that can indeed be very slow, depending on the
video bus your hardware has.

Beyond that, this is just not the newsgroup for your question.  Your
question has zero to do with C# or .NET, and if you want a _good_ answer,
you need to post it in a newsgroup where it's on-topic and people familiar
with the issues are reading.  For example, a newsgroup specifically about
using DirectX and/or using DirectX in managed code.

Pete




== 2 of 3 ==
Date: Sun, May 11 2008 2:53 pm
From: "colin"


"Peter Duniho" <NpOeStPeAdM@nnowslpianmk.com> wrote in message
news:op.uaz8ncby8jd0ej@petes-computer.local...
> On Sun, 11 May 2008 03:45:09 -0700, colin <colin.rowe1@ntworld.NOSPAM.com>
> wrote:
>
>> Hi,
>> Ive written a 3dmodel editor, and it works fairly well
>> it harldy uses any cpu exept when its loading a texture from bitmap
>> in the debugger, at all other times it hardly uses any cpu
>> but from the debugger even in release mode it takes a second or so
>> to load a 65k texture, with a 2ghz pc this is 10k instructions per pixel
>> !
>
> Where is the data in the Bitmap located?  If you are copying data that's
> in video memory already, that can indeed be very slow, depending on the
> video bus your hardware has.
>
> Beyond that, this is just not the newsgroup for your question.  Your
> question has zero to do with C# or .NET, and if you want a _good_ answer,
> you need to post it in a newsgroup where it's on-topic and people familiar
> with the issues are reading.  For example, a newsgroup specifically about
> using DirectX and/or using DirectX in managed code.
>
> Pete

well its real fast without the debugger attatched...
so it must be something todo with c#/.net with the way the debugger
handles managed to unmanaged transitions although its using managed directx.

if i press ctrl-f5 to run the program independantly or run it normally it
runs
and loads the bitmaps almost instantly. same in both release and debug build
versions.
ive tried saving the bitmap to a memory stream and loading it from there.

Il ask in the gamers forum though thanks ...

Colin =^.^=






== 3 of 3 ==
Date: Sun, May 11 2008 4:26 pm
From: "Peter Duniho"


On Sun, 11 May 2008 14:53:27 -0700, colin <colin.rowe1@ntworld.NOSPAM.com>
wrote:

> well its real fast without the debugger attatched...
> so it must be something todo with c#/.net with the way the debugger
> handles managed to unmanaged transitions although its using managed
> directx. [...]

Sorry.  I missed the "debugger" aspect of your question.  Reading too fast
I guess.

I still don't know the answer, but I suppose there's a slightly higher
chance of you getting an answer here than I first thought, if it's a
debugger-specific problem.

Pete





==============================================================================
TOPIC: IEnumerable objects are essentially arrays, right?
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/3f98344137cc00de?hl=en
==============================================================================

== 1 of 7 ==
Date: Sun, May 11 2008 1:13 pm
From: gnewsgroup


I've read the msdn doc about IEnumerable. It seems to me that
IEnumerable objects are essentially wrapped-up arrays. It simply gives
us the foreach convenience. Is this correct?




== 2 of 7 ==
Date: Sun, May 11 2008 1:54 pm
From: Jon Skeet [C# MVP]


gnewsgroup <gnewsgroup@gmail.com> wrote:
> I've read the msdn doc about IEnumerable. It seems to me that
> IEnumerable objects are essentially wrapped-up arrays. It simply gives
> us the foreach convenience. Is this correct?

No, not at all.

IEnumerable represents a sequence of items - but unlike arrays:

1) It doesn't provide random access; you basically have to go forwards
(or start again)

2) It's read-only

3) IEnumerable is an *interface* - it can be implemented any way that's
appropriate

4) Arrays are always totally in-memory. IEnumerable implementations can
enumerate anything; for instance, it could enumerate each line in a web
response *as it arrives* without even knowing how long the response is.
Heck, you could enumerate an infinite random number sequence - it's up
to the caller to quit when they want to.

<blatant plug>
See http://www.manning-source.com/books/skeet/Chapter6sample.pdf for
rather more about the iterator pattern.
</blatant plug>

--
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon.skeet
C# in Depth: http://csharpindepth.com




== 3 of 7 ==
Date: Sun, May 11 2008 2:27 pm
From: gnewsgroup


Jon Skeet [ C# MVP ] wrote:
> gnewsgroup <gnewsgroup@gmail.com> wrote:
> > I've read the msdn doc about IEnumerable. It seems to me that
> > IEnumerable objects are essentially wrapped-up arrays. It simply gives
> > us the foreach convenience. Is this correct?
>
> No, not at all.
>
> IEnumerable represents a sequence of items - but unlike arrays:
>
> 1) It doesn't provide random access; you basically have to go forwards
> (or start again)
>
> 2) It's read-only
>
> 3) IEnumerable is an *interface* - it can be implemented any way that's
> appropriate
>
> 4) Arrays are always totally in-memory. IEnumerable implementations can
> enumerate anything; for instance, it could enumerate each line in a web
> response *as it arrives* without even knowing how long the response is.
> Heck, you could enumerate an infinite random number sequence - it's up
> to the caller to quit when they want to.
>
> <blatant plug>
> See http://www.manning-source.com/books/skeet/Chapter6sample.pdf for
> rather more about the iterator pattern.
> </blatant plug>
>
> --
> Jon Skeet - <skeet@pobox.com>
> Web site: http://www.pobox.com/~skeet
> Blog: http://www.msmvps.com/jon.skeet
> C# in Depth: http://csharpindepth.com

Thank you. I know IEnumerable is an interface.  I didn't mean
IEnumerable objects and arrays are exactly the same.  I notice that
quite often the constructor of an IEnumerable class takes an array as
the argument, and I think foreach internally makes use of the MoveNext
method. Is it the case that the core of an IEnumerable object is an
array? Thanks.




== 4 of 7 ==
Date: Sun, May 11 2008 2:44 pm
From: Pavel Minaev


On May 12, 1:27 am, gnewsgroup <gnewsgr...@gmail.com> wrote:

> Thank you. I know IEnumerable is an interface.  I didn't mean
> IEnumerable objects and arrays are exactly the same.  I notice that
> quite often the constructor of an IEnumerable class takes an array as
> the argument, and I think foreach internally makes use of the MoveNext
> method. Is it the case that the core of an IEnumerable object is an
> array? Thanks.

No, it is not. It all depends on which particular implementation of
IEnumerable you take. E.g. array itself is IEnumerable. List<T> is
IEnumerable and also wraps an array. But LinkedList<T> is IEnumerable,
and is not an array, nor does it behave like one (you can't access
elements by index). Another example would be method Enumerable.Range()
in .NET 3.5 - you give it a lower and an upper bound, and returns an
implementation of IEnumerable that produces numbers in that range. It
would be implemented something like this:

class Range : IEnumerable<int>
{
 private int lowerBound, upperBound;

 public Range(int lowerBound, int upperBound)
 {
   this.lowerBound = lowerBound;
   this.upperBound = upperBound;
 }

 public IEnumerator<int> GetEnumerator()
 {
   for (int i = lowerBound; i <= upperBound; ++i)
   {
     yield return i;
   }
 }
}

As you can notice, there are no arrays here at all...

The concept that IEnumerable represents is actually a "sequence" (a
finite or an infinite one - noone says that MoveNext() ever has to
return false!). "Array" is a more specific concept - to quote
Wikipedia, "In computer science an array is a data structure
consisting of a group of elements that are accessed by indexing. In
most programming languages each element has the same data type and the
array occupies a contiguous area of storage.". Obviously, any array is
also a sequence, but not every sequence is an array or even array-like
(since not every sequence can be indexed, and some - e.g.
Dictionary<T> and HashSet<T> - do not even have any specific ordering).




== 5 of 7 ==
Date: Sun, May 11 2008 4:10 pm
From: gnewsgroup


On May 11, 5:44 pm, Pavel Minaev <int...@gmail.com> wrote:
> On May 12, 1:27 am, gnewsgroup <gnewsgr...@gmail.com> wrote:
>
> > Thank you. I know IEnumerable is an interface.  I didn't mean
> > IEnumerable objects and arrays are exactly the same.  I notice that
> > quite often the constructor of an IEnumerable class takes an array as
> > the argument, and I think foreach internally makes use of the MoveNext
> > method. Is it the case that the core of an IEnumerable object is an
> > array? Thanks.
>
> No, it is not. It all depends on which particular implementation of
> IEnumerable you take. E.g. array itself is IEnumerable. List<T> is
> IEnumerable and also wraps an array. But LinkedList<T> is IEnumerable,
> and is not an array, nor does it behave like one (you can't access
> elements by index). Another example would be method Enumerable.Range()
> in .NET 3.5 - you give it a lower and an upper bound, and returns an
> implementation of IEnumerable that produces numbers in that range. It
> would be implemented something like this:
>
> class Range : IEnumerable<int>
> {
>  private int lowerBound, upperBound;
>
>   public Range(int lowerBound, int upperBound)
>   {
>     this.lowerBound = lowerBound;
>     this.upperBound = upperBound;
>   }
>
>   public IEnumerator<int> GetEnumerator()
>   {
>     for (int i = lowerBound; i <= upperBound; ++i)
>     {
>       yield return i;
>     }
>   }
>
> }
>
> As you can notice, there are no arrays here at all...
>
> The concept that IEnumerable represents is actually a "sequence" (a
> finite or an infinite one - noone says that MoveNext() ever has to
> return false!). "Array" is a more specific concept - to quote
> Wikipedia, "In computer science an array is a data structure
> consisting of a group of elements that are accessed by indexing. In
> most programming languages each element has the same data type and the
> array occupies a contiguous area of storage.". Obviously, any array is
> also a sequence, but not every sequence is an array or even array-like
> (since not every sequence can be indexed, and some - e.g.
> Dictionary<T> and HashSet<T> - do not even have any specific ordering).

Thank you very much.  I think it is much clearer to me.  The range
example you gave is actually a question I have which I am planning on
following up in this thread, although really the example I am
interested in is the Power example as shown  at
http://msdn.microsoft.com/en-us/library/9k7k7cf0(VS.80).aspx . You'll
notice that it is very similar to your Range example.

The question I have about the Power example is:

The while loop:

while (counter++ < exponent)
{
     result = result * number;
     yield return result;
}

indicates that block likely will execute multiple times.  The question
is, where does the result go?  Note that result is declared as an
int.  Is it converting the int result to IEnumerable and pad the
result to this IEnumberabilized result?  This is where I don't
understand.  I hope that I have made my question clear.  Thank you.




== 6 of 7 ==
Date: Sun, May 11 2008 4:28 pm
From: "Tim Jarvis"


gnewsgroup wrote:

> > <blatant plug>
> > See http://www.manning-source.com/books/skeet/Chapter6sample.pdf for
> > rather more about the iterator pattern.

>
> Thank you. I know IEnumerable is an interface.  I didn't mean
> IEnumerable objects and arrays are exactly the same.  I notice that
> quite often the constructor of an IEnumerable class takes an array as
> the argument, and I think foreach internally makes use of the MoveNext
> method. Is it the case that the core of an IEnumerable object is an
> array? Thanks.

The thing about an Interface is that there is no requirement that the
underlying implementation is a specific class, thats the beauty of
interfaces they provide polymorphic behaviour /accross/ class
heirachy's. Its simply a contract that the underlying implementation
will provide a (in this case) GetEnumerator method, it so happens that
system.array does, but so do many other classes. So I guess the exact
answer to your question is Sometimes the "core" is an array, sometimes
its not.

Definitely have a read of Jon's chapter, he explains in quite some
detail what's going on.

Regards Tim.

--





== 7 of 7 ==
Date: Sun, May 11 2008 4:51 pm
From: "Peter Duniho"


On Sun, 11 May 2008 16:10:23 -0700, gnewsgroup <gnewsgroup@gmail.com>
wrote:

> [...]
> The question I have about the Power example is:
>
> The while loop:
>
> while (counter++ < exponent)
> {
>       result = result * number;
>       yield return result;
> }
>
> indicates that block likely will execute multiple times.  The question
> is, where does the result go?

It's returned by IEnumerator.Current, where the IEnumerator is "returned"
(sort of) by the method in question, indirectly through the IEnumerable in
that particular example.

> Note that result is declared as an
> int.  Is it converting the int result to IEnumerable and pad the
> result to this IEnumberabilized result?  This is where I don't
> understand.  I hope that I have made my question clear.  Thank you.

To answer your direct question: no, the int is not converted to
IEnumerable.

It is a little confusing, because the compiler is hiding so much from
you.  But a method that contains a "yield" statement is treated
differently from normal methods.  The compiler essentially creates a
hidden class that implements the enumeration described by the method, via
the IEnumerable interface in this example.

This hidden class manages the current state.  When you call the method,
all that's returned is a reference to the IEnumerable (or whatever type
was declared for the iterator) that the compiler created.  Something using
IEnumerable (for example, a "foreach" loop) calls GetEnumerator() to get
the IEnumerator interface implemented by the hidden class.  The compiler
has built the hidden class so that when you call IEnumerator.MoveNext(),
it executes the code in the method that you wrote until it hits the
"yield" statement.  At that point, the return value is stored and the
MoveNext() implementation returns.  Calling IEnumerator.Current retrieves
the stored value.

For the non-generic IEnumerable, the IEnumerator returned is of course a
non-generic implementation and so Current always returns an Object.  When
the "yield" statement returns an int, this is boxed automatically.  It's
then unboxed by whatever code is actually using the
IEnumerable/IEnumerator.

If you implement the generic IEnumerable<T> interface, then the value
returned by IEnumerator<T>.Current will be the same type as that returned
by the "yield" statement, without any boxing.

But in neither case does the return value associated with the "yield"
statement have anything directly to do with the declared return type of
the method.  An iterator method must return IEnumerable, IEnumerator, or
the generic versions of those interfaces.  The type of the "yield return"
statement determines the type of the data returned by the Current property
of the relevant enumerator interface.  The _presence_ of a "yield"
statement requires that enumerable/enumerator return value, and the type
actually returned by the "yield" statement determines what Current returns
(boxed, if necessary).

For more information, if you haven't already you may want to read the
description of C# iterators:
http://msdn.microsoft.com/en-us/library/dscyy5s0.aspx (there's a link to
that document from the doc page for "yield" that you mentioned)

Pete





==============================================================================
TOPIC: basic source code archiver
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/6453172ce135b3db?hl=en
==============================================================================

== 1 of 2 ==
Date: Sun, May 11 2008 1:55 pm
From: "Andre Prins"


colin wrote:

> Hi,
>
> I could do with a simple source code archiver
> something that can save all source files,
> and then save any changed source file,
> but I dont realy want or need the
> complexity of source code control.

Try AJC Active Backup.

http://www.ajcsoft.com/AJCActBk.php

Highly configurable and yet simple to use.

--
Andre Prins
Twain Development




== 2 of 2 ==
Date: Sun, May 11 2008 4:26 pm
From: fd123456@hotmail.com


On 11 mai, 12:57, "colin" <colin.ro...@ntworld.NOSPAM.com> wrote:
> Hi,
>
> I could do with a simple source code archiver
> something that can save all source files,
> and then save any changed source file,
> but I dont realy want or need the
> complexity of source code control.
>
> at the moment I just zip the entire directory,
> and save in numbered files, but theres a lot of large
> files that arnt modified often such as 3d model objects.
>
> thanks
> Colin =^.^=

MOGware FileHamster does just that. I'm using the free version, it's
unobstrusive and does it's job well.

Michel





==============================================================================
TOPIC: How to determine console or winform app?
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/d5f8ad3f3ebaa4e6?hl=en
==============================================================================

== 1 of 2 ==
Date: Sun, May 11 2008 2:04 pm
From: "Paul E Collins"


"None" <none@none.com> wrote:

> Hello, my app is written in C#. Given an app file path (e.g.
> e:\abc.exe), how can I determine if it's a winform app or a console
> one. (note: abc.exe can be either a native exe or a .net one)

You will need to study the Portable Executable (PE) file format.
http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx
Then you can open the .exe file with a BinaryReader and pick out the
information you need.

Eq.






== 2 of 2 ==
Date: Sun, May 11 2008 4:33 pm
From: "Peter Duniho"


On Sun, 11 May 2008 06:43:31 -0700, None <none@none.com> wrote:

> Hello, my app is written in C#. Given an app file path (e.g. e:\abc.exe),
> how can I determine if it's a winform app or a console one. (note:
> abc.exe
> can be either a native exe or a .net one)

One way would be to use the "Debug Help" library
(http://msdn.microsoft.com/en-us/library/ms679309(VS.85).aspx).  You can
use the ImageNtHeader() function to retrieve the PE headers for the
executable, and then check the subsystem information to see whether it's
GUI or command-line.

Note that a console application can in fact create a GUI.  It's not really
clear why you're trying to do this, but keep in mind that you may or may
not be able to reliably accomplish your goal, depending on what
applications you're dealing with and why you really want to know whether
they are console or GUI.

Pete





==============================================================================
TOPIC: Stop XmlDocument.Load() from using cached data?
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/6f3892acd2eca71b?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, May 11 2008 2:05 pm
From: "Anthony Jones"


"Mahmoud Al-Qudsi" <mqudsi@gmail.com> wrote in message
news:1195a8ef-2e45-4498-8a81-520878958b6f@m3g2000hsc.googlegroups.com...
>
> > Assuming you don't have a conflicting setting in the application's
config(s)
> > then yes that should do it.
>
> Thanks, it worked great.

Perhaps I should have mentioned in response to your previous reply that
modifying the DefaultCachePolicy as you are doing there affects _all_ Web
Client code.  This may have some un-wanted side effects in previously
working code.

Since any code in the app domain can muck about with the DefaultCachePolicy
its actually not a good idea to change it or rely on it.  I think the best
approach is to use an instance of HttpWebRequest and set the policy of that
instance.



--
Anthony Jones - MVP ASP/ASP.NET







==============================================================================
TOPIC: After upgrade to 2.0, Error CS1595 System.TimeSpan is defined in
multiple places
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/9dd6566f1396dd7c?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, May 11 2008 2:50 pm
From: Pavel Minaev


On May 11, 9:28 pm, Brent <writebr...@gmail.com> wrote:
> This is a good question. Actually, I'm using a csc.exe located in the
> same folder as the .CS file. When I pointed to the CSC.exe file
> located in c:\windows\Microsoft.NET\Framework\v1.1.4322\ , the
> compiling works fine! Could it be that the absence of a csc.exe.config
> in the local folder causes the csc to look all over the place for the
> referenced namespaces, and come up with conflicts?

Not really. It's just that csc always references some assemblies (in
particular, mscorlib) from the corresponding version of .NET
Framework, and then also those that you explicitly specify. In your
case, it would seem that this results in both mscorlib from 1.1 and
mscorlib from 2.0 being referenced, hence the clash.

.NET 1.1 and 2.0 do play nice with each other in a sense that they can
be installed side by side, and programs will run using whatever
version of .NET they were built with. But if you're compiling with csc
2.0, you should really be referencing 2.0 assemblies, not 1.1 ones.





==============================================================================
TOPIC: Select XML Node
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/65c8d80b201ba538?hl=en
==============================================================================

== 1 of 7 ==
Date: Sun, May 11 2008 3:18 pm
From: "Thom Little"


Using C# 3.5 I want to select a value from an XML file.  The intent of the
following is to print "EpsilonGamma".  It does not work.  Can you point out
my probably very obvious error?

XmlDocument document = new XmlDocument();
document.Load("sample.xml");
XmlElement root = document.DocumentElement;
XmlNode node = root.SelectSingleNode("//menu[id=b]");
Console.Write( node.SelectSingleNode("//menu[id=b]/row[id=1]/vis").Value );
Console.Write( node.SelectSingleNode("//menu[id=b]/row[id=0]/vis").Value );

For ...

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<menus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <menu>
         <id>a</id>
         <row>
                <id>0</id>
                <vis>Alpha</vis>
         </row>
         <row>
                <id>1</id>
                <vis>Beta</vis>
         </row>
  </menu>
  <menu>
         <id>b</id>
         <row>
                <id>0</id>
                <vis>Gamma</vis>
         </row>
         <row>
                <id>1</id>
                <vis>Epsilon</vis>
         </row>
  </menu>
</menus>


... Thom
___________________________________________________
  Thom Little  -  www.tlanet.net  -  Thom Little Associates, Ltd.




== 2 of 7 ==
Date: Sun, May 11 2008 3:27 pm
From: Arne Vajhřj


Thom Little wrote:
> Using C# 3.5 I want to select a value from an XML file.  The intent of the
> following is to print "EpsilonGamma".  It does not work.  Can you point out
> my probably very obvious error?
>
> XmlDocument document = new XmlDocument();
> document.Load("sample.xml");
> XmlElement root = document.DocumentElement;
> XmlNode node = root.SelectSingleNode("//menu[id=b]");
 > Console.Write(
node.SelectSingleNode("//menu[id=b]/row[id=1]/vis").Value );
 > Console.Write(
node.SelectSingleNode("//menu[id=b]/row[id=0]/vis").Value );

What do you get ?

My guess would be that you want:

Console.Write( root.SelectSingleNode("//menu[id=b]/row[id=1]/vis").Value );
Console.Write( root.SelectSingleNode("//menu[id=b]/row[id=0]/vis").Value );

to search from root instead of node.

> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <menus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>    <menu>
>         <id>a</id>
>         <row>
>                <id>0</id>
>                <vis>Alpha</vis>
>         </row>
>         <row>
>                <id>1</id>
>                <vis>Beta</vis>
>         </row>
>    </menu>
>    <menu>
>         <id>b</id>
>         <row>
>                <id>0</id>
>                <vis>Gamma</vis>
>         </row>
>         <row>
>                <id>1</id>
>                <vis>Epsilon</vis>
>         </row>
>    </menu>
> </menus>

Arne




== 3 of 7 ==
Date: Sun, May 11 2008 3:30 pm
From: Marcin Hoppe


Thom Little pisze:
> Can you point out my probably very obvious error?

The first problem that I see is that you first select the second menu
node and try to run an XPath query on this node as if it was a root. Try
to change your second and third XPath query to something like:

"/row[id=x]/vis"

Best regards!
--
Marcin Hoppe
Email: marcin.hoppe@gmail.com
Blog: http://devlicio.us/blogs/marcin_hoppe




== 4 of 7 ==
Date: Sun, May 11 2008 3:52 pm
From: "Thom Little"


When using just one Console.Write I get ...

Additional information: Object reference not set to an instance of an
object.

With your change (if I did it correctly) I get the same result.

... Thom
___________________________________________________
  Thom Little  -  www.tlanet.net  -  Thom Little Associates, Ltd.




== 5 of 7 ==
Date: Sun, May 11 2008 3:55 pm
From: "Thom Little"


When using just one Console.Write I get ...

An unhandled exception of type 'System.NullReferenceException' occurred in
ConsoleXML.exe
Additional information: Object reference not set to an instance of an
object.

With your change (if I did it correctly) I get the same result.

... Thom
___________________________________________________
  Thom Little  -  www.tlanet.net  -  Thom Little Associates, Ltd.




== 6 of 7 ==
Date: Sun, May 11 2008 4:12 pm
From: Arne Vajhřj


Thom Little wrote:
> When using just one Console.Write I get ...
>
> Additional information: Object reference not set to an instance of an
> object.
>
> With your change (if I did it correctly) I get the same result.

You also missed some '' around values and to get the actual text.

Console.Write(
root.SelectSingleNode("//menu[id='b']/row[id='1']/vis/text()").Value );
Console.Write(
root.SelectSingleNode("//menu[id='b']/row[id='0']/vis/text()").Value );

works for me.

Arne




== 7 of 7 ==
Date: Sun, May 11 2008 4:56 pm
From: "Tim Jarvis"


Thom Little wrote:

> Using C# 3.5 I want to select a value from an XML file.  The intent
> of the following is to print "EpsilonGamma".  It does not work.  Can
> you point out my probably very obvious error?
>
> XmlDocument document = new XmlDocument();
> document.Load("sample.xml");
> XmlElement root = document.DocumentElement;
> XmlNode node = root.SelectSingleNode("//menu[id=b]");
> Console.Write(
> node.SelectSingleNode("//menu[id=b]/row[id=1]/vis").Value );
> Console.Write(
> node.SelectSingleNode("//menu[id=b]/row[id=0]/vis").Value );
>
> For ...
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <menus xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
>    <menu>
>         <id>a</id>
>         <row>
>                <id>0</id>
>                <vis>Alpha</vis>
>         </row>
>         <row>
>                <id>1</id>
>                <vis>Beta</vis>
>         </row>
>    </menu>
>    <menu>
>         <id>b</id>
>         <row>
>                <id>0</id>
>                <vis>Gamma</vis>
>         </row>
>         <row>
>                <id>1</id>
>                <vis>Epsilon</vis>
>         </row>
>    </menu>
> </menus>
>
>
> ... Thom
> ___________________________________________________
>    Thom Little  -  www.tlanet.net  -  Thom Little Associates, Ltd.

Hi Thom,

Apart from the excellent replies that you already have, given that you
are using C# 3.5, maybe you should also think about using Linq for XML,
I personally find that this is the absolute best way to work with XML,
not just the query syntax, but the whole new xml API that does not work
with a DOM, sooo much easier.

In this case, one way do do this would be....

     XElement xe = XElement.Load(@"C:\Temp\Test.xml");

     var elements = from menu in xe.DescendantsAndSelf("menu")
                    where (string)menu.Element("id") == "b"
                    from row in menu.Descendants("row")
                    select row;

     StringBuilder sb = new StringBuilder();

     foreach (XElement x in elements)
     {
       sb.Append((string)x.Element("vis"));
     }
     MessageBox.Show(sb.ToString());

Regards Tim.

--






==============================================================================
TOPIC: Checking if a list of names appears in a body of text.
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/462037d91c08e693?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, May 11 2008 4:28 pm
From: "Peter Bromberg [C# MVP]"


Tomas Petricek has a very nice article with sample code along these lines
here:
http://tomasp.net/articles/ahocorasick.aspx
Peter
"Peter Duniho" <NpOeStPeAdM@nnowslpianmk.com> wrote in message
news:op.uajytbh18jd0ej@petes-computer.local...
> On Fri, 02 May 2008 17:23:21 -0700, Brent <writebrent@gmail.com> wrote:
>
>> I have a list of company names (say, IBM, Corning, General Motors, and
>> another 5,000 of them).
>>
>> If I take a body of text, a news article, for instance, and I want to
>> see which company names appear in that text, is there an efficient way
>> to do this?
>
> This comes up here surprisingly often.  :)
>
> For the general case, so far I've yet to see someone suggest a better
> solution that the one I've proposed in the past: using a state graph.
> This approach assumes that you've got a static list that you can use to
> initialize your state graph once, and then use the same graph to process
> multiple input over and over.  The cost of creating the graph would be
> prohibitive if you had to create it for each iteration of input.
>
> In an earlier thread, I posted some code that provided a generic
> implementation of a state graph.  I'm not claiming it's the best
> implementation, but it does work.  :)  You can find that message here:
> http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/msg/0f06f696d4500b77
>
> VERY IMPORTANT!  That code had a performance bug in it that severely
> limited its usefulness.  The original person I'd posted the code for never
> bothered to comment on it, so I never even noticed until much later, when
> I recommended the same code to someone else and they complained that it
> wasn't as fast as I'd said it should be.  You can find my follow-up post
> in which I included the bug-fix for the earlier code here:
> http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/msg/ac50505b568a75fd
>
> If you care about performance (and obviously you do :) ), do NOT use the
> code I originally posted without including the later bug-fix.
>
> You may want to review both threads for comments from other people.  A
> number of other folks contributed to the threads, and they had insightful
> and useful comments, especially pertaining to special cases where you can
> get good performance by knowing something particular about the input.  The
> state graph performs well as a general-purpose solution, but sometimes you
> can get equal or better performance with a different solution that takes
> advantage of some particular known characteristic of the input.
>
> Pete






==============================================================================
TOPIC: DataGridView: Need to make Enter key create newline in textbox
http://groups.google.com/group/microsoft.public.dotnet.languages.csharp/browse_thread/thread/ed6aa115ab5b180a?hl=en
==============================================================================

== 1 of 1 ==
Date: Sun, May 11 2008 4:49 pm
From: Steve K


Steve K wrote:
> I've got a full day invested in this now and I still can't make it work.
>  Hopefully someone here can offer some suggestions.
>
> Here is the situation:  I have a data entry application and am using a
> DataGridView to enter order details.  When it comes to the serial
> numbers we will use a barcode reader which send a carriage return
> character after each barcode is read.  We can't change this behavior
> (well, we can but it works great in the other 3-4 applications we use)
>
> When a user is entering serial numbers into the serial number cell I
> want each scanned serial number to be on it's own line, just like:
> abc123
> abc456
> abc789
>
> I'm able to get this behavior by pressing the SHIFT+ENTER combo but I
> can't setup the barcode reader to send this combination.
>
> The solution I've come up with (based on an article I found online
> somewhere) is to create my own DGV Cell, Column and EditingControl.
>
> Here is the code for those classes:
> <code>
> public class PMDDataGridViewTextBoxEditingControl :
> DataGridViewTextBoxEditingControl
> {
>     public override bool EditingControlWantsInputKey(Keys keyData, bool
> dataGridViewWantsInputKey)
>     {
>         switch (keyData & Keys.KeyCode)
>         {
>             case Keys.Prior:
>             case Keys.Next:
>             case Keys.End:
>             case Keys.Home:
>             case Keys.Left:
>             case Keys.Up:
>             case Keys.Right:
>             case Keys.Down:
>             case Keys.Delete:
>             case Keys.Enter:
>             return true;
>         }
>
>         return base.EditingControlWantsInputKey(keyData,
> dataGridViewWantsInputKey);
>     }
>
>     protected override void OnKeyDown(KeyEventArgs e)
>     {
>         if (e.KeyCode == Keys.Enter)
>         {
>             this.Text += Environment.NewLine;
>             this.Select(this.Text.Length, 0);
>         }
>
>         base.OnKeyDown(e);
>     }
> }
>
> public class PMDMultilinDataGridViewCell : DataGridViewTextBoxCell
> {
>     public override Type EditType
>     {
>         get
>         {
>             return typeof(PMDDataGridViewTextBoxEditingControl);
>         }
>     }
> }
>
> public class PMDMultilineDataGridViewColumn : DataGridViewColumn
> {
>     public PMDMultilineDataGridViewColumn()
>         : base(new PMDMultilinDataGridViewCell())
>     {
>         this.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
>     }
> }
> </code>
>
> Note that in the EditingControl I am inserting a newline and moving the
> cursor to this newline when an enter key is detected.
>
> My question (finally!) is if this is a sound solution?  It works, but
> feels "hacky" to me and I suspect I may be missing a more elegant solution.
>
> Anyone have any ideas?


If anyone is interested my current revision of the above solution works
pretty well.  You could do plenty to make it better, but for me it does
the job.

Here is the code:
<code>
namespace PMD.Library.WinFormControls
{
    public class PMDDataGridViewMultiLineTextBoxCell :
DataGridViewTextBoxCell
    {
        public override Type EditType
        {
            get
            {
                return
typeof(PMDDataGridViewMultiLineTextBoxEditingControl);
            }
        }
    }
}

namespace PMD.Library.WinFormControls
{
    public class PMDDataGridViewMultiLineTextBoxColumn : DataGridViewColumn
    {
        public PMDDataGridViewMultiLineTextBoxColumn()
            : base(new PMDDataGridViewMultiLineTextBoxCell())
        {
            this.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
        }
    }
}

namespace PMD.Library.WinFormControls
{
    public class PMDDataGridViewMultiLineTextBoxEditingControl :
DataGridViewTextBoxEditingControl
    {
        private const int MAX_DISPLAY_LINES = 5;
        private readonly int _lineHeight = 0;

        public PMDDataGridViewMultiLineTextBoxEditingControl()
            : base()
        {
            using (Graphics g = Graphics.FromHwnd(this.Handle))
            {
                _lineHeight = Convert.ToInt32(g.MeasureString("T",
this.Font).Height);
            }

            this.Multiline     = true;
            this.AcceptsReturn = true;
        }

        public override bool EditingControlWantsInputKey(Keys keyData,
bool dataGridViewWantsInputKey)
        {
            switch (keyData & Keys.KeyCode)
            {
                case Keys.Prior:
                case Keys.Next:
                case Keys.End:
                case Keys.Home:
                case Keys.Left:
                case Keys.Up:
                case Keys.Right:
                case Keys.Down:
                case Keys.Delete:
                case Keys.Enter:
                return true;
            }

            return base.EditingControlWantsInputKey(keyData,
dataGridViewWantsInputKey);
        }

        protected override void OnGotFocus(EventArgs e)
        {
            SetRowHeight();
            base.OnGotFocus(e);
        }

        private void SetRowHeight()
        {
            int numLinesToShow = Math.Min(NumLines, MAX_DISPLAY_LINES);
            int rowHeight = Math.Max((int)(numLinesToShow *
_lineHeight), this.EditingControlDataGridView.RowTemplate.Height);


this.EditingControlDataGridView.Rows[this.EditingControlRowIndex].Height
= rowHeight;
        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.Text += Environment.NewLine;
                this.Select(this.Text.Length, 0);

                int numLines = NumLines;

                if (NumLines < MAX_DISPLAY_LINES)
                {
                    this.ScrollBars = ScrollBars.None;
                }
                else
                {
                    this.ScrollBars = ScrollBars.Vertical;
                }

                SetRowHeight();
                this.ScrollToCaret();
            }

            base.OnKeyDown(e);
        }

        private int NumLines
        {
            get
            {
                return this.Text.Split(new string[] {
Environment.NewLine }, StringSplitOptions.None).Length;
            }
        }

        protected override void OnValidated(EventArgs e)
        {
            //  remove any trailing whitespace
            //this.Text = this.Text.Trim();
            base.OnValidated(e);
        }
    }
}
</code>

Please, if you see anything that could be better, more efficient, etc.
please let me know.

-Steve



No comments: