|
I'm wondering why you must have an array with unknown length fixed to an indeterminate length.
Wouldn't this be better served by using a Hashtable ? Then you don't need to worry about lengths. If employeeLookup is a Hashtable then employeeLookup[someemployeeid] is the value you are working with. No messing with lengths at all.
|
|
|
|
|
Instead of using an array by itself you probably need to deploy a more complex collection. For example:
public class EmployeeCollection:System.Collections.SortedList
{
}
This would provide you with a base collection that associates a key:value pair. Your key would be your employeeID and your value would be your employeeObject.
You would have to implement your Add, indexed access, and Remove to have them strongly-typed for your employee object and your employee ID along with validation that a valid ID is passed for adding to the hashtotal.
This particular collection would then allow you to access either by index or key.
myObject = employeeLookup[employeeKey];
myotherObject = employeeLookup[245];
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
I could go through find the highest employeeID and then create a fixed array, then I wouln't have to worry about any resizing whatsoever.
Basiclly I want to get to the point where eventually I am going to do assignments to another array by using NewArray[employeeLookup[employeeID]] = 5;
I haven't used the hastable object before but it seems like a lot of overhead for something simple, espically when I never plan to use any of the search functions or anything like that it offers (Could be wrong on this).
|
|
|
|
|
The SortedList is one way of deploying an array that also gives you a keyed access (which is what you are really asking for). HashTable is the only way you can create a keyed lookup within an array or collection. It is also the only way to avoid getting an index exception if you go to get a number that does not exist in the array. You really are not implementing any significant overhead when you do this. In fact I think you are adding more overhead by trying to set a capacity for an array.
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
I am getting the following exception when I try to run the following MSDN Article[^].
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed.
I have not changed any of the code in the example, just loaded it in Visual Studio and did a build. Any ideas what is wrong?
|
|
|
|
|
Without knowing what object the exception is in reference too, you usually see this exception when an object is specifically made to not be marshalled for remoting. There are good security reasons why you don't want some objects to serialize let alone tell another computer the data structure.
Can you tell us any more? There is code access security that needs to be addressed for remoting but if you are running the client and the server on the same machine you should have all of the access you need to make it work.
|
|
|
|
|
<br />
internal static int ProcessRun(string[] args, Type userApplicationType) <br />
{<br />
SingletonCommunicator comm = (SingletonCommunicator)RemotingServices.Connect(typeof(SingletonCommunicator), SingletonCommunicatorUrl);<br />
<br />
if (comm.Control == null) <br />
{<br />
comm.Control = new SingletonCommunicatorControl();<br />
IntPtr h = comm.Control.Handle;<br />
<br />
UserApplicationContext context = (UserApplicationContext)Activator.CreateInstance(userApplicationType, true);<br />
comm.Control.App = context;<br />
<br />
comm.Control.App.FirstInstanceRun(args);<br />
}<br />
else <br />
{<br />
comm.Control.App.SecondInstanceRun(args);<br />
}<br />
return 0;<br />
}<br />
<br />
This is the method it kicks back to on the line: IntPtr h = comm.Control.Handle;
With this exception:
An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll
Additional information: Because of security restrictions, the type System.Runtime.Remoting.ObjRef cannot be accessed.
Full source code can be found at MSDN link[^]
|
|
|
|
|
If you are running the 1.1. Framework and using VS 2003, then you need to add a command to your remoting initialization.
BinaryServerFormatterSinkProvider serverProv =
new BinaryServerFormatterSinkProvider();
provider.TypeFilterLevel =
System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clientProv =
new BinaryClientFormatterSinkProvider();
IDictionary props = new Hashtable();
props["port"] = 1234;
HttpChannel chan = new HttpChannel(props, clientProv, provider);
ChannelServices.RegisterChannel( chan );
The 1.1 framework raised security of remoting. Default is set to the TypeFilterLevel.Low which does not allow marshalling ObjRef. Adding the TypeFilterLevel and setting it to Full will get around the issue.
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
Where do I change the security for remoting?
|
|
|
|
|
AFAIK there's no global place to change this.
You have to configure your channel formatters to use full type filtering either programmatically or by using your app.config file.
The ugly thing is that .NET 1.0 doesn't understand the "typeFilterLevel" property, so you have to decide whether you app will run with .NET 1.0 or 1.1.
Take a look here for details.
Oh, and because you use the framework from the "Real World Applications Sample" articles on MSDN: In case you haven't done yet don't forget to override InitializeLifetimeService() in the SingletonCommunicator class or you won't be able to activate your running app after about 2 mins of inactivity...
|
|
|
|
|
I have not looked at the MSDN 'real world sample' so I cannot speak specifically to that one project. mav.northwind is correct, though, in that there is no single way you implement TypeFilter ing...it all depends on how you establish your channels.
The example might not address the fact that you can configure your channel either in the configuration file or in code. The code I posted in my reply gives you the development direction within your program.
Generally: If you have an application - and it always connects to only one machine - and you never have to dynamically change this -- then you can use a configuration section. The GotDotNet article that mav pointed to will give you a discussion on the config file pieces.
Specifically: In any remoting application that we have put together we do not have a single machine being connected to. Thus we allow the user to answer a few questions in a wizard and then we let them dynamically choose the server to connect to. Then, programmatically, we get the URL from the user choice, append the remoting object URI pieces, and then create and establish the channel to the specific server. We have control over the formatters as well as defining the needed parameters such as killing the proxy server search. It minimizes what is exposed to the client that they can go mucking about in, it lets us update servers by modifying a simple config statement, and it does no expose any remoting-specific information outside of what is needed at the IIS side.
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
Hi,
I have a TabControl with 4 TabPages. Based on Access Permissions I want to grey out the selection of a particular TabPage.
I used following property to disbale:-
tabControlDeal.TabPages[3].Enabled = false
But this disables all the controls on TabPages[3], but doesn't greyout TabPage selection.
Is there any way out to greyout TabPage selection.
Thanks in advance
Ruchi
|
|
|
|
|
You could owner-draw the tabs and set the text color to SystemColors.GrayText based on the TabPage.Enabled property. Then, just make sure to reset the focus in case someone clicks on the tab. It's simplistic, but there's not a whole lot you can do with the TabControl provided in the .NET FCL (mostly because there's not a lot you can do with the tab common control it encapsulates).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want to convert html file to Doc or rtf file. How it will be possible using c# through coding. Actually i have xml file and xsl file too. So if there is a way through which we can create a doc or rtf file if we provide xml and xsl file path or html file path than guide me to that.
Thanx in advance
Inam
|
|
|
|
|
There's many ways to do this. Since RTF, for example, is just simple text, you could write your XSLT to output the necessary lines (actually, XSLT can also output binary files, but this gets much more difficult). You can find the RTF specifications on Microsoft's site, as well as other places if you try googling.
To create Word docs, you could do a number of things. You could use the Office PIAs (primary interop assemblies, which is recommended as opposed to making your own interop assemblies) to load the HTML document into word and then save it back out as a Word Document or an RTF document, all without showing the Word UI (it's still started, but not visible until you call Show on the application).
Also, Word 2000, XP, and 2003 all support XHTML - an XML document with the default namespace resembling HTML. You could always generate this instead of HTML (which doesn't necessarily conform to XML standards - nor does it have to in some cases). Word 2003 also has a well-defined schema for Word Documents that is also published on MSDN[^].
Finally, in referene to this and your previous question, there's products out there that can save reports (if you're doing any sort of reporting) to many common formats, such as HTML, PDF, and RTF. Crystal Reports for VS.NET comes with VS.NET and is installed by default. The runtime and your report definitions can be distributed freely so long as you have a valid license for VS.NET, have registered Crystal Reports for VS.NET, and are shipping as part of a Windows Forms application (ASP.NET application have additional restrictions and typically require additional runtime licenses). A cheaper alternative is ActiveReports from Data Dynamics[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i would like to implement a ihttphandler to handle all image request in a particular folder so i an add a "watermark" to the images, i have it working great for jpegs, pngs and bmps... problem is gifs, especially animated gifs... how can i watermark these on the fly?
i cannot seem to open the gifs into a Graphic object, thanks!
|
|
|
|
|
You can create a new Bitmap from a file path or a Stream . Use Graphics.FromImage to get a Graphics object for that image.
Keep in mind, however, that GIFs are indexed images and require a palette. If you're using different colors other than what exists in teh palette, you'll need to generate a new palette from the existing one and add the colors you need.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I want to convert html file to pdf file. How it will be possible using c# through coding. Actually i have xml file and xsl file too. So if there is a way through which we can create a pdf file if we provide xml and xsl file path or html file path than guide me to that.
Thanx in advance
Inam
|
|
|
|
|
FOP allows you to use an XML file with an FO formatted XSLT and produce PDFs. This was original for Java but there is a .NET port at http://sourceforge.net/projects/fop-dotnet[^]. There's also many products that give you programmatic control to create PDFs (even some that can use templates), such as Tall PDF that advertises here on CodeProject. Just try a search for "PDF" and ".NET". You should find several.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
hi,
I have several classes in my application, one of them called 'database' which handles all the database connections etc.. The concept of the program is that an SQL query is executed on a database, and parts of the results are listed in a listBox on the main form. To simplify this process, i have created a function called addList to the frmMain class which is called with the appropriate arguments to add the data to the listBox. However, because this function is being called from a class which has been created by code in frmMain, the database class does not seem to recognise that there is a function called addList, and says there needs to be an object reference or something. How do i call the addList function in frmMain from the database class? a quick reply would be appreciated,
thanks in advance,
eddmun
|
|
|
|
|
Let's say you have something like this:
namespace MyCompany.MyDepartment.MyApplication
{
public class frmMain
{
public void AddList(string[] args)
{}
}
}
namespace MyCompany.MyDepartment.MyApplication
{
public class database
{}
}
then all you may need to do is this:
change AddList from public to static
in your database class add a using MyCompany.MyDepartment.MyApplication;
Then see if it compiles.
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
Your database class needs to be able to access an instance of your form if you need to call an instance method (to make the method static would also be problematic since you can only add data to your UI in an instance of the form). If your form, for example, is what creates the instance of your database class, pass this (a self-reference to the form) to the database class's constructor or something. Another way - although not recommended - is to provide a static property on your form class that gets an instance of the form, which the form can set in its constructor like so:
public class MyForm : Form
{
public MyForm()
{
instance = this;
}
private static MyForm instance;
public static MyForm Instance { get { return instance; } }
} The problem with this is that multiple instance of your form will "reset" the static field (and be returned in the property). If you're sure that you'll never have more than one instance of this form, this would work in a pinch, though something like the first way I mentioned (passing an instance of the form to your database class) might be better if possible.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I posted this question late last night, didn't get a satisfactory answer, and now all the experts can't see the post. So I will post one more time.
I have a class with a private event/delegate model.
[Serializable]
public class MyClass
{
private SomeCollection collection = new SomeCollection();
public MyClass()
{
this.collection.Changed += new EventHandler(this.SomePrivateMethod);
}
private void SomePrivateMethod(object sender, EventArgs e)
{
}
}
I can serialize the above class without problem, however, upon deserialization, I recieve an exception telling me "delegates to non-public methods cannot be deserialized." If I change the accessor of SomePrivateMethod to public the whole things works. But I really don't want to have to expose SomePrivateMethod as public.
So what do I do here, how can I serialize and deserialize the above class without SomePrivateMethod having a public accessor?
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|
|
If you are doing XMLSerializer then only public properties that contain public setters and getters will serialize/deserialize. However if you deployed using the binary serializer, then you should get the behavior you want.
If this object is being passed between application domains via remoting, and you happen to use the SOAP formatters, that is your problem. You can change your remoting channel definition and that should behave more in the fashion you want them to behave. So you would define the channel as follows:
public static void InitializeRemoting(bool DebugState)
{
try
{
if (DebugState == false)
{
channel = new HttpChannel(null,new BinaryClientFormatterSinkProvider(),new BinaryServerFormatterSinkProvider());
System.Diagnostics.Debug.WriteLine("System 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("System 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);
}
}
The debug work is to switch over to the SOAP converter in the event I make remote changes that return the famous 'version incompatability' error. The SOAP channel lets the true exception pass through so that I can see where I screwed up.
I hope this helps, and if not then just let me know where you need additional direction.
_____________________________________________
Of all the senses I could possibly lose, It is most often the one called 'common' that gets lost.
|
|
|
|
|
Thanks for the reply. I am using remoting with soap formatters, so you hit the nail on the head.
So, what code in particular makes the difference - the channel properties? Or just passing in BinarySink providers?
In reply to your other post, yeah you're the 3rd person to recommend Ingo Rammer's website/FAQ/book to me. My boss just purchased Rammer's remoting book for me, so I'll definitely be having a peak at this in the near future.
---------------------------
He who knows that enough is enough will always have enough.
-Lao Tsu
|
|
|
|