|
Why didn't I think of that?
It's not there -- it should be right before "Confuse a Belgian".
|
|
|
|
|
PIEBALDconsult wrote: right before "Confuse a Belgian"
Even less likely to be found in an index.
Would be an interesting title for a book though.
|
|
|
|
|
Sooo... my Colour class didn't help.
I now have a kludge working that passes the Argb as a string and parses it on the other side. Fugly fugly fugly, but here it is.
(This is the class I was using last spring.)
Using a partial class, I have only those properties that are to be serialized in Record.cs:
namespace Junk.Types
{
[System.Runtime.Serialization.DataContractAttribute()]
public sealed partial class Record
{
[System.Runtime.Serialization.DataMemberAttribute()]
public System.Guid ID { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public string LastName { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public string FirstName { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public Junk.Types.Gender Gender { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
private string colourstring { get ; set ; }
}
}
Note that the colourstring is private.
Other members of the class are in RecordPlus.cs:
namespace Junk.Types
{
using PIEBALD.Lib.LibExt.ParseColor ;
public partial class Record
{
private System.Drawing.Color? favouritecolour = null ;
public Record
(
)
{
return ;
}
public Record
(
System.Guid ID
,
string LastName
,
string FirstName
,
Junk.Types.Gender Gender
,
System.Drawing.Color FavouriteColour
)
{
this.ID = ID ;
this.LastName = LastName ;
this.FirstName = FirstName ;
this.Gender = Gender ;
this.FavouriteColour = FavouriteColour ;
return ;
}
public System.Drawing.Color FavouriteColour
{
get
{
if ( !this.favouritecolour.HasValue )
{
this.favouritecolour = this.colourstring.ParseColor() ;
}
return ( this.favouritecolour.Value ) ;
}
set
{
this.favouritecolour = value ;
this.colourstring = "#" + value.ToArgb().ToString( "X8" ) ;
return ;
}
}
public string
FullName
{
get
{
return ( System.String.Format
(
"{0}, {1}"
,
this.LastName
,
this.FirstName
) ) ;
}
}
public override string
ToString
(
)
{
return ( System.String.Format
(
"{0} {1} {2}"
,
this.FullName
,
this.Gender
,
this.colourstring
) ) ;
}
}
}
(ParseColor is an Extension Method.)
On the server side, the code uses the class as defined in these two files.
On the client side, the code uses the second file and the proxy file, which has its own version of the first file.
That's all the jiggery-pokery I've been doing, and it works fine for the types I've been using.
As for non-.net practitioners, they'd see the #FFFFFFFF and deal with it however they need to.
|
|
|
|
|
OK, thanks. I'll study that tomorrow.
One question though: Is this still part of SOAP and WSDL/svcutil plus extra client methods;
or is this part of (or built on top of) WCF?
|
|
|
|
|
The JunkClient.cs (in this case) file that svcutil generates from the WSDL contains a (partial) Record class containing only those properties that are specified in the contract. Then I supply the rest of the class via another file.
Record.cs + RecordPlus.cs == Record class
| |
| |
WSDL/svcutil |
| |
| |
V V
JunkClient.cs + RecordPlus.cs == Record class
|
|
|
|
|
so it does not need WCF, it is just SOAP, WSDL and partial classes, and .NET 2.0 can do all of those. Right?
|
|
|
|
|
It doesn't need WCF. I could try compiling it with .net 2.0 -- this is a project I started on to try out VS 2010.
I'll get back to you later, the kid wants me to read to him.
Have good night.
|
|
|
|
|
Good Night to all of you then.
|
|
|
|
|
I sit corrected:
DataMemberAttribute Class[^]
.NET Framework
Supported in: 4, 3.5, 3.0
So, no, not .net 2.0 -- unless maybe you write your own, like you can with ExtensionAttribute...
And my code as it stands uses Extension Methods and HashSet, so I would need to remove those.
modified on Sunday, September 26, 2010 12:54 AM
|
|
|
|
|
The stuff that everybody else said is confusing, so I thought I'd make it simple if anybody else is curious.
The properties A, R, G, and B on the Color struct only have getters (i.e., they don't have setters). No setters, the serializer can't set them. And the underlying property that they are based upon, Value, is private (not to mention it only has a getter), which serialization skips.
The Size struct serializes/deserializes fine because the Width and Height properties are public and have setters.
Oh, and in case you are curious why the deserialization requires a public setter... it first creates an instance of the class by calling the default constructor, then it calls the setter on each public property. That, by the way, means that serialization doesn't work by default on classes without a default constructor (I've been annoyed by that a couple times).
I think you can inherit from (or as PIEBALD might say, implement) an interface or something that allows you to implement custom serialization, but I've never had to resort to that.
|
|
|
|
|
aspdotnetdev wrote: as PIEBALD might say, implement
Correct, you're learning, grasshopper.
Much of that is true, but the question remains of why MS chose to implement Color in such a way that it won't serialize/deserialize in some meaningful way.
As I demonstrated with my last experiment, the property that gets serialized/deserialized (colourstring) doesn't have to be public (because objects serialize/deserialize themselves). MS could implement Color with serialization as I did with my Colour class.
Edit:
Allow me to amend that. This being a (WCF) Web Service, the class that is generated for the proxy includes:
[System.Runtime.Serialization.DataMemberAttribute()]
public string colourstring
{
get
{
return this.colourstringField;
}
set
{
this.colourstringField = value;
}
}
So, although the property in the class I wrote is private, the property that gets deserialized is public.
Crap, that's no good... what genius came up with that idea?
|
|
|
|
|
Aah ha ha ha!
System.ConsoleColor is an enumeration, so it passes through just fine... if you like 16-color.
Or write your own enumeration with the colours you want... how many could there be?
|
|
|
|
|
Yes, that was my initial approach, just an enum for CP colors (mainly: Orange, DarkGreen, Platinum, Gold, Silver, Bronze), but then I wanted to get the actual color components so an app could somewhat mimic the site look, even when CP itself changes some of its style parameters.
As DateTimes did just fine, I got a big bad surprise by Color acting up. You know the rest.
|
|
|
|
|
I have now rewritten my Colour class (as a struct) and it seems to work properly.
Record.cs as it now stands:
namespace Junk.Types
{
[System.Runtime.Serialization.DataContractAttribute()]
public sealed partial class Record
{
[System.Runtime.Serialization.DataMemberAttribute()]
public System.Guid ID { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public string LastName { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public string FirstName { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public Junk.Types.Gender Gender { get ; set ; }
[System.Runtime.Serialization.DataMemberAttribute()]
public Junk.Types.Colour FavouriteColour { get ; set ; }
}
}
Colour.cs:
namespace Junk.Types
{
public partial struct Colour
{
public byte A ;
public byte R ;
public byte G ;
public byte B ;
}
}
ColourPlus.cs:
namespace Junk.Types
{
using PIEBALD.Lib.LibExt.ParseArgb ;
public partial struct Colour
{
public override string
ToString
(
)
{
return ( System.String.Format
(
"#{0:X2}{1:X2}{2:X2}{3:X2}"
,
this.A
,
this.R
,
this.G
,
this.B
) ) ;
}
public static Colour
Parse
(
string Argb
)
{
return ( Colour.FromArgb ( Argb.ParseArgb() ) ) ;
}
public int
ToArgb
(
)
{
return ( this.A << 24 | this.R << 16 | this.G << 8 | this.B ) ;
}
public static Colour
FromArgb
(
int Argb
)
{
Colour result = new Colour() ;
result.B = (byte) ( Argb & 0x0FF ) ;
Argb >>= 8 ;
result.G = (byte) ( Argb & 0x0FF ) ;
Argb >>= 8 ;
result.R = (byte) ( Argb & 0x0FF ) ;
Argb >>= 8 ;
result.A = (byte) ( Argb & 0x0FF ) ;
return ( result ) ;
}
public static implicit operator System.Drawing.Color
(
Colour Colour
)
{
return ( System.Drawing.Color.FromArgb ( Colour.ToArgb() ) ) ;
}
public static implicit operator Colour
(
System.Drawing.Color Color
)
{
return ( Colour.FromArgb ( Color.ToArgb() ) ) ;
}
}
}
(ParseArgb replaces ParseColor, it returns an int.)
I haven't inspected the SOAP messages (I don't know how), but I expect they contain the four byte values; something along the lines of:
<FavouriteColour><A>256</A><R>256</R><G>256</G><B>256</B></FavouriteColour>
|
|
|
|
|
I'll experiment with this later today.
BTW: are you with Procter&Gamble? your favorite color is "whiter than white" (that is, if your code recovers from overflow when parsing the example)
|
|
|
|
|
I prefer Belgian White.
|
|
|
|
|
beer, wine, or chocolate?
|
|
|
|
|
Only tried the beer so far.
|
|
|
|
|
|
sure.
I have been working on semantics of the service, almost done now.
I experimented with a client-side extra file, works OK with WSDL.
I tried svcutil, no luck yet. To be continued.
Today I'm busy otherwise. Tomorrow I'll do some compatibility tests (what happens when server spec evolves, client lags?). Then I'll decide what I'll put in the proposal.
Cheers.
|
|
|
|
|
I'm trying to write an addin that updates a build number in an rc file *before* the build happens. I have a version of this that works fine for VC++ 6, but when trying to make this work in VS 2008, I can't get the build to recalculate every time - it only does it every other time.
I'm reading in an RC file, modifing it, then writing it back out. This is occuring in the OnBuildProjConfigBegin event (I have also tried OnBuildBegin as well with the same results).
|
|
|
|
|
Jim Crafton wrote: I'm reading in an RC file, modifing it, then writing it back out.
I don't know much about this, but I thought I'd throw out an idea or two. Are you flusing/closing the file too? Maybe Visual Studio is performing a threaded build and sometimes one thread gets ahead of the other? Can you do something less complicated to show whether or not your code is getting run each time (e.g., write to a new text file)? Or perahps show a message box? If it is getting executed every time, perhaps the RC file is getting overwritten after you change it?
|
|
|
|
|
hey guys..i want to connect my program with access..To do that i created a database in Access 2007 and saved it as Access 2003 with mdb extension..and i moved it to my project's debug file and i tried to connect it with udl file under debug fiile also...mdb has a password...i dont make a password for the mdb the connection is successfull but when i make a password there it gives error like "the provider had an error while connecting " and something like that
so what is wrong here? and why i can connect to database when i dont have a password
|
|
|
|
|
That's a database question.
Did you specify that the password should be saved to the UDL file?
Did you look in the UDL file and confirm that it's there?
|
|
|
|
|
Dear Coders.
I have a form, with a text box to allow a user to type a question, and a scrollable edit box that instantly relays the question.
Then, I send the typed question to my object, and it produces a responce (a bit like the AI webbots on here)
I want a delay while waiting for the responce, so it is more realistic.
I am using Thread.Sleep(3000) to produce a 3 second pause.
Now, this works fine EXCEPT, while the program is pausing, the text that the user has entered does not appear in the chat box.
once the pause has finished, the text AND the responce end up in the chat box at the same time.
So, when a user types a question, I would like it to appear straight away in the chat box, and only the reponse should be delayed.
I have tried moving the sleep function into every different call I make to see if it that but it makes no difference.
I even tried to call invalidate() on my edit box to update the display BEFORE I call sleep(), but again, no help.
Can anyone shed some light on this please?
Thank you
Steve
|
|
|
|
|