|
oh,let me explain,I want to use Webpage automation operation to deal with my page,so I select c# to do this job with the webbrowser control.
|
|
|
|
|
|
Hi,
I have executed Exchange 2007 commands inside of c sharp code before, but have not attempted to do so with 2013 until now. There are no management tools installed on the machines this app will run on, so I believe I have to open up a remote PSsession to an Exchange 2013 server which is something else I have not done.
I was wondering if any one had an example of doing this with an Exchange 2013 specific cmdlet?
Thank you
|
|
|
|
|
I found this
$session = new-pssession -configurationname microsoft.exchange -connectionuri http://exchangeserver.domain.com/powershell -auth kerberos -credential (get-credential)
import-psession $session
And I can at least see the commands in the powershell session now, so this is a start
|
|
|
|
|
This is telling me the "State of runspace is not valid for this operation" at line 1082, which is the var results2 = powerShell.Invoke(); line.
Any ideas?
using (PowerShell powerShell = PowerShell.Create())
{
powerShell.Runspace = runspace;
string un = @"domain\username";
System.Security.SecureString pw = new System.Security.SecureString();
string password = "password";
foreach (char ch in password)
{
pw.AppendChar(ch);
}
PSCredential cred = new PSCredential(un, pw);
string CONNECTION_URI = @"http://exchangeserver.com/powershell";
PSCommand psSession = new PSCommand();
psSession.AddCommand("$session = New-PSSession");
psSession.AddParameter("ConfigurationName", "Microsoft.Exchange");
psSession.AddParameter("ConnectionUri", new Uri(CONNECTION_URI));
psSession.AddParameter("Kerberos");
psSession.AddParameter("Credential", cred);
psSession.AddParameter("AllowRedirection");
psSession.AddCommand("Import-PSSession");
psSession.AddParameter("$session");
psSession.AddCommand("Get-MailboxDatabaseCopyStatus");
psSession.AddParameter("databasename");
powerShell.Commands = psSession;
var results2 = powerShell.Invoke();
foreach (var item in results2)
{
MessageBox.Show(item.Members.ToString());
}
}
|
|
|
|
|
In case someone comes across this in a search
string un = @"domain\username";
System.Security.SecureString pw = new System.Security.SecureString();
string password = "password";
string databaseName = "databasename";
string exchangeServerName = "http://exchangeserver.com/powershell";
string microsoftSchemaName = "http://schemas.microsoft.com/powershell/Microsoft.Exchange";
foreach (char ch in password)
{
pw.AppendChar(ch);
}
PSCredential cred = new PSCredential(un, pw);
WSManConnectionInfo connectionInfo = new WSManConnectionInfo(new Uri(exchangeServerName), microsoftSchemaName, cred);
connectionInfo.AuthenticationMechanism = AuthenticationMechanism.Kerberos;
using (Runspace runspace = RunspaceFactory.CreateRunspace(connectionInfo))
{
using (PowerShell powershell = PowerShell.Create())
{
powershell.AddCommand("Get-Mailboxdatabasecopystatus");
powershell.AddParameter("identity", databaseName);
powershell.AddCommand("select-object");
var props = new string[] { "name", "status" };
powershell.AddParameter("property", props);
runspace.Open();
powershell.Runspace = runspace;
Collection<PSObject> results = powershell.Invoke();
foreach (PSObject result in results)
{
MessageBox.Show(result.ToString());
}
}
}
|
|
|
|
|
Question: How can I have multiple datareaders writing data in a loop?
Example:
For (int i=0; i<column.count;i++)
{
Step 1:
Run the following query to get datareader values:
select [] Column[i], count(Column[i]) AS COUNT
from <Table Name>
group by [] Column[i]
Step 2:
From the first row of datareader create a string.
}
Expected output when DataReader1 returns 3 rows and DataReader returns 3 rows:
Sample:
--> Row#1 from first dataReader
--> Row#1 from second dataReader
--> Row#2 from first dataReader
--> Row#2 from second dataReader
--> Row#3 from first dataReader
--> Row#3 from second dataReader
modified 16-Jan-15 11:42am.
|
|
|
|
|
If you want multiple DataReaders you will need multiple Commands and Connections as well -- a Connection can have only one active Command executing against it at one time.
|
|
|
|
|
Thanks for your reply.
Can I have a list of SqlConnection, SqlDataReader & SqlCommand?
Eg: List<SqlConnection> SQLConnections = new <SqlConnection>();
|
|
|
|
|
Sure you can, but I recommend making a class that holds a Connection, a Command, and a DataReader -- then make a list of those.
|
|
|
|
|
Thanks a ton..
|
|
|
|
|
I think you're trying to solve a problem that doesn't exist. The DataReader portion of the code is very fast (assuming you aren't overusing .ToString() . The expense is executing the query itself and getting the data back over the wire.
If you want to process the data in different threads, thats a different story. Use ONE DataReader and dump the data into a List. Then use Parallel.ForEach on the List.
|
|
|
|
|
Thanks for the information. If I am not wrong, this command is available for .NET 4 and above.
If yes, then it might not work for me as I am working on 3.5.
Please Advise.
-- modified 16-Jan-15 13:00pm.
|
|
|
|
|
Well, you can use multi-threading on the List in 3.5 without the Parallel.ForEach.
Parallel.ForEach just makes it trivial and handles everything for you. As Pie mentioned, is it a lot of data? If its not a lot of data, just expensive processing, I'd dump it in a List and multi-thread process the List. If it is a lot of data, are you sure you need all that data at once?
If its a lot of data AND you need it all at once, can you limit your app to run on a 64-bit OS? If so, memory won't really be an issue (as long as your machine has enough RAM).
If its a lot of data AND you need it all at once AND you can't restrict to a 64-bit OS AND/OR it would be too much data to keep in memory, etc. and you really need to do the multi-threaded reader approach, is the data coming from a table or pre-computed? If so, you could have a paging approach.... have each reader grab x records on its own connection, etc, but that approach will kill performance as calling a SP and spinning up the connection and disposing it is relatively expensive.
|
|
|
|
|
If it's tons of data I wouldn't want to hold it all in memory without good reason.
(And it doesn't look like threading.)
|
|
|
|
|
From his original post, it looks like he is trying to implement multi-threaded processing of the table, just in the wrong way.
|
|
|
|
|
I considered that, but I don't think so. Of course, the situation is unclear.
|
|
|
|
|
Here is my xml file i want to get the value of contextExpression eg.
I have tried lots of example to get the value but failed
Can anybody help to how to do using XDocument in C#
modified 15-Jan-15 11:24am.
|
|
|
|
|
|
Try this:
XDocument document = XDocument.Parse(@"<?xml version=""1.0"" encoding=""utf-8""?>
<campaign xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns=""urn:nds:dyn:campaign:version02"" handle=""4329"" campaignId=""4329"" campaignType=""EPG"" startDateTime=""2015-01-15T10:07:51"" endDateTime=""2015-01-15T12:07:51"" lastModifiedDateTime=""2014-10-25T06:24:28"" amsEnabled=""false"">
<contextExpression><![CDATA[(zoneId==176)&&((startTime==100)&&(endTime==1200))]]></contextExpression>
<adContent>
<contentInstance xsi:type=""ImageInstanceType"" language=""English"" imageType=""PNG"" height=""228"" width=""178"" epgResolution=""HD"">
<contentInstanceRef>image.png</contentInstanceRef>
</contentInstance>
</adContent>
</campaign>");
XNamespace defaultNamespace = document.Root.Name.Namespace;
XName contextExpressionNodeName = defaultNamespace + "contextExpression";
XElement contextExpressionNode = document.Root.Element(contextExpressionNodeName);
string contextExpression = (string)contextExpressionNode;
Console.WriteLine(contextExpression);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
|
So, I have an enum and want to get the ASCII code of the numeric value of a certain enum value. For example if I have the enum value STANDARD (=1), I want to get the ASCII code for '1' (49) in a byte variable. I cant seem to figure out how to do. Anyone?
enum PackageType : byte { STANDARD=1, REQUEST=2, ANSWER=3 }
PackageType type = PackageType.STANDARD;
byte b = (byte)type;
|
|
|
|
|
|
"How about make STANDARD=49 ?"
Well, I guess it´s time to call it a night. Lol
I´ll make STANDARD=49.
|
|
|
|
|
((int)type).ToString();
Or, if you want just the first character:
((int)type).ToString()[0];
The difficult we do right away...
...the impossible takes slightly longer.
modified 14-Jan-15 15:13pm.
|
|
|
|