|
Sounds like you want the Shunting-yard algorithm[^]
You may have to change the "output queue" to "output stack" but that's trivial.
|
|
|
|
|
can we create object of partial class
This code was posted by me...
|
|
|
|
|
Yes, for example, the following code works:
public partial class Class1
{
int i = 10;
public void Foo()
{
Console.WriteLine(i);
}
}
static class Program
{
static void Main()
{
Class1 cl1 = new Class1();
cl1.Foo();
}
}
|
|
|
|
|
Yes but it will create an instance of all parts of the class (if that makes sense) and not just one of the partial implementations.
|
|
|
|
|
What exactly do you mean?
The partial keyword means nothing but: the source code for a certain class can be found in more than one ASCII file. It's all about text...
So a partial class is just another class, there is nothing like 'partial' in the IL code that the compiler generates. And of course you can instantiate a normal class...
Regards
Thomas
www.thomas-weller.de
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. Programmer - an organism that turns coffee into software.
|
|
|
|
|
The partial keyword is just a hint to the compiler. Once the code is compiled, it is no longer partial.
|
|
|
|
|
i m writing a web app to communicate with the card reader/writer.
before communicating i need to set the COM port on which it is connected .
i knw that the system emulates this usb port as a serial port.
i need to knw the COM Port on which the device is connected ,recognize a device is connected / disconnected.i m trying to use Microsoft.Win32 but not getting how to use it actually.
i m new to c# pgming ,any answers will be a great help.
plz provide sample codes if possible.
Thanx in advance.
mukeshmkg
|
|
|
|
|
If your web app is trying to read data from the users usb connection it can't be done using ASP. If you're trying to read data from a card reader connected to the server then people will be able to help but can you clarify if you are trying to use a card reader on the server or the client?
|
|
|
|
|
I write a class, its inherit from List<>. Like this;
public class ParametersList : List<Parameter>
I don't want to show all List<> property and functions when using intellisense intance of ParametersList class. I want to use just Add() function. I write add() function in my class, like this;
public new void Add(Parameter parameter)
How can I let private other List<> property and functions?
Thanks...
|
|
|
|
|
Maybe what you want is encapsulation, rather than inheritance. With inheritance you cannot, by design, hide the public implementation of the inherited class.
try this.
public class ParameterList
{
private List<Parameter> innerList;
public ParameterList()
{
this.innerList = new List<Parameter>();
}
public void Add(Parameter parm)
{
innerList.Add(parm);
}
}
Additionally, if you are using inheritance because you want your list to conform to some interface (say IList<T> ) you can achieve this by implementing the interface in your class and passing all methods through to innerList .
|
|
|
|
|
dataminers wrote: public new void Add(Parameter parameter)
I don't recommend that; especially if you are changing what the Add method does.
As mentioned by the other responder, wrap the List and implement the IList interface, don't derive.
|
|
|
|
|
|
Hi,
I have an application in which I want to upload some values, signatures and photos to the server.I want to show 4 progress bars. Some values, signatures and photos upload status on their own progress bar. 4th progress bar will show the status of all above 3 uploads collectively.
I am posting a method where I have code for it.
private void UploadServiceValuesPhotosAndSignature()
{
bool[] allResponses;
List<signature> signatures = null;
foreach (var serviceInstance in serviceInstances)
{
//Get All Signatures
signatures = serviceValues.Select(sv => sv.Signature).Distinct().ToList();
//Get All Photos
allPhotosToUpload = PostPhotoCollection.GetPhotos(serviceInstance, context);
int count = allPhotosToUpload.Count + signatures.Count + 1;
allResponses = new bool[count];
int i = 0;
//Upload serviceValues
serviceValuesWorker = new BackgroundWorker();
serviceValuesWorker.WorkerReportsProgress = true;
serviceValuesWorker.WorkerSupportsCancellation = true;
serviceValuesWorker.DoWork += delegate(object s, DoWorkEventArgs args)
{
serviceValuesWorker.ReportProgress(10);
if (serviceValuesWorker.CancellationPending)
{
args.Cancel = true;
return;
}
serviceValuesWorker.ReportProgress(50);
//serviceValuesWorker doing its work
var serializableValues = serviceInstance.ServiceValues.AsSerializable();
var serialisedValues = new Dictionary<string, object[]=""> { { "ValuesInfo", serializableValues } }.Serialize();
string responseFromServer = ServiceRequest.GetResponse("UpdateServiceInstanceMobile", "ServiceInstances", serialisedValues, serviceInstance.ServiceInstanceID.ToString());
var response = responseFromServer.Deserialize<dictionary<string, object="">>();
bool successServiceValues = (bool)response["success"];
if (successServiceValues)
{
serviceValuesWorker.ReportProgress(100);
}
args.Result = successServiceValues;
};
serviceValuesWorker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
{
serviceValuesProgressBar.Value = args.ProgressPercentage;
};
serviceValuesWorker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
//serviceValuesWorker modifying the allResponses array
allResponses[i++] = (bool) args.Result;
};
serviceValuesWorker.RunWorkerAsync();
//Upload Signatures
signatureWorker = new BackgroundWorker();
signatureWorker.WorkerReportsProgress = true;
signatureWorker.WorkerSupportsCancellation = true;
signatureWorker.DoWork += delegate(object s, DoWorkEventArgs args)
{
signatureWorker.ReportProgress(10);
if (signatureWorker.CancellationPending)
{
args.Cancel = true;
return;
}
signatureWorker.ReportProgress(50);
//signatureWorker doing its work
bool[] responseArray = new bool[signatures.Count];
int j = 0;
foreach (var signature in signatures)
{
string signaturePath = signature.SignaturePath;
byte[] signatureByteArray = SignatureFileConversion.SignatureFileToByteArray(signaturePath);
string signatureToUpload = signatureByteArray.Serialize();
var signatureResponseFromServer = ServiceRequest.GetSignatureResponse("AddSignature", "ServiceInstances", serviceValuesString, serviceInstance.ServiceInstanceID.ToString(), signatureToUpload);
var signatureResponse = signatureResponseFromServer.Deserialize<dictionary<string, object="">>();
responseArray[j++] = (bool)signatureResponse["success"];
}
}
if(!responseArray.Contains(false))
{
signatureWorker.ReportProgress(100);
}
args.Result = responseArray;
};
signatureWorker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
{
signatureProgressBar.Value = args.ProgressPercentage;
};
signatureWorker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
bool[] signatureResponses = (bool[]) args.Result;
foreach (var response in signatureResponses)
{
//modifying the allResponses array
allResponses[i++] = response;
}
};
signatureWorker.RunWorkerAsync();
//Upload Photos
photoWorker = new BackgroundWorker();
photoWorker.WorkerReportsProgress = true;
photoWorker.WorkerSupportsCancellation = true;
photoWorker.DoWork += delegate(object s, DoWorkEventArgs args)
{
photoWorker.ReportProgress(10);
if (photoWorker.CancellationPending)
{
args.Cancel = true;
return;
}
photoWorker.ReportProgress(50);
//photoWorker doing its work
bool[] photoResponseArray = new bool[allPhotosToUpload.Count];
int k = 0;
foreach (var photo in allPhotosToUpload)
{
photoResponseArray[k++] = PostPhotoCollection.SendPhoto(photo);
}
if(!photoResponseArray.Contains(false))
{
photoWorker.ReportProgress(100);
}
args.Result = photoResponseArray;
};
photoWorker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
{
serviceValuesProgressBar.Value = args.ProgressPercentage;
};
photoWorker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
bool[] photoResponses = (bool[]) args.Result;
foreach (var response in photoResponses)
{
allResponses[i++] = response;
}
};
photoWorker.RunWorkerAsync();
//Update main ProgressBar
mainWorker = new BackgroundWorker();
mainWorker.WorkerReportsProgress = true;
mainWorker.WorkerSupportsCancellation = true;
mainWorker.DoWork += delegate(object s, DoWorkEventArgs args)
{
mainWorker.ReportProgress(10);
if (mainWorker.CancellationPending)
{
args.Cancel = true;
return;
}
mainWorker.ReportProgress(50);
//mainWorker doing its work
if (!allResponses.Contains(false))
{
bool IsDone = true;
string finalResponseFromServer = ServiceRequest.GetFinalResponse("SubmitChanges", "ServiceInstances", IsDone.ToString(), serviceInstance.ServiceInstanceID.ToString(), allPhotosToUpload.Count.ToString(), signatures.Count().ToString());
var finalResponse = finalResponseFromServer.Deserialize<dictionary<string, object="">>();
finalSuccessMessage = (bool)finalResponse["success"];
args.Result = finalSuccessMessage;
if (finalSuccessMessage)
{
mainWorker.ReportProgress(100);
}
}
};
mainWorker.ProgressChanged += delegate(object s, ProgressChangedEventArgs args)
{
mainProgressBar.Value = args.ProgressPercentage;
};
mainWorker.RunWorkerCompleted += delegate(object s, RunWorkerCompletedEventArgs args)
{
btnClose.IsEnabled = true;
};
mainWorker.RunWorkerAsync();
}
}
I am getting AccessViolation exception, and the array allResponses is not modified at all.
I know the result of DoWork event can be accessed in RunCompleted event, then why allResponses array is not modifying.
Thanks for reading I know the code block is too long.
|
|
|
|
|
I would declare 1 delegate for ShowProgress. Something like the below:
public delegate void ShowProgress(ProgressBar progressbar, int prg);
private void showProgress(ProgressBar progressbar, int prg)
{
if (this.WindowState == FormWindowState.Minimized)
return;
if (progressbar.InvokeRequired)
progressbar.BeginInvoke(new ShowProgress(showProgress), new object[] { progressbar, prg });
else
{
if (prg < progressbar.Maximum)
progressbar.Value = prg;
else
progressbar.Value = progressbar.Maximum;
}
}
Then call the progressbar in each worker.
showProgress(progressBar1, 100);
I think this should work.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Thanks ,
I will give it a try.
Thanks again.
|
|
|
|
|
Sorry I tried delegates to update progress bar, but got the same exception "AccessViolation".
Thanks,
|
|
|
|
|
What is the full message? If you post the full error message I might be able to help a bit more. I suppose that it is trying to access something outside the Thread that it was called on? Can you post the full error message?
Are you using VS2005 or VS2008? Does the code actually compile? When I try to compile the code I get numerous errors i.e. Expression errors etc.
Excellence is doing ordinary things extraordinarily well.
|
|
|
|
|
Thanks for all your help,
This is the runtime exception I am getting "AccessViolationException".
"Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
My code does compile. I just trimmed it down since it will be too long.
As far as I know about backgroundWorker, in DoWork event args.Result stores the result of long running process.
And this result is available in RunCompleted event as args.Result.
In my case the array allResponses is not modifying at all after the work is done. I have to modify that array in all three long running processes.
I am using VS2008. My upload is working perfectly fine without progressBars and threads.
I think there is some locking issue.
Thanks,
|
|
|
|
|
Hello there i need to build a receipt number the values that am receiveing is this
RecieptCode LastRecieptNumber RecieptDisplayDigits
Rcp2008- 248 8
now the main prob is in receipdisplayDigits
i know in python if i write z*8 it will be zzzzzzzz
i want the same thing in C# but if i did it i will not be able to add the last reciept number/
how could this be done?
i have another method but am sure there would be a better one my method is to add the lastreceiptnumber
with 10^(receipt display digt) then i remove the 1 and write the receipt code it will look like this
the example above
10^8 = 100000000
100000000 + 249 (since it should be new receipt) = 100000249
Convert it to string and remove the 1 = 00000249
Then i add the receipt code
Is there better way taking into concideration the performance
Best Regards
|
|
|
|
|
The reciept will be Rcp2008-00000249
please note that the receipt code is Rcp2008-
receiptLat number is 248
diplay digits is 8
|
|
|
|
|
If I understood correctly, you can do like this:
string receiptCode = "Rcp2008";
int lastReceiptNumber = 248;
int receiptDisplayDigits = 8;
string receiptString = lastReceiptNumber.ToString().PadLeft(receiptDisplayDigits, '0');
string fullReceiptCode = string.Format("{0}-{1}", receiptCode, receiptString);
EDIT: expanded taking into account your second post.
|
|
|
|
|
it worked fine but i did not understand the last line of code could you explain it please??
|
|
|
|
|
string receiptString = lastReceiptNumber.ToString().PadLeft(receiptDisplayDigits, '0');
This line converts lastReceiptNumber to string, then adds as many 0 at its left as it's needed to have a string receiptDisplayDigits characters long.
You cas also do as musefan suggested and use receiptString = lastReceiptNumber.ToString("D" + receiptDisplayDigits); instead.
After this line, receiptString will be 00000249 .
string fullReceiptCode = string.Format("{0}-{1}", receiptCode, receiptString);
This line will concatenate the string created in the first line with receiptCode , using a template to define the string format.
You can also use a direct string concatenation (string fullReceiptCode = receiptCode + "-" + receiptString; ).
After this line, fullReceiptCode will be Rcp2008-00000249 .
|
|
|
|
|
Ahh ok ok man thanks alot i knew this but i forgot it because its been a while since i used {0} {1}...
|
|
|
|
|
It did not work the thing you wrote about padding left since when i convert to int
the 0000000000 will turn into 0
but thanks you gave me an answer about the padding thing
|
|
|
|