|
Hi George,
good for you.
I didn't know the article you referred to, but it is quite good indeed.
One thing it did not mention is you can pass an arbitrary object through the optional second parameter "UserState" of ReportProgress(); e.g. a progress string could be useful there.
Cheers.
|
|
|
|
|
Hello everyone,
I am using the following code to serialize a Type1 object instance and deserialize the object instance into a Type2 object instance.
There is exception when I deserialize, which says can not convert from Type1 to Type2. My question is, even if the content of two types are compatible (both Type1 and Type2 contain a single int field), we can not deserialize into different types?
[Serializable]
public class Type1
{
public int abc;
}
[Serializable]
public class Type2
{
public int cba;
}
public class Program
{
static void Main(string[] args)
{
Type1 input = new Type1();
input.abc = 12345;
Type2 output = new Type2();
IFormatter formatter = new BinaryFormatter();
Stream stream = new FileStream("output.bin", FileMode.Create, FileAccess.Write, FileShare.None);
formatter.Serialize(stream, input);
stream.Close();
stream = new FileStream("output.bin", FileMode.Open, FileAccess.Read, FileShare.None);
output = (Type2)formatter.Deserialize(stream);
return;
}
}
thanks in advance,
George
|
|
|
|
|
You can't cast two unrelated classes. This is no a deserialization issue, you will get a compiler error if you try to do this at compile time:
Type1 input = new Type1();
Type2 output = (Type2)input;
Cannot convert type 'Type1' to 'Type2'
Since deserialization happens at runtime you won't get a compiler error but a runtime error.
If you need to share common functionality then both should inherit from the same base class. If this is not possible then you have to copy the field values from Type1 over to Type2.
regards
modified on Sunday, November 30, 2008 10:18 AM
modified 12-Sep-18 21:01pm.
|
|
|
|
|
|
I'm looking for ideas on how to implement audit trails for my objects in C#, for the current project,basically I need to:
1.Store the old values and new values of a given object. 2.Record creation of new objects. 3.Deletion of old object.
Is there any generic way of doing this,like using C# Generics,so that I don't have to write code for events of the base object like on creation,on deletion etc.(ORM objects).The thing is that if there was a way to inject audit trail if one is using a .Anybody have any experiences or any methods they follow.Any way to do this in a Aspect-oriented (AOP) mannner.
Please share your ideas etc.
|
|
|
|
|
PostSharp[^] might be what you are looking for. It injects AOP information at compile time to your objects, so you can do the sort of things you mentioned.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
I already has castle.net as aop
|
|
|
|
|
I've use Phil Laureano's LinFu to do this type of thing.
|
|
|
|
|
Hi All,
1. Do you know if I can (and how) create an alias to the sql server via code ? what objects do I use and how ?
2. Can I configure the sql server remote access control via code (TCP/IP and name pipes) ?
Thanks
|
|
|
|
|
|
Hi Mika, thanks for your reply.
The configuration part is what I was looking for.
Regarding the alias:
In the SQL Tools -> SQL Server configuration manager ->
under SQL Native client configuration
you can create new alias to a server.
How can I do it using code ?
Thanks
|
|
|
|
|
|
Thanks !!! Works like a charm.
|
|
|
|
|
No problem
|
|
|
|
|
Hi,
I am developing a Windows Form Application using C# in Visual Studio 2008.
I have developed a form with menu strip, and now there are five different type of screens in File-> New-> I have them listed, but i am not sure how to have 5 different screens based on user choice.
Do i need to create five different forms? How can I then embed that in the main Form window?
Thanks a lot for your help
Karmendra
|
|
|
|
|
Have a FormLevel variable containing which option is clicked and accordingly make Controls Visble/Invisble on the form,or create Dynamic controls and add them to the form .
|
|
|
|
|
Use your main form as a form conteiner ok? or create 5 usercontrols and use them as pages you know? here you will have to use delegates because you can´t acess the usercontrols, just main form can acess them because is his parent.
So, if you like use main form like a form conteiner and load the other 4 forms inside him ok?
nelsonpaixao@yahoo.com.br
trying to help & get help
|
|
|
|
|
This isn't really something I need help on, but more wondering why or which way is better from asking experienced programmers.
Request.QueryString["..."];
or
Request.QueryString.Get("....");
Is there a reason for both of them? Does using the .Get save it time from not having to realize it needs to "Get" the query string? Just a silly question that has been bugging me so I've decided to ask.
|
|
|
|
|
There is no difference. The Item property get method (that you use in the first case) just calls the Get method.
The reason that both exists is probably to support programming languages that can not use an indexer (the first alternative).
Another alternative to get the values is the GetValues method, and that one is different. It returns the values as a string array instead of concatenating them together as a comma separated list.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Excellent. Thank you. Just something I've been wondering about. Thanks again!
|
|
|
|
|
Hii all..
I am creating a small application that supposed to monitor printing activities. I used Win32_PrintJob and successfully get the informations of printing process such as DocumentsName, PagesPrinted,TotalPages,Size,etc.
I store these values into database as printer log.
But, I have some difficulties in getting the bytes of printed files. Is it possible to do that using Win32_PrintJob?
I want to get these bytes to store it into database, so that the admin can see the content of printed files in the next time.
Thanks before for the answers.
|
|
|
|
|
I don't think there's an easy way to get the print job bytes using WMI. Try another, faster approach. Get every print queue using the LocalPrintServer.GetPrintQueues() method, iterate from 0 to the return value of the PrintQueue.NumberOfJobs property of the individual print queue, and use the returned PrintSystemJobInfo class from the PrintQueue.GetJob() method. There should be a PrintSystemJobInfo.JobStream property which will give you the stream of the job's data. All of these can be found in the System.Printing namespace, which you need to add a reference to (ignore what the MSDN page says about Vista, it works on XP just as well)
|
|
|
|
|
1 LocalPrintServer lps = new LocalPrintServer();
2 PrintQueueCollection pqc = lps.GetPrintQueues();
3 PrintSystemJobInfo pj;
4 foreach (PrintQueue pq in pqc)
5 {
6 pj = pq.GetJob(pq.NumberOfJobs);
7
8 }
As u sugggested, I create above code. But, I get an error at 6 line. With error description "Value cannot be null. Parameter name: printingHandler".
Do you have some suggestion? Or could you give me simple code that show your suggestion will work.
Thanks...
|
|
|
|
|
private PrintSystemJobInfo GetInfo()
{
LocalPrintServer localPrintServer = new LocalPrintServer();
PrintQueue q = LocalPrintServer.GetDefaultPrintQueue();
q.Refresh();
foreach (PrintSystemJobInfo pj in q.GetPrintJobInfoCollection())
{
return pj;
}
return null;
}
PrintSystemJobInfo pj = GetInfo();
int len = pj.JobStream.Length;
I use Windows XP Sp2
When executing len = pj.JobStream.Length an error occur "Object reference not set to an instance of an object."
Is JobStream works in XP? Because I read that it works on vista only.
|
|
|
|
|
If it only worked in Vista, then a different exception would have been thrown. As it is, you seem to be dropping past the foreach() for some reason. You do have something printing, even if only to a dummy printer, which isn't connected to the computer?
On the other point, I looked through the System.Printing.PrintQueue class with Reflector, and there doesn't seem to be any code which checks if you're running Vista, unless it relies on some new APIs, but I haven't seen any
|
|
|
|