|
Please don't repost questions so soon after you have asked it originally. You asked this question once today already - give people a chance to answer before you do it again. It's only polite.
Deja View - the feeling that you've seen this post before.
|
|
|
|
|
Hi,
I want to invoke DsmSetLoadBalancePolicy through WMI; whatever I try, it gives me in valid parameters.
Could someone please help me here.
Regards,
DJ.
|
|
|
|
|
Just to add to it, I am using C# (may be its obvious ).
|
|
|
|
|
Show us how you're trying it. Also, have you looked at the System.Management.dll included in the .NET framework?
|
|
|
|
|
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());
}
}
|
|
|
|
|
OKAY!.
Finally the problem solved and lesson learned.
What I was doing is sending a "ManagementBaseObject" object as in parameter but the InvokeMethod expects it to be a "object" type.
So I copied the "ManagementBaseObject policyObj" into a "object tempObj" by
tempObj = policyObj.Clone();
And now instead of doing,
tinParams["LoadBalancePolicy"] = (ManagementBaseObject)policyObj;
I did,
tinParams["LoadBalancePolicy"] = checkObj;
This works fine.
Regards,
DJ.
|
|
|
|
|
Greets all
Can anyone tell me how to apply the SeDenyInteractiveLogonRight right to an account in C#, preferably using the DirectoryEntry class?
Thanks
ccitt
|
|
|
|
|
Hi every one,
I have some questions in c# and i'd appreciate any help with this concern.
1)I can't find the splash screen option in the properties of the project and i could'nt add it from add new item dialog box, so how can i add a splash screen??
2)I need to have a database (ms access) in my application, how can i create the setup for my application that includes the database and other resources such as some .swf files??
3) can i convert an image (say .jpeg) to an icon (.ico) using the Icon class?? How??
Thanks in advance to all..
|
|
|
|
|
r_jaz wrote: 1)I can't find the splash screen option in the properties of the project and i could'nt add it from add new item dialog box, so how can i add a splash screen??
In C#, you have to create a splash screen out of a form, then call it as the startup form.
r_jaz wrote: 3) can i convert an image (say .jpeg) to an icon (.ico) using the Icon class?? How??
Just use a bitmap and save it in an icon format, like so:
Bitmap bmp;
bmp = new Bitmap(@"C:\Image.png");
bmp.Save(@"C:\Icon.ico", System.Drawing.Imaging.ImageFormat.Bmp);
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
2- Create a new Setup and Deployment -> Setup Project from the File->New->Proect and create your folders, choose what to add into your folders.
NOTE: Better if you use Sql Server Express Edition 2005 (free and better than MS Access)
|
|
|
|
|
hi i done a windowns application with msaccess as database
i want to create a set up file how can i create set up file in .net 2003
i want to install all files at perticular location in harddisk
srikanth_2ma2
|
|
|
|
|
File|Add|New
Expand "Other Project Types"
Select "Setup and Deployment"
Select "Setup Project"
Give it a name, click OK
|
|
|
|
|
I tried this:
<br />
System.IO.DriveInfo[] allDrives = DriveInfo.GetDrives();<br />
<br />
foreach (DriveInfo d in allDrives)<br />
{<br />
if (d.IsReady == true & d.DriveType == "Removable")<br />
{<br />
listBox1.Items.Add(d.Name);<br />
}<br />
}<br />
...and it did not work.
I'm getting a headache. How do I accomplish what I'm trying to do?
|
|
|
|
|
What type of error did you receive? Your if statement is incorrect. Your if statement should contain && not &. This may be a typo but add another & and see what happens.
Nathan
|
|
|
|
|
Try replacing d.DriveType == "Removable" with d.DriveType == System.IO.DriveType.Removable .
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Thanks a bunch, guys. The world's easiest way to list all USB drives on the system...This worked:
System.IO.DriveInfo[] allDrives = System.IO.DriveInfo.GetDrives();
foreach (System.IO.DriveInfo d in allDrives)
{
if (d.IsReady == true && d.DriveType == System.IO.DriveType.Removable)
{
listBox1.Items.Add(d.Name);
}
}
Ok. Now that we have that worked out. Let me say this: I have this code in "form1.designer.cs", which I know is incorrect. How do I get it where it belongs (in form1.cs) and have it work right? I put it in there previously, and it didn't work.
|
|
|
|
|
simplicitylabs wrote: I put it in there previously, and it didn't work.
It works fine for me. Was there an error message?
Trinity: Neo... nobody has ever done this before.
Neo: That's why it's going to work.
|
|
|
|
|
Oh, it compiles and runs nicely. However, because I have it in form1.designer.cs, which is automatically generated by the designer, and not form1.cs, I get a warning and cannot view the form in design mode:
-------The warning-------
The code within the method 'InitializeComponent' is generated by the designer and should not be manually modified. Please remove any changes and try opening the designer again.
-------------------------
I'm using Visual Studio 2005.
|
|
|
|
|
I got it. Thank you for your help, everyone. I'm sure I'll be back with more questions soon.
|
|
|
|
|
Have a look at:
http://icsharpcode.net/OpenSource/SharpUSBLib/default.aspx
|
|
|
|
|
hi
i don't know how to show relationalData in treeView, how to ?
plz give an example.
thanks
|
|
|
|
|
|
Here's an example I just whipped up. The constructor populates a DataSet with some hierarchical data, and the Form.Load populates a TreeView with it.
There are many other ways this same data could be displayed in the TreeView, which is why there's no "automatic" way. You need to decide how you want your tree to look (this is one of the reasons I use a TreeView much more frequently than a DataGridView).
namespace PlayGround
{
public partial class Form1 : System.Windows.Forms.Form
{
private enum Gender { Male , Female } ;
private System.Data.DataSet ds = new System.Data.DataSet() ;
public Form1 ( string[] args )
{
InitializeComponent() ;
System.Data.DataRow dr ;
ds.Tables.Add ( new System.Data.DataTable ( "PetType" ) ) ;
ds.Tables.Add ( new System.Data.DataTable ( "Person" ) ) ;
ds.Tables.Add ( new System.Data.DataTable ( "Pet" ) ) ;
ds.Tables [ "PetType" ].Columns.Add ( new System.Data.DataColumn ( "Id" , typeof(int) ) ) ;
ds.Tables [ "PetType" ].Columns.Add ( new System.Data.DataColumn ( "Type" , typeof(string) ) ) ;
ds.Tables [ "PetType" ].Columns.Add ( new System.Data.DataColumn ( "DisplayColor" , typeof(string) ) ) ;
ds.Tables [ "Person" ].Columns.Add ( new System.Data.DataColumn ( "Id" , typeof(int) ) ) ;
ds.Tables [ "Person" ].Columns.Add ( new System.Data.DataColumn ( "Name" , typeof(string) ) ) ;
ds.Tables [ "Person" ].Columns.Add ( new System.Data.DataColumn ( "Gender" , typeof(string) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Id" , typeof(int) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "PetType" , typeof(int) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Owner" , typeof(int) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Name" , typeof(string) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Gender" , typeof(string) ) ) ;
ds.Tables [ "Pet" ].Columns.Add ( new System.Data.DataColumn ( "Age" , typeof(int) ) ) ;
ds.Relations.Add ( new System.Data.DataRelation ( "TypeOfPet" , ds.Tables [ "PetType" ].Columns [ "Id" ] , ds.Tables [ "Pet" ].Columns [ "PetType" ] ) ) ;
ds.Relations.Add ( new System.Data.DataRelation ( "OwnerOfPet" , ds.Tables [ "Person" ].Columns [ "Id" ] , ds.Tables [ "Pet" ].Columns [ "Owner" ] ) ) ;
dr = ds.Tables [ "PetType" ].NewRow() ;
dr [ "Id" ] = 0 ;
dr [ "Type" ] = "Dog" ;
dr [ "DisplayColor" ] = "Green" ;
ds.Tables [ "PetType" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "PetType" ].NewRow() ;
dr [ "Id" ] = 1 ;
dr [ "Type" ] = "Cat" ;
dr [ "DisplayColor" ] = "Blue" ;
ds.Tables [ "PetType" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Person" ].NewRow() ;
dr [ "Id" ] = 0 ;
dr [ "Name" ] = "Joe" ;
dr [ "Gender" ] = Gender.Male ;
ds.Tables [ "Person" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Person" ].NewRow() ;
dr [ "Id" ] = 1 ;
dr [ "Name" ] = "Mary" ;
dr [ "Gender" ] = Gender.Female ;
ds.Tables [ "Person" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 0 ;
dr [ "PetType" ] = 0 ;
dr [ "Owner" ] = 0 ;
dr [ "Name" ] = "Spot" ;
dr [ "Gender" ] = Gender.Male ;
dr [ "Age" ] = 2 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 1 ;
dr [ "PetType" ] = 0 ;
dr [ "Owner" ] = 0 ;
dr [ "Name" ] = "Rover" ;
dr [ "Gender" ] = Gender.Male ;
dr [ "Age" ] = 5 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 2 ;
dr [ "PetType" ] = 1 ;
dr [ "Owner" ] = 0 ;
dr [ "Name" ] = "Fluffy" ;
dr [ "Gender" ] = Gender.Female ;
dr [ "Age" ] = 3 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 3 ;
dr [ "PetType" ] = 1 ;
dr [ "Owner" ] = 1 ;
dr [ "Name" ] = "Gilligan" ;
dr [ "Gender" ] = Gender.Male ;
dr [ "Age" ] = 4 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
dr = ds.Tables [ "Pet" ].NewRow() ;
dr [ "Id" ] = 4 ;
dr [ "PetType" ] = 1 ;
dr [ "Owner" ] = 1 ;
dr [ "Name" ] = "Ginger" ;
dr [ "Gender" ] = Gender.Female ;
dr [ "Age" ] = 4 ;
ds.Tables [ "Pet" ].Rows.Add ( dr ) ;
return ;
}
private void Form1_Load ( object sender , System.EventArgs e )
{
System.Windows.Forms.TreeNode person ;
System.Windows.Forms.TreeNode pettype ;
System.Windows.Forms.TreeNode pet ;
foreach ( System.Data.DataRow personrow in ds.Tables [ "Person" ].Rows )
{
person = new System.Windows.Forms.TreeNode ( string.Format ( "{0} {1} ({2})" , (int) personrow [ "Id" ] , (string) personrow [ "Name" ] , personrow [ "Gender" ] .ToString() ) ) ;
person.Tag = personrow ;
foreach ( System.Data.DataRow pettyperow in ds.Tables [ "PetType" ].Rows )
{
pettype = new System.Windows.Forms.TreeNode ( (string) pettyperow [ "Type" ] + "s" ) ;
pettype.Tag = pettyperow ;
pettype.ForeColor = System.Drawing.Color.FromName ( (string) pettyperow [ "DisplayColor" ] ) ;
ds.Tables [ "Pet" ].DefaultView.RowFilter = string.Format ( "Owner={0} and PetType={1}" , personrow [ "Id" ] , pettyperow [ "Id" ] ) ;
foreach ( System.Data.DataRowView petrow in ds.Tables [ "Pet" ].DefaultView )
{
pet = new System.Windows.Forms.TreeNode ( string.Format ( "{0} {1} {2} year old {3}" , (int) petrow [ "Id" ] , (string) petrow [ "Name" ] , (int) petrow [ "Age" ] , petrow [ "Gender" ] .ToString() ) ) ;
pet.Tag = petrow ;
pet.ForeColor = pettype.ForeColor ;
pettype.Nodes.Add ( pet ) ;
}
person.Nodes.Add ( pettype ) ;
}
treeView1.Nodes.Add ( person ) ;
}
}
}
}
|
|
|
|
|
Hi friends!
I have some problems with GUI in C#.Net ,Can anybody solve these?
First ,How can I save the image from the PictureBox to the Harddrive…. Is it wrong method or not for save the any image ? like as
//Save file
private void savebt_Click(object sender, System.EventArgs e)
{
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
filename =saveFileDialog1.FileName;
Stream filestream =File.OpenWrite(filename);
using(StreamWriter fwriter= new StreamWriter(filestream))
{ fwriter.Write(PictureBox.Image);}
}
}
Second , I use the following codes for drawing into the pictureBox2 by Pen
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
if (e.Button == MouseButtons.Left)
{ g.DrawEllipse(p, e.X, e.Y, 5, 7); }
}
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
if (e.Button == MouseButtons.Left)
{ g.DrawEllipse(p, e.X, e.Y, 5, 7); }
}
But there is a problem when I RUN the program and start the drawing if when I move the mouse fastly then such drawing break into small ellipse,I think you have understand
Third , I use follwing codes to draw the line into the pictureBox2 :
private void pictureBox2_MouseDown(object sender, MouseEventArgs e)
{ Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
g.DrawEllipse(p, e.X, e.Y, 2, 2);
mx = e.X;
my = e.Y;
}
private void pictureBox2_MouseUp(object sender, MouseEventArgs e)
{
Pen p = new Pen(Color.Red, 5);
g = pictureBox2.CreateGraphics();
g.DrawLine(p, mx, my, e.X, e.Y);
}
But I confuse for that
private void pictureBox2_MouseMove(object sender, MouseEventArgs e)
{
???????????????????????????????
}
I want when I move the mouse arrow onto the pictureBox2 ,then the line move with respect to the mouse and not draw untill UP the mouse button.
I am waiting for your kindly response
Thanks
|
|
|
|
|
Hi,
1.
to save an image, use Image.Save()
2.
dont draw in MouseDown or any other non-paint event handler;
all drawing should be done in the paint handler.
Hence, use data structures to describe your drawing, modify the data as you
like (e.g. in OnMouseDown), but draw it in OnPaint().
There are many benefits now:
- the drawing gets redrawn when necessary (e.g. on Resize, restore from
minimized, etc)
- the drawing can be saved by saving the data structures
- better code structure.
|
|
|
|
|