|
Thanks everyone for the feedback! The solution I went with is the following:
public static class Permutation {
private static Random rand = new Random();
public static T[] Permute<T>(IEnumerable<T> list) {
T[] permArray = list.ToArray();
long arraySize = permArray.LongLength;
long[] perm = Permutation.Random(arraySize);
long i = 0;
foreach (T item in list) {
permArray[perm[i++]] = item;
}
return permArray;
}
public static long[] Random(long size) {
long[] perm = new long[size];
lock(rand) {
for (long i = size - 2; i >= 0; --i) {
perm[i] = rand.NextInt64(size - i);
for (long j = i + 1; j < size; ++j) {
if (perm[i] <= perm[j])
++perm[j];
}
}
}
return perm;
}
} This will allow a client a way to get a permutation from a set or dictionary as well. Thanks again for the ideas!
Sounds like somebody's got a case of the Mondays
-Jeff
modified 13-Sep-12 13:32pm.
|
|
|
|
|
Nice work !
The question of what you'd need to do randomly re-order a Dictionary<T,V> remains of interest to me.
best, Bill
<color>"When it comes to atoms, language can be used only as in poetry. The poet, too, is not nearly so concerned with describing facts as with creating images." Niels Bohr
|
|
|
|
|
Dictionaries don't have order anyway.
|
|
|
|
|
Skippums wrote: make the method that returns the array public
That sounds like a better idea. And/or something like a RandomSequence(int n) that returns an array of 0..n in random order.
|
|
|
|
|
Actually, I did end up making my method that returns a T[] public, and deleted all the wrapper methods. I figured that if clients want the result in a stack, queue, list, etc., they can build it themselves with a simple constructor call. Plus, having an extension method on IEnumerable allows a client to get a permutation from a set, which seems like it could be a useful operation.
PIEBALDconsult wrote: something like a RandomSequence(int n) that returns an array of 0..n in random order
Actually, in the code I posted, a client can get this with a call to long[] Permutation.Random(long size) . I suppose I could add the same code for int, but don't really see the point. I also thought about allowing a client to get a specific permutation, but that only works for permutations up to length 20 (since 21! > 264), unless I include a large integer library.
Sounds like somebody's got a case of the Mondays
-Jeff
|
|
|
|
|
In a C# 2010 application, I have the following value obtained from an Xdocument,
Det.Element("TransCount").Value.
I would like to know how to change this xdocument type to an integer data type.
|
|
|
|
|
It's just a string variable. You should use int.TryParse to convert it into an integer.
|
|
|
|
|
I tried what you suggested and that did not work. do you have any other suggestions?
|
|
|
|
|
rachel_m wrote: I tried what you suggested and that did not work.
What does that mean? Did it not compile, or did you get an exception during execution? If yes, can you post the message here?
rachel_m wrote: do you have any other suggestions?
Convert.ToInt32, but the TryParse method should work too. I suggest you try again.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
the
Convert.ToInt32 worked. Thanks!
|
|
|
|
|
Use TryParse, not Convert.
|
|
|
|
|
What did your code look like at this point? If TryParse isn't working, then you don't have a valid integer in there. What exactly does this value contain?
|
|
|
|
|
There was an article written by Roman Kiss that a former co-worker used as a basis for our software.
Using the COM+ Event System service in the .Net Application.[^]
This was back when Windows XP was popular, now when I take this code and try to run it in Windows 7 I get a bunch of access denied errors on the registry keys in the article. I can get around this by editing the registry and taking ownership away from TrustedInstaller and giving it to Administrators and then giving permissions where needed.
The problem is it still does not work after this. I also tried upgrading everything to .net 4 but that did not change anything. I need to get this working so I can upgrade our software from Windows XP to 7 and then move everything into .net 4.
The problem I notice in debugging is that the Subscriber Write method never actually gets called.
When registering EventClass.dll the first error I get is access denied on {4E14FBA2-2E22-11D1-9964-00C04FBBB345}. If I take ownership of this I then get errors on the next one in line, once I cover all those I just get and OLE HRESULT error (can't remember exactly) at this point I had to do some major digging to get at the right registry keys to make EventClass.dll register.
I had to change all of the following registry keys:
• CLSID
o 4E14FBA2-2E22-11D1-9964-00C04FBBB345
o 7542E960-79C7-11D1-88F9-0080C7D771BF
o 00020420-0000-0000-C000-000000000046
o 00020421-0000-0000-C000-000000000046
o 00020422-0000-0000-C000-000000000046
o 00020423-0000-0000-C000-000000000046
o 00020424-0000-0000-C000-000000000046
o 00020425-0000-0000-C000-000000000046
• Interface
o 4E14FB9F-2E22-11D1-9964-00C04FBBB345
o 4A6B0E15-2E38-11D1-9965-00C04FBBB345
o 4A6B0E16-2E38-11D1-9965-00C04FBBB345
o 64B8F404-A4AE-11D1-B7B6-00C04FB926AF
o B5A1729E-B721-3121-A838-FDE43AF13468
• HKLM\Software\Classes\TypLib
o 4E14FB90-2E22-11D1-9964-00C04FBBB345
Don't necessarily concern yourself with these keys there may be a better way.
If anyone can make this work or has ideas on how to make it work I would really appreciate your help.
Thank you,
Brett
|
|
|
|
|
Two major points to consider:
- Security issues on Windows 7. The access to registry keys in ROOT and LOCAL MACHINE is severly restricted, non-administrative users must nit write there.
- 32bit/64bit issues: 32bit applications' registry access gets redirected to the Wow6432Node . 32bit applications must not load 64bit dlls and vice versa.
|
|
|
|
|
Good afternoon,
I have a simple form that using c# server side validation. When using a radio button or dropdownlist with autopostback, I have to call Page.Validate(); within the code behind method. When I do this, it does not run the Javascript on the page that overrides the default functions of the c# validation.
How can I get the javascript - ValidatorUpdateDisplay function to run when i call the Page.Validate() call in the autopostback method?
Thanks in advance!
Rob
Javascript:
<pre lang="cs">
ValidatorUpdateDisplay = function (val) {
var ctl = $('#' + val.controltovalidate);
var eCount = 0;
for (var i = 0; i < Page_Validators.length; i++) {
var v = Page_Validators[i];
if (v.controltovalidate == val.controltovalidate) {
if (!v.isvalid) {
eCount++;
ctl.addClass('validationError');
$('td.question:eq(' + i + ')').addClass('someClass');
}
};
}
if (eCount > 0) {
ctl.addClass('validationError');
} else {
ctl.removeClass('validationError');
}
if (typeof (val.display) == "string") {
if (val.display == "None") {
return;
}
if (val.display == "Dynamic") {
val.style.display = val.isvalid ? "none" : "inline";
return;
}
}
if ((navigator.userAgent.indexOf("Mac") > -1) &&
(navigator.userAgent.indexOf("MSIE") > -1)) {
val.style.display = "inline";
}
val.style.visibility = val.isvalid ? "hidden" : "visible";
}
|
|
|
|
|
ocmd.CommandText = "update sms_enquiry set status='conformed' where enq_no='" + cmb_enq_no.Text + "'";
ocmd.ExecuteNonQuery();
I am getting ora-01036 oracle exception that is,illegal variable name/number
Plz send me its urgent
|
|
|
|
|
yaswanth001 wrote: Plz send me its urgent
Is it now?
yaswanth001 wrote: I am getting ora-01036 oracle exception that is,illegal variable name/number
Have you even tried Googling[^] for it? It does show quite the positive results.
We are not here to do your work for you. We may help if you try to make it yourself and you fail though, but more than suggestions and the occasional code snippet / article link we don't usually provide.
OTOH, show that you did actually try to fix this yourself and you are almost guaranteed that someone will pitch in and help.
Question downvoted for the obvious reasons
Full-fledged Java/.NET lover, full-fledged PHP hater.
Full-fledged Google/Microsoft lover, full-fledged Apple hater.
Full-fledged Skype lover, full-fledged YM hater.
|
|
|
|
|
Try debugging the source code.
Once you do that, you would be able to try and figure out the error yourself.
|
|
|
|
|
Put a breakpoint on the line ocmd.ExecuteNonQuery(); (an easy way to do this is to put your cursor on that line and press F9). Run your application in debug mode, and wait until it hits that line. Now, take a look at what ocmd.CommandText really says - if I were you, I would inspect this in the Locals Window. Take a copy of that text and try to execute it directly in Oracle.
|
|
|
|
|
I was wondering what you do when you are logging errors and providing error messages during dev, qa, uat and then production. For example, for qa I provide a message to include a guid with their ticket. I provide them the guid. I then use this guid to look up the error message in the log and see what the issue was.
The error messages will change once it goes to production as it will not make sense to ask users to include the guid with their ticket. You simply tell them something went wrong or if they can fix it, tell them what they can do.
The question is:
What is the best practice to use to change error reporting based on qa, uat and production phases?
Here are some ideas I have:
1. I can read from config file for the phase and provide errors accordingly
2. I can have a preprocessor directive defined for each phase
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
I'm not keen on this idea because you aren't testing like for like code (and yes, testing exception handling is testing the code). In other words, each environment is required to behave differently, which means that you cannot be 100% confident that your code will behave correctly as you haven't tested it in the previous environment.
|
|
|
|
|
Point taken! I was looking for more ideas from everyone else and assumed my idea was not the best approach. Can you provide some ideas about how you handle such? I am using Log4Net if that matters.
I am pretty sure I am not the first to come across this.
CodingYoshi
Artificial Intelligence is no match for Human Stupidity.
|
|
|
|
|
It really depends on what you are hooking into. If you are logging your errors into a database, then you could have a configuration in that database to identify the level of detail to provide, or you could have the actual error message in there. Supposing that the Guid that you display in QA is the identity of the logged error, then your message could be "There was an error logged with id {0}".
Now, if you provide the Guid into this using string.Format and there's no {0} written there then the Guid wouldn't be written out in the error message - satisfying that criteria of not displaying unecessary info to the end user.
|
|
|
|
|
CodingYoshi wrote: 1. I can read from config file for the phase and provide errors accordingly
2. I can have a preprocessor directive defined for each phase
I'd recommend a unified way of phoning home; have every unexpected exception be automatically logged in the bugtracker, and have the bugtracker look up the actual phase of development.
You could add in a conditional compile; adding some complexity that does not add much value to the end-product.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
You could think about using log4net - this will handle a lot of the logging framework for you.
If you want you can turn off debugging logs in the production environment.
|
|
|
|