|
Either in a static constructor or inline:
static int[] intArray[] = { 1, 2, 3 }; I hope this helps!
Luis Alonso Ramos
Intelectix
Chihuahua, Mexico Not much here: My CP Blog!
|
|
|
|
|
Hello everybody
I'm trying to scale down a image file, the thing is that I can't find anyway to do that without getting the image into a Grapgics object.
Using the graphics object to scale down is easy (using ScaleTransform()), the thing is that I want to convert back to Image in order to place the image in a picturebox.
can anyone help me with that???
Thanks in advance!
|
|
|
|
|
Instead of changing your instance you could create a new one:
Image oldImage;
Image newImage = new Bitmap(wantedWidth, wantedHeight);
using (Graphics g = Graphics.FromImage(newImage))
{
g.DrawImage(oldImage, 0, 0, wantedWidth, wantedHeight);
}
|
|
|
|
|
how can i change the machine name using C# code?
|
|
|
|
|
complete method is available at following link.
http://www.thescripts.com/forum/thread108650.html
Shajeel
|
|
|
|
|
Say, I have this string ℵ, the hebrew Alef Symbol. In the charmap program it maps to the Unicode code point U+2135 (hex). However when I do a GetBytes on a string with alef in it, I get back a 3 byte representation: E2 84 B5.
I'm just confused on how to map this back into 21 35???? How does the hex E2 84 B5 relate to 21 35. Why does charmap say alef is 2 bytes, when UTF8Encoding.GetBytes says it's 3 bytes?
/\ |_ E X E GG
|
|
|
|
|
What encoding do you use?
If you use UTF8, for instance, most characters are encoded as 8 bits, but the characters that really need 16 bits have to use an extra byte to form an entity that contains 16 bits of data and still is distinguishable from two regular characters.
If you examine the bit pattern of the bytes, it's easy to see how it works.
The binary code for 0x2135 is 0010000100110101. This is divided into three parts: 0010, 000100 and 110101.
By adding 1110 before the first part and 10 before the two other, you get the patterns 11100010, 10000100 and 10110101, which written in hexadecimal are 0xE2, 0x84 and 0xB5.
---
b { font-weight: normal; }
|
|
|
|
|
Guffa wrote: By adding 1110 before the first part and 10 before the two other
Where did you get the idea to do that?
/\ |_ E X E GG
|
|
|
|
|
Hi,
I want to create label array. Like this lable1[0], lable1[1]...
Thanks...
|
|
|
|
|
dataminers wrote: I want to create label array. Like this lable1[0], lable1[1]...
I shall allow this.
Seriously, though, it's not different from making an array of other objects. Are you making an array of labels already on a form?
Label[] label1 = new Label[] { firstLabel, secondLabel, thirdLabel, ... };
Or to make an array of labelCount labels:
Label[] label1 = new Label[labelCount];
label1[0] = new Label();
label1[1] = new Label();
--
I've killed again, haven't I?
|
|
|
|
|
Good afternoon.
How to send the e-mail through Outlook that there was no window Outlook Security in C#?
HOW use MAPI in C#??? Please take the sourse in which e-mail letter sends.
Thanks!
|
|
|
|
|
Hello programmers,
I wrote a remoting server and a client. I use some basic Remoting techniques:
1) There is a class/interface (remote object) declaring the Functions, like "String SendCommand(String text) ". Lets call it RemoteObj (IRemoteObj ).
2) Then, I register a well-known Type:
RemotingConfiguration.RegisterWellKnownServiceType(<br />
typeof(RemoteObj), "RemoteServer",<br />
WellKnownObjectMode.Singleton);
Now there is my problem: When the client executes the method, then i need to handle it completely inside the RemoteObj since i dont have a reference to the registered Object instance. This is not what i want actually, because i have the whole ready application around the RemoteObj Object which is able to return the whole data needed. The Remote Server is just a part of my application, not the other way round.
Is there a possibility to reference the Singleton object instance? I even could imagine to handle the communication by delegates/events.
Can you help me?
Thanks in Advance!
|
|
|
|
|
Your question/problem is not very clearly stated....
however here is how I deploy remoting.
On the server side I have RemoteClass which inherits IRemoteEntity (I changed your name to avoid confusion)
On the remote side you should register IRemoteEntity NOT RemoteObj
On the client side you want to connect to the remote server asking for a type IRemoteEntity. All references on the client side work with the IRemoteEntity instead of the RemoteObj.
So now I have a reference via an instance variable in the client to my remote object which was defined
IRemoteEntity remoting;
Now I can do this:
string value = remoting.SendCommand( command );
All code is now executed on the remote server.
|
|
|
|
|
Ok thanks so far, but this is not exactly the problem, let me explain further.
You explained how to contact the Remoting Server from the Client, so lets continue from there.
The Server received the command String sent from the Client (from SendCommand Method. Now, everything happens in an instance of RemoteObj (which implements IRemoteEntity and MarshalByRefObject ).
But now, the RemoteObj needs information from the current instance of the Server Application which originally registered the Service (you remember my first post? ), which is the instance doing the actual work.
But i dont have any reference to the instance neither from the RemoteObj to the server application, nor the other way.
I hope, you can understand now.
Here is another very small example:
using System.Runtime.Remoting...
namespace MyService
{
public class SimServer
{
private int listeningPort = 17998;
private TcpChannel channel;
public int justATestVariable = 123;
RemotingConfiguration.RegisterWellKnownServiceType(
typeof(MyService.ServerObj), "TheServer",
WellKnownObjectMode.Singleton);
}
public class ServerObj : MarshalByRefObject, IRemoteEntity
{
public String SendMessage(String message) {
}
}
}
Now, imagine the Server was started, therefore a single instance of MyService.ServerObj was created. Then, the method SendCommand was called from a client, and the Serving Object (ServerObj ) needs the current value of justATestVariable to be able to reply to the clients request.
Any advices?
Thank you!
|
|
|
|
|
Your class SimServer is usually called the Remoting Host. In all designs I've seen so far, the only purpose of the Host was setting up the Remiting environment and providing the process the Server (your class ServerObj) runs in. I've never tried to establish any communication between the Remoting Server object and its Host. Therefore, the following approach is just an idea and has not been tested.
If the Server and the Host exist within the same AppDomain of the Host's process, you may declare certain methods/properties of the Host static.
<br />
namespace MyService<br />
{<br />
public class SimServer<br />
{<br />
static public int justATestVariable = 123;<br />
}<br />
<br />
public class ServerObj : MarshalByRefObject, IRemoteEntity<br />
{<br />
int myCopy = SimServer.justATestVariable;<br />
}<br />
}<br />
Alternatively you can make the Host a singleton and access its only instance from your server object.
If the Server and the Host are placed in different AppDomains, things will become more complicated. You will have to set up a separate channel of communication between the two objects, e.g. using pipes. There are some articles here on CP about this topic.
|
|
|
|
|
Thanks Tim for your reply and your explainations
I really appreciate your help!
I understand your design approaches, but i want to clarify my approach here:
Looks like i run into that problem because the application was originally never designed to be a server, but we found out later, that it might be very handy to have it started on a server machine and be able to get the needed data by requesting it from a small client application. So the basic idea of the remoting server functionality was more just a plugin or addon feature to the main application, therefore, the main application became just a host and not the Remoting Server itself. It can run completely without the server, it has its own GUI, its even based on its GUI.
So this is the main reason why the - let me call it: "Remoting Server Plugin" needs most of its data from the host.
The idea to provide Static methods is maybe not cleanest design but it might be the easiest one. I have no idea how to make the Host a Singleton.
Well thanks again!
|
|
|
|
|
In C# it is really simple to create a Singleton. You don't have to use the double-checked locked accessor as it is used in C++ or Java.
public class Server
{
private static readonly Server _instance = new Server();
private Server()
{
}
public static Server Instance
{
get{ return Server._instance; }
}
}
Within your code you now must use Server.Instance instead of new Server() . Thus your "Server Host" and your "Remoting Plugin" will access the same object.
|
|
|
|
|
Hi,
I'm developing an asp.net application which logs error in case of exceptions.
When it logs error teh following message displayed in event log.
Error loading an Event Sink of type 'Microsoft.EnterpriseInstrumentation.EventSinks.LogEventSink'. The Event Source of name 'Application' will not write events out to this Event Sink. The following exception was returned during the load:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentException: An error occurred determining if the Windows Event Log source of Application (Loan) exists on machine .. This may be due to an incorrect machineName parameter. ---> System.Security.SecurityException: Requested registry access is not allowed.
at Microsoft.Win32.RegistryKey.OpenSubKey(String name, Boolean writable)
at System.Diagnostics.EventLog.FindSourceRegistration(String source, String machineName, Boolean readOnly)
at System.Diagnostics.EventLog.SourceExists(String source, String machineName)
at Microsoft.EnterpriseInstrumentation.EventSinks.LogEventSink..ctor(IDictionary parameters, EventSource eventSource)
--- End of inner exception stack trace ---
at Microsoft.EnterpriseInstrumentation.EventSinks.LogEventSink..ctor(IDictionary parameters, EventSource eventSource)
--- End of inner exception stack trace ---
at System.Reflection.RuntimeConstructorInfo.InternalInvoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault)
at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.RuntimeType.CreateInstanceImpl(BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Activator.CreateInstance(Type type, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at System.Reflection.Assembly.CreateInstance(String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes)
at Microsoft.EnterpriseInstrumentation.EventSinks.EventSink.CreateNewEventSinks(DataRow[] eventSinkRows, EventSource eventSource)
Can you please help me in this.
thanks in advance
Priya
|
|
|
|
|
I have had this problem using the Enterprise Library... it a matter of rigths over the register...
if you do it with a win application ( just for testing ) you'll see that no error is written in the Event Log... because the Win Applications runs with the Credentials of the user is logged in the machine... but the ASP.NET user doesn't have this rigths... you have to give the ASP.NET user rigths to write in the Event Log.
Regards
Ricardo Casquete
|
|
|
|
|
How would programatically change the NotifyIcon icon while a program is running. Like say I had an email checking program that ran down in the system tray but I wanted the icon to change from black to green if I have an email waiting? Or better yet display a number that is the quanitity of unread email messages on the server. Is there a away to do this without having a 99 .ico files somehwhere on the file system that are loaded when needed.
In other words is there a way to dynamically generate an icon file on the fly and then use it as the NotifyIcon?
|
|
|
|
|
|
Does anyone have some good samples of Serializing a parent object that has child objects that in
turn may have child objects. I can serialize the parent but it doesnt like what I am doing with the children unless I make them an array. At least I think it likes the array. I would like to keep the children in an ArrayList or Generic List<child>. I have one example but it uses a Hashtable and I am not sure the sample will translate into what I am doing.
|
|
|
|
|
What are you using to serialize the object graph? The XmlSerializer? The BinaryFormatter? SoapFormatter? The different serialization techniques have different requirements/constraints.
Josh
|
|
|
|
|
I would like to serialize it to XML so I am using the XmlSerializer. It serializes the parent but chokes on the the children. I have some code but it is not quite what I am doing. Any other help would be appreicated.
|
|
|
|
|
Without the actual error message it's hard to say what the problem is. But, here are some things to keep in mind about the XmlSerializer:
1) It does not serialize object graphs with circularites (A references B, and B directly or indirectly references A). It makes exceptions to this rule for a select few classes in the .NET framework, such as the DataSet, but that doesn't help the rest of us.
2) As 'theRealCondor' mentioned, it only serializes public get/set properties of an object. (It also will serialize public fields, but those should never exist!)
3) There are some attributes you can use to control how the serialization of sub-objects is performed (this might be relevant to your issue, somehow).
Here's a great tutorial on everything you would ever want to know about the XmlSerializer: http://www.topxml.com/xmlserializer/[^]
I hope that helps,
Josh
|
|
|
|
|