how to automatically insert javafx code like netebeans8 in apache-netbeans 13++? - javafx

netbeans8 allow insert javafx bean properties with their setters and getters , but newer versions does not have that feature ( perhaps) . how can I do that in apache netbeans 13 ?

make code via macro
This example initializes a SimpleStringProperty with their imports (if they are available), and getter/setters.
To implement it in Apache Netbeans, create a new macro using Tools > Options > Editor > Macros, name it, paste the code below as macro in the new macro you made, and finally create a shortcut.
To use it, create an identifier and then, with the caret inside the identifier, press the macro's shortcut. That was Ctrl+Shift+Alt+1 in my case, but of course you might select a different shortcut.
The macro can easily be modified for other property types, such as boolean, short, integer, etc...
There are two versions shown below. The one to use depends on your "insert closing brackets automatically" setting, which is shown under Tools > Options > Editor > Code Completion:
with "insert closing brackets automatically" turned off
select-word caret-begin-word selection-end-word cut-to-clipboard
caret-line-first-column
insert-tab "private final StringProperty " paste-from-clipboard " = new SimpleStringProperty();" insert-break
insert-break
"public void " paste-from-clipboard make-setter "(String string) {" insert-break
paste-from-clipboard ".set(string);" insert-break "}" insert-break
insert-break
"public String " paste-from-clipboard make-getter "() {" insert-break
"return " paste-from-clipboard ".get();" insert-break "}" insert-break
insert-break
"public StringProperty " paste-from-clipboard "() {" insert-break
" return " paste-from-clipboard " ;" insert-break
"}" insert-break
fix-imports caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up
with "insert closing brackets automatically" turned on
select-word caret-begin-word selection-end-word cut-to-clipboard
caret-line-first-column
insert-tab "private final StringProperty " paste-from-clipboard " = new SimpleStringProperty();" insert-break
insert-break
"public void " paste-from-clipboard make-setter "(String string) {" insert-break
paste-from-clipboard ".set(string);" insert-break "}" insert-break
insert-break
"public String " paste-from-clipboard make-getter "() {" insert-break
"return " paste-from-clipboard ".get();" insert-break "}" insert-break
insert-break
"public StringProperty " paste-from-clipboard "() {" insert-break
" return " paste-from-clipboard " ;" insert-break
fix-imports caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up caret-up

Related

C# returning " rather than "

My code is returning " rather than "
In .cs
public string openingVal
{
get
{
string opening = "";
opening += "\"openingHoursSpecification\": [";
opening += "{";
opening += "\"#type\": \"OpeningHoursSpecification\",";
opening += "\"dayOfWeek\": [";
opening += "\"Tuesday\",";
opening += "\"Wednesday\",";
opening += "\"Thursday\",";
opening += "\"Friday\",";
opening += "\"Saturday\"";
opening += "],";
opening += "\"opens\": \"09:00\",";
opening += "\"closes\": \"19:00\"";
opening += "}";
opening += "],";
return HttpUtility.HtmlDecode(opening);
}
}
In .aspx
<%:addressOpening.openingVal.Replace("quot;","\"") %>
Which then returns
"openingHoursSpecification": [{"#type": "OpeningHoursSpecification","dayOfWeek": ["Tuesday","Wednesday","Thursday","Friday","Saturday"],"opens": "09:00","closes": "19:00"}],
I've tried the HtmlDecode Utility, also using Replace. Both of which do nothing.
Am I losing my mind?

How to create a JSON string in Visual Basic using json.net?

I'm using json.net to parse a JSON text. I got a JObject now:
Dim json_text As String
json_text = "{" & Chr(34) & "Venue" & Chr(34) & ": {" & Chr(34) & "ID" & Chr(34) & ":" & Chr(34) & "JSON" & Chr(34) & "}}"
Console.WriteLine(json_text)
Dim json As JObject
json = JObject.Parse(json_text)
Console.WriteLine(json.SelectToken("Venue").SelectToken("ID"))
Now I want to do the opposite and create a JSON text from the JSON variable.
Unfortunately, I cannot find any solution out there.
Imports Newtonsoft.Json.Linq
Imports Newtonsoft.Json
Dim json_text As String
json_text = "{" & Chr(34) & "Venue" & Chr(34) & ": {" & Chr(34) & "ID" & Chr(34) & ":" & Chr(34) & "JSON" & Chr(34) & "}}"
Console.WriteLine(json_text)
Dim json As JObject
json = JObject.Parse(json_text)
Console.WriteLine(json.SelectToken("Venue").SelectToken("ID"))
Dim json_string As String = JsonConvert.SerializeObject(json,
Formatting.Indented, New JsonSerializerSettings())
Console.WriteLine(json_string)
This results in:
{"Venue": {"ID":"JSON"}}
JSON
{
"Venue": {
"ID": "JSON"
}
}

How to Asynchronous two job in asp.net

Net. I need your favour Please help me. See my Code..
If My First job is finished then exit from btn_ok code behind and update to ASP.NET screen, but at the same time Job 2 must working (Bulk Email is processing)
protected void btn_ok(object sender, EventArgs e)
{
try
{
//**Job 1:**
CommonCls com = new CommonCls();
com.SaveRecord(**Parameter Values**);
//Note :after save this, it must exit from this function and update Message to web Application Screen
//**Job 2**
EmailDAL em = new EmailDAL();
.....
.....
try {
em.SendEmail(PTEmail, "Appointment Rescheduled ", "Dear " + PTName + "<br> Appointment with " + PName + " referred by " + GPName + " has been rescheduled " + Stime + ". <br> with Regards <br> <b>" + GPName + "</b>" + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
try
{
em.SendEmail(PEmail, "Appointment Rescheduled ", "Dear " + PName + "<br> Appointment for " + PTName + "(" + PTCode + ") referred by " + GPName + " has been rescheduled " + Stime + ". <br> with Regards <br> <b>" + GPName + "</b>" + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
try
{
em.SendEmail(GPEmail, "Appointment Rescheduled ", "Dear " + GPName + "<br> Appointment for " + PTName + "(" + PTCode + ") with " + PName + " has been rescheduled " + Stime + ". <br> with Regards <br> " + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
}
catch (Exception ex)
{ }
}
catch (Exception ex)
{ }
}
Email Data Access Layer
public class EmailDAL
{
internal string SMTP = ConfigurationManager.AppSettings["smtpServer"];
internal string MailAddress = ConfigurationManager.AppSettings["smtpUser"];
internal string Pwd = ConfigurationManager.AppSettings["smtpPass"];
internal int Port = Convert.ToInt16(ConfigurationManager.AppSettings["smtpPort"]);
internal bool ssl = Convert.ToBoolean(ConfigurationManager.AppSettings["EnableSsl"]);
public string SendEmail(string toMail, string mailSubject, string Message)
{
SmtpClient SmtpServer = new SmtpClient(SMTP);
var mail = new MailMessage();
mail.From = new MailAddress(MailAddress);
mail.To.Add(toMail);
mail.Subject = mailSubject;
mail.IsBodyHtml = true;
mail.Body = "<p style='line-height: 30px;'>" + Message + "</p>";
SmtpServer.Port = Port;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(MailAddress, Pwd);
SmtpServer.EnableSsl = ssl;
try
{
SmtpServer.Send(mail);
return "Send Sucessfully";
}
catch (Exception ex)
{
return ex.Message.ToString();
}
}
}
**Edited Answer
After seeing your methods, it looks like you will need to make that EmailDAL.SendEmail() method of yours async. To do that you could do something like the following:
public async Task<string> SendEmailAsync(string toMail, string mailSubject, string Message) {
SmtpClient SmtpServer = new SmtpClient(SMTP);
var mail = new MailMessage();
mail.From = new MailAddress(MailAddress);
mail.To.Add(toMail);
mail.Subject = mailSubject;
mail.IsBodyHtml = true;
mail.Body = "<p style='line-height: 30px;'>" + Message + "</p>";
SmtpServer.Port = Port;
SmtpServer.UseDefaultCredentials = false;
SmtpServer.Credentials = new System.Net.NetworkCredential(MailAddress, Pwd);
SmtpServer.EnableSsl = ssl;
try {
await SmtpServer.SendAsync(mail);
return "Send Successfully";
} catch(Exception ex) {
return ex.Message;
}
}
Then, btn_ok() might look like:
protected async void btn_ok(object sender, EventArgs e) {
try {
//**Job 1:**
CommonCls com = new CommonCls();
com.SaveRecord(**Parameter Values**);
//Note :after save this, it must exit from this function and update Message to web Application Screen
//**Job 2**
EmailDAL em = new EmailDAL();
.....
.....
try {
await em.SendEmailAsync(PTEmail, "Appointment Rescheduled ", "Dear " + PTName + "<br> Appointment with " + PName + " referred by " + GPName + " has been rescheduled " + Stime + ". <br> with Regards <br> <b>" + GPName + "</b>" + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
try {
await em.SendEmailAsync(PEmail, "Appointment Rescheduled ", "Dear " + PName + "<br> Appointment for " + PTName + "(" + PTCode + ") referred by " + GPName + " has been rescheduled " + Stime + ". <br> with Regards <br> <b>" + GPName + "</b>" + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
try {
await em.SendEmailAsync(GPEmail, "Appointment Rescheduled ", "Dear " + GPName + "<br> Appointment for " + PTName + "(" + PTCode + ") with " + PName + " has been rescheduled " + Stime + ". <br> with Regards <br> " + axolbl);
}
catch (Exception ex) { logger.Error(ex.ToString()); }
}
catch (Exception ex) { }
}
Check out the link below to read more about using the SmtpClient.SendAsync method and how to receive updates when the email has finished transmitting.
https://msdn.microsoft.com/en-us/library/x5x13z6h(v=vs.110).aspx
Now we still need to see what CommonCls.SaveRecord() looks like to make that one async.
**Original Answer
You may want to try using Task.WhenAny() along with async and await. It will return as soon as a single job finishes but then it will still continue to let the second job finish. Although I cannot tell what version of .NET you are working with.
Below is an MSDN article about it. Hope this helps:
https://msdn.microsoft.com/en-us/library/jj155756.aspx

Evaluate math expression in c# that should handle whitespace if it exists

I am trying to use the following code to evaluate math expression. currently, the expression parser only works if there is a whitespace between every character. ex: (x + y) *2.... if the expression is (x+y)*2, the expression does not evaluate. Trying to use regex so the expression evaluates with or without spaces,but still unable to meet the goal. Any direction/help is greatly appreciated.
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string input = "(x + y)*2";
string pattern = "\\s+";
string replacement = " ";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
}
}
If extra spaces between the terms is fine, please try this code:
public static void Main()
{
string input = "(x + y)*2";
string pattern = "";
string replacement = " ";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
}
public static void Main()
{
string input = "(x + y)*2";
string pattern = "";
string replacement = " ";
Regex rgx = new Regex(pattern);
string result = rgx.Replace(input, replacement);
pattern = " ";
replacement = " ";
rgx = new Regex(pattern);
result = rgx.Replace(result, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("Replacement String: {0}", result);
}

sugestions on global error handler to get dump of diagnostic data

there are loads of resources that show how to use global.ascx global error event handler to capture un-managed errors in the web application but i am yet to find a good sample of code to include in this method that will report on major topics like error message, an output of stack trace, page that generated the error, the user-name/ role that generated the error... and the such.
has anyone used, have, or come across a nice code spinet for this purpose?
thanks in advance.
Your best best it to do nothing. ASP.NET Health Monitoring will write an event to the event log containing most of the data you could need.
If that's not enough information for you, then you should look into wrapping certain of your exceptions in an outer exception which includes the additional data. For instance:
string fileSpec = " ... ";
try
{
using (var stream = new FileStream(fileSpec))
{
// Something
}
}
catch (IOException ex)
{
throw new Exception(String.Format("Error processing {0}", fileSpec), ex);
}
Here's what we're using though we may now want to switch to Health Monitoring seeing the other answers to this question.
public static void LogErrorWithStackTrace(String message, Exception exception,
EventLogEntryType entryType)
{
var context = HttpContext.Current;
var session = context.Session;
var request = context.Request;
var errorMessage =
String.Format(
#"Message: {0}
Error in: {1}
Referer: {2}
Agent: {3}
IP: {4}
Request type: {5}",
message, request.Url, request.UrlReferrer,
request.UserAgent, request.UserHostAddress, request.RequestType);
errorMessage += "\rQuery string variables:";
errorMessage = request.QueryString.Keys.Cast<string>().Aggregate(errorMessage,
(current, key) =>
current +
"\r " + key + " = " +
request.QueryString[
key]);
errorMessage += "\rForm variables:";
errorMessage = request.Form.Keys.Cast<string>().Aggregate(errorMessage,
(current, key) =>
current + "\r " + key +
" = " +
request.Form[key]);
errorMessage += "\rCookies:";
errorMessage = request.Cookies.Keys.Cast<string>().Aggregate(errorMessage,
(current, key) =>
current + "\r " + key +
" = " +
request.Cookies[key]);
if (session != null)
{
errorMessage += "\rISession:";
var sess = (ISession) session["session"];
errorMessage += sess.ToString();
errorMessage += "\rSession:";
errorMessage = session.Keys.Cast<string>().Aggregate(errorMessage,
(current, sessionKey) =>
current +
"\r " + sessionKey + ": " +
session[sessionKey]);
}
errorMessage += "\rStack Trace:";
errorMessage += exception.StackTrace;
WriteEntry(errorMessage, entryType);
if (!QuietTypes.Contains(exception.GetType()))
SendExceptionEmail(errorMessage);
}
This is some VB code we use, it provides enougth info for us to diagnose most problems. Only downside with emailing errors like this is when there is a major failure you can end up with thousands of messages in your mailbox :(
Dim e As Exception
If System.Web.HttpContext.Current.Request.IsLocal Then Exit Sub
e = System.Web.HttpContext.Current.Server.GetLastError
If e IsNot Nothing Then
If TypeOf e Is HttpException Then
Dim he As HttpException = DirectCast(e, HttpException)
If he.GetHttpCode=404 Then
System.Web.HttpContext.Current.Server.ClearError()
Response.Redirect("/")
Exit Sub
End If
End If
MsgBody += "Exception: " & e.Message & vbCrLf & vbCrLf
MsgBody += e.ToString & vbCrLf & vbCrLf & vbCrLf
Else
MsgBody += "Unknown Error" & vbCrLf & vbCrLf & vbCrLf
End If
If System.Web.HttpContext.Current.Request.Url Is Nothing Then
MsgBody += "URL: ?" & vbCrLf & vbCrLf
Else
MsgBody += "URL: " & System.Web.HttpContext.Current.Request.Url.ToString & vbCrLf
If System.Web.HttpContext.Current.Request.RawUrl IsNot Nothing Then MsgBody += System.Web.HttpContext.Current.Request.RawUrl & vbCrLf
MsgBody += vbCrLf
End If
If System.Web.HttpContext.Current.Request.UrlReferrer Is Nothing Then
MsgBody += "Referer: <direct>" & vbCrLf & vbCrLf
Else
MsgBody += "Referer: " & System.Web.HttpContext.Current.Request.UrlReferrer.ToString() & vbCrLf & vbCrLf
End If
If User IsNot Nothing Then MsgBody += "User: " & User.Identity.Name & vbCrLf
MsgBody += "User-Agent: " & System.Web.HttpContext.Current.Request.UserAgent & vbCrLf
MsgBody += "User-IP: " & System.Web.HttpContext.Current.Request.UserHostAddress & vbCrLf
MsgBody += "Server: " & System.Environment.MachineName & vbCrLf
MsgBody += vbCrLf & "RequestType: " & System.Web.HttpContext.Current.Request.RequestType() & vbCrLf & vbCrLf
' dump request items
' QueryString, Form, Cookies, ServerVariables
MsgBody += "Querystring Variables ================" & vbCrLf
If Request.QueryString.Count > 0 Then
For Each key As String In Request.QueryString.Keys
MsgBody += key & " = " & Request.QueryString(key) & vbCrLf
Next
Else
MsgBody += "(none)" & vbCrLf
End If
MsgBody += vbCrLf
MsgBody += "Form Variables =======================" & vbCrLf
If Request.Form.Count > 0 Then
For Each key As String In Request.Form.Keys
MsgBody += key & " = " & Request.Form(key) & vbCrLf
Next
Else
MsgBody += "(none)" & vbCrLf
End If
MsgBody += vbCrLf
MsgBody += "Cookies ==============================" & vbCrLf
If Request.Cookies.Count > 0 Then
For Each key As String In Request.Cookies.Keys
MsgBody += key & " = " & Request.Cookies(key).Value & vbCrLf
Next
Else
MsgBody += "(none)" & vbCrLf
End If
MsgBody += vbCrLf
MsgBody += "ServerVariables ======================" & vbCrLf
If Request.ServerVariables.Count > 0 Then
For Each key As String In Request.ServerVariables.Keys
MsgBody += key & " = " & Request.ServerVariables(key) & vbCrLf
Next
Else
MsgBody += "(none)" & vbCrLf
End If
MsgBody += vbCrLf
' we send MsgBody via email using the System.Net.Mail.MailMessage & System.Net.Mail.SmtpClient classes
' we've handled the error
System.Web.HttpContext.Current.Server.ClearError()
' depending on the error we redirect to our homepage /default.aspx unless that is the faulting page then redirect to static /error.html

Resources