|
Guinness4Strength wrote:
Am I missing something ?
Yeah, replacing "Namespace" with the namespace of your resource!
When you add resources to your assembly via VS.NET, the namespace is created from the root namespace of the project (by default, your project name) plus any folders in which the resource is contained. So, if your project is "MyProject" and you create a folder in your project called "Databases" into which the MDB was added, then the fully-qualified resource name is "MyProject.Databases.HL7Builder.dat". If you're unsure, open your assembly with ildasm.exe (installed with the .NET SDK) and look at the manifest file. Toward the bottom (after the assembly references and assembly attributes, plus any public key info), you'll see .mresource Name. That full name is what you'd use in GetManifestResourceStream .
Also, why ReadByte ? You know how long that'd take you to write out the file? Use Read and Write with appropriate buffer sizes to make it much faster. 4096 is a good buffer size:
Type t = this.GetType();
Stream s = t.Assembly.GetManifestResourceStream
("MyProject.Databases.HL7Builder.dat");
Stream mdb = null;
try
{
byte[] buffer = new byte[4096];
mdb = File.Create("C:\TEMP\MyDB.mdb", buffer.Length);
int read = 0;
do
{
read = s.Read(buffer, 0, buffer.Length);
mdb.Write(buffer, 0, buffer.Length);
} while (read == buffer.Length);
}
finally
{
if (mdb != null)
{
mdb.Flush();
mdb.Close();
}
} This is just a basic example and you should add some decent exception handling, but hopefully you get the picture.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks forall the info. The reason I used ReadByte, was that Read didn't work at first because I couldn't read off the stream, I am trying new things Once I cn read off the Stream I'll go back to Read using a byte buffer.
|
|
|
|
|
Right a file (your mdb) in the Solution Explorer, select propetries. You should see the build action property with choices of compile, content, embedded resource
|
|
|
|
|
Perhaps I'm not being clear, or I'm not understanding you.
I imported the MDB into an RCT file in my project which does NOT have a build option in its properties.
The RESX files DO have a build property, but these types of resourse files only appear to be able to hold string values. I need to acces the RCT file or perhaps theres another way to import the MDB file into an RESX file?
|
|
|
|
|
I was just thinking. Would it be better to distibute the mdb through a setup or is this not possible in your case?
|
|
|
|
|
I'm writing a simple little c# class to simply function as an alarm - you pass it a System.DateTime with the constructor, and when that time is reached, it fires an "Alarm" event. Simple enough. However, what's the most efficient way of doing this? Currently, I have thought of two ways. The first has a timer within the class that raises it's event every second or so, and each time it checks to see whether the time now is the same as the target time (accurate to the minute essentially, which is all that's neccesary).
The second is to work out how many milliseconds is between the time the control is enabled, and the target time, and set the interval to that. With repeat turned off, this means that in theory the timer will fire when the alarm is due, which is maybe more efficient than regular comparison checking?
Are these both crazy? Which is more sensible? Is the System.Timers.Timer accurate enough to do the second option anyway?
Am i missing a very easy way of doing this that is nothing like the above? Thank you very much in advance for any comments.
|
|
|
|
|
Yes, these options seem reasonable.
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
|
|
|
|
|
Nothing crazy, these are probably the only two methods for accomplishing this. I'd go with the second method.
|
|
|
|
|
How to capture data from the local serial port through a Aspx page situated in a Web Server ??
NRS
|
|
|
|
|
This is ambiguous. Local to who? The client or the server?
--Colin Mackay--
"In the confrontation between the stream and the rock, the stream always wins - not through strength but perseverance." (H. Jackson Brown)
|
|
|
|
|
Local is the client machine
|
|
|
|
|
Hello all,
I posted this to microsoft.public.dotnet.framework.remoting
but it's awfully quiet over there. Hopefully someone here can shed
some light on this.
A client makes a call on a ContextBoundObject. The call is a simple call
to a property accessor. Depending upon the current values of a Singleton
I either want to simply return the value of the property of the object
or,
--> leaving the actual value of the field unchanged <--
return a different value.
A simple example would be
1) a client references a property of an object,
2) a security setting is checked and
3) either the actual value is returned - or - something like "Access
Denied" is put in it's place.
When RealProxy sends back the IMethodReturnMessage, the ReturnValue
property is read only. How can I alter this value before passing it back
to the client? Most of the AOP examples I have run across have not dealt
with this.
Thanks
Robert Zurer
robert@zurer.com
|
|
|
|
|
You'll have to extend RealProxy with your own class and override Invoke . Implement IMethodReturnMessage and then you can access the IDictionary through the IMessage.Properties (since IMethodReturnMessage implements IMessage ). To make sure that the ContextBoundObject uses your RealProxy instead, derive from ProxyAttribute to return an instance of your custom RealProxy and attribute your ContextBoundObject with your derived ProxyAttribute (see the SDK documentation for ProxyAttribute for an example).
If you also see the SDK documentation for the RealProxy.Invoke abstract method, you'll see an example of how this can be done as well.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
This was extremely helpful. You really pointed me in the right direction.
Thanks so much.
Robert Zurer
robert@zurer.com
|
|
|
|
|
Glad I could help! Out of curiosity, though, why not just throw an UnauthorizedAccessException or something from your ContextBoundObject , and handle that in your client app?
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
One reason is the the security is very granular. For instance, if the client wants to see Employee.Name, Employee.Position and Employee.Salary but has no rights to Employee.Salary, I want to return
Name: Ludwig Wittgenstein
Position: TA, Philosophy
SSN : Access Denied
rather than throwing an execption.
I could easily pass around some sort of security token and handle this in the get_Methods, but my aim is to have my business objects contain ONLY business logic. I want security, profiling, versioning and concurrency concerns to be coded using aspect-oriented techniques.
Robert Zurer
robert@zurer.com
|
|
|
|
|
I guess I'm of the mind that while modularity is good (I'm a stickler for a good object-model), allowing some degree of control / not hiding too much is good between objects. For example, our data tier objects in the app I designed always throw exceptions unless they can recover from certain exceptions, while the business objects or UI tier decide what to do with the exceptions. This allows the app to pass extra information to the client about why the exception occured (not to mention it's handy to debug when some of my guys don't have the source for some components) and allows the caller to decide how to handle it. We also use proxies ala remoting. I guess whatever works for you, though. There's never an absolute correct way in development! (Although there are a lot of stupid and flat-out wrong ones...not that yours is - just my commentary! )
I'm going to have to read-up on this aspect-oriented technique. I've heard it mentioned several times and know there's an article around here in CP somewhere, I've just never read it. I'll have to do that and google for a few other resources, but if you've got a link or too to something you found useful, I'd sure appreciate it.
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
There is a tremendous amount out there. I really should have kept a list but here are two.
http://msdn.microsoft.com/msdnmag/issues/02/03/AOP/default.aspx
http://msdn.microsoft.com/msdnmag/issues/03/03/contextsinnet/
Robert
|
|
|
|
|
Interesting - since the public inception of .NET (and even for a while before that with some of my newer COM libraries) I've already been programming like most of what I read. I guess it just made sense too - to basically delegate responsibility to unknown objects at compile time and piece together those components at runtime. The application I architected for work works very much like that, although it could use a complete overhaul (the CEO gave me a couple weeks to design an app that has about 400,000 lines of actual code, is Internet-deployed, and now includes far too many "modules" to be deployed in such a way - plus it had to be easy enough for entry-level programmers / industrial engineers - who are now much better through lots of tutalige - to work on).
I've spent a lot of time in previous years studying COM (started about the time it evolved from OLE to COM) and especially all the interfaces that Office commonly implements. With a sprinkle of that with some of the stuff I developed since I originally architect the app (that is, I knew from the start this would come back to bite us so I kept track of everything I wanted to do in the first place but couldn't because we either didn't have time for a good design or didn't have the technical help from the rest of the code monkeys that was necessary). The Microsoft Patterns and Practices added a few more good ideas to the batch.
Thanks for the resources, though! At least I got a better grip on it and - strangly enough - realize that I've been doing it for a while so I don't feel like I'm missing the train!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Here's a MS WebTV piece detailing your original post.
http://www.microsoft.com/downloads/details.aspx?FamilyId=EF89345E-01A6-4AB1-8DDF-565286CC5DAC&displaylang=en
The presenter mentions that this is a more lightweight solution than using the MessageSink chain, implying that it could work the MessageSink chain.
In fact it can, using the ReturnValue property of MethodReturnMessageWrapper which can be assigned.
IMessage retMsg = nextSink.SyncProcessMessage(msg);
MethodReturnMessageWrapper mrm = new MethodReturnMessageWrapper((IMethodReturnMessage)retMsg);
Console.WriteLine("Here is the intercepted ReturnValue {0}", mrm.ReturnValue);
Robert Zurer
robert@zurer.com
Robert Zurer
robert@zurer.com
|
|
|
|
|
I need to get the following code working in C#:
char szText[255];
::SendMessage(hwndCurr, WM_GETTEXT, 255, (LPARAM)szText);
m_strPassword = szText;
And I've defined the SendMessage function
const int WM_GETTEXT = 0x000D;
[DllImport("user32.dll")]
static extern int SendMessage(IntPtr window, int message, int wparam, [Out]long lparam);
Does anybody know what I should do to make this work?
Andreas Philipson
|
|
|
|
|
Define it like so:
const int WM_GETTEXT = 0x000D;
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
static extern int SendMessage(IntPtr hWnd, int msg, int wParam, out char[] lParam); You can get the HWND from controls' Handle property (and remember that Form derives from Control , so it has a handle too). Notice that I also used the out keyword (not the OutAttribute , which you could still use). This is necessary to get this to work in .NET. Call it like so:
char[] text = new char[255];
SendMessage(myTextBox.Handle, WM_GETTEXT, 255, out text);
password = text; Now, if you're some cracker trying to get a password from another application, keep in mind that calls to WM_GETTEXT from another process for Edit controls (TextBox controls in .NET) with the ES_PASSWORD style set return an empty string (or NULL - I don't remember)...and get a life!
If you're not a cracker, ignore the above statement except the bit about password fields in other processes!
-----BEGIN GEEK CODE BLOCK-----
Version: 3.21
GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++
-----END GEEK CODE BLOCK-----
|
|
|
|
|
Thanks for the help! I'll try it when I get home.
And regarding my use of this code - I'm trying to create a Password Manager which allows Drag&Drop to any edit control.
Andreas Philipson
|
|
|
|
|
After changing the solution to
[DllImport("user32.dll", CharSet=CharSet.Ansi)]
static extern int SendMessage(IntPtr hWnd, int msg, int wParam, [Out]StringBuilder lParam);
It works perfectly! Thanks again!
Andreas Philipson
|
|
|
|
|
Thank you Heath Stewart:
I saw all of the source-code.But they are local-hooks
I really want to know journal-hooks .
thamk you.
sdfasd
|
|
|
|