|
When doing Remoting Configuration on client side
Can I have multiple entries under <client> like:
<client>
<wellknown type...>
<wellknown type...>
</client>
in the configuration file.
If yes, then how can I choose a particular entry and
get a proxy remote object.
|
|
|
|
|
If I understand your question, I think what you are trying to do is connect to one of multiple remote servers. If so...here is your solution which works for me today.
First, get rid of your client config.
Next you want to establish your channel and load your remote objects dynamically with code as well as having the ability to reset your location to go to a new server.
The reset is basically : at the time a new server is requested you close your connection and free up your channel.
Getting the channel is very generic. I use SOAP over HTTP is my connection returns the 'Version number error' and I use Binary over HTTP otherwise for speed and agility.
When the user has selected a location (in this code it is stored in a string variable named (obviously) url:
public static void reSetWebsite(NamedWebsite passedWeb)
{
currentWeb = passedWeb.Clone();
globalObjects = null;
if (channel != null)
ChannelServices.UnregisterChannel(channel);
}
public static void InitializeRemoting(bool DebugState)
{
try
{
if (DebugState == false)
{
channel = new HttpChannel(null,
new BinaryClientFormatterSinkProvider(),
new BinaryServerFormatterSinkProvider());
System.Diagnostics.Debug.WriteLine("MyApp has not been requested to run in debug mode.", "Remote Communication Manager");
}
else
{
channel = new HttpChannel(null,null,null);
runningInDebugMode = true;
System.Diagnostics.Debug.WriteLine("MYApp has been requested to run in debug mode.", "Remote Communication Manager");
}
channel.Properties["proxyName"] = null;
channel.Properties["useDefaultCredentials"] = "true";
ChannelServices.RegisterChannel(channel);
}
catch (System.Exception exc)
{
throw new System.Exception("Problem initializing the remote object channel", exc);
}
}
public static void LoadGlobalManager()
{
try
{
string location = url + "\GlobalManager.rem";
globalObjects = (IGlobalManager) Activator.GetObject(
typeof(IGlobalManager),
location);
System.Diagnostics.Debug.WriteLineIf(runningInDebugMode, "Placing remote communication library in debug mode", "Remote Communication Manager");
globalObjects.SetDebug = runningInDebugMode;
}
catch (Exception se)
{
throw new ApplicationException("Load of global objects failed", se);
}
}
_____________________________________________
Of all the senses I could possibly lose, It is the one called 'common' that gets lost the most.
|
|
|
|
|
When ever I put a node into the treeview I get
horizontal scrollbar immediately.
Ho do I avoid It?
How can I customize the TreeView Scroll Bar like backcolor etc.
|
|
|
|
|
When doing Remoting Configuration on client side
Can I have multiple entries under <client> like:
<client>
<wellknown type...>
<wellknown type...>
</client>
If yes, then how can I choose a particular entry and
get a proxy remote object.
|
|
|
|
|
If you configure .NET remoting by calling RemotingConfiguration.Configure , passing the path to the file that contains this (often the application's .config file), then you can either use the new operator (just like you use to instantiate any other class) or Activator.CreateInstance . Since each client instance of the <wellknown> element includes a type, when the the CLR create a new instance of the class the remoting infrastructure creates a new proxy for your type.
So, if you had something like this:
<client>
<wellknown type="Class1, MyAsm" url="tcp://localhost:8000/Class1.rem" />
<wellknown type="Class2, MyAsm" url="tcp://localhost:8000/Class2.rem" />
</client> Then a simple call to new Class1() would create the first well-known object.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a main application that is referenced by a plugin. I would like the plugin assembly to be copied into the main application folder. Currently I have to do it manually because VS.net will not allow me to add a circular dependency.
Any solutions?
|
|
|
|
|
The solution is a simple logical solution: a plugin should typically not have a dependency on the application that hosts it, but perhaps a shared assembly that the application uses. Having the plugin depend on the application itself makes your design very inflexible.
Worse yet, never have a dependency on your plugin. The whole idea of plugins is that they can be added or removed from your application (either before executing it or while executing it) without the application knowing about it. This is where polymorphism comes into play. You either use interfaces or abstract classes declared in a shared assembly that plugins reference. They extend the abstract class and/or implement the required interfaces. Your application communicates with the plugins through these classes or interfaces without knowledge of the actual implementation. This is the entire fundation of COM, .NET (a progression of COM, but not a replacement), web services, and many other technologies. All communication is done through a common interface (also called a "contract") so that the implementation is hidden. That's a true plugin.
These plugins could be loaded from the .config file (common in .NET applications), some other file or the registry (which COM uses, but is not recommended for .NET code for deployment reasons), or even enumerated in a directory and loaded.
There are many articles here on CodeProject that discuss various implementations of plug-in system. Just try a search for "plug-ins" or something similar.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I understand all of that. It's just the way I worded it.
My solution: create an xml files that holds the plugins currently in use. For plugin paths just use the existing file structure without copying the files to the local directory.
I admit I should not have been working for the 18 hour that day.
|
|
|
|
|
Why not have the plugin simply implement a delegate/event? The main application would add a handler for that event. Each time the event is caught, the main app could make a call into the plugin. Hence the plugin would initiate a call from the main app.
|
|
|
|
|
Hi guys & experts,
wanna ask u some questions...
I've managed to create a windows media player custom control, which inherits from HtmlControl, but having problem in setting the URL attribute. Here's the code:
<br />
using System;<br />
using System.Web;<br />
using System.Web.UI;<br />
using System.Collections;<br />
using System.Collections.Specialized;<br />
using System.Reflection;<br />
using Microsoft.MediaPlayer;<br />
using System.Web.UI.HtmlControls;<br />
using System.Web.UI.WebControls;<br />
<br />
<br />
namespace LogPlayer1<br />
{<br />
public class MediaPlayer : HtmlControl <br />
{<br />
<br />
<br />
public MediaPlayer()<br />
{<br />
<br />
Url = WebForm1.passedURL;<br />
<br />
<br />
}<br />
public string Url <br />
{ <br />
get { return (string) ViewState["Url"]; } <br />
set { ViewState["Url"] = value; } <br />
} <br />
protected override void Render(HtmlTextWriter writer) <br />
{ <br />
writer.WriteBeginTag("OBJECT");<br />
writer.WriteAttribute("style", "Z-INDEX: 101; LEFT: 152px; WIDTH: 464px; POSITION: absolute; TOP: 160px; HEIGHT: 397px"); <br />
writer.WriteAttribute("classid", "clsid:6BF52A52-394A-11D3-B153-00C04F79FAA6");<br />
<br />
writer.WriteBeginTag("param");<br />
writer.WriteAttribute("name", "URL"); <br />
writer.WriteAttribute("value", Url); <br />
writer.WriteEndTag("param"); <br />
<br />
writer.WriteEndTag("object"); <br />
<br />
}<br />
<br />
}<br />
}<br />
<br />
<br />
This code basically writes the the windows media player to the ASPX file. but somehow I can't set the URL. The WebForm1.passedURL is a variable containing the url of the file. I've done some tests, and proven that the passedURL value is passed to the MediaPlayer class, but somehow cannot be set as the URL of the windows media player object. Or maybe the player won't play it for some reason. Could any of u give any solutions to this?
thanks in advance guyz
|
|
|
|
|
NEVER have a class request information from its parent in this way! This is WAY to tightly coupled. In your page, you simply set this control's Url property to whatever you want, just like you wouls set the <asp:HyperLink> 's NavigateUrl property, for instance, or many other contro's Text properties, etc. Why else would you declare it as a property? Your class is request accessing from a particular instance, which is completely the wrong way of doing it. Callers of your class set properties. In this case, that may be either the .aspx or .ascx file that contains the element for your control or your code-behind file.
Also, there are a couple of different param names that Windows Media Player uses depending on which version you're embedding. You should look at the Windows Media SDK on MSDN[^] and/or check out other examples online to use the right property with the right CLSID (class ID, a GUID).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
sorry... don't really understand your language... could u explain more?
thanks
|
|
|
|
|
You don't understand simple object-oriented development? Think, for example, of Console.WriteLine . Does it ask you what to print, or do you tell it? The latter of course.
Your WMP control should have the Url property set by the container control (like the Page or other container), just like they set the Text property of a Label or the NavigateUrl or a HyperLink control either in the HTML declaration of your control, or programmatically. NEVER request a property from a page like that, which wouldn't work properly anyway without a reference to the page itself (and a cast in order to get a field defined in your class, not the Page or other container control's class).
It's a simple difference between callers and callees. Just look at all the other server controls declared in your page. Are they asking your page for data, or does your page provide the data to them. Again, the latter case is true. Your control should act no differently, such that in your .aspx you might find:
<uc1:wmp id="wmp1" runat="server" url="/path/to/file.wmv" /> ASP.NET uses the url proeprty to set your Url property in your class, and when the Render method is called by ASP.NET your code will get the value of that property. At no point does this code request a variable from some page.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
whoa.... that was quick ... and harsh... forgive me for not knowing basic knowledge... that's why I'm not a Microsoft MVP maybe?...
thanks for the reply though..
|
|
|
|
|
I have a borderless form with a background color/transparent setting so that the form background is sucsesfully transparent. When I place a .png (or gif) in a picturebox on top of this transparent form, the transparent bits of the png show as white and not as transparent. I don't see a specific picturebox color transparent setting - anything else I should try?
|
|
|
|
|
I had the same problem with a label. I ended up writing the text out manually with the graphics object. You might have to do the same.
My goal is to look at code like a chessmaster looks at a chessboard to see positions and possibilites beyond lines and characters.
|
|
|
|
|
I was afraid of that. It's a fairly complex photoshop image and I doubt I could recreate it easly with graphics.
Still looking for some help here...
|
|
|
|
|
Only forms have transparency support through layered window support. A PictureBox is a separate control, not a layered window, so the container window - while still being layered - is not what's showing up again.
A good way to solve this is to either set your picture as the form's BackgroundImage or paint it on yourself, and then set the color in the image you want transparent as the TransparencyKey for the Form . See the documentation for the TransparencyKey property for more information.
EDIT: Oh yeah, and that's only supported in Windows 2000, XP, 2003 and newer. For older Windows OS's you'll have to resort to clipping regions, which won't give you great quality and is typically a pain since you have to code all the splines.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath, another excellent answer!
|
|
|
|
|
I have a VC dialog that hosts a FlexGrid control. The contol has two columns with data. The first column has read only data and is fixed. So it has a 3D edge for each cell that looks like a button. The second column is editable.
I'm porting this to C#. In the form I place a DataGrid to display the data. Two things I cannot do with DataGrid. First, I cannot get the 3D edge for the cells in column 1 and second, I cannot stop DataGrid from adding new rows. I just need to edit the contents of column 2 and not add more rows.
Can somebody help ?
« Superman »
|
|
|
|
|
To create custom columns, extend the DataGridColumnStyle and override the necessary methods. You could then paint whatever borders you want. There are many examples here on CodeProject, MSDN[^], and elsewhere (just google).
To disallow new rows, you either need to bind to an IList or IListSource implementation that is fixed in size (like an array of objects), or bind to a DataView instead of a DataSet or DataTable . Set the DataView.AllowNew property to true when doing so. See the documentation for the DataView class for more information and example code.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks Heath for you earlier reply. I could get what I wanted done.
But I have another problem and thought maybe you could shed some light.
The grid has 2 columns and 5 rows out of which one column is editable. I'm implementing an observer pattern where the grid is one of the views. When the user changes the text in the grid column I need to update the model. For this I register for the LostFocus event of the TextBox hosted in the DataGridTextBoxColumn. This is done in my derived class.
Everything is allright if the user enters text and changes focus using the mouse. But using the arrow keys, the focus does change to the next grid cell, but there is no LostFocus event generated.
« Superman »
|
|
|
|
|
When deriving your own classes, you can fire all the events you want. The Commit method is still called on the derived class so add an event to your class and fire it inside the Commit implementation. It's your class - you have control of what happens.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hello,
I am using drag and drop in my app. I have this code for the DragEnter event:
<br />
private void tabPage1_DragEnter(object sender, System.Windows.Forms.DragEventArgs e)<br />
{<br />
if( e.Data.GetDataPresent(DataFormats.FileDrop, false) == true )<br />
e.Effect = DragDropEffects.All;<br />
else<br />
e.Effect = DragDropEffects.None;<br />
}<br />
Now, how can I tell if a file or folder was dropped? What I am using now in DragDrop is:
<br />
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);<br />
<br />
foreach( string file in files )<br />
{<br />
DirectoryInfo di = new DirectoryInfo(file);<br />
if (di.Exists)<br />
MessageBox.Show("DIR: "+file);<br />
else<br />
MessageBox.Show("FILE: "+file);<br />
}<br />
Is this the proper way to do the check?
Thanx for the help,
-Flack
|
|
|
|
|
You handle the DragDrop event and use the DragEventArgs.Data.GetDate to get a string[] array (in your case). Then just copy the files or whatever.
In your DragEnter event handler, don't use DragDropEffects.All unless you intend to support all effects (some of which aren't often relevant). Just set the ones you actually support, like Move or Copy , which are the two most common ones.
Microsoft MVP, Visual C#
My Articles
|
|
|
|