|
Hello, CP! I have a question and I have yet to find the answer I need. I have created a custom ToolStrip renderer as well as a class derived from ToolStrip. I have also created a class derived from a standard Button control. Along with these, I have a "ThemeBase" class which all theme sets are derived from, I have two theme sets and I have a "ThemeManager" class. ThemeManager is a singleton class and it works perfectly fine for theming the application all at once. At runtime, that is.
However, I would like to add design-time support for dynamically changing the theme in the Forms Designer. Would this be possible without too much headache? The way it is currently set up is that the controls display in the Forms Designer with the default theme that I set. This is no issue as the themes are virtually identical aside from their color schemes. So if changing the theme at design-time is too much of a hassle then I am not worried about it.
I have looked at custom designers, deriving from ControlDesigner. However, I could not picture that as the solution I am looking for. I have seen controls which you can change the theme for individually at design-time and it takes effect. I am positive I know how that is done. I am interested in theming all controls in the designer (where applicable) at once. Maybe it is not even really possible but I wanted to ask since I could not find the answer elsewhere on my own.
Thank you!
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Controls render themselves normally (using Paint) at design time, so if that depends on the theme, you should be able to set the theme at design time and have controls change. So I think if you want it to be unified across a whole form or application you need to make your ThemeManager a component so you can get an icon for it at design time and get its properties (such as which theme is being used). You'd then have to make the controls look for the right theme manager and the theme manager would need to invalidate all applicable controls (in the tree of its parent?) when the theme changed.
|
|
|
|
|
Dear Fellows,
I want to create a DSN for oracle through code. I have searched a lot but couldn't get satisfatory solution. Could anyone help me out to get rid of the problem? It would be great if anyone can post a code for that.
Regards,
KS
|
|
|
|
|
I don't see the point. If you have the information to create a DSN you can just make a connection directly.
However, on a previous job I had to copy some ODBC configurations to various servers so I used a RegEdit script file to do it, maybe it'll help.
(This is for Cache , not Oracle.)
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\InterSystems Cache ODBC]
"Driver"="C:\\CacheSys\\bin\\CacheODBC.dll"
"Setup"="C:\\CacheSys\\bin\\CacheODBC.dll"
"SQLLevel"="1"
"FileUsage"="0"
"DriverODBCVer"="02.10"
"ConnectFunctions"="YYN"
"APILevel"="1"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBCINST.INI\ODBC Drivers]
"InterSystems Cache ODBC"="Installed"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\CABMATE1]
"Driver"="C:\\CacheSys\\bin\\CacheODBC.dll"
"Protocol"="TCP"
"Host"="xx.xx.xx.xx"
"Port"="xxxx"
"Namespace"="CABMATE"
"UID"="xxxxxxx"
"Password"="xxx"
"Description"="CabMate on TTCAB1"
"Query Timeout"="0"
[HKEY_LOCAL_MACHINE\SOFTWARE\ODBC\ODBC.INI\CABMATE2]
"Driver"="C:\\CacheSys\\bin\\CacheODBC.dll"
"Protocol"="TCP"
"Host"="xx.xx.xx.xx"
"Port"="xxxx"
"Namespace"="CABMATE"
"UID"="xxxxxxx"
"Password"="xxx"
"Description"="CabMate on TTCAB2"
"Query Timeout"="0"
|
|
|
|
|
Greetings Gurus,
I have been searching the forums and tuts for an answer to a question regarding getting running processes off a XP SP3 box without luck so I am posting here hoping one of the Gurus could help me solve this problem.
Running a Windows service under the Local System account (yes I am aware of the dangers this poses but I have taken care of that).
If I run
try
{
SqlConnection myconn = new SqlConnection("User id = a; password = b; server=c;" database=e; connection timeout=30");
SqlCommand insp = new SqlCommand("INSERT INTO dbo.tbconn(Tstamp, SysID, PID, PName)VALUES (@Tstamp, @SysID, @PID, @PName)", myconn);
insp.Parameters.Add("@Tstamp", SqlDbType.DateTime);
insp.Parameters.Add("@SysID", SqlDbType.Int);
insp.Parameters.Add("@PID", SqlDbType.Int);
insp.Parameters.Add("@PName", SqlDbType.NVarChar, 50);
DateTime Tstamp = DateTime.Now;
Process[] processlist = Process.GetProcesses();
foreach (Process p in processlist)
{
insp.Parameters["@Tstamp"].Value = Tstamp;
insp.Parameters["@SysID"].Value = 100;
insp.Parameters["@PID"].Value = p.Id;
insp.Parameters["@PName"].Value = p.ProcessName;
ProcMon.Open();
insp.ExecuteNonQuery();
ProcMon.Close();
}
}
catch (Exception procinfo)
{
everything writes to the table as expected, however I get 3 errors if I run
try
{
SqlConnection myconn = new SqlConnection("User id = a; password = b; server=c;" database=e; connection timeout=30");
SqlCommand insp = new SqlCommand("INSERT INTO dbo.tbconn(Tstamp, SysID, PID, PName, PExe, PCPU, PMem)VALUES (@Tstamp, @SysID, @PID, @PName, @PExe, @PCPU, @PMem)", myconn);
insp.Parameters.Add("@Tstamp", SqlDbType.DateTime);
insp.Parameters.Add("@SysID", SqlDbType.Int);
insp.Parameters.Add("@PID", SqlDbType.Int);
insp.Parameters.Add("@PName", SqlDbType.NVarChar, 50);
insp.Parameters.Add("@PExe", SqlDbType.NVarChar, -1);
insp.Parameters.Add("@PCPU", SqlDbType.Int);
insp.Parameters.Add("@PMem", SqlDbType.Int)
DateTime Tstamp = DateTime.Now;
Process[] processlist = Process.GetProcesses();
foreach (Process p in processlist)
{
insp.Parameters["@Tstamp"].Value = Tstamp;
insp.Parameters["@SysID"].Value = 100;
insp.Parameters["@PID"].Value = p.Id;
insp.Parameters["@PName"].Value = p.ProcessName;
insp.Parameters["@PExe"].Value = p.MainModule.FileName; //Error 1
insp.Parameters["@PCPU"].Value = p.TotalProcessorTime; //Error 2
insp.Parameters["@PMem"].Value = p.VirtualMemorySize64; //Error 3
ProcMon.Open();
insp.ExecuteNonQuery();
ProcMon.Close();
}
}
catch (Exception procinfo)
{
Error 1: System.ComponentModel.Win32Exception: Unable to enumerate the process modules - Still writes all fields but excludes "IDLE"
Error 2: System.InvalidCastException: Failed to convert parameter value from a TimeSpan to a Int32. System.InvalidCastException: Object must implement IConvertible - Writes all values except the TotalProcessorTime,"SYSTEM" and "IDLE" values.
Error 3: System.ComponentModel.Win32Exception: Unable to enumerate the process modules - Writes all values except TotalProcessorTime, "SYSTEM" and "IDLE".
I have tried running it piecemeal and as a Console App but I can't seem to shake these errors (even trying some Convert.ToX stuff).
Can someone help me move this forward please?
Many thanks.
|
|
|
|
|
1 and 3. You were told here[^] what you needed to do when you asked this before.
2. A TimeSpan is a complex structure - not an integer. Write the Tick count out from the TimeSpan instead (you can use this to recreate the TimeSpan later if you need to).
|
|
|
|
|
Hi Pete,
1 & 3
The previously posted example was a Console App running as a local admin, this question is based on the script being run as a Local System Windows service. Does that not make a difference?
I am fairly sure that Local System has access to enumerate those 2 processes (it can definately get the PID & Name, as can the Local Admin user) and, as my reply in the previous posting suggests, NTAuthority\System is the owner so should be able to manipulate the processes in question. Assuming that Local System can't get those values then what role/privilege is required to be able to get the starttime & mainmodule filename?
As I mentioned in the original question, the process [] getprocesses does return the values when the starttime & mainmodule are excluded from the request. Is there a way to get it to write the System and Idle values that are available and exclude the values it can't access?
2
The TotalProcessorTime works when run as a Console App under a local admin account so why does it error as a Windows service? Do I need to pre-format the request/return value? I am afraid I don't know (yet) how to remove the tick count from a built-in property as all I am really doing is taking this http://msdn.microsoft.com/en-us/library/system.diagnostics.process.totalprocessortime.aspx and writing it into a service.
I would like to add that while my original question and this are related, I was hoping that changing the environment of the script would solve the permissions problem. I would also like to add that the WMI example can pull (most) of that data as can the Task manager pull the CPU time.
This tells me that there is a way to do it. I just don't know, and/or can't find, it. Thus my posting.
Thank you for your response.
|
|
|
|
|
CCodeNewbie wrote: 2 The TotalProcessorTime works when run as a Console App under a local admin
account so why does it error as a Windows service? Do I need to pre-format the
request/return value? I am afraid I don't know (yet) how to remove the tick
count from a built-in property as all I am really doing is taking this
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.totalprocessortime.aspx
and writing it into a service.
The issue you are hitting here is that you are trying to save the TimeSpan into an integer value (in the database part). This has to be the number only, so just use the Ticks value.
|
|
|
|
|
I have taken this as far as I can, thanks to Pete O'Hanlon and a number of forums.
The final code I can offer (which I am sure can be much improved upon and expanded) is this - please forgive the formatting
{
DateTime Tstamp = DateTime.Now;
Process[] processlist = Process.GetProcesses();
foreach (Process p in processlist)
{
if (p.ProcessName == "Idle")
{
SqlConnection myconn = new SqlConnection("User id = a; password = b; server = c database = e connection timeout=30");
SqlCommand insp = new SqlCommand("INSERT INTO dbo.tbconn(Tstamp, SysID, PID, PName, PMem) VALUES (@Tstamp, @SysID, @PID, @PName, @PMem)", myconn);
insp.Parameters.Add("@Tstamp", SqlDbType.DateTime);
insp.Parameters.Add("@SysID", SqlDbType.Int);
insp.Parameters.Add("@PID", SqlDbType.Int);
insp.Parameters.Add("@PName", SqlDbType.NVarChar, 50);
insp.Parameters.Add("@PMem", SqlDbType.Int);
insp.Parameters["@Tstamp"].Value = Tstamp;
insp.Parameters["@SysID"].Value = 100;
insp.Parameters["@PID"].Value = p.Id;
insp.Parameters["@PName"].Value = p.ProcessName;
insp.Parameters["@PMem"].Value = p.WorkingSet64 / 1024;
myconn.Open();
insp.ExecuteNonQuery();
myconn.Close();
}
if (p.ProcessName == "System")
{
SqlConnection myconn = new SqlConnection("User id = a; password = b; server = c database = e connection timeout=30");
SqlCommand insp = new SqlCommand("INSERT INTO dbo.tbconn(Tstamp, SysID, PID, PName, PCPU, PMem) VALUES (@Tstamp, @SysID, @PID,@PName, @PCPU, @PMem)", myconn);
insp.Parameters.Add("@Tstamp", SqlDbType.DateTime);
insp.Parameters.Add("@SysID", SqlDbType.Int);
insp.Parameters.Add("@PID", SqlDbType.Int);
insp.Parameters.Add("@PName", SqlDbType.NVarChar, 50);
insp.Parameters.Add("@PCPU", SqlDbType.Int);
insp.Parameters.Add("@PMem", SqlDbType.Int);
insp.Parameters["@Tstamp"].Value = Tstamp;
insp.Parameters["@SysID"].Value = 100;
insp.Parameters["@PID"].Value = p.Id;
insp.Parameters["@PName"].Value = p.ProcessName;
insp.Parameters["@PCPU"].Value = p.TotalProcessorTime.TotalMilliseconds/ 1000;
insp.Parameters["@PMem"].Value = p.WorkingSet64/1024;
myconn.Open();
insp.ExecuteNonQuery();
myconn.Close();
}
else
{
SqlConnection myconn = new SqlConnection("User id = a; password = b; server = c database = e connection timeout=30");
SqlCommand insp = new SqlCommand("INSERT INTO dbo.tbconn(Tstamp, SysID, PID, PName, PStart, PExe, PCPU, PMem) VALUES (@Tstamp, @SysID, @PID, @PName, @PStart, @PExe, @PCPU, @PMem)", myconn);
insp.Parameters.Add("@Tstamp", SqlDbType.DateTime);
insp.Parameters.Add("@SysID", SqlDbType.Int);
insp.Parameters.Add("@PID", SqlDbType.Int);
insp.Parameters.Add("@PName", SqlDbType.NVarChar, 50);
insp.Parameters.Add("@PStart", SqlDbType.DateTime);
insp.Parameters.Add("@PExe", SqlDbType.NVarChar, -1);
insp.Parameters.Add("@PCPU", SqlDbType.Int);
insp.Parameters.Add("@PMem", SqlDbType.Int);
insp.Parameters["@Tstamp"].Value = Tstamp;
insp.Parameters["@SysID"].Value = 100;
insp.Parameters["@PID"].Value = p.Id;
insp.Parameters["@PName"].Value = p.ProcessName;
insp.Parameters["@PStart"].Value = p.StartTime;
insp.Parameters["@PExe"].Value = p.MainModule.FileName;
insp.Parameters["@PCPU"].Value = p.TotalProcessorTime.TotalMilliseconds / 1000;
insp.Parameters["@PMem"].Value = p.WorkingSet64/1024;
myconn.Open();
insp.ExecuteNonQuery();
myconn.Close();
}
}
}
I look forward to any replies.
Thanks to all who helped.
|
|
|
|
|
I would like to create a program in C# to process audio and perform low pass and high pass filtering on it.
Can anyone tell me where I should start to implement these filters? Is there any source code you are aware of, or maybe ready made DLLs which I can use?
|
|
|
|
|
Maybe this will give you some clues about it.
No memory stick has been harmed during establishment of this signature.
|
|
|
|
|
I am using MVC3 with razor and binding dropdownlist with a list
Now issue is
@Html.DropDownListFor(model => model.Result, new SelectList(Model.Result.OrderBy(item => item.Enhet), "EnhetID", "Enhet"), "ALL")
in Enhet i am getting 3 values
Nitin
NA
NA
I want to make sure that values are always unique, how can i remove duplicate values.
|
|
|
|
|
You should be able to use Distinct to satisfy this.
|
|
|
|
|
I tried but it's not working. I also tried GroupBy but it also didnt worked
|
|
|
|
|
The Distinct method has an overload that takes an IEqualityComparer. Have you tried that?
No comment
|
|
|
|
|
That tells you that you're attempting to perform a distinct operation on something that isn't, inherently, distinct (Distinct uses Hash codes to determine whether something is, or is not a distinct item). This would normally be the case if you were trying to perform a distinct on the whole object.
Rather than doing that, you should just look to do something like this
@Html.DropDownListFor(model => model.Result, new SelectList(Model.Result.OrderBy(item => item.Enhet), "EnhetID", "Enhet"), "ALL")
.GroupBy(x => x.Enhet)
.Select(x => x.First()); This is untested, I just whipped it together in the browser.
|
|
|
|
|
Do you need to use a List in your model, can you use a HashSet[^] instead, as this works like a dictionary in that it doesn't allow duplicates, but doesn't throw an exception if you try and add an item already in the set.
|
|
|
|
|
Hi, I have a working wcf server-client application.Client makes a call every 3 seconds.If client doesn't call any method for ten seconds, server drops the connection based on the closetimeout setting(10 secs).(not prefer but with this setting, if something happens to client like ethernet/power plug off, I detect lost connection)
But as a side effect of this, if server's response time exceeds 10 secs(like a messagebox asking for a user confirm.), the client is waiting and the connection is gone of course, because client can't make another call until the previous one answered.(InstanceContextMode=PerSession)
Oddly,it is said that setting a void method as "IsOneway=true" the client doesn't wait for server to finish process and so it can make another call. But it's not so in action, it still waits server to finish. ???
The question is:
I want to get rid of closetimeout setting by setting it to int.maxvalue and detect lost connections by service or instance faults.Any way of doing this?
(I tried the closed and faulted events of operationContext...etc with no success)
(I didn't try faultContract because I don't want to send fault details to clients(am I wrong about this?). I only want whether the client is connected or not)
modified 31-Oct-11 7:20am.
|
|
|
|
|
I think you're making things hard on yourself. I don't see why the server would care about how frequently a client calls methods.
|
|
|
|
|
PIEBALDconsult wrote: why the server would care about how frequently a client calls methods.
Client needs to get the updated data every three seconds and server already is fine with that but that isn't the problem.
If I don't use closetimeout property, client seems connected even if down.Because wcf service do not tell me whether client is still connected. And with this property set, server drops the connection and I am able to know when connection goes.
All I want is to know when connection is lost
|
|
|
|
|
PIEBALDconsult wrote: I don't see why the server would care about how frequently a client calls
methods.
If the client disappears without closing the connection then the connection will remain forever.
Which won't work in a standard 24x7 type server.
|
|
|
|
|
|
PIEBALDconsult wrote:
There is no connection.
The protocol in use is nettcp, so yes there is a connection.
|
|
|
|
|
Like all HTTP based web services, WCF doesn't really have the concept of a connection, so if you care, you need to do something like what you describe. Alternatively, you can just let the HTTP session expire if a user disappears. The considerations you need to make are similar to when creating a normal web application. Requiring a login to make an authenticated session in the first place means that it generally doesn't matter if you have inactive sessions not being actively closed, as they are pretty difficult to hijack (I think IIS sessions are bound to IP and session ID).
A web service call should never block waiting for server side user input. Web services should be able to run in a lights-out environment, with the only communication needed to talk to them being the service interface itself. (Any client side user input can be taken before or after particular service calls, which may require splitting a large call up into smaller ones if intermediate input is required, but each call should be self contained and executable.) If you want to provide information at runtime so you don't have to recompile the service, you should use some sort of configuration file or data store which the service can look at to make its decision.
If your service is doing something for which manual inspection of requests is necessary (this is very rarely actually necessary, but perhaps for military or dangerous research environments there are times when it could be), the service function should place a request onto a queue, and immediately return with a value that indicates that the request is pending approval. Any further attempts to do anything on that request that can't proceed until the server-side operator approves it should cause service methods to throw exceptions until it is manually approved, and the client should poll to find out whether the status of any of its pending requests has changed. That queue should also be read by another application which is what the manual approver will use to inspect pending requests.
I strongly suspect you don't actually need that but if you think you do, please state your requirement for that in more detail so some better help can be created for you (if that one paragraph version was not enough).
|
|
|
|
|
BobJanova wrote: Like all HTTP based web services, WCF doesn't really have the concept of a connection, so if you care, you need to do something like what you describe. Alternatively, you can just let the HTTP session expire if a user disappears.
sorry for not mentioning. This is a cybercafe software(netTcpBinding based persession scenario and server/client on the same lan).
BobJanova wrote: If your service is doing something for which manual inspection of requests is necessary
by approval, I mean, client is sending me drink orders which opens up a form on server side and admin approves or cancels. This is where the story begins.If I don't approve in ten seconds(closetimeout=10) connection is broken. in order to avoid this, I create a backgroundworker for every session that listens incoming orders and handles the approval form, this way connection isn't dropped. But this time there are too many unnecessary backgroundworkers with extra load(think of 25+ clients/sessions) Also, same approval mechanism needed for clients for requests from server to clients and same load
So, Do you have any better idea?
|
|
|
|
|