Click here to Skip to main content
15,914,016 members
Home / Discussions / C#
   

C#

 
AnswerRe: Backup MYSQL Database Pin
Judah Gabriel Himango8-May-07 12:59
sponsorJudah Gabriel Himango8-May-07 12:59 
QuestionReflections Pin
eunderwo008-May-07 10:06
eunderwo008-May-07 10:06 
AnswerRe: Reflections Pin
Daniel Turini8-May-07 10:14
Daniel Turini8-May-07 10:14 
AnswerRe: Reflections Pin
Pete O'Hanlon8-May-07 10:22
mvePete O'Hanlon8-May-07 10:22 
QuestionWMI Invoke Method Pin
dancelicious8-May-07 9:46
dancelicious8-May-07 9:46 
QuestionRe: WMI Invoke Method Pin
dancelicious8-May-07 9:51
dancelicious8-May-07 9:51 
AnswerRe: WMI Invoke Method Pin
Judah Gabriel Himango8-May-07 13:00
sponsorJudah Gabriel Himango8-May-07 13:00 
GeneralRe: WMI Invoke Method Pin
dancelicious8-May-07 15:55
dancelicious8-May-07 15:55 
I am already using System.Management
This is what I am doing.
- Read the current load balance policy of the lun we are interested in
- create new ManagementBaseObject from this object
- Use this close as parameter to the invoke method.

I think creating a clone may not be a good diea but I am not sure how to create a ManagementBaseObject of a specific class type.

Following is the code snippet for your reference.

int ChangeLoadBalancePolicy(string szLunName, uint uiLbPolicy, List<ulong> lu64PathIds)
{
try
{
string szScope = "\\\\localhost\\root\\WMI";
ManagementClass deviceInfo = new ManagementClass( szScope,
"MYDSM_QueryLBPolicy",
null);
ManagementObjectCollection deviceCollection = deviceInfo.GetInstances();

ManagementBaseObject policyObj;

// Get the LB Policies for each device
// and for each device create associated DSM Path objects
foreach (ManagementObject device in deviceCollection)
{
string szInstanceName = device["InstanceName"].ToString();

// if found the instance
if (szInstanceName.Equals(szLunName))
{
ManagementBaseObject lbPolicy = (ManagementBaseObject)device["LoadBalancePolicy"];
policyObj = (ManagementBaseObject)lbPolicy.Clone();

ManagementBaseObject[] dsmPathList = (ManagementBaseObject[])lbPolicy["DSM_Paths"];
ManagementBaseObject[] inDsmPath;
inDsmPath = new ManagementBaseObject[dsmPathList.Length];

int i = 0;
// For each Path, get the adapter info, which has the path info
foreach (ManagementBaseObject dsmPath in dsmPathList)
{
//ManagementBaseObject mPath;
inDsmPath[i] = (ManagementBaseObject)dsmPath.Clone();

inDsmPath[i]["DsmPathId"] = (ulong)dsmPath["DsmPathId"];
inDsmPath[i]["Reserved"] = 1;
inDsmPath[i]["PathWeight"] = 0;
bPathSelected = false;

// If DSM path id is slected as a part of the change policy request
// mark it as primary path.
foreach (ulong u64PathId in lu64PathIds)
if (u64PathId.Equals((ulong)dsmPath["DsmPathId"]))
{
dsmPath.SetPropertyValue("PrimaryPath", 1);
inDsmPath[i]["PrimaryPath"] = 1;
bPathSelected = true;
m_Log.WriteEntry(dsmPath["DsmPathId"].ToString() + " is selected");
}

if (!bPathSelected)
{
dsmPath.SetPropertyValue("PrimaryPath", 0);
m_Log.WriteEntry(dsmPath["DsmPathId"].ToString() + " not selected");
inDsmPath[i]["PrimaryPath"] = 0;
}
i++;
}

// Preparing the in parameter
policyObj["LoadBalancePolicy"] = uiLbPolicy;
policyObj["Version"] = 1;
policyObj["Reserved"] = 1;
policyObj["DSMPathCount"] = inDsmPath.Length;
policyObj["DSM_Paths"] = inDsmPath;

ManagementClass policyInfo = new ManagementClass(szScope, "MYDSM_SetLBPolicy", null);
ManagementObjectCollection lunCollection = policyInfo.GetInstances();

foreach (ManagementObject lun in lunCollection)
{
if (szLunName.Equals(lun["InstanceName"].ToString()))
{
// Method Options
InvokeMethodOptions methodOptions = new InvokeMethodOptions();
methodOptions.Timeout = TimeSpan.FromMinutes(1);

ManagementBaseObject tinParams = lun.GetMethodParameters("DsmSetLoadBalancePolicy");
tinParams["LoadBalancePolicy"] = (ManagementBaseObject)policyObj;

ManagementBaseObject outParams = lun.InvokeMethod("DsmSetLoadBalancePolicy", tinParams, methodOptions);

return (int)outParams["returnValue"];
}
}
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
GeneralRe: WMI Invoke Method Pin
dancelicious9-May-07 14:26
dancelicious9-May-07 14:26 
Questionapplying c# security Pin
ccitt8-May-07 9:32
ccitt8-May-07 9:32 
QuestionsplashScreen, .exe and con class Pin
r_jaz8-May-07 9:28
r_jaz8-May-07 9:28 
AnswerRe: splashScreen, .exe and con class Pin
MatrixCoder8-May-07 9:59
MatrixCoder8-May-07 9:59 
AnswerRe: splashScreen, .exe and con class Pin
AFSEKI8-May-07 23:05
AFSEKI8-May-07 23:05 
Questionhow to creat a setup file Pin
kanth_2ma28-May-07 9:18
kanth_2ma28-May-07 9:18 
AnswerRe: how to creat a setup file Pin
PIEBALDconsult8-May-07 9:43
mvePIEBALDconsult8-May-07 9:43 
QuestionUSB (removable) drives in listbox Pin
simplicitylabs8-May-07 9:12
simplicitylabs8-May-07 9:12 
AnswerRe: USB (removable) drives in listbox Pin
nateraaaa8-May-07 9:23
nateraaaa8-May-07 9:23 
AnswerRe: USB (removable) drives in listbox Pin
MatrixCoder8-May-07 9:45
MatrixCoder8-May-07 9:45 
GeneralRe: USB (removable) drives in listbox Pin
simplicitylabs8-May-07 10:19
simplicitylabs8-May-07 10:19 
GeneralRe: USB (removable) drives in listbox Pin
MatrixCoder8-May-07 10:40
MatrixCoder8-May-07 10:40 
GeneralRe: USB (removable) drives in listbox Pin
simplicitylabs8-May-07 12:06
simplicitylabs8-May-07 12:06 
GeneralRe: USB (removable) drives in listbox Pin
simplicitylabs8-May-07 12:16
simplicitylabs8-May-07 12:16 
AnswerRe: USB (removable) drives in listbox Pin
AFSEKI8-May-07 23:11
AFSEKI8-May-07 23:11 
Questionproblem to use TreeView in show Hierarchy data. Pin
hdv2128-May-07 8:52
hdv2128-May-07 8:52 
AnswerRe: problem to use TreeView in show Hierarchy data. Pin
PIEBALDconsult8-May-07 9:51
mvePIEBALDconsult8-May-07 9:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.