|
The problem is that the interface says the Property has to be of type IBehavior and not Behaviorclass. To have a typesafe accessor in Itemclass and still adhere to the interface do the following:
public class Itemclass : IBehaviorActing
{
public Behaviorclass Behavior
{
get {...}
}
IBehavior IBehaviorActing.Behavior {
get { this.Behavior; }
}
}
The compiler will call the normal Behavior property whenever you access Behavior via the concrete class. Whenever it is accessed via an interface variable it will access the interface implemenation (which in turn calls the typesafe one).
I regulary use these constructs. It's also extremely useful when working with the ICloneable interface.
|
|
|
|
|
can you tell me where to find an example, with code, of a scientifc calculator, in Csharp, that has these functions too - BIN, OCT, HEX, DEC number transformation?
Ronald24
|
|
|
|
|
I'm having a problem with scaling GIF images down without getting pixelation. I am using HighQualityBicubic interpolation with HighQuality smoothing.
Converting the images to JPG seems to work fine, but saving to their native format produces undesirable image quality.
Any ideas on how I might clear this obstacle?
Thanks,
Robert K
|
|
|
|
|
We're working on a project that goes against another application that exposes it's API via web services. Pretty cool, except for the complexity of actually getting anything done due to the interdependacy of the calls.
So what we're doing is writing wrapper classes to abstract away the details to let people call a simple function that takes care of all the nitty gritty bits. Plus give us the future option of moving to another third party app by simply rewriting the wrappers.
Now for the problem area... we want to hide the actual web service calls from the application programmers using our wrapper. Basically we want to try to prevent someone from going outside the sandbox and using the API directly, potentially causing problems with the app or future portability. With them referenced in the assembly, you can see them by default. I know it's probably basic, but haven't worked out how to make them private or internal.
Someone got a pointer?
|
|
|
|
|
You can create this wrapper in an external project (into single DLL Assembly) to prevent programmers from seeing those. You can even obfuscate it to add more protection.
But there is one thing I would suggest, is that are you sure the details (such as service address, WSDL, etc) won't change? If you're sure, then it's quite straight forward. But if you're not sure if the service address won't change, maybe you can "extract" the service address to be read from an external configuration. As for the WSDL uncertainty, I'm not quite sure about that, but maybe you can write your own WSDL&SOAP parser
Hope it helps
"If Mohammed won't go to the mountain, then the mountain must go to Mohammed" - Gil Grissom, CSI
|
|
|
|
|
I'm afraid I don't follow. What we have currently is a single DLL wrapper project. That DLL has web references to the web services API of the other product.
When a reference to the DLL is added to a client application, they not only see our wrapper functions, but also the raw service API as well. What we want to do is simply have them see our wrapper functions. The service address is driven by external configuration, but the autogenerated code from the WSDL generated by adding the web reference in our wrapper DLL is what we would ultimately like to hide.
|
|
|
|
|
So you mean the automatically-generated code (by Visual Studio) is exposed automatically, and you want to hide this, and only expose facade class (that you made) to the client?
In the DLL wrapper project, go to the Solution Explorer window, in the top click second icon from the left (It says "Shows All Files"). After that, you should be able to see in your Web References folder, you WS (which was one node only), now can be expanded. Try to expand it, and expand Reference.map, and you should file Reference.cs
This cs file contains WS operation that we've been talking about. If you don't want to expose it, just change all class declaration here from public into internal . Therefore, only class in this wrapper DLL (in the same assembly) can access this.
"If Mohammed won't go to the mountain, then the mountain must go to Mohammed" - Gil Grissom, CSI
|
|
|
|
|
Looks like that might do it, thanks!
|
|
|
|
|
Hey all. I'm new @ C# and I am trying to make a small application on my PC. Basically the functionality of this is to allow incoming TCP connections and pass them through to the COM port and vice versa. (So I can connect home and tell my TV to tune to a channel and start recording).
The parts function perfectly independently. I have a main class that spawns a new thread. That new thread opens up a SerialPort connection, and basically sits and waits for commands to be heard from the serialport (for my box to talk back to me and tell it that it did what I wanted it to do). When I do things on the TV, it talks to the COM port, and when I send it commands the TV receives them and does the command, so that part works fine.
Now the second part is my TCP/IP connection. I am using TcpServiceProvider to make this happen. It's listening on port 15555 for commands. When I run this (with MessageBox windows), when I telnet into it and send commands, it receives them, and when I send it commands it sees them just fine.
So, now my problem is tying the two of these classes together. Basically in my main class, I want to open the SerialPort connection and keep it open. I want the TCP server class to talk to the COM port through that variable that I created in the main class.
What I've done to try to accomplish this is in my TCP server class, I created a private variable like so:
private SerialPort _sp;
I created a method too:
public void SetSPVariable(SerialPort sp)
{
_sp = sp;
// for debug, I did this
_sp.Write("TEST");
}
public void TestComs()
{
_sp.Write("TESTING NUMBER TWO"); // this never works
}
It works fine when I call the SetSPVariable method. Now there are other methods within my TCP server class that need to talk to the serial port too (which is why I opted for the private variable within the class). Those other classes can not talk to it whatsoever. It just doesn't work and I can't figure out why. I've tried to pass by reference, but that didn't work either. So basically, in my main class I do something like this:
sp.Open(....);
sp.Write("This works fine");
TCPServerVariable.SetSPVariable(sp);
// at this point in time, you can see the TEST message coming out the COM port from within the
// TCPServer class
TCPServerVariable.TestComs();
// You never see the communication coming from there.
I know that the serial port is still being held open by the main class because when I send commands from another laptop via NULL MODEM cable they show up in the debug message.
I tried passing by reference, but that didn't seem to work. It appears that when the method is finished it somehow is messing up the local class _sp variable. I don't know why. Like I said I'm new to it, and it is probably something really silly.
I'd really appreciate any help on the matter. I've read through for three hours trying to figure this out, and I figure that it's about time to ask for help on the matter.
Thanks greatly
SHULTAS
|
|
|
|
|
I would try running it in a debugger and see what the state of the socket is when you hit the TestComs method. Is it still connected/opened? Or did it get closed somehow?
Like the Stefan mentioned, it could be that one thread is setting the socket while another thread is trying to use it, which might cause a problem if the conditions are right.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I don't think there is something wrong with passing the serial port object. More likely there may be some threading issues or similar.
Does the following work?
public void SetSPVariable(SerialPort sp)
{
_sp = sp;
_sp.Write("TEST");
_sp.Write("TEST2");
}
Is there some code between calls to SetSPVariable and TestComs?
www.troschuetz.de
|
|
|
|
|
Thanks for the quick reply, I appreciate it.
Yes, the multiple _sp.Write()'s work just fine. The flow of the program is as such: Program Loads. Main Class creates a new thread (the thread is another class). The thread then creates an initializes a SerialPort variable, and opens the COM PORT. Next, that thread creates the Provider (TcpServiceProvider) and starts the server. (It has an AsyncCallBack that calls a method within the TCPServer class when data is received from the TCP port). After it does that stuff, I basically have a while (running) { } loop in there that just keeps it running until you press the close button. (I put code in there to write to a file while it was running, and it runs non-stop). While it is running, it is basically calling SerialPort.ReadExisting() to get what's in the buffer (if anything). It just keeps looping and checking the incoming com port buffer for text. If it sees any text, that thread calls the TCPServer class "SendString" method to send out the string. That works totally fine, when I send data into the COM port on my PC, it immediately shows up in the telnet window. When I type in the telnet window, a message box pops up saying "I received this text: " and the text, directly after the message box text it does the _sp.Write() method, but nothing ever shows up on the COM port at that point. But, if I go ahead and type some more stuff on the COM port after that, it shows up in the telnet window (so that is telling me that the COM port is being held open). The odd thing is that no errors are thrown and no exceptions or program crashes are happening and I'm totally stumped at this point.
Again, thanks for the help, it is gladly accepted
*** Addendum: I just loaded this up in debugger as the other poster had mentioned, and I get the following error:
A first chance exception of type 'System.NullReferenceException' occurred in TcpServerDemo.exe
So it does appear that at some point that local pointer:
_sp = sp;
is getting wiped out for some reason?
|
|
|
|
|
Seems like a really weird problem you're having there. I can't image that the private variable is wiped out for some mysterical reason. At least it would be the first time i hear of something like this. Are you sure the exception is thrown when you access the _sp variable? Do you have any code that changes this variable other than the Set function that may be executed for some reason? I think the best would be adding a breakpoint in the Write method of your serial port and check step by step what goes wrong. (as mentioned)
www.troschuetz.de
|
|
|
|
|
Does anybody know's a free obfuscator for .net? One that can do the job and not mess the code up...
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
|
Thank you.
When I mentioned about messing up the code I ment messing with the functionality too - I used a not so famous obfuscator and it maked my assemblies to give errors at runtime (that without obfuscation from that application would not appear).
protected internal static readonly ... and I wish the list could continue ...
|
|
|
|
|
Yeah, I hear you. My opinion of obfuscators is that they're a hack; they break functionality, especially in .NET remoting apps. I've yet to find one that really works on our large client/server app.
|
|
|
|
|
Like Judah said, the point of an obfuscator is to make the code harder to read by removing context (i.e. messing it up). The point being that it makes reversing engineering of your code harder. So for an obfuscator to do it's job it will need to mess around with the code.
|
|
|
|
|
I have a problem whith aplication on the server..this
server back me this message:
The server viewstate cache has timed out. The application was unable to successfully recover state. To address this exception, modify your web.config to use client-side viewstate caching, or to extend the server cache timeout value.
|
|
|
|
|
|
Hi friends
I want some help regarding Textbox editor like when we compose mail then it gets formatting (ex: Bold, Italic,Underline,spell check etc..).
In Web apllication (ASP.NET with C#).\
Thanking u,
Naren
please help me
|
|
|
|
|
I don't think there's anything like that out of the box. You may have to author something like this yourself or purchase a component that does this for you. But, I'm no ASP.NET exptert; perhaps this would best be answered in the appropriate forum[^].
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: How 'bout a little guitar now?
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
I need to have a database of all runned applications. I have a server - terminal, and other users log in terminal. I need to have a list of running applications, of its owners etc...
And of course I want to know how can I update my Database effectively!
Please help me...
P.S. Sorry of my bad English. It's not my native language!
|
|
|
|
|
|
Hi everyone,
I've got a problem and I can't solve it with anything! I have a button that when one clicks on it a groupbox is enabled showing a label with the value of a row which was random from a database. Then when one clicks the next button another question is random and displayed in the same label.Now I would like that after the user clicks the next button for ten times, it is disabled. How can I do this?
Thanks
|
|
|
|
|