|
Microsoft supplies one example libaray WinSamples,
there is many examples that how to use the chart.
|
|
|
|
|
Hey everyone,
I have a problem with XmlSerialization.
I have a property like this one:
[XmlElement(typeof(MyClass1),
ElementName = "myClass1"),
XmlElement(typeof(MyClass2),
ElementName = "myClass2"),
XmlElement(typeof(MyClass3),
ElementName = "myClass3"),
XmlElement(typeof(MyClass4),
ElementName = "myClass4")]
public ArrayList Items
{
get { return _items; }
set { _items = value; }
}
All MyClasses are derived from the same base-class.
Now, I like to check which XmlElements are "allowed" for my property "Items". It would be very nice if I have a function which returns me a list of the Class-Names (MyClass1, MyClass2, MyClass3, MyClass4). Is this possible? I found no way to access the XmlElement-Attributes of a property.
Thanks in advance
|
|
|
|
|
I would recommend using List<yourbaseclass> rather than an ArrayList. The more strong typing you can do, the better. That would automatically limit the allowed types to some degree. Are there other subclasses that you do not want to be allowed in the list?
|
|
|
|
|
The arraylist is fix because this code snippet is already in use and I can't change all dependencys. I can only add a function.
|
|
|
|
|
How to have Ruler for form in RunTime with diffrent units (centimeters OR pixels OR inch OR ...)!
|
|
|
|
|
I assume you want to use Windows Forms. Assuming that, you might want to look at this[^] article. Now, it's for inches but it would be fairly easy for you to convert it to support different units.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi guys,
I posted last week about an issue that I'm having but it was lost in a flood of new posts.
Conceptually - I need to be able to have my process write a file to an external share that is locked down by a production controlled ProcessID | Password combination. We have a contrived development example that is configured as a folder locked down by a local User Account ("Foo" | "Bar") on one of our developer's machines.
I need to:
1)reference this machine via UNC (\\server\share)
2)programmatically provide the above credentials from our configuration file
3)deposit a file.
Impersonation is a very last resort, as it would require jumping through tons of hoops with Security(...among other things and just generally being a very bad idea)
Does anyone have any experience at all completing this suite of tasks?
"I need build Skynet. Plz send code"
|
|
|
|
|
I'm afraid impersonation is the only solution, or run process as user, which is simpler to implement.
I'm not sure I understand what you mean by ProcessId|Password combination? Is this ProcessId a user account? or rather a Unix-like setuid assigned to the executable?
|
|
|
|
|
...a User account in our corporate directory that exists not for an employee but for a process that needs access to resources in the corporate domain having a password that is only known by our production management group
"I need build Skynet. Plz send code"
|
|
|
|
|
meh...Impersonation it is then, I guess. This is a major shortcoming of the .NET platform. There is no excuse for this not to be encapsulated by the managed runtime. At any rate, if anyone needs to Impersonate a user, here is the code for a class that I threw together...DuplicateToken isn't even invoked, but I wrote it, so I'll include it.
using System;
using System.Data;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Principal;
using System.Security.Permissions;
using System.Web.Security;
using System.Web;
using System.Runtime.CompilerServices;
[assembly:AllowPartiallyTrustedCallers]
namespace NationallyKnownPoliticallyContentiousProjectThatIAmNotAtLibertyToDisclose.data
{
public class ImpersonationManager
{
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
public static extern bool LogonUser(String lpszUsername, String lpszDomain, String lpszPassword, int dwLogonType, int dwLogonProvider, ref IntPtr phToken);
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern bool CloseHandle(IntPtr handle);
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool DuplicateToken(IntPtr hToken, int SECURITY_IMPERSONATION_LEVEL, ref IntPtr hDuplicateToken);
[DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Auto)]
public static extern bool RevertToSelf();
public static string Domain { get; set; }
public static string UserName { get; set; }
public static string Password { get; set; }
private static WindowsImpersonationContext _context;
[PermissionSetAttribute(SecurityAction.Demand, Name = "FullTrust")]
public static void BeginImpersonation()
{
const int LOGON32_PROVIDER_DEFAULT = 0;
const int LOGON32_LOGON_INTERACTIVE = 2;
IntPtr tokenHandle = IntPtr.Zero;
try
{
bool successfulLogin = LogonUser(UserName, Domain, Password, LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref tokenHandle);
if (successfulLogin)
{
WindowsIdentity identity = new WindowsIdentity(tokenHandle);
_context = identity.Impersonate();
}
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (tokenHandle != IntPtr.Zero)
CloseHandle(tokenHandle);
}
}
public static void EndImpersonation()
{
_context.Undo();
}
}
}
invocation looks something like this:
public static void DeliverOutbound(string document, MessageType messageInfo)
{
WindowsImpersonationContext context = null;
try
{
string filePath = data.StaticDataClassTEMP.getFileSavePath();
string archivePath = data.StaticDataClassTEMP.getArchiveSavePath();
XmlDocument xDocument = new XmlDocument();
xDocument.Load(HttpContext.Current.Server.MapPath("~/data/ApplicationSettings.xml"));
ImpersonationManager.UserName = xDocument.DocumentElement.SelectSingleNode("username").InnerText;
ImpersonationManager.Password = xDocument.DocumentElement.SelectSingleNode("password").InnerText;
ImpersonationManager.Domain = xDocument.DocumentElement.SelectSingleNode("domain").InnerText;
ImpersonationManager.BeginImpersonation();
WriteArchive(document, messageInfo, archivePath);
DeliverZip(document, messageInfo, filePath);
ImpersonationManager.EndImpersonation();
}
catch (Exception ex)
{
throw ex;
}
finally
{
}
}
...and in ApplicationSettings (listing just to be completely thorough for those wanting an example)
<username>processID</username>
<password>processPW</password>
<domain>Corp</domain>
"I need build Skynet. Plz send code"
|
|
|
|
|
it is floyd marshall algorithm but it is run slowly
how can i increase speed?
i have quad pc and it use %25 cpu but i wait so much .
for (int k = 0; k < 2000; k++)
for (int i = 0; i < 2000; i++)
for (int j = 0; j < 2000; j++)
G[i, j] = Math.Min(G[i, j], G[i, k] + G[k, j]);
|
|
|
|
|
Your inner loop is executing 8 billion times; no wonder it takes a while.
The Floyd-Warshall algorithm is O(n^3), so if you double the number of nodes in the graph, it will slow down another factor of 8. A brute force approach like this is reasonable only for small graphs.
One way to somewhat improve speed is by using pointers; multi-dimensional array lookup isn't very efficient.
Another possible improvement is getting better cache efficiency by reordering the operations (a bit tricky). And then you could go for more elaborate algorithms, requiring a lot more code.
|
|
|
|
|
If you use 25% cpu, on a quad CPU, with a single thread, there is room for improvement, unfortunately, it's bit more complicated than what you're using. HAve a look at this[^].
|
|
|
|
|
Exactly what he needs. Plz send codez ASAP.
|
|
|
|
|
There's a reason you're only at 25% on your CPU. You're running the process on a single thread which means only one core is being used. So, you're actually maxing out that single core and using nothing on the other cores.
I don't really see any way to speed up that algorithm.
I take it back...Pete may have found a great solution with 4.0
modified on Monday, May 3, 2010 2:37 PM
|
|
|
|
|
If you are using .NET 4, you might want to take a look at Parallel.For . Take a look at the Task Parallel Library[^].
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Would that really work, with all the odd data dependencies? (I don't know, which is why I'm asking..)
|
|
|
|
|
With careful marshalling, yes. It would move the calculation off one core, and it would be interesting to see how it performs.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
My blog | My articles | MoXAML PowerToys | Onyx
|
|
|
|
|
Hi Harold,
in
for (int k = 0; k < 2000; k++) {
for (int i = 0; i < 2000; i++) {
for (int j = 0; j < 2000; j++) {
G[i, j] = Math.Min(G[i, j], G[i, k] + G[k, j]);
}
}
}
each element G[i,j] depends on the elements from the row and column it sits in, so you can execute the iterations of the inner loop in parallel as they all modify a different matrix element, and all read elements that are not going to be written, unless k==i or k==j. You can deal with the former right away (outside the inner loop), and the latter can be handled separately. So it becomes:
for (int k = 0; k < 2000; k++) {
for (int i = 0; i < 2000; i++) {
if (i==k) {
for (int j = 0; j < 2000; j++) {
G[i, j] = Math.Min(G[i, j], G[i, k] + G[k, j]);
}
} else {
//G[i, j] = Math.Min(G[i, j], G[i, j] + G[j, j]); // special case k==j
G[i, k] = Math.Min(G[i, k], G[i, k] + G[k, k]); // special case k==j
for (int j = 0; j < 2000; j++) {
if (j!=k) G[i, j] = Math.Min(G[i, j], G[i, k] + G[k, j]);
}
}
}
}
And now the highlighted loop has no data dependencies any more.
Furthermore, the diagonal elements start at value zero; assuming no negative cycles in the graph, their MIN operation won't affect them, and the special cases do not need to be set aside, so we are back at the original code.
If negative cycles are allowed, proper handling still allows parallellization with negative cycle detection (which turns diagonal elements into negative values), and even then the special cases are not really necessary as the presence of negative cycles makes the results not optimal as the optimum would be minus infinity anyway.
[EDIT]
fixed a mistake, signaled by Pete
[\EDIT]
|
|
|
|
|
Nice thanks
|
|
|
|
|
you're welcome.
Now go install .NET 4.0 and write that article!
|
|
|
|
|
I'm not sure.. that's actually quite advanced.. and I'm still only halfway understanding linear time suffix array construction (bit slow I know..)
|
|
|
|
|
If things are getting slow, you should start doing some of them in parallel...
|
|
|
|
|
Win
Anyway, how's your prime number thing going?
|
|
|
|
|
very good, thanks, it currently uses 1.1 threads. There isn't enough work to keep a dual-core busy
I'll publish it later this year.
|
|
|
|
|