|
shutdown /s /m \\computername That's the commandline for doing so; if you need to do it from C#, call it via System.Diagnostics.Process.Start() .
|
|
|
|
|
But in window form, button Shutdown, Reboot in server are not shutdown,reboot client.
|
|
|
|
|
What are you talking about?? The shutdown command line works the same whether the target it a server or a workstation.
|
|
|
|
|
Hi Friends,
I am in situation to develop a custom plugin that communicate to the windows application from web application. Also, that developed plugin need to install automatically, when I view the web application.
I have implemented the desktop application to communicate the dictaphone device. Also, I have implemented the web application in MVC4.
I want to communicate some data from web application to desktop application. Whenever a button pressed in web application, some data needs to pass to the desktop application.
I have tried to do the same by using the database and it works fine but it slows the performance.
Could you please let me know if you have any thoughts or solutions to achieve this?
|
|
|
|
|
Here is what i did so far. The problem is if a conjunction appears twice in the sentence the code doesnt work for the 2nd appearance of the conjunction. plz if any expert can help ?
private void SplitSentence_Click(object sender, EventArgs e)
{
richTextBox2.Text = "";
richTextBox3.Text = "";
string[] keywords = { " or ", " and ", " hence", "so that", "however", " because" };
string[] sentences = SentenceTokenizer(richTextBox1.Text);
string remSentence;
foreach (string sentence in sentences)
{
remSentence = sentence;
richTextBox3.Text = remSentence;
for (int i =0; i < keywords.Length; i++)
{
if ((remSentence.Contains(keywords[i])))// || (remSentence.IndexOf(keywords[i]) > 0))
{
richTextBox2.Text += remSentence.Substring(0, remSentence.IndexOf(keywords[i])) + '\n' + keywords[i] + '\n';
remSentence = remSentence.Substring(remSentence.IndexOf(keywords[i]) + keywords[i].Length);
}
}
richTextBox2.Text += remSentence;
}
}
public static string[] SentenceTokenizer(string text)
{
char[] sentdelimiters = new char[] { '.', '?', '۔', '؟', '\r', ':', '-' }; // '{ ',' }', '( ', ' )', ' [', ']', '>', '<','-', '_', '= ', '+','|', '\\', ':', ';', ' ', '\'', ',', '.', '/', '?', '~', '!','@', '#', '$', '%', '^', '&', '*', ' ', '\r', '\n', '\t'};
// text.Remove('\n');
return text.Split(sentdelimiters, StringSplitOptions.RemoveEmptyEntries);
}
|
|
|
|
|
|
here is what i did using regex. it works well. But doing this way, Splitting with regex, i lost the control over the word "and" for further processing. I have a lexicon of 20 words that normally appears before the "and (اور)" in urdu language. In next step I want to have a way to check the word before "and" against the lexicon and if found the sentence is broken else display the complete sentence.
private void button1_Click(object sender, EventArgs e)
{
{
richTextBox2.Text = "";
richTextBox3.Text = "";
string[] sentences = SentenceTokenizer(richTextBox1.Text);
string remSentence;
// these are urdu conjunctions. i am actually working on urdu language.
Regex r = new Regex("(کہ |اور | تاکہ| مگر | تاہم | کیونکہ | لیکن )");
foreach (string sentence in sentences)
{
remSentence = sentence;
remSentence = r.Replace(remSentence, "|");
string[] phrases = remSentence.Split('|');
for (int i = 0; i < phrases.Length; i++)
{
richTextBox2.Text += phrases[i] + '\n';
}
}
}
}
|
|
|
|
|
if ((remSentence.Contains(keywords[i]))) That's the position your trouble starts: you execute it once only regardless of the number of occurrences. You'll better use a function to split the sentence, and apply that function recursively on the resulting sub-sentences.
And yes: Regular Expressions are preferred.
|
|
|
|
|
here is what i did using regex. it works well. But doing this way, Splitting with regex, i lost the control over the word "and" for further processing. I have a lexicon of 20 words that normally appears before the "and (اور)" in urdu language. In next step I want to have a way to check the word before "and" against the lexicon and if found the sentence is broken else display the complete sentence.
private void button1_Click(object sender, EventArgs e)
{
{
richTextBox2.Text = "";
richTextBox3.Text = "";
string[] sentences = SentenceTokenizer(richTextBox1.Text);
string remSentence;
// these are urdu conjunctions. i am actually working on urdu language.
Regex r = new Regex("(کہ |اور | تاکہ| مگر | تاہم | کیونکہ | لیکن )");
foreach (string sentence in sentences)
{
remSentence = sentence;
remSentence = r.Replace(remSentence, "|");
string[] phrases = remSentence.Split('|');
for (int i = 0; i < phrases.Length; i++)
{
richTextBox2.Text += phrases[i] + '\n';
}
}
}
}
|
|
|
|
|
would you plz share some coded modification?
-- modified 2-Apr-14 5:26am.
|
|
|
|
|
I am not Bernhard Hiller.
All the label says is that this stuff contains chemicals "... known to the State of California to cause cancer in rats and low-income test subjects." Roger Wright http://www.codeproject.com/lounge.asp?select=965687&exp=5&fr=1#xx965687xx
|
|
|
|
|
Something like the below will loop for each keyword until there are no more matches left for that keyword - but it wont be perfect because it will skip over other keywords while it's looking
e.g "if you had this and that or the other and something"
you'd strip out all the Ands before stripping out the Or
What you need to do is
Repeat
Find the first occurrence of ANY of the keywords in your sentence.
Split the sentence
Until no occurrences found
Using the IndexOf method you can loop through your keywords, finding the lowest, non zero value of IndexOf and storing that word.
When the loop finishes , split the sentence using that word.
bool finished = false;
while (not finished)
if ((remSentence.Contains(keywords[i])))
{
richTextBox2.Text += remSentence.Substring(0, remSentence.IndexOf(keywords[i])) + '\n' + keywords[i] + '\n';
remSentence = remSentence.Substring(remSentence.IndexOf(keywords[i]) + keywords[i].Length);
}
else
{
finished = true;
}
|
|
|
|
|
Private objTestStr As String
Public Property Get TestStr() As String
Set TestStr = objTestStr
End Property
how will the code looks like in c#?
|
|
|
|
|
In C# you can create a Property in multiple ways :
Full blown Property :
private string testString;
public string TestString
{
get
{
return testString;
}
set
{
testString = value;
}
}
Or you can use Auto Implemented Properties:
public string TestString { get; set; };
For a good explanation of C# properties see the MSDN page here[^]
Everyone dies - but not everyone lives
|
|
|
|
|
does the vb code above includes both the Get and Set? or its just a readonly Property where is should only include Get?
|
|
|
|
|
Your code shows a read-only property.
private string objTestStr;
public string TestStr
{
get { return objTestStr; }
}
Well, naming conventions differ a little, _TestString would be preferred instead of objTestStr.
You could also use:
public string TestStr { get; private set; }
|
|
|
|
|
i am very new to c# and i want to write a program to manage a small inventory,i will like to know how i can connect to microsoft access database and using oledbAdapter and write code to save,delete and Update my datasource.pls
|
|
|
|
|
Let me Google that for you...[^]
I'm not questioning your powers of observation; I'm merely remarking upon the paradox of asking a masked man who he is. (V)
|
|
|
|
|
|
Check here[^]
The link to connectionstrings.com is in the article.
Although if you can, forget about access. There are free versions of MySQL, PostgreSQL, Oracle and SQL-Server which are far better.
hope this helps.
|
|
|
|
|
|
For you all, "if one method throws an exception, the other methods will not run." this is the main reason I am using separate try..catch blocks. So that, even if a function gives an exception, the next can execute.
Can you suggest me a nice approach other than I am using here to execute the next function even if an exception occurred during the first function.
My Code
public XmlDocument GetXML(string[] arrInputInfo)
{
string rtnErrno=null;
ArrayList rtnValidateLogin=null;
string rtnPostSMS = null;
string strStartDateTime = DateTime.Now.ToString();
string strEndDateTime = DateTime.Now.ToString();
DataSet dst=new DataSet();
string[] arrLogReq = new string[5];
string strLoginRef = "-999";
string strstatus = "20";
try
{
//Validate Input Details
rtnErrno = ValidateInputInfo(arrInputInfo);
if (rtnErrno != "0")
{
throw new Exception("Exception raised at Input Validation");
}
//Validate Login Details
rtnValidateLogin = objLogin.ValidateCPLogin(arrInputInfo[0], arrInputInfo[1]);
if (rtnValidateLogin[0].ToString() != "0")
{
rtnErrno = rtnValidateLogin[0].ToString();
throw new Exception("Exception raised at Login Validation");
}
else
{
dst = (DataSet)rtnValidateLogin[1];
strLoginRef = dst.Tables[0].Rows[0][0].ToString();
}
//Insert Message
rtnPostSMS = PostSMSText(arrInputInfo);
if (rtnPostSMS.ToString() != "0")
{
rtnErrno = rtnPostSMS[0].ToString();
throw new Exception("Exception raised at Inserting Message");
}
}
catch (Exception ex)
{
strstatus = "30";
LogErrorHelper.LogError(Constants.ERROR_WEBSERVICES_LOGFILE, ex, "BLL.CSMSService-->GetXML");
}
finally
{
GC.Collect();
}
try
{
strEndDateTime = DateTime.Now.ToString();
arrLogReq[0] = strLoginRef; //Login Ref no
arrLogReq[1] = string.Concat(arrInputInfo[2], "~", arrInputInfo[3]); //Mobile No and Message
arrLogReq[2] = strStartDateTime; //start time
arrLogReq[3] = strEndDateTime; //end time
arrLogReq[4] = strstatus;
//To Log Incoming Requests
rtnErrno = LogConfirmation(arrLogReq);
}
catch (Exception ex)
{
LogErrorHelper.LogError(Constants.ERROR_WEBSERVICES_LOGFILE, ex, "BLL.CSMSService-->GetXML");
}
finally
{
GC.Collect();
}
return GetFinalXml(rtnErrno);
}
|
|
|
|
|
..one does not add a try-block around each statement; not every statement throws exceptions, and it makes your code hard to read and harder to maintain.
DoSafe(() => { throw new Exception(); });
DoSafe(() => Console.WriteLine("hi"));
Console.ReadKey();
}
static void DoSafe(Action whatEva)
{
try
{
whatEva.Invoke();
}
catch (Exception)
{
}
}
Then again, if I ever come across code using above construct, I'll delete it without asking permission. And no, you don't need to call GC.Collect.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
Eddy Vluggen wrote: if I ever come across code using above construct, I'll delete it without asking permission
I really can't decide whether to vote you up for that comment, or down for introducing the concept of "On Error Resume Next" to c#...
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952)
Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
|
|
|
|
|
I've been thinking about this a lot recently. So much code I see catches an exception, logs it, then just carries on.
I'm subscribing more and more to the idea (in general) that if something exceptional has happened, the application is now in an unstable state and should be shut down until investigation has found out what went wrong. Obviously exceptions which we sort of expect we can handle with try/catch blocks but for now anyway, I'm avoiding all exception handling for anything else except at the AppDomain level which logs it, emails an alert and Environment.Exit s.
I hate exceptions. In fact, I've just removed TcpListener/TcpClient from my vocabulary because they are too prone to throwing them. The other end disconnected - is that really that exceptional? I'd argue not. TcpClient.Connect - couldn't connect, that's because I have started the other end yet. Why is there no TryConnect??
It's interesting in interviews that they always ask about Exceptions - try/catch/finally - what happens to disposable objects etc. What they should ask is not how you do it, but when and why you should do it and how you are going to recover afterwards.
Well, if you ask me, that is.
Regards,
Rob Philpott.
|
|
|
|
|