|
I've received a project to replace an old (ASP based) OS Deployment protal with a new one - based on ASP.NET using C#.
Code example:
Function GetResourceIDbyMac(server, mac)
Dim counter:counter = 0
Log ""
Log "WMI Machine Check "
On Error Resume Next
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(server, "\Root\SMS\site_EMEA, username, password)
objSWbemServices.Security_.ImpersonationLevel = 3
Set colSwbemObjectSet = objSWbemServices.ExecQuery("Select distinct ResourceID from SMS_G_System_NETWORK_ADAPTER where MACAddress = '" & mac & "'")
For Each objProcess in colSWbemObjectSet
log "Record found with Resource ID " & objProcess.ResourceID
counter = counter + 1
Next
If err.number <> 0 Then
Log "F:GetResourceID: " & ex.Message
Else
If counter = 0 Then
GetResourceIDbyMac = -1
Else
GetResourceIDbyMac = 0
End If
End if
End Function
I've searched the web and the SCCM SDK but currently I'm unable to understand where and how i should start with this.
Could someone tell me how i can (should) connect to SCCM and get or set data there. A native C# translation of the code lines listed above would be really helpful.
Thanks in advance,
Uwe
(Germany)
|
|
|
|
|
You aren't going to be able to translate that directly: there is (thankfully) no equivalent of "On Error Resume Next" in C#. If your code relies on that, then translation becomes a lot of work, as you have to work out what errors it is masking and code round them...
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
Ok, maybe i didn't describe my problem (and the wishes) correctly.
I want to write several methods in C# do get data from our SCCM landscape and to update / delete data there. Currently the is an ASP based portal in place and use which should be replaced by a new ASP.NET solution - written in C#.
I don't know what kind of libraries and methods i've to use to recreate a C# solution which contains methods - currently available in the ASP solution. Probably it's not a good idea to "translate" the original code. I'm looking (more or less) for a general answer how i can attach the SCCM landscape and how i can manipulate data there.
Example (old):
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
Set objSWbemServices = objSWbemLocator.ConnectServer(server, "\Root\SMS\site_EMEA, username, password)
objSWbemServices.Security_.ImpersonationLevel = 3
Set colSwbemObjectSet = objSWbemServices.ExecQuery("Select distinct ResourceID from SMS_G_System_NETWORK_ADAPTER where MACAddress = '" & mac & "'")
For Each objProcess in colSWbemObjectSet
counter = counter + 1
Next
Example (new):
SmsNamedValuesDictionary namedValues = new SmsNamedValuesDictionary();
WqlConnectionManager connection = new WqlConnectionManager(namedValues);
connection.Connect(server, username, password);
connection.ConnectionScope.Path.Path = "\\Root\\SMS\\site_EMEA";
connection.ConnectionScope.Options.Impersonation = ImpersonationLevel.Impersonate;
IResultObject iResult = connection.QueryProcessor.ExecuteQuery("Select distinct ResourceID from SMS_G_System_NETWORK_ADAPTER where MACAddress = '" + mac + "'");
foreach (IResultObject result in iResult) {
counter++;
}
Is that the right way to do what I want ? There are other options available to do this ? I did some trials but wasn't successful. Maybe one of you have a method which can be a good example. I don't expect a complete solution - only a hint.
Best regards and thanks in advance,
Uwe
(Germany)
|
|
|
|
|
Hello
I have a button in a datagridview cell, whenever the datagridview is displayed, the button repeats itself
does anyone know how to avoid that please?
Thank you.
|
|
|
|
|
What do you mean by repeating of button?
Naina
|
|
|
|
|
That is the normal behaviour of DataGridView.
What do you want...?
|
|
|
|
|
If you put DataGridViewButtonColumn in a Datagridview, then each row will have it's own button: this is teh normal behavior and is exactly what I would expect.
What did you expect, and what are you trying to do?
Real men don't use instructions. They are only the manufacturers opinion on how to put the thing together.
Manfred R. Bihy: "Looks as if OP is learning resistant."
|
|
|
|
|
I have researched into "Fluent Interface development", http://en.wikipedia.org/wiki/Fluent_interface[^] and would like to know what the code project community thinks about them...
Do people like using them?
What scenarios would you use them in?
Alternatives?
I use them for objects that require too many arguments or optional inputs.
ICustomerFactory c = new CustomerFluentFactory.Create()
.WithName("James")
.WithID();
|
|
|
|
|
I have seldom written class along those lines, although the very useful LINQ does!
One alternative I like is object initializer:
var o = new MyObject
{
Name = "foo",
ID = Guid.NewGuid(),
Foo = new Bar
{
Snafu = true,
},
};
A train station is where the train stops. A bus station is where the bus stops. On my desk, I have a work station....
_________________________________________________________
My programs never have bugs, they just develop random features.
|
|
|
|
|
Thank you for the reply!
|
|
|
|
|
I use them for classes where there are logically linked discrete behaviours, such as validation. When you validate a property it is common to check multiple things on it, and a fluent interface is a nice way to do this.
|
|
|
|
|
Pete O'Hanlon wrote: such as validation
Thanks for the reply, that's a good idea I may start applying that concept also
|
|
|
|
|
venomation wrote: What scenarios would you use them in?
Any place where I want to help someone who is "using" that part of the code. It makes life easier for those who need to work with it, just a good documentation or an example would.
venomation wrote: Alternatives?
I prefer to implement the Decorator pattern
I are Troll
|
|
|
|
|
Thanks for the comment
Eddy Vluggen wrote: I prefer to implement the Decorator pattern
I am familiar with that design pattern, but doesn't that seem more complicated than a simple fluent design?
Or is there a way of making a fluent design also a decorator...?
|
|
|
|
|
venomation wrote: I am familiar with that design pattern, but doesn't that seem more complicated than a simple fluent design?
I guess it is. A template of the pattern makes it quite easy to implement, it just takes a bit more time. Might depend on what structures you're most familiair with.
venomation wrote: Or is there a way of making a fluent design also a decorator...?
Not that I'm aware of.
I are Troll
|
|
|
|
|
|
You're welcome
|
|
|
|
|
venomation wrote: What scenarios would you use them in?
I doubt I would ever use them.
Especially since the only touted benefit is that it makes it more 'readable' which is a subjective term that one can use to rationalize almost anything.
venomation wrote: I use them for objects that require too many arguments or optional inputs.
I don't see that your example has "too many arguments" in the first place.
But generally something that does in fact have too many arguments might have a design problem. And certainly if one sees a lot of code like that (versus say 1 out of 1000) then it would seem very likely that there are design problems.
|
|
|
|
|
jschell wrote: might have a design problem
Thanks for the comment!
|
|
|
|
|
I think it has a needless apostrophe.
|
|
|
|
|
I am having a nightmare about table exceptions such as if item is not found in the table
a message should be given to the user by using try-throw-catch or if-else statements.
i don't have any idea
Any help would be gratefully received.
|
|
|
|
|
Please provide the code you have written, especially the API you are using to retrieve the record from a table.
Suggest you to read the documentation for the API. It might guide you to handle this specific scenario.
Praveen Raghuvanshi
Software Developer
|
|
|
|
|
Thanks for your attention.I saw that i used same name for two different variables . issue solved
|
|
|
|
|
your question is little bit confusing for me about table exception.
please mentioned which kind of table is it related with database or not.
as possible give some more information or some code so we can justify what is problem.
|
|
|
|
|
i need to use the local language font (sinhala) with textbox in my app in xp, so the user can type in the local language.
for this i'm using ttf font. i can set the font to textbox without any problem. but when i'm typing in the text box it
shows the english font,but i tried
char[] ch = {'\u0db8' };
textBox2.Text = new string(ch);
in the form load and it showed the correct letter, but when type in the text box still only the english letters. (at the same time i set true regional setting->language->install files for east asian languages,when i set this off , characters in the textbox shows as black squares)
so any one got any idea why this happens, but i tried the same app with the same font in win 7 and it works perfect, but i need this app to run in xp.
thanx in advance.
|
|
|
|