Display text as html in Razor page - html

I've just started using Blazor and Razor pages.. it's a lot better than my old plain html pages I was building. But I'm having a problem converting my strings of html I build into actual HTML. Now, this works if I copy and paste my string and save that as an html page. It displays as html no problem. However, when I try to get my Razor page to display it, it displays as plain text. Even trying the trick:
<div>
#(new HtmlString(htmlString))
</div>
displays plain text. This is going to be painful as it's kind of long, but here is the string I'm trying to convert:
"<pre><br><b>STATION INFO</b><br><br> Extension: 34263 Lock Messages? n BCC: 0 <br> Type: 9630 Security Code: 12345 TN: 1<br> Port: S17746 Coverage Path 1: 132 COR: 44<br> Name: Lastname, Firstname Coverage Path 2: COS: 1<br><br><b>STATION OPTIONS</b><br> Time of Day Lock Table: <br> Loss Group: 19 Personalized Ringing Pattern: 1<br> Message Lamp Ext: 34263<br> Speakerphone: 2-way Mute Button Enabled? y<br> Display Language: english Expansion Module? <br> Survivable GK Node Name: <br> Survivable COR: internal Media Complex Ext: <br> Survivable Trunk Dest? IP SoftPhone? y<br><br> IP Video Softphone? n<br><br> Customizable Labels? y<br><br><br> <b>FEATURE OPTIONS</b><br><br> LWC Reception: spe Auto Select Any Idle Appearance? n<br> LWC Activation? y Coverage Msg Retrieval? y<br> LWC Log External Calls? n Auto Answer: none<br> CDR Privacy? n Data Restriction? n<br> Redirect Notification? y Idle Appearance Preference? n<br> Per Button Ring Control? n Bridged Idle Line Preference? n<br> Bridged Call Alerting? n Restrict Last Appearance? y<br> Active Station Ringing: continuous<br> EMU Login Allowed? n<br> H.320 Conversion? n Per Station CPN - Send Calling Number? y<br> Service Link Mode: as-needed EC500 State: unknown<br> Multimedia Mode: enhanced Audible Message Waiting? n<br> MWI Served User Type: sip-adjunct Display Client Redirection? n</pre><br>"
it's being built by my method that returns a string. For fun, here is my method:
public static string CreateStationString(List<StarfishStation> html)
{
var myHTML1 =
"<pre>" + "<br>" +
"<b>STATION INFO</b>" + "<br>" +
"" + "<br>" +
" Extension: " + html[0].DeftyExtension.PadRight(29, ' ') + "Lock Messages? " + html[0].DeftyMessagelock.PadRight(9, ' ') + "BCC: 0 <br>" +
" Type: " + html[0].DeftyDisplaysettype.PadRight(29, ' ') + "Security Code: " + html[0].DeftySecuritycode.PadRight(10, ' ') + "TN: " + html[0].DeftyTenantpartitionnumber + "<br>" +
" Port: " + html[0].DeftyPort.PadRight(27, ' ') + "Coverage Path 1: " + html[0].DeftyCoveragepath.PadRight(9, ' ') + "COR: " + html[0].DeftyCor + "<br>" +
" Name: " + html[0].DeftyName.PadRight(27, ' ') + "Coverage Path 2: " + html[0].DeftyCoverage2path.PadRight(9, ' ') + "COS: " + html[0].DeftyCos + "<br><br>" +
"<b>STATION OPTIONS</b>" + "<br>" +
" Time of Day Lock Table: <br>" +
" Loss Group: " + html[0].DeftyLossgroup + " Personalized Ringing Pattern: " + html[0].DeftyPersonalizedringpattern + "<br>" +
" Message Lamp Ext: " + html[0].DeftyMessagewaitlamplextension + "<br>" +
" Speakerphone: " + html[0].DeftySpeakerphone + " Mute Button Enabled? " + html[0].DeftyMutebutton + "<br>" +
" Display Language: " + html[0].DeftyLanguage.PadRight(32, ' ') + "Expansion Module? " + html[0].DeftyExpansionmodule + "<br>" +
" Survivable GK Node Name: <br>" +
" Survivable COR: internal Media Complex Ext: <br>" +
" Survivable Trunk Dest? IP SoftPhone? " + html[0].DeftyIpsoftphone + "<br>" +
"" + "<br>" +
" IP Video Softphone? n<br>" +
"<br>" +
" Customizable Labels? y<br><br>" +
"<br>" +
" <b>FEATURE OPTIONS</b><br><br>" +
" LWC Reception: " + html[0].DeftyLwcreception.PadRight(20, ' ') + "Auto Select Any Idle Appearance? " + html[0].DeftyIdleappearancepreference + "<br>" +
" LWC Activation? " + html[0].DeftyLwcactivation.PadRight(29, ' ') + "Coverage Msg Retrieval? " + html[0].DeftyCoveragemessageretrieval + "<br>" +
" LWC Log External Calls? " + html[0].DeftyLwclogexterncall.PadRight(40, ' ') + "Auto Answer: " + html[0].DeftyAutoanswer + "<br>" +
" CDR Privacy? " + html[0].DeftyCdrprivacy.PadRight(35, ' ') + "Data Restriction? " + html[0].DeftyDatarestriction + "<br>" +
" Redirect Notification? " + html[0].DeftyRedirectnotification.PadRight(25, ' ') + "Idle Appearance Preference? " + html[0].DeftyIdleappearancepreference + "<br>" +
" Per Button Ring Control? " + html[0].DeftyPerbuttonnringcontrol.PadRight(23, ' ') + "Bridged Idle Line Preference? n" + "<br>" +
" Bridged Call Alerting? " + html[0].DeftyBridgecallalerting.PadRight(27, ' ') + "Restrict Last Appearance? " + html[0].DeftyRestrictlastappearance + "<br>" +
" Active Station Ringing: " + html[0].DeftyActivestationringing + "<br>" +
" EMU Login Allowed? " + html[0].DeftyEMULoginAllowed + "<br>" +
" H.320 Conversion? " + html[0].DeftyH320conv.PadRight(14, ' ') + "Per Station CPN - Send Calling Number? " + html[0].DeftyCpnrestriction + "<br>" +
" Service Link Mode: " + html[0].DeftyServicelinkmode.PadRight(31, ' ') + "EC500 State: unknown<br>" + //check ec500
" Multimedia Mode: " + html[0].DeftyMultimediamode.PadRight(28, ' ') + "Audible Message Waiting? " + html[0].DeftyAudiblemessagewaiting + "<br>" +
" MWI Served User Type: " + html[0].DeftyMessagewaitindicatortype.PadRight(25, ' ') + "Display Client Redirection? n</pre><br>";
return myHTML1;
}
When I look at the frame source, here's what I see:
<div>
<pre><br><b>STATION INFO</b><br><br> Extension: 34263 Lock Messages? n BCC: 0 <br> Type: 9630 Security Code: 12345 TN: 1<br> Port: S17746 Coverage Path 1: 132 COR: 44<br> Name: Lastname Firstname Coverage Path 2: COS: 1<br><br><b>STATION OPTIONS</b><br> Time of Day Lock Table: <br> Loss Group: 19 Personalized Ringing Pattern: 1<br> Message Lamp Ext: 34263<br> Speakerphone: 2-way Mute Button Enabled? y<br> Display Language: english Expansion Module? <br> Survivable GK Node Name: <br> Survivable COR: internal Media Complex Ext: <br> Survivable Trunk Dest? IP SoftPhone? y<br><br> IP Video Softphone? n<br><br> Customizable Labels? y<br><br><br> <b>FEATURE OPTIONS</b><br><br> LWC Reception: spe Auto Select Any Idle Appearance? n<br> LWC Activation? y Coverage Msg Retrieval? y<br> LWC Log External Calls? n Auto Answer: none<br> CDR Privacy? n Data Restriction? n<br> Redirect Notification? y Idle Appearance Preference? n<br> Per Button Ring Control? n Bridged Idle Line Preference? n<br> Bridged Call Alerting? n Restrict Last Appearance? y<br> Active Station Ringing: continuous<br> EMU Login Allowed? n<br> H.320 Conversion? n Per Station CPN - Send Calling Number? y<br> Service Link Mode: as-needed EC500 State: unknown<br> Multimedia Mode: enhanced Audible Message Waiting? n<br> MWI Served User Type: sip-adjunct Display Client Redirection? n</pre><br>
</div>
Sorry this is so long.. but can anyone please help me out?
Thanks!
Dave M.

Wow ok.. so stumbled upon the answer:
<div>
#((MarkupString)htmlString)
</div>
instead of:
<div>
#(new HtmlString(htmlString))
</div>
found the answer here: Convert plain text with html tags to html string and render it in Blazor

Related

Why is setting SQL variable is creating an error?

Following SQL statement is creating an error with message :
"Message: Fatal error encountered during command execution."
"Inner exception: Parameter '#LastUserID' must be defined."
If I directly use LAST_INSERT_ID() instead of LastUserID, it always returns zero (hence fails at second insert) when executed like this.
I don't see my syntax is different than in mySQL document.
Could some one help me ?
string Query = #"INSERT INTO login (" +
"LOGIN_EMAIL," +
"LOGIN_PASSWORD," +
"LOGIN_SALT," +
"LOGIN_LAST_LOGIN_DATE," +
// "LOGIN_LAST_LOGIN_LOCATION," +
"LOGIN_ACCOUNT_STATUS," +
"LOGIN_LOGIN_ATTEMPTS," +
"LOGIN_CREATED_DATE) " +
"VALUES (" +
"#Parameter2," +
"#Parameter3," +
"#Parameter4," +
"#Parameter5," +
// "#Parameter6," +
"#Parameter6," +
"#Parameter7," +
"#Parameter8); " +
"SET #LastUserID = LAST_INSERT_ID(); " +
"INSERT INTO user_role (" +
"USER_ROLE_USER_ID," +
"USER_ROLE_ROLE," +
"USER_ROLE_STATUS," +
"USER_ROLE_CREATED_DATE) " +
"SELECT " +
"#LastUserID," +
"#Parameter9," +
"#Parameter10," +
"#Parameter11 " +
"FROM dual WHERE NOT EXISTS (SELECT USER_ROLE_USER_ID FROM user_role " +
"WHERE USER_ROLE_USER_ID = #LastUserID AND USER_ROLE_ROLE = #Parameter9)";
MySqlCommand oCommand = new MySqlCommand(Query, oMySQLConnecion);
oCommand.Transaction = tr;
Create a procedure in which you first do your insert, cache the last inserted id, do the other insert and let it print out your parameters with a bool if your last insert worked or not. That way you can debug it properly.
In general you should avoid concatinating strings to generate sql-commands or you might get troubles with parameters containing unexpected characters or be hit by a injection.
Simple fix : Replace "$LastUserID" with "$'LastUserID'". The ephostophy makes the difference.

JSON parsing of finance.google.com result

I'm not getting how to parse finance.google.com results, i.e. I got
[
{
"id":"787381",
"t":"HDFC",
"e":"NSE",
"l":"1,424.00",
"l_fix":"1424.00",
"l_cur":"₹1,424.00",
"s":"0",
"ltt":"3:46PM GMT+5:30",
"lt":"Sep 23, 3:46PM GMT+5:30",
"lt_dts":"2016-09-23T15:46:54Z",
"c":"+10.75",
"c_fix":"10.75",
"cp":"0.76",
"cp_fix":"0.76",
"ccol":"chg",
"pcls_fix":"1413.25"
}
]
when I made call to this endpoint using httpopenConnection method, I didn't get anything returned because I couldn't find the JSON object name and i am going to use the result in my android app.
Assuming js is your tool of choice, and you since you don't say what you're trying to do with the array, just assign to a var named obj and you can access it - loop as required...
<!DOCTYPE HTML>
<html>
<body>
<h2>Manage a JSON Object in JavaScript</h2>
<p id="demo"></p>
<script>
var obj = [{"id":"787381","t":"HDFC","e":"NSE","l":"1,424.00","l_fix":"1424.00","l_cur":"₹1,424.00","s":"0","ltt":"3:46PM GMT+5:30","lt":"Sep 23, 3:46PM GMT+5:30","lt_dts":"2016-09-23T15:46:54Z","c":"+10.75","c_fix":"10.75","cp":"0.76","cp_fix":"0.76","ccol":"chg","pcls_fix":"1413.25"}];
document.getElementById("demo").innerHTML =
obj[0].id + "<br>" +
obj[0].t + "<br>" +
obj[0].e + "<br>" +
obj[0].l + "<br>" +
obj[0].l_fix + "<br>" +
obj[0].l_cur + "<br>" +
obj[0].s + "<br>" +
obj[0].ltt + "<br>" +
obj[0].lt + "<br>" +
obj[0].lt_dts + "<br>" +
obj[0].c + "<br>" +
obj[0].c_fix + "<br>" +
obj[0].cp + "<br>" +
obj[0].cp_fix + "<br>" +
obj[0].ccol + "<br>" +
obj[0].pcls_fix + "<br>";
</script>
</body>
</html>
Resulting output to browser is:
Accessing a JSON Object in JavaScript
787381
HDFC
NSE
1,424.00
1424.00
₹1,424.00
0
3:46PM GMT+5:30
Sep 23, 3:46PM GMT+5:30
2016-09-23T15:46:54Z
+10.75
10.75
0.76
0.76
chg
1413.25

Why CurrentApp::AppId take so long in Windows Phone 10?

I have a windows 8 universal project and have a function to get APP ID,
The following function works well in Windows Phone 8.1
Platform::Guid appId = Windows::ApplicationModel::Store::CurrentApp::AppId;
however, it spent around 40s in Windows Phone 10.
From MSDN, only the Metadata is different,
May I know is it caused by the metadata? And how to solve it?
To instead of using AppID, you might use the following code,
Windows::ApplicationModel::Package^ package = Windows::ApplicationModel::Package::Current;
Windows::ApplicationModel::PackageId^ packageId = package->Id;
Windows::ApplicationModel::PackageVersion version = packageId->Version;
Platform::String^ output =
"Name: \"" + packageId->Name + "\"\n" +
"Version: " + version.Major.ToString() + "."
+ version.Minor.ToString() + "."
+ version.Revision.ToString() + "."
+ version.Build.ToString() + "\n" +
"Architecture: " + packageId->Architecture.ToString() + "\n" +
"ResourceId: \"" + packageId->ResourceId + "\"\n" +
"Publisher: \"" + packageId->Publisher + "\"\n" +
"PublisherId: \"" + packageId->PublisherId + "\"\n" +
"FullName: \"" + packageId->FullName + "\"\n" +
"FamilyName: \"" + packageId->FamilyName + "\"\n" +
"IsFramework: " + package->IsFramework.ToString();
Sample output from device
Output:
Name: "f3e02737-ddfa-47a0-a837-37ee53459898"
Version: 1.0.0.0
Architecture: Arm
ResourceId: ""
Publisher: "CN=heefan"
PublisherId: "gsbawe9kfjm1p"
FullName: "f3e02737-ddfa-47a0-a837-37ee53459898_1.0.0.0_arm__gsbawe9kfjm1p"
FamilyName: "f3e02737-ddfa-47a0-a837-37ee53459898_gsbawe9kfjm1p"
IsFramework: false
I also have no idea why AppID take long time to compute.

SSRS expression to get first character from string

I am having a field with string values as "First Middle Last" and i want to show the initial characters from this string as "FML"
how can i do it in terms of ssrs expression ?
Assuming the field MyString always has 3 words the following will find the first character of the First, Second and Last words. This admittedly doesn't handle instances where there are more or less than 3 words, but hopefully should get you started if you require more finesse.
=Left(Fields!MyString.Value, 1) + " " +
Left(Mid(Fields!MyString.Value, InStr(Fields!MyString.Value, " ") + 1), 1) + " " +
Left(Mid(Fields!MyString.Value, InStrRev(Fields!MyString.Value, " ") + 1), 1)
Edit
To cope with the possiblity of only two words (as suggested in the commetns below) a check for the index of the spaces could be used to ensure that they are not the same, and thus 3 words exist. This would make the code as follows
=Left(Fields!MyString.Value, 1) + " " +
Left(Mid(Fields!MyString.Value, InStr(Fields!MyString.Value, " ") + 1), 1) +
iif(InStrRev(Fields!MyString.Value, " ") > InStr(Fields!MyString.Value, " "),
" " + Left(Mid(Fields!MyString.Value, InStrRev(Fields!MyString.Value, " ") + 1), 1),
"")

Is there command line to deploy chrome extension for faster development?

http://developer.chrome.com/extensions/getstarted.html
In the docs,
it instructs we have to open the chrome:extesion page every time and load our own extension
is there any way to use command line such that i can do faster?
(mac OS or linux)
Thanks
Check out chrome.runtime.reload(). I haven't used it myself, but I suppose you could put a button somewhere convenient and trigger that method with it.
A team I am working with on a Chrome extension has figured out the following CHROME_RUN.py Python script:
cwd = sys.path[0]
CHROME_EXTENSION_DIR = cwd + "/Chrome-Extension"
TEMP_DIR = tempfile.mkdtemp()
TEMP_CHROME_PROFILE = TEMP_DIR + "/Chrome-Temp-Profile"
ccUrl = "PAGE_TO_OPEN.HTML"
if not os.path.exists(TEMP_DIR):
os.makedirs(TEMP_DIR)
FULL_CHROME_ARGS = "-user-data-dir=" + TEMP_CHROME_PROFILE + " --load-extension=" + CHROME_EXTENSION_DIR + " \"" + ccUrl + "\"";
if _platform == "win32":
os.system("BUILD_CHROME_PROJECT.py")
os.system("start chrome " + "-user-data-dir=" + TEMP_CHROME_PROFILE + " --load-extension=" + CHROME_EXTENSION_DIR + " \"" + ccUrl + "\"")
elif _platform == "darwin":
os.system("python BUILD_CHROME_PROJECT.py")
os.system("open /Applications/Google\ Chrome.app --args " + "-user-data-dir=" + TEMP_CHROME_PROFILE + " --load-extension=" + CHROME_EXTENSION_DIR + " \"" + ccUrl + "\"")
elif _platform == "linux" or _platform == "linux2":
os.system("./BUILD_CHROME_PROJECT.py")
os.system("chromium " + "-user-data-dir=" + TEMP_CHROME_PROFILE + " --load-extension=" + CHROME_EXTENSION_DIR + " \"" + ccUrl + "\"")
shutil.rmtree(TEMP_DIR)
which is compatible with OSX, Windows and Linux.
If you are looking for the actual arguments to provide Chrome, it is as follows:
FULL_CHROME_ARGS = "-user-data-dir=" + TEMP_CHROME_PROFILE + " --load-extension=" + CHROME_EXTENSION_DIR + " \"" + ccUrl + "\"";
It will creates a temporary profile and launches Chrome with the provided URL. This version of Chrome is similar to how FireFox sandboxes an instance of the browser for plugin testing (fresh, clean instance of the browser with history, cache, etc. from your browsing history)
Go to the extension page, press ctrl+R, the original extension will be reloaded automatically and that doesn't need to do any import action any more.