|
DaveyM69 wrote: Have I got this right?
TCPConnection knows about FramingEngine.
FramingEngine knows about MessagingEngine.
Not really no. At least not in my current implementation. I wanted to maintain strict abstraction between these classes so that, in future, I could still replace any of the classes without having to make changes to the other classes. Say for instance I decide to employ a whole new and different type of framing, I could just replace the FramingEngine with something new and not have to worry about TCPConnection or MessagingEngine breaking.
Also, let's say I'm not using TCP comms anymore but some direct serial cable link or whatever. I simply have to write a new class called SerialConnection which can still pass messages down through FramingEngine to MessagingEngine etc.
I could even decide to drop FramingEngine altogether and couple TCPConnection and MessagingEngine directly without having to make changes to either.
DaveyM69 wrote: If so,
TCPConnection could call a method in FramingEngine.
FramingEngine could call a method in MessagingEngine.
I'm starting to think that this would indeed have been a better approach, obviously losing the freedom I just described above but what the heck. I doubt it's THAT important anyway.
|
|
|
|
|
Dewald wrote: So, I decided to employ this mechanism of events being raised and handled to pass the message up the chain of abstraction again. As I said, it works, but I'm not sure this is good programming. What are your opinions?
Yeah that seems a bit off. Perhaps something far simpler ( KISS[^] ), like associating the Socket to the Message until it is determined that no reply is required, otherwise the socket is then used to send the reply.
led mike
|
|
|
|
|
The event mechanism looks ok for the receiving part, but it looks a bit awkard for the sending part. Usually, people think of events as things that are optional i.e., you can subscribe if you're interested. People also implicitly associate it with multiple listeners. All of which fit in nicely when receiving data - multiple clients could listen to FramingEngine if they want to etc..
But sending the message is different - you don't want to have a SendMessage event with zero subscribers, do you? Do you anticipate multiple subscribers sending messages?
OTOH, I think of an interface, like
interface IFrameEngine
{
event MessageReceived;
void SendMessage(...);
}
and have message engine hold a reference to this interface. The dependencies are only one way i.e., MessageEngine depends on IFrameEngine.
Just my 2 cents
|
|
|
|
|
S. Senthil Kumar wrote: The event mechanism looks ok for the receiving part, but it looks a bit awkard for the sending part.
That's exactly what I was thinking, and what prompted my question. Thanks for at least confirming that.
S. Senthil Kumar wrote: Usually, people think of events as things that are optional i.e., you can subscribe if you're interested. People also implicitly associate it with multiple listeners.
That makes sense. Thanks, it helps to get such comments. I'm still pretty new to events and delegates.
S. Senthil Kumar wrote: But sending the message is different - you don't want to have a SendMessage event with zero subscribers, do you?
No, I dont.
S. Senthil Kumar wrote: Do you anticipate multiple subscribers sending messages?
Nope.
S. Senthil Kumar wrote: OTOH, I think of an interface, like
interface IFrameEngine
{
event MessageReceived;
void SendMessage(...);
}
and have message engine hold a reference to this interface. The dependencies are only one way i.e., MessageEngine depends on IFrameEngine.
That looks more like what I should have done. Would you mind elaborating a bit? Sorry if I'm asking stupid questions but, believe it or not, I have never used an interface in my life.
|
|
|
|
|
Dewald wrote: Would you mind elaborating a bit?
The interface is to avoid a direct dependency from MessageEngine to FrameEngine, so that you can provide varying implementations of FrameEngine. Something like
interface IFrameEngine
{
event MessageReceived;
void SendMessage(...);
}
class DefaultFrameEngine : IFrameEngine
{
public event MessageReceived;
public void SendMesssage(...) {...}
protected void RaiseMessageReceived(...) {...}
}
class MessageEngine
{
IFrameEngine frameEngine;
internal MessageEngine(IFrameEngine frameEngine)
{
this.frameEngine = frameEngine;
this.frameEngine.MessageReceived += ....(HandleMessageReceived)
}
internal void HandleMessageReceived(...)
{
if (mustSendMesssage)
frameEngine.SendMessage(...);
}
}
You could then write a OptimizedFrameEngine , implementing the same interface, and pass it to MessageEngine, and MessageEngine wouldn't know about it.
|
|
|
|
|
Excellent! Thanks. I think this is precisely what I need.
|
|
|
|
|
Hi!
I got a problem I've been working on for 2 full days now. I hope someone can help me out here!
Summory:
How can I use a C#.dll compiled in .net v2.0 (v2.0.50727) in a C#.dll compiled in .net v1.1 (v1.1.4322)?
The whole story:
I made a library in C# which validates xml files with an xmlSchema. I include this library in Excel 2003 by following the normal ways to do this.
This all works fine!
Then I encountered the following problem. The system this library needs to run on has Excel 2002 installed! The problem with Excel 2002 is that it looks at libraries as if they are made in .net v1.1. It's possible to work around this problem by telling excel to look at the library from a v2.0 perspective by including an excel.exe.config in the excel directory. However, the users who have to use this library do not have administrator rights and the excel folder is read-only.
I tried to work around this problem by splitting up my library in 2 different libraries.
The first library is compiled as a v1.1 dll (Parser.dll), which i include in excel.
The other library is compiled as a v2.0 dll (XmlValidator.dll) and contains my xmlSchema validation code (not available in v1.1).
I want to make some calls to those v2.0 functions from my v1.1 dll.
And the problem is that I do not get this cross version call to work.
parser.dll
using ...
public class Parser
{
private XmlDocument doc = new XmlDocument();
public string ParseXml(string xmlPath)
{
if (XmlValidator.ValidateXml(xmlPath))
{
doc.Load(xmlPath);
return "parsed";
}
else
{
return "validation failed";
}
}
}
XmlValidator.dll
using ...
class XmlValidator
{
...
public static bool ValidateXmlFile(string xmlPath)
{
doc = new XmlDocument();
doc.Load(xmlPath);
doc.Validate(eventHandler);
if (validationMessage != null)
{
return false;
}
else
{
return true;
}
}
...
}
Both of the above files do what they should do seperately. Or when I include them in the same namespace and compile them both in v2.0.
I've been experimenting with the regasm.exe tool and typelibraries. But I can not find any decent examples from people with a similar problem.
So... any ideas?
Basje
modified on Thursday, October 9, 2008 9:03 AM
|
|
|
|
|
What's .net 1.3? After 1.1, .NET went to 2.0.
|
|
|
|
|
Since I mentioned "v1.3" 7 times... I suppose I'm unable to hide behind a "typo issue".
I did off course mean 1.1, i have no idea why i typed 1.3! Sorry about the confusion!
|
|
|
|
|
One application can only run one version of the framework. To get access to the methods in framework 2.0 the application has to use that version of the framework.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
I hoped to get around this by building them seperately and using something like DLLImport.
|
|
|
|
|
Not going to happen. DLLImports are imported directly into the process using the imported functions. A process can only use a single version of the .NET CLR at any one time. In order to use both CLR's, you'd have to have an external component running as it's own process. Now you're limited to using Remoting methods to talk between two processes.
|
|
|
|
|
I hoped to read something like: "do this, that and it works !"
Anyway, thanks for the info guys! Time to look for a different solution!
-Basje
|
|
|
|
|
Got it working with .Net remoting
Thx a lot!
|
|
|
|
|
Np problem.
|
|
|
|
|
You might be able to do this by writing a com wrapper in 2.0 around the library you need. The catch being that you'll be limited to COM's more restricted set of data types in your interfaces. Other forms of software as a service might work but I'm not familiar enough with any of them to have an intelligent opinion.
Today's lesson is brought to you by the word "niggardly". Remember kids, don't attribute to racism what can be explained by Scandinavian language roots.
-- Robert Royall
|
|
|
|
|
I want to make a crystal report using sql server query this report is cross tab report. dont use the expert to design the report.
kindly help me in this regard.
thanks.
Tanvir
|
|
|
|
|
|
Hi Guys,
the code I was using for one of my previous application worked perfectly.
But not any more - using visual studio 2008 and .Net 2.0.
I read a couple of articles .... I also came accross this sample:
http://www.codeproject.com/KB/cs/prettygoodsplashscreen.aspx
Well, after downloading and running this sample I got the same error again.
when puttin this in the Stat-thread-method:
CheckForIllegalCrossThreadCalls = false;
it works fine, but this is not the right solution in my opinion.
I appreciate any suggestions for a clean solution, how to show a splascreen before starting the application / showing the main form. (couldnt find anything useful on the internet)
thanks
best regards
tom
ps- my startupform code:
public partial class StartUpForm : Telerik.WinControls.UI.ShapedForm
{
private static Thread _splashLauncher;
private static StartUpForm _splashScreen;
private static event Error _RaiseException = null;
public StartUpForm()
{
InitializeComponent();
radWaitingBar1.StartWaiting();
label2.Text = "Initalising Software.....please wait...";
}
~StartUpForm()
{
radWaitingBar1.EndWaiting();
}
private static void RaiseException(string ErrorMessage, Exception ex)
{
if (_RaiseException != null)
_RaiseException.Invoke(ErrorMessage, ex);
}
public static void ShowSplash()
{
try
{
_splashLauncher = new Thread(new ThreadStart(LaunchSplash));
_splashLauncher.IsBackground = true;
_splashLauncher.Start();
}
catch (ArgumentNullException ex)
{
RaiseException("The start parameter is a null reference", ex);
}
catch (ThreadStateException ex)
{
RaiseException("The thread has already been started.", ex);
}
catch (SecurityException ex)
{
RaiseException("The caller does not have the appropriate SecurityPermission.", ex);
}
catch (OutOfMemoryException ex)
{
RaiseException("There is not enough memory available to start this thread.", ex);
}
}
private static void LaunchSplash()
{
_splashScreen = new StartUpForm();
try
{
Application.Run(_splashScreen);
}
catch (Exception ex)
{
RaiseException("A main message loop is already running on the current thread", ex);
}
}
private static void CloseSplashDown()
{
Application.ExitThread();
}
public static void CloseSplash()
{
MethodInvoker mi = new MethodInvoker(CloseSplashDown);
_splashScreen.BeginInvoke(mi);
}
}
code for application entry point:
static class Program
{
///
/// Der Haupteinstiegspunkt für die Anwendung.
///
[STAThread]
static void Main()
{
try
{
//CheckForIllegalCrossThreadCalls = false;
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
StartUpForm.ShowSplash();
Application.Run(new Form1());
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + ex.InnerException + ex.StackTrace + " " +
Thread.CurrentThread.ManagedThreadId);
}
}
}
|
|
|
|
|
Can you post the exception stack trace? The code looks ok to me.
|
|
|
|
|
Hi Senthil,
the code breaks every time on a different position. the 1st and 2nd stacktrace are from the main-form, where the exception occured. the last exception happened at the application-entry point [StatThread]
thanks for your help mate!
cheers
Tom
1.
" bei System.Drawing.Drawing2D.Matrix.get_Elements()\r\n bei Telerik.WinControls.TelerikHelper.GetBoundingRect(RectangleF rect, Matrix matrix)\r\n bei Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.Measure(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.MeasureOverride(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.Measure(SizeF availableSize)\r\n bei Telerik.WinControls.UI.ComboBoxEditorLayoutPanel.MeasureOverride(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.Measure(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.MeasureOverride(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.Measure(SizeF availableSize)\r\n bei Telerik.WinControls.RootRadElement.MeasureOverride(SizeF availableSize)\r\n bei Telerik.WinControls.RootRadElement.MeasureCore(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.Measure(SizeF availableSize)\r\n bei Telerik.WinControls.ComponentLayoutElementTree.PerformInnerLayout(Boolean performMeasure, Int32 x, Int32 y, Int32 width, Int32 height)\r\n bei Telerik.WinControls.ComponentLayoutElementTree.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)\r\n bei Telerik.WinControls.RadControl.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)\r\n bei System.Windows.Forms.Control.SetBounds(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)\r\n bei System.Windows.Forms.Control.set_Size(Size value)\r\n bei AngebotsControlDLL.ctrlRatenEinlage.InitializeComponent() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlRatenEinlage.Designer.cs:Zeile 113.\r\n bei AngebotsControlDLL.ctrlRatenEinlage..ctor() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlRatenEinlage.cs:Zeile 16.\r\n bei AngebotsControlDLL.ctrlAngebot.InitializeComponent() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlAngebot.Designer.cs:Zeile 57.\r\n bei AngebotsControlDLL.ctrlAngebot.Init() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlAngebot.cs:Zeile 59.\r\n bei AngebotsControlDLL.ctrlAngebot..ctor() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlAngebot.cs:Zeile 41.\r\n bei GUIAngebotsSoftware.Angebotssoftware.InitializeComponent() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\GUIAngebotsSoftware\\Angebotssoftware.Designer.cs:Zeile 213.\r\n bei GUIAngebotsSoftware.Angebotssoftware..ctor() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\GUIAngebotsSoftware\\Angebotssoftware.cs:Zeile 75."
2.
" bei System.Drawing.Drawing2D.Matrix.get_IsIdentity()\r\n bei Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.Measure(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.MeasureOverride(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.MeasureCore(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.Measure(SizeF availableSize)\r\n bei Telerik.WinControls.RootRadElement.MeasureOverride(SizeF availableSize)\r\n bei Telerik.WinControls.RootRadElement.MeasureCore(SizeF availableSize)\r\n bei Telerik.WinControls.RadElement.Measure(SizeF availableSize)\r\n bei Telerik.WinControls.ComponentLayoutElementTree.PerformInnerLayout(Boolean performMeasure, Int32 x, Int32 y, Int32 width, Int32 height)\r\n bei Telerik.WinControls.ComponentLayoutElementTree.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)\r\n bei Telerik.WinControls.RadControl.SetBoundsCore(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)\r\n bei System.Windows.Forms.Control.SetBounds(Int32 x, Int32 y, Int32 width, Int32 height, BoundsSpecified specified)\r\n bei System.Windows.Forms.Control.set_Size(Size value)\r\n bei AngebotsControlDLL.ctrlRatenEinlage.InitializeComponent() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlRatenEinlage.Designer.cs:Zeile 136.\r\n bei AngebotsControlDLL.ctrlRatenEinlage..ctor() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlRatenEinlage.cs:Zeile 16.\r\n bei AngebotsControlDLL.ctrlAngebot.InitializeComponent() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlAngebot.Designer.cs:Zeile 57.\r\n bei AngebotsControlDLL.ctrlAngebot.Init() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlAngebot.cs:Zeile 59.\r\n bei AngebotsControlDLL.ctrlAngebot..ctor() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\AngebotsControlDLL\\ctrlAngebot.cs:Zeile 41.\r\n bei GUIAngebotsSoftware.Angebotssoftware.InitializeComponent() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\GUIAngebotsSoftware\\Angebotssoftware.Designer.cs:Zeile 213.\r\n bei GUIAngebotsSoftware.Angebotssoftware..ctor() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\GUIAngebotsSoftware\\Angebotssoftware.cs:Zeile 75."
3.
" bei System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)\r\n bei System.Windows.Forms.Control.BeginInvoke(Delegate method, Object[] args)\r\n bei System.Windows.Forms.Control.BeginInvoke(Delegate method)\r\n bei GUIAngebotsSoftware.StartUpForm.CloseSplash() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\GUIAngebotsSoftware\\StartUpForm.cs:Zeile 84.\r\n bei GUIAngebotsSoftware.Angebotssoftware..ctor() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\GUIAngebotsSoftware\\Angebotssoftware.cs:Zeile 96.\r\n bei GUIAngebotsSoftware.Program.Main() in E:\\Development\\AngebotsSoftware\\AngebotsSoftware\\GUIAngebotsSoftware\\Program.cs:Zeile 23."
|
|
|
|
|
I can't comment on the first two, as they seem to originate from designer code. Are you sure you're not accessing any properties of StartupForm from anywhere else in the code?
For the third, I'd guess that you called Close even before the form could initialize. You could try putting a IsHandleCreated check, or you could simply store that you called Close in a boolean variable and then close the form after it has completed initialization.
|
|
|
|
|
|
Hi,
i have a variable strpicture in c# code behind file and i want to pass this variable to a javascript function ShowPicture(take strpicture as parameter) how can i pass this variable to a javascript function if some one know please give me a hint.
KnightGuy
|
|
|
|
|
Hi,
i'm not really sure what you want to achieve, but if you want to pass the content of the strpicture-variable to a javascript-function during the "onLoad" you could use hiddenfields. Just put strpicture into a hiddenfield of your asp-form and access the value of this field during the "onLoad".
Should look like this (client-side):
function onload() {
value = document.getElementById("here goes the hiddenfield-name").value;
ShowPicture(value);
}
...
<body onload='javascript:onload()'>...
Hope this helps...
Regards
Sebastian
|
|
|
|
|